Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug CLI public-decrypt",
"type": "node",
"request": "launch",
"runtimeExecutable": "npx",
"runtimeArgs": [
".",
"test",
"public-decrypt",
"--types",
"euint32",
"--fetch-retries",
"10",
"--fetch-retry-delay",
"2000",
"--debug"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}
]
}
5 changes: 2 additions & 3 deletions bin/commands/acl-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { logCLI, parseCommonOptions } from '../utils.js';

// npx . acl address
export async function testACLAddressCommand(options) {
const { config, provider } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (!config.fhevmInstanceConfig.aclContractAddress) {
logCLI(
Expand Down
18 changes: 18 additions & 0 deletions bin/commands/acl-is-allowed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

import { parseCommonOptions } from '../utils.js';
import { ACL } from '../../lib/internal.js';

// npx . acl is-allowed --handle 0xf6751d547a5c06123575aad93f22f76b7d841c4cacff0000000000aa36a70000 --address 0x37AC010c1c566696326813b840319B58Bb5840E4
export async function aclIsAllowedCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const aclContractAddress = config.fhevmInstanceConfig.aclContractAddress;

const acl = new ACL({ aclContractAddress, provider });

const ok = await acl.persistAllowed([options.handle, options.address]);

console.log(ok[0]);
}
7 changes: 3 additions & 4 deletions bin/commands/acl-is-publicly-decryptable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { logCLI, parseCommonOptions } from '../utils.js';
import { ACL } from '../../lib/internal.js';

// npx . acl is-publicly-decryptable --handle 0xe85c2a81338b8542a6c0a99a5a794f158f4fb0f6a2ff0000000000aa36a70400
export async function testFHETestIsPubliclyDecryptableCommand(options) {
const { config, provider, signer } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
export async function aclIsPubliclyDecryptable(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const aclContractAddress = config.fhevmInstanceConfig.aclContractAddress;

Expand Down
3 changes: 2 additions & 1 deletion bin/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { parseCommonOptions } from '../utils.js';
// npx . config --network mainnet
// npx . config --contract-address 0xb2a8A265dD5A27026693Aa6cE87Fb21Ac197b6b9 --user-address 0x37AC010c1c566696326813b840319B58Bb5840E4
export async function configCommand(options) {
const { config, provider } = parseCommonOptions(options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const iv = await InputVerifier.loadFromChain({
inputVerifierContractAddress:
Expand Down
4 changes: 3 additions & 1 deletion bin/commands/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { parseCommonOptions, parseHandles } from '../utils.js';
*/
// npx . handle "0x36a1f452f2c26d7cbf329d23220d92c342062fa7f7000000000000aa36a70000 0xce6f699529292547e11ad7635537997fef29519ecf010000000000aa36a70200 0x9162215c0789609fb2132615c76e80af78209797d9020000000000aa36a70600 0xa8225e1781cab16dedf1b9a5f5c0ed0f03b64d1fb3030000000000aa36a70700"
export async function handleCommand(args, options) {
const { config } = parseCommonOptions(options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const fhevmHandles = parseHandles(args);
console.log(safeJSONstringify(fhevmHandles, 2));
}
7 changes: 4 additions & 3 deletions bin/commands/input-proof.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import {
// npx . input-proof --contract-address 0xb2a8A265dD5A27026693Aa6cE87Fb21Ac197b6b9 --user-address 0x37AC010c1c566696326813b840319B58Bb5840E4 --values 123:euint32
// npx . input-proof --values 123:euint32 true:ebool 1234567890123456789:euint256 0xb2a8A265dD5A27026693Aa6cE87Fb21Ac197b6b9:eaddress --version 2 --network mainnet
export async function inputProofCommand(options) {
const { config, zamaFhevmApiKey } = parseCommonOptions(options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const { publicKey, publicParams } = await loadFhevmPublicKeyConfig(
config,
options,
);

const fheTypedValues = valueColumnTypeListToFheTypedValues(options.values);
const o = await inputProof(
const o = await inputProof({
fheTypedValues,
config,
publicKey,
publicParams,
zamaFhevmApiKey,
options,
);
});
console.log(safeJSONstringify(o, 2));
}
10 changes: 8 additions & 2 deletions bin/commands/public-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ import { parseCommonOptions, parseHandles } from '../utils.js';
// npx . public-decrypt --version 2 --handles 0xe85c2a81338b8542a6c0a99a5a794f158f4fb0f6a2ff0000000000aa36a70400
// npx . public-decrypt --version 2 --handles 0x7abb4a6c63af220fcd7da6bba4a0891fbe77e576efff00000000000000010500
export async function publicDecryptCommand(options) {
const { config, zamaFhevmApiKey } = parseCommonOptions(options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const fhevmHandles = parseHandles(options.handles);
const handles = fhevmHandles.map((h) => {
return h.toBytes32Hex();
});

const res = await publicDecrypt(handles, config, zamaFhevmApiKey, options);
const res = await publicDecrypt({
handles,
config,
zamaFhevmApiKey,
options,
});

console.log(safeJSONstringify(res, 2));
}
12 changes: 4 additions & 8 deletions bin/commands/test/test-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export async function testFHETestAddCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
logCLI('🚀 route: v' + config.version, options);
logCLI(`🍔 signer: ${signer.address}`);
logCLI(`🧀 value: ${BigInt(options.value)}`);
logCLI(`🍉 type: ${options.type}`);

const fheTypedValues = [
{
value: BigInt(options.value),
Expand All @@ -44,14 +38,14 @@ export async function testFHETestAddCommand(options) {
options,
);

const o = await inputProof(
const o = await inputProof({
fheTypedValues,
config,
publicKey,
publicParams,
zamaFhevmApiKey,
options,
);
});
console.log(safeJSONstringify(o, 2));

const contract = new ethers.Contract(
Expand All @@ -71,6 +65,7 @@ export async function testFHETestAddCommand(options) {
contractAddresses: [contractAddress],
signer,
config,
zamaFhevmApiKey,
options,
});

Expand Down Expand Up @@ -98,6 +93,7 @@ export async function testFHETestAddCommand(options) {
contractAddresses: [contractAddress],
signer,
config,
zamaFhevmApiKey,
options,
});

Expand Down
5 changes: 2 additions & 3 deletions bin/commands/test/test-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { FHETestAddresses } from './fheTest.js';

// npx . test address
export async function testFHETestAddressCommand(options) {
const { config, provider } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
Expand Down
5 changes: 2 additions & 3 deletions bin/commands/test/test-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { ethers } from 'ethers';
// npx . test get --type euint32 --network testnet --json
// npx . test get --type euint32 --network mainnet --json
export async function testFHETestGetCommand(options) {
const { config, provider, signer } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
Expand Down
47 changes: 47 additions & 0 deletions bin/commands/test/test-is-publicly-decryptable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

import { ACL } from '../../../lib/internal.js';
import { logCLI, parseCommonOptions } from '../../utils.js';
import { FHETestAddresses } from './fheTest.js';
import { ethers } from 'ethers';

// npx . test is-publicly-decryptable --type euint32 --network devnet
// npx . test is-publicly-decryptable --type euint32 --network testnet
// npx . test is-publicly-decryptable --type euint32 --network mainnet
export async function testFHETestIsPubliclyDecryptableCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
}

const contractAddress = FHETestAddresses[config.name];

// Turn 'euint32' into 'Euint32'
const t = 'E' + options.type.substring(1);
const funcName = `makePubliclyDecryptable${t}`;
const getFuncName = `get${t}`;

const contract = new ethers.Contract(
contractAddress,
[
`function ${funcName}() external`,
`function ${getFuncName}() view returns (bytes32)`,
],
signer,
);

const handle = await contract[getFuncName]();
logCLI(`🏈 handle: ${handle}`);

const acl = new ACL({
aclContractAddress: config.fhevmInstanceConfig.aclContractAddress,
provider,
});

const ok = await acl.isAllowedForDecryption([handle]);

console.log(ok[0]);
}
8 changes: 3 additions & 5 deletions bin/commands/test/test-make-publicly-decryptable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import { ethers } from 'ethers';
// npx . test make-publicly-decryptable --type euint32 --network testnet
// npx . test make-publicly-decryptable --type euint32 --network mainnet
export async function testFHETestMakePubliclyDecryptableCommand(options) {
const { config, provider, signer } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
logCLI('🚀 route: v' + config.version, options);
logCLI(`🍔 signer: ${signer.address}`);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
Expand Down Expand Up @@ -43,6 +40,7 @@ export async function testFHETestMakePubliclyDecryptableCommand(options) {
aclContractAddress: config.fhevmInstanceConfig.aclContractAddress,
provider,
});

const ok = await acl.isAllowedForDecryption([handle]);
if (ok[0] === true) {
logCLI(`🚨 handle is already publicly decryptable.`);
Expand Down
11 changes: 6 additions & 5 deletions bin/commands/test/test-public-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export async function testFHETestPublicDecryptCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

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

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
Expand Down Expand Up @@ -54,7 +50,12 @@ export async function testFHETestPublicDecryptCommand(options) {
logCLI(`🏈 handle: ${handle}`, options);
}

const res = await publicDecrypt(handles, config, zamaFhevmApiKey, options);
const res = await publicDecrypt({
handles,
config,
zamaFhevmApiKey,
options,
});

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

Expand Down
7 changes: 2 additions & 5 deletions bin/commands/test/test-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import { ethers } from 'ethers';
// npx . test random --type euint32 --network testnet
// npx . test random --type euint32 --network devnet
export async function testFHETestRandomCommand(options) {
const { config, provider, signer } = parseCommonOptions(options);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

if (options.type === 'eaddress') {
logCLI(`❌ FHETest does not support random addresses`, options);
process.exit(1);
}

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

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
Expand Down
4 changes: 0 additions & 4 deletions bin/commands/test/test-user-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export async function testFHETestUserDecryptCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

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

if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
Expand Down
7 changes: 2 additions & 5 deletions bin/commands/user-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { logCLI, parseCommonOptions } from '../utils.js';

// npx . user-decrypt --version 2 --handle 0xe85c2a81338b8542a6c0a99a5a794f158f4fb0f6a2ff0000000000aa36a70400 --contract-address 0x1E7eA8fE4877E6ea5dc8856f0dA92da8d5066241 --network testnet
export async function userDecryptCommand(options) {
const { config, signer, zamaFhevmApiKey } = parseCommonOptions(options);

logCLI('🚚 network: ' + config.name, options);
logCLI('🚀 route: v' + config.version, options);
logCLI(`🍔 signer: ${signer.address}`);
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);

const handle = options.handle;
const contractAddress = config.contractAddress;
Expand Down
Loading