@fhevm/sdk 0.15.0-0 → 0.15.0-10
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/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/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/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/_types/core/_version.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/core/_version.ts +1 -1
- 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/package.json +1 -1
|
@@ -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
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,11 +1,140 @@
|
|
|
1
|
+
import type { BytesHex, ChecksummedAddress, Uint32BigInt } from '../../../types/primitives.js';
|
|
1
2
|
import type { FetchUserDecryptParametersV2, FetchUserDecryptReturnType, RelayerClientWithRuntime } from '../types.js';
|
|
3
|
+
import { asUint32BigInt, tryParseUintBigIntString } from '../../../base/uint.js';
|
|
4
|
+
import { getTrustedClient } from '../../../runtime/CoreFhevm-p.js';
|
|
5
|
+
import { signKmsSigncryptedShares } from './signers.js';
|
|
6
|
+
|
|
7
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
// runUserDecryptV2OnChain
|
|
9
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
10
|
+
|
|
11
|
+
const userDecryptV2Abi = [
|
|
12
|
+
{
|
|
13
|
+
type: 'function',
|
|
14
|
+
name: 'userDecryptV2',
|
|
15
|
+
inputs: [
|
|
16
|
+
{
|
|
17
|
+
name: 'handles',
|
|
18
|
+
type: 'tuple[]',
|
|
19
|
+
internalType: 'struct HandleEntry[]',
|
|
20
|
+
components: [
|
|
21
|
+
{ name: 'handle', type: 'bytes32', internalType: 'bytes32' },
|
|
22
|
+
{
|
|
23
|
+
name: 'contractAddress',
|
|
24
|
+
type: 'address',
|
|
25
|
+
internalType: 'address',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'ownerAddress',
|
|
29
|
+
type: 'address',
|
|
30
|
+
internalType: 'address',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'permit',
|
|
36
|
+
type: 'tuple',
|
|
37
|
+
internalType: 'struct UserDecryptPermitV2',
|
|
38
|
+
components: [
|
|
39
|
+
{ name: 'userAddress', type: 'address', internalType: 'address' },
|
|
40
|
+
{ name: 'publicKey', type: 'bytes', internalType: 'bytes' },
|
|
41
|
+
{
|
|
42
|
+
name: 'allowedContracts',
|
|
43
|
+
type: 'address[]',
|
|
44
|
+
internalType: 'address[]',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'startTimestamp',
|
|
48
|
+
type: 'uint256',
|
|
49
|
+
internalType: 'uint256',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'durationSeconds',
|
|
53
|
+
type: 'uint256',
|
|
54
|
+
internalType: 'uint256',
|
|
55
|
+
},
|
|
56
|
+
{ name: 'extraData', type: 'bytes', internalType: 'bytes' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{ name: 'signature', type: 'bytes', internalType: 'bytes' },
|
|
60
|
+
],
|
|
61
|
+
outputs: [
|
|
62
|
+
{ name: 'payload', type: 'bytes', internalType: 'bytes' },
|
|
63
|
+
{ name: 'signers', type: 'address[]', internalType: 'address[]' },
|
|
64
|
+
{ name: 'threshold', type: 'uint256', internalType: 'uint256' },
|
|
65
|
+
{ name: 'signedExtraData', type: 'bytes', internalType: 'bytes' },
|
|
66
|
+
],
|
|
67
|
+
stateMutability: 'view',
|
|
68
|
+
},
|
|
69
|
+
] as const;
|
|
70
|
+
|
|
71
|
+
async function runUserDecryptV2OnChain(
|
|
72
|
+
relayerClient: RelayerClientWithRuntime,
|
|
73
|
+
payload: FetchUserDecryptParametersV2['payload'],
|
|
74
|
+
): Promise<{
|
|
75
|
+
readonly commonKmsSigncryptedSharePayload: BytesHex;
|
|
76
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
77
|
+
readonly threshold: Uint32BigInt;
|
|
78
|
+
readonly extraData: BytesHex;
|
|
79
|
+
}> {
|
|
80
|
+
const { kmsDecryptEip712Message, kmsDecryptEip712Signature } = payload;
|
|
81
|
+
const pairs = payload.handleContractPairs;
|
|
82
|
+
const trustedClient = getTrustedClient(relayerClient);
|
|
83
|
+
// The signed permit fields are passed verbatim, extraData included: the host runs the gateway's and the
|
|
84
|
+
// kms-worker's checks against them and returns the signers of the KMS context the extraData names.
|
|
85
|
+
const res = (await relayerClient.runtime.ethereum.readContract(trustedClient, {
|
|
86
|
+
abi: userDecryptV2Abi,
|
|
87
|
+
address: relayerClient.chain.fhevm.contracts.kmsVerifier.address as ChecksummedAddress,
|
|
88
|
+
args: [
|
|
89
|
+
pairs.map((p) => ({
|
|
90
|
+
handle: p.handle.bytes32Hex,
|
|
91
|
+
contractAddress: p.contractAddress,
|
|
92
|
+
ownerAddress: p.ownerAddress,
|
|
93
|
+
})),
|
|
94
|
+
{
|
|
95
|
+
userAddress: kmsDecryptEip712Message.userAddress,
|
|
96
|
+
publicKey: kmsDecryptEip712Message.publicKey,
|
|
97
|
+
allowedContracts: kmsDecryptEip712Message.allowedContracts,
|
|
98
|
+
startTimestamp: _parseUintBigIntString(
|
|
99
|
+
'kmsDecryptEip712Message.startTimestamp',
|
|
100
|
+
kmsDecryptEip712Message.startTimestamp,
|
|
101
|
+
),
|
|
102
|
+
durationSeconds: _parseUintBigIntString(
|
|
103
|
+
'kmsDecryptEip712Message.durationSeconds',
|
|
104
|
+
kmsDecryptEip712Message.durationSeconds,
|
|
105
|
+
),
|
|
106
|
+
extraData: kmsDecryptEip712Message.extraData,
|
|
107
|
+
},
|
|
108
|
+
kmsDecryptEip712Signature,
|
|
109
|
+
],
|
|
110
|
+
functionName: userDecryptV2Abi[0].name,
|
|
111
|
+
})) as unknown[];
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
commonKmsSigncryptedSharePayload: res[0] as BytesHex,
|
|
115
|
+
signersAddress: res[1] as readonly ChecksummedAddress[],
|
|
116
|
+
threshold: asUint32BigInt(res[2]),
|
|
117
|
+
extraData: res[3] as BytesHex,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
2
120
|
|
|
3
121
|
////////////////////////////////////////////////////////////////////////////////
|
|
4
122
|
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
6
123
|
export async function fetchUserDecryptV2(
|
|
7
|
-
|
|
8
|
-
|
|
124
|
+
relayerClient: RelayerClientWithRuntime,
|
|
125
|
+
parameters: FetchUserDecryptParametersV2,
|
|
9
126
|
): Promise<FetchUserDecryptReturnType> {
|
|
10
|
-
|
|
127
|
+
// On chain only: forge-fhevm v1 has no unified (V2) decryption permit path.
|
|
128
|
+
const res = await runUserDecryptV2OnChain(relayerClient, parameters.payload);
|
|
129
|
+
return signKmsSigncryptedShares(relayerClient, { ...res, threshold: Number(res.threshold) });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
133
|
+
|
|
134
|
+
function _parseUintBigIntString(label: string, value: string): bigint {
|
|
135
|
+
const bn = tryParseUintBigIntString(value);
|
|
136
|
+
if (bn === undefined) {
|
|
137
|
+
throw new Error(`${label} is not a valid uint string, got ${JSON.stringify(value)}`);
|
|
138
|
+
}
|
|
139
|
+
return bn;
|
|
11
140
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { BytesHex, ChecksummedAddress } from '../../../types/primitives.js';
|
|
2
|
+
import type { KmsSigncryptedShare } from '../../../types/kms-p.js';
|
|
3
|
+
import type { FetchUserDecryptResultItem } from '../../../types/relayer.js';
|
|
2
4
|
import type { CleartextEthereumModule } from '../../ethereum/types-ct.js';
|
|
3
5
|
import type { RelayerClientWithRuntime } from '../types.js';
|
|
6
|
+
import { remove0x } from '../../../base/string.js';
|
|
7
|
+
import { randomUniqueUints } from '../../../base/uint.js';
|
|
8
|
+
import { userDecryptResultToKmsSigncryptedShares } from '../utils.js';
|
|
4
9
|
|
|
5
10
|
////////////////////////////////////////////////////////////////////////////////
|
|
6
11
|
|
|
@@ -70,6 +75,62 @@ export function getKmsSignersPrivateKeyMap(relayerClient: RelayerClientWithRunti
|
|
|
70
75
|
|
|
71
76
|
////////////////////////////////////////////////////////////////////////////////
|
|
72
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The KMS nodes that answer a request, as a relayer forwards one response per node: a random subset of
|
|
80
|
+
* `signersAddress`, of random size between `threshold` and all of them.
|
|
81
|
+
*/
|
|
82
|
+
export function pickRespondingKmsSigners(
|
|
83
|
+
signersAddress: readonly ChecksummedAddress[],
|
|
84
|
+
threshold: number,
|
|
85
|
+
): ChecksummedAddress[] {
|
|
86
|
+
const n = signersAddress.length;
|
|
87
|
+
if (!Number.isInteger(threshold) || threshold < 1 || threshold > n) {
|
|
88
|
+
throw new Error(`Invalid KMS threshold ${threshold} for ${n} signers`);
|
|
89
|
+
}
|
|
90
|
+
let count = threshold + Math.floor(Math.random() * (n - threshold + 1));
|
|
91
|
+
// Defensive: the guard above already keeps count within [threshold, n].
|
|
92
|
+
if (count < 1) {
|
|
93
|
+
count = 1;
|
|
94
|
+
}
|
|
95
|
+
if (count > n) {
|
|
96
|
+
count = n;
|
|
97
|
+
}
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
|
+
return randomUniqueUints(n, count).map((i) => signersAddress[i]!);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One signcrypted share per responding KMS node, each signing the common payload. */
|
|
103
|
+
export async function signKmsSigncryptedShares(
|
|
104
|
+
relayerClient: RelayerClientWithRuntime,
|
|
105
|
+
parameters: {
|
|
106
|
+
readonly commonKmsSigncryptedSharePayload: BytesHex;
|
|
107
|
+
readonly extraData: BytesHex;
|
|
108
|
+
readonly signersAddress: readonly ChecksummedAddress[];
|
|
109
|
+
readonly threshold: number;
|
|
110
|
+
},
|
|
111
|
+
): Promise<readonly KmsSigncryptedShare[]> {
|
|
112
|
+
const cleartextEthereumModule = relayerClient.runtime.ethereum as CleartextEthereumModule;
|
|
113
|
+
const { commonKmsSigncryptedSharePayload: payload, extraData, signersAddress, threshold } = parameters;
|
|
114
|
+
const privateKeys = getKmsSignersPrivateKeyMap(relayerClient);
|
|
115
|
+
const responders = pickRespondingKmsSigners(signersAddress, threshold);
|
|
116
|
+
|
|
117
|
+
const result: FetchUserDecryptResultItem[] = [];
|
|
118
|
+
for (const signerAddress of responders) {
|
|
119
|
+
const privateKey = privateKeys.get(signerAddress);
|
|
120
|
+
if (privateKey === undefined) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Unable to find KMS signer for address ${signerAddress} (${responders.length} of ${signersAddress.length} responding)`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const signature = await cleartextEthereumModule.sign({ hash: payload, privateKey });
|
|
126
|
+
result.push({ signature: remove0x(signature), payload: remove0x(payload), extraData });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return userDecryptResultToKmsSigncryptedShares(result);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
133
|
+
|
|
73
134
|
function _fillSignersPrivateKey(
|
|
74
135
|
relayerClient: RelayerClientWithRuntime,
|
|
75
136
|
hdPathSuffix: string,
|