@fhevm/sdk 0.14.4-0 → 0.14.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/_version.js.map +1 -1
- package/_cjs/core/chains/definitions/bscTestnet.js +36 -0
- package/_cjs/core/chains/definitions/bscTestnet.js.map +1 -0
- package/_cjs/core/chains/index.js +3 -1
- package/_cjs/core/chains/index.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js +40 -47
- package/_cjs/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchPublicDecrypt.js +13 -7
- package/_cjs/core/modules/relayer/cleartext/fetchPublicDecrypt.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV1.js +38 -45
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV1.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV2.js +104 -2
- package/_cjs/core/modules/relayer/cleartext/fetchUserDecryptV2.js.map +1 -1
- package/_cjs/core/modules/relayer/cleartext/signers.js +35 -0
- package/_cjs/core/modules/relayer/cleartext/signers.js.map +1 -1
- package/_cjs/core/modules/relayer/module/RelayerAsyncRequest.js +12 -2
- package/_cjs/core/modules/relayer/module/RelayerAsyncRequest.js.map +1 -1
- package/_cjs/core/modules/relayer/module/fetchFheEncryptionKeySource.js +5 -3
- package/_cjs/core/modules/relayer/module/fetchFheEncryptionKeySource.js.map +1 -1
- package/_cjs/core/modules/relayer/module/relayerUrl.js +37 -0
- package/_cjs/core/modules/relayer/module/relayerUrl.js.map +1 -1
- package/_cjs/wasm/tfhe/loadTfheLib.js.map +1 -1
- package/_cjs/wasm/tkms/loadKmsLib.js.map +1 -1
- package/_esm/core/_version.js +1 -1
- package/_esm/core/_version.js.map +1 -1
- package/_esm/core/chains/definitions/bscTestnet.js +33 -0
- package/_esm/core/chains/definitions/bscTestnet.js.map +1 -0
- package/_esm/core/chains/index.js +1 -0
- package/_esm/core/chains/index.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js +43 -51
- package/_esm/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchPublicDecrypt.js +15 -9
- package/_esm/core/modules/relayer/cleartext/fetchPublicDecrypt.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV1.js +42 -49
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV1.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV2.js +111 -3
- package/_esm/core/modules/relayer/cleartext/fetchUserDecryptV2.js.map +1 -1
- package/_esm/core/modules/relayer/cleartext/signers.js +41 -0
- package/_esm/core/modules/relayer/cleartext/signers.js.map +1 -1
- package/_esm/core/modules/relayer/module/RelayerAsyncRequest.js +14 -2
- package/_esm/core/modules/relayer/module/RelayerAsyncRequest.js.map +1 -1
- package/_esm/core/modules/relayer/module/fetchFheEncryptionKeySource.js +7 -4
- package/_esm/core/modules/relayer/module/fetchFheEncryptionKeySource.js.map +1 -1
- package/_esm/core/modules/relayer/module/relayerUrl.js +48 -1
- package/_esm/core/modules/relayer/module/relayerUrl.js.map +1 -1
- package/_types/core/_version.d.ts.map +1 -1
- package/_types/core/chains/definitions/bscTestnet.d.ts +3 -0
- package/_types/core/chains/definitions/bscTestnet.d.ts.map +1 -0
- package/_types/core/chains/index.d.ts +1 -0
- package/_types/core/chains/index.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchPublicDecrypt.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV1.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV2.d.ts +1 -1
- package/_types/core/modules/relayer/cleartext/fetchUserDecryptV2.d.ts.map +1 -1
- package/_types/core/modules/relayer/cleartext/signers.d.ts +13 -0
- package/_types/core/modules/relayer/cleartext/signers.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/RelayerAsyncRequest.d.ts +1 -0
- package/_types/core/modules/relayer/module/RelayerAsyncRequest.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/fetchFheEncryptionKeySource.d.ts.map +1 -1
- package/_types/core/modules/relayer/module/relayerUrl.d.ts +12 -1
- package/_types/core/modules/relayer/module/relayerUrl.d.ts.map +1 -1
- package/_types/core/types/relayer.d.ts +6 -0
- package/_types/core/types/relayer.d.ts.map +1 -1
- package/core/_version.ts +1 -1
- package/core/chains/definitions/bscTestnet.ts +34 -0
- package/core/chains/index.ts +1 -0
- package/core/modules/relayer/cleartext/fetchDelegatedUserDecryptV1.ts +49 -60
- package/core/modules/relayer/cleartext/fetchPublicDecrypt.ts +19 -9
- package/core/modules/relayer/cleartext/fetchUserDecryptV1.ts +48 -58
- package/core/modules/relayer/cleartext/fetchUserDecryptV2.ts +133 -4
- package/core/modules/relayer/cleartext/signers.ts +61 -0
- package/core/modules/relayer/module/RelayerAsyncRequest.ts +11 -2
- package/core/modules/relayer/module/fetchFheEncryptionKeySource.ts +12 -4
- package/core/modules/relayer/module/relayerUrl.ts +52 -1
- package/core/types/relayer.ts +6 -0
- package/package.json +1 -1
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* - parses as a URL
|
|
7
7
|
* - protocol is `http:` or `https:`
|
|
8
8
|
* - contains no userinfo (`user:pass@host`)
|
|
9
|
-
* - contains no query string or fragment (they would corrupt path concatenation)
|
|
10
9
|
* - if `hasAuth` is true, requires `https:` unless the host is localhost
|
|
11
10
|
*
|
|
12
11
|
* Normalization (via WHATWG `URL`):
|
|
@@ -14,6 +13,7 @@
|
|
|
14
13
|
* - default ports collapsed (`:443` for https, `:80` for http)
|
|
15
14
|
* - path percent-encoded canonically
|
|
16
15
|
* - bare-origin URLs get a single trailing `/` (`https://x` → `https://x/`)
|
|
16
|
+
* - query string and fragment dropped, with a warning (use `options.query` instead)
|
|
17
17
|
*
|
|
18
18
|
* Throws {@link InvalidUrlError} on any failure so the caller surfaces a
|
|
19
19
|
* uniform error type.
|
|
@@ -22,4 +22,15 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function validateRelayerBaseUrl(relayerUrl: unknown, hasAuth: boolean): URL;
|
|
24
24
|
export declare function buildRelayerUrlString(relayerBaseUrl: URL, path: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Validates `options.query` once at intake and returns a detached copy of its string entries.
|
|
27
|
+
*
|
|
28
|
+
* @throws If a key or value cannot be percent-encoded, so a bad query fails here and not as a generic fetch error.
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeRelayerQuery(query: unknown): Readonly<Record<string, string>> | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Use the result only as the URL passed to `fetch()`. Keep the query-less `url`
|
|
33
|
+
* for errors, logs and callbacks, so they show the endpoint, not per-request metadata.
|
|
34
|
+
*/
|
|
35
|
+
export declare function appendRelayerQuery(url: string, query: Readonly<Record<string, string>> | undefined): string;
|
|
25
36
|
//# sourceMappingURL=relayerUrl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayerUrl.d.ts","sourceRoot":"","sources":["../../../../../core/modules/relayer/module/relayerUrl.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"relayerUrl.d.ts","sourceRoot":"","sources":["../../../../../core/modules/relayer/module/relayerUrl.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,GAAG,CAsDjF;AAED,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAkBlG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GAAG,MAAM,CAS3G"}
|
|
@@ -24,6 +24,12 @@ export type FetchDelegatedUserDecryptResult = readonly FetchUserDecryptResultIte
|
|
|
24
24
|
export type RelayerCommonOptions = {
|
|
25
25
|
auth?: Auth | undefined;
|
|
26
26
|
headers?: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Extra query parameters sent with job requests and the key-URL lookup.
|
|
29
|
+
* Used by the Zama SDK to send its metadata (`zama_*`) when a proxy in front
|
|
30
|
+
* of the relayer doesn't forward custom headers. Prefer `headers`.
|
|
31
|
+
*/
|
|
32
|
+
query?: Record<string, string> | undefined;
|
|
27
33
|
debug?: boolean | undefined;
|
|
28
34
|
fetchRetries?: number | undefined;
|
|
29
35
|
fetchRetryDelayInMilliseconds?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayer.d.ts","sourceRoot":"","sources":["../../../core/types/relayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA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Q,CAAC,eAAe,EAAE;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CACF,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,oBAAoB,IAAI,QAAQ,CAC7E,wBAAwB,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;CACnC,CACF,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,IACnD,QAAQ,CACV,yBAAyB,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CACF,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,oBAAoB,IAAI,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;AAEjH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,oBAAoB,IAAI,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
package/core/_version.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FhevmChain } from '../../types/fhevmChain.js';
|
|
2
|
+
import { defineFhevmChain } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export const bscTestnet: FhevmChain = /*#__PURE__*/ defineFhevmChain({
|
|
5
|
+
id: 97,
|
|
6
|
+
fhevm: {
|
|
7
|
+
contracts: {
|
|
8
|
+
acl: {
|
|
9
|
+
address: '0x9Adac873Ae2f737AF011f0778305Cff0B220ac36',
|
|
10
|
+
},
|
|
11
|
+
inputVerifier: {
|
|
12
|
+
address: '0xDd378841F0125656b97818d9d371e1027Df4c424',
|
|
13
|
+
},
|
|
14
|
+
kmsVerifier: {
|
|
15
|
+
address: '0x1F7CAD0c05fDED5F988683AdfDB4F242b310cdcB',
|
|
16
|
+
},
|
|
17
|
+
protocolConfig: {
|
|
18
|
+
address: '0xC320dd3d4e15D8E4c20dff42fE09Aa936A88b3ED',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
relayerUrl: 'https://relayer.testnet.zama.org',
|
|
22
|
+
gateway: {
|
|
23
|
+
id: 10_901,
|
|
24
|
+
contracts: {
|
|
25
|
+
decryption: {
|
|
26
|
+
address: '0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478',
|
|
27
|
+
},
|
|
28
|
+
inputVerification: {
|
|
29
|
+
address: '0x483b9dE06E4E4C7D35CCf5837A1668487406D955',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
package/core/chains/index.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { defineFhevmChain } from './utils.js';
|
|
|
4
4
|
|
|
5
5
|
export { mainnet } from './definitions/mainnet.js';
|
|
6
6
|
export { sepolia } from './definitions/sepolia.js';
|
|
7
|
+
export { bscTestnet } from './definitions/bscTestnet.js';
|
|
7
8
|
export { polygon } from './definitions/polygon.js';
|
|
8
9
|
export { polygonAmoy } from './definitions/polygonAmoy.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { BytesHex, ChecksummedAddress, Uint32BigInt } from '../../../types/primitives.js';
|
|
2
|
-
import type { FetchUserDecryptResultItem } from '../../../types/relayer.js';
|
|
3
|
-
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
4
2
|
import type {
|
|
5
3
|
FetchDelegatedUserDecryptParameters,
|
|
6
4
|
FetchUserDecryptReturnType,
|
|
@@ -8,11 +6,9 @@ import type {
|
|
|
8
6
|
} from '../types.js';
|
|
9
7
|
import type { KmsSignersContext } from '../../../types/kmsSignersContext.js';
|
|
10
8
|
import type { FhevmClientFrozenContext } from '../../../types/fhevmClientFrozenContext-p.js';
|
|
11
|
-
import {
|
|
12
|
-
import { asUint32BigInt, tryParseUintBigIntString, randomUniqueUints } from '../../../base/uint.js';
|
|
9
|
+
import { asUint32BigInt, tryParseUintBigIntString } from '../../../base/uint.js';
|
|
13
10
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
14
|
-
import {
|
|
15
|
-
import { getKmsSignersPrivateKeyMap } from './signers.js';
|
|
11
|
+
import { signKmsSigncryptedShares } from './signers.js';
|
|
16
12
|
import { isForgeFhevmV1, readPlaintexts, xorMaskWithPublicKey } from './forgeFhevmV1.js';
|
|
17
13
|
import { readCurrentKmsSignersContext } from '../../../host-contracts/readKmsSignersContext-p.js';
|
|
18
14
|
|
|
@@ -74,10 +70,10 @@ async function runDelegatedUserDecryptOffChain(
|
|
|
74
70
|
// runDelegatedUserDecryptOnChain
|
|
75
71
|
////////////////////////////////////////////////////////////////////////////////
|
|
76
72
|
|
|
77
|
-
const
|
|
73
|
+
const delegatedUserDecryptV1Abi = [
|
|
78
74
|
{
|
|
79
75
|
type: 'function',
|
|
80
|
-
name: '
|
|
76
|
+
name: 'delegatedUserDecryptV1',
|
|
81
77
|
inputs: [
|
|
82
78
|
{
|
|
83
79
|
name: 'pairs',
|
|
@@ -92,31 +88,39 @@ const delegatedUserDecryptAbi = [
|
|
|
92
88
|
},
|
|
93
89
|
],
|
|
94
90
|
},
|
|
95
|
-
{ name: 'delegator', type: 'address', internalType: 'address' },
|
|
96
|
-
{ name: 'delegate', type: 'address', internalType: 'address' },
|
|
97
|
-
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
98
91
|
{
|
|
99
|
-
name: '
|
|
100
|
-
type: '
|
|
101
|
-
internalType: '
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
92
|
+
name: 'permit',
|
|
93
|
+
type: 'tuple',
|
|
94
|
+
internalType: 'struct DelegatedUserDecryptPermitV1',
|
|
95
|
+
components: [
|
|
96
|
+
{ name: 'delegateAddress', type: 'address', internalType: 'address' },
|
|
97
|
+
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
98
|
+
{
|
|
99
|
+
name: 'contractAddresses',
|
|
100
|
+
type: 'address[]',
|
|
101
|
+
internalType: 'address[]',
|
|
102
|
+
},
|
|
103
|
+
{ name: 'delegatorAddress', type: 'address', internalType: 'address' },
|
|
104
|
+
{
|
|
105
|
+
name: 'startTimestamp',
|
|
106
|
+
type: 'uint256',
|
|
107
|
+
internalType: 'uint256',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'durationDays',
|
|
111
|
+
type: 'uint256',
|
|
112
|
+
internalType: 'uint256',
|
|
113
|
+
},
|
|
114
|
+
{ name: 'extraData', type: 'bytes', internalType: 'bytes' },
|
|
115
|
+
],
|
|
112
116
|
},
|
|
113
|
-
{ name: '
|
|
117
|
+
{ name: 'signature', type: 'bytes', internalType: 'bytes' },
|
|
114
118
|
],
|
|
115
119
|
outputs: [
|
|
116
120
|
{ name: 'payload', type: 'bytes', internalType: 'bytes' },
|
|
117
121
|
{ name: 'signers', type: 'address[]', internalType: 'address[]' },
|
|
118
122
|
{ name: 'threshold', type: 'uint256', internalType: 'uint256' },
|
|
119
|
-
{ name: '
|
|
123
|
+
{ name: 'signedExtraData', type: 'bytes', internalType: 'bytes' },
|
|
120
124
|
],
|
|
121
125
|
stateMutability: 'view',
|
|
122
126
|
},
|
|
@@ -134,23 +138,33 @@ async function runDelegatedUserDecryptOnChain(
|
|
|
134
138
|
const { kmsDecryptEip712Message, kmsDecryptEip712Signer, kmsDecryptEip712Signature } = payload;
|
|
135
139
|
const pairs = payload.handleContractPairs;
|
|
136
140
|
const trustedClient = getTrustedClient(relayerClient);
|
|
141
|
+
// The permit's extraData is passed verbatim, as in fetchUserDecryptV1.
|
|
137
142
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
138
|
-
abi:
|
|
143
|
+
abi: delegatedUserDecryptV1Abi,
|
|
139
144
|
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
140
145
|
args: [
|
|
141
146
|
pairs.map((p) => ({
|
|
142
147
|
handle: p.handle.bytes32Hex,
|
|
143
148
|
contractAddress: p.contractAddress,
|
|
144
149
|
})),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
{
|
|
151
|
+
delegateAddress: kmsDecryptEip712Signer,
|
|
152
|
+
publicKey: kmsDecryptEip712Message.publicKey,
|
|
153
|
+
contractAddresses: kmsDecryptEip712Message.contractAddresses,
|
|
154
|
+
delegatorAddress: kmsDecryptEip712Message.delegatorAddress,
|
|
155
|
+
startTimestamp: _parseUintBigIntString(
|
|
156
|
+
'kmsDecryptEip712Message.startTimestamp',
|
|
157
|
+
kmsDecryptEip712Message.startTimestamp,
|
|
158
|
+
),
|
|
159
|
+
durationDays: _parseUintBigIntString(
|
|
160
|
+
'kmsDecryptEip712Message.durationDays',
|
|
161
|
+
kmsDecryptEip712Message.durationDays,
|
|
162
|
+
),
|
|
163
|
+
extraData: kmsDecryptEip712Message.extraData,
|
|
164
|
+
},
|
|
151
165
|
kmsDecryptEip712Signature,
|
|
152
166
|
],
|
|
153
|
-
functionName:
|
|
167
|
+
functionName: delegatedUserDecryptV1Abi[0].name,
|
|
154
168
|
})) as unknown[];
|
|
155
169
|
|
|
156
170
|
const commonKmsSigncryptedSharePayload = res[0] as BytesHex;
|
|
@@ -172,7 +186,6 @@ export async function fetchDelegatedUserDecrypt(
|
|
|
172
186
|
relayerClient: RelayerClientWithRuntime,
|
|
173
187
|
parameters: FetchDelegatedUserDecryptParameters,
|
|
174
188
|
): Promise<FetchUserDecryptReturnType> {
|
|
175
|
-
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
176
189
|
const { payload, fhevmContext } = parameters;
|
|
177
190
|
const pairs = payload.handleContractPairs;
|
|
178
191
|
const contractAddresses = payload.kmsDecryptEip712Message.contractAddresses;
|
|
@@ -200,31 +213,7 @@ export async function fetchDelegatedUserDecrypt(
|
|
|
200
213
|
res = await runDelegatedUserDecryptOnChain(relayerClient, payload);
|
|
201
214
|
}
|
|
202
215
|
|
|
203
|
-
|
|
204
|
-
const extraData = res.extraData;
|
|
205
|
-
const threshold = res.threshold;
|
|
206
|
-
const signersAddress = res.signersAddress;
|
|
207
|
-
|
|
208
|
-
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
209
|
-
|
|
210
|
-
const randomSignersAddress = randomUniqueUints(signersAddress.length, Number(threshold)).map(
|
|
211
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
212
|
-
(i) => signersAddress[i]!,
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
const result: FetchUserDecryptResultItem[] = [];
|
|
216
|
-
|
|
217
|
-
for (const signerAddress of randomSignersAddress) {
|
|
218
|
-
const privateKey = signers.get(signerAddress);
|
|
219
|
-
if (privateKey === undefined) {
|
|
220
|
-
throw new Error(`Unable to find KMS signer for address ${signerAddress}`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const signature = await cleartextEthereumModule.sign({ hash: commonKmsSigncryptedSharePayload, privateKey });
|
|
224
|
-
result.push({ signature: remove0x(signature), payload: remove0x(commonKmsSigncryptedSharePayload), extraData });
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return userDecryptResultToKmsSigncryptedShares(result);
|
|
216
|
+
return signKmsSigncryptedShares(relayerClient, { ...res, threshold: Number(res.threshold) });
|
|
228
217
|
}
|
|
229
218
|
|
|
230
219
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -4,7 +4,7 @@ import type { FetchPublicDecryptParameters, FetchPublicDecryptReturnType, Relaye
|
|
|
4
4
|
import type { KmsSignersContext } from '../../../types/kmsSignersContext.js';
|
|
5
5
|
import type { FhevmClientFrozenContext } from '../../../types/fhevmClientFrozenContext-p.js';
|
|
6
6
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
7
|
-
import { getKmsSignersPrivateKeyMap } from './signers.js';
|
|
7
|
+
import { getKmsSignersPrivateKeyMap, pickRespondingKmsSigners } from './signers.js';
|
|
8
8
|
import { encodeTypedCleartexts, isForgeFhevmV1, readPlaintexts } from './forgeFhevmV1.js';
|
|
9
9
|
import { createKmsEip712Domain } from '../../../kms/createKmsEip712Domain.js';
|
|
10
10
|
import { readCurrentKmsSignersContext } from '../../../host-contracts/readKmsSignersContext-p.js';
|
|
@@ -16,7 +16,10 @@ const publicDecryptAbi = [
|
|
|
16
16
|
{
|
|
17
17
|
type: 'function',
|
|
18
18
|
name: 'publicDecrypt',
|
|
19
|
-
inputs: [
|
|
19
|
+
inputs: [
|
|
20
|
+
{ name: 'handles', type: 'bytes32[]', internalType: 'bytes32[]' },
|
|
21
|
+
{ name: 'extraData', type: 'bytes', internalType: 'bytes' },
|
|
22
|
+
],
|
|
20
23
|
outputs: [
|
|
21
24
|
{
|
|
22
25
|
name: 'abiEncodedCleartexts',
|
|
@@ -26,7 +29,7 @@ const publicDecryptAbi = [
|
|
|
26
29
|
{ name: 'digest', type: 'bytes32', internalType: 'bytes32' },
|
|
27
30
|
{ name: 'signers', type: 'address[]', internalType: 'address[]' },
|
|
28
31
|
{ name: 'threshold', type: 'uint256', internalType: 'uint256' },
|
|
29
|
-
{ name: '
|
|
32
|
+
{ name: 'signedExtraData', type: 'bytes', internalType: 'bytes' },
|
|
30
33
|
],
|
|
31
34
|
stateMutability: 'view',
|
|
32
35
|
},
|
|
@@ -42,6 +45,7 @@ async function runPublicDecryptOffChain(
|
|
|
42
45
|
readonly orderedAbiEncodedClearValues: BytesHex;
|
|
43
46
|
readonly digest: Bytes32Hex;
|
|
44
47
|
readonly signersAddress: readonly ChecksummedAddress[];
|
|
48
|
+
readonly threshold: number;
|
|
45
49
|
readonly extraData: BytesHex;
|
|
46
50
|
}> {
|
|
47
51
|
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
@@ -96,6 +100,7 @@ async function runPublicDecryptOffChain(
|
|
|
96
100
|
orderedAbiEncodedClearValues,
|
|
97
101
|
digest,
|
|
98
102
|
signersAddress: currentKmsSignersContext.signers,
|
|
103
|
+
threshold: currentKmsSignersContext.threshold,
|
|
99
104
|
extraData,
|
|
100
105
|
};
|
|
101
106
|
}
|
|
@@ -111,25 +116,29 @@ async function runPublicDecryptOnChain(
|
|
|
111
116
|
readonly orderedAbiEncodedClearValues: BytesHex;
|
|
112
117
|
readonly digest: Bytes32Hex;
|
|
113
118
|
readonly signersAddress: readonly ChecksummedAddress[];
|
|
119
|
+
readonly threshold: number;
|
|
114
120
|
readonly extraData: BytesHex;
|
|
115
121
|
}> {
|
|
116
122
|
const trustedClient = getTrustedClient(relayerClient);
|
|
123
|
+
// The host signs over exactly the requested extraData and returns the signers of the context it names.
|
|
117
124
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
118
125
|
abi: publicDecryptAbi,
|
|
119
126
|
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
120
|
-
args: [payload.orderedHandles.map((h) => h.bytes32Hex)],
|
|
127
|
+
args: [payload.orderedHandles.map((h) => h.bytes32Hex), payload.extraData],
|
|
121
128
|
functionName: publicDecryptAbi[0].name,
|
|
122
129
|
})) as unknown[];
|
|
123
130
|
|
|
124
131
|
const orderedAbiEncodedClearValues = res[0] as BytesHex;
|
|
125
132
|
const digest = res[1] as Bytes32Hex;
|
|
126
133
|
const signersAddress = res[2] as readonly ChecksummedAddress[];
|
|
134
|
+
const threshold = Number(res[3]);
|
|
127
135
|
const extraData = res[4] as BytesHex;
|
|
128
136
|
|
|
129
137
|
return {
|
|
130
138
|
orderedAbiEncodedClearValues,
|
|
131
139
|
digest,
|
|
132
140
|
signersAddress,
|
|
141
|
+
threshold,
|
|
133
142
|
extraData,
|
|
134
143
|
};
|
|
135
144
|
}
|
|
@@ -152,16 +161,17 @@ export async function fetchPublicDecrypt(
|
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
const digest = res.digest;
|
|
155
|
-
const signersAddress = res.signersAddress;
|
|
156
164
|
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
165
|
+
const responders = pickRespondingKmsSigners(res.signersAddress, res.threshold);
|
|
157
166
|
|
|
158
167
|
const kmsPublicDecryptEip712Signatures: Bytes65Hex[] = [];
|
|
159
168
|
|
|
160
|
-
for (
|
|
161
|
-
|
|
162
|
-
const privateKey = signers.get(signersAddress[i]!);
|
|
169
|
+
for (const signerAddress of responders) {
|
|
170
|
+
const privateKey = signers.get(signerAddress);
|
|
163
171
|
if (privateKey === undefined) {
|
|
164
|
-
throw new Error(
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Unable to find KMS signer for address ${signerAddress} (${responders.length} of ${res.signersAddress.length} responding)`,
|
|
174
|
+
);
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
const signature = await cleartextEthereumModule.sign({ hash: digest, privateKey });
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { BytesHex, ChecksummedAddress, Uint32BigInt } from '../../../types/primitives.js';
|
|
2
|
-
import type { FetchUserDecryptResultItem } from '../../../types/relayer.js';
|
|
3
|
-
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
4
2
|
import type { FetchUserDecryptParametersV1, FetchUserDecryptReturnType, RelayerClientWithRuntime } from '../types.js';
|
|
5
3
|
import type { KmsSignersContext } from '../../../types/kmsSignersContext.js';
|
|
6
4
|
import type { FhevmClientFrozenContext } from '../../../types/fhevmClientFrozenContext-p.js';
|
|
7
|
-
import {
|
|
8
|
-
import { asUint32BigInt, tryParseUintBigIntString, randomUniqueUints } from '../../../base/uint.js';
|
|
5
|
+
import { asUint32BigInt, tryParseUintBigIntString } from '../../../base/uint.js';
|
|
9
6
|
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
10
|
-
import {
|
|
11
|
-
import { getKmsSignersPrivateKeyMap } from './signers.js';
|
|
7
|
+
import { signKmsSigncryptedShares } from './signers.js';
|
|
12
8
|
import { readCurrentKmsSignersContext } from '../../../host-contracts/readKmsSignersContext-p.js';
|
|
13
9
|
import { isForgeFhevmV1, readPlaintexts, xorMaskWithPublicKey } from './forgeFhevmV1.js';
|
|
14
10
|
|
|
@@ -70,10 +66,10 @@ async function runUserDecryptOffChain(
|
|
|
70
66
|
// runUserDecryptOnChain
|
|
71
67
|
////////////////////////////////////////////////////////////////////////////////
|
|
72
68
|
|
|
73
|
-
const
|
|
69
|
+
const userDecryptV1Abi = [
|
|
74
70
|
{
|
|
75
71
|
type: 'function',
|
|
76
|
-
name: '
|
|
72
|
+
name: 'userDecryptV1',
|
|
77
73
|
inputs: [
|
|
78
74
|
{
|
|
79
75
|
name: 'pairs',
|
|
@@ -88,30 +84,38 @@ const userDecryptAbi = [
|
|
|
88
84
|
},
|
|
89
85
|
],
|
|
90
86
|
},
|
|
91
|
-
{ name: 'userAddress', type: 'address', internalType: 'address' },
|
|
92
|
-
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
93
87
|
{
|
|
94
|
-
name: '
|
|
95
|
-
type: '
|
|
96
|
-
internalType: '
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
88
|
+
name: 'permit',
|
|
89
|
+
type: 'tuple',
|
|
90
|
+
internalType: 'struct UserDecryptPermitV1',
|
|
91
|
+
components: [
|
|
92
|
+
{ name: 'userAddress', type: 'address', internalType: 'address' },
|
|
93
|
+
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
94
|
+
{
|
|
95
|
+
name: 'contractAddresses',
|
|
96
|
+
type: 'address[]',
|
|
97
|
+
internalType: 'address[]',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'startTimestamp',
|
|
101
|
+
type: 'uint256',
|
|
102
|
+
internalType: 'uint256',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'durationDays',
|
|
106
|
+
type: 'uint256',
|
|
107
|
+
internalType: 'uint256',
|
|
108
|
+
},
|
|
109
|
+
{ name: 'extraData', type: 'bytes', internalType: 'bytes' },
|
|
110
|
+
],
|
|
107
111
|
},
|
|
108
|
-
{ name: '
|
|
112
|
+
{ name: 'signature', type: 'bytes', internalType: 'bytes' },
|
|
109
113
|
],
|
|
110
114
|
outputs: [
|
|
111
115
|
{ name: 'payload', type: 'bytes', internalType: 'bytes' },
|
|
112
116
|
{ name: 'signers', type: 'address[]', internalType: 'address[]' },
|
|
113
117
|
{ name: 'threshold', type: 'uint256', internalType: 'uint256' },
|
|
114
|
-
{ name: '
|
|
118
|
+
{ name: 'signedExtraData', type: 'bytes', internalType: 'bytes' },
|
|
115
119
|
],
|
|
116
120
|
stateMutability: 'view',
|
|
117
121
|
},
|
|
@@ -129,22 +133,33 @@ async function runUserDecryptOnChain(
|
|
|
129
133
|
const { kmsDecryptEip712Message, kmsDecryptEip712Signer, kmsDecryptEip712Signature } = payload;
|
|
130
134
|
const pairs = payload.handleContractPairs;
|
|
131
135
|
const trustedClient = getTrustedClient(relayerClient);
|
|
136
|
+
// The permit's extraData is passed verbatim: the host verifies the signature over it and returns the
|
|
137
|
+
// signers of the KMS context it names, which may no longer be the current one.
|
|
132
138
|
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
133
|
-
abi:
|
|
139
|
+
abi: userDecryptV1Abi,
|
|
134
140
|
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
135
141
|
args: [
|
|
136
142
|
pairs.map((p) => ({
|
|
137
143
|
handle: p.handle.bytes32Hex,
|
|
138
144
|
contractAddress: p.contractAddress,
|
|
139
145
|
})),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
{
|
|
147
|
+
userAddress: kmsDecryptEip712Signer,
|
|
148
|
+
publicKey: kmsDecryptEip712Message.publicKey,
|
|
149
|
+
contractAddresses: kmsDecryptEip712Message.contractAddresses,
|
|
150
|
+
startTimestamp: _parseUintBigIntString(
|
|
151
|
+
'kmsDecryptEip712Message.startTimestamp',
|
|
152
|
+
kmsDecryptEip712Message.startTimestamp,
|
|
153
|
+
),
|
|
154
|
+
durationDays: _parseUintBigIntString(
|
|
155
|
+
'kmsDecryptEip712Message.durationDays',
|
|
156
|
+
kmsDecryptEip712Message.durationDays,
|
|
157
|
+
),
|
|
158
|
+
extraData: kmsDecryptEip712Message.extraData,
|
|
159
|
+
},
|
|
145
160
|
kmsDecryptEip712Signature,
|
|
146
161
|
],
|
|
147
|
-
functionName:
|
|
162
|
+
functionName: userDecryptV1Abi[0].name,
|
|
148
163
|
})) as unknown[];
|
|
149
164
|
|
|
150
165
|
const commonKmsSigncryptedSharePayload = res[0] as BytesHex;
|
|
@@ -166,7 +181,6 @@ export async function fetchUserDecryptV1(
|
|
|
166
181
|
relayerClient: RelayerClientWithRuntime,
|
|
167
182
|
parameters: FetchUserDecryptParametersV1,
|
|
168
183
|
): Promise<FetchUserDecryptReturnType> {
|
|
169
|
-
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
170
184
|
const { payload, fhevmContext } = parameters;
|
|
171
185
|
const pairs = payload.handleContractPairs;
|
|
172
186
|
const contractAddresses = payload.kmsDecryptEip712Message.contractAddresses;
|
|
@@ -194,31 +208,7 @@ export async function fetchUserDecryptV1(
|
|
|
194
208
|
res = await runUserDecryptOnChain(relayerClient, payload);
|
|
195
209
|
}
|
|
196
210
|
|
|
197
|
-
|
|
198
|
-
const extraData = res.extraData;
|
|
199
|
-
const threshold = res.threshold;
|
|
200
|
-
const signersAddress = res.signersAddress;
|
|
201
|
-
|
|
202
|
-
const signers = getKmsSignersPrivateKeyMap(relayerClient);
|
|
203
|
-
|
|
204
|
-
const randomSignersAddress = randomUniqueUints(signersAddress.length, Number(threshold)).map(
|
|
205
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
206
|
-
(i) => signersAddress[i]!,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const result: FetchUserDecryptResultItem[] = [];
|
|
210
|
-
|
|
211
|
-
for (const signerAddress of randomSignersAddress) {
|
|
212
|
-
const privateKey = signers.get(signerAddress);
|
|
213
|
-
if (privateKey === undefined) {
|
|
214
|
-
throw new Error(`Unable to find KMS signer for address ${signerAddress}`);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const signature = await cleartextEthereumModule.sign({ hash: commonKmsSigncryptedSharePayload, privateKey });
|
|
218
|
-
result.push({ signature: remove0x(signature), payload: remove0x(commonKmsSigncryptedSharePayload), extraData });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return userDecryptResultToKmsSigncryptedShares(result);
|
|
211
|
+
return signKmsSigncryptedShares(relayerClient, { ...res, threshold: Number(res.threshold) });
|
|
222
212
|
}
|
|
223
213
|
|
|
224
214
|
////////////////////////////////////////////////////////////////////////////////
|