@fhevm/sdk 1.1.0-alpha.7 → 1.1.0-alpha.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/README.md +5 -5
- package/_cjs/core/_version.js +1 -1
- package/_cjs/core/actions/encrypt/encryptValue.js +2 -1
- package/_cjs/core/actions/encrypt/encryptValue.js.map +1 -1
- package/_cjs/core/actions/encrypt/encryptValues.js +2 -1
- package/_cjs/core/actions/encrypt/encryptValues.js.map +1 -1
- package/_cjs/core/actions/encrypt/generateZkProof.js +2 -1
- package/_cjs/core/actions/encrypt/generateZkProof.js.map +1 -1
- package/_cjs/core/actions/host/readKmsVerifierContractData.js +1 -1
- package/_cjs/core/actions/host/readKmsVerifierContractData.js.map +1 -1
- package/_cjs/core/base/cachedFetch.js +1 -1
- package/_cjs/core/base/cachedFetch.js.map +1 -1
- package/_cjs/core/handle/FheType.js +4 -0
- package/_cjs/core/handle/FheType.js.map +1 -1
- package/_cjs/core/host-contracts/HostContractVersion-p.js +4 -0
- package/_cjs/core/host-contracts/HostContractVersion-p.js.map +1 -1
- package/_cjs/core/host-contracts/KmsSignersContext-p.js +15 -25
- package/_cjs/core/host-contracts/KmsSignersContext-p.js.map +1 -1
- package/_cjs/core/host-contracts/getKmsContextSignersAndThreshold-p.js.map +1 -1
- package/_cjs/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.js +7 -6
- package/_cjs/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.js.map +1 -1
- package/_cjs/core/host-contracts/readKmsSignersContext-p.js +55 -67
- package/_cjs/core/host-contracts/readKmsSignersContext-p.js.map +1 -1
- package/_cjs/core/kms/KmsSigncryptedShares-p.js +40 -4
- package/_cjs/core/kms/KmsSigncryptedShares-p.js.map +1 -1
- package/_cjs/core/kms/PublicDecryptionProof-p.js +4 -3
- package/_cjs/core/kms/PublicDecryptionProof-p.js.map +1 -1
- package/_cjs/core/kms/SignedDecryptionPermitV1-p.js +1 -14
- package/_cjs/core/kms/SignedDecryptionPermitV1-p.js.map +1 -1
- package/_cjs/core/kms/SignedDecryptionPermitV2-p.js +3 -15
- package/_cjs/core/kms/SignedDecryptionPermitV2-p.js.map +1 -1
- package/_cjs/core/kms/createKmsDelegatedUserDecryptEip712V1.js +3 -4
- package/_cjs/core/kms/createKmsDelegatedUserDecryptEip712V1.js.map +1 -1
- package/_cjs/core/kms/createKmsUserDecryptEip712V1.js +6 -5
- package/_cjs/core/kms/createKmsUserDecryptEip712V1.js.map +1 -1
- package/_cjs/core/kms/createKmsUserDecryptEip712V2.js +4 -5
- package/_cjs/core/kms/createKmsUserDecryptEip712V2.js.map +1 -1
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV1-p.js +1 -1
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV1-p.js.map +1 -1
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV2-p.js +1 -1
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV2-p.js.map +1 -1
- package/_cjs/core/kms/kmsExtraData-p.js +234 -0
- package/_cjs/core/kms/kmsExtraData-p.js.map +1 -0
- package/_cjs/core/kms/publicDecrypt.js +4 -4
- package/_cjs/core/kms/publicDecrypt.js.map +1 -1
- package/_cjs/core/kms/verifyKmsPublicDecryptEip712-p.js +5 -4
- package/_cjs/core/kms/verifyKmsPublicDecryptEip712-p.js.map +1 -1
- package/_cjs/core/modules/decrypt/mock.js +6 -6
- package/_cjs/core/modules/decrypt/mock.js.map +1 -1
- package/_cjs/core/modules/decrypt/module/api-p.js +7 -7
- package/_cjs/core/modules/decrypt/module/api-p.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchCoprocessorSignatures.js +53 -3
- package/_cjs/core/modules/relayer/cleartext/fetchCoprocessorSignatures.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/{fetchDelegatedUserDecrypt.js → fetchDelegatedUserDecryptV1.js} +67 -21
- package/_cjs/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js.map +1 -0
- package/_cjs/core/modules/relayer/cleartext/fetchPublicDecrypt.js +61 -4
- package/_cjs/core/modules/relayer/cleartext/fetchPublicDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecrypt.js +9 -108
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV1.js +163 -0
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV1.js.map +1 -0
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV2.js +7 -0
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV2.js.map +1 -0
- package/_cjs/core/modules/relayer/cleartext/forgeFhevmV1.js +83 -0
- package/_cjs/core/modules/relayer/cleartext/forgeFhevmV1.js.map +1 -0
- package/_cjs/core/modules/relayer/cleartext/mock.js +2 -2
- package/_cjs/core/modules/relayer/cleartext/mock.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/signers.js +14 -0
- package/_cjs/core/modules/relayer/cleartext/signers.js.map +1 -1
- package/_cjs/ethers/internal/ethereum-ct.js +11 -0
- package/_cjs/ethers/internal/ethereum-ct.js.map +1 -1
- package/_cjs/ethers/internal/runtime-ct.js +9 -7
- package/_cjs/ethers/internal/runtime-ct.js.map +1 -1
- package/_cjs/viem/internal/ethereum-ct.js +8 -0
- package/_cjs/viem/internal/ethereum-ct.js.map +1 -1
- package/_cjs/viem/internal/runtime-ct.js +9 -7
- package/_cjs/viem/internal/runtime-ct.js.map +1 -1
- package/_cjs/wasm/tfhe/loadTfheLib.js.map +1 -1
- package/_cjs/wasm/tkms/loadKmsLib.js.map +1 -1
- package/_esm/core/_version.js +1 -1
- package/_esm/core/actions/encrypt/encryptValue.js +2 -1
- package/_esm/core/actions/encrypt/encryptValue.js.map +1 -1
- package/_esm/core/actions/encrypt/encryptValues.js +2 -1
- package/_esm/core/actions/encrypt/encryptValues.js.map +1 -1
- package/_esm/core/actions/encrypt/generateZkProof.js +2 -1
- package/_esm/core/actions/encrypt/generateZkProof.js.map +1 -1
- package/_esm/core/actions/host/readKmsVerifierContractData.js +2 -2
- package/_esm/core/actions/host/readKmsVerifierContractData.js.map +1 -1
- package/_esm/core/base/cachedFetch.js +1 -1
- package/_esm/core/base/cachedFetch.js.map +1 -1
- package/_esm/core/handle/FheType.js +10 -0
- package/_esm/core/handle/FheType.js.map +1 -1
- package/_esm/core/host-contracts/HostContractVersion-p.js +6 -0
- package/_esm/core/host-contracts/HostContractVersion-p.js.map +1 -1
- package/_esm/core/host-contracts/KmsSignersContext-p.js +16 -25
- package/_esm/core/host-contracts/KmsSignersContext-p.js.map +1 -1
- package/_esm/core/host-contracts/getKmsContextSignersAndThreshold-p.js.map +1 -1
- package/_esm/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.js +6 -5
- package/_esm/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.js.map +1 -1
- package/_esm/core/host-contracts/readKmsSignersContext-p.js +133 -69
- package/_esm/core/host-contracts/readKmsSignersContext-p.js.map +1 -1
- package/_esm/core/kms/KmsSigncryptedShares-p.js +70 -4
- package/_esm/core/kms/KmsSigncryptedShares-p.js.map +1 -1
- package/_esm/core/kms/PublicDecryptionProof-p.js +4 -3
- package/_esm/core/kms/PublicDecryptionProof-p.js.map +1 -1
- package/_esm/core/kms/SignedDecryptionPermitV1-p.js +2 -32
- package/_esm/core/kms/SignedDecryptionPermitV1-p.js.map +1 -1
- package/_esm/core/kms/SignedDecryptionPermitV2-p.js +4 -16
- package/_esm/core/kms/SignedDecryptionPermitV2-p.js.map +1 -1
- package/_esm/core/kms/createKmsDelegatedUserDecryptEip712V1.js +3 -4
- package/_esm/core/kms/createKmsDelegatedUserDecryptEip712V1.js.map +1 -1
- package/_esm/core/kms/createKmsUserDecryptEip712V1.js +7 -6
- package/_esm/core/kms/createKmsUserDecryptEip712V1.js.map +1 -1
- package/_esm/core/kms/createKmsUserDecryptEip712V2.js +4 -5
- package/_esm/core/kms/createKmsUserDecryptEip712V2.js.map +1 -1
- package/_esm/core/kms/fetchKmsSigncryptedSharesV1-p.js +26 -2
- package/_esm/core/kms/fetchKmsSigncryptedSharesV1-p.js.map +1 -1
- package/_esm/core/kms/fetchKmsSigncryptedSharesV2-p.js +2 -2
- package/_esm/core/kms/fetchKmsSigncryptedSharesV2-p.js.map +1 -1
- package/_esm/core/kms/kmsExtraData-p.js +298 -0
- package/_esm/core/kms/kmsExtraData-p.js.map +1 -0
- package/_esm/core/kms/publicDecrypt.js +5 -5
- package/_esm/core/kms/publicDecrypt.js.map +1 -1
- package/_esm/core/kms/verifyKmsPublicDecryptEip712-p.js +5 -4
- package/_esm/core/kms/verifyKmsPublicDecryptEip712-p.js.map +1 -1
- package/_esm/core/modules/decrypt/mock.js +6 -6
- package/_esm/core/modules/decrypt/mock.js.map +1 -1
- package/_esm/core/modules/decrypt/module/api-p.js +7 -7
- package/_esm/core/modules/decrypt/module/api-p.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchCoprocessorSignatures.js +69 -12
- package/_esm/core/modules/relayer/cleartext/fetchCoprocessorSignatures.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/{fetchDelegatedUserDecrypt.js → fetchDelegatedUserDecryptV1.js} +76 -22
- package/_esm/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js.map +1 -0
- package/_esm/core/modules/relayer/cleartext/fetchPublicDecrypt.js +77 -4
- package/_esm/core/modules/relayer/cleartext/fetchPublicDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchUserDecrypt.js +13 -114
- package/_esm/core/modules/relayer/cleartext/fetchUserDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV1.js +173 -0
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV1.js.map +1 -0
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV2.js +6 -0
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV2.js.map +1 -0
- package/_esm/core/modules/relayer/cleartext/forgeFhevmV1.js +140 -0
- package/_esm/core/modules/relayer/cleartext/forgeFhevmV1.js.map +1 -0
- package/_esm/core/modules/relayer/cleartext/mock.js +1 -1
- package/_esm/core/modules/relayer/cleartext/mock.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/signers.js +26 -0
- package/_esm/core/modules/relayer/cleartext/signers.js.map +1 -1
- package/_esm/ethers/internal/ethereum-ct.js +12 -1
- package/_esm/ethers/internal/ethereum-ct.js.map +1 -1
- package/_esm/ethers/internal/runtime-ct.js +9 -7
- package/_esm/ethers/internal/runtime-ct.js.map +1 -1
- package/_esm/viem/internal/ethereum-ct.js +10 -2
- package/_esm/viem/internal/ethereum-ct.js.map +1 -1
- package/_esm/viem/internal/runtime-ct.js +9 -7
- package/_esm/viem/internal/runtime-ct.js.map +1 -1
- package/_types/core/actions/encrypt/encryptValue.d.ts.map +1 -1
- package/_types/core/actions/encrypt/encryptValues.d.ts.map +1 -1
- package/_types/core/actions/encrypt/generateZkProof.d.ts.map +1 -1
- package/_types/core/base/cachedFetch.d.ts.map +1 -1
- package/_types/core/handle/FheType.d.ts +8 -0
- package/_types/core/handle/FheType.d.ts.map +1 -1
- package/_types/core/host-contracts/HostContractVersion-p.d.ts +8 -0
- package/_types/core/host-contracts/HostContractVersion-p.d.ts.map +1 -1
- package/_types/core/host-contracts/KmsSignersContext-p.d.ts +3 -2
- package/_types/core/host-contracts/KmsSignersContext-p.d.ts.map +1 -1
- package/_types/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.d.ts +3 -2
- package/_types/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.d.ts.map +1 -1
- package/_types/core/host-contracts/readKmsSignersContext-p.d.ts +43 -26
- package/_types/core/host-contracts/readKmsSignersContext-p.d.ts.map +1 -1
- package/_types/core/kms/KmsSigncryptedShares-p.d.ts +18 -0
- package/_types/core/kms/KmsSigncryptedShares-p.d.ts.map +1 -1
- package/_types/core/kms/PublicDecryptionProof-p.d.ts.map +1 -1
- package/_types/core/kms/SignedDecryptionPermitV1-p.d.ts.map +1 -1
- package/_types/core/kms/SignedDecryptionPermitV2-p.d.ts.map +1 -1
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712V1.d.ts +2 -1
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712V1.d.ts.map +1 -1
- package/_types/core/kms/createKmsUserDecryptEip712V1.d.ts +2 -1
- package/_types/core/kms/createKmsUserDecryptEip712V1.d.ts.map +1 -1
- package/_types/core/kms/createKmsUserDecryptEip712V2.d.ts +2 -1
- package/_types/core/kms/createKmsUserDecryptEip712V2.d.ts.map +1 -1
- package/_types/core/kms/fetchKmsSigncryptedSharesV1-p.d.ts.map +1 -1
- package/_types/core/kms/kmsExtraData-p.d.ts +66 -0
- package/_types/core/kms/kmsExtraData-p.d.ts.map +1 -0
- package/_types/core/kms/publicDecrypt.d.ts.map +1 -1
- package/_types/core/kms/verifyKmsPublicDecryptEip712-p.d.ts.map +1 -1
- package/_types/core/modules/ethereum/types-ct.d.ts +20 -2
- package/_types/core/modules/ethereum/types-ct.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchCoprocessorSignatures.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/{fetchDelegatedUserDecrypt.d.ts → fetchDelegatedUserDecryptV1.d.ts} +1 -1
- package/_types/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.d.ts.map +1 -0
- package/_types/core/modules/relayer/cleartext/fetchPublicDecrypt.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchUserDecrypt.d.ts +2 -2
- package/_types/core/modules/relayer/cleartext/fetchUserDecrypt.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV1.d.ts +3 -0
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV1.d.ts.map +1 -0
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV2.d.ts +3 -0
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV2.d.ts.map +1 -0
- package/_types/core/modules/relayer/cleartext/forgeFhevmV1.d.ts +29 -0
- package/_types/core/modules/relayer/cleartext/forgeFhevmV1.d.ts.map +1 -0
- package/_types/core/modules/relayer/cleartext/signers.d.ts +1 -0
- package/_types/core/modules/relayer/cleartext/signers.d.ts.map +1 -1
- package/_types/core/types/kms-p.d.ts +7 -1
- package/_types/core/types/kms-p.d.ts.map +1 -1
- package/_types/ethers/internal/ethereum-ct.d.ts.map +1 -1
- package/_types/ethers/internal/runtime-ct.d.ts.map +1 -1
- package/_types/viem/internal/ethereum-ct.d.ts.map +1 -1
- package/_types/viem/internal/runtime-ct.d.ts.map +1 -1
- package/core/_version.ts +1 -1
- package/core/actions/encrypt/encryptValue.ts +4 -1
- package/core/actions/encrypt/encryptValues.ts +5 -1
- package/core/actions/encrypt/generateZkProof.ts +2 -1
- package/core/actions/host/readKmsVerifierContractData.ts +2 -2
- package/core/base/cachedFetch.ts +1 -1
- package/core/handle/FheType.ts +11 -0
- package/core/host-contracts/HostContractVersion-p.ts +12 -0
- package/core/host-contracts/KmsSignersContext-p.ts +29 -36
- package/core/host-contracts/getKmsContextSignersAndThreshold-p.ts +1 -0
- package/core/host-contracts/getKmsContextSignersAndThresholdFromExtraData-p.ts +10 -7
- package/core/host-contracts/readKmsSignersContext-p.ts +157 -116
- package/core/kms/KmsSigncryptedShares-p.ts +87 -4
- package/core/kms/PublicDecryptionProof-p.ts +6 -4
- package/core/kms/SignedDecryptionPermitV1-p.ts +5 -47
- package/core/kms/SignedDecryptionPermitV2-p.ts +8 -25
- package/core/kms/createKmsDelegatedUserDecryptEip712V1.ts +5 -5
- package/core/kms/createKmsUserDecryptEip712V1.ts +9 -7
- package/core/kms/createKmsUserDecryptEip712V2.ts +6 -6
- package/core/kms/fetchKmsSigncryptedSharesV1-p.ts +27 -15
- package/core/kms/fetchKmsSigncryptedSharesV2-p.ts +2 -2
- package/core/kms/kmsExtraData-p.ts +374 -0
- package/core/kms/publicDecrypt.ts +8 -7
- package/core/kms/verifyKmsPublicDecryptEip712-p.ts +7 -5
- package/core/modules/decrypt/mock.ts +6 -6
- package/core/modules/decrypt/module/api-p.ts +7 -7
- package/core/modules/ethereum/types-ct.ts +25 -2
- package/core/modules/relayer/cleartext/fetchCoprocessorSignatures.ts +98 -15
- package/core/modules/relayer/cleartext/{fetchDelegatedUserDecrypt.ts → fetchDelegatedUserDecryptV1.ts} +115 -27
- package/core/modules/relayer/cleartext/fetchPublicDecrypt.ts +112 -6
- package/core/modules/relayer/cleartext/fetchUserDecrypt.ts +24 -132
- package/core/modules/relayer/cleartext/fetchUserDecryptV1.ts +229 -0
- package/core/modules/relayer/cleartext/fetchUserDecryptV2.ts +11 -0
- package/core/modules/relayer/cleartext/forgeFhevmV1.ts +185 -0
- package/core/modules/relayer/cleartext/mock.ts +1 -1
- package/core/modules/relayer/cleartext/signers.ts +35 -0
- package/core/types/kms-p.ts +16 -1
- package/ethers/internal/ethereum-ct.ts +15 -1
- package/ethers/internal/runtime-ct.ts +9 -7
- package/package.json +1 -1
- package/viem/internal/ethereum-ct.ts +14 -2
- package/viem/internal/runtime-ct.ts +9 -7
- package/_cjs/core/kms/kmsExtraData.js +0 -82
- package/_cjs/core/kms/kmsExtraData.js.map +0 -1
- package/_cjs/core/modules/relayer/cleartext/fetchDelegatedUserDecrypt.js.map +0 -1
- package/_esm/core/kms/kmsExtraData.js +0 -99
- package/_esm/core/kms/kmsExtraData.js.map +0 -1
- package/_esm/core/modules/relayer/cleartext/fetchDelegatedUserDecrypt.js.map +0 -1
- package/_types/core/kms/kmsExtraData.d.ts +0 -25
- package/_types/core/kms/kmsExtraData.d.ts.map +0 -1
- package/_types/core/modules/relayer/cleartext/fetchDelegatedUserDecrypt.d.ts.map +0 -1
- package/core/kms/kmsExtraData.ts +0 -127
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import type { Bytes32Hex, BytesHex, Uint256BigInt, Uint8Number } from '../types/primitives.js';
|
|
2
|
+
import type { ErrorMetadataParams } from '../base/errors/ErrorBase.js';
|
|
3
|
+
import type { HostContractVersion } from '../types/hostContract.js';
|
|
4
|
+
import type { KmsExtraData } from '../types/kms-p.js';
|
|
5
|
+
import { asUint256BigInt, asUint8Number } from '../base/uint.js';
|
|
6
|
+
import { asBytes32Hex, assertIsBytesHex } from '../base/bytes.js';
|
|
7
|
+
import { isVersionEqual, isVersionStrictlyBefore } from '../host-contracts/HostContractVersion-p.js';
|
|
8
|
+
import { InvalidTypeError } from '../base/errors/InvalidTypeError.js';
|
|
9
|
+
|
|
10
|
+
export const EXTRA_DATA_V0: Uint8Number = 0x00 as Uint8Number; // 0x00
|
|
11
|
+
export const EXTRA_DATA_V1: Uint8Number = 0x01 as Uint8Number; // 1 version byte + 32-byte big-endian context ID = 33 bytes
|
|
12
|
+
export const EXTRA_DATA_V2: Uint8Number = 0x02 as Uint8Number; // 1 version byte + 32-byte big-endian context ID + 32-byte big-endian epoch ID = 65 bytes
|
|
13
|
+
|
|
14
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
15
|
+
|
|
16
|
+
const PRIVATE_TOKEN = Symbol('KmsExtraData.token');
|
|
17
|
+
|
|
18
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
// ExtraDataImpl class
|
|
20
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export class KmsExtraDataImpl implements KmsExtraData {
|
|
26
|
+
readonly #version: Uint8Number;
|
|
27
|
+
readonly #kmsContextId: Uint256BigInt;
|
|
28
|
+
readonly #kmsEpochId: Uint256BigInt;
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
privateToken: symbol,
|
|
32
|
+
parameters: {
|
|
33
|
+
readonly version: Uint8Number;
|
|
34
|
+
readonly kmsContextId: Uint256BigInt;
|
|
35
|
+
readonly kmsEpochId: Uint256BigInt;
|
|
36
|
+
},
|
|
37
|
+
) {
|
|
38
|
+
if (privateToken !== PRIVATE_TOKEN) {
|
|
39
|
+
throw new Error('Unauthorized');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.#kmsContextId = asUint256BigInt(parameters.kmsContextId);
|
|
43
|
+
this.#kmsEpochId = asUint256BigInt(parameters.kmsEpochId);
|
|
44
|
+
this.#version = asUint8Number(parameters.version);
|
|
45
|
+
|
|
46
|
+
this.#validate();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#validate(): void {
|
|
50
|
+
switch (this.#version) {
|
|
51
|
+
case EXTRA_DATA_V0: {
|
|
52
|
+
if (this.#kmsContextId !== 0n) {
|
|
53
|
+
throw new Error('kmsContextId must be 0 for v0 kms extraData');
|
|
54
|
+
}
|
|
55
|
+
if (this.#kmsEpochId !== 0n) {
|
|
56
|
+
throw new Error('kmsEpochId must be 0 for v0 kms extraData');
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case EXTRA_DATA_V1: {
|
|
61
|
+
if (this.#kmsContextId === 0n) {
|
|
62
|
+
throw new Error('kmsContextId cannot be 0 for v1 kms extraData');
|
|
63
|
+
}
|
|
64
|
+
if (this.#kmsEpochId !== 0n) {
|
|
65
|
+
throw new Error('kmsEpochId must be 0 for v1 kms extraData');
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
case EXTRA_DATA_V2: {
|
|
70
|
+
if (this.#kmsContextId === 0n) {
|
|
71
|
+
throw new Error('kmsContextId cannot be 0 for v2 kms extraData');
|
|
72
|
+
}
|
|
73
|
+
if (this.#kmsEpochId === 0n) {
|
|
74
|
+
throw new Error('kmsEpochId cannot be 0 for v2 kms extraData');
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`Unsupported kms extraData version ${this.#version}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public get version(): Uint8Number {
|
|
84
|
+
return this.#version;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public get kmsContextId(): Uint256BigInt {
|
|
88
|
+
return this.#kmsContextId;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public get kmsEpochId(): Uint256BigInt {
|
|
92
|
+
return this.#kmsEpochId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Encodes a KMS context into an extraData format.
|
|
97
|
+
* v0: `0x00`
|
|
98
|
+
* v1: `0x01` + 32-byte big-endian context ID.
|
|
99
|
+
* v2: `0x02` + 32-byte big-endian context ID + 32-byte big-endian epoch ID.
|
|
100
|
+
*/
|
|
101
|
+
public toBytesHex(): BytesHex {
|
|
102
|
+
const v = this.#version.toString(16).padStart(2, '0');
|
|
103
|
+
|
|
104
|
+
switch (this.#version) {
|
|
105
|
+
case EXTRA_DATA_V0: {
|
|
106
|
+
return `0x${v}` as BytesHex;
|
|
107
|
+
}
|
|
108
|
+
case EXTRA_DATA_V1: {
|
|
109
|
+
const contextId = this.#kmsContextId.toString(16).padStart(64, '0');
|
|
110
|
+
return `0x${v}${contextId}` as BytesHex;
|
|
111
|
+
}
|
|
112
|
+
case EXTRA_DATA_V2: {
|
|
113
|
+
const contextId = this.#kmsContextId.toString(16).padStart(64, '0');
|
|
114
|
+
const epochId = this.#kmsEpochId.toString(16).padStart(64, '0');
|
|
115
|
+
return `0x${v}${contextId}${epochId}` as BytesHex;
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
throw new Error(`Unsupported kms extraData version ${this.#version}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
124
|
+
|
|
125
|
+
export function fromKmsExtraDataBytesHex(extraDataBytesHex: BytesHex): KmsExtraData {
|
|
126
|
+
if ((extraDataBytesHex as string) === '0x00' || (extraDataBytesHex as string) === '0x') {
|
|
127
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
128
|
+
version: EXTRA_DATA_V0,
|
|
129
|
+
kmsContextId: 0n as Uint256BigInt,
|
|
130
|
+
kmsEpochId: 0n as Uint256BigInt,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (extraDataBytesHex.length <= 4) {
|
|
135
|
+
throw new Error(`Unsupported kms extraData length ${extraDataBytesHex.length}: must be more than 4 bytes`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// First byte = version (characters 2-3 after '0x')
|
|
139
|
+
const version = asUint8Number(Number('0x' + extraDataBytesHex.slice(2, 4)));
|
|
140
|
+
|
|
141
|
+
if (version === EXTRA_DATA_V1) {
|
|
142
|
+
// ExtraData v1 format: 1 version byte + 32-byte big-endian context ID = 33 bytes = 66 hex chars + 2 for '0x' = 68
|
|
143
|
+
// 0x01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
144
|
+
// ↑ ↑ ↑
|
|
145
|
+
// 0 4 68
|
|
146
|
+
// 0 1 2 3 4 5 6
|
|
147
|
+
// 01234567890123456789012345678901234567890123456789012345678901234567
|
|
148
|
+
|
|
149
|
+
if (extraDataBytesHex.length != 68) {
|
|
150
|
+
throw new Error(`Invalid kms extraData length for v1: expected 68, got ${extraDataBytesHex.length}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 32-byte contextId starts at byte 1 (hex chars 4..67)
|
|
154
|
+
const contextIdBytes32Hex: Bytes32Hex = asBytes32Hex(`0x${extraDataBytesHex.slice(4, 68)}`);
|
|
155
|
+
const kmsContextId = asUint256BigInt(BigInt(contextIdBytes32Hex));
|
|
156
|
+
|
|
157
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
158
|
+
version: EXTRA_DATA_V1,
|
|
159
|
+
kmsContextId,
|
|
160
|
+
kmsEpochId: 0n as Uint256BigInt,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (version === EXTRA_DATA_V2) {
|
|
165
|
+
// ExtraData v2 format: 1 version byte + 32-byte big-endian context ID + 32-byte big-endian epoch ID = 65 bytes = 130 hex chars + 2 for '0x' = 132
|
|
166
|
+
// 0x01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|
167
|
+
// ↑ ↑ ↑ ↑
|
|
168
|
+
// 0 4 68 132
|
|
169
|
+
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
|
170
|
+
// 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
|
|
171
|
+
|
|
172
|
+
if (extraDataBytesHex.length != 132) {
|
|
173
|
+
throw new Error(`Invalid extraData length for v2: expected 132, got ${extraDataBytesHex.length}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 32-byte contextId starts at byte 1 (hex chars 4..67)
|
|
177
|
+
const contextIdBytes32Hex: Bytes32Hex = asBytes32Hex(`0x${extraDataBytesHex.slice(4, 68)}`);
|
|
178
|
+
const kmsContextId = asUint256BigInt(BigInt(contextIdBytes32Hex));
|
|
179
|
+
|
|
180
|
+
// 32-byte epochId starts at byte 33 (hex chars 68..131)
|
|
181
|
+
const epochIdBytes32Hex: Bytes32Hex = asBytes32Hex(`0x${extraDataBytesHex.slice(68, 132)}`);
|
|
182
|
+
const kmsEpochId = asUint256BigInt(BigInt(epochIdBytes32Hex));
|
|
183
|
+
|
|
184
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
185
|
+
version: EXTRA_DATA_V2,
|
|
186
|
+
kmsContextId,
|
|
187
|
+
kmsEpochId: kmsEpochId,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
throw new Error(`Unsupported kms extraData version ${version}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
195
|
+
|
|
196
|
+
export function createKmsExtraDataV0(): KmsExtraData {
|
|
197
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
198
|
+
version: EXTRA_DATA_V0,
|
|
199
|
+
kmsContextId: 0n as Uint256BigInt,
|
|
200
|
+
kmsEpochId: 0n as Uint256BigInt,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
205
|
+
|
|
206
|
+
export function createKmsExtraDataV1(parameters: { readonly kmsContextId: Uint256BigInt }): KmsExtraData {
|
|
207
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
208
|
+
version: EXTRA_DATA_V1,
|
|
209
|
+
kmsContextId: parameters.kmsContextId,
|
|
210
|
+
kmsEpochId: 0n as Uint256BigInt,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
215
|
+
|
|
216
|
+
export function createKmsExtraDataV2(parameters: {
|
|
217
|
+
readonly kmsContextId: Uint256BigInt;
|
|
218
|
+
readonly kmsEpochId: Uint256BigInt;
|
|
219
|
+
}): KmsExtraData {
|
|
220
|
+
return new KmsExtraDataImpl(PRIVATE_TOKEN, {
|
|
221
|
+
version: EXTRA_DATA_V2,
|
|
222
|
+
kmsContextId: parameters.kmsContextId,
|
|
223
|
+
kmsEpochId: parameters.kmsEpochId,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
228
|
+
|
|
229
|
+
export function validateKmsExtraDataParams(parameters: {
|
|
230
|
+
readonly kmsContextId: Uint256BigInt;
|
|
231
|
+
readonly kmsEpochId: Uint256BigInt;
|
|
232
|
+
}): void {
|
|
233
|
+
if (parameters.kmsEpochId !== 0n && parameters.kmsContextId === 0n) {
|
|
234
|
+
throw new Error('kmsContextId cannot be 0 if kmsEpochId is not 0');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
239
|
+
|
|
240
|
+
export function createKmsExtraData(parameters: {
|
|
241
|
+
readonly kmsContextId: Uint256BigInt;
|
|
242
|
+
readonly kmsEpochId: Uint256BigInt;
|
|
243
|
+
}): KmsExtraData {
|
|
244
|
+
validateKmsExtraDataParams(parameters);
|
|
245
|
+
|
|
246
|
+
if (parameters.kmsEpochId === 0n) {
|
|
247
|
+
if (parameters.kmsContextId === 0n) {
|
|
248
|
+
return createKmsExtraDataV0();
|
|
249
|
+
}
|
|
250
|
+
return createKmsExtraDataV1({
|
|
251
|
+
kmsContextId: parameters.kmsContextId,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return createKmsExtraDataV2({
|
|
256
|
+
kmsContextId: parameters.kmsContextId,
|
|
257
|
+
kmsEpochId: parameters.kmsEpochId,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
262
|
+
|
|
263
|
+
export function equalsKmsExtraData(a: KmsExtraData, b: KmsExtraData): boolean {
|
|
264
|
+
assertIsKmsExtraData(a, {});
|
|
265
|
+
assertIsKmsExtraData(b, {});
|
|
266
|
+
return a.version === b.version && a.kmsContextId === b.kmsContextId && a.kmsEpochId === b.kmsEpochId;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Module-only helper. Narrows an unknown value to the concrete
|
|
273
|
+
* {@link KmsExtraDataImpl} class by verifying it via {@link assertIsKmsExtraData}
|
|
274
|
+
* and returning it typed as the implementation class, so other functions in this
|
|
275
|
+
* module can reach class-only members. Prefer this over a bare cast.
|
|
276
|
+
*
|
|
277
|
+
* Must never be exported: `Impl` classes are internal to the SDK and never leave
|
|
278
|
+
* the module, so a function that hands one back must stay module-private too.
|
|
279
|
+
* The public surface exposes only the {@link KmsExtraData} interface.
|
|
280
|
+
*
|
|
281
|
+
* @param value - The value to narrow.
|
|
282
|
+
* @returns The same value typed as {@link KmsExtraDataImpl}.
|
|
283
|
+
* @throws {InvalidTypeError} If `value` is not a {@link KmsExtraDataImpl} instance.
|
|
284
|
+
*/
|
|
285
|
+
function _asKmsExtraDataImpl(value: unknown): KmsExtraDataImpl {
|
|
286
|
+
assertIsKmsExtraData(value, {});
|
|
287
|
+
return value as KmsExtraDataImpl;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
291
|
+
|
|
292
|
+
export function isKmsExtraData(value: unknown): value is KmsExtraData {
|
|
293
|
+
return value instanceof KmsExtraDataImpl;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
297
|
+
|
|
298
|
+
export function assertIsKmsExtraData(
|
|
299
|
+
value: unknown,
|
|
300
|
+
options: { readonly subject?: string } & ErrorMetadataParams,
|
|
301
|
+
): asserts value is KmsExtraData {
|
|
302
|
+
if (!isKmsExtraData(value)) {
|
|
303
|
+
throw new InvalidTypeError(
|
|
304
|
+
{
|
|
305
|
+
subject: options.subject,
|
|
306
|
+
type: typeof value,
|
|
307
|
+
expectedType: 'KmsExtraData',
|
|
308
|
+
},
|
|
309
|
+
options,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
315
|
+
|
|
316
|
+
export function assertIsKmsExtraDataBytesHex(
|
|
317
|
+
value: unknown,
|
|
318
|
+
options: { subject?: string } & ErrorMetadataParams,
|
|
319
|
+
): asserts value is BytesHex {
|
|
320
|
+
if (value === '0x00' || value === '0x') {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
assertIsBytesHex(value, options);
|
|
325
|
+
|
|
326
|
+
// Will valid extraData length too
|
|
327
|
+
fromKmsExtraDataBytesHex(value);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Returns `true` if `kmsExtraData`'s version is accepted by the given
|
|
334
|
+
* KMSVerifier contract version.
|
|
335
|
+
*
|
|
336
|
+
* | KMSVerifier version | protocol | max extraData version |
|
|
337
|
+
* | ------------------- | --------------- | --------------------- |
|
|
338
|
+
* | < 0.2.0 | v0.11.0 | v0 |
|
|
339
|
+
* | 0.2.0 – 0.3.x | v0.12.0/v0.13.0 | v1 |
|
|
340
|
+
* | 0.4.0 | v0.14.0 | v2 |
|
|
341
|
+
* | > 0.4.0 | v0.14.1+ | not checked (`true`) |
|
|
342
|
+
*/
|
|
343
|
+
export function isKmsExtraDataCompatibleWithKmsVerifier(
|
|
344
|
+
kmsExtraData: KmsExtraData,
|
|
345
|
+
kmsVerifierVersion: HostContractVersion,
|
|
346
|
+
): boolean {
|
|
347
|
+
const ed = _asKmsExtraDataImpl(kmsExtraData);
|
|
348
|
+
|
|
349
|
+
// Protocol v0.11.0
|
|
350
|
+
if (isVersionStrictlyBefore(kmsVerifierVersion, { major: 0, minor: 2 })) {
|
|
351
|
+
return ed.version <= EXTRA_DATA_V0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Protocol v0.12.0/v0.13.0
|
|
355
|
+
if (isVersionStrictlyBefore(kmsVerifierVersion, { major: 0, minor: 4 })) {
|
|
356
|
+
return ed.version <= EXTRA_DATA_V1;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Protocol v0.14.0
|
|
360
|
+
if (isVersionEqual(kmsVerifierVersion, { major: 0, minor: 4, patch: 0 })) {
|
|
361
|
+
return ed.version <= EXTRA_DATA_V2;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Protocol v0.14.1+ (beyond the versions this SDK release knows about).
|
|
365
|
+
//
|
|
366
|
+
// We deliberately return `true` (compatible) instead of guessing an upper
|
|
367
|
+
// bound on `extraData.version`. On v0.14.0 the KMSVerifier reverts for
|
|
368
|
+
// `extraData.version > 2`, but we cannot know the accepted range of future
|
|
369
|
+
// contract versions. Pre-validating here would risk rejecting extraData that
|
|
370
|
+
// a newer contract actually supports. If the on-chain contract does reject it,
|
|
371
|
+
// the call reverts — and surfacing that revert is the source of truth, not a
|
|
372
|
+
// speculative client-side check.
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { RelayerPublicDecryptOptions } from '../types/relayer.js';
|
|
2
2
|
import type { FhevmChain } from '../types/fhevmChain.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChecksummedAddress, Uint64BigInt } from '../types/primitives.js';
|
|
4
4
|
import type { PublicDecryptionProof } from '../types/publicDecryptionProof-p.js';
|
|
5
5
|
import type { KmsSignersContext } from '../types/kmsSignersContext.js';
|
|
6
6
|
import type { FhevmRuntime } from '../types/coreFhevmRuntime.js';
|
|
7
7
|
import type { Handle } from '../types/encryptedTypes-p.js';
|
|
8
|
+
import type { KmsExtraData } from '../types/kms-p.js';
|
|
8
9
|
import { assertHandlesBelongToSameChainId } from '../handle/FhevmHandle.js';
|
|
9
10
|
import { assertKmsDecryptionBitLimit } from '../kms/utils.js';
|
|
10
|
-
import {
|
|
11
|
+
import { readCurrentKmsSignersContext, reconcileKmsSignersContext } from '../host-contracts/readKmsSignersContext-p.js';
|
|
11
12
|
import { kmsSignersContextToExtraData } from '../host-contracts/KmsSignersContext-p.js';
|
|
12
13
|
import { createPublicDecryptionProof } from '../kms/PublicDecryptionProof-p.js';
|
|
13
14
|
import { checkAllowedForDecryption } from '../host-contracts/checkAllowedForDecryption.js';
|
|
@@ -38,12 +39,12 @@ export async function publicDecrypt(context: Context, parameters: Parameters): P
|
|
|
38
39
|
// Contrary to the userDecrypt flow, the publicDecrypt doesn't require for an
|
|
39
40
|
// EIP-712 signature from the user, so the SDK can safely fetch the current
|
|
40
41
|
// context ID and build the extraData transparently to the user.
|
|
41
|
-
const requestedKmsSignersContext = await
|
|
42
|
+
const requestedKmsSignersContext = await readCurrentKmsSignersContext(context, {
|
|
42
43
|
kmsVerifierAddress: context.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
43
44
|
protocolConfigAddress: context.chain.fhevm.contracts.protocolConfig?.address as ChecksummedAddress | undefined,
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
const requestedExtraData:
|
|
47
|
+
const requestedExtraData: KmsExtraData = kmsSignersContextToExtraData(requestedKmsSignersContext);
|
|
47
48
|
|
|
48
49
|
const orderedHandles = handles;
|
|
49
50
|
|
|
@@ -74,11 +75,11 @@ export async function publicDecrypt(context: Context, parameters: Parameters): P
|
|
|
74
75
|
const {
|
|
75
76
|
orderedAbiEncodedClearValues,
|
|
76
77
|
kmsPublicDecryptEip712Signatures,
|
|
77
|
-
extraData:
|
|
78
|
+
extraData: relayerExtraDataBytesHex,
|
|
78
79
|
} = await context.runtime.relayer.fetchPublicDecrypt(context, {
|
|
79
80
|
payload: {
|
|
80
81
|
orderedHandles,
|
|
81
|
-
extraData: requestedExtraData,
|
|
82
|
+
extraData: requestedExtraData.toBytesHex(),
|
|
82
83
|
},
|
|
83
84
|
options: relayerOptions,
|
|
84
85
|
});
|
|
@@ -87,7 +88,7 @@ export async function publicDecrypt(context: Context, parameters: Parameters): P
|
|
|
87
88
|
const reconciledKmsSignersContext: KmsSignersContext = await reconcileKmsSignersContext(context, {
|
|
88
89
|
kmsVerifierAddress: context.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
89
90
|
protocolConfigAddress: context.chain.fhevm.contracts.protocolConfig?.address as ChecksummedAddress | undefined,
|
|
90
|
-
|
|
91
|
+
relayerKmsExtraDataBytesHex: relayerExtraDataBytesHex,
|
|
91
92
|
requestedKmsSignersContext: requestedKmsSignersContext,
|
|
92
93
|
mode: 'loose',
|
|
93
94
|
});
|
|
@@ -4,10 +4,12 @@ import type { KmsPublicDecryptEip712Message } from '../types/kms.js';
|
|
|
4
4
|
import type { KmsSignersContext } from '../types/kmsSignersContext.js';
|
|
5
5
|
import type { Bytes32Hex, Bytes65Hex, BytesHex } from '../types/primitives.js';
|
|
6
6
|
import type { Handle } from '../types/encryptedTypes-p.js';
|
|
7
|
+
import type { KmsExtraData } from '../types/kms-p.js';
|
|
7
8
|
import { recoverSigners } from '../utils-p/runtime/recoverSigners.js';
|
|
8
9
|
import { assertKmsSignerThreshold, kmsSignersContextToExtraData } from '../host-contracts/KmsSignersContext-p.js';
|
|
9
10
|
import { createKmsEip712Domain } from './createKmsEip712Domain.js';
|
|
10
11
|
import { kmsPublicDecryptEip712Types } from './kmsPublicDecryptEip712Types.js';
|
|
12
|
+
import { EXTRA_DATA_V0 } from './kmsExtraData-p.js';
|
|
11
13
|
|
|
12
14
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
15
|
|
|
@@ -30,16 +32,16 @@ export async function verifyKmsPublicDecryptEip712(context: Context, parameters:
|
|
|
30
32
|
|
|
31
33
|
// TODO: use createKmsPublicDecryptEip712 instead!
|
|
32
34
|
|
|
33
|
-
const extraData:
|
|
35
|
+
const extraData: KmsExtraData = kmsSignersContextToExtraData(kmsSignersContext);
|
|
34
36
|
|
|
35
37
|
////////////////////////////////////////////////////////////////////////////
|
|
36
38
|
//
|
|
37
39
|
// Warning!!!! Do not use '0x00' here!! Only '0x' is permitted!
|
|
38
40
|
//
|
|
39
41
|
////////////////////////////////////////////////////////////////////////////
|
|
40
|
-
let
|
|
41
|
-
if (extraData ===
|
|
42
|
-
|
|
42
|
+
let signedExtraDataBytesHex: BytesHex = extraData.toBytesHex();
|
|
43
|
+
if (extraData.version === EXTRA_DATA_V0) {
|
|
44
|
+
signedExtraDataBytesHex = '0x' as BytesHex;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
const handlesBytes32Hex: readonly Bytes32Hex[] = orderedEncryptedValues.map((h) => h.bytes32Hex);
|
|
@@ -47,7 +49,7 @@ export async function verifyKmsPublicDecryptEip712(context: Context, parameters:
|
|
|
47
49
|
const message: KmsPublicDecryptEip712Message = {
|
|
48
50
|
ctHandles: handlesBytes32Hex,
|
|
49
51
|
decryptedResult: orderedAbiEncodedClearValues,
|
|
50
|
-
extraData:
|
|
52
|
+
extraData: signedExtraDataBytesHex,
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
//////////////////////////////////////////////////////////////////////////////
|
|
@@ -17,12 +17,12 @@ import type { TkmsPrivateKey } from '../../types/tkms-p.js';
|
|
|
17
17
|
import type { BytesHex } from '../../types/primitives.js';
|
|
18
18
|
import type { KmsSigncryptedShare, KmsSigncryptedSharesMetadata } from '../../types/kms-p.js';
|
|
19
19
|
import type { ClearValue } from '../../types/encryptedTypes-p.js';
|
|
20
|
-
import { assertIsKmsExtraData } from '../../kms/kmsExtraData.js';
|
|
21
20
|
import { ensure0x, remove0x } from '../../base/string.js';
|
|
22
21
|
import { getMetadata, getShares } from '../../kms/KmsSigncryptedShares-p.js';
|
|
23
22
|
import { asBytesHex, bytesToHex, hexToBytes } from '../../base/bytes.js';
|
|
24
23
|
import { bigintToClearValueType } from '../../handle/FheType.js';
|
|
25
24
|
import { createClearValue } from '../../handle/ClearValue.js';
|
|
25
|
+
import { assertIsKmsExtraDataBytesHex } from '../../kms/kmsExtraData-p.js';
|
|
26
26
|
|
|
27
27
|
////////////////////////////////////////////////////////////////////////////////
|
|
28
28
|
|
|
@@ -71,8 +71,8 @@ export async function decryptAndReconstruct(
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
const extraDataBytesHex: BytesHex = ensure0x(firstExtraData);
|
|
75
|
+
assertIsKmsExtraDataBytesHex(extraDataBytesHex, {});
|
|
76
76
|
|
|
77
77
|
for (let i = 0; i < sharesArray.length; ++i) {
|
|
78
78
|
const s = sharesArray[i];
|
|
@@ -100,13 +100,13 @@ export async function decryptAndReconstruct(
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const maskedCleartexts = decoded[0] as bigint[];
|
|
103
|
-
const
|
|
103
|
+
const signedExtraDataBytesHex = decoded[1] as BytesHex;
|
|
104
104
|
|
|
105
105
|
const cleartexts: bigint[] = _xorUnmaskWithPublicKey(publicKeySecp256k1, maskedCleartexts);
|
|
106
106
|
|
|
107
|
-
if (
|
|
107
|
+
if (extraDataBytesHex !== signedExtraDataBytesHex) {
|
|
108
108
|
throw new Error(
|
|
109
|
-
`extraData mismatch: share extraData="${
|
|
109
|
+
`extraData mismatch: share extraData="${extraDataBytesHex}" does not match the signed payload's extraData="${signedExtraDataBytesHex}".`,
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -31,10 +31,10 @@ import { uint32ToBytes32 } from '../../../base/uint.js';
|
|
|
31
31
|
import { createClearValue } from '../../../handle/ClearValue.js';
|
|
32
32
|
import { bytesToClearValueType } from '../../../handle/FheType.js';
|
|
33
33
|
import { ensure0x, remove0x } from '../../../base/string.js';
|
|
34
|
-
import { assertIsKmsExtraData } from '../../../kms/kmsExtraData.js';
|
|
35
34
|
import { bytesToHexLarge } from '../../../base/bytes.js';
|
|
36
35
|
import { initTkmsModule } from './init-p.js';
|
|
37
36
|
import { getMetadata, getShares } from '../../../kms/KmsSigncryptedShares-p.js';
|
|
37
|
+
import { assertIsKmsExtraDataBytesHex } from '../../../kms/kmsExtraData-p.js';
|
|
38
38
|
|
|
39
39
|
////////////////////////////////////////////////////////////////////////////////
|
|
40
40
|
|
|
@@ -256,18 +256,18 @@ export async function decryptAndReconstruct(
|
|
|
256
256
|
throw new Error('Expected at least one signcrypted share.');
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
const
|
|
259
|
+
const firstExtraDataBytesHex = firstShare.extraData;
|
|
260
260
|
for (let i = 1; i < sharesArray.length; i++) {
|
|
261
261
|
const share = sharesArray[i];
|
|
262
|
-
if (share !== undefined && share.extraData !==
|
|
262
|
+
if (share !== undefined && share.extraData !== firstExtraDataBytesHex) {
|
|
263
263
|
throw new Error(
|
|
264
|
-
`Mismatched extraData across shares: share[0]="${
|
|
264
|
+
`Mismatched extraData across shares: share[0]="${firstExtraDataBytesHex}" vs share[${i}]="${share.extraData}".`,
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
const
|
|
270
|
-
|
|
269
|
+
const extraDataBytesHex: BytesHex = ensure0x(firstExtraDataBytesHex);
|
|
270
|
+
assertIsKmsExtraDataBytesHex(extraDataBytesHex, {});
|
|
271
271
|
|
|
272
272
|
const aggRespWasmArg: ReadonlyArray<Omit<KmsSigncryptedShare, 'extraData'> & { extra_data: BytesHexNo0x }> =
|
|
273
273
|
sharesArray.map((s) => {
|
|
@@ -333,7 +333,7 @@ export async function decryptAndReconstruct(
|
|
|
333
333
|
enc_key: remove0x(publicEncKeyMlKem512WasmBytesHex),
|
|
334
334
|
ciphertext_handles: metadata.handles.map((h) => h.bytes32HexNo0x),
|
|
335
335
|
eip712_verifying_contract: metadata.eip712Domain.verifyingContract,
|
|
336
|
-
extra_data: remove0x(
|
|
336
|
+
extra_data: remove0x(extraDataBytesHex),
|
|
337
337
|
};
|
|
338
338
|
|
|
339
339
|
//
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Bytes65Hex, BytesHex, ChecksummedAddress } from '../../types/primitives.js';
|
|
1
|
+
import type { Bytes32Hex, Bytes65Hex, BytesHex, ChecksummedAddress, Uint256 } from '../../types/primitives.js';
|
|
2
2
|
import type { Prettify } from '../../types/utils.js';
|
|
3
3
|
import type { EthereumModule } from './types.js';
|
|
4
4
|
|
|
@@ -32,6 +32,28 @@ export type SignModuleFunction = {
|
|
|
32
32
|
sign(parameters: SignParameters): Promise<SignReturnType>;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
36
|
+
// hashTypedData
|
|
37
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
export type HashTypedDataParameters = Readonly<{
|
|
40
|
+
domain: {
|
|
41
|
+
readonly chainId: Uint256;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly verifyingContract: ChecksummedAddress;
|
|
44
|
+
readonly version: string;
|
|
45
|
+
};
|
|
46
|
+
types: Readonly<Record<string, ReadonlyArray<{ name: string; type: string }>>>;
|
|
47
|
+
primaryType: string;
|
|
48
|
+
message: Readonly<Record<string, unknown>>;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export type HashTypedDataReturnType = Bytes32Hex;
|
|
52
|
+
|
|
53
|
+
export type HashTypedDataModuleFunction = {
|
|
54
|
+
hashTypedData(parameters: HashTypedDataParameters): HashTypedDataReturnType;
|
|
55
|
+
};
|
|
56
|
+
|
|
35
57
|
////////////////////////////////////////////////////////////////////////////////
|
|
36
58
|
// generatePrivateKey
|
|
37
59
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -81,7 +103,8 @@ export type CleartextEthereumModule = EthereumModule &
|
|
|
81
103
|
SignModuleFunction &
|
|
82
104
|
GeneratePrivateKeyModuleFunction &
|
|
83
105
|
GetPublicKeyModuleFunction &
|
|
84
|
-
RecoverAddressModuleFunction
|
|
106
|
+
RecoverAddressModuleFunction &
|
|
107
|
+
HashTypedDataModuleFunction
|
|
85
108
|
>;
|
|
86
109
|
|
|
87
110
|
export type CleartextEthereumModuleFactory = () => {
|