@inco/js 0.6.8 → 0.7.0
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/README.md +8 -8
- package/dist/cjs/advancedacl/session-key.d.ts +39 -19
- package/dist/cjs/advancedacl/session-key.js +59 -108
- package/dist/cjs/attestedcompute/attested-compute.d.ts +6 -6
- package/dist/cjs/attestedcompute/attested-compute.js +5 -28
- package/dist/cjs/attesteddecrypt/attested-decrypt.d.ts +68 -16
- package/dist/cjs/attesteddecrypt/attested-decrypt.js +108 -66
- package/dist/cjs/attesteddecrypt/types.d.ts +8 -3
- package/dist/cjs/attesteddecrypt/types.js +1 -1
- package/dist/cjs/encryption/encryption.d.ts +8 -10
- package/dist/cjs/encryption/encryption.js +6 -6
- package/dist/cjs/generated/abis/add-two.d.ts +1 -1
- package/dist/cjs/generated/abis/add-two.js +1 -1
- package/dist/cjs/generated/abis/lightning-preview.d.ts +40 -0
- package/dist/cjs/generated/abis/lightning-preview.js +29 -1
- package/dist/cjs/generated/abis/lightning.d.ts +1 -1
- package/dist/cjs/generated/abis/lightning.js +1 -1
- package/dist/cjs/generated/abis/verifier.d.ts +126 -67
- package/dist/cjs/generated/abis/verifier.js +108 -54
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +15 -1
- package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.js +1 -1
- package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +87 -132
- package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.js +21 -27
- package/dist/cjs/generated/lightning.d.ts +40 -32
- package/dist/cjs/generated/lightning.js +43 -33
- package/dist/cjs/generated/local-node.d.ts +11 -11
- package/dist/cjs/generated/local-node.js +28 -12
- package/dist/cjs/kms/client.d.ts +8 -4
- package/dist/cjs/kms/client.js +9 -4
- package/dist/cjs/kms/quorumClient.d.ts +58 -0
- package/dist/cjs/kms/quorumClient.js +378 -0
- package/dist/cjs/kms/thresholdPromises.d.ts +7 -0
- package/dist/cjs/kms/thresholdPromises.js +52 -0
- package/dist/cjs/lite/deployments.d.ts +20 -2
- package/dist/cjs/lite/deployments.js +1 -1
- package/dist/cjs/lite/index.d.ts +1 -2
- package/dist/cjs/lite/index.js +1 -2
- package/dist/cjs/lite/lightning.d.ts +109 -77
- package/dist/cjs/lite/lightning.js +279 -112
- package/dist/cjs/local/local-node.d.ts +1 -2
- package/dist/cjs/local/local-node.js +2 -3
- package/dist/cjs/test/mocks.d.ts +15 -0
- package/dist/cjs/test/mocks.js +45 -0
- package/dist/cjs/viem.d.ts +1 -1
- package/dist/esm/advancedacl/session-key.d.ts +39 -19
- package/dist/esm/advancedacl/session-key.js +52 -100
- package/dist/esm/attestedcompute/attested-compute.d.ts +6 -6
- package/dist/esm/attestedcompute/attested-compute.js +6 -29
- package/dist/esm/attesteddecrypt/attested-decrypt.d.ts +68 -16
- package/dist/esm/attesteddecrypt/attested-decrypt.js +109 -68
- package/dist/esm/attesteddecrypt/types.d.ts +8 -3
- package/dist/esm/attesteddecrypt/types.js +1 -1
- package/dist/esm/encryption/encryption.d.ts +8 -10
- package/dist/esm/encryption/encryption.js +6 -6
- package/dist/esm/generated/abis/add-two.d.ts +1 -1
- package/dist/esm/generated/abis/add-two.js +1 -1
- package/dist/esm/generated/abis/lightning-preview.d.ts +40 -0
- package/dist/esm/generated/abis/lightning-preview.js +29 -1
- package/dist/esm/generated/abis/lightning.d.ts +1 -1
- package/dist/esm/generated/abis/lightning.js +1 -1
- package/dist/esm/generated/abis/verifier.d.ts +126 -67
- package/dist/esm/generated/abis/verifier.js +108 -54
- package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +15 -1
- package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.js +1 -1
- package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +87 -132
- package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.js +19 -25
- package/dist/esm/generated/lightning.d.ts +40 -32
- package/dist/esm/generated/lightning.js +43 -33
- package/dist/esm/generated/local-node.d.ts +11 -11
- package/dist/esm/generated/local-node.js +28 -12
- package/dist/esm/kms/client.d.ts +8 -4
- package/dist/esm/kms/client.js +8 -4
- package/dist/esm/kms/quorumClient.d.ts +58 -0
- package/dist/esm/kms/quorumClient.js +374 -0
- package/dist/esm/kms/thresholdPromises.d.ts +7 -0
- package/dist/esm/kms/thresholdPromises.js +49 -0
- package/dist/esm/lite/deployments.d.ts +20 -2
- package/dist/esm/lite/deployments.js +1 -1
- package/dist/esm/lite/index.d.ts +1 -2
- package/dist/esm/lite/index.js +1 -2
- package/dist/esm/lite/lightning.d.ts +109 -77
- package/dist/esm/lite/lightning.js +278 -111
- package/dist/esm/local/local-node.d.ts +1 -2
- package/dist/esm/local/local-node.js +2 -3
- package/dist/esm/test/mocks.d.ts +15 -0
- package/dist/esm/test/mocks.js +39 -0
- package/dist/esm/viem.d.ts +1 -1
- package/dist/types/advancedacl/session-key.d.ts +39 -19
- package/dist/types/attestedcompute/attested-compute.d.ts +6 -6
- package/dist/types/attesteddecrypt/attested-decrypt.d.ts +68 -16
- package/dist/types/attesteddecrypt/types.d.ts +8 -3
- package/dist/types/encryption/encryption.d.ts +8 -10
- package/dist/types/generated/abis/add-two.d.ts +1 -1
- package/dist/types/generated/abis/lightning-preview.d.ts +40 -0
- package/dist/types/generated/abis/lightning.d.ts +1 -1
- package/dist/types/generated/abis/verifier.d.ts +126 -67
- package/dist/types/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +15 -1
- package/dist/types/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +87 -132
- package/dist/types/generated/lightning.d.ts +40 -32
- package/dist/types/generated/local-node.d.ts +11 -11
- package/dist/types/kms/client.d.ts +8 -4
- package/dist/types/kms/quorumClient.d.ts +58 -0
- package/dist/types/kms/thresholdPromises.d.ts +7 -0
- package/dist/types/lite/deployments.d.ts +20 -2
- package/dist/types/lite/index.d.ts +1 -2
- package/dist/types/lite/lightning.d.ts +109 -77
- package/dist/types/local/local-node.d.ts +1 -2
- package/dist/types/test/mocks.d.ts +15 -0
- package/dist/types/viem.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/attestedreveal/attested-reveal.d.ts +0 -21
- package/dist/cjs/attestedreveal/attested-reveal.js +0 -67
- package/dist/cjs/attestedreveal/index.d.ts +0 -1
- package/dist/cjs/attestedreveal/index.js +0 -18
- package/dist/cjs/attestedreveal/types.d.ts +0 -7
- package/dist/cjs/attestedreveal/types.js +0 -16
- package/dist/cjs/generated/es/cosmos_proto/cosmos_pb.d.ts +0 -174
- package/dist/cjs/generated/es/cosmos_proto/cosmos_pb.js +0 -118
- package/dist/cjs/generated/es/inco/fhe/v1/types_pb.d.ts +0 -419
- package/dist/cjs/generated/es/inco/fhe/v1/types_pb.js +0 -136
- package/dist/cjs/lite/reencrypt.d.ts +0 -23
- package/dist/cjs/lite/reencrypt.js +0 -131
- package/dist/esm/attestedreveal/attested-reveal.d.ts +0 -21
- package/dist/esm/attestedreveal/attested-reveal.js +0 -64
- package/dist/esm/attestedreveal/index.d.ts +0 -1
- package/dist/esm/attestedreveal/index.js +0 -2
- package/dist/esm/attestedreveal/types.d.ts +0 -7
- package/dist/esm/attestedreveal/types.js +0 -12
- package/dist/esm/generated/es/cosmos_proto/cosmos_pb.d.ts +0 -174
- package/dist/esm/generated/es/cosmos_proto/cosmos_pb.js +0 -115
- package/dist/esm/generated/es/inco/fhe/v1/types_pb.d.ts +0 -419
- package/dist/esm/generated/es/inco/fhe/v1/types_pb.js +0 -133
- package/dist/esm/lite/reencrypt.d.ts +0 -23
- package/dist/esm/lite/reencrypt.js +0 -122
- package/dist/types/attestedreveal/attested-reveal.d.ts +0 -21
- package/dist/types/attestedreveal/index.d.ts +0 -1
- package/dist/types/attestedreveal/types.d.ts +0 -7
- package/dist/types/generated/es/cosmos_proto/cosmos_pb.d.ts +0 -174
- package/dist/types/generated/es/inco/fhe/v1/types_pb.d.ts +0 -419
- package/dist/types/lite/reencrypt.d.ts +0 -23
|
@@ -1,29 +1,72 @@
|
|
|
1
1
|
import type { Account, Chain, Transport, WalletClient } from 'viem';
|
|
2
|
-
import { HexString } from '../binary.js';
|
|
3
|
-
import { SupportedChainId } from '../chain.js';
|
|
4
|
-
import { EciesScheme, SupportedFheType } from '../encryption/encryption.js';
|
|
5
|
-
import
|
|
2
|
+
import { type HexString } from '../binary.js';
|
|
3
|
+
import { type SupportedChainId } from '../chain.js';
|
|
4
|
+
import { type EciesScheme, type SupportedFheType } from '../encryption/encryption.js';
|
|
5
|
+
import { KmsQuorumClient } from '../kms/quorumClient.js';
|
|
6
|
+
import type { Secp256k1Keypair } from '../lite/ecies.js';
|
|
6
7
|
import type { BackoffConfig } from '../retry.js';
|
|
7
|
-
import { DecryptionAttestation } from './types.js';
|
|
8
|
+
import { type DecryptionAttestation, type EncryptedDecryptionAttestation } from './types.js';
|
|
8
9
|
export declare const ATTESTED_DECRYPT_DOMAIN_NAME = "IncoAttestedDecrypt";
|
|
9
|
-
export declare const ATTESTED_DECRYPT_DOMAIN_VERSION = "
|
|
10
|
-
/**
|
|
11
|
-
* Validates a handle format.
|
|
12
|
-
* @param handle - The handle to validate
|
|
13
|
-
* @throws {AttestedDecryptError} If the handle format is invalid
|
|
14
|
-
*/
|
|
15
|
-
export declare function validateHandle(handle: HexString): void;
|
|
10
|
+
export declare const ATTESTED_DECRYPT_DOMAIN_VERSION = "1";
|
|
16
11
|
/**
|
|
17
12
|
* Arguments for creating an attested decrypt request.
|
|
18
13
|
*/
|
|
19
14
|
export interface IncoLiteAttestedDecryptorArgs {
|
|
20
15
|
/** The wallet used to interact with the blockchain and sign the decrypt request */
|
|
21
16
|
walletClient: WalletClient<Transport, Chain, Account>;
|
|
22
|
-
/** The KMS
|
|
23
|
-
|
|
17
|
+
/** The KMS quorum client instance */
|
|
18
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
24
19
|
/** The chain ID to use */
|
|
25
20
|
chainId: SupportedChainId;
|
|
26
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Decrypt multiple handles in a single attested request without wallet authentication.
|
|
24
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
25
|
+
*
|
|
26
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
27
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
28
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
29
|
+
*/
|
|
30
|
+
export declare function attestedDecrypt({ handles, backoffConfig, chainId, kmsQuorumClient, }: {
|
|
31
|
+
handles: HexString[];
|
|
32
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
33
|
+
chainId: SupportedChainId;
|
|
34
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
35
|
+
}): Promise<Array<DecryptionAttestation<EciesScheme, SupportedFheType>>>;
|
|
36
|
+
/**
|
|
37
|
+
* Decrypt multiple handles in a single attested request.
|
|
38
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
39
|
+
*
|
|
40
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
41
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
42
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
43
|
+
*/
|
|
44
|
+
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, }: {
|
|
45
|
+
handles: HexString[];
|
|
46
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
47
|
+
walletClient: WalletClient<Transport, Chain, Account>;
|
|
48
|
+
chainId: SupportedChainId;
|
|
49
|
+
reencryptPubKey: Uint8Array;
|
|
50
|
+
reencryptKeypair: Secp256k1Keypair;
|
|
51
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
52
|
+
}): Promise<Array<DecryptionAttestation<EciesScheme, SupportedFheType>>>;
|
|
53
|
+
/**
|
|
54
|
+
* Decrypt multiple handles in a single attested request.
|
|
55
|
+
* Returns an array of attestations aligned with the response ordering.
|
|
56
|
+
*
|
|
57
|
+
* @param args - The arguments for creating the attested decrypt function
|
|
58
|
+
* @returns A function that can decrypt handles and return an attestation
|
|
59
|
+
* @throws {AttestedDecryptError} If the creation fails
|
|
60
|
+
*/
|
|
61
|
+
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, kmsQuorumClient, }: {
|
|
62
|
+
handles: HexString[];
|
|
63
|
+
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
64
|
+
walletClient: WalletClient<Transport, Chain, Account>;
|
|
65
|
+
chainId: SupportedChainId;
|
|
66
|
+
reencryptPubKey: Uint8Array;
|
|
67
|
+
reencryptKeypair?: never;
|
|
68
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
69
|
+
}): Promise<Array<EncryptedDecryptionAttestation<EciesScheme, SupportedFheType>>>;
|
|
27
70
|
/**
|
|
28
71
|
* Decrypt multiple handles in a single attested request.
|
|
29
72
|
* Returns an array of attestations aligned with the response ordering.
|
|
@@ -32,10 +75,19 @@ export interface IncoLiteAttestedDecryptorArgs {
|
|
|
32
75
|
* @returns A function that can decrypt handles and return an attestation
|
|
33
76
|
* @throws {AttestedDecryptError} If the creation fails
|
|
34
77
|
*/
|
|
35
|
-
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId,
|
|
78
|
+
export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, kmsQuorumClient, }: {
|
|
36
79
|
handles: HexString[];
|
|
37
80
|
backoffConfig?: Partial<BackoffConfig> | undefined;
|
|
38
81
|
walletClient: WalletClient<Transport, Chain, Account>;
|
|
39
82
|
chainId: SupportedChainId;
|
|
40
|
-
|
|
83
|
+
reencryptPubKey?: never;
|
|
84
|
+
reencryptKeypair?: never;
|
|
85
|
+
kmsQuorumClient: KmsQuorumClient;
|
|
41
86
|
}): Promise<Array<DecryptionAttestation<EciesScheme, SupportedFheType>>>;
|
|
87
|
+
export declare function decryptEncryptedAttestations(attestations: Array<DecryptionAttestation<EciesScheme, SupportedFheType> | EncryptedDecryptionAttestation<EciesScheme, SupportedFheType>>, reencryptKeypair: Secp256k1Keypair): Promise<Array<DecryptionAttestation<EciesScheme, SupportedFheType>>>;
|
|
88
|
+
/**
|
|
89
|
+
* Validates a handle format.
|
|
90
|
+
* @param handle - The handle to validate
|
|
91
|
+
* @throws {AttestedDecryptError} If the handle format is invalid
|
|
92
|
+
*/
|
|
93
|
+
export declare function validateHandle(handle: HexString): void;
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import { create } from '@bufbuild/protobuf';
|
|
2
|
-
import { hexToBytes } from 'viem';
|
|
2
|
+
import { bytesToHex, hexToBytes } from 'viem';
|
|
3
3
|
import { bytesToBigInt } from '../binary.js';
|
|
4
|
-
import { getSupportedChain } from '../chain.js';
|
|
5
4
|
import { bigintToPlaintext, encryptionSchemes, } from '../encryption/encryption.js';
|
|
6
|
-
import { AttestedDecryptRequestSchema, } from '../generated/es/inco/kms/lite/v1/kms_service_pb.js';
|
|
5
|
+
import { AttestedDecryptRequestSchema, AttestedRevealRequestSchema, } from '../generated/es/inco/kms/lite/v1/kms_service_pb.js';
|
|
7
6
|
import { HandleWithProofSchema, } from '../generated/es/inco/kms/lite/v1/types_pb.js';
|
|
8
7
|
import { getHandleType } from '../handle.js';
|
|
9
|
-
import {
|
|
8
|
+
import { decrypt } from '../lite/ecies.js';
|
|
10
9
|
import { createEIP712Payload } from '../reencryption/eip712.js';
|
|
11
|
-
import {
|
|
12
|
-
import { AttestedDecryptError } from './types.js';
|
|
10
|
+
import { AttestedDecryptError, } from './types.js';
|
|
13
11
|
export const ATTESTED_DECRYPT_DOMAIN_NAME = 'IncoAttestedDecrypt';
|
|
14
|
-
export const ATTESTED_DECRYPT_DOMAIN_VERSION = '
|
|
15
|
-
/**
|
|
16
|
-
* Validates a handle format.
|
|
17
|
-
* @param handle - The handle to validate
|
|
18
|
-
* @throws {AttestedDecryptError} If the handle format is invalid
|
|
19
|
-
*/
|
|
20
|
-
export function validateHandle(handle) {
|
|
21
|
-
if (!handle.startsWith('0x') || handle.length !== 2 + 2 * 32) {
|
|
22
|
-
throw new AttestedDecryptError('Invalid handle format: must be a 32-byte hex string with 0x prefix');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
12
|
+
export const ATTESTED_DECRYPT_DOMAIN_VERSION = '1';
|
|
25
13
|
/**
|
|
26
14
|
* Decrypt multiple handles in a single attested request.
|
|
27
15
|
* Returns an array of attestations aligned with the response ordering.
|
|
@@ -30,61 +18,39 @@ export function validateHandle(handle) {
|
|
|
30
18
|
* @returns A function that can decrypt handles and return an attestation
|
|
31
19
|
* @throws {AttestedDecryptError} If the creation fails
|
|
32
20
|
*/
|
|
33
|
-
export async function attestedDecrypt({ handles, backoffConfig, walletClient, chainId,
|
|
21
|
+
export async function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, }) {
|
|
34
22
|
try {
|
|
35
23
|
handles.forEach(validateHandle);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
chainId: BigInt(chainId),
|
|
41
|
-
primaryType: 'AttestedDecryptRequest',
|
|
42
|
-
primaryTypeFields: [{ name: 'handles', type: 'bytes32[]' }],
|
|
43
|
-
message: {
|
|
44
|
-
handles: handles,
|
|
45
|
-
},
|
|
46
|
-
domainName: ATTESTED_DECRYPT_DOMAIN_NAME,
|
|
47
|
-
domainVersion: ATTESTED_DECRYPT_DOMAIN_VERSION,
|
|
24
|
+
const eip712Payload = buildEip712Payload({
|
|
25
|
+
chainId,
|
|
26
|
+
handles,
|
|
27
|
+
...(reencryptPubKey !== undefined ? { reencryptPubKey } : {}),
|
|
48
28
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
},
|
|
29
|
+
let response;
|
|
30
|
+
if (walletClient) {
|
|
31
|
+
const eip712SignatureHex = await signEip712(walletClient, eip712Payload);
|
|
32
|
+
const handlesWithProofs = buildHandlesWithProofs(handles);
|
|
33
|
+
const attestedDecryptRequest = buildAttestedDecryptRequest({
|
|
34
|
+
userAddress: walletClient.account.address,
|
|
35
|
+
handlesWithProofs,
|
|
36
|
+
eip712Signature: hexToBytes(eip712SignatureHex),
|
|
37
|
+
...(reencryptPubKey !== undefined ? { reencryptPubKey } : {}),
|
|
60
38
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const response = await retryWithBackoff(async () => {
|
|
68
|
-
return await kmsClient.attestedDecrypt(attestedDecryptRequest);
|
|
69
|
-
}, backoffConfig);
|
|
70
|
-
if (!response.decryptionAttestations ||
|
|
71
|
-
response.decryptionAttestations.length === 0) {
|
|
72
|
-
throw new AttestedDecryptError('No decryption attestations in response');
|
|
73
|
-
}
|
|
74
|
-
const results = response.decryptionAttestations.map((att) => {
|
|
75
|
-
if (att.plaintext === undefined) {
|
|
76
|
-
throw new AttestedDecryptError('No plaintext in attestation');
|
|
39
|
+
// Call quorum client which returns aggregated attestations directly
|
|
40
|
+
// The quorum client handles retry logic internally for each KMS client
|
|
41
|
+
response = await kmsQuorumClient.attestedDecrypt(attestedDecryptRequest, backoffConfig);
|
|
42
|
+
// If reencryptPubKey is provided with a keypair, decrypt the encrypted attestations
|
|
43
|
+
if (reencryptPubKey !== undefined && reencryptKeypair) {
|
|
44
|
+
response = await decryptEncryptedAttestations(response, reencryptKeypair);
|
|
77
45
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
return results;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const attestedRevealRequest = create(AttestedRevealRequestSchema, {
|
|
49
|
+
handles: handles,
|
|
50
|
+
});
|
|
51
|
+
response = await kmsQuorumClient.attestedReveal(attestedRevealRequest, backoffConfig);
|
|
52
|
+
}
|
|
53
|
+
return response;
|
|
88
54
|
}
|
|
89
55
|
catch (error) {
|
|
90
56
|
if (error instanceof AttestedDecryptError) {
|
|
@@ -93,4 +59,79 @@ export async function attestedDecrypt({ handles, backoffConfig, walletClient, ch
|
|
|
93
59
|
throw new AttestedDecryptError('Failed to decrypt handles', error);
|
|
94
60
|
}
|
|
95
61
|
}
|
|
96
|
-
|
|
62
|
+
// Small helpers to make the main flow readable
|
|
63
|
+
function buildEip712Payload(params) {
|
|
64
|
+
return createEIP712Payload({
|
|
65
|
+
chainId: BigInt(params.chainId),
|
|
66
|
+
primaryType: 'AttestedDecryptRequest',
|
|
67
|
+
primaryTypeFields: [
|
|
68
|
+
{ name: 'handles', type: 'bytes32[]' },
|
|
69
|
+
{ name: 'publicKey', type: 'bytes' },
|
|
70
|
+
],
|
|
71
|
+
message: {
|
|
72
|
+
handles: params.handles,
|
|
73
|
+
publicKey: bytesToHex(params.reencryptPubKey ? params.reencryptPubKey : new Uint8Array()),
|
|
74
|
+
},
|
|
75
|
+
domainName: ATTESTED_DECRYPT_DOMAIN_NAME,
|
|
76
|
+
domainVersion: ATTESTED_DECRYPT_DOMAIN_VERSION,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function signEip712(walletClient, eip712Payload) {
|
|
80
|
+
return await walletClient.signTypedData(eip712Payload);
|
|
81
|
+
}
|
|
82
|
+
function buildHandlesWithProofs(handles) {
|
|
83
|
+
return handles.map((handle) => {
|
|
84
|
+
return create(HandleWithProofSchema, {
|
|
85
|
+
handle: handle,
|
|
86
|
+
aclProof: {
|
|
87
|
+
proof: {
|
|
88
|
+
case: 'incoLiteBasicAclProof',
|
|
89
|
+
value: {},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function buildAttestedDecryptRequest(params) {
|
|
96
|
+
return create(AttestedDecryptRequestSchema, {
|
|
97
|
+
userAddress: params.userAddress,
|
|
98
|
+
handlesWithProofs: params.handlesWithProofs,
|
|
99
|
+
eip712Signature: params.eip712Signature,
|
|
100
|
+
reencryptPubKey: params.reencryptPubKey
|
|
101
|
+
? params.reencryptPubKey
|
|
102
|
+
: new Uint8Array(),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export async function decryptEncryptedAttestations(attestations, reencryptKeypair) {
|
|
106
|
+
return Promise.all(attestations.map(async (att) => {
|
|
107
|
+
// If already a plaintext attestation, return as-is
|
|
108
|
+
if ('plaintext' in att && att.plaintext !== undefined) {
|
|
109
|
+
return att;
|
|
110
|
+
}
|
|
111
|
+
// Otherwise, decrypt the encrypted attestation
|
|
112
|
+
if ('encryptedPlaintext' in att && att.encryptedPlaintext !== undefined) {
|
|
113
|
+
const encryptedAtt = att;
|
|
114
|
+
const ct = hexToBytes(encryptedAtt.encryptedPlaintext.ciphertext.value);
|
|
115
|
+
const plaintextBytes = await decrypt(reencryptKeypair, ct);
|
|
116
|
+
const bigIntValue = bytesToBigInt(plaintextBytes);
|
|
117
|
+
const handleType = getHandleType(encryptedAtt.handle);
|
|
118
|
+
return {
|
|
119
|
+
handle: encryptedAtt.handle,
|
|
120
|
+
plaintext: bigintToPlaintext(encryptionSchemes.ecies, handleType, bigIntValue),
|
|
121
|
+
covalidatorSignatures: encryptedAtt.covalidatorSignatures,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
throw new AttestedDecryptError('Attestation is neither plaintext nor encrypted');
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Validates a handle format.
|
|
129
|
+
* @param handle - The handle to validate
|
|
130
|
+
* @throws {AttestedDecryptError} If the handle format is invalid
|
|
131
|
+
*/
|
|
132
|
+
export function validateHandle(handle) {
|
|
133
|
+
if (!handle.startsWith('0x') || handle.length !== 2 + 2 * 32) {
|
|
134
|
+
throw new AttestedDecryptError('Invalid handle format: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IsU0FBUyxFQUFFLGlCQUFpQixDQUMxQixpQkFBaUIsQ0FBQyxLQUFLLEVBQ3ZCLFVBQThCLEVBQzlCLFdBQVcsQ0FDWjtnQkFDRCxxQkFBcUIsRUFBRSxZQUFZLENBQUMscUJBQXFCO2FBQ0YsQ0FBQztRQUM1RCxDQUFDO1FBRUQsTUFBTSxJQUFJLG9CQUFvQixDQUM1QixnREFBZ0QsQ0FDakQsQ0FBQztJQUNKLENBQUMsQ0FBQyxDQUNILENBQUM7QUFDSixDQUFDO0FBRUQ7Ozs7R0FJRztBQUNILE1BQU0sVUFBVSxjQUFjLENBQUMsTUFBaUI7SUFDOUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLElBQUksTUFBTSxDQUFDLE1BQU0sS0FBSyxDQUFDLEdBQUcsQ0FBQyxHQUFHLEVBQUUsRUFBRSxDQUFDO1FBQzdELE1BQU0sSUFBSSxvQkFBb0IsQ0FDNUIsb0VBQW9FLENBQ3JFLENBQUM7SUFDSixDQUFDO0FBQ0gsQ0FBQyJ9
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HexString } from '../binary.js';
|
|
2
|
-
import { EncryptionScheme, PlaintextOf, SupportedFheType } from '../encryption/encryption.js';
|
|
1
|
+
import type { HexString } from '../binary.js';
|
|
2
|
+
import type { EncryptionScheme, EncryptResultOf, PlaintextOf, SupportedFheType } from '../encryption/encryption.js';
|
|
3
3
|
import type { BackoffConfig } from '../retry.js';
|
|
4
4
|
/**
|
|
5
5
|
* Custom error class for attested decrypt operations.
|
|
@@ -11,7 +11,12 @@ export declare class AttestedDecryptError extends Error {
|
|
|
11
11
|
export type DecryptionAttestation<S extends EncryptionScheme, T extends SupportedFheType> = {
|
|
12
12
|
handle: HexString;
|
|
13
13
|
plaintext: PlaintextOf<S, T>;
|
|
14
|
-
|
|
14
|
+
covalidatorSignatures: Uint8Array[];
|
|
15
|
+
};
|
|
16
|
+
export type EncryptedDecryptionAttestation<S extends EncryptionScheme, T extends SupportedFheType> = {
|
|
17
|
+
handle: HexString;
|
|
18
|
+
encryptedPlaintext: EncryptResultOf<S, T>;
|
|
19
|
+
covalidatorSignatures: Uint8Array[];
|
|
15
20
|
};
|
|
16
21
|
export type AttestedDecryptor<S extends EncryptionScheme> = <T extends SupportedFheType>(args: AttestedDecryptFnArgs<S, T>) => Promise<DecryptionAttestation<S, T>>;
|
|
17
22
|
export type AttestedDecryptFnArgs<S extends EncryptionScheme, T extends SupportedFheType> = {
|
|
@@ -9,4 +9,4 @@ export class AttestedDecryptError extends Error {
|
|
|
9
9
|
this.name = 'AttestedDecryptError';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRkZWNyeXB0L3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNBOztHQUVHO0FBQ0gsTUFBTSxPQUFPLG9CQUFxQixTQUFRLEtBQUs7SUFHM0I7SUFGbEIsWUFDRSxPQUFlLEVBQ0MsS0FBZTtRQUUvQixLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFGQyxVQUFLLEdBQUwsS0FBSyxDQUFVO1FBRy9CLElBQUksQ0FBQyxJQUFJLEdBQUcsc0JBQXNCLENBQUM7SUFDckMsQ0FBQztDQUNGIn0=
|
|
@@ -14,21 +14,19 @@ export type SupportedFheTypeName = typeof SupportedFheTypeName.Type;
|
|
|
14
14
|
export declare const SupportedFheType: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
15
15
|
export type SupportedFheType = typeof SupportedFheType.Type;
|
|
16
16
|
export declare const encryptionSchemes: {
|
|
17
|
-
readonly tfhe: 0;
|
|
18
17
|
readonly ecies: 1;
|
|
19
18
|
};
|
|
20
19
|
export declare function getEncryptionSchemeName(scheme: number): string;
|
|
21
20
|
export type EncryptionSchemes = typeof encryptionSchemes;
|
|
22
21
|
export type EciesScheme = EncryptionSchemes['ecies'];
|
|
23
|
-
export
|
|
24
|
-
export declare const EncryptionScheme: Schema.Literal<[0, 1]>;
|
|
22
|
+
export declare const EncryptionScheme: Schema.Literal<[1]>;
|
|
25
23
|
export type EncryptionScheme = typeof EncryptionScheme.Type;
|
|
26
24
|
type DistType<P, S extends EncryptionScheme, T extends SupportedFheType> = P extends any ? P & {
|
|
27
25
|
scheme: S;
|
|
28
26
|
type: T;
|
|
29
27
|
} : never;
|
|
30
28
|
export declare const Ciphertext: Schema.Struct<{
|
|
31
|
-
scheme: Schema.Literal<[
|
|
29
|
+
scheme: Schema.Literal<[1]>;
|
|
32
30
|
type: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
33
31
|
value: Schema.TemplateLiteral<`0x${string}`>;
|
|
34
32
|
}>;
|
|
@@ -36,7 +34,7 @@ export type Ciphertext = typeof Ciphertext.Type;
|
|
|
36
34
|
export type CiphertextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Ciphertext, S, T>;
|
|
37
35
|
export declare const CiphertextWithContext: Schema.Struct<{
|
|
38
36
|
ciphertext: Schema.Struct<{
|
|
39
|
-
scheme: Schema.Literal<[
|
|
37
|
+
scheme: Schema.Literal<[1]>;
|
|
40
38
|
type: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
41
39
|
value: Schema.TemplateLiteral<`0x${string}`>;
|
|
42
40
|
}>;
|
|
@@ -53,7 +51,7 @@ export type CiphertextWithContextOf<S extends EncryptionScheme, T extends Suppor
|
|
|
53
51
|
};
|
|
54
52
|
export declare const EncryptResult: Schema.Struct<{
|
|
55
53
|
ciphertext: Schema.Struct<{
|
|
56
|
-
scheme: Schema.Literal<[
|
|
54
|
+
scheme: Schema.Literal<[1]>;
|
|
57
55
|
type: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
58
56
|
value: Schema.TemplateLiteral<`0x${string}`>;
|
|
59
57
|
}>;
|
|
@@ -71,11 +69,11 @@ export type EncryptResultOf<S extends EncryptionScheme, T extends SupportedFheTy
|
|
|
71
69
|
ciphertext: CiphertextOf<S, T>;
|
|
72
70
|
};
|
|
73
71
|
export declare const Plaintext: Schema.Union<[Schema.Struct<{
|
|
74
|
-
scheme: Schema.Literal<[
|
|
72
|
+
scheme: Schema.Literal<[1]>;
|
|
75
73
|
type: Schema.Literal<[5, 7, 8]>;
|
|
76
74
|
value: typeof Schema.BigInt;
|
|
77
75
|
}>, Schema.Struct<{
|
|
78
|
-
scheme: Schema.Literal<[
|
|
76
|
+
scheme: Schema.Literal<[1]>;
|
|
79
77
|
type: Schema.Literal<[0]>;
|
|
80
78
|
value: typeof Schema.Boolean;
|
|
81
79
|
}>]>;
|
|
@@ -83,11 +81,11 @@ export type Plaintext = typeof Plaintext.Type;
|
|
|
83
81
|
export type PlaintextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Plaintext, S, T>;
|
|
84
82
|
export declare const PlaintextWithContext: Schema.Struct<{
|
|
85
83
|
plaintext: Schema.Union<[Schema.Struct<{
|
|
86
|
-
scheme: Schema.Literal<[
|
|
84
|
+
scheme: Schema.Literal<[1]>;
|
|
87
85
|
type: Schema.Literal<[5, 7, 8]>;
|
|
88
86
|
value: typeof Schema.BigInt;
|
|
89
87
|
}>, Schema.Struct<{
|
|
90
|
-
scheme: Schema.Literal<[
|
|
88
|
+
scheme: Schema.Literal<[1]>;
|
|
91
89
|
type: Schema.Literal<[0]>;
|
|
92
90
|
value: typeof Schema.Boolean;
|
|
93
91
|
}>]>;
|
|
@@ -2,6 +2,7 @@ import { Schema } from 'effect';
|
|
|
2
2
|
import { decodeAbiParameters, encodeAbiParameters, } from 'viem';
|
|
3
3
|
import { bigintToBytes, bigintToBytes32, Bytes32, bytesToBigInt, HexString, } from '../binary.js';
|
|
4
4
|
import { handleTypes, InputContext } from '../handle.js';
|
|
5
|
+
// TODO: review need of euint64 and euint160 as supported encrypted data type cause Lib.sol only supports euint256 and ebool
|
|
5
6
|
export const supportedFheTypes = {
|
|
6
7
|
euint64: handleTypes.euint64,
|
|
7
8
|
euint160: handleTypes.euint160,
|
|
@@ -13,20 +14,17 @@ export const SupportedFheTypeName = Schema.Literal(...supportedFheTypeNames);
|
|
|
13
14
|
// TODO: extend to all types
|
|
14
15
|
export const SupportedFheType = Schema.Literal(...Object.values(supportedFheTypes));
|
|
15
16
|
export const encryptionSchemes = {
|
|
16
|
-
tfhe: 0,
|
|
17
17
|
ecies: 1,
|
|
18
18
|
};
|
|
19
19
|
export function getEncryptionSchemeName(scheme) {
|
|
20
20
|
switch (scheme) {
|
|
21
|
-
case encryptionSchemes.tfhe:
|
|
22
|
-
return 'TFHE';
|
|
23
21
|
case encryptionSchemes.ecies:
|
|
24
22
|
return 'ECIES';
|
|
25
23
|
default:
|
|
26
24
|
throw new Error(`Unknown encryption scheme: ${scheme}`);
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
|
-
export const EncryptionScheme = Schema.Literal(encryptionSchemes.
|
|
27
|
+
export const EncryptionScheme = Schema.Literal(encryptionSchemes.ecies);
|
|
30
28
|
export const Ciphertext = Schema.Struct({
|
|
31
29
|
scheme: EncryptionScheme,
|
|
32
30
|
type: SupportedFheType,
|
|
@@ -71,8 +69,10 @@ export function bigintToPlaintext(scheme, type, bigPt) {
|
|
|
71
69
|
type,
|
|
72
70
|
value: bigPt !== 0n,
|
|
73
71
|
};
|
|
72
|
+
default:
|
|
73
|
+
console.warn(`bigintToPlaintext: Unsupported Encryption Scheme type ${type}`);
|
|
74
74
|
}
|
|
75
|
-
throw new Error(`Unsupported
|
|
75
|
+
throw new Error(`Unsupported Encryption Scheme type: ${type}`);
|
|
76
76
|
}
|
|
77
77
|
// This defines the schema we use for input encoding compatible with abi.decode
|
|
78
78
|
// on chain:
|
|
@@ -112,4 +112,4 @@ export function bytes32ToPlaintext(plaintext, scheme, type) {
|
|
|
112
112
|
export function bytesToPlaintext(plaintext, scheme, type) {
|
|
113
113
|
return bigintToPlaintext(scheme, type, BigInt(bytesToBigInt(plaintext)));
|
|
114
114
|
}
|
|
115
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
115
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jcnlwdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9lbmNyeXB0aW9uL2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLFFBQVEsQ0FBQztBQUNoQyxPQUFPLEVBR0wsbUJBQW1CLEVBQ25CLG1CQUFtQixHQUVwQixNQUFNLE1BQU0sQ0FBQztBQUNkLE9BQU8sRUFDTCxhQUFhLEVBQ2IsZUFBZSxFQUNmLE9BQU8sRUFDUCxhQUFhLEVBQ2IsU0FBUyxHQUNWLE1BQU0sY0FBYyxDQUFDO0FBQ3RCLE9BQU8sRUFBRSxXQUFXLEVBQUUsWUFBWSxFQUFFLE1BQU0sY0FBYyxDQUFDO0FBZ0J6RCw0SEFBNEg7QUFDNUgsTUFBTSxDQUFDLE1BQU0saUJBQWlCLEdBQUc7SUFDL0IsT0FBTyxFQUFFLFdBQVcsQ0FBQyxPQUFPO0lBQzVCLFFBQVEsRUFBRSxXQUFXLENBQUMsUUFBUTtJQUM5QixRQUFRLEVBQUUsV0FBVyxDQUFDLFFBQVE7SUFDOUIsS0FBSyxFQUFFLFdBQVcsQ0FBQyxLQUFLO0NBQ2hCLENBQUM7QUFFWCxNQUFNLHFCQUFxQixHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQ3ZDLGlCQUFpQixDQU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NLENBQUMsYUFBYSxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUMzRSxDQUFDIn0=
|
|
@@ -44,7 +44,7 @@ export declare const addTwoAbi: readonly [{
|
|
|
44
44
|
readonly internalType: "bytes";
|
|
45
45
|
readonly type: "bytes";
|
|
46
46
|
}];
|
|
47
|
-
readonly name: "
|
|
47
|
+
readonly name: "addTwoEoa";
|
|
48
48
|
readonly outputs: readonly [{
|
|
49
49
|
readonly name: "result";
|
|
50
50
|
readonly internalType: "euint256";
|
|
@@ -31,7 +31,7 @@ export const addTwoAbi = [
|
|
|
31
31
|
{
|
|
32
32
|
type: 'function',
|
|
33
33
|
inputs: [{ name: 'uint256EInput', internalType: 'bytes', type: 'bytes' }],
|
|
34
|
-
name: '
|
|
34
|
+
name: 'addTwoEoa',
|
|
35
35
|
outputs: [
|
|
36
36
|
{ name: 'result', internalType: 'euint256', type: 'bytes32' },
|
|
37
37
|
{ name: 'resultRevealed', internalType: 'euint256', type: 'bytes32' },
|
|
@@ -1135,6 +1135,26 @@ export declare const iIncoLightningPreviewAbi: readonly [{
|
|
|
1135
1135
|
readonly type: "bytes32";
|
|
1136
1136
|
}];
|
|
1137
1137
|
readonly stateMutability: "nonpayable";
|
|
1138
|
+
}, {
|
|
1139
|
+
readonly type: "function";
|
|
1140
|
+
readonly inputs: readonly [];
|
|
1141
|
+
readonly name: "majorVersion";
|
|
1142
|
+
readonly outputs: readonly [{
|
|
1143
|
+
readonly name: "";
|
|
1144
|
+
readonly internalType: "uint8";
|
|
1145
|
+
readonly type: "uint8";
|
|
1146
|
+
}];
|
|
1147
|
+
readonly stateMutability: "view";
|
|
1148
|
+
}, {
|
|
1149
|
+
readonly type: "function";
|
|
1150
|
+
readonly inputs: readonly [];
|
|
1151
|
+
readonly name: "minorVersion";
|
|
1152
|
+
readonly outputs: readonly [{
|
|
1153
|
+
readonly name: "";
|
|
1154
|
+
readonly internalType: "uint8";
|
|
1155
|
+
readonly type: "uint8";
|
|
1156
|
+
}];
|
|
1157
|
+
readonly stateMutability: "view";
|
|
1138
1158
|
}, {
|
|
1139
1159
|
readonly type: "function";
|
|
1140
1160
|
readonly inputs: readonly [{
|
|
@@ -1229,6 +1249,16 @@ export declare const iIncoLightningPreviewAbi: readonly [{
|
|
|
1229
1249
|
readonly type: "bytes32";
|
|
1230
1250
|
}];
|
|
1231
1251
|
readonly stateMutability: "payable";
|
|
1252
|
+
}, {
|
|
1253
|
+
readonly type: "function";
|
|
1254
|
+
readonly inputs: readonly [];
|
|
1255
|
+
readonly name: "patchVersion";
|
|
1256
|
+
readonly outputs: readonly [{
|
|
1257
|
+
readonly name: "";
|
|
1258
|
+
readonly internalType: "uint8";
|
|
1259
|
+
readonly type: "uint8";
|
|
1260
|
+
}];
|
|
1261
|
+
readonly stateMutability: "view";
|
|
1232
1262
|
}, {
|
|
1233
1263
|
readonly type: "function";
|
|
1234
1264
|
readonly inputs: readonly [{
|
|
@@ -1247,6 +1277,16 @@ export declare const iIncoLightningPreviewAbi: readonly [{
|
|
|
1247
1277
|
readonly type: "bool";
|
|
1248
1278
|
}];
|
|
1249
1279
|
readonly stateMutability: "view";
|
|
1280
|
+
}, {
|
|
1281
|
+
readonly type: "function";
|
|
1282
|
+
readonly inputs: readonly [];
|
|
1283
|
+
readonly name: "salt";
|
|
1284
|
+
readonly outputs: readonly [{
|
|
1285
|
+
readonly name: "";
|
|
1286
|
+
readonly internalType: "bytes32";
|
|
1287
|
+
readonly type: "bytes32";
|
|
1288
|
+
}];
|
|
1289
|
+
readonly stateMutability: "view";
|
|
1250
1290
|
}];
|
|
1251
1291
|
export declare const voucherEip712CheckerAbi: readonly [{
|
|
1252
1292
|
readonly type: "function";
|