@fhevm/sdk 1.1.0-alpha.6 → 1.1.0-alpha.7
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/_cjs/core/_version.js +1 -1
- package/_cjs/core/actions/base/index.js +1 -17
- package/_cjs/core/actions/base/index.js.map +1 -1
- package/_cjs/core/actions/base/signDecryptionPermit.js +0 -3
- package/_cjs/core/actions/base/signDecryptionPermit.js.map +1 -1
- package/_cjs/core/actions/chain/index.js +1 -13
- package/_cjs/core/actions/chain/index.js.map +1 -1
- package/_cjs/core/actions/chain/parseSignedDecryptionPermit.js.map +1 -1
- package/_cjs/core/actions/chain/serializeSignedDecryptionPermit.js.map +1 -1
- package/_cjs/core/actions/decrypt/canDecryptValue.js.map +1 -1
- package/_cjs/core/actions/decrypt/canDecryptValues.js.map +1 -1
- package/_cjs/core/actions/decrypt/canDecryptValuesFromPairs.js.map +1 -1
- package/_cjs/core/actions/decrypt/decryptValue.js +1 -0
- package/_cjs/core/actions/decrypt/decryptValue.js.map +1 -1
- package/_cjs/core/actions/decrypt/decryptValues.js +2 -0
- package/_cjs/core/actions/decrypt/decryptValues.js.map +1 -1
- package/_cjs/core/actions/decrypt/decryptValuesFromPairs.js +2 -0
- package/_cjs/core/actions/decrypt/decryptValuesFromPairs.js.map +1 -1
- package/_cjs/core/actions/decrypt/index.js +1 -3
- package/_cjs/core/actions/decrypt/index.js.map +1 -1
- package/_cjs/core/actions/host/index.js +1 -9
- package/_cjs/core/actions/host/index.js.map +1 -1
- package/_cjs/core/base/cachedFetch.js +2 -1
- package/_cjs/core/base/cachedFetch.js.map +1 -1
- package/_cjs/core/base/uint.js +7 -0
- package/_cjs/core/base/uint.js.map +1 -1
- package/_cjs/core/clients/decorators/base.js +1 -1
- package/_cjs/core/clients/decorators/base.js.map +1 -1
- package/_cjs/core/host-contracts/canDecryptValuesFromPairs.js +4 -1
- package/_cjs/core/host-contracts/canDecryptValuesFromPairs.js.map +1 -1
- package/_cjs/core/host-contracts/getCoprocessorContextSignersAndThreshold-p.js +1 -1
- package/_cjs/core/host-contracts/getCoprocessorContextSignersAndThreshold-p.js.map +1 -1
- package/_cjs/core/host-contracts/getCurrentKmsContextAndEpoch-p.js +1 -1
- package/_cjs/core/host-contracts/getCurrentKmsContextAndEpoch-p.js.map +1 -1
- package/_cjs/core/host-contracts/getCurrentKmsContextId-p.js +1 -1
- package/_cjs/core/host-contracts/getCurrentKmsContextId-p.js.map +1 -1
- package/_cjs/core/host-contracts/getKmsContextSignersAndThreshold-p.js +1 -1
- package/_cjs/core/host-contracts/getKmsContextSignersAndThreshold-p.js.map +1 -1
- package/_cjs/core/kms/PublicDecryptionProof-p.js +4 -4
- package/_cjs/core/kms/SignedDecryptionPermit-p.js +33 -199
- package/_cjs/core/kms/SignedDecryptionPermit-p.js.map +1 -1
- package/_cjs/core/kms/SignedDecryptionPermitV1-p.js +217 -0
- package/_cjs/core/kms/SignedDecryptionPermitV1-p.js.map +1 -0
- package/_cjs/core/kms/SignedDecryptionPermitV2-p.js +184 -0
- package/_cjs/core/kms/SignedDecryptionPermitV2-p.js.map +1 -0
- package/_cjs/core/kms/{createKmsDelegatedUserDecryptEip712.js → createKmsDelegatedUserDecryptEip712V1.js} +9 -9
- package/_cjs/core/kms/createKmsDelegatedUserDecryptEip712V1.js.map +1 -0
- package/_cjs/core/kms/{createKmsUserDecryptEip712.js → createKmsUserDecryptEip712V1.js} +16 -16
- package/_cjs/core/kms/createKmsUserDecryptEip712V1.js.map +1 -0
- package/_cjs/core/kms/decryptValuesFromPairs.js +18 -2
- package/_cjs/core/kms/decryptValuesFromPairs.js.map +1 -1
- package/_cjs/core/kms/{fetchKmsSigncryptedShares-p.js → fetchKmsSigncryptedSharesV1-p.js} +18 -8
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV1-p.js.map +1 -0
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV2-p.js +95 -0
- package/_cjs/core/kms/fetchKmsSigncryptedSharesV2-p.js.map +1 -0
- package/_cjs/core/kms/{kmsDelegatedUserDecryptEip712Types.js → kmsDelegatedUserDecryptEip712V1Types.js} +8 -8
- package/_cjs/core/kms/kmsDelegatedUserDecryptEip712V1Types.js.map +1 -0
- package/_cjs/core/kms/{kmsUserDecryptEip712Types.js → kmsUserDecryptEip712V1Types.js} +8 -8
- package/_cjs/core/kms/kmsUserDecryptEip712V1Types.js.map +1 -0
- package/_cjs/core/kms/kmsUserDecryptEip712V2Types.js.map +1 -1
- package/_cjs/core/kms/publicDecrypt.js +2 -2
- package/_cjs/core/kms/utils.js +0 -19
- package/_cjs/core/kms/utils.js.map +1 -1
- package/_cjs/core/kms/verifyKmsPublicDecryptEip712-p.js +1 -1
- package/_cjs/core/modules/decrypt/module/api-p.js +5 -5
- package/_cjs/core/modules/decrypt/module/init-p.js +6 -7
- package/_cjs/core/modules/decrypt/module/init-p.js.map +1 -1
- package/_cjs/core/modules/encrypt/module/init-p.js +12 -11
- package/_cjs/core/modules/encrypt/module/init-p.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchPublicDecrypt.js +3 -3
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/module/{fetchDelegatedUserDecrypt.js → fetchDelegatedUserDecryptV1.js} +1 -1
- package/_cjs/core/modules/relayer/module/fetchDelegatedUserDecryptV1.js.map +1 -0
- package/_cjs/core/modules/relayer/module/fetchPublicDecrypt.js +1 -1
- package/_cjs/core/modules/relayer/module/fetchUserDecrypt.js +11 -45
- package/_cjs/core/modules/relayer/module/fetchUserDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/module/fetchUserDecryptV1.js +52 -0
- package/_cjs/core/modules/relayer/module/fetchUserDecryptV1.js.map +1 -0
- package/_cjs/core/modules/relayer/module/fetchUserDecryptV2.js +54 -0
- package/_cjs/core/modules/relayer/module/fetchUserDecryptV2.js.map +1 -0
- package/_cjs/core/modules/relayer/module/guards/RelayerResponseFailed.js +10 -2
- package/_cjs/core/modules/relayer/module/guards/RelayerResponseFailed.js.map +1 -1
- package/_cjs/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.js +5 -2
- package/_cjs/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.js.map +1 -1
- package/_cjs/core/modules/relayer/module/guards/api-errors/RelayerApiError503.js +2 -0
- package/_cjs/core/modules/relayer/module/guards/api-errors/RelayerApiError503.js.map +1 -1
- package/_cjs/core/modules/relayer/module/index.js +2 -2
- package/_cjs/core/modules/relayer/module/index.js.map +1 -1
- package/_cjs/core/runtime/HyperWasmSolver-p.js +1 -6
- package/_cjs/core/runtime/HyperWasmSolver-p.js.map +1 -1
- package/_cjs/core/utils-p/decrypt/{verifyKmsDelegatedUserDecryptEip712.js → verifyKmsDelegatedUserDecryptEip712V1.js} +5 -5
- package/_cjs/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712V1.js.map +1 -0
- package/_cjs/core/utils-p/decrypt/{verifyKmsUserDecryptEip712.js → verifyKmsUserDecryptEip712V1.js} +5 -5
- package/_cjs/core/utils-p/decrypt/verifyKmsUserDecryptEip712V1.js.map +1 -0
- package/_cjs/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.js +30 -0
- package/_cjs/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.js.map +1 -0
- 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/base/index.js +0 -8
- package/_esm/core/actions/base/index.js.map +1 -1
- package/_esm/core/actions/base/signDecryptionPermit.js +0 -6
- package/_esm/core/actions/base/signDecryptionPermit.js.map +1 -1
- package/_esm/core/actions/chain/index.js +0 -6
- package/_esm/core/actions/chain/index.js.map +1 -1
- package/_esm/core/actions/chain/parseSignedDecryptionPermit.js.map +1 -1
- package/_esm/core/actions/chain/serializeSignedDecryptionPermit.js.map +1 -1
- package/_esm/core/actions/decrypt/canDecryptValue.js +40 -0
- package/_esm/core/actions/decrypt/canDecryptValue.js.map +1 -1
- package/_esm/core/actions/decrypt/canDecryptValues.js +1 -0
- package/_esm/core/actions/decrypt/canDecryptValues.js.map +1 -1
- package/_esm/core/actions/decrypt/canDecryptValuesFromPairs.js +1 -0
- package/_esm/core/actions/decrypt/canDecryptValuesFromPairs.js.map +1 -1
- package/_esm/core/actions/decrypt/decryptValue.js +1 -0
- package/_esm/core/actions/decrypt/decryptValue.js.map +1 -1
- package/_esm/core/actions/decrypt/decryptValues.js +2 -0
- package/_esm/core/actions/decrypt/decryptValues.js.map +1 -1
- package/_esm/core/actions/decrypt/decryptValuesFromPairs.js +2 -0
- package/_esm/core/actions/decrypt/decryptValuesFromPairs.js.map +1 -1
- package/_esm/core/actions/decrypt/index.js +0 -1
- package/_esm/core/actions/decrypt/index.js.map +1 -1
- package/_esm/core/actions/host/index.js +0 -4
- package/_esm/core/actions/host/index.js.map +1 -1
- package/_esm/core/base/cachedFetch.js +1 -0
- package/_esm/core/base/cachedFetch.js.map +1 -1
- package/_esm/core/base/uint.js +7 -0
- package/_esm/core/base/uint.js.map +1 -1
- package/_esm/core/clients/decorators/base.js +2 -4
- package/_esm/core/clients/decorators/base.js.map +1 -1
- package/_esm/core/coprocessor/coprocessorEip712Types.js +2 -2
- package/_esm/core/host-contracts/canDecryptValuesFromPairs.js +5 -2
- package/_esm/core/host-contracts/canDecryptValuesFromPairs.js.map +1 -1
- package/_esm/core/host-contracts/getCoprocessorContextSignersAndThreshold-p.js +2 -2
- package/_esm/core/host-contracts/getCoprocessorContextSignersAndThreshold-p.js.map +1 -1
- package/_esm/core/host-contracts/getCurrentKmsContextAndEpoch-p.js +2 -2
- package/_esm/core/host-contracts/getCurrentKmsContextAndEpoch-p.js.map +1 -1
- package/_esm/core/host-contracts/getCurrentKmsContextId-p.js +2 -2
- package/_esm/core/host-contracts/getCurrentKmsContextId-p.js.map +1 -1
- package/_esm/core/host-contracts/getKmsContextSignersAndThreshold-p.js +2 -2
- package/_esm/core/host-contracts/getKmsContextSignersAndThreshold-p.js.map +1 -1
- package/_esm/core/kms/PublicDecryptionProof-p.js +4 -4
- package/_esm/core/kms/SignedDecryptionPermit-p.js +48 -245
- package/_esm/core/kms/SignedDecryptionPermit-p.js.map +1 -1
- package/_esm/core/kms/SignedDecryptionPermitV1-p.js +258 -0
- package/_esm/core/kms/SignedDecryptionPermitV1-p.js.map +1 -0
- package/_esm/core/kms/SignedDecryptionPermitV2-p.js +204 -0
- package/_esm/core/kms/SignedDecryptionPermitV2-p.js.map +1 -0
- package/_esm/core/kms/{createKmsDelegatedUserDecryptEip712.js → createKmsDelegatedUserDecryptEip712V1.js} +8 -8
- package/_esm/core/kms/createKmsDelegatedUserDecryptEip712V1.js.map +1 -0
- package/_esm/core/kms/createKmsPublicDecryptEip712.js +1 -1
- package/_esm/core/kms/{createKmsUserDecryptEip712.js → createKmsUserDecryptEip712V1.js} +16 -16
- package/_esm/core/kms/createKmsUserDecryptEip712V1.js.map +1 -0
- package/_esm/core/kms/decryptValuesFromPairs.js +18 -2
- package/_esm/core/kms/decryptValuesFromPairs.js.map +1 -1
- package/_esm/core/kms/{fetchKmsSigncryptedShares-p.js → fetchKmsSigncryptedSharesV1-p.js} +23 -13
- package/_esm/core/kms/fetchKmsSigncryptedSharesV1-p.js.map +1 -0
- package/_esm/core/kms/fetchKmsSigncryptedSharesV2-p.js +119 -0
- package/_esm/core/kms/fetchKmsSigncryptedSharesV2-p.js.map +1 -0
- package/_esm/core/kms/{kmsDelegatedUserDecryptEip712Types.js → kmsDelegatedUserDecryptEip712V1Types.js} +9 -8
- package/_esm/core/kms/kmsDelegatedUserDecryptEip712V1Types.js.map +1 -0
- package/_esm/core/kms/kmsPublicDecryptEip712Types.js +1 -1
- package/_esm/core/kms/{kmsUserDecryptEip712Types.js → kmsUserDecryptEip712V1Types.js} +9 -8
- package/_esm/core/kms/kmsUserDecryptEip712V1Types.js.map +1 -0
- package/_esm/core/kms/kmsUserDecryptEip712V2Types.js +2 -1
- package/_esm/core/kms/kmsUserDecryptEip712V2Types.js.map +1 -1
- package/_esm/core/kms/publicDecrypt.js +2 -2
- package/_esm/core/kms/utils.js +0 -18
- package/_esm/core/kms/utils.js.map +1 -1
- package/_esm/core/kms/verifyKmsPublicDecryptEip712-p.js +2 -2
- package/_esm/core/modules/decrypt/module/api-p.js +6 -6
- package/_esm/core/modules/decrypt/module/init-p.js +7 -7
- package/_esm/core/modules/decrypt/module/init-p.js.map +1 -1
- package/_esm/core/modules/encrypt/module/init-p.js +13 -11
- package/_esm/core/modules/encrypt/module/init-p.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchPublicDecrypt.js +3 -3
- package/_esm/core/modules/relayer/cleartext/fetchUserDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/module/{fetchDelegatedUserDecrypt.js → fetchDelegatedUserDecryptV1.js} +1 -1
- package/_esm/core/modules/relayer/module/fetchDelegatedUserDecryptV1.js.map +1 -0
- package/_esm/core/modules/relayer/module/fetchPublicDecrypt.js +1 -1
- package/_esm/core/modules/relayer/module/fetchUserDecrypt.js +11 -46
- package/_esm/core/modules/relayer/module/fetchUserDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/module/fetchUserDecryptV1.js +53 -0
- package/_esm/core/modules/relayer/module/fetchUserDecryptV1.js.map +1 -0
- package/_esm/core/modules/relayer/module/fetchUserDecryptV2.js +56 -0
- package/_esm/core/modules/relayer/module/fetchUserDecryptV2.js.map +1 -0
- package/_esm/core/modules/relayer/module/guards/RelayerResponseFailed.js +10 -2
- package/_esm/core/modules/relayer/module/guards/RelayerResponseFailed.js.map +1 -1
- package/_esm/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.js +6 -3
- package/_esm/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.js.map +1 -1
- package/_esm/core/modules/relayer/module/guards/api-errors/RelayerApiError503.js +2 -0
- package/_esm/core/modules/relayer/module/guards/api-errors/RelayerApiError503.js.map +1 -1
- package/_esm/core/modules/relayer/module/index.js +1 -1
- package/_esm/core/modules/relayer/module/index.js.map +1 -1
- package/_esm/core/runtime/HyperWasmSolver-p.js +1 -6
- package/_esm/core/runtime/HyperWasmSolver-p.js.map +1 -1
- package/_esm/core/utils-p/decrypt/{verifyKmsDelegatedUserDecryptEip712.js → verifyKmsDelegatedUserDecryptEip712V1.js} +5 -5
- package/_esm/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712V1.js.map +1 -0
- package/_esm/core/utils-p/decrypt/{verifyKmsUserDecryptEip712.js → verifyKmsUserDecryptEip712V1.js} +5 -5
- package/_esm/core/utils-p/decrypt/verifyKmsUserDecryptEip712V1.js.map +1 -0
- package/_esm/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.js +27 -0
- package/_esm/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.js.map +1 -0
- package/_types/core/actions/base/index.d.ts +0 -8
- package/_types/core/actions/base/index.d.ts.map +1 -1
- package/_types/core/actions/base/signDecryptionPermit.d.ts +4 -5
- package/_types/core/actions/base/signDecryptionPermit.d.ts.map +1 -1
- package/_types/core/actions/chain/index.d.ts +1 -7
- package/_types/core/actions/chain/index.d.ts.map +1 -1
- package/_types/core/actions/chain/parseSignedDecryptionPermit.d.ts +1 -0
- package/_types/core/actions/chain/parseSignedDecryptionPermit.d.ts.map +1 -1
- package/_types/core/actions/chain/serializeSignedDecryptionPermit.d.ts +3 -2
- package/_types/core/actions/chain/serializeSignedDecryptionPermit.d.ts.map +1 -1
- package/_types/core/actions/decrypt/canDecryptValue.d.ts +3 -4
- package/_types/core/actions/decrypt/canDecryptValue.d.ts.map +1 -1
- package/_types/core/actions/decrypt/canDecryptValues.d.ts +3 -4
- package/_types/core/actions/decrypt/canDecryptValues.d.ts.map +1 -1
- package/_types/core/actions/decrypt/canDecryptValuesFromPairs.d.ts +3 -4
- package/_types/core/actions/decrypt/canDecryptValuesFromPairs.d.ts.map +1 -1
- package/_types/core/actions/decrypt/decryptValue.d.ts.map +1 -1
- package/_types/core/actions/decrypt/decryptValues.d.ts.map +1 -1
- package/_types/core/actions/decrypt/decryptValuesFromPairs.d.ts.map +1 -1
- package/_types/core/actions/decrypt/index.d.ts +0 -1
- package/_types/core/actions/decrypt/index.d.ts.map +1 -1
- package/_types/core/actions/host/index.d.ts +0 -4
- package/_types/core/actions/host/index.d.ts.map +1 -1
- package/_types/core/base/cachedFetch.d.ts +1 -0
- package/_types/core/base/cachedFetch.d.ts.map +1 -1
- package/_types/core/base/uint.d.ts +2 -1
- package/_types/core/base/uint.d.ts.map +1 -1
- package/_types/core/clients/decorators/base.d.ts +12 -23
- package/_types/core/clients/decorators/base.d.ts.map +1 -1
- package/_types/core/host-contracts/canDecryptValuesFromPairs.d.ts +2 -2
- package/_types/core/host-contracts/canDecryptValuesFromPairs.d.ts.map +1 -1
- package/_types/core/kms/PublicDecryptionProof-p.d.ts +1 -1
- package/_types/core/kms/SignedDecryptionPermit-p.d.ts +15 -29
- package/_types/core/kms/SignedDecryptionPermit-p.d.ts.map +1 -1
- package/_types/core/kms/SignedDecryptionPermitV1-p.d.ts +7 -0
- package/_types/core/kms/SignedDecryptionPermitV1-p.d.ts.map +1 -0
- package/_types/core/kms/SignedDecryptionPermitV2-p.d.ts +7 -0
- package/_types/core/kms/SignedDecryptionPermitV2-p.d.ts.map +1 -0
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712V1.d.ts +15 -0
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712V1.d.ts.map +1 -0
- package/_types/core/kms/createKmsUserDecryptEip712V1.d.ts +26 -0
- package/_types/core/kms/createKmsUserDecryptEip712V1.d.ts.map +1 -0
- package/_types/core/kms/createKmsUserDecryptEip712V2.d.ts +1 -1
- package/_types/core/kms/createKmsUserDecryptEip712V2.d.ts.map +1 -1
- package/_types/core/kms/decryptValuesFromPairs.d.ts +4 -11
- package/_types/core/kms/decryptValuesFromPairs.d.ts.map +1 -1
- package/_types/core/kms/{fetchKmsSigncryptedShares-p.d.ts → fetchKmsSigncryptedSharesV1-p.d.ts} +10 -12
- package/_types/core/kms/fetchKmsSigncryptedSharesV1-p.d.ts.map +1 -0
- package/_types/core/kms/fetchKmsSigncryptedSharesV2-p.d.ts +28 -0
- package/_types/core/kms/fetchKmsSigncryptedSharesV2-p.d.ts.map +1 -0
- package/_types/core/kms/kmsDelegatedUserDecryptEip712V1Types.d.ts +3 -0
- package/_types/core/kms/kmsDelegatedUserDecryptEip712V1Types.d.ts.map +1 -0
- package/_types/core/kms/kmsUserDecryptEip712V1Types.d.ts +3 -0
- package/_types/core/kms/kmsUserDecryptEip712V1Types.d.ts.map +1 -0
- package/_types/core/kms/kmsUserDecryptEip712V2Types.d.ts.map +1 -1
- package/_types/core/kms/utils.d.ts +0 -4
- package/_types/core/kms/utils.d.ts.map +1 -1
- package/_types/core/kms/verifyKmsPublicDecryptEip712-p.d.ts +1 -1
- package/_types/core/modules/encrypt/module/init-p.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/module/{fetchDelegatedUserDecrypt.d.ts → fetchDelegatedUserDecryptV1.d.ts} +1 -1
- package/_types/core/modules/relayer/module/fetchDelegatedUserDecryptV1.d.ts.map +1 -0
- package/_types/core/modules/relayer/module/fetchUserDecrypt.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/fetchUserDecryptV1.d.ts +3 -0
- package/_types/core/modules/relayer/module/fetchUserDecryptV1.d.ts.map +1 -0
- package/_types/core/modules/relayer/module/fetchUserDecryptV2.d.ts +3 -0
- package/_types/core/modules/relayer/module/fetchUserDecryptV2.d.ts.map +1 -0
- package/_types/core/modules/relayer/module/guards/RelayerResponseFailed.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.d.ts +1 -1
- package/_types/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/guards/api-errors/RelayerApiError503.d.ts.map +1 -1
- package/_types/core/modules/relayer/types.d.ts +18 -5
- package/_types/core/modules/relayer/types.d.ts.map +1 -1
- package/_types/core/types/kms.d.ts +18 -19
- package/_types/core/types/kms.d.ts.map +1 -1
- package/_types/core/types/logger.d.ts +3 -3
- package/_types/core/types/logger.d.ts.map +1 -1
- package/_types/core/types/record-p.d.ts +2 -1
- package/_types/core/types/record-p.d.ts.map +1 -1
- package/_types/core/types/relayer-p.d.ts +27 -5
- package/_types/core/types/relayer-p.d.ts.map +1 -1
- package/_types/core/types/signedDecryptionPermit.d.ts +37 -26
- package/_types/core/types/signedDecryptionPermit.d.ts.map +1 -1
- package/_types/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712V1.d.ts +14 -0
- package/_types/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712V1.d.ts.map +1 -0
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712V1.d.ts +14 -0
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712V1.d.ts.map +1 -0
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.d.ts +14 -0
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.d.ts.map +1 -0
- package/_types/core/utils-p/runtime/recoverSigners.d.ts +2 -2
- package/core/_version.ts +1 -1
- package/core/actions/base/index.ts +0 -42
- package/core/actions/base/signDecryptionPermit.ts +3 -31
- package/core/actions/chain/index.ts +0 -28
- package/core/actions/chain/parseSignedDecryptionPermit.ts +1 -0
- package/core/actions/chain/serializeSignedDecryptionPermit.ts +3 -2
- package/core/actions/decrypt/canDecryptValue.ts +2 -16
- package/core/actions/decrypt/canDecryptValues.ts +2 -16
- package/core/actions/decrypt/canDecryptValuesFromPairs.ts +2 -16
- package/core/actions/decrypt/decryptValue.ts +2 -1
- package/core/actions/decrypt/decryptValues.ts +3 -1
- package/core/actions/decrypt/decryptValuesFromPairs.ts +3 -1
- package/core/actions/decrypt/index.ts +0 -6
- package/core/actions/host/index.ts +0 -20
- package/core/base/cachedFetch.ts +1 -0
- package/core/base/uint.ts +18 -1
- package/core/clients/decorators/base.ts +13 -37
- package/core/coprocessor/coprocessorEip712Types.ts +2 -2
- package/core/host-contracts/canDecryptValuesFromPairs.ts +7 -7
- package/core/host-contracts/getCoprocessorContextSignersAndThreshold-p.ts +2 -2
- package/core/host-contracts/getCurrentKmsContextAndEpoch-p.ts +2 -2
- package/core/host-contracts/getCurrentKmsContextId-p.ts +2 -2
- package/core/host-contracts/getKmsContextSignersAndThreshold-p.ts +2 -2
- package/core/kms/PublicDecryptionProof-p.ts +5 -5
- package/core/kms/SignedDecryptionPermit-p.ts +67 -357
- package/core/kms/SignedDecryptionPermitV1-p.ts +350 -0
- package/core/kms/SignedDecryptionPermitV2-p.ts +292 -0
- package/core/kms/{createKmsDelegatedUserDecryptEip712.ts → createKmsDelegatedUserDecryptEip712V1.ts} +16 -16
- package/core/kms/createKmsPublicDecryptEip712.ts +1 -1
- package/core/kms/{createKmsUserDecryptEip712.ts → createKmsUserDecryptEip712V1.ts} +26 -24
- package/core/kms/createKmsUserDecryptEip712V2.ts +1 -1
- package/core/kms/decryptValuesFromPairs.ts +34 -22
- package/core/kms/{fetchKmsSigncryptedShares-p.ts → fetchKmsSigncryptedSharesV1-p.ts} +35 -30
- package/core/kms/fetchKmsSigncryptedSharesV2-p.ts +176 -0
- package/core/kms/{kmsDelegatedUserDecryptEip712Types.ts → kmsDelegatedUserDecryptEip712V1Types.ts} +9 -8
- package/core/kms/kmsPublicDecryptEip712Types.ts +1 -1
- package/core/kms/{kmsUserDecryptEip712Types.ts → kmsUserDecryptEip712V1Types.ts} +9 -8
- package/core/kms/kmsUserDecryptEip712V2Types.ts +2 -1
- package/core/kms/publicDecrypt.ts +2 -2
- package/core/kms/utils.ts +0 -32
- package/core/kms/verifyKmsPublicDecryptEip712-p.ts +3 -3
- package/core/modules/decrypt/module/api-p.ts +8 -8
- package/core/modules/decrypt/module/init-p.ts +7 -7
- package/core/modules/encrypt/module/init-p.ts +16 -11
- package/core/modules/relayer/cleartext/fetchPublicDecrypt.ts +3 -3
- package/core/modules/relayer/cleartext/fetchUserDecrypt.ts +2 -2
- package/core/modules/relayer/module/fetchPublicDecrypt.ts +1 -1
- package/core/modules/relayer/module/fetchUserDecrypt.ts +20 -56
- package/core/modules/relayer/module/fetchUserDecryptV1.ts +69 -0
- package/core/modules/relayer/module/fetchUserDecryptV2.ts +71 -0
- package/core/modules/relayer/module/guards/RelayerResponseFailed.ts +10 -2
- package/core/modules/relayer/module/guards/api-errors/RelayerApiError400NoDetails.ts +6 -3
- package/core/modules/relayer/module/guards/api-errors/RelayerApiError503.ts +2 -0
- package/core/modules/relayer/module/index.ts +1 -1
- package/core/modules/relayer/types.ts +24 -5
- package/core/runtime/HyperWasmSolver-p.ts +1 -5
- package/core/types/kms.ts +40 -28
- package/core/types/logger.ts +3 -3
- package/core/types/record-p.ts +2 -1
- package/core/types/relayer-p.ts +48 -5
- package/core/types/signedDecryptionPermit.ts +47 -26
- package/core/utils-p/decrypt/{verifyKmsDelegatedUserDecryptEip712.ts → verifyKmsDelegatedUserDecryptEip712V1.ts} +9 -9
- package/core/utils-p/decrypt/{verifyKmsUserDecryptEip712.ts → verifyKmsUserDecryptEip712V1.ts} +9 -9
- package/core/utils-p/decrypt/verifyKmsUserDecryptEip712V2.ts +43 -0
- package/core/utils-p/runtime/recoverSigners.ts +2 -2
- package/package.json +1 -1
- package/_cjs/core/actions/base/createVerifiedInputProofFromRawBytes.js +0 -10
- package/_cjs/core/actions/base/createVerifiedInputProofFromRawBytes.js.map +0 -1
- package/_cjs/core/actions/base/fetchKmsSigncryptedShares.js +0 -19
- package/_cjs/core/actions/base/fetchKmsSigncryptedShares.js.map +0 -1
- package/_cjs/core/actions/base/fetchVerifiedInputProof.js +0 -11
- package/_cjs/core/actions/base/fetchVerifiedInputProof.js.map +0 -1
- package/_cjs/core/actions/base/readKmsSignersContext.js +0 -11
- package/_cjs/core/actions/base/readKmsSignersContext.js.map +0 -1
- package/_cjs/core/actions/base/verifyHandlesCoprocessorSignatures.js +0 -31
- package/_cjs/core/actions/base/verifyHandlesCoprocessorSignatures.js.map +0 -1
- package/_cjs/core/actions/base/verifyInputProof.js +0 -24
- package/_cjs/core/actions/base/verifyInputProof.js.map +0 -1
- package/_cjs/core/actions/base/verifyZkProofCoprocessorSignatures.js +0 -17
- package/_cjs/core/actions/base/verifyZkProofCoprocessorSignatures.js.map +0 -1
- package/_cjs/core/actions/chain/createCoprocessorEip712Domain.js +0 -11
- package/_cjs/core/actions/chain/createCoprocessorEip712Domain.js.map +0 -1
- package/_cjs/core/actions/chain/createKmsDelegatedUserDecryptEip712.js +0 -17
- package/_cjs/core/actions/chain/createKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_cjs/core/actions/chain/createKmsEip712Domain.js +0 -11
- package/_cjs/core/actions/chain/createKmsEip712Domain.js.map +0 -1
- package/_cjs/core/actions/chain/createKmsUserDecryptEip712.js +0 -16
- package/_cjs/core/actions/chain/createKmsUserDecryptEip712.js.map +0 -1
- package/_cjs/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.js +0 -8
- package/_cjs/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_cjs/core/actions/chain/verifyKmsUserDecryptEip712.js +0 -8
- package/_cjs/core/actions/chain/verifyKmsUserDecryptEip712.js.map +0 -1
- package/_cjs/core/actions/decrypt/decryptKmsSigncryptedShares.js +0 -13
- package/_cjs/core/actions/decrypt/decryptKmsSigncryptedShares.js.map +0 -1
- package/_cjs/core/kms/createKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_cjs/core/kms/createKmsUserDecryptEip712.js.map +0 -1
- package/_cjs/core/kms/fetchKmsSigncryptedShares-p.js.map +0 -1
- package/_cjs/core/kms/kmsDelegatedUserDecryptEip712Types.js.map +0 -1
- package/_cjs/core/kms/kmsUserDecryptEip712Types.js.map +0 -1
- package/_cjs/core/modules/relayer/module/fetchDelegatedUserDecrypt.js.map +0 -1
- package/_cjs/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_cjs/core/utils-p/decrypt/verifyKmsUserDecryptEip712.js.map +0 -1
- package/_esm/core/actions/base/createVerifiedInputProofFromRawBytes.js +0 -7
- package/_esm/core/actions/base/createVerifiedInputProofFromRawBytes.js.map +0 -1
- package/_esm/core/actions/base/fetchKmsSigncryptedShares.js +0 -17
- package/_esm/core/actions/base/fetchKmsSigncryptedShares.js.map +0 -1
- package/_esm/core/actions/base/fetchVerifiedInputProof.js +0 -8
- package/_esm/core/actions/base/fetchVerifiedInputProof.js.map +0 -1
- package/_esm/core/actions/base/readKmsSignersContext.js +0 -10
- package/_esm/core/actions/base/readKmsSignersContext.js.map +0 -1
- package/_esm/core/actions/base/verifyHandlesCoprocessorSignatures.js +0 -35
- package/_esm/core/actions/base/verifyHandlesCoprocessorSignatures.js.map +0 -1
- package/_esm/core/actions/base/verifyInputProof.js +0 -22
- package/_esm/core/actions/base/verifyInputProof.js.map +0 -1
- package/_esm/core/actions/base/verifyZkProofCoprocessorSignatures.js +0 -14
- package/_esm/core/actions/base/verifyZkProofCoprocessorSignatures.js.map +0 -1
- package/_esm/core/actions/chain/createCoprocessorEip712Domain.js +0 -8
- package/_esm/core/actions/chain/createCoprocessorEip712Domain.js.map +0 -1
- package/_esm/core/actions/chain/createKmsDelegatedUserDecryptEip712.js +0 -15
- package/_esm/core/actions/chain/createKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_esm/core/actions/chain/createKmsEip712Domain.js +0 -8
- package/_esm/core/actions/chain/createKmsEip712Domain.js.map +0 -1
- package/_esm/core/actions/chain/createKmsUserDecryptEip712.js +0 -14
- package/_esm/core/actions/chain/createKmsUserDecryptEip712.js.map +0 -1
- package/_esm/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.js +0 -5
- package/_esm/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_esm/core/actions/chain/verifyKmsUserDecryptEip712.js +0 -5
- package/_esm/core/actions/chain/verifyKmsUserDecryptEip712.js.map +0 -1
- package/_esm/core/actions/decrypt/decryptKmsSigncryptedShares.js +0 -11
- package/_esm/core/actions/decrypt/decryptKmsSigncryptedShares.js.map +0 -1
- package/_esm/core/kms/createKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_esm/core/kms/createKmsUserDecryptEip712.js.map +0 -1
- package/_esm/core/kms/fetchKmsSigncryptedShares-p.js.map +0 -1
- package/_esm/core/kms/kmsDelegatedUserDecryptEip712Types.js.map +0 -1
- package/_esm/core/kms/kmsUserDecryptEip712Types.js.map +0 -1
- package/_esm/core/modules/relayer/module/fetchDelegatedUserDecrypt.js.map +0 -1
- package/_esm/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712.js.map +0 -1
- package/_esm/core/utils-p/decrypt/verifyKmsUserDecryptEip712.js.map +0 -1
- package/_types/core/actions/base/createVerifiedInputProofFromRawBytes.d.ts +0 -14
- package/_types/core/actions/base/createVerifiedInputProofFromRawBytes.d.ts.map +0 -1
- package/_types/core/actions/base/fetchKmsSigncryptedShares.d.ts +0 -41
- package/_types/core/actions/base/fetchKmsSigncryptedShares.d.ts.map +0 -1
- package/_types/core/actions/base/fetchVerifiedInputProof.d.ts +0 -14
- package/_types/core/actions/base/fetchVerifiedInputProof.d.ts.map +0 -1
- package/_types/core/actions/base/readKmsSignersContext.d.ts +0 -6
- package/_types/core/actions/base/readKmsSignersContext.d.ts.map +0 -1
- package/_types/core/actions/base/verifyHandlesCoprocessorSignatures.d.ts +0 -14
- package/_types/core/actions/base/verifyHandlesCoprocessorSignatures.d.ts.map +0 -1
- package/_types/core/actions/base/verifyInputProof.d.ts +0 -14
- package/_types/core/actions/base/verifyInputProof.d.ts.map +0 -1
- package/_types/core/actions/base/verifyZkProofCoprocessorSignatures.d.ts +0 -11
- package/_types/core/actions/base/verifyZkProofCoprocessorSignatures.d.ts.map +0 -1
- package/_types/core/actions/chain/createCoprocessorEip712Domain.d.ts +0 -7
- package/_types/core/actions/chain/createCoprocessorEip712Domain.d.ts.map +0 -1
- package/_types/core/actions/chain/createKmsDelegatedUserDecryptEip712.d.ts +0 -15
- package/_types/core/actions/chain/createKmsDelegatedUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/actions/chain/createKmsEip712Domain.d.ts +0 -7
- package/_types/core/actions/chain/createKmsEip712Domain.d.ts.map +0 -1
- package/_types/core/actions/chain/createKmsUserDecryptEip712.d.ts +0 -14
- package/_types/core/actions/chain/createKmsUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.d.ts +0 -7
- package/_types/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/actions/chain/verifyKmsUserDecryptEip712.d.ts +0 -7
- package/_types/core/actions/chain/verifyKmsUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/actions/decrypt/decryptKmsSigncryptedShares.d.ts +0 -13
- package/_types/core/actions/decrypt/decryptKmsSigncryptedShares.d.ts.map +0 -1
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712.d.ts +0 -15
- package/_types/core/kms/createKmsDelegatedUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/kms/createKmsUserDecryptEip712.d.ts +0 -26
- package/_types/core/kms/createKmsUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/kms/fetchKmsSigncryptedShares-p.d.ts.map +0 -1
- package/_types/core/kms/kmsDelegatedUserDecryptEip712Types.d.ts +0 -3
- package/_types/core/kms/kmsDelegatedUserDecryptEip712Types.d.ts.map +0 -1
- package/_types/core/kms/kmsUserDecryptEip712Types.d.ts +0 -3
- package/_types/core/kms/kmsUserDecryptEip712Types.d.ts.map +0 -1
- package/_types/core/modules/relayer/module/fetchDelegatedUserDecrypt.d.ts.map +0 -1
- package/_types/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712.d.ts +0 -14
- package/_types/core/utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712.d.ts.map +0 -1
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712.d.ts +0 -14
- package/_types/core/utils-p/decrypt/verifyKmsUserDecryptEip712.d.ts.map +0 -1
- package/core/actions/base/createVerifiedInputProofFromRawBytes.ts +0 -24
- package/core/actions/base/fetchKmsSigncryptedShares.ts +0 -83
- package/core/actions/base/fetchVerifiedInputProof.ts +0 -25
- package/core/actions/base/readKmsSignersContext.ts +0 -20
- package/core/actions/base/verifyHandlesCoprocessorSignatures.ts +0 -60
- package/core/actions/base/verifyInputProof.ts +0 -45
- package/core/actions/base/verifyZkProofCoprocessorSignatures.ts +0 -32
- package/core/actions/chain/createCoprocessorEip712Domain.ts +0 -16
- package/core/actions/chain/createKmsDelegatedUserDecryptEip712.ts +0 -36
- package/core/actions/chain/createKmsEip712Domain.ts +0 -16
- package/core/actions/chain/createKmsUserDecryptEip712.ts +0 -34
- package/core/actions/chain/verifyKmsDelegatedUserDecryptEip712.ts +0 -16
- package/core/actions/chain/verifyKmsUserDecryptEip712.ts +0 -16
- package/core/actions/decrypt/decryptKmsSigncryptedShares.ts +0 -34
- /package/core/modules/relayer/module/{fetchDelegatedUserDecrypt.ts → fetchDelegatedUserDecryptV1.ts} +0 -0
|
@@ -1,108 +1,9 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _SignedDecryptionPermitBaseImpl_eip712, _SignedDecryptionPermitBaseImpl_signature, _SignedDecryptionPermitBaseImpl_signerAddress;
|
|
13
|
-
import { verifyKmsUserDecryptEip712 } from '../utils-p/decrypt/verifyKmsUserDecryptEip712.js';
|
|
14
|
-
import { verifyKmsDelegatedUserDecryptEip712 } from '../utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712.js';
|
|
15
|
-
import { assertRecordNonNullableProperty } from '../base/record.js';
|
|
16
|
-
import { assertRecordBytes65HexProperty } from '../base/bytes.js';
|
|
17
1
|
import { InvalidTypeError } from '../base/errors/InvalidTypeError.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { assertKmsEIP712DeadlineValidity } from './utils.js';
|
|
24
|
-
import { readKmsSignersContext } from '../host-contracts/readKmsSignersContext-p.js';
|
|
25
|
-
import { kmsSignersContextToExtraData } from '../host-contracts/KmsSignersContext-p.js';
|
|
26
|
-
import { fromKmsExtraData } from './kmsExtraData.js';
|
|
27
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
28
|
-
const PRIVATE_TOKEN = Symbol('SignedDecryptionPermit.token');
|
|
29
|
-
const MAX_USER_DECRYPT_DURATION_DAYS = 365;
|
|
30
|
-
const MAX_USER_DECRYPT_CONTRACT_ADDRESSES = 10;
|
|
31
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
32
|
-
/**
|
|
33
|
-
* Private implementation of {@link SignedDecryptionPermit}.
|
|
34
|
-
* Immutable by design — all fields are stored as private properties
|
|
35
|
-
* and exposed via readonly getters. Instances are only created through
|
|
36
|
-
* SDK-internal factory functions that guarantee the signature has been verified.
|
|
37
|
-
*
|
|
38
|
-
* **Invariant:** Every instance of this class has a verified signature.
|
|
39
|
-
* Construction is only possible through factory functions that validate the
|
|
40
|
-
* signature against the on-chain verifier before returning. If the EIP-712
|
|
41
|
-
* format has changed (e.g. loading a permit serialized by an older SDK version),
|
|
42
|
-
* verification will fail and construction will throw.
|
|
43
|
-
*
|
|
44
|
-
* As a consequence, any code within the SDK that receives a
|
|
45
|
-
* `SignedDecryptionPermit` (verified via `instanceof`) can safely trust
|
|
46
|
-
* its contents without re-verification.
|
|
47
|
-
*/
|
|
48
|
-
class SignedDecryptionPermitBaseImpl {
|
|
49
|
-
constructor(privateToken, parameters) {
|
|
50
|
-
_SignedDecryptionPermitBaseImpl_eip712.set(this, void 0);
|
|
51
|
-
_SignedDecryptionPermitBaseImpl_signature.set(this, void 0);
|
|
52
|
-
_SignedDecryptionPermitBaseImpl_signerAddress.set(this, void 0);
|
|
53
|
-
if (privateToken !== PRIVATE_TOKEN) {
|
|
54
|
-
throw new Error('Unauthorized');
|
|
55
|
-
}
|
|
56
|
-
__classPrivateFieldSet(this, _SignedDecryptionPermitBaseImpl_eip712, parameters.eip712, "f");
|
|
57
|
-
__classPrivateFieldSet(this, _SignedDecryptionPermitBaseImpl_signature, parameters.signature, "f");
|
|
58
|
-
__classPrivateFieldSet(this, _SignedDecryptionPermitBaseImpl_signerAddress, parameters.signerAddress, "f");
|
|
59
|
-
}
|
|
60
|
-
get eip712() {
|
|
61
|
-
return __classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f");
|
|
62
|
-
}
|
|
63
|
-
get signature() {
|
|
64
|
-
return __classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_signature, "f");
|
|
65
|
-
}
|
|
66
|
-
get signerAddress() {
|
|
67
|
-
return __classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_signerAddress, "f");
|
|
68
|
-
}
|
|
69
|
-
assertNotExpired() {
|
|
70
|
-
assertKmsEIP712DeadlineValidity(__classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message, MAX_USER_DECRYPT_DURATION_DAYS);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Asserts that this permit was signed against the given {@link KmsSignersContext}.
|
|
74
|
-
*
|
|
75
|
-
* Compares the `extraData` embedded in the permit's EIP-712 message with the
|
|
76
|
-
* `extraData` derived from the provided context. A mismatch indicates the permit
|
|
77
|
-
* was created for a different KMS context (e.g. different context ID or version)
|
|
78
|
-
* and must not be used for decryption.
|
|
79
|
-
*
|
|
80
|
-
* @todo The current check is a strict byte-level comparison. A permit signed
|
|
81
|
-
* with the correct `kmsContextId` but a different `extraData` encoding format
|
|
82
|
-
* (e.g. a version change in the serialization scheme) will be rejected even
|
|
83
|
-
* though the context ID matches. Consider comparing the decoded `kmsContextId`
|
|
84
|
-
* instead of the raw `extraData` bytes.
|
|
85
|
-
*
|
|
86
|
-
* @param kmsSignersContext - The current KMS signers context to validate against.
|
|
87
|
-
* @throws If the permit's `extraData` does not match the context's `extraData`.
|
|
88
|
-
*/
|
|
89
|
-
assertMatchesKmsContext(kmsSignersContext) {
|
|
90
|
-
const expectedExtraData = kmsSignersContextToExtraData(kmsSignersContext);
|
|
91
|
-
if (expectedExtraData !== __classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message.extraData) {
|
|
92
|
-
throw new Error(`Invalid permit: extraData "${__classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message.extraData}" does not match expected "${expectedExtraData}" from KmsSignersContext.`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
get transportPublicKey() {
|
|
96
|
-
return __classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message.publicKey;
|
|
97
|
-
}
|
|
98
|
-
get kmsContextId() {
|
|
99
|
-
return fromKmsExtraData(__classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message.extraData).kmsContextId;
|
|
100
|
-
}
|
|
101
|
-
get kmsEpochId() {
|
|
102
|
-
return fromKmsExtraData(__classPrivateFieldGet(this, _SignedDecryptionPermitBaseImpl_eip712, "f").message.extraData).kmsEpochId;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
_SignedDecryptionPermitBaseImpl_eip712 = new WeakMap(), _SignedDecryptionPermitBaseImpl_signature = new WeakMap(), _SignedDecryptionPermitBaseImpl_signerAddress = new WeakMap();
|
|
2
|
+
import { getResolvedProtocolVersion } from '../runtime/CoreFhevm-p.js';
|
|
3
|
+
import { isSemverStrictlyBefore } from '../base/semver.js';
|
|
4
|
+
import { isSignedDecryptionPermitV1, parseSignedDecryptionPermitV1, signDecryptionPermitV1, } from './SignedDecryptionPermitV1-p.js';
|
|
5
|
+
import { isSignedDecryptionPermitV2, parseSignedDecryptionPermitV2, signDecryptionPermitV2, } from './SignedDecryptionPermitV2-p.js';
|
|
6
|
+
import { isRecordUintNumberProperty } from '../base/uint.js';
|
|
106
7
|
////////////////////////////////////////////////////////////////////////////////
|
|
107
8
|
/**
|
|
108
9
|
* Serializes a signed decryption permit to a plain object suitable for
|
|
@@ -113,52 +14,32 @@ _SignedDecryptionPermitBaseImpl_eip712 = new WeakMap(), _SignedDecryptionPermitB
|
|
|
113
14
|
*/
|
|
114
15
|
export function serializeSignedDecryptionPermitToJSON(permit) {
|
|
115
16
|
assertIsSignedDecryptionPermit(permit, {});
|
|
17
|
+
// Defensive check
|
|
18
|
+
const version = permit.version;
|
|
19
|
+
if (version !== 1 && version !== 2) {
|
|
20
|
+
throw new Error(`Unsupported permit version: ${version}. Supported versions are 1 and 2.`);
|
|
21
|
+
}
|
|
22
|
+
// This if branch is needed for tsc
|
|
23
|
+
if (permit.version === 1) {
|
|
24
|
+
return {
|
|
25
|
+
version: 1,
|
|
26
|
+
eip712: permit.eip712,
|
|
27
|
+
signature: permit.signature,
|
|
28
|
+
signerAddress: permit.signerAddress,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
116
31
|
return {
|
|
32
|
+
version: 2,
|
|
117
33
|
eip712: permit.eip712,
|
|
118
34
|
signature: permit.signature,
|
|
119
35
|
signerAddress: permit.signerAddress,
|
|
120
36
|
};
|
|
121
37
|
}
|
|
122
38
|
////////////////////////////////////////////////////////////////////////////////
|
|
123
|
-
// SignedUserDecryptionPermitImpl
|
|
124
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
125
|
-
class SignedSelfDecryptionPermitImpl extends SignedDecryptionPermitBaseImpl {
|
|
126
|
-
get eip712() {
|
|
127
|
-
return super.eip712;
|
|
128
|
-
}
|
|
129
|
-
get encryptedDataOwnerAddress() {
|
|
130
|
-
return this.signerAddress;
|
|
131
|
-
}
|
|
132
|
-
get isDelegated() {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
137
|
-
// SignedDelegatedDecryptionPermitImpl
|
|
138
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
139
|
-
class SignedDelegatedDecryptionPermitImpl extends SignedDecryptionPermitBaseImpl {
|
|
140
|
-
get eip712() {
|
|
141
|
-
return super.eip712;
|
|
142
|
-
}
|
|
143
|
-
get encryptedDataOwnerAddress() {
|
|
144
|
-
return this.eip712.message.delegatorAddress;
|
|
145
|
-
}
|
|
146
|
-
get isDelegated() {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
151
|
-
Object.freeze(SignedDecryptionPermitBaseImpl);
|
|
152
|
-
Object.freeze(SignedDecryptionPermitBaseImpl.prototype);
|
|
153
|
-
Object.freeze(SignedSelfDecryptionPermitImpl);
|
|
154
|
-
Object.freeze(SignedSelfDecryptionPermitImpl.prototype);
|
|
155
|
-
Object.freeze(SignedDelegatedDecryptionPermitImpl);
|
|
156
|
-
Object.freeze(SignedDelegatedDecryptionPermitImpl.prototype);
|
|
157
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
158
39
|
// isSignedDecryptionPermit
|
|
159
40
|
////////////////////////////////////////////////////////////////////////////////
|
|
160
41
|
export function isSignedDecryptionPermit(value) {
|
|
161
|
-
return value
|
|
42
|
+
return isSignedDecryptionPermitV1(value) || isSignedDecryptionPermitV2(value);
|
|
162
43
|
}
|
|
163
44
|
/** Throws {@link InvalidTypeError} if value is not a valid {@link SignedDecryptionPermit}. */
|
|
164
45
|
export function assertIsSignedDecryptionPermit(value, options) {
|
|
@@ -171,120 +52,42 @@ export function assertIsSignedDecryptionPermit(value, options) {
|
|
|
171
52
|
}
|
|
172
53
|
}
|
|
173
54
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
55
|
+
* Creates a signed decryption permit by constructing the EIP-712 typed data
|
|
56
|
+
* and signing it with the provided signer.
|
|
57
|
+
*
|
|
58
|
+
* If `delegatorAddress` is provided, creates a delegated permit that allows the signer
|
|
59
|
+
* to decrypt encrypted values belonging to the `delegatorAddress` account.
|
|
60
|
+
* Otherwise, creates a standard permit where the signer decrypts their own values.
|
|
61
|
+
*
|
|
62
|
+
* The EIP-712 message includes the key pair's public key, allowing the gateway
|
|
63
|
+
* to encrypt the decrypted result for this specific key pair.
|
|
64
|
+
*
|
|
65
|
+
* @throws If the signer, address, or key pair is invalid.
|
|
66
|
+
* @throws If the signature verification fails.
|
|
176
67
|
*/
|
|
177
|
-
export function assertPermitIncludesContractAddresses(permit, contractAddresses) {
|
|
178
|
-
const permitAddresses = permit.eip712.message.contractAddresses;
|
|
179
|
-
for (const address of contractAddresses) {
|
|
180
|
-
if (!permitAddresses.some((a) => a.toLowerCase() === address.toLowerCase())) {
|
|
181
|
-
throw Error(`contract address ${address} is not listed in the permit's contractAddresses`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
186
|
-
// createSignedDecryptionPermit
|
|
187
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
188
|
-
async function _createSignedDecryptionPermit(context, parameters) {
|
|
189
|
-
const { signerAddress, eip712, signature } = parameters;
|
|
190
|
-
if (eip712.message.contractAddresses.length === 0) {
|
|
191
|
-
throw Error('contractAddresses is empty');
|
|
192
|
-
}
|
|
193
|
-
if (eip712.message.contractAddresses.length > MAX_USER_DECRYPT_CONTRACT_ADDRESSES) {
|
|
194
|
-
throw Error(`contractAddresses max length of ${MAX_USER_DECRYPT_CONTRACT_ADDRESSES} exceeded`);
|
|
195
|
-
}
|
|
196
|
-
if (Number(eip712.message.durationDays) > MAX_USER_DECRYPT_DURATION_DAYS) {
|
|
197
|
-
throw Error(`durationDays is above max duration of ${MAX_USER_DECRYPT_DURATION_DAYS}`);
|
|
198
|
-
}
|
|
199
|
-
if (eip712.primaryType === 'UserDecryptRequestVerification') {
|
|
200
|
-
await verifyKmsUserDecryptEip712(context, {
|
|
201
|
-
signer: signerAddress,
|
|
202
|
-
message: eip712.message,
|
|
203
|
-
signature,
|
|
204
|
-
});
|
|
205
|
-
return new SignedSelfDecryptionPermitImpl(PRIVATE_TOKEN, parameters);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
await verifyKmsDelegatedUserDecryptEip712(context, {
|
|
209
|
-
signer: signerAddress,
|
|
210
|
-
message: eip712.message,
|
|
211
|
-
signature,
|
|
212
|
-
});
|
|
213
|
-
return new SignedDelegatedDecryptionPermitImpl(PRIVATE_TOKEN, parameters);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
68
|
export async function signDecryptionPermit(context, parameters) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
221
|
-
const extraData = kmsSignersContextToExtraData(kmsSignersContext);
|
|
222
|
-
const { contractAddresses, startTimestamp, durationDays, signerAddress: signerAddressArg, transportKeyPair: transportKeyPair, signer, delegatorAddress, } = parameters;
|
|
223
|
-
assertIsTransportKeyPair(transportKeyPair, {});
|
|
224
|
-
assertIsAddress(signerAddressArg, {});
|
|
225
|
-
if (delegatorAddress !== undefined) {
|
|
226
|
-
assertIsAddress(delegatorAddress, {});
|
|
227
|
-
if (signerAddressArg.toLowerCase() === delegatorAddress.toLowerCase()) {
|
|
228
|
-
throw new Error('signerAddress and delegatorAddress must be different. ' +
|
|
229
|
-
'Use a non-delegated permit to decrypt your own values.');
|
|
230
|
-
}
|
|
69
|
+
const protocolVersion = getResolvedProtocolVersion(context);
|
|
70
|
+
if (protocolVersion === undefined) {
|
|
71
|
+
throw new Error('Unable to resolve protocol version from context, ensure proper initialization of the FhevmRuntime and FhevmChain.');
|
|
231
72
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
contractAddresses,
|
|
237
|
-
durationDays,
|
|
238
|
-
startTimestamp,
|
|
239
|
-
extraData,
|
|
240
|
-
publicKey: transportKeyPair.publicKey,
|
|
241
|
-
};
|
|
242
|
-
const eip712 = delegatorAddress !== undefined
|
|
243
|
-
? createKmsDelegatedUserDecryptEip712({
|
|
244
|
-
...commonMessage,
|
|
245
|
-
delegatorAddress,
|
|
246
|
-
})
|
|
247
|
-
: createKmsUserDecryptEip712(commonMessage);
|
|
248
|
-
const signature = await context.runtime.ethereum.signTypedData(signer, {
|
|
249
|
-
account: signerAddress,
|
|
250
|
-
...eip712,
|
|
251
|
-
});
|
|
252
|
-
return await _createSignedDecryptionPermit(context, {
|
|
253
|
-
signature,
|
|
254
|
-
signerAddress,
|
|
255
|
-
eip712,
|
|
256
|
-
});
|
|
73
|
+
if (isSemverStrictlyBefore(protocolVersion.version, '0.14.0')) {
|
|
74
|
+
return await signDecryptionPermitV1(context, parameters);
|
|
75
|
+
}
|
|
76
|
+
return await signDecryptionPermitV2(context, parameters);
|
|
257
77
|
}
|
|
258
78
|
////////////////////////////////////////////////////////////////////////////////
|
|
259
79
|
// parseSignedDecryptionPermit
|
|
260
80
|
////////////////////////////////////////////////////////////////////////////////
|
|
261
81
|
export async function parseSignedDecryptionPermit(context, transportKeyPair, permit) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
assertRecordAddressProperty(permit, 'signerAddress', permitName, options);
|
|
268
|
-
const eip712 = permit.eip712;
|
|
269
|
-
assertRecordStringProperty(eip712, 'primaryType', `${permitName}.eip712`, options);
|
|
270
|
-
const primaryType = eip712.primaryType;
|
|
271
|
-
if (primaryType === 'UserDecryptRequestVerification') {
|
|
272
|
-
assertIsKmsUserDecryptEip712(eip712, `${permitName}.eip712`, options);
|
|
82
|
+
const hasVersion = isRecordUintNumberProperty(permit, 'version');
|
|
83
|
+
// if no version, interpret as permit v1
|
|
84
|
+
const version = hasVersion ? permit.version : 1;
|
|
85
|
+
if (version === 1) {
|
|
86
|
+
return await parseSignedDecryptionPermitV1(context, transportKeyPair, permit);
|
|
273
87
|
}
|
|
274
|
-
|
|
275
|
-
|
|
88
|
+
if (version === 2) {
|
|
89
|
+
return await parseSignedDecryptionPermitV2(context, transportKeyPair, permit);
|
|
276
90
|
}
|
|
277
|
-
|
|
278
|
-
throw new Error(`Unknown permit primaryType: ${primaryType}`);
|
|
279
|
-
}
|
|
280
|
-
if (eip712.message.publicKey.toLowerCase() !== transportKeyPair.publicKey.toLowerCase()) {
|
|
281
|
-
throw new Error("The permit's publicKey does not match the TransportKeyPairKeyPair's publicKey. " +
|
|
282
|
-
'Ensure the permit was signed with the same key pair.');
|
|
283
|
-
}
|
|
284
|
-
return await _createSignedDecryptionPermit(context, {
|
|
285
|
-
signature: permit.signature,
|
|
286
|
-
eip712,
|
|
287
|
-
signerAddress: addressToChecksummedAddress(permit.signerAddress),
|
|
288
|
-
});
|
|
91
|
+
throw new Error(`Unsupported permit version: ${version}. Supported versions are 1 and 2.`);
|
|
289
92
|
}
|
|
290
93
|
//# sourceMappingURL=SignedDecryptionPermit-p.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignedDecryptionPermit-p.js","sourceRoot":"","sources":["../../../core/kms/SignedDecryptionPermit-p.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SignedDecryptionPermit-p.js","sourceRoot":"","sources":["../../../core/kms/SignedDecryptionPermit-p.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,gFAAgF;AAEhF;;;;;;GAMG;AACH,MAAM,UAAU,qCAAqC,CAAC,MAA8B;IAalF,8BAA8B,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAE3C,kBAAkB;IAClB,MAAM,OAAO,GAAG,MAAM,CAAC,OAA4B,CAAC;IACpD,IAAI,OAAO,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,+BAA+B,OAAO,mCAAmC,CAAC,CAAC;IAC7F,CAAC;IAED,mCAAmC;IACnC,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,2BAA2B;AAC3B,gFAAgF;AAEhF,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,OAAO,0BAA0B,CAAC,KAAK,CAAC,IAAI,0BAA0B,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,8BAA8B,CAC5C,KAAc,EACd,OAAmD;IAEnD,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,gBAAgB,CACxB;YACE,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO,KAAK;YAClB,YAAY,EAAE,wBAAwB;SACvC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;AACH,CAAC;AAmBD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAoC,EACpC,UAA0C;IAE1C,MAAM,eAAe,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC5D,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;IACJ,CAAC;IAED,IAAI,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9D,OAAO,MAAM,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,MAAM,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED,gFAAgF;AAChF,8BAA8B;AAC9B,gFAAgF;AAEhF,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAoC,EACpC,gBAAkC,EAClC,MAAe;IAEf,MAAM,UAAU,GAAG,0BAA0B,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEjE,wCAAwC;IACxC,MAAM,OAAO,GAAW,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAExD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,MAAM,6BAA6B,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC;IAED,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,MAAM,6BAA6B,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,OAAO,mCAAmC,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _SignedDecryptionPermitV1Impl_eip712, _SignedDecryptionPermitV1Impl_signature, _SignedDecryptionPermitV1Impl_signerAddress;
|
|
13
|
+
import { verifyKmsUserDecryptEip712V1 } from '../utils-p/decrypt/verifyKmsUserDecryptEip712V1.js';
|
|
14
|
+
import { verifyKmsDelegatedUserDecryptEip712V1 } from '../utils-p/decrypt/verifyKmsDelegatedUserDecryptEip712V1.js';
|
|
15
|
+
import { assertRecordNonNullableProperty } from '../base/record.js';
|
|
16
|
+
import { assertRecordBytes65HexProperty } from '../base/bytes.js';
|
|
17
|
+
import { addressToChecksummedAddress, assertIsAddress, assertRecordAddressProperty } from '../base/address.js';
|
|
18
|
+
import { assertIsKmsUserDecryptEip712V1, createKmsUserDecryptEip712V1 } from './createKmsUserDecryptEip712V1.js';
|
|
19
|
+
import { assertIsKmsDelegatedUserDecryptEip712V1, createKmsDelegatedUserDecryptEip712V1, } from './createKmsDelegatedUserDecryptEip712V1.js';
|
|
20
|
+
import { assertRecordStringProperty } from '../base/string.js';
|
|
21
|
+
import { assertIsTransportKeyPair } from './TransportKeyPair-p.js';
|
|
22
|
+
import { readKmsSignersContext } from '../host-contracts/readKmsSignersContext-p.js';
|
|
23
|
+
import { kmsSignersContextToExtraData } from '../host-contracts/KmsSignersContext-p.js';
|
|
24
|
+
import { fromKmsExtraData } from './kmsExtraData.js';
|
|
25
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
26
|
+
const PRIVATE_TOKEN = Symbol('SignedDecryptionPermitV1.token');
|
|
27
|
+
const MAX_USER_DECRYPT_DURATION_DAYS = 365;
|
|
28
|
+
const MAX_USER_DECRYPT_CONTRACT_ADDRESSES = 10;
|
|
29
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
30
|
+
function assertKmsEip712V1DeadlineValidity({ startTimestamp, durationDays, }, maxDurationDays) {
|
|
31
|
+
if (durationDays === 0) {
|
|
32
|
+
throw Error('durationDays is zero');
|
|
33
|
+
}
|
|
34
|
+
const durationDaysBigInt = BigInt(durationDays);
|
|
35
|
+
if (durationDaysBigInt > BigInt(maxDurationDays)) {
|
|
36
|
+
throw Error(`durationDays is above max duration of ${maxDurationDays}`);
|
|
37
|
+
}
|
|
38
|
+
const startTimestampBigInt = BigInt(startTimestamp);
|
|
39
|
+
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
40
|
+
if (startTimestampBigInt > currentTimestamp) {
|
|
41
|
+
throw Error('startTimestamp is set in the future');
|
|
42
|
+
}
|
|
43
|
+
const durationInSeconds = durationDaysBigInt * BigInt(24 * 60 * 60);
|
|
44
|
+
if (startTimestampBigInt + durationInSeconds < currentTimestamp) {
|
|
45
|
+
throw Error('request has expired');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Private implementation of {@link SignedDecryptionPermit}.
|
|
50
|
+
* Immutable by design — all fields are stored as private properties
|
|
51
|
+
* and exposed via readonly getters. Instances are only created through
|
|
52
|
+
* SDK-internal factory functions that guarantee the signature has been verified.
|
|
53
|
+
*
|
|
54
|
+
* **Invariant:** Every instance of this class has a verified signature.
|
|
55
|
+
* Construction is only possible through factory functions that validate the
|
|
56
|
+
* signature against the on-chain verifier before returning. If the EIP-712
|
|
57
|
+
* format has changed (e.g. loading a permit serialized by an older SDK version),
|
|
58
|
+
* verification will fail and construction will throw.
|
|
59
|
+
*
|
|
60
|
+
* As a consequence, any code within the SDK that receives a
|
|
61
|
+
* `SignedDecryptionPermit` (verified via `instanceof`) can safely trust
|
|
62
|
+
* its contents without re-verification.
|
|
63
|
+
*/
|
|
64
|
+
class SignedDecryptionPermitV1Impl {
|
|
65
|
+
constructor(privateToken, parameters) {
|
|
66
|
+
_SignedDecryptionPermitV1Impl_eip712.set(this, void 0);
|
|
67
|
+
_SignedDecryptionPermitV1Impl_signature.set(this, void 0);
|
|
68
|
+
_SignedDecryptionPermitV1Impl_signerAddress.set(this, void 0);
|
|
69
|
+
Object.defineProperty(this, "version", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: 1
|
|
74
|
+
});
|
|
75
|
+
if (privateToken !== PRIVATE_TOKEN) {
|
|
76
|
+
throw new Error('Unauthorized');
|
|
77
|
+
}
|
|
78
|
+
__classPrivateFieldSet(this, _SignedDecryptionPermitV1Impl_eip712, parameters.eip712, "f");
|
|
79
|
+
__classPrivateFieldSet(this, _SignedDecryptionPermitV1Impl_signature, parameters.signature, "f");
|
|
80
|
+
__classPrivateFieldSet(this, _SignedDecryptionPermitV1Impl_signerAddress, parameters.signerAddress, "f");
|
|
81
|
+
}
|
|
82
|
+
get eip712() {
|
|
83
|
+
return __classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f");
|
|
84
|
+
}
|
|
85
|
+
get signature() {
|
|
86
|
+
return __classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_signature, "f");
|
|
87
|
+
}
|
|
88
|
+
get signerAddress() {
|
|
89
|
+
return __classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_signerAddress, "f");
|
|
90
|
+
}
|
|
91
|
+
assertNotExpired() {
|
|
92
|
+
assertKmsEip712V1DeadlineValidity(__classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message, MAX_USER_DECRYPT_DURATION_DAYS);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Asserts that this permit was signed against the given {@link KmsSignersContext}.
|
|
96
|
+
*
|
|
97
|
+
* Compares the `extraData` embedded in the permit's EIP-712 message with the
|
|
98
|
+
* `extraData` derived from the provided context. A mismatch indicates the permit
|
|
99
|
+
* was created for a different KMS context (e.g. different context ID or version)
|
|
100
|
+
* and must not be used for decryption.
|
|
101
|
+
*
|
|
102
|
+
* @todo The current check is a strict byte-level comparison. A permit signed
|
|
103
|
+
* with the correct `kmsContextId` but a different `extraData` encoding format
|
|
104
|
+
* (e.g. a version change in the serialization scheme) will be rejected even
|
|
105
|
+
* though the context ID matches. Consider comparing the decoded `kmsContextId`
|
|
106
|
+
* instead of the raw `extraData` bytes.
|
|
107
|
+
*
|
|
108
|
+
* @param kmsSignersContext - The current KMS signers context to validate against.
|
|
109
|
+
* @throws If the permit's `extraData` does not match the context's `extraData`.
|
|
110
|
+
*/
|
|
111
|
+
assertMatchesKmsContext(kmsSignersContext) {
|
|
112
|
+
const expectedExtraData = kmsSignersContextToExtraData(kmsSignersContext);
|
|
113
|
+
if (expectedExtraData !== __classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message.extraData) {
|
|
114
|
+
throw new Error(`Invalid permit: extraData "${__classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message.extraData}" does not match expected "${expectedExtraData}" from KmsSignersContext.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
get transportPublicKey() {
|
|
118
|
+
return __classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message.publicKey;
|
|
119
|
+
}
|
|
120
|
+
get kmsContextId() {
|
|
121
|
+
return fromKmsExtraData(__classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message.extraData).kmsContextId;
|
|
122
|
+
}
|
|
123
|
+
get kmsEpochId() {
|
|
124
|
+
return fromKmsExtraData(__classPrivateFieldGet(this, _SignedDecryptionPermitV1Impl_eip712, "f").message.extraData).kmsEpochId;
|
|
125
|
+
}
|
|
126
|
+
get encryptedDataOwnerAddress() {
|
|
127
|
+
if (this.eip712.primaryType === 'DelegatedUserDecryptRequestVerification') {
|
|
128
|
+
return this.eip712.message.delegatorAddress;
|
|
129
|
+
}
|
|
130
|
+
return this.signerAddress;
|
|
131
|
+
}
|
|
132
|
+
get isDelegated() {
|
|
133
|
+
return this.eip712.primaryType === 'DelegatedUserDecryptRequestVerification';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
_SignedDecryptionPermitV1Impl_eip712 = new WeakMap(), _SignedDecryptionPermitV1Impl_signature = new WeakMap(), _SignedDecryptionPermitV1Impl_signerAddress = new WeakMap();
|
|
137
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
138
|
+
Object.freeze(SignedDecryptionPermitV1Impl);
|
|
139
|
+
Object.freeze(SignedDecryptionPermitV1Impl.prototype);
|
|
140
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
141
|
+
export function isSignedDecryptionPermitV1(value) {
|
|
142
|
+
return value instanceof SignedDecryptionPermitV1Impl;
|
|
143
|
+
}
|
|
144
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
145
|
+
// _createSignedDecryptionPermitV1
|
|
146
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
147
|
+
async function _createSignedDecryptionPermitV1(context, parameters) {
|
|
148
|
+
const { signerAddress, eip712, signature } = parameters;
|
|
149
|
+
if (eip712.message.contractAddresses.length === 0) {
|
|
150
|
+
throw Error('contractAddresses is empty');
|
|
151
|
+
}
|
|
152
|
+
if (eip712.message.contractAddresses.length > MAX_USER_DECRYPT_CONTRACT_ADDRESSES) {
|
|
153
|
+
throw Error(`contractAddresses max length of ${MAX_USER_DECRYPT_CONTRACT_ADDRESSES} exceeded`);
|
|
154
|
+
}
|
|
155
|
+
if (Number(eip712.message.durationDays) > MAX_USER_DECRYPT_DURATION_DAYS) {
|
|
156
|
+
throw Error(`durationDays is above max duration of ${MAX_USER_DECRYPT_DURATION_DAYS}`);
|
|
157
|
+
}
|
|
158
|
+
if (eip712.primaryType === 'UserDecryptRequestVerification') {
|
|
159
|
+
await verifyKmsUserDecryptEip712V1(context, {
|
|
160
|
+
signer: signerAddress,
|
|
161
|
+
message: eip712.message,
|
|
162
|
+
signature,
|
|
163
|
+
});
|
|
164
|
+
return new SignedDecryptionPermitV1Impl(PRIVATE_TOKEN, parameters);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
await verifyKmsDelegatedUserDecryptEip712V1(context, {
|
|
168
|
+
signer: signerAddress,
|
|
169
|
+
message: eip712.message,
|
|
170
|
+
signature,
|
|
171
|
+
});
|
|
172
|
+
return new SignedDecryptionPermitV1Impl(PRIVATE_TOKEN, parameters);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
176
|
+
// signDecryptionPermitV1
|
|
177
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
178
|
+
export async function signDecryptionPermitV1(context, parameters) {
|
|
179
|
+
const kmsSignersContext = await readKmsSignersContext(context, {
|
|
180
|
+
kmsVerifierAddress: context.chain.fhevm.contracts.kmsVerifier.address,
|
|
181
|
+
protocolConfigAddress: context.chain.fhevm.contracts.protocolConfig?.address,
|
|
182
|
+
});
|
|
183
|
+
const extraData = kmsSignersContextToExtraData(kmsSignersContext);
|
|
184
|
+
const { contractAddresses, startTimestamp, durationSeconds, signerAddress: signerAddressArg, transportKeyPair: transportKeyPair, signer, delegatorAddress, } = parameters;
|
|
185
|
+
if (durationSeconds % 86_400 !== 0) {
|
|
186
|
+
throw new Error(`Protocol v13 requires durationSeconds to be a whole number of days, got ${durationSeconds}`);
|
|
187
|
+
}
|
|
188
|
+
const durationDays = durationSeconds / 86_400;
|
|
189
|
+
assertIsTransportKeyPair(transportKeyPair, {});
|
|
190
|
+
assertIsAddress(signerAddressArg, {});
|
|
191
|
+
if (delegatorAddress !== undefined) {
|
|
192
|
+
assertIsAddress(delegatorAddress, {});
|
|
193
|
+
if (signerAddressArg.toLowerCase() === delegatorAddress.toLowerCase()) {
|
|
194
|
+
throw new Error('signerAddress and delegatorAddress must be different. ' +
|
|
195
|
+
'Use a non-delegated permit to decrypt your own values.');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const signerAddress = addressToChecksummedAddress(signerAddressArg);
|
|
199
|
+
const commonMessage = {
|
|
200
|
+
verifyingContractAddressDecryption: context.chain.fhevm.gateway.contracts.decryption.address,
|
|
201
|
+
chainId: context.chain.id,
|
|
202
|
+
contractAddresses,
|
|
203
|
+
durationDays,
|
|
204
|
+
startTimestamp,
|
|
205
|
+
extraData,
|
|
206
|
+
publicKey: transportKeyPair.publicKey,
|
|
207
|
+
};
|
|
208
|
+
const eip712 = delegatorAddress !== undefined
|
|
209
|
+
? createKmsDelegatedUserDecryptEip712V1({
|
|
210
|
+
...commonMessage,
|
|
211
|
+
delegatorAddress,
|
|
212
|
+
})
|
|
213
|
+
: createKmsUserDecryptEip712V1(commonMessage);
|
|
214
|
+
const signature = await context.runtime.ethereum.signTypedData(signer, {
|
|
215
|
+
account: signerAddress,
|
|
216
|
+
...eip712,
|
|
217
|
+
});
|
|
218
|
+
return await _createSignedDecryptionPermitV1(context, {
|
|
219
|
+
signature,
|
|
220
|
+
signerAddress,
|
|
221
|
+
eip712,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
225
|
+
// parseSignedDecryptionPermitV1
|
|
226
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
227
|
+
export async function parseSignedDecryptionPermitV1(context, transportKeyPair, permit) {
|
|
228
|
+
assertIsTransportKeyPair(transportKeyPair, {});
|
|
229
|
+
const permitName = 'permit';
|
|
230
|
+
const options = {};
|
|
231
|
+
assertRecordNonNullableProperty(permit, 'eip712', permitName, options);
|
|
232
|
+
assertRecordBytes65HexProperty(permit, 'signature', permitName, options);
|
|
233
|
+
assertRecordAddressProperty(permit, 'signerAddress', permitName, options);
|
|
234
|
+
const eip712 = permit.eip712;
|
|
235
|
+
assertRecordStringProperty(eip712, 'primaryType', `${permitName}.eip712`, options);
|
|
236
|
+
const primaryType = eip712.primaryType;
|
|
237
|
+
const signerAddress = addressToChecksummedAddress(permit.signerAddress);
|
|
238
|
+
if (primaryType === 'UserDecryptRequestVerification') {
|
|
239
|
+
assertIsKmsUserDecryptEip712V1(eip712, `${permitName}.eip712`, options);
|
|
240
|
+
if (eip712.message.publicKey.toLowerCase() !== transportKeyPair.publicKey.toLowerCase()) {
|
|
241
|
+
throw new Error("The permit's publicKey does not match the TransportKeyPair's publicKey. " +
|
|
242
|
+
'Ensure the permit was signed with the same key pair.');
|
|
243
|
+
}
|
|
244
|
+
return await _createSignedDecryptionPermitV1(context, { signature: permit.signature, eip712, signerAddress });
|
|
245
|
+
}
|
|
246
|
+
else if (primaryType === 'DelegatedUserDecryptRequestVerification') {
|
|
247
|
+
assertIsKmsDelegatedUserDecryptEip712V1(eip712, `${permitName}.eip712`, options);
|
|
248
|
+
if (eip712.message.publicKey.toLowerCase() !== transportKeyPair.publicKey.toLowerCase()) {
|
|
249
|
+
throw new Error("The permit's publicKey does not match the TransportKeyPair's publicKey. " +
|
|
250
|
+
'Ensure the permit was signed with the same key pair.');
|
|
251
|
+
}
|
|
252
|
+
return await _createSignedDecryptionPermitV1(context, { signature: permit.signature, eip712, signerAddress });
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
throw new Error(`Unknown permit primaryType: ${primaryType}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=SignedDecryptionPermitV1-p.js.map
|