@fhevm/sdk 1.0.0-alpha.3 → 1.0.0-alpha.5
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/fetchEncryptedValues.js +18 -0
- package/_cjs/core/actions/base/fetchEncryptedValues.js.map +1 -0
- package/_cjs/core/actions/base/index.js +3 -1
- package/_cjs/core/actions/base/index.js.map +1 -1
- package/_cjs/core/actions/chain/createKmsDelegatedUserDecryptEip712.js.map +1 -1
- package/_cjs/core/actions/chain/createKmsUserDecryptEip712.js.map +1 -1
- package/_cjs/core/actions/chain/index.js +5 -5
- package/_cjs/core/actions/chain/parseSignedDecryptionPermit.js +2 -2
- package/_cjs/core/actions/chain/parseSignedDecryptionPermit.js.map +1 -1
- package/_cjs/core/actions/chain/parseTransportKeyPair.js +8 -0
- package/_cjs/core/actions/chain/parseTransportKeyPair.js.map +1 -0
- package/_cjs/core/actions/chain/serializeTransportKeyPair.js +8 -0
- package/_cjs/core/actions/chain/serializeTransportKeyPair.js.map +1 -0
- package/_cjs/core/actions/decrypt/generateTransportKeyPair.js +8 -0
- package/_cjs/core/actions/decrypt/generateTransportKeyPair.js.map +1 -0
- package/_cjs/core/actions/decrypt/index.js +3 -3
- package/_cjs/core/actions/decrypt/index.js.map +1 -1
- package/_cjs/core/actions/encrypt/generateZkProof.js.map +1 -1
- package/_cjs/core/base/address.js.map +1 -1
- package/_cjs/core/base/fetch.js +2 -2
- package/_cjs/core/base/fetch.js.map +1 -1
- package/_cjs/core/base/index.js +0 -5
- package/_cjs/core/base/index.js.map +1 -1
- package/_cjs/core/base/sign.js +12 -6
- package/_cjs/core/base/sign.js.map +1 -1
- package/_cjs/core/base/typedValue.js +20 -6
- package/_cjs/core/base/typedValue.js.map +1 -1
- package/_cjs/core/base/uint.js +23 -0
- package/_cjs/core/base/uint.js.map +1 -1
- package/_cjs/core/base/wasm.js +1 -1
- package/_cjs/core/base/wasm.js.map +1 -1
- package/_cjs/core/clients/decorators/base.js +4 -4
- package/_cjs/core/clients/decorators/decrypt.js +2 -2
- package/_cjs/core/coprocessor/ZkProof-p.js +2 -1
- package/_cjs/core/coprocessor/ZkProof-p.js.map +1 -1
- package/_cjs/core/handle/EncryptedValue.js +0 -4
- package/_cjs/core/handle/EncryptedValue.js.map +1 -1
- package/_cjs/core/handle/FheType.js.map +1 -1
- package/_cjs/core/host-contracts/canDecryptValuesFromPairs.js +3 -3
- package/_cjs/core/host-contracts/checkDelegation.js +13 -0
- package/_cjs/core/host-contracts/checkDelegation.js.map +1 -1
- package/_cjs/core/host-contracts/constants.js +5 -0
- package/_cjs/core/host-contracts/constants.js.map +1 -0
- package/_cjs/core/kms/SignedDecryptionPermit-p.js +9 -9
- package/_cjs/core/kms/SignedDecryptionPermit-p.js.map +1 -1
- package/_cjs/core/kms/{TransportKeypair-p.js → TransportKeyPair-p.js} +48 -48
- package/_cjs/core/kms/{TransportKeypair-p.js.map → TransportKeyPair-p.js.map} +1 -1
- package/_cjs/core/kms/decryptKmsSignedcryptedShares-p.js +3 -3
- package/_cjs/core/kms/decryptKmsSignedcryptedShares-p.js.map +1 -1
- package/_cjs/core/kms/decryptValuesFromPairs.js +2 -2
- package/_cjs/core/kms/decryptValuesFromPairs.js.map +1 -1
- package/_cjs/core/kms/index.js +0 -1
- package/_cjs/core/modules/decrypt/mock.js.map +1 -1
- package/_cjs/core/modules/decrypt/module/init-p.js +3 -7
- package/_cjs/core/modules/decrypt/module/init-p.js.map +1 -1
- package/_cjs/core/modules/encrypt/mock.js.map +1 -1
- package/_cjs/core/modules/encrypt/module/api-p.js.map +1 -1
- package/_cjs/core/modules/encrypt/module/index.js.map +1 -1
- package/_cjs/core/modules/encrypt/module/init-p.js +18 -13
- package/_cjs/core/modules/encrypt/module/init-p.js.map +1 -1
- package/_cjs/core/modules/relayer/module/fetchPublicDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/module/fetchUserDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/module/guards/RelayerErrorBody.js +27 -0
- package/_cjs/core/modules/relayer/module/guards/RelayerErrorBody.js.map +1 -0
- package/_cjs/core/types/index.js +4 -0
- package/_cjs/core/types/index.js.map +1 -1
- package/_cjs/core/utils-p/decrypt/assertPermitMatchesKeyPair.js +14 -0
- package/_cjs/core/utils-p/decrypt/{assertPermitMatchesKeypair.js.map → assertPermitMatchesKeyPair.js.map} +1 -1
- package/_cjs/core/utils-p/decrypt/verifyTkmsPublicKey.js +1 -1
- package/_esm/core/_version.js +1 -1
- package/_esm/core/actions/base/fetchEncryptedValues.js +16 -0
- package/_esm/core/actions/base/fetchEncryptedValues.js.map +1 -0
- package/_esm/core/actions/base/index.js +1 -0
- package/_esm/core/actions/base/index.js.map +1 -1
- package/_esm/core/actions/chain/createKmsDelegatedUserDecryptEip712.js.map +1 -1
- package/_esm/core/actions/chain/createKmsUserDecryptEip712.js.map +1 -1
- package/_esm/core/actions/chain/index.js +2 -2
- package/_esm/core/actions/chain/parseSignedDecryptionPermit.js +3 -3
- package/_esm/core/actions/chain/parseSignedDecryptionPermit.js.map +1 -1
- package/_esm/core/actions/chain/parseTransportKeyPair.js +5 -0
- package/_esm/core/actions/chain/parseTransportKeyPair.js.map +1 -0
- package/_esm/core/actions/chain/serializeTransportKeyPair.js +5 -0
- package/_esm/core/actions/chain/{serializeTransportKeypair.js.map → serializeTransportKeyPair.js.map} +1 -1
- package/_esm/core/actions/decrypt/generateTransportKeyPair.js +6 -0
- package/_esm/core/actions/decrypt/{generateTransportKeypair.js.map → generateTransportKeyPair.js.map} +1 -1
- package/_esm/core/actions/decrypt/index.js +3 -1
- package/_esm/core/actions/decrypt/index.js.map +1 -1
- package/_esm/core/actions/encrypt/generateZkProof.js.map +1 -1
- package/_esm/core/base/address.js.map +1 -1
- package/_esm/core/base/fetch.js +2 -2
- package/_esm/core/base/fetch.js.map +1 -1
- package/_esm/core/base/index.js +1 -1
- package/_esm/core/base/index.js.map +1 -1
- package/_esm/core/base/sign.js +15 -8
- package/_esm/core/base/sign.js.map +1 -1
- package/_esm/core/base/typedValue.js +24 -7
- package/_esm/core/base/typedValue.js.map +1 -1
- package/_esm/core/base/uint.js +21 -0
- package/_esm/core/base/uint.js.map +1 -1
- package/_esm/core/base/wasm.js +1 -1
- package/_esm/core/base/wasm.js.map +1 -1
- package/_esm/core/clients/decorators/base.js +4 -4
- package/_esm/core/clients/decorators/decrypt.js +2 -2
- package/_esm/core/coprocessor/ZkProof-p.js +3 -2
- package/_esm/core/coprocessor/ZkProof-p.js.map +1 -1
- package/_esm/core/handle/EncryptedValue.js +0 -3
- package/_esm/core/handle/EncryptedValue.js.map +1 -1
- package/_esm/core/handle/FheType.js +10 -17
- package/_esm/core/handle/FheType.js.map +1 -1
- package/_esm/core/host-contracts/canDecryptValuesFromPairs.js +3 -3
- package/_esm/core/host-contracts/checkDelegation.js +19 -5
- package/_esm/core/host-contracts/checkDelegation.js.map +1 -1
- package/_esm/core/host-contracts/constants.js +2 -0
- package/_esm/core/host-contracts/constants.js.map +1 -0
- package/_esm/core/kms/SignedDecryptionPermit-p.js +9 -9
- package/_esm/core/kms/SignedDecryptionPermit-p.js.map +1 -1
- package/_esm/core/kms/{TransportKeypair-p.js → TransportKeyPair-p.js} +55 -55
- package/_esm/core/kms/{TransportKeypair-p.js.map → TransportKeyPair-p.js.map} +1 -1
- package/_esm/core/kms/decryptKmsSignedcryptedShares-p.js +4 -4
- package/_esm/core/kms/decryptKmsSignedcryptedShares-p.js.map +1 -1
- package/_esm/core/kms/decryptValuesFromPairs.js +2 -2
- package/_esm/core/kms/decryptValuesFromPairs.js.map +1 -1
- package/_esm/core/modules/decrypt/mock.js.map +1 -1
- package/_esm/core/modules/decrypt/module/init-p.js +13 -11
- package/_esm/core/modules/decrypt/module/init-p.js.map +1 -1
- package/_esm/core/modules/encrypt/mock.js.map +1 -1
- package/_esm/core/modules/encrypt/module/api-p.js.map +1 -1
- package/_esm/core/modules/encrypt/module/index.js.map +1 -1
- package/_esm/core/modules/encrypt/module/init-p.js +34 -17
- package/_esm/core/modules/encrypt/module/init-p.js.map +1 -1
- package/_esm/core/modules/relayer/module/fetchPublicDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/module/fetchUserDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/module/guards/RelayerErrorBody.js +24 -0
- package/_esm/core/modules/relayer/module/guards/RelayerErrorBody.js.map +1 -0
- package/_esm/core/types/index.js +1 -1
- package/_esm/core/types/index.js.map +1 -1
- package/_esm/core/utils-p/decrypt/assertPermitMatchesKeyPair.js +19 -0
- package/_esm/core/utils-p/decrypt/{assertPermitMatchesKeypair.js.map → assertPermitMatchesKeyPair.js.map} +1 -1
- package/_esm/core/utils-p/decrypt/verifyTkmsPublicKey.js +1 -1
- package/_types/core/actions/base/fetchEncryptedValues.d.ts +16 -0
- package/_types/core/actions/base/fetchEncryptedValues.d.ts.map +1 -0
- package/_types/core/actions/base/index.d.ts +1 -0
- package/_types/core/actions/base/index.d.ts.map +1 -1
- package/_types/core/actions/chain/createKmsDelegatedUserDecryptEip712.d.ts.map +1 -1
- package/_types/core/actions/chain/createKmsUserDecryptEip712.d.ts.map +1 -1
- package/_types/core/actions/chain/index.d.ts +2 -2
- package/_types/core/actions/chain/parseSignedDecryptionPermit.d.ts +4 -4
- package/_types/core/actions/chain/parseSignedDecryptionPermit.d.ts.map +1 -1
- package/_types/core/actions/chain/{parseTransportKeypair.d.ts → parseTransportKeyPair.d.ts} +5 -5
- package/_types/core/actions/chain/{parseTransportKeypair.d.ts.map → parseTransportKeyPair.d.ts.map} +1 -1
- package/_types/core/actions/chain/{serializeTransportKeypair.d.ts → serializeTransportKeyPair.d.ts} +6 -6
- package/_types/core/actions/chain/{serializeTransportKeypair.d.ts.map → serializeTransportKeyPair.d.ts.map} +1 -1
- package/_types/core/actions/decrypt/canDecryptValue.d.ts +4 -4
- package/_types/core/actions/decrypt/canDecryptValues.d.ts +2 -2
- package/_types/core/actions/decrypt/canDecryptValuesFromPairs.d.ts +2 -2
- package/_types/core/actions/decrypt/decryptKmsSignedcryptedShares.d.ts +2 -2
- package/_types/core/actions/decrypt/decryptValue.d.ts +2 -2
- package/_types/core/actions/decrypt/decryptValues.d.ts +2 -2
- package/_types/core/actions/decrypt/decryptValuesFromPairs.d.ts +2 -2
- package/_types/core/actions/decrypt/{generateTransportKeypair.d.ts → generateTransportKeyPair.d.ts} +4 -4
- package/_types/core/actions/decrypt/{generateTransportKeypair.d.ts.map → generateTransportKeyPair.d.ts.map} +1 -1
- package/_types/core/actions/decrypt/index.d.ts +3 -1
- package/_types/core/actions/decrypt/index.d.ts.map +1 -1
- package/_types/core/actions/encrypt/encryptValue.d.ts +5 -2
- package/_types/core/actions/encrypt/encryptValue.d.ts.map +1 -1
- package/_types/core/actions/encrypt/encryptValues.d.ts +5 -2
- package/_types/core/actions/encrypt/encryptValues.d.ts.map +1 -1
- package/_types/core/actions/encrypt/generateZkProof.d.ts +4 -2
- package/_types/core/actions/encrypt/generateZkProof.d.ts.map +1 -1
- package/_types/core/base/address.d.ts.map +1 -1
- package/_types/core/base/errors/InvalidTypeError.d.ts +1 -1
- package/_types/core/base/errors/InvalidTypeError.d.ts.map +1 -1
- package/_types/core/base/index.d.ts +1 -1
- package/_types/core/base/index.d.ts.map +1 -1
- package/_types/core/base/sign.d.ts.map +1 -1
- package/_types/core/base/typedValue.d.ts +3 -13
- package/_types/core/base/typedValue.d.ts.map +1 -1
- package/_types/core/base/uint.d.ts +4 -0
- package/_types/core/base/uint.d.ts.map +1 -1
- package/_types/core/clients/decorators/base.d.ts +6 -6
- package/_types/core/clients/decorators/base.d.ts.map +1 -1
- package/_types/core/clients/decorators/decrypt.d.ts +2 -2
- package/_types/core/coprocessor/ZkProof-p.d.ts +2 -1
- package/_types/core/coprocessor/ZkProof-p.d.ts.map +1 -1
- package/_types/core/handle/EncryptedValue.d.ts +0 -1
- package/_types/core/handle/EncryptedValue.d.ts.map +1 -1
- package/_types/core/handle/FheType.d.ts +10 -17
- package/_types/core/handle/FheType.d.ts.map +1 -1
- package/_types/core/host-contracts/canDecryptValuesFromPairs.d.ts +2 -2
- package/_types/core/host-contracts/checkDelegation.d.ts.map +1 -1
- package/_types/core/host-contracts/constants.d.ts +3 -0
- package/_types/core/host-contracts/constants.d.ts.map +1 -0
- package/_types/core/kms/SignedDecryptionPermit-p.d.ts +6 -6
- package/_types/core/kms/{TransportKeypair-p.d.ts → TransportKeyPair-p.d.ts} +23 -23
- package/_types/core/kms/{TransportKeypair-p.d.ts.map → TransportKeyPair-p.d.ts.map} +1 -1
- package/_types/core/kms/decryptKmsSignedcryptedShares-p.d.ts +2 -2
- package/_types/core/kms/decryptValuesFromPairs.d.ts +3 -3
- package/_types/core/kms/index.d.ts +1 -1
- package/_types/core/kms/index.d.ts.map +1 -1
- package/_types/core/modules/decrypt/module/init-p.d.ts.map +1 -1
- package/_types/core/modules/encrypt/mock.d.ts +2 -2
- package/_types/core/modules/encrypt/mock.d.ts.map +1 -1
- package/_types/core/modules/encrypt/module/api-p.d.ts +2 -2
- package/_types/core/modules/encrypt/module/api-p.d.ts.map +1 -1
- package/_types/core/modules/encrypt/module/init-p.d.ts.map +1 -1
- package/_types/core/modules/encrypt/types.d.ts +2 -2
- package/_types/core/modules/encrypt/types.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/fetchUserDecrypt.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/guards/RelayerErrorBody.d.ts +13 -0
- package/_types/core/modules/relayer/module/guards/RelayerErrorBody.d.ts.map +1 -0
- package/_types/core/types/index.d.ts +2 -0
- package/_types/core/types/index.d.ts.map +1 -1
- package/_types/core/types/primitives.d.ts +4 -0
- package/_types/core/types/primitives.d.ts.map +1 -1
- package/_types/core/utils-p/decrypt/assertPermitMatchesKeyPair.d.ts +12 -0
- package/_types/core/utils-p/decrypt/{assertPermitMatchesKeypair.d.ts.map → assertPermitMatchesKeyPair.d.ts.map} +1 -1
- package/core/_version.ts +1 -1
- package/core/actions/base/fetchEncryptedValues.ts +42 -0
- package/core/actions/base/index.ts +6 -0
- package/core/actions/chain/createKmsDelegatedUserDecryptEip712.ts +1 -2
- package/core/actions/chain/createKmsUserDecryptEip712.ts +1 -2
- package/core/actions/chain/index.ts +8 -8
- package/core/actions/chain/parseSignedDecryptionPermit.ts +6 -6
- package/core/actions/chain/{parseTransportKeypair.ts → parseTransportKeyPair.ts} +7 -7
- package/core/actions/chain/{serializeTransportKeypair.ts → serializeTransportKeyPair.ts} +10 -10
- package/core/actions/decrypt/canDecryptValue.ts +4 -4
- package/core/actions/decrypt/canDecryptValues.ts +2 -2
- package/core/actions/decrypt/canDecryptValuesFromPairs.ts +2 -2
- package/core/actions/decrypt/decryptKmsSignedcryptedShares.ts +2 -2
- package/core/actions/decrypt/decryptValue.ts +2 -2
- package/core/actions/decrypt/decryptValues.ts +2 -2
- package/core/actions/decrypt/decryptValuesFromPairs.ts +2 -2
- package/core/actions/decrypt/{generateTransportKeypair.ts → generateTransportKeyPair.ts} +7 -7
- package/core/actions/decrypt/index.ts +8 -4
- package/core/actions/encrypt/encryptValue.ts +2 -2
- package/core/actions/encrypt/encryptValues.ts +2 -2
- package/core/actions/encrypt/generateZkProof.ts +1 -2
- package/core/base/address.ts +2 -2
- package/core/base/errors/InvalidTypeError.ts +1 -1
- package/core/base/fetch.ts +2 -2
- package/core/base/index.ts +0 -1
- package/core/base/sign.ts +16 -8
- package/core/base/typedValue.ts +32 -25
- package/core/base/uint.ts +30 -0
- package/core/base/wasm.ts +1 -1
- package/core/clients/decorators/base.ts +18 -18
- package/core/clients/decorators/decrypt.ts +4 -4
- package/core/coprocessor/ZkProof-p.ts +6 -6
- package/core/handle/EncryptedValue.ts +0 -4
- package/core/handle/FheType.ts +10 -17
- package/core/host-contracts/canDecryptValuesFromPairs.ts +5 -5
- package/core/host-contracts/checkDelegation.ts +20 -5
- package/core/host-contracts/constants.ts +3 -0
- package/core/kms/SignedDecryptionPermit-p.ts +13 -13
- package/core/kms/{TransportKeypair-p.ts → TransportKeyPair-p.ts} +42 -42
- package/core/kms/decryptKmsSignedcryptedShares-p.ts +6 -6
- package/core/kms/decryptValuesFromPairs.ts +5 -5
- package/core/kms/index.ts +0 -1
- package/core/modules/decrypt/mock.ts +3 -3
- package/core/modules/decrypt/module/init-p.ts +13 -14
- package/core/modules/encrypt/mock.ts +4 -6
- package/core/modules/encrypt/module/api-p.ts +4 -6
- package/core/modules/encrypt/module/index.ts +2 -2
- package/core/modules/encrypt/module/init-p.ts +37 -21
- package/core/modules/encrypt/types.ts +2 -2
- package/core/modules/relayer/module/fetchPublicDecrypt.ts +2 -2
- package/core/modules/relayer/module/fetchUserDecrypt.ts +1 -2
- package/core/modules/relayer/module/guards/RelayerErrorBody.ts +33 -0
- package/core/types/index.ts +2 -0
- package/core/types/primitives.ts +4 -0
- package/core/utils-p/decrypt/{assertPermitMatchesKeypair.ts → assertPermitMatchesKeyPair.ts} +9 -9
- package/core/utils-p/decrypt/verifyTkmsPublicKey.ts +1 -1
- package/package.json +3 -2
- package/_cjs/core/actions/chain/parseTransportKeypair.js +0 -8
- package/_cjs/core/actions/chain/parseTransportKeypair.js.map +0 -1
- package/_cjs/core/actions/chain/serializeTransportKeypair.js +0 -8
- package/_cjs/core/actions/chain/serializeTransportKeypair.js.map +0 -1
- package/_cjs/core/actions/decrypt/generateTransportKeypair.js +0 -8
- package/_cjs/core/actions/decrypt/generateTransportKeypair.js.map +0 -1
- package/_cjs/core/utils-p/decrypt/assertPermitMatchesKeypair.js +0 -14
- package/_esm/core/actions/chain/parseTransportKeypair.js +0 -5
- package/_esm/core/actions/chain/parseTransportKeypair.js.map +0 -1
- package/_esm/core/actions/chain/serializeTransportKeypair.js +0 -5
- package/_esm/core/actions/decrypt/generateTransportKeypair.js +0 -6
- package/_esm/core/utils-p/decrypt/assertPermitMatchesKeypair.js +0 -19
- package/_types/core/utils-p/decrypt/assertPermitMatchesKeypair.d.ts +0 -12
- package/tsconfig.json +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FhevmChain } from '../types/fhevmChain.js';
|
|
2
2
|
import type { SignedDelegatedDecryptionPermit, SignedSelfDecryptionPermit } from '../types/signedDecryptionPermit.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TransportKeyPair } from '../kms/TransportKeyPair-p.js';
|
|
4
4
|
import type { ChecksummedAddress, Uint64BigInt } from '../types/primitives.js';
|
|
5
5
|
import type { FhevmRuntime } from '../types/coreFhevmRuntime.js';
|
|
6
6
|
import type { Handle } from '../types/encryptedTypes-p.js';
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
assertIsSignedDecryptionPermit,
|
|
11
11
|
assertPermitIncludesContractAddresses,
|
|
12
12
|
} from '../kms/SignedDecryptionPermit-p.js';
|
|
13
|
-
import {
|
|
13
|
+
import { assertPermitMatchesKeyPair } from '../utils-p/decrypt/assertPermitMatchesKeyPair.js';
|
|
14
14
|
import { isUserDecryptable } from '../host-contracts/isUserDecryptable.js';
|
|
15
15
|
|
|
16
16
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -30,7 +30,7 @@ type Parameters =
|
|
|
30
30
|
| {
|
|
31
31
|
readonly pairs: ReadonlyArray<{ readonly handle: Handle; readonly contractAddress: ChecksummedAddress }>;
|
|
32
32
|
readonly signedPermit: SignedSelfDecryptionPermit | SignedDelegatedDecryptionPermit;
|
|
33
|
-
readonly
|
|
33
|
+
readonly transportKeyPair?: TransportKeyPair | undefined;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
type ReturnType = {
|
|
@@ -66,8 +66,8 @@ export async function canDecryptValuesFromPairs(context: Context, parameters: Pa
|
|
|
66
66
|
signedPermit.assertNotExpired();
|
|
67
67
|
assertPermitIncludesContractAddresses(signedPermit, contractAddresses);
|
|
68
68
|
|
|
69
|
-
if (parameters.
|
|
70
|
-
|
|
69
|
+
if (parameters.transportKeyPair !== undefined) {
|
|
70
|
+
assertPermitMatchesKeyPair(signedPermit, parameters.transportKeyPair);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
userAddress = signedPermit.encryptedDataOwnerAddress;
|
|
@@ -4,6 +4,7 @@ import type { ChecksummedAddress } from '../types/primitives.js';
|
|
|
4
4
|
import type { HandleContractPair } from '../types/other-p.js';
|
|
5
5
|
import { AclUserDecryptionError } from '../errors/AclError.js';
|
|
6
6
|
import { isHandleDelegatedForUserDecryption } from './isHandleDelegatedForUserDecryption-p.js';
|
|
7
|
+
import { WILDCARD_DELEGATION_ADDRESS } from './constants.js';
|
|
7
8
|
|
|
8
9
|
////////////////////////////////////////////////////////////////////////////////
|
|
9
10
|
|
|
@@ -45,7 +46,21 @@ export async function checkDelegation(context: Context, parameters: Parameters):
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
// 2. Verify
|
|
49
|
+
// 2. Verify rule: delegate !== WILDCARD_CONTRACT
|
|
50
|
+
if (delegate.toLowerCase() === WILDCARD_DELEGATION_ADDRESS.toLowerCase()) {
|
|
51
|
+
throw new AclUserDecryptionError({
|
|
52
|
+
contractAddress: address,
|
|
53
|
+
message: `delegate cannot be equal to wildcard contract address`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (delegator.toLowerCase() === WILDCARD_DELEGATION_ADDRESS.toLowerCase()) {
|
|
57
|
+
throw new AclUserDecryptionError({
|
|
58
|
+
contractAddress: address,
|
|
59
|
+
message: `delegator cannot be equal to wildcard contract address`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 3. Verify rules: delegator !== contractAddress & delegate !== contractAddress
|
|
49
64
|
for (const pair of handleContractPairs) {
|
|
50
65
|
if (delegator.toLowerCase() === pair.contractAddress.toLowerCase()) {
|
|
51
66
|
throw new AclUserDecryptionError({
|
|
@@ -61,7 +76,7 @@ export async function checkDelegation(context: Context, parameters: Parameters):
|
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
|
|
64
|
-
//
|
|
79
|
+
// 4. Collect all unique (contractAddress, handle) pairs to avoid duplicate RPC calls
|
|
65
80
|
const allChecks: HandleContractPair[] = [];
|
|
66
81
|
const seenKeys = new Set<string>();
|
|
67
82
|
|
|
@@ -81,7 +96,7 @@ export async function checkDelegation(context: Context, parameters: Parameters):
|
|
|
81
96
|
throw new Error('checkDelegation: no delegation checks to perform (unexpected empty dedup result)');
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
//
|
|
99
|
+
// 5. Single batched RPC call for all unique checks
|
|
85
100
|
const allResults = await isHandleDelegatedForUserDecryption(context, {
|
|
86
101
|
address,
|
|
87
102
|
delegator,
|
|
@@ -89,7 +104,7 @@ export async function checkDelegation(context: Context, parameters: Parameters):
|
|
|
89
104
|
pairs: allChecks,
|
|
90
105
|
});
|
|
91
106
|
|
|
92
|
-
//
|
|
107
|
+
// 6. Build result map for lookup
|
|
93
108
|
const resultMap = new Map<string, boolean>();
|
|
94
109
|
for (const [i, check] of allChecks.entries()) {
|
|
95
110
|
const result = allResults[i];
|
|
@@ -101,7 +116,7 @@ export async function checkDelegation(context: Context, parameters: Parameters):
|
|
|
101
116
|
resultMap.set(key, result);
|
|
102
117
|
}
|
|
103
118
|
|
|
104
|
-
//
|
|
119
|
+
// 7. Verify delegation for each requested pair
|
|
105
120
|
for (const pair of handleContractPairs) {
|
|
106
121
|
const key = getKey(pair.contractAddress, pair.handle.bytes32Hex);
|
|
107
122
|
if (resultMap.get(key) !== true) {
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
createKmsDelegatedUserDecryptEip712,
|
|
30
30
|
} from './createKmsDelegatedUserDecryptEip712.js';
|
|
31
31
|
import { assertRecordStringProperty } from '../base/string.js';
|
|
32
|
-
import {
|
|
32
|
+
import { assertIsTransportKeyPair, type TransportKeyPair } from './TransportKeyPair-p.js';
|
|
33
33
|
import { assertKmsEIP712DeadlineValidity } from './utils.js';
|
|
34
34
|
import { readKmsSignersContext } from '../host-contracts/readKmsSignersContext-p.js';
|
|
35
35
|
import { kmsSignersContextToExtraData } from '../host-contracts/KmsSignersContext-p.js';
|
|
@@ -301,7 +301,7 @@ type SignDecryptionPermitCommonParameters = {
|
|
|
301
301
|
readonly durationDays: number;
|
|
302
302
|
readonly signerAddress: string;
|
|
303
303
|
readonly signer: NativeSigner;
|
|
304
|
-
readonly
|
|
304
|
+
readonly transportKeyPair: TransportKeyPair;
|
|
305
305
|
};
|
|
306
306
|
|
|
307
307
|
export type SignSelfDecryptionPermitParameters = SignDecryptionPermitCommonParameters & {
|
|
@@ -324,10 +324,10 @@ export type SignDecryptionPermitParameters =
|
|
|
324
324
|
* to decrypt encrypted values belonging to the `delegatorAddress` account.
|
|
325
325
|
* Otherwise, creates a standard permit where the signer decrypts their own values.
|
|
326
326
|
*
|
|
327
|
-
* The EIP-712 message includes the
|
|
328
|
-
* to encrypt the decrypted result for this specific
|
|
327
|
+
* The EIP-712 message includes the key pair's public key, allowing the gateway
|
|
328
|
+
* to encrypt the decrypted result for this specific key pair.
|
|
329
329
|
*
|
|
330
|
-
* @throws If the signer, address, or
|
|
330
|
+
* @throws If the signer, address, or key pair is invalid.
|
|
331
331
|
* @throws If the signature verification fails.
|
|
332
332
|
*/
|
|
333
333
|
export async function signDecryptionPermit(
|
|
@@ -353,12 +353,12 @@ export async function signDecryptionPermit(
|
|
|
353
353
|
startTimestamp,
|
|
354
354
|
durationDays,
|
|
355
355
|
signerAddress: signerAddressArg,
|
|
356
|
-
|
|
356
|
+
transportKeyPair: transportKeyPair,
|
|
357
357
|
signer,
|
|
358
358
|
delegatorAddress,
|
|
359
359
|
} = parameters;
|
|
360
360
|
|
|
361
|
-
|
|
361
|
+
assertIsTransportKeyPair(transportKeyPair, {});
|
|
362
362
|
assertIsAddress(signerAddressArg, {});
|
|
363
363
|
|
|
364
364
|
if (delegatorAddress !== undefined) {
|
|
@@ -380,7 +380,7 @@ export async function signDecryptionPermit(
|
|
|
380
380
|
durationDays,
|
|
381
381
|
startTimestamp,
|
|
382
382
|
extraData,
|
|
383
|
-
publicKey:
|
|
383
|
+
publicKey: transportKeyPair.publicKey,
|
|
384
384
|
};
|
|
385
385
|
|
|
386
386
|
const eip712 =
|
|
@@ -414,10 +414,10 @@ export async function parseSignedDecryptionPermit(
|
|
|
414
414
|
readonly client: NonNullable<object>;
|
|
415
415
|
readonly options: { readonly batchRpcCalls: boolean };
|
|
416
416
|
},
|
|
417
|
-
|
|
417
|
+
transportKeyPair: TransportKeyPair,
|
|
418
418
|
permit: unknown,
|
|
419
419
|
): Promise<SignedDecryptionPermit> {
|
|
420
|
-
|
|
420
|
+
assertIsTransportKeyPair(transportKeyPair, {});
|
|
421
421
|
|
|
422
422
|
const permitName = 'permit';
|
|
423
423
|
const options = {};
|
|
@@ -438,10 +438,10 @@ export async function parseSignedDecryptionPermit(
|
|
|
438
438
|
throw new Error(`Unknown permit primaryType: ${primaryType}`);
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
if (eip712.message.publicKey.toLowerCase() !==
|
|
441
|
+
if (eip712.message.publicKey.toLowerCase() !== transportKeyPair.publicKey.toLowerCase()) {
|
|
442
442
|
throw new Error(
|
|
443
|
-
"The permit's publicKey does not match the
|
|
444
|
-
'Ensure the permit was signed with the same
|
|
443
|
+
"The permit's publicKey does not match the E2eTransportKeyPair's publicKey. " +
|
|
444
|
+
'Ensure the permit was signed with the same key pair.',
|
|
445
445
|
);
|
|
446
446
|
}
|
|
447
447
|
|
|
@@ -10,22 +10,22 @@ import { verifyTkmsPublicKey } from '../utils-p/decrypt/verifyTkmsPublicKey.js';
|
|
|
10
10
|
|
|
11
11
|
////////////////////////////////////////////////////////////////////////////////
|
|
12
12
|
|
|
13
|
-
const PRIVATE_TOKEN = Symbol('
|
|
13
|
+
const PRIVATE_TOKEN = Symbol('TransportKeyPair.token');
|
|
14
14
|
|
|
15
15
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
16
|
|
|
17
|
-
declare const
|
|
17
|
+
declare const TransportKeyPairBrand: unique symbol;
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export type TransportKeyPair = {
|
|
20
20
|
readonly publicKey: BytesHex;
|
|
21
|
-
readonly [
|
|
21
|
+
readonly [TransportKeyPairBrand]: true;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
////////////////////////////////////////////////////////////////////////////////
|
|
25
|
-
//
|
|
25
|
+
// TransportKeyPairImpl
|
|
26
26
|
//
|
|
27
27
|
// Unexported class wrapping closures that bind a tkmsPrivateKey.
|
|
28
|
-
// - Class: enables instanceof checks (
|
|
28
|
+
// - Class: enables instanceof checks (isTransportKeyPair)
|
|
29
29
|
// - Closures: methods capture privateKey without exposing it
|
|
30
30
|
// - Frozen: instance, class, and prototype are all immutable
|
|
31
31
|
// - Tree-shakable: unused exports are eliminated by bundlers
|
|
@@ -35,8 +35,8 @@ export type TransportKeypair = {
|
|
|
35
35
|
const GetTkmsPrivateKeyFn = Symbol();
|
|
36
36
|
const SerializeFn = Symbol();
|
|
37
37
|
|
|
38
|
-
class
|
|
39
|
-
declare readonly [
|
|
38
|
+
class TransportKeyPairImpl implements TransportKeyPair {
|
|
39
|
+
declare readonly [TransportKeyPairBrand]: true;
|
|
40
40
|
|
|
41
41
|
readonly #publicKeyBytesHex: BytesHex;
|
|
42
42
|
readonly #privateKeyBytes: Bytes;
|
|
@@ -82,7 +82,7 @@ class TransportKeypairImpl implements TransportKeypair {
|
|
|
82
82
|
throw new Error('Unauthorized');
|
|
83
83
|
}
|
|
84
84
|
// If the runtime was GC'd, deref() returns undefined, which !== expectedRuntime → throws.
|
|
85
|
-
// This is intentional: a GC'd runtime means the
|
|
85
|
+
// This is intentional: a GC'd runtime means the key pair is stale.
|
|
86
86
|
if (expectedRuntime !== this.#runtime.deref()) {
|
|
87
87
|
throw new Error('Invalid runtime');
|
|
88
88
|
}
|
|
@@ -109,7 +109,7 @@ class TransportKeypairImpl implements TransportKeypair {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* Hidden method (Symbol key) that serializes the
|
|
112
|
+
* Hidden method (Symbol key) that serializes the key pair including the private key.
|
|
113
113
|
*
|
|
114
114
|
* Access is protected by the Symbol key (not exported) and the private token.
|
|
115
115
|
*/
|
|
@@ -135,29 +135,29 @@ class TransportKeypairImpl implements TransportKeypair {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
Object.freeze(
|
|
139
|
-
Object.freeze(
|
|
138
|
+
Object.freeze(TransportKeyPairImpl);
|
|
139
|
+
Object.freeze(TransportKeyPairImpl.prototype);
|
|
140
140
|
|
|
141
141
|
////////////////////////////////////////////////////////////////////////////////
|
|
142
142
|
|
|
143
143
|
/** Type guard. */
|
|
144
|
-
export function
|
|
145
|
-
return value instanceof
|
|
144
|
+
export function isTransportKeyPair(value: unknown): value is TransportKeyPair {
|
|
145
|
+
return value instanceof TransportKeyPairImpl;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
////////////////////////////////////////////////////////////////////////////////
|
|
149
149
|
|
|
150
|
-
/** Throws {@link InvalidTypeError} if value is not a valid {@link
|
|
151
|
-
export function
|
|
150
|
+
/** Throws {@link InvalidTypeError} if value is not a valid {@link TransportKeyPair}. */
|
|
151
|
+
export function assertIsTransportKeyPair(
|
|
152
152
|
value: unknown,
|
|
153
153
|
options: { subject?: string } & ErrorMetadataParams,
|
|
154
|
-
): asserts value is
|
|
155
|
-
if (!
|
|
154
|
+
): asserts value is TransportKeyPair {
|
|
155
|
+
if (!isTransportKeyPair(value)) {
|
|
156
156
|
throw new InvalidTypeError(
|
|
157
157
|
{
|
|
158
158
|
subject: options.subject,
|
|
159
159
|
type: typeof value,
|
|
160
|
-
expectedType: '
|
|
160
|
+
expectedType: 'TransportKeyPair',
|
|
161
161
|
},
|
|
162
162
|
options,
|
|
163
163
|
);
|
|
@@ -166,14 +166,14 @@ export function assertIsTransportKeypair(
|
|
|
166
166
|
|
|
167
167
|
////////////////////////////////////////////////////////////////////////////////
|
|
168
168
|
|
|
169
|
-
/** Generates a fresh {@link
|
|
170
|
-
export async function
|
|
169
|
+
/** Generates a fresh {@link TransportKeyPair}. */
|
|
170
|
+
export async function generateTransportKeyPair(context: { readonly runtime: WithDecrypt }): Promise<TransportKeyPair> {
|
|
171
171
|
const tkmsPrivateKey = await context.runtime.decrypt.generateTkmsPrivateKey();
|
|
172
172
|
const tkmsPrivateKeyBytes = await context.runtime.decrypt.serializeTkmsPrivateKey({ tkmsPrivateKey });
|
|
173
173
|
const tkmsPublicKeyBytesHex = await context.runtime.decrypt.getTkmsPublicKeyHex({
|
|
174
174
|
tkmsPrivateKey,
|
|
175
175
|
});
|
|
176
|
-
return new
|
|
176
|
+
return new TransportKeyPairImpl(PRIVATE_TOKEN, context.runtime, {
|
|
177
177
|
privateKeyBytes: tkmsPrivateKeyBytes,
|
|
178
178
|
publicKeyBytesHex: tkmsPublicKeyBytesHex,
|
|
179
179
|
tkmsPrivateKey,
|
|
@@ -181,25 +181,25 @@ export async function generateTransportKeypair(context: { readonly runtime: With
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
* Converts an unknown value into a {@link
|
|
184
|
+
* Converts an unknown value into a {@link TransportKeyPair}.
|
|
185
185
|
*
|
|
186
186
|
* Accepted inputs:
|
|
187
|
-
* - An existing {@link
|
|
187
|
+
* - An existing {@link TransportKeyPair} (returned as-is)
|
|
188
188
|
* - A plain object `{ publicKey, privateKey }` where each is `Bytes` or `BytesHex`
|
|
189
189
|
*
|
|
190
|
-
* @throws {InvalidTypeError} If `value` is not a recognized
|
|
190
|
+
* @throws {InvalidTypeError} If `value` is not a recognized key pair shape.
|
|
191
191
|
*/
|
|
192
|
-
export async function
|
|
192
|
+
export async function toTransportKeyPair(
|
|
193
193
|
context: { readonly runtime: FhevmRuntime },
|
|
194
194
|
value: unknown,
|
|
195
|
-
): Promise<
|
|
196
|
-
if (
|
|
195
|
+
): Promise<TransportKeyPair> {
|
|
196
|
+
if (isTransportKeyPair(value)) {
|
|
197
197
|
// Force realize
|
|
198
|
-
await (value as
|
|
198
|
+
await (value as TransportKeyPairImpl)[GetTkmsPrivateKeyFn](PRIVATE_TOKEN, context.runtime);
|
|
199
199
|
return value;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
const name = '
|
|
202
|
+
const name = 'TransportKeyPair';
|
|
203
203
|
const options = {};
|
|
204
204
|
|
|
205
205
|
assertRecordNonNullableProperty(value, 'publicKey', name, {
|
|
@@ -240,7 +240,7 @@ export async function toTransportKeypair(
|
|
|
240
240
|
await verifyTkmsPublicKey({ runtime: runtimeWithDecrypt }, { tkmsPrivateKey, tkmsPublicKeyBytesHex });
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
return new
|
|
243
|
+
return new TransportKeyPairImpl(PRIVATE_TOKEN, context.runtime, {
|
|
244
244
|
privateKeyBytes: tkmsPrivateKeyBytes,
|
|
245
245
|
publicKeyBytesHex: tkmsPublicKeyBytesHex,
|
|
246
246
|
tkmsPrivateKey,
|
|
@@ -248,31 +248,31 @@ export async function toTransportKeypair(
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
|
-
* Serializes an {@link
|
|
251
|
+
* Serializes an {@link TransportKeyPair} including the private key.
|
|
252
252
|
*
|
|
253
253
|
* **The output contains sensitive key material — handle and store securely.**
|
|
254
254
|
*
|
|
255
|
-
* @throws {InvalidTypeError} If `value` is not a valid {@link
|
|
255
|
+
* @throws {InvalidTypeError} If `value` is not a valid {@link TransportKeyPair}.
|
|
256
256
|
*/
|
|
257
|
-
export function
|
|
257
|
+
export function serializeTransportKeyPair(value: TransportKeyPair): {
|
|
258
258
|
publicKey: BytesHex;
|
|
259
259
|
privateKey: BytesHex;
|
|
260
260
|
} {
|
|
261
|
-
|
|
262
|
-
return (value as
|
|
261
|
+
assertIsTransportKeyPair(value, {});
|
|
262
|
+
return (value as TransportKeyPairImpl)[SerializeFn](PRIVATE_TOKEN);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
|
-
* Extracts the deserialized TKMS private key from an {@link
|
|
266
|
+
* Extracts the deserialized TKMS private key from an {@link TransportKeyPair}.
|
|
267
267
|
* Lazily deserializes and verifies the key on first access.
|
|
268
268
|
*
|
|
269
|
-
* @throws {InvalidTypeError} If `value` is not a valid {@link
|
|
269
|
+
* @throws {InvalidTypeError} If `value` is not a valid {@link TransportKeyPair}.
|
|
270
270
|
* @throws If the runtime does not match or the key verification fails.
|
|
271
271
|
*/
|
|
272
|
-
export async function
|
|
272
|
+
export async function transportKeyPairToTkmsPrivateKey(
|
|
273
273
|
context: { readonly runtime: FhevmRuntime },
|
|
274
|
-
value:
|
|
274
|
+
value: TransportKeyPair,
|
|
275
275
|
): Promise<TkmsPrivateKey> {
|
|
276
|
-
|
|
277
|
-
return await (value as
|
|
276
|
+
assertIsTransportKeyPair(value, {});
|
|
277
|
+
return await (value as TransportKeyPairImpl)[GetTkmsPrivateKeyFn](PRIVATE_TOKEN, context.runtime);
|
|
278
278
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { WithDecrypt } from '../types/coreFhevmRuntime.js';
|
|
2
2
|
import type { KmsSigncryptedShares } from '../types/kms.js';
|
|
3
3
|
import type { ClearValue } from '../types/encryptedTypes-p.js';
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
4
|
+
import type { TransportKeyPair } from './TransportKeyPair-p.js';
|
|
5
|
+
import { transportKeyPairToTkmsPrivateKey } from './TransportKeyPair-p.js';
|
|
6
6
|
|
|
7
7
|
////////////////////////////////////////////////////////////////////////////////
|
|
8
8
|
// decryptKmsSignedcryptedShares (with privateKey)
|
|
@@ -14,7 +14,7 @@ type Context = {
|
|
|
14
14
|
|
|
15
15
|
type Parameters = {
|
|
16
16
|
readonly kmsSigncryptedShares: KmsSigncryptedShares;
|
|
17
|
-
readonly
|
|
17
|
+
readonly transportKeyPair: TransportKeyPair;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
type ReturnType = readonly ClearValue[];
|
|
@@ -22,10 +22,10 @@ type ReturnType = readonly ClearValue[];
|
|
|
22
22
|
////////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
export async function decryptKmsSignedcryptedShares(context: Context, parameters: Parameters): Promise<ReturnType> {
|
|
25
|
-
const {
|
|
25
|
+
const { transportKeyPair: transportKeyPair, kmsSigncryptedShares } = parameters;
|
|
26
26
|
|
|
27
|
-
// also validates `
|
|
28
|
-
const tkmsPrivateKey = await
|
|
27
|
+
// also validates `transportKeyPair`
|
|
28
|
+
const tkmsPrivateKey = await transportKeyPairToTkmsPrivateKey(context, transportKeyPair);
|
|
29
29
|
|
|
30
30
|
// Using the `KmsSigncryptedShares` decrypt and reconstruct clear values
|
|
31
31
|
const orderedDecryptedHandles: readonly ClearValue[] = await context.runtime.decrypt.decryptAndReconstruct({
|
|
@@ -7,7 +7,7 @@ import type { KmsSigncryptedShares } from '../types/kms.js';
|
|
|
7
7
|
import type { ChecksummedAddress, TypedValue } from '../types/primitives.js';
|
|
8
8
|
import type { RelayerDelegatedUserDecryptOptions, RelayerUserDecryptOptions } from '../types/relayer.js';
|
|
9
9
|
import type { SignedDelegatedDecryptionPermit, SignedSelfDecryptionPermit } from '../types/signedDecryptionPermit.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { TransportKeyPair } from './TransportKeyPair-p.js';
|
|
11
11
|
import { decryptKmsSignedcryptedShares } from './decryptKmsSignedcryptedShares-p.js';
|
|
12
12
|
import { fetchKmsSignedcryptedShares } from './fetchKmsSignedcryptedShares-p.js';
|
|
13
13
|
|
|
@@ -27,7 +27,7 @@ type Parameters =
|
|
|
27
27
|
readonly contractAddress: ChecksummedAddress;
|
|
28
28
|
}>;
|
|
29
29
|
readonly signedPermit: SignedSelfDecryptionPermit;
|
|
30
|
-
readonly
|
|
30
|
+
readonly transportKeyPair: TransportKeyPair;
|
|
31
31
|
readonly options?: RelayerUserDecryptOptions | undefined;
|
|
32
32
|
}
|
|
33
33
|
| {
|
|
@@ -36,7 +36,7 @@ type Parameters =
|
|
|
36
36
|
readonly contractAddress: ChecksummedAddress;
|
|
37
37
|
}>;
|
|
38
38
|
readonly signedPermit: SignedDelegatedDecryptionPermit;
|
|
39
|
-
readonly
|
|
39
|
+
readonly transportKeyPair: TransportKeyPair;
|
|
40
40
|
readonly options?: RelayerDelegatedUserDecryptOptions | undefined;
|
|
41
41
|
};
|
|
42
42
|
|
|
@@ -45,13 +45,13 @@ export type ReturnType = readonly TypedValue[];
|
|
|
45
45
|
////////////////////////////////////////////////////////////////////////////////
|
|
46
46
|
|
|
47
47
|
export async function decryptValuesFromPairs(fhevm: Context, parameters: Parameters): Promise<ReturnType> {
|
|
48
|
-
const {
|
|
48
|
+
const { transportKeyPair: transportKeyPair } = parameters;
|
|
49
49
|
|
|
50
50
|
const kmsSigncryptedShares: KmsSigncryptedShares = await fetchKmsSignedcryptedShares(fhevm, parameters);
|
|
51
51
|
|
|
52
52
|
// Using the `KmsSigncryptedShares` decrypt and reconstruct clear values
|
|
53
53
|
return decryptKmsSignedcryptedShares(fhevm, {
|
|
54
54
|
kmsSigncryptedShares,
|
|
55
|
-
|
|
55
|
+
transportKeyPair: transportKeyPair,
|
|
56
56
|
});
|
|
57
57
|
}
|
package/core/kms/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { TransportKeypair } from './TransportKeypair-p.ts';
|
|
@@ -53,7 +53,7 @@ export async function decryptAndReconstruct(
|
|
|
53
53
|
const cleartextEthereumModule = runtime.ethereum as CleartextEthereumModule;
|
|
54
54
|
const { tkmsPrivateKey, shares } = parameters;
|
|
55
55
|
|
|
56
|
-
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey
|
|
56
|
+
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey);
|
|
57
57
|
const publicKeySecp256k1 = cleartextEthereumModule.getPublicKey({ privateKey: privateKeySecp256k1 });
|
|
58
58
|
|
|
59
59
|
const metadata: KmsSigncryptedSharesMetadata = getMetadata(shares);
|
|
@@ -149,7 +149,7 @@ export async function getTkmsPublicKeyHex(
|
|
|
149
149
|
parameters: GetTkmsPublicKeyHexParameters,
|
|
150
150
|
): Promise<GetTkmsPublicKeyHexReturnType> {
|
|
151
151
|
const { tkmsPrivateKey } = parameters;
|
|
152
|
-
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey
|
|
152
|
+
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey);
|
|
153
153
|
const cleartextEthereumModule = runtime.ethereum as CleartextEthereumModule;
|
|
154
154
|
const publicKeySecp256k1 = cleartextEthereumModule.getPublicKey({ privateKey: privateKeySecp256k1 });
|
|
155
155
|
return Promise.resolve(publicKeySecp256k1);
|
|
@@ -164,7 +164,7 @@ export async function serializeTkmsPrivateKey(
|
|
|
164
164
|
parameters: SerializeTkmsPrivateKeyParameters,
|
|
165
165
|
): Promise<SerializeTkmsPrivateKeyReturnType> {
|
|
166
166
|
const { tkmsPrivateKey } = parameters;
|
|
167
|
-
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey
|
|
167
|
+
const privateKeySecp256k1 = asBytesHex(tkmsPrivateKey);
|
|
168
168
|
const privateKeySecp256k1Bytes = hexToBytes(privateKeySecp256k1);
|
|
169
169
|
return Promise.resolve(privateKeySecp256k1Bytes);
|
|
170
170
|
}
|
|
@@ -109,22 +109,21 @@ export async function initTkmsModule(runtime: FhevmRuntime): Promise<void> {
|
|
|
109
109
|
|
|
110
110
|
ownerUid = runtime.uid;
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
// Cache the TKMS initialization promise once and keep it cached even if it
|
|
113
|
+
// rejects.
|
|
114
|
+
//
|
|
115
|
+
// Retry is not supported:
|
|
116
|
+
// -----------------------
|
|
117
|
+
// The underlying KMS/WASM bindings
|
|
118
|
+
// keep module-level state that cannot be reset reliably after a partial
|
|
119
|
+
// initialization failure; later callers should observe the original error
|
|
120
|
+
// instead of retrying against half-initialized state.
|
|
121
|
+
if (cachedTkmsModulePromise === undefined) {
|
|
122
|
+
// resolve is sync
|
|
123
|
+
const cfg = _getOrResolveTkmsModuleConfig(runtime);
|
|
124
|
+
cachedTkmsModulePromise = _initTkmsModule(cfg);
|
|
114
125
|
}
|
|
115
126
|
|
|
116
|
-
// Use existing config if already set, otherwise resolve from runtime
|
|
117
|
-
const cfg = _getOrResolveTkmsModuleConfig(runtime);
|
|
118
|
-
|
|
119
|
-
cachedTkmsModulePromise = _initTkmsModule(cfg);
|
|
120
|
-
|
|
121
|
-
// This is purely theoretical. Retry is not yet possible since the `_initTkmsModule`
|
|
122
|
-
// does not support retry (see kms lib internal global variables).
|
|
123
|
-
cachedTkmsModulePromise.catch(() => {
|
|
124
|
-
// Clear cache on failure so retry is possible
|
|
125
|
-
cachedTkmsModulePromise = undefined;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
127
|
return cachedTkmsModulePromise;
|
|
129
128
|
}
|
|
130
129
|
|
|
@@ -6,15 +6,13 @@ import type { FhevmRuntime } from '../../types/coreFhevmRuntime.js';
|
|
|
6
6
|
import type {
|
|
7
7
|
FheEncryptionCrs,
|
|
8
8
|
FheEncryptionCrsBrand,
|
|
9
|
-
FheEncryptionCrsBytes,
|
|
10
9
|
FheEncryptionKeyBytes,
|
|
11
10
|
FheEncryptionPublicKey,
|
|
12
11
|
FheEncryptionPublicKeyBrand,
|
|
13
|
-
FheEncryptionPublicKeyBytes,
|
|
14
12
|
} from '../../types/fheEncryptionKey.js';
|
|
15
13
|
import type { Bytes, BytesHex, UintNumber } from '../../types/primitives.js';
|
|
16
14
|
import type {
|
|
17
|
-
|
|
15
|
+
BuildWithProofPackedParameters,
|
|
18
16
|
BuildWithProofPackedReturnType,
|
|
19
17
|
ParseTFHEProvenCompactCiphertextListParameters,
|
|
20
18
|
ParseTFHEProvenCompactCiphertextListReturnType,
|
|
@@ -123,7 +121,7 @@ export async function parseTFHEProvenCompactCiphertextList(
|
|
|
123
121
|
////////////////////////////////////////////////////////////////////////////////
|
|
124
122
|
|
|
125
123
|
export async function buildWithProofPacked(
|
|
126
|
-
parameters:
|
|
124
|
+
parameters: BuildWithProofPackedParameters,
|
|
127
125
|
): Promise<BuildWithProofPackedReturnType> {
|
|
128
126
|
const { fheEncryptionKey: publicEncryptionParams, metaData, typedValues, extraData } = parameters;
|
|
129
127
|
|
|
@@ -219,7 +217,7 @@ export async function serializeFheEncryptionPublicKey(
|
|
|
219
217
|
return Object.freeze({
|
|
220
218
|
id: tfhePublicKey.id,
|
|
221
219
|
bytes: tfhePublicKeyBytes,
|
|
222
|
-
})
|
|
220
|
+
});
|
|
223
221
|
}
|
|
224
222
|
|
|
225
223
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -246,7 +244,7 @@ export async function serializeFheEncryptionCrs(
|
|
|
246
244
|
id: tfheCrs.id,
|
|
247
245
|
capacity: tfheCrs.capacity,
|
|
248
246
|
bytes: tfheCrsBytes,
|
|
249
|
-
})
|
|
247
|
+
});
|
|
250
248
|
}
|
|
251
249
|
|
|
252
250
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
BuildWithProofPackedParameters,
|
|
3
3
|
BuildWithProofPackedReturnType,
|
|
4
4
|
ParseTFHEProvenCompactCiphertextListParameters,
|
|
5
5
|
ParseTFHEProvenCompactCiphertextListReturnType,
|
|
@@ -17,11 +17,9 @@ import type {
|
|
|
17
17
|
import type {
|
|
18
18
|
FheEncryptionCrs,
|
|
19
19
|
FheEncryptionCrsBrand,
|
|
20
|
-
FheEncryptionCrsBytes,
|
|
21
20
|
FheEncryptionKeyBytes,
|
|
22
21
|
FheEncryptionPublicKey,
|
|
23
22
|
FheEncryptionPublicKeyBrand,
|
|
24
|
-
FheEncryptionPublicKeyBytes,
|
|
25
23
|
} from '../../../types/fheEncryptionKey.js';
|
|
26
24
|
import type { CompactCiphertextListBuilder } from '../../../../wasm/tfhe/tfhe.v1.5.3.js';
|
|
27
25
|
import type { Bytes, UintNumber } from '../../../types/primitives.js';
|
|
@@ -195,7 +193,7 @@ export async function parseTFHEProvenCompactCiphertextList(
|
|
|
195
193
|
|
|
196
194
|
export async function buildWithProofPacked(
|
|
197
195
|
runtime: FhevmRuntime,
|
|
198
|
-
parameters:
|
|
196
|
+
parameters: BuildWithProofPackedParameters,
|
|
199
197
|
): Promise<BuildWithProofPackedReturnType> {
|
|
200
198
|
await initTfheModule(runtime);
|
|
201
199
|
|
|
@@ -359,7 +357,7 @@ export async function serializeFheEncryptionPublicKey(
|
|
|
359
357
|
return Object.freeze({
|
|
360
358
|
id: tfhePublicKey.id,
|
|
361
359
|
bytes: tfhePublicKeyBytes,
|
|
362
|
-
})
|
|
360
|
+
});
|
|
363
361
|
}
|
|
364
362
|
|
|
365
363
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -389,7 +387,7 @@ export async function serializeFheEncryptionCrs(
|
|
|
389
387
|
id: tfheCrs.id,
|
|
390
388
|
capacity: tfheCrs.capacity,
|
|
391
389
|
bytes: tfheCrsBytes,
|
|
392
|
-
})
|
|
390
|
+
});
|
|
393
391
|
}
|
|
394
392
|
|
|
395
393
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FhevmRuntime } from '../../../types/coreFhevmRuntime.js';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
3
|
+
BuildWithProofPackedParameters,
|
|
4
4
|
DeserializeFheEncryptionCrsParameters,
|
|
5
5
|
DeserializeFheEncryptionPublicKeyParameters,
|
|
6
6
|
EncryptModuleFactory,
|
|
@@ -31,7 +31,7 @@ export const encryptModule: EncryptModuleFactory = (runtime: FhevmRuntime) => {
|
|
|
31
31
|
getTfheModuleInfo: () => getTfheModuleInfo(),
|
|
32
32
|
parseTFHEProvenCompactCiphertextList: (args: ParseTFHEProvenCompactCiphertextListParameters) =>
|
|
33
33
|
parseTFHEProvenCompactCiphertextList(runtime, args),
|
|
34
|
-
buildWithProofPacked: (args:
|
|
34
|
+
buildWithProofPacked: (args: BuildWithProofPackedParameters) => buildWithProofPacked(runtime, args),
|
|
35
35
|
serializeFheEncryptionKey: (args: SerializeFheEncryptionKeyParameters) =>
|
|
36
36
|
serializeFheEncryptionKey(runtime, args),
|
|
37
37
|
serializeFheEncryptionPublicKey: (args: SerializeFheEncryptionPublicKeyParameters) =>
|