@zama-fhe/relayer-sdk 0.1.0-1
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/LICENSE +28 -0
- package/README.md +55 -0
- package/bin/relayer.js +61 -0
- package/bin/utils.js +14 -0
- package/bundle/fhevm.js +40713 -0
- package/bundle/fhevm.umd.cjs +24 -0
- package/bundle/kms_lib_bg.wasm +0 -0
- package/bundle/tfhe_bg.wasm +0 -0
- package/bundle/workerHelpers.js +2 -0
- package/bundle.d.ts +1 -0
- package/bundle.js +12 -0
- package/lib/config.d.ts +30 -0
- package/lib/index.d.ts +29 -0
- package/lib/init.d.ts +7 -0
- package/lib/kms_lib_bg.wasm +0 -0
- package/lib/node.cjs +1152 -0
- package/lib/node.d.ts +2 -0
- package/lib/relayer/decryptUtils.d.ts +2 -0
- package/lib/relayer/handles.d.ts +4 -0
- package/lib/relayer/network.d.ts +31 -0
- package/lib/relayer/network.test.d.ts +1 -0
- package/lib/relayer/publicDecrypt.d.ts +3 -0
- package/lib/relayer/publicDecrypt.test.d.ts +1 -0
- package/lib/relayer/sendEncryption.d.ts +41 -0
- package/lib/relayer/sendEncryption.test.d.ts +1 -0
- package/lib/relayer/userDecrypt.d.ts +11 -0
- package/lib/relayer/userDecrypt.test.d.ts +1 -0
- package/lib/sdk/encrypt.d.ts +34 -0
- package/lib/sdk/encrypt.test.d.ts +1 -0
- package/lib/sdk/encryptionTypes.d.ts +13 -0
- package/lib/sdk/keypair.d.ts +34 -0
- package/lib/sdk/keypair.test.d.ts +1 -0
- package/lib/test/index.d.ts +10 -0
- package/lib/tfhe.d.ts +7 -0
- package/lib/tfhe_bg.wasm +0 -0
- package/lib/utils.d.ts +9 -0
- package/lib/web.d.ts +2 -0
- package/lib/web.js +27305 -0
- package/lib/workerHelpers.js +24774 -0
- package/node.d.ts +1 -0
- package/node.js +1 -0
- package/package.json +99 -0
- package/web.d.ts +1 -0
- package/web.js +1 -0
package/lib/node.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ENCRYPTION_TYPES } from '../sdk/encryptionTypes';
|
|
2
|
+
type EncryptionBitwidths = keyof typeof ENCRYPTION_TYPES;
|
|
3
|
+
export declare const computeHandles: (ciphertextWithZKProof: Uint8Array, bitwidths: EncryptionBitwidths[], aclContractAddress: string, chainId: number, ciphertextVersion: number) => Uint8Array<ArrayBuffer>[];
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type RelayerKeysItem = {
|
|
2
|
+
data_id: string;
|
|
3
|
+
param_choice: number;
|
|
4
|
+
urls: string[];
|
|
5
|
+
signatures: string[];
|
|
6
|
+
};
|
|
7
|
+
export type RelayerKey = {
|
|
8
|
+
data_id: string;
|
|
9
|
+
param_choice: number;
|
|
10
|
+
signatures: string[];
|
|
11
|
+
urls: string[];
|
|
12
|
+
};
|
|
13
|
+
export type RelayerKeys = {
|
|
14
|
+
response: {
|
|
15
|
+
fhe_key_info: {
|
|
16
|
+
fhe_public_key: RelayerKey;
|
|
17
|
+
fhe_server_key: RelayerKey;
|
|
18
|
+
}[];
|
|
19
|
+
verf_public_key: {
|
|
20
|
+
key_id: string;
|
|
21
|
+
server_id: number;
|
|
22
|
+
verf_public_key_address: string;
|
|
23
|
+
verf_public_key_url: string;
|
|
24
|
+
}[];
|
|
25
|
+
crs: {
|
|
26
|
+
[key: string]: RelayerKeysItem;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
status: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const getKeysFromRelayer: (url: string, publicKeyId?: string | null) => Promise<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { DecryptedResults } from './decryptUtils';
|
|
3
|
+
export declare const publicDecryptRequest: (kmsSigners: string[], thresholdSigners: number, gatewayChainId: number, verifyingContractAddress: string, aclContractAddress: string, relayerUrl: string, provider: ethers.JsonRpcProvider | ethers.BrowserProvider) => (_handles: (Uint8Array | string)[]) => Promise<DecryptedResults>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TfheCompactPublicKey, CompactPkeCrs } from 'node-tfhe';
|
|
2
|
+
import { EncryptedInput } from '../sdk/encrypt';
|
|
3
|
+
import { ENCRYPTION_TYPES } from '../sdk/encryptionTypes';
|
|
4
|
+
type EncryptionTypes = keyof typeof ENCRYPTION_TYPES;
|
|
5
|
+
export declare const currentCiphertextVersion: () => number;
|
|
6
|
+
export type FhevmRelayerInputProofResponse = {
|
|
7
|
+
response: {
|
|
8
|
+
handles: string[];
|
|
9
|
+
signatures: string[];
|
|
10
|
+
};
|
|
11
|
+
status: string;
|
|
12
|
+
};
|
|
13
|
+
export type RelayerEncryptedInputInternal = RelayerEncryptedInput & {
|
|
14
|
+
_input: EncryptedInput;
|
|
15
|
+
};
|
|
16
|
+
export type RelayerEncryptedInput = {
|
|
17
|
+
addBool: (value: boolean | number | bigint) => RelayerEncryptedInput;
|
|
18
|
+
add8: (value: number | bigint) => RelayerEncryptedInput;
|
|
19
|
+
add16: (value: number | bigint) => RelayerEncryptedInput;
|
|
20
|
+
add32: (value: number | bigint) => RelayerEncryptedInput;
|
|
21
|
+
add64: (value: number | bigint) => RelayerEncryptedInput;
|
|
22
|
+
add128: (value: number | bigint) => RelayerEncryptedInput;
|
|
23
|
+
add256: (value: number | bigint) => RelayerEncryptedInput;
|
|
24
|
+
addBytes64: (value: Uint8Array) => RelayerEncryptedInput;
|
|
25
|
+
addBytes128: (value: Uint8Array) => RelayerEncryptedInput;
|
|
26
|
+
addBytes256: (value: Uint8Array) => RelayerEncryptedInput;
|
|
27
|
+
addAddress: (value: string) => RelayerEncryptedInput;
|
|
28
|
+
getBits: () => EncryptionTypes[];
|
|
29
|
+
encrypt: () => Promise<{
|
|
30
|
+
handles: Uint8Array[];
|
|
31
|
+
inputProof: Uint8Array;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
export type PublicParams<T = CompactPkeCrs> = {
|
|
35
|
+
[key in EncryptionTypes]?: {
|
|
36
|
+
publicParams: T;
|
|
37
|
+
publicParamsId: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare const createRelayerEncryptedInput: (aclContractAddress: string, verifyingContractAddressInputVerification: string, chainId: number, gatewayChainId: number, relayerUrl: string, tfheCompactPublicKey: TfheCompactPublicKey, publicParams: PublicParams, coprocessorSigners: string[], thresholdCoprocessorSigners: number) => (contractAddress: string, userAddress: string) => RelayerEncryptedInputInternal;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { DecryptedResults } from './decryptUtils';
|
|
3
|
+
export type HandleContractPair = {
|
|
4
|
+
handle: Uint8Array | string;
|
|
5
|
+
contractAddress: string;
|
|
6
|
+
};
|
|
7
|
+
export type HandleContractPairRelayer = {
|
|
8
|
+
handle: string;
|
|
9
|
+
contractAddress: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const userDecryptRequest: (kmsSigners: string[], gatewayChainId: number, chainId: number, verifyingContractAddress: string, aclContractAddress: string, relayerUrl: string, provider: ethers.JsonRpcProvider | ethers.BrowserProvider) => (_handles: HandleContractPair[], privateKey: string, publicKey: string, signature: string, contractAddresses: string[], userAddress: string, startTimestamp: string | number, durationDays: string | number) => Promise<DecryptedResults>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TfheCompactPublicKey, CompactPkeCrs } from 'node-tfhe';
|
|
2
|
+
import { ENCRYPTION_TYPES } from './encryptionTypes';
|
|
3
|
+
type EncryptionTypes = keyof typeof ENCRYPTION_TYPES;
|
|
4
|
+
export type EncryptedInput = {
|
|
5
|
+
addBool: (value: boolean | number | bigint) => EncryptedInput;
|
|
6
|
+
add8: (value: number | bigint) => EncryptedInput;
|
|
7
|
+
add16: (value: number | bigint) => EncryptedInput;
|
|
8
|
+
add32: (value: number | bigint) => EncryptedInput;
|
|
9
|
+
add64: (value: number | bigint) => EncryptedInput;
|
|
10
|
+
add128: (value: number | bigint) => EncryptedInput;
|
|
11
|
+
add256: (value: number | bigint) => EncryptedInput;
|
|
12
|
+
addBytes64: (value: Uint8Array) => EncryptedInput;
|
|
13
|
+
addBytes128: (value: Uint8Array) => EncryptedInput;
|
|
14
|
+
addBytes256: (value: Uint8Array) => EncryptedInput;
|
|
15
|
+
addAddress: (value: string) => EncryptedInput;
|
|
16
|
+
getBits: () => EncryptionTypes[];
|
|
17
|
+
encrypt: () => Uint8Array;
|
|
18
|
+
};
|
|
19
|
+
export type PublicParams<T = CompactPkeCrs> = {
|
|
20
|
+
[key in EncryptionTypes]?: {
|
|
21
|
+
publicParams: T;
|
|
22
|
+
publicParamsId: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type EncryptInputParams = {
|
|
26
|
+
aclContractAddress: string;
|
|
27
|
+
chainId: number;
|
|
28
|
+
tfheCompactPublicKey: TfheCompactPublicKey;
|
|
29
|
+
publicParams: PublicParams;
|
|
30
|
+
contractAddress: string;
|
|
31
|
+
userAddress: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const createEncryptedInput: ({ aclContractAddress, chainId, tfheCompactPublicKey, publicParams, contractAddress, userAddress, }: EncryptInputParams) => EncryptedInput;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type EIP712Type = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
};
|
|
5
|
+
export type EIP712 = {
|
|
6
|
+
domain: {
|
|
7
|
+
chainId: number;
|
|
8
|
+
name: string;
|
|
9
|
+
verifyingContract: string;
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
message: any;
|
|
13
|
+
primaryType: string;
|
|
14
|
+
types: {
|
|
15
|
+
[key: string]: EIP712Type[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates an EIP712 structure specifically for user decrypt requests
|
|
20
|
+
*
|
|
21
|
+
* @param gatewayChainId The chain ID of the gateway
|
|
22
|
+
* @param verifyingContract The address of the contract that will verify the signature
|
|
23
|
+
* @param publicKey The user's public key as a hex string or Uint8Array
|
|
24
|
+
* @param contractAddresses Array of contract addresses that can access the decryption
|
|
25
|
+
* @param contractsChainId The chain ID where the contracts are deployed
|
|
26
|
+
* @param startTimestamp The timestamp when the decryption permission becomes valid
|
|
27
|
+
* @param durationDays How many days the decryption permission remains valid
|
|
28
|
+
* @returns EIP712 typed data structure for user decryption
|
|
29
|
+
*/
|
|
30
|
+
export declare const createEIP712: (gatewayChainId: number, verifyingContract: string, contractsChainId: number) => (publicKey: string | Uint8Array, contractAddresses: string[], startTimestamp: string | number, durationDays: string | number, delegatedAccount?: string) => EIP712;
|
|
31
|
+
export declare const generateKeypair: () => {
|
|
32
|
+
publicKey: string;
|
|
33
|
+
privateKey: string;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CompactPkeCrs, TfheClientKey, TfheCompactPublicKey } from 'node-tfhe';
|
|
2
|
+
export declare const publicKeyId = "408d8cbaa51dece7f782fe04ba0b1c1d017b1088";
|
|
3
|
+
export declare const privateKey: TfheClientKey;
|
|
4
|
+
export declare const publicKey: TfheCompactPublicKey;
|
|
5
|
+
export declare const publicParams: {
|
|
6
|
+
2048: {
|
|
7
|
+
publicParams: CompactPkeCrs;
|
|
8
|
+
publicParamsId: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
package/lib/tfhe.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TfheCompactPublicKey, TfheClientKey, CompactPkeCrs } from 'node-tfhe';
|
|
2
|
+
export declare const createTfheKeypair: () => {
|
|
3
|
+
clientKey: TfheClientKey;
|
|
4
|
+
publicKey: TfheCompactPublicKey;
|
|
5
|
+
crs: CompactPkeCrs;
|
|
6
|
+
};
|
|
7
|
+
export declare const createTfhePublicKey: () => string;
|
package/lib/tfhe_bg.wasm
ADDED
|
Binary file
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SERIALIZED_SIZE_LIMIT_CIPHERTEXT: bigint;
|
|
2
|
+
export declare const SERIALIZED_SIZE_LIMIT_PK: bigint;
|
|
3
|
+
export declare const SERIALIZED_SIZE_LIMIT_CRS: bigint;
|
|
4
|
+
export declare const cleanURL: (url: string | undefined) => string;
|
|
5
|
+
export declare const numberToHex: (num: number) => string;
|
|
6
|
+
export declare const fromHexString: (hexString: string) => Uint8Array;
|
|
7
|
+
export declare const toHexString: (bytes: Uint8Array, with0x?: boolean) => string;
|
|
8
|
+
export declare const bytesToHex: (byteArray: Uint8Array) => string;
|
|
9
|
+
export declare const bytesToBigInt: (byteArray: Uint8Array) => bigint;
|
package/lib/web.d.ts
ADDED