@fhevm/sdk 1.0.0-alpha.4 → 1.0.0-alpha.6
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/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/sign.js +12 -6
- package/_cjs/core/base/sign.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/kms/SignedDecryptionPermit-p.js +10 -10
- 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/kms/kmsExtraData.js +7 -1
- package/_cjs/core/kms/kmsExtraData.js.map +1 -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/RelayerAsyncRequest.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 +1 -0
- package/_cjs/core/utils-p/decrypt/verifyTkmsPublicKey.js +1 -1
- package/_cjs/core/utils-p/decrypt/verifyTkmsPublicKey.js.map +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/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/sign.js +15 -8
- package/_esm/core/base/sign.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/kms/SignedDecryptionPermit-p.js +10 -10
- 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/kms/kmsExtraData.js +7 -1
- package/_esm/core/kms/kmsExtraData.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/RelayerAsyncRequest.js +13 -0
- package/_esm/core/modules/relayer/module/RelayerAsyncRequest.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 +1 -0
- package/_esm/core/utils-p/decrypt/verifyTkmsPublicKey.js +1 -1
- package/_esm/core/utils-p/decrypt/verifyTkmsPublicKey.js.map +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/base/address.d.ts.map +1 -1
- package/_types/core/base/sign.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/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/kms/kmsExtraData.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/RelayerAsyncRequest.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 +3 -0
- package/_types/core/types/index.d.ts.map +1 -1
- package/_types/core/types/signedDecryptionPermit.d.ts +1 -1
- package/_types/core/types/signedDecryptionPermit.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/base/address.ts +2 -2
- package/core/base/fetch.ts +2 -2
- package/core/base/sign.ts +16 -8
- 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/kms/SignedDecryptionPermit-p.ts +14 -14
- 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/kms/kmsExtraData.ts +8 -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/RelayerAsyncRequest.ts +14 -0
- 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 +3 -0
- package/core/types/signedDecryptionPermit.ts +1 -1
- package/core/utils-p/decrypt/assertPermitMatchesKeyPair.ts +27 -0
- 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/_cjs/core/utils-p/decrypt/assertPermitMatchesKeypair.js.map +0 -1
- 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/_esm/core/utils-p/decrypt/assertPermitMatchesKeypair.js.map +0 -1
- package/_types/core/utils-p/decrypt/assertPermitMatchesKeypair.d.ts +0 -12
- package/core/utils-p/decrypt/assertPermitMatchesKeypair.ts +0 -27
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -17
package/core/handle/FheType.ts
CHANGED
|
@@ -316,8 +316,6 @@ export function assertIsEncryptionBitsArray(
|
|
|
316
316
|
|
|
317
317
|
/**
|
|
318
318
|
* Converts an encryption bit width to its corresponding FheTypeId.
|
|
319
|
-
* Accepts loose `number` input; validates internally via `isEncryptionBits`.
|
|
320
|
-
* @throws A {@link FheTypeError} If bitwidth is not a valid encryption bit width.
|
|
321
319
|
* @example fheTypeIdFromEncryptionBits(8) // 2 (euint8)
|
|
322
320
|
*/
|
|
323
321
|
export function fheTypeIdFromEncryptionBits(bitwidth: EncryptionBits): FheTypeId {
|
|
@@ -326,8 +324,6 @@ export function fheTypeIdFromEncryptionBits(bitwidth: EncryptionBits): FheTypeId
|
|
|
326
324
|
|
|
327
325
|
/**
|
|
328
326
|
* Converts an FheType to its corresponding FheTypeId.
|
|
329
|
-
* Accepts loose `string` input; validates internally via `isFheType`.
|
|
330
|
-
* @throws A {@link FheTypeError} If name is not a valid FheType.
|
|
331
327
|
* @example fheTypeIdFromName('euint8') // 2
|
|
332
328
|
*/
|
|
333
329
|
export function fheTypeIdFromName(name: FheType): FheTypeId {
|
|
@@ -336,7 +332,6 @@ export function fheTypeIdFromName(name: FheType): FheTypeId {
|
|
|
336
332
|
|
|
337
333
|
/**
|
|
338
334
|
* Converts an FheTypeId to its corresponding FheType.
|
|
339
|
-
* @throws A {@link FheTypeError} If id is not a valid FheTypeId.
|
|
340
335
|
* @example fheTypeNameFromId(2) // 'euint8'
|
|
341
336
|
*/
|
|
342
337
|
export function fheTypeNameFromId(typeId: FheTypeId): FheType {
|
|
@@ -353,7 +348,7 @@ export function fheTypeNameFromTypeName(typeName: ValueTypeName): FheType {
|
|
|
353
348
|
|
|
354
349
|
/**
|
|
355
350
|
* Converts a FheType to its corresponding TypeName.
|
|
356
|
-
* @example
|
|
351
|
+
* @example typeNameFromFheTypeName('euint8') // 'uint8'
|
|
357
352
|
*/
|
|
358
353
|
export function typeNameFromFheTypeName(fheType: FheType): ValueTypeName {
|
|
359
354
|
return fheType.substring(1) as ValueTypeName;
|
|
@@ -365,7 +360,6 @@ export function typeNameFromFheTypeName(fheType: FheType): ValueTypeName {
|
|
|
365
360
|
|
|
366
361
|
/**
|
|
367
362
|
* Returns the Solidity primitive type name for an FheTypeId.
|
|
368
|
-
* Accepts loose `number` input; validates internally via `isFheTypeId`.
|
|
369
363
|
* @example solidityPrimitiveTypeNameFromFheTypeId(0) // 'bool'
|
|
370
364
|
* @example solidityPrimitiveTypeNameFromFheTypeId(7) // 'address'
|
|
371
365
|
* @example solidityPrimitiveTypeNameFromFheTypeId(2) // 'uint256'
|
|
@@ -398,9 +392,9 @@ export function encryptionBitsFromFheTypeId(typeId: FheTypeId): EncryptionBits {
|
|
|
398
392
|
* Returns the encryption bit width for an FheType name.
|
|
399
393
|
* @param name - The FHE type name (e.g., 'ebool', 'euint32', 'eaddress')
|
|
400
394
|
* @returns The encryption bit width (always \>= 2)
|
|
401
|
-
* @example
|
|
402
|
-
* @example
|
|
403
|
-
* @example
|
|
395
|
+
* @example encryptionBitsFromFheType('ebool') // 2
|
|
396
|
+
* @example encryptionBitsFromFheType('euint32') // 32
|
|
397
|
+
* @example encryptionBitsFromFheType('eaddress') // 160
|
|
404
398
|
*/
|
|
405
399
|
export function encryptionBitsFromFheType(name: FheType): EncryptionBits {
|
|
406
400
|
const bw = FheTypeIdToEncryptionBits[FheTypeNameToId[name]];
|
|
@@ -463,11 +457,11 @@ export function bytesToClearValueType<etype extends FheType>(fheType: etype, byt
|
|
|
463
457
|
* and returns it narrowed. No conversion is performed.
|
|
464
458
|
*
|
|
465
459
|
* - `ebool` → `boolean`
|
|
466
|
-
* - `eaddress` → `string` (
|
|
460
|
+
* - `eaddress` → `string` (validated address)
|
|
467
461
|
* - `euint8/16/32` → `number`
|
|
468
462
|
* - `euint64/128/256` → `bigint`
|
|
469
463
|
*
|
|
470
|
-
* @throws If `value` is not the expected JS type
|
|
464
|
+
* @throws If `value` is not the expected JS type.
|
|
471
465
|
*/
|
|
472
466
|
export function asClearValueType<etype extends FheType>(
|
|
473
467
|
fheTypeName: etype,
|
|
@@ -504,14 +498,13 @@ export function asClearValueType<etype extends FheType>(
|
|
|
504
498
|
|
|
505
499
|
/**
|
|
506
500
|
* Converts `value` to the correct JS type for the given `fheTypeName`.
|
|
507
|
-
* Accepts any uint-like input (number, bigint, string) and coerces it.
|
|
508
501
|
*
|
|
509
|
-
* - `ebool` → `boolean`
|
|
502
|
+
* - `ebool` → `boolean` (value must already be a `boolean`; no coercion)
|
|
510
503
|
* - `eaddress` → `string` (validated address)
|
|
511
|
-
* - `euint8/16/32` → coerced to `number` via `Number()`
|
|
512
|
-
* - `euint64/128/256` → coerced to `bigint` via `BigInt()`
|
|
504
|
+
* - `euint8/16/32` → coerced to `number` via `Number()` (accepts `number` or `bigint`)
|
|
505
|
+
* - `euint64/128/256` → coerced to `bigint` via `BigInt()` (accepts `number` or `bigint`)
|
|
513
506
|
*
|
|
514
|
-
* @throws If `value`
|
|
507
|
+
* @throws If `value` is not the expected JS type or cannot be coerced.
|
|
515
508
|
*/
|
|
516
509
|
export function toClearValueType<etype extends FheType>(
|
|
517
510
|
fheTypeName: etype,
|
|
@@ -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;
|
|
@@ -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';
|
|
@@ -125,7 +125,7 @@ abstract class SignedDecryptionPermitBaseImpl {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
public get
|
|
128
|
+
public get transportPublicKey(): BytesHex {
|
|
129
129
|
return this.#eip712.message.publicKey;
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -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 TransportKeyPairKeyPair'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';
|
package/core/kms/kmsExtraData.ts
CHANGED
|
@@ -9,6 +9,13 @@ export function fromKmsExtraData(extraData: BytesHex): {
|
|
|
9
9
|
version: Uint8Number;
|
|
10
10
|
kmsContextId: Uint256BigInt;
|
|
11
11
|
} {
|
|
12
|
+
if ((extraData as string) === '0x00' || (extraData as string) === '0x') {
|
|
13
|
+
return {
|
|
14
|
+
version: 0 as Uint8Number,
|
|
15
|
+
kmsContextId: 0n as Uint256BigInt,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
// First byte = version (characters 2-3 after '0x')
|
|
13
20
|
const version = asUint8Number(parseInt(extraData.slice(2, 4), 16));
|
|
14
21
|
|
|
@@ -43,7 +50,7 @@ export function assertIsKmsExtraData(
|
|
|
43
50
|
value: unknown,
|
|
44
51
|
options: { subject?: string } & ErrorMetadataParams,
|
|
45
52
|
): asserts value is BytesHex {
|
|
46
|
-
if (value === '0x00') {
|
|
53
|
+
if (value === '0x00' || value === '0x') {
|
|
47
54
|
return;
|
|
48
55
|
}
|
|
49
56
|
assertIsBytesHex(value, { ...options, byteLength: 33 as ByteLength });
|
|
@@ -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
|
////////////////////////////////////////////////////////////////////////////////
|