Skip to content

Commit 6222623

Browse files
authored
WASM modules init (#394)
* chore: add generateKeypair test * chore: fix missing env file in CLI, add key infos * chore: add setTFHE and setTKMS module setup functions. remove window.xxx init * fix: cli output * chore: remove dead code
1 parent 6af7e3a commit 6222623

40 files changed

Lines changed: 2260 additions & 97 deletions

bin/commands/test/test-add.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { ethers } from 'ethers';
1111
// npx . test add --type euint32 --value 123 --network testnet
1212
// npx . test add --type euint32 --value 123 --network devnet
1313
export async function testFHETestAddCommand(options) {
14-
const { config, provider, signer } = parseCommonOptions(options);
14+
const { config, provider, signer, zamaFhevmApiKey } =
15+
parseCommonOptions(options);
1516

1617
logCLI('🚚 network: ' + config.name, options);
1718
logCLI('🚀 route: v' + config.version, options);
@@ -48,6 +49,7 @@ export async function testFHETestAddCommand(options) {
4849
config,
4950
publicKey,
5051
publicParams,
52+
zamaFhevmApiKey,
5153
options,
5254
);
5355
console.log(safeJSONstringify(o, 2));

bin/commands/test/test-public-decrypt.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function testFHETestPublicDecryptCommand(options) {
2424

2525
logCLI('🚚 network: ' + config.name, options);
2626
logCLI('🚀 route: v' + config.version, options);
27-
logCLI(`🍔 signer: ${signer.address}`);
27+
logCLI(`🍔 signer: ${signer.address}`, options);
2828

2929
if (!FHETestAddresses[config.name]) {
3030
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
@@ -51,14 +51,14 @@ export async function testFHETestPublicDecryptCommand(options) {
5151
for (let i = 0; i < getFuncNames.length; ++i) {
5252
const handle = await contract[getFuncNames[i]]();
5353
handles.push(handle);
54-
logCLI(`🏈 handle: ${handle}`);
54+
logCLI(`🏈 handle: ${handle}`, options);
5555
}
5656

5757
const res = await publicDecrypt(handles, config, zamaFhevmApiKey, options);
5858

5959
console.log(safeJSONstringify(res, 2));
6060

61-
logCLI(`Verify ...`);
61+
logCLI(`Verify ...`, options);
6262

6363
// Simulate the transaction using staticCall (dry run)
6464
await contract.verify.staticCall(
@@ -67,5 +67,5 @@ export async function testFHETestPublicDecryptCommand(options) {
6767
res.decryptionProof,
6868
);
6969

70-
logCLI(`✅ Verification succeeded!`);
70+
logCLI(`✅ Verification succeeded!`, options);
7171
}

bin/inputProof.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function inputProof(
1313
const arr = fheTypedValuesToBuilderFunctionWithArg(fheTypedValues);
1414

1515
const instanceOptions = {
16-
...(options.verbose === true ? { debug: true } : {}),
16+
...(options?.verbose === true ? { debug: true } : {}),
1717
auth: { __type: 'ApiKeyHeader', value: zamaFhevmApiKey },
1818
};
1919

bin/instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createInstance } from '../lib/node.cjs';
1+
import { createInstance } from '../lib/internal.js';
22
import { logCLI } from './utils.js';
33

44
let __instance;

bin/pubkeyCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import fs from 'fs';
22
import path from 'path';
33
import { homedir } from 'os';
44
import {
5-
createRelayerFhevm,
65
TFHEPkeCrs,
76
TFHEPublicKey,
7+
createRelayerFhevm,
88
} from '../lib/internal.js';
99
import { logCLI } from './utils.js';
1010

bin/publicDecrypt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function publicDecrypt(handles, config, zamaFhevmApiKey, options) {
99
);
1010

1111
const instanceOptions = {
12-
...(options.verbose === true ? { debug: true } : {}),
12+
//...(options.verbose === true ? { debug: true } : {}),
1313
auth: { __type: 'ApiKeyHeader', value: zamaFhevmApiKey },
1414
};
1515

bin/userDecrypt.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function userDecrypt({
1717
);
1818

1919
const instanceOptions = {
20-
...(options.verbose === true ? { debug: true } : {}),
20+
//...(options.verbose === true ? { debug: true } : {}),
2121
auth: { __type: 'ApiKeyHeader', value: zamaFhevmApiKey },
2222
};
2323

@@ -39,6 +39,9 @@ export async function userDecrypt({
3939

4040
const keypair = instance.generateKeypair();
4141

42+
logCLI(`privateKey hex length:${keypair.privateKey.length}`);
43+
logCLI(`publicKey hex length:${keypair.publicKey.length}`);
44+
4245
logCLI('Running user decrypt...', options);
4346

4447
const startTimeStamp = Math.floor(Date.now() / 1000);

bin/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ethers } from 'ethers';
44
import {
55
encryptionBitsFromFheTypeName,
66
FhevmHandle,
7-
isChecksummedAddress,
87
isFheTypeName,
8+
isChecksummedAddress,
99
} from '../lib/internal.js';
1010
import { FHETestAddresses } from './commands/test/fheTest.js';
1111

@@ -35,6 +35,9 @@ export function getEnv(envName, envFile) {
3535
if (!envFile) {
3636
throwError(`Missing env filename`);
3737
}
38+
if (!fs.existsSync(envFile)) {
39+
throwError(`Missing env file ${envFile}`);
40+
}
3841
const parsedEnv = dotenv.parse(fs.readFileSync(envFile));
3942
return process.env[envName] ?? parsedEnv[envName];
4043
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "../dist.tmp/node-mock.d.ts",
4+
"dtsRollup": {
5+
"enabled": true,
6+
"untrimmedFilePath": "../lib/node-mock.d.ts"
7+
},
8+
"compiler": {
9+
"tsconfigFilePath": "./tsconfig.api-extractor.json"
10+
},
11+
"projectFolder": ".",
12+
"apiReport": {
13+
"enabled": false
14+
},
15+
"docModel": {
16+
"enabled": false
17+
},
18+
"tsdocMetadata": {
19+
"enabled": false
20+
},
21+
"messages": {
22+
"extractorMessageReporting": {
23+
"ae-missing-release-tag": {
24+
"logLevel": "none"
25+
}
26+
}
27+
}
28+
}

config/rollup.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ export default [
9191
// https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency
9292
external: ['ethers', 'fetch-retry', 'node-tfhe', 'node-tkms', 'keccak'],
9393
},
94+
{
95+
input: 'src/node-mock.ts',
96+
output: {
97+
file: 'lib/node-mock.js',
98+
name: 'relayer-sdk-js',
99+
format: 'es',
100+
},
101+
plugins: [...nodePlugins],
102+
// Suppress warning
103+
// https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency
104+
external: ['ethers', 'fetch-retry', 'node-tfhe', 'node-tkms', 'keccak'],
105+
},
94106
// Internal entry point for bin/ scripts (not part of public API)
95107
{
96108
input: 'src/internal.ts',

0 commit comments

Comments
 (0)