@fhevm/sdk 1.1.0-alpha.7 → 1.1.0-alpha.8
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 +54 -66
- 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 +132 -68
- 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 +156 -115
- 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
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import type { Bytes65Hex, BytesHex, ChecksummedAddress } from '../../../types/primitives.js';
|
|
1
|
+
import type { Bytes65Hex, BytesHex, ChecksummedAddress, Uint32BigInt } from '../../../types/primitives.js';
|
|
2
2
|
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
3
3
|
import type {
|
|
4
4
|
FetchCoprocessorSignaturesParameters,
|
|
5
5
|
FetchCoprocessorSignaturesReturnType,
|
|
6
6
|
RelayerClientWithRuntime,
|
|
7
7
|
} from '../types.js';
|
|
8
|
-
import {
|
|
8
|
+
import type { CoprocessorSignersContext } from '../../../types/coprocessorSignersContext.js';
|
|
9
|
+
import { asUint32BigInt, asUint64BigInt, randomUniqueUints } from '../../../base/uint.js';
|
|
9
10
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
10
11
|
import { getCoprocessorSignersPrivateKeyMap } from './signers.js';
|
|
12
|
+
import { isForgeFhevmV1 } from './forgeFhevmV1.js';
|
|
13
|
+
import { createCoprocessorEip712Domain } from '../../../coprocessor/createCoprocessorEip712Domain.js';
|
|
14
|
+
import { coprocessorEip712PrimaryType, coprocessorEip712Types } from '../../../coprocessor/coprocessorEip712Types.js';
|
|
15
|
+
import { readCoprocessorSignersContext } from '../../../host-contracts/readCoprocessorSignersContext-p.js';
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly coprocessorEip712Signatures: readonly Bytes65Hex[];
|
|
16
|
-
readonly extraData: BytesHex;
|
|
17
|
-
};
|
|
17
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
// runInputProofOnChain
|
|
19
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
18
20
|
|
|
19
|
-
*/
|
|
20
21
|
const inputProofAbi = [
|
|
21
22
|
{
|
|
22
23
|
type: 'function',
|
|
@@ -44,13 +45,14 @@ const inputProofAbi = [
|
|
|
44
45
|
},
|
|
45
46
|
] as const;
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
async function runInputProofOnChain(
|
|
48
49
|
relayerClient: RelayerClientWithRuntime,
|
|
49
|
-
|
|
50
|
-
): Promise<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
payload: FetchCoprocessorSignaturesParameters['payload'],
|
|
51
|
+
): Promise<{
|
|
52
|
+
readonly digest: BytesHex;
|
|
53
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
54
|
+
readonly threshold: Uint32BigInt;
|
|
55
|
+
}> {
|
|
54
56
|
const trustedClient = getTrustedClient(relayerClient);
|
|
55
57
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
56
58
|
abi: inputProofAbi,
|
|
@@ -67,6 +69,87 @@ export async function fetchCoprocessorSignatures(
|
|
|
67
69
|
const digest = res[0] as BytesHex;
|
|
68
70
|
const signersAddress = res[1] as ChecksummedAddress[];
|
|
69
71
|
const threshold = asUint32BigInt(res[2]);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
digest,
|
|
75
|
+
signersAddress,
|
|
76
|
+
threshold,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
81
|
+
// runInputProofOffChain
|
|
82
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
83
|
+
|
|
84
|
+
async function runInputProofOffChain(
|
|
85
|
+
relayerClient: RelayerClientWithRuntime,
|
|
86
|
+
payload: FetchCoprocessorSignaturesParameters['payload'],
|
|
87
|
+
): Promise<{
|
|
88
|
+
readonly digest: BytesHex;
|
|
89
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
90
|
+
readonly threshold: Uint32BigInt;
|
|
91
|
+
}> {
|
|
92
|
+
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
93
|
+
const { zkProof } = payload;
|
|
94
|
+
|
|
95
|
+
// Read the coprocessor signer set + threshold from the InputVerifier's on-chain
|
|
96
|
+
// storage. In the forge-fhevm-v1 setup only the `inputProof` view is missing;
|
|
97
|
+
// the signers/threshold and the EIP-712 material are still readable, so we
|
|
98
|
+
// recompute the digest off-chain below (mirroring CleartextInputVerifier.inputProof).
|
|
99
|
+
const coprocessorSignersContext: CoprocessorSignersContext = await readCoprocessorSignersContext(relayerClient, {
|
|
100
|
+
address: relayerClient.chain.fhevm.contracts.inputVerifier.address as ChecksummedAddress,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// The 'InputVerification' domain uses the gateway chainId + gateway
|
|
104
|
+
// inputVerification address (same as verifyHandlesCoprocessorSignatures).
|
|
105
|
+
const domain = createCoprocessorEip712Domain({
|
|
106
|
+
gatewayChainId: relayerClient.chain.fhevm.gateway.id,
|
|
107
|
+
verifyingContractAddressInputVerification: relayerClient.chain.fhevm.gateway.contracts.inputVerification.address,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Mirror CleartextInputVerifier.inputProof: hash the CiphertextVerification
|
|
111
|
+
// struct with contractChainId = block.chainid (the host chain), and extraData
|
|
112
|
+
// taken verbatim from the ZK proof (as the on-chain view would receive it).
|
|
113
|
+
const digest: BytesHex = cleartextEthereumModule.hashTypedData({
|
|
114
|
+
domain,
|
|
115
|
+
types: coprocessorEip712Types,
|
|
116
|
+
primaryType: coprocessorEip712PrimaryType,
|
|
117
|
+
message: {
|
|
118
|
+
ctHandles: zkProof.getInputHandles().map((h) => h.bytes32Hex),
|
|
119
|
+
userAddress: zkProof.userAddress,
|
|
120
|
+
contractAddress: zkProof.contractAddress,
|
|
121
|
+
contractChainId: asUint64BigInt(BigInt(relayerClient.chain.id)),
|
|
122
|
+
extraData: zkProof.getExtraData(),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
digest,
|
|
128
|
+
signersAddress: coprocessorSignersContext.signers,
|
|
129
|
+
threshold: asUint32BigInt(BigInt(coprocessorSignersContext.threshold)),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function fetchCoprocessorSignatures(
|
|
134
|
+
relayerClient: RelayerClientWithRuntime,
|
|
135
|
+
parameters: FetchCoprocessorSignaturesParameters,
|
|
136
|
+
): Promise<FetchCoprocessorSignaturesReturnType> {
|
|
137
|
+
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
138
|
+
const { payload } = parameters;
|
|
139
|
+
|
|
140
|
+
const offChain = await isForgeFhevmV1(relayerClient);
|
|
141
|
+
|
|
142
|
+
let res;
|
|
143
|
+
if (offChain) {
|
|
144
|
+
res = await runInputProofOffChain(relayerClient, payload);
|
|
145
|
+
} else {
|
|
146
|
+
res = await runInputProofOnChain(relayerClient, payload);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const digest = res.digest;
|
|
150
|
+
const signersAddress = res.signersAddress;
|
|
151
|
+
const threshold = res.threshold;
|
|
152
|
+
|
|
70
153
|
const signers = getCoprocessorSignersPrivateKeyMap(relayerClient);
|
|
71
154
|
|
|
72
155
|
const randomSignersAddress = randomUniqueUints(signersAddress.length, Number(threshold)).map(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BytesHex, ChecksummedAddress } from '../../../types/primitives.js';
|
|
1
|
+
import type { BytesHex, ChecksummedAddress, Uint32BigInt } from '../../../types/primitives.js';
|
|
2
2
|
import type { FetchUserDecryptResultItem } from '../../../types/relayer.js';
|
|
3
3
|
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
4
4
|
import type {
|
|
@@ -6,12 +6,69 @@ import type {
|
|
|
6
6
|
FetchUserDecryptReturnType,
|
|
7
7
|
RelayerClientWithRuntime,
|
|
8
8
|
} from '../types.js';
|
|
9
|
+
import type { KmsSignersContext } from '../../../types/kmsSignersContext.js';
|
|
9
10
|
import { remove0x } from '../../../base/string.js';
|
|
10
11
|
import { asUint32BigInt, tryParseUintBigIntString, randomUniqueUints } from '../../../base/uint.js';
|
|
11
12
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
12
13
|
import { userDecryptResultToKmsSigncryptedShares } from '../utils.js';
|
|
13
14
|
import { getKmsSignersPrivateKeyMap } from './signers.js';
|
|
15
|
+
import { isForgeFhevmV1, readPlaintexts, xorMaskWithPublicKey } from './forgeFhevmV1.js';
|
|
16
|
+
import { readCurrentKmsSignersContext } from '../../../host-contracts/readKmsSignersContext-p.js';
|
|
14
17
|
|
|
18
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
// runDelegatedUserDecryptOffChain
|
|
20
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
|
|
22
|
+
async function runDelegatedUserDecryptOffChain(
|
|
23
|
+
relayerClient: RelayerClientWithRuntime,
|
|
24
|
+
payload: FetchDelegatedUserDecryptParameters['payload'],
|
|
25
|
+
): Promise<{
|
|
26
|
+
readonly commonKmsSigncryptedSharePayload: BytesHex;
|
|
27
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
28
|
+
readonly threshold: Uint32BigInt;
|
|
29
|
+
readonly extraData: BytesHex;
|
|
30
|
+
}> {
|
|
31
|
+
const { kmsDecryptEip712Message } = payload;
|
|
32
|
+
const pairs = payload.handleContractPairs;
|
|
33
|
+
const trustedClient = getTrustedClient(relayerClient);
|
|
34
|
+
|
|
35
|
+
const rawCleartexts = await readPlaintexts(
|
|
36
|
+
relayerClient,
|
|
37
|
+
trustedClient,
|
|
38
|
+
pairs.map((p) => p.handle),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const currentKmsSignersContext: KmsSignersContext = await readCurrentKmsSignersContext(relayerClient, {
|
|
42
|
+
kmsVerifierAddress: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
43
|
+
protocolConfigAddress: relayerClient.chain.fhevm.contracts.protocolConfig?.address as
|
|
44
|
+
| ChecksummedAddress
|
|
45
|
+
| undefined,
|
|
46
|
+
});
|
|
47
|
+
const signersAddress = currentKmsSignersContext.signers;
|
|
48
|
+
const threshold = currentKmsSignersContext.threshold;
|
|
49
|
+
|
|
50
|
+
const maskedCleartexts = xorMaskWithPublicKey(kmsDecryptEip712Message.publicKey, rawCleartexts);
|
|
51
|
+
|
|
52
|
+
// extraData: the permit's message.extraData is already asserted equal to the
|
|
53
|
+
// current KmsSignersContext extraData by the caller (fetchKmsSigncryptedSharesV1
|
|
54
|
+
// step 9), so reusing it keeps the shares consistent with that context.
|
|
55
|
+
const extraData = kmsDecryptEip712Message.extraData;
|
|
56
|
+
|
|
57
|
+
const commonKmsSigncryptedSharePayload = relayerClient.runtime.ethereum.encode({
|
|
58
|
+
types: ['uint256[]', 'bytes'],
|
|
59
|
+
values: [maskedCleartexts, extraData],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
signersAddress,
|
|
64
|
+
threshold: BigInt(threshold) as Uint32BigInt,
|
|
65
|
+
commonKmsSigncryptedSharePayload,
|
|
66
|
+
extraData,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
71
|
+
// runDelegatedUserDecryptOnChain
|
|
15
72
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
73
|
|
|
17
74
|
const delegatedUserDecryptAbi = [
|
|
@@ -62,32 +119,17 @@ const delegatedUserDecryptAbi = [
|
|
|
62
119
|
},
|
|
63
120
|
] as const;
|
|
64
121
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export async function fetchDelegatedUserDecrypt(
|
|
122
|
+
async function runDelegatedUserDecryptOnChain(
|
|
68
123
|
relayerClient: RelayerClientWithRuntime,
|
|
69
|
-
|
|
70
|
-
): Promise<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const authCount = contractAddresses.length;
|
|
77
|
-
for (const { contractAddress: c } of pairs) {
|
|
78
|
-
let authorized: boolean = false;
|
|
79
|
-
for (let i = 0; i < authCount; ++i) {
|
|
80
|
-
if (contractAddresses[i] == c) {
|
|
81
|
-
authorized = true;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!authorized) {
|
|
86
|
-
throw new Error(`ContractAddressNotAuthorized: ${c} is not in the EIP-712 authorized contractAddresses list.`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
124
|
+
payload: FetchDelegatedUserDecryptParameters['payload'],
|
|
125
|
+
): Promise<{
|
|
126
|
+
readonly commonKmsSigncryptedSharePayload: BytesHex;
|
|
127
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
128
|
+
readonly threshold: Uint32BigInt;
|
|
129
|
+
readonly extraData: BytesHex;
|
|
130
|
+
}> {
|
|
90
131
|
const { kmsDecryptEip712Message, kmsDecryptEip712Signer, kmsDecryptEip712Signature } = payload;
|
|
132
|
+
const pairs = payload.handleContractPairs;
|
|
91
133
|
const trustedClient = getTrustedClient(relayerClient);
|
|
92
134
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
93
135
|
abi: delegatedUserDecryptAbi,
|
|
@@ -109,11 +151,57 @@ export async function fetchDelegatedUserDecrypt(
|
|
|
109
151
|
})) as unknown[];
|
|
110
152
|
|
|
111
153
|
const commonKmsSigncryptedSharePayload = res[0] as BytesHex;
|
|
112
|
-
const commonKmsSigncryptedSharePayloadNo0x = remove0x(commonKmsSigncryptedSharePayload);
|
|
113
154
|
const signersAddress = res[1] as readonly ChecksummedAddress[];
|
|
114
155
|
const threshold = asUint32BigInt(res[2]);
|
|
115
156
|
const extraData = res[3] as BytesHex;
|
|
116
157
|
|
|
158
|
+
return {
|
|
159
|
+
commonKmsSigncryptedSharePayload,
|
|
160
|
+
signersAddress,
|
|
161
|
+
threshold,
|
|
162
|
+
extraData,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
167
|
+
|
|
168
|
+
export async function fetchDelegatedUserDecrypt(
|
|
169
|
+
relayerClient: RelayerClientWithRuntime,
|
|
170
|
+
parameters: FetchDelegatedUserDecryptParameters,
|
|
171
|
+
): Promise<FetchUserDecryptReturnType> {
|
|
172
|
+
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
173
|
+
const { payload } = parameters;
|
|
174
|
+
const pairs = payload.handleContractPairs;
|
|
175
|
+
const contractAddresses = payload.kmsDecryptEip712Message.contractAddresses;
|
|
176
|
+
|
|
177
|
+
const authCount = contractAddresses.length;
|
|
178
|
+
for (const { contractAddress: c } of pairs) {
|
|
179
|
+
let authorized: boolean = false;
|
|
180
|
+
for (let i = 0; i < authCount; ++i) {
|
|
181
|
+
if (contractAddresses[i] == c) {
|
|
182
|
+
authorized = true;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (!authorized) {
|
|
187
|
+
throw new Error(`ContractAddressNotAuthorized: ${c} is not in the EIP-712 authorized contractAddresses list.`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const offChain = await isForgeFhevmV1(relayerClient);
|
|
192
|
+
|
|
193
|
+
let res;
|
|
194
|
+
if (offChain) {
|
|
195
|
+
res = await runDelegatedUserDecryptOffChain(relayerClient, payload);
|
|
196
|
+
} else {
|
|
197
|
+
res = await runDelegatedUserDecryptOnChain(relayerClient, payload);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const commonKmsSigncryptedSharePayload = res.commonKmsSigncryptedSharePayload;
|
|
201
|
+
const extraData = res.extraData;
|
|
202
|
+
const threshold = res.threshold;
|
|
203
|
+
const signersAddress = res.signersAddress;
|
|
204
|
+
|
|
117
205
|
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
118
206
|
|
|
119
207
|
const randomSignersAddress = randomUniqueUints(signersAddress.length, Number(threshold)).map(
|
|
@@ -130,7 +218,7 @@ export async function fetchDelegatedUserDecrypt(
|
|
|
130
218
|
}
|
|
131
219
|
|
|
132
220
|
const signature = await cleartextEthereumModule.sign({ hash: commonKmsSigncryptedSharePayload, privateKey });
|
|
133
|
-
result.push({ signature: remove0x(signature), payload:
|
|
221
|
+
result.push({ signature: remove0x(signature), payload: remove0x(commonKmsSigncryptedSharePayload), extraData });
|
|
134
222
|
}
|
|
135
223
|
|
|
136
224
|
return userDecryptResultToKmsSigncryptedShares(result);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { Bytes32Hex, Bytes65Hex, BytesHex, ChecksummedAddress } from '../../../types/primitives.js';
|
|
2
2
|
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
3
3
|
import type { FetchPublicDecryptParameters, FetchPublicDecryptReturnType, RelayerClientWithRuntime } from '../types.js';
|
|
4
|
+
import type { KmsSignersContext } from '../../../types/kmsSignersContext.js';
|
|
4
5
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
5
6
|
import { getKmsSignersPrivateKeyMap } from './signers.js';
|
|
7
|
+
import { encodeTypedCleartexts, isForgeFhevmV1, readPlaintexts } from './forgeFhevmV1.js';
|
|
8
|
+
import { createKmsEip712Domain } from '../../../kms/createKmsEip712Domain.js';
|
|
9
|
+
import { readCurrentKmsSignersContext } from '../../../host-contracts/readKmsSignersContext-p.js';
|
|
10
|
+
import { kmsPublicDecryptEip712Types } from '../../../kms/kmsPublicDecryptEip712Types.js';
|
|
6
11
|
|
|
7
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
8
13
|
|
|
@@ -28,22 +33,123 @@ const publicDecryptAbi = [
|
|
|
28
33
|
|
|
29
34
|
////////////////////////////////////////////////////////////////////////////////
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
async function runPublicDecryptOffChain(
|
|
32
37
|
relayerClient: RelayerClientWithRuntime,
|
|
33
|
-
|
|
34
|
-
): Promise<
|
|
38
|
+
payload: FetchPublicDecryptParameters['payload'],
|
|
39
|
+
): Promise<{
|
|
40
|
+
readonly orderedAbiEncodedClearValues: BytesHex;
|
|
41
|
+
readonly digest: Bytes32Hex;
|
|
42
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
43
|
+
readonly extraData: BytesHex;
|
|
44
|
+
}> {
|
|
35
45
|
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
46
|
+
const { orderedHandles } = payload;
|
|
36
47
|
|
|
48
|
+
// Option B: read cleartexts from CleartextFHEVMExecutor.plaintexts and rebuild
|
|
49
|
+
// the public-decrypt result off-chain instead of reading the CleartextKMSVerifier
|
|
50
|
+
// view. ACL `isAllowedForDecryption` gating is enforced by the caller
|
|
51
|
+
// (publicDecrypt step 4, checkAllowedForDecryption).
|
|
52
|
+
const trustedClient = getTrustedClient(relayerClient);
|
|
53
|
+
const cleartexts = await readPlaintexts(relayerClient, trustedClient, orderedHandles);
|
|
54
|
+
|
|
55
|
+
const orderedAbiEncodedClearValues = encodeTypedCleartexts(cleartextEthereumModule, orderedHandles, cleartexts);
|
|
56
|
+
|
|
57
|
+
// The caller passes the requested extraData (= current KmsSignersContext
|
|
58
|
+
// extraData). Reuse it verbatim so the returned extraData reconciles exactly
|
|
59
|
+
// (publicDecrypt step 6) and the signed digest matches the verifier's.
|
|
60
|
+
const extraData = payload.extraData;
|
|
61
|
+
|
|
62
|
+
////////////////////////////////////////////////////////////////////////////
|
|
63
|
+
// Warning!!!! Do not sign over '0x00' — only '0x' is permitted (matches
|
|
64
|
+
// verifyKmsPublicDecryptEip712 / createPublicDecryptionProof).
|
|
65
|
+
////////////////////////////////////////////////////////////////////////////
|
|
66
|
+
const signedExtraData: BytesHex = extraData === ('0x00' as BytesHex) ? ('0x' as BytesHex) : extraData;
|
|
67
|
+
|
|
68
|
+
// A 'PublicDecryptVerification' domain uses the gateway chainId.
|
|
69
|
+
const domain = createKmsEip712Domain({
|
|
70
|
+
chainId: relayerClient.chain.fhevm.gateway.id,
|
|
71
|
+
verifyingContractAddressDecryption: relayerClient.chain.fhevm.gateway.contracts.decryption.address,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const currentKmsSignersContext: KmsSignersContext = await readCurrentKmsSignersContext(relayerClient, {
|
|
75
|
+
kmsVerifierAddress: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
76
|
+
protocolConfigAddress: relayerClient.chain.fhevm.contracts.protocolConfig?.address as
|
|
77
|
+
| ChecksummedAddress
|
|
78
|
+
| undefined,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const digest: Bytes32Hex = cleartextEthereumModule.hashTypedData({
|
|
82
|
+
domain,
|
|
83
|
+
types: kmsPublicDecryptEip712Types,
|
|
84
|
+
primaryType: 'PublicDecryptVerification',
|
|
85
|
+
message: {
|
|
86
|
+
ctHandles: orderedHandles.map((h) => h.bytes32Hex),
|
|
87
|
+
decryptedResult: orderedAbiEncodedClearValues,
|
|
88
|
+
extraData: signedExtraData,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
orderedAbiEncodedClearValues,
|
|
94
|
+
digest,
|
|
95
|
+
signersAddress: currentKmsSignersContext.signers,
|
|
96
|
+
extraData,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
// runPublicDecryptOnChain
|
|
102
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
103
|
+
|
|
104
|
+
async function runPublicDecryptOnChain(
|
|
105
|
+
relayerClient: RelayerClientWithRuntime,
|
|
106
|
+
payload: FetchPublicDecryptParameters['payload'],
|
|
107
|
+
): Promise<{
|
|
108
|
+
readonly orderedAbiEncodedClearValues: BytesHex;
|
|
109
|
+
readonly digest: Bytes32Hex;
|
|
110
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
111
|
+
readonly extraData: BytesHex;
|
|
112
|
+
}> {
|
|
37
113
|
const trustedClient = getTrustedClient(relayerClient);
|
|
38
114
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
39
115
|
abi: publicDecryptAbi,
|
|
40
116
|
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
41
|
-
args: [
|
|
117
|
+
args: [payload.orderedHandles.map((h) => h.bytes32Hex)],
|
|
42
118
|
functionName: publicDecryptAbi[0].name,
|
|
43
119
|
})) as unknown[];
|
|
44
120
|
|
|
121
|
+
const orderedAbiEncodedClearValues = res[0] as BytesHex;
|
|
45
122
|
const digest = res[1] as Bytes32Hex;
|
|
46
123
|
const signersAddress = res[2] as readonly ChecksummedAddress[];
|
|
124
|
+
const extraData = res[4] as BytesHex;
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
orderedAbiEncodedClearValues,
|
|
128
|
+
digest,
|
|
129
|
+
signersAddress,
|
|
130
|
+
extraData,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
135
|
+
|
|
136
|
+
export async function fetchPublicDecrypt(
|
|
137
|
+
relayerClient: RelayerClientWithRuntime,
|
|
138
|
+
parameters: FetchPublicDecryptParameters,
|
|
139
|
+
): Promise<FetchPublicDecryptReturnType> {
|
|
140
|
+
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
141
|
+
|
|
142
|
+
const offChain = await isForgeFhevmV1(relayerClient);
|
|
143
|
+
|
|
144
|
+
let res;
|
|
145
|
+
if (offChain) {
|
|
146
|
+
res = await runPublicDecryptOffChain(relayerClient, parameters.payload);
|
|
147
|
+
} else {
|
|
148
|
+
res = await runPublicDecryptOnChain(relayerClient, parameters.payload);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const digest = res.digest;
|
|
152
|
+
const signersAddress = res.signersAddress;
|
|
47
153
|
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
48
154
|
|
|
49
155
|
const kmsPublicDecryptEip712Signatures: Bytes65Hex[] = [];
|
|
@@ -60,8 +166,8 @@ export async function fetchPublicDecrypt(
|
|
|
60
166
|
}
|
|
61
167
|
|
|
62
168
|
return {
|
|
63
|
-
orderedAbiEncodedClearValues: res
|
|
169
|
+
orderedAbiEncodedClearValues: res.orderedAbiEncodedClearValues,
|
|
64
170
|
kmsPublicDecryptEip712Signatures,
|
|
65
|
-
extraData: res
|
|
171
|
+
extraData: res.extraData,
|
|
66
172
|
};
|
|
67
173
|
}
|
|
@@ -1,141 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name: 'userDecrypt',
|
|
17
|
-
inputs: [
|
|
18
|
-
{
|
|
19
|
-
name: 'pairs',
|
|
20
|
-
type: 'tuple[]',
|
|
21
|
-
internalType: 'struct HandleContractPair[]',
|
|
22
|
-
components: [
|
|
23
|
-
{ name: 'handle', type: 'bytes32', internalType: 'bytes32' },
|
|
24
|
-
{
|
|
25
|
-
name: 'contractAddress',
|
|
26
|
-
type: 'address',
|
|
27
|
-
internalType: 'address',
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
{ name: 'userAddress', type: 'address', internalType: 'address' },
|
|
32
|
-
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
33
|
-
{
|
|
34
|
-
name: 'contractAddresses',
|
|
35
|
-
type: 'address[]',
|
|
36
|
-
internalType: 'address[]',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: 'startTimestamp',
|
|
40
|
-
type: 'uint256',
|
|
41
|
-
internalType: 'uint256',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'durationDays',
|
|
45
|
-
type: 'uint256',
|
|
46
|
-
internalType: 'uint256',
|
|
47
|
-
},
|
|
48
|
-
{ name: 'userSignature', type: 'bytes', internalType: 'bytes' },
|
|
49
|
-
],
|
|
50
|
-
outputs: [
|
|
51
|
-
{ name: 'payload', type: 'bytes', internalType: 'bytes' },
|
|
52
|
-
{ name: 'signers', type: 'address[]', internalType: 'address[]' },
|
|
53
|
-
{ name: 'threshold', type: 'uint256', internalType: 'uint256' },
|
|
54
|
-
{ name: 'extraData', type: 'bytes', internalType: 'bytes' },
|
|
55
|
-
],
|
|
56
|
-
stateMutability: 'view',
|
|
57
|
-
},
|
|
58
|
-
] as const;
|
|
59
|
-
|
|
60
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
1
|
+
import type {
|
|
2
|
+
FetchUserDecryptParameters,
|
|
3
|
+
FetchUserDecryptParametersV1,
|
|
4
|
+
FetchUserDecryptParametersV2,
|
|
5
|
+
FetchUserDecryptReturnType,
|
|
6
|
+
RelayerClientWithRuntime,
|
|
7
|
+
} from '../types.js';
|
|
8
|
+
import { getResolvedProtocolVersion } from '../../../runtime/CoreFhevm-p.js';
|
|
9
|
+
import { isSemverStrictlyBefore } from '../../../base/semver.js';
|
|
10
|
+
import { fetchUserDecryptV1 } from './fetchUserDecryptV1.js';
|
|
11
|
+
import { fetchUserDecryptV2 } from './fetchUserDecryptV2.js';
|
|
12
|
+
|
|
13
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
14
|
+
// fetchUserDecrypt
|
|
15
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
61
16
|
|
|
62
17
|
export async function fetchUserDecrypt(
|
|
63
18
|
relayerClient: RelayerClientWithRuntime,
|
|
64
|
-
parameters:
|
|
19
|
+
parameters: FetchUserDecryptParameters,
|
|
65
20
|
): Promise<FetchUserDecryptReturnType> {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const authCount = contractAddresses.length;
|
|
72
|
-
for (const { contractAddress: c } of pairs) {
|
|
73
|
-
let authorized: boolean = false;
|
|
74
|
-
for (let i = 0; i < authCount; ++i) {
|
|
75
|
-
if (contractAddresses[i] == c) {
|
|
76
|
-
authorized = true;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (!authorized) {
|
|
81
|
-
throw new Error(`ContractAddressNotAuthorized: ${c} is not in the EIP-712 authorized contractAddresses list.`);
|
|
82
|
-
}
|
|
21
|
+
const protocolVersion = getResolvedProtocolVersion(relayerClient);
|
|
22
|
+
if (protocolVersion === undefined) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Unable to resolve protocol version from context, ensure proper initialization of the FhevmRuntime and FhevmChain.',
|
|
25
|
+
);
|
|
83
26
|
}
|
|
84
27
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
88
|
-
abi: userDecryptAbi,
|
|
89
|
-
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
90
|
-
args: [
|
|
91
|
-
pairs.map((p) => ({
|
|
92
|
-
handle: p.handle.bytes32Hex,
|
|
93
|
-
contractAddress: p.contractAddress,
|
|
94
|
-
})),
|
|
95
|
-
kmsDecryptEip712Signer,
|
|
96
|
-
kmsDecryptEip712Message.publicKey,
|
|
97
|
-
kmsDecryptEip712Message.contractAddresses,
|
|
98
|
-
_parseUintBigIntString('kmsDecryptEip712Message.startTimestamp', kmsDecryptEip712Message.startTimestamp),
|
|
99
|
-
_parseUintBigIntString('kmsDecryptEip712Message.durationDays', kmsDecryptEip712Message.durationDays),
|
|
100
|
-
kmsDecryptEip712Signature,
|
|
101
|
-
],
|
|
102
|
-
functionName: userDecryptAbi[0].name,
|
|
103
|
-
})) as unknown[];
|
|
104
|
-
|
|
105
|
-
const commonKmsSigncryptedSharePayload = res[0] as BytesHex;
|
|
106
|
-
const commonKmsSigncryptedSharePayloadNo0x = remove0x(commonKmsSigncryptedSharePayload);
|
|
107
|
-
const signersAddress = res[1] as readonly ChecksummedAddress[];
|
|
108
|
-
const threshold = asUint32BigInt(res[2]);
|
|
109
|
-
const extraData = res[3] as BytesHex;
|
|
110
|
-
|
|
111
|
-
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
112
|
-
|
|
113
|
-
const randomSignersAddress = randomUniqueUints(signersAddress.length, Number(threshold)).map(
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
115
|
-
(i) => signersAddress[i]!,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const result: FetchUserDecryptResultItem[] = [];
|
|
119
|
-
|
|
120
|
-
for (const signerAddress of randomSignersAddress) {
|
|
121
|
-
const privateKey = signers.get(signerAddress);
|
|
122
|
-
if (privateKey === undefined) {
|
|
123
|
-
throw new Error(`Unable to find KMS signer for address ${signerAddress}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const signature = await cleartextEthereumModule.sign({ hash: commonKmsSigncryptedSharePayload, privateKey });
|
|
127
|
-
result.push({ signature: remove0x(signature), payload: commonKmsSigncryptedSharePayloadNo0x, extraData });
|
|
28
|
+
if (isSemverStrictlyBefore(protocolVersion.version, '0.14.0')) {
|
|
29
|
+
return await fetchUserDecryptV1(relayerClient, parameters as FetchUserDecryptParametersV1);
|
|
128
30
|
}
|
|
129
31
|
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
134
|
-
|
|
135
|
-
function _parseUintBigIntString(label: string, value: string): bigint {
|
|
136
|
-
const bn = tryParseUintBigIntString(value);
|
|
137
|
-
if (bn === undefined) {
|
|
138
|
-
throw new Error(`${label} is not a valid uint string, got ${JSON.stringify(value)}`);
|
|
139
|
-
}
|
|
140
|
-
return bn;
|
|
32
|
+
return await fetchUserDecryptV2(relayerClient, parameters as FetchUserDecryptParametersV2);
|
|
141
33
|
}
|