@zama-fhe/relayer-sdk 0.1.0-7 → 0.1.0-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/relayer.js CHANGED
@@ -3,32 +3,40 @@
3
3
 
4
4
  import { program } from 'commander';
5
5
  import { toHexString, prependHttps, throwError } from './utils.js';
6
- import { createInstance } from '../lib/node.cjs';
6
+ import { createInstance, SepoliaConfig } from '../lib/node.cjs';
7
7
 
8
8
  const allowedBits = [1, 4, 8, 16, 32, 64];
9
9
 
10
- const FHE_LIB_ADDRESS = '0x000000000000000000000000000000000000005d';
11
-
12
10
  let _instance;
13
11
 
14
12
  const getInstance = async (networkUrl) => {
15
13
  if (_instance) return _instance;
16
14
 
17
15
  try {
18
- _instance = await createInstance({ networkUrl });
16
+ // NOTE: hack to get the instance created
17
+ const config = { ...SepoliaConfig, network: networkUrl };
18
+ console.debug(`Using network ${config.network}`);
19
+ _instance = await createInstance(config);
19
20
  } catch (e) {
20
21
  return throwError(
21
22
  `This network (${networkUrl}) doesn't seem to use Fhevm or use an incompatible version.`,
23
+ e,
22
24
  );
23
25
  }
24
26
  return _instance;
25
27
  };
26
28
 
29
+ // TODO: be able to pass a full configuration, or simply the chain-id/name, or relayer-url
27
30
  program
28
31
  .command('encrypt')
29
32
  .argument('<contractAddress>', 'address of the contract')
30
33
  .argument('<userAddress>', 'address of the account')
31
34
  .argument('<values:bits...>', 'values with number of bits eg: 1:1 3324242:64')
35
+ .requiredOption(
36
+ '-n, --node <url>',
37
+ 'url of the blockchain',
38
+ 'https://eth-sepolia.public.blastapi.io',
39
+ )
32
40
  .action(async (contractAddress, userAddress, valuesArr, options) => {
33
41
  const host = prependHttps(options.node);
34
42
  const instance = await getInstance(host);
@@ -55,7 +63,6 @@ program
55
63
  console.log(`Handle ${i}`);
56
64
  console.log(`0x${toHexString(handle)}`);
57
65
  });
58
- })
59
- .requiredOption('-n, --node <url>', 'url of the blockchain');
66
+ });
60
67
 
61
- program.parseAsync(process.argv);
68
+ program.parseAsync();
package/bin/utils.js CHANGED
@@ -8,7 +8,11 @@ export const prependHttps = (host) => {
8
8
  export const toHexString = (bytes) =>
9
9
  bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
10
10
 
11
- export const throwError = (error) => {
12
- console.error(`Error: ${error}`);
11
+ export const throwError = (error, cause) => {
12
+ if (cause) {
13
+ console.error(`Error: ${error} with cause: ${cause}`);
14
+ } else {
15
+ console.error(`Error: ${error}`);
16
+ }
13
17
  process.exit();
14
18
  };