node-tkms 0.9.0-rc11
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/LICENSE +28 -0
- package/README.md +1 -0
- package/kms_lib.d.ts +405 -0
- package/kms_lib.js +2065 -0
- package/kms_lib_bg.wasm +0 -0
- package/package.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause Clear License
|
|
2
|
+
|
|
3
|
+
Copyright © 2024 ZAMA.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
7
|
+
are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this
|
|
13
|
+
list of conditions and the following disclaimer in the documentation and/or other
|
|
14
|
+
materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of ZAMA nor the names of its contributors may be used to endorse
|
|
17
|
+
or promote products derived from this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE ZAMA AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
21
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
22
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
23
|
+
ZAMA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
24
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
25
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
26
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
28
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# node-tkms
|
package/kms_lib.d.ts
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* @param {PublicSigKey} pk
|
|
5
|
+
* @returns {Uint8Array}
|
|
6
|
+
*/
|
|
7
|
+
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* @param {Uint8Array} v
|
|
10
|
+
* @returns {PublicSigKey}
|
|
11
|
+
*/
|
|
12
|
+
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
13
|
+
/**
|
|
14
|
+
* @param {PrivateSigKey} sk
|
|
15
|
+
* @returns {Uint8Array}
|
|
16
|
+
*/
|
|
17
|
+
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* @param {Uint8Array} v
|
|
20
|
+
* @returns {PrivateSigKey}
|
|
21
|
+
*/
|
|
22
|
+
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
23
|
+
/**
|
|
24
|
+
* Instantiate a new client.
|
|
25
|
+
*
|
|
26
|
+
* * `server_pks` - a list of KMS server signature public keys,
|
|
27
|
+
* which can parsed using [u8vec_to_public_sig_key].
|
|
28
|
+
*
|
|
29
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
30
|
+
* must be prefixed with "0x".
|
|
31
|
+
*
|
|
32
|
+
* * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
33
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
34
|
+
* @param {(string)[]} server_addrs
|
|
35
|
+
* @param {string} client_address_hex
|
|
36
|
+
* @param {string} param_choice
|
|
37
|
+
* @returns {Client}
|
|
38
|
+
*/
|
|
39
|
+
export function new_client(server_addrs: (string)[], client_address_hex: string, param_choice: string): Client;
|
|
40
|
+
/**
|
|
41
|
+
* @param {Client} client
|
|
42
|
+
* @returns {(string)[]}
|
|
43
|
+
*/
|
|
44
|
+
export function get_server_addrs(client: Client): (string)[];
|
|
45
|
+
/**
|
|
46
|
+
* @param {Client} client
|
|
47
|
+
* @returns {PrivateSigKey | undefined}
|
|
48
|
+
*/
|
|
49
|
+
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* @param {Client} client
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
export function get_client_address(client: Client): string;
|
|
55
|
+
/**
|
|
56
|
+
* @returns {PrivateEncKey}
|
|
57
|
+
*/
|
|
58
|
+
export function cryptobox_keygen(): PrivateEncKey;
|
|
59
|
+
/**
|
|
60
|
+
* @param {PrivateEncKey} sk
|
|
61
|
+
* @returns {PublicEncKey}
|
|
62
|
+
*/
|
|
63
|
+
export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey;
|
|
64
|
+
/**
|
|
65
|
+
* @param {PublicEncKey} pk
|
|
66
|
+
* @returns {Uint8Array}
|
|
67
|
+
*/
|
|
68
|
+
export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* @param {PrivateEncKey} sk
|
|
71
|
+
* @returns {Uint8Array}
|
|
72
|
+
*/
|
|
73
|
+
export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array;
|
|
74
|
+
/**
|
|
75
|
+
* @param {Uint8Array} v
|
|
76
|
+
* @returns {PublicEncKey}
|
|
77
|
+
*/
|
|
78
|
+
export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey;
|
|
79
|
+
/**
|
|
80
|
+
* @param {Uint8Array} v
|
|
81
|
+
* @returns {PrivateEncKey}
|
|
82
|
+
*/
|
|
83
|
+
export function u8vec_to_cryptobox_sk(v: Uint8Array): PrivateEncKey;
|
|
84
|
+
/**
|
|
85
|
+
* @param {Uint8Array} msg
|
|
86
|
+
* @param {PublicEncKey} their_pk
|
|
87
|
+
* @param {PrivateEncKey} my_sk
|
|
88
|
+
* @returns {CryptoBoxCt}
|
|
89
|
+
*/
|
|
90
|
+
export function cryptobox_encrypt(msg: Uint8Array, their_pk: PublicEncKey, my_sk: PrivateEncKey): CryptoBoxCt;
|
|
91
|
+
/**
|
|
92
|
+
* @param {CryptoBoxCt} ct
|
|
93
|
+
* @param {PrivateEncKey} my_sk
|
|
94
|
+
* @param {PublicEncKey} their_pk
|
|
95
|
+
* @returns {Uint8Array}
|
|
96
|
+
*/
|
|
97
|
+
export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array;
|
|
98
|
+
/**
|
|
99
|
+
* Process the reencryption response from JavaScript objects.
|
|
100
|
+
* The result is a byte array representing a plaintext of any length.
|
|
101
|
+
*
|
|
102
|
+
* * `client` - client that wants to perform reencryption.
|
|
103
|
+
*
|
|
104
|
+
* * `request` - the initial reencryption request JS object.
|
|
105
|
+
* It can be set to null if `verify` is false.
|
|
106
|
+
* Otherwise the caller needs to give the following JS object.
|
|
107
|
+
* Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
|
|
108
|
+
* ```
|
|
109
|
+
* {
|
|
110
|
+
* signature: '15a4f9a8eb61459cfba7d103d8f911fb04ce91ecf841b34c49c0d56a70b896d20cbc31986188f91efc3842b7df215cee8acb40178daedb8b63d0ba5d199bce121c',
|
|
111
|
+
* client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
|
|
112
|
+
* enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
|
|
113
|
+
* ciphertext_digest: '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358',
|
|
114
|
+
* eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* * `eip712_domain` - the EIP-712 domain JS object.
|
|
119
|
+
* It can be set to null if `verify` is false.
|
|
120
|
+
* Otherwise the caller needs to give the following JS object.
|
|
121
|
+
* Note that `salt` is optional and `verifying_contract` follows EIP-55,
|
|
122
|
+
* additionally, `chain_id` is an array of u8.
|
|
123
|
+
* ```
|
|
124
|
+
* {
|
|
125
|
+
* name: 'Authorization token',
|
|
126
|
+
* version: '1',
|
|
127
|
+
* chain_id: [
|
|
128
|
+
* 70, 31, 0, 0, 0, 0, 0, 0, 0,
|
|
129
|
+
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
130
|
+
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
131
|
+
* 0, 0, 0, 0, 0
|
|
132
|
+
* ],
|
|
133
|
+
* verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
|
|
134
|
+
* salt: []
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* * `agg_resp` - the response JS object from the gateway.
|
|
139
|
+
* It has two fields like so, both are hex encoded byte arrays.
|
|
140
|
+
* ```
|
|
141
|
+
* [
|
|
142
|
+
* {
|
|
143
|
+
* signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
|
|
144
|
+
* payload: '0100000029...'
|
|
145
|
+
* }
|
|
146
|
+
* ]
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* * `enc_pk` - The ephemeral public key.
|
|
150
|
+
*
|
|
151
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
152
|
+
*
|
|
153
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
154
|
+
* It is insecure if `verify = false`!
|
|
155
|
+
* @param {Client} client
|
|
156
|
+
* @param {any} request
|
|
157
|
+
* @param {any} eip712_domain
|
|
158
|
+
* @param {any} agg_resp
|
|
159
|
+
* @param {PublicEncKey} enc_pk
|
|
160
|
+
* @param {PrivateEncKey} enc_sk
|
|
161
|
+
* @param {boolean} verify
|
|
162
|
+
* @returns {Uint8Array}
|
|
163
|
+
*/
|
|
164
|
+
export function process_reencryption_resp_from_js(client: Client, request: any, eip712_domain: any, agg_resp: any, enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array;
|
|
165
|
+
/**
|
|
166
|
+
* Process the reencryption response from Rust objects.
|
|
167
|
+
* Consider using [process_reencryption_resp_from_js]
|
|
168
|
+
* when using the JS API.
|
|
169
|
+
* The result is a byte array representing a plaintext of any length.
|
|
170
|
+
*
|
|
171
|
+
* * `client` - client that wants to perform reencryption.
|
|
172
|
+
*
|
|
173
|
+
* * `request` - the initial reencryption request.
|
|
174
|
+
* Must be given if `verify` is true.
|
|
175
|
+
*
|
|
176
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
177
|
+
* Must be given if `verify` is true.
|
|
178
|
+
*
|
|
179
|
+
* * `agg_resp` - the vector of reencryption responses.
|
|
180
|
+
*
|
|
181
|
+
* * `enc_pk` - The ephemeral public key.
|
|
182
|
+
*
|
|
183
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
184
|
+
*
|
|
185
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
186
|
+
* It is insecure if `verify = false`!
|
|
187
|
+
* @param {Client} client
|
|
188
|
+
* @param {ParsedReencryptionRequest | undefined} request
|
|
189
|
+
* @param {Eip712DomainMsg | undefined} eip712_domain
|
|
190
|
+
* @param {(ReencryptionResponse)[]} agg_resp
|
|
191
|
+
* @param {PublicEncKey} enc_pk
|
|
192
|
+
* @param {PrivateEncKey} enc_sk
|
|
193
|
+
* @param {boolean} verify
|
|
194
|
+
* @returns {Uint8Array}
|
|
195
|
+
*/
|
|
196
|
+
export function process_reencryption_resp(client: Client, request: ParsedReencryptionRequest | undefined, eip712_domain: Eip712DomainMsg | undefined, agg_resp: (ReencryptionResponse)[], enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array;
|
|
197
|
+
/**
|
|
198
|
+
* The plaintext types that can be encrypted in a fhevm ciphertext.
|
|
199
|
+
*/
|
|
200
|
+
export enum FheType {
|
|
201
|
+
Ebool = 0,
|
|
202
|
+
Euint4 = 1,
|
|
203
|
+
Euint8 = 2,
|
|
204
|
+
Euint16 = 3,
|
|
205
|
+
Euint32 = 4,
|
|
206
|
+
Euint64 = 5,
|
|
207
|
+
Euint128 = 6,
|
|
208
|
+
Euint160 = 7,
|
|
209
|
+
Euint256 = 8,
|
|
210
|
+
Euint512 = 9,
|
|
211
|
+
Euint1024 = 10,
|
|
212
|
+
Euint2048 = 11,
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Simple client to interact with the KMS servers. This can be seen as a proof-of-concept
|
|
216
|
+
* and reference code for validating the KMS. The logic supplied by the client will be
|
|
217
|
+
* distributed across the aggregator/proxy and smart contracts.
|
|
218
|
+
*/
|
|
219
|
+
export class Client {
|
|
220
|
+
free(): void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
*/
|
|
224
|
+
export class CryptoBoxCt {
|
|
225
|
+
free(): void;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* <https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator>
|
|
229
|
+
* eventually chain_id, verifying_contract and salt will be parsed in to
|
|
230
|
+
* solidity types
|
|
231
|
+
*/
|
|
232
|
+
export class Eip712DomainMsg {
|
|
233
|
+
free(): void;
|
|
234
|
+
/**
|
|
235
|
+
*/
|
|
236
|
+
chain_id: Uint8Array;
|
|
237
|
+
/**
|
|
238
|
+
*/
|
|
239
|
+
name: string;
|
|
240
|
+
/**
|
|
241
|
+
*/
|
|
242
|
+
salt: Uint8Array;
|
|
243
|
+
/**
|
|
244
|
+
*/
|
|
245
|
+
verifying_contract: string;
|
|
246
|
+
/**
|
|
247
|
+
*/
|
|
248
|
+
version: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Validity of this struct is not checked.
|
|
252
|
+
*/
|
|
253
|
+
export class ParsedReencryptionRequest {
|
|
254
|
+
free(): void;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
*/
|
|
258
|
+
export class Plaintext {
|
|
259
|
+
free(): void;
|
|
260
|
+
/**
|
|
261
|
+
*/
|
|
262
|
+
bytes: Uint8Array;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
*/
|
|
266
|
+
export class PrivateEncKey {
|
|
267
|
+
free(): void;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
*/
|
|
271
|
+
export class PrivateSigKey {
|
|
272
|
+
free(): void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
*/
|
|
276
|
+
export class PublicEncKey {
|
|
277
|
+
free(): void;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
*/
|
|
281
|
+
export class PublicSigKey {
|
|
282
|
+
free(): void;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
*/
|
|
286
|
+
export class ReencryptionRequest {
|
|
287
|
+
free(): void;
|
|
288
|
+
/**
|
|
289
|
+
*/
|
|
290
|
+
domain?: Eip712DomainMsg;
|
|
291
|
+
/**
|
|
292
|
+
*/
|
|
293
|
+
payload?: ReencryptionRequestPayload;
|
|
294
|
+
/**
|
|
295
|
+
* The ID that identifies this request.
|
|
296
|
+
* Future queries for the result must use this request ID.
|
|
297
|
+
*/
|
|
298
|
+
request_id?: RequestId;
|
|
299
|
+
/**
|
|
300
|
+
* Signature of the serialization of \[ReencryptionRequestPayload\].
|
|
301
|
+
*/
|
|
302
|
+
signature: Uint8Array;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
*/
|
|
306
|
+
export class ReencryptionRequestPayload {
|
|
307
|
+
free(): void;
|
|
308
|
+
/**
|
|
309
|
+
* The actual ciphertext to decrypt, taken directly from the fhevm.
|
|
310
|
+
* When creating the payload, this field may be empty,
|
|
311
|
+
* it is the responsibility of the gateway to fetch the
|
|
312
|
+
* ciphertext for the given digest below.
|
|
313
|
+
*/
|
|
314
|
+
ciphertext?: Uint8Array;
|
|
315
|
+
/**
|
|
316
|
+
* The SHA3 digest of the ciphertext above.
|
|
317
|
+
*/
|
|
318
|
+
ciphertext_digest: Uint8Array;
|
|
319
|
+
/**
|
|
320
|
+
* The client's (blockchain wallet) address,
|
|
321
|
+
* encoded using EIP-55.
|
|
322
|
+
*/
|
|
323
|
+
client_address: string;
|
|
324
|
+
/**
|
|
325
|
+
* Encoding of the user's public encryption key for this request.
|
|
326
|
+
* Encoding using the default encoding of libsodium, i.e. the 32 bytes of a
|
|
327
|
+
* Montgomery point.
|
|
328
|
+
*/
|
|
329
|
+
enc_key: Uint8Array;
|
|
330
|
+
/**
|
|
331
|
+
* The type of plaintext encrypted.
|
|
332
|
+
*/
|
|
333
|
+
fhe_type: number;
|
|
334
|
+
/**
|
|
335
|
+
* The key id to use for decryption. Will be the request_id used during key
|
|
336
|
+
* generation
|
|
337
|
+
*/
|
|
338
|
+
key_id?: RequestId;
|
|
339
|
+
/**
|
|
340
|
+
* Version of the request format.
|
|
341
|
+
*/
|
|
342
|
+
version: number;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
*/
|
|
346
|
+
export class ReencryptionResponse {
|
|
347
|
+
free(): void;
|
|
348
|
+
/**
|
|
349
|
+
* Signature of the serialization of \[ReencryptionResponsePayload\].
|
|
350
|
+
*/
|
|
351
|
+
payload?: ReencryptionResponsePayload;
|
|
352
|
+
/**
|
|
353
|
+
*/
|
|
354
|
+
signature: Uint8Array;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
*/
|
|
358
|
+
export class ReencryptionResponsePayload {
|
|
359
|
+
free(): void;
|
|
360
|
+
/**
|
|
361
|
+
* The degree of the sharing scheme used.
|
|
362
|
+
*/
|
|
363
|
+
degree: number;
|
|
364
|
+
/**
|
|
365
|
+
* The concatenation of two digests:
|
|
366
|
+
* (eip712_signing_hash(pk, domain) || ciphertext digest).
|
|
367
|
+
* This is needed to ensure the response corresponds to the request.
|
|
368
|
+
*/
|
|
369
|
+
digest: Uint8Array;
|
|
370
|
+
/**
|
|
371
|
+
* The type of plaintext encrypted.
|
|
372
|
+
*/
|
|
373
|
+
fhe_type: number;
|
|
374
|
+
/**
|
|
375
|
+
* The ID of the MPC party doing the reencryption. Used for polynomial
|
|
376
|
+
* reconstruction.
|
|
377
|
+
*/
|
|
378
|
+
party_id: number;
|
|
379
|
+
/**
|
|
380
|
+
* The signcrypted payload, using a hybrid encryption approach in
|
|
381
|
+
* sign-then-encrypt.
|
|
382
|
+
*/
|
|
383
|
+
signcrypted_ciphertext: Uint8Array;
|
|
384
|
+
/**
|
|
385
|
+
* The server's signature verification key.
|
|
386
|
+
* Encoded using SEC1.
|
|
387
|
+
* Needed to validate the response, but MUST also be linked to a list of
|
|
388
|
+
* trusted keys.
|
|
389
|
+
*/
|
|
390
|
+
verification_key: Uint8Array;
|
|
391
|
+
/**
|
|
392
|
+
* Version of the response format.
|
|
393
|
+
*/
|
|
394
|
+
version: number;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Simple response to return an ID, to be used to retrieve the computed result
|
|
398
|
+
* later on.
|
|
399
|
+
*/
|
|
400
|
+
export class RequestId {
|
|
401
|
+
free(): void;
|
|
402
|
+
/**
|
|
403
|
+
*/
|
|
404
|
+
request_id: string;
|
|
405
|
+
}
|