node-tkms 0.10.0-rc1 → 0.11.0-rc5
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/kms_lib.d.ts +144 -178
- package/kms_lib.js +665 -468
- package/kms_lib_bg.wasm +0 -0
- package/package.json +1 -1
- package/LICENSE +0 -28
package/kms_lib.d.ts
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* @param {PublicSigKey} pk
|
|
5
|
-
* @returns {Uint8Array}
|
|
6
|
-
*/
|
|
7
3
|
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
8
|
-
/**
|
|
9
|
-
* @param {Uint8Array} v
|
|
10
|
-
* @returns {PublicSigKey}
|
|
11
|
-
*/
|
|
12
4
|
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
13
|
-
/**
|
|
14
|
-
* @param {PrivateSigKey} sk
|
|
15
|
-
* @returns {Uint8Array}
|
|
16
|
-
*/
|
|
17
5
|
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
18
|
-
/**
|
|
19
|
-
* @param {Uint8Array} v
|
|
20
|
-
* @returns {PrivateSigKey}
|
|
21
|
-
*/
|
|
22
6
|
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
23
7
|
/**
|
|
24
8
|
* Instantiate a new client.
|
|
@@ -29,71 +13,20 @@ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
|
29
13
|
* * `client_address_hex` - the client (wallet) address in hex,
|
|
30
14
|
* must be prefixed with "0x".
|
|
31
15
|
*
|
|
32
|
-
* * `
|
|
16
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
33
17
|
* 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
18
|
*/
|
|
19
|
+
export function new_client(server_addrs: (string)[], client_address_hex: string, fhe_parameter: string): Client;
|
|
44
20
|
export function get_server_addrs(client: Client): (string)[];
|
|
45
|
-
/**
|
|
46
|
-
* @param {Client} client
|
|
47
|
-
* @returns {PrivateSigKey | undefined}
|
|
48
|
-
*/
|
|
49
21
|
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* @param {Client} client
|
|
52
|
-
* @returns {string}
|
|
53
|
-
*/
|
|
54
22
|
export function get_client_address(client: Client): string;
|
|
55
|
-
/**
|
|
56
|
-
* @returns {PrivateEncKey}
|
|
57
|
-
*/
|
|
58
23
|
export function cryptobox_keygen(): PrivateEncKey;
|
|
59
|
-
/**
|
|
60
|
-
* @param {PrivateEncKey} sk
|
|
61
|
-
* @returns {PublicEncKey}
|
|
62
|
-
*/
|
|
63
24
|
export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey;
|
|
64
|
-
/**
|
|
65
|
-
* @param {PublicEncKey} pk
|
|
66
|
-
* @returns {Uint8Array}
|
|
67
|
-
*/
|
|
68
25
|
export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array;
|
|
69
|
-
/**
|
|
70
|
-
* @param {PrivateEncKey} sk
|
|
71
|
-
* @returns {Uint8Array}
|
|
72
|
-
*/
|
|
73
26
|
export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array;
|
|
74
|
-
/**
|
|
75
|
-
* @param {Uint8Array} v
|
|
76
|
-
* @returns {PublicEncKey}
|
|
77
|
-
*/
|
|
78
27
|
export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey;
|
|
79
|
-
/**
|
|
80
|
-
* @param {Uint8Array} v
|
|
81
|
-
* @returns {PrivateEncKey}
|
|
82
|
-
*/
|
|
83
28
|
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
29
|
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
30
|
export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array;
|
|
98
31
|
/**
|
|
99
32
|
* Process the reencryption response from JavaScript objects.
|
|
@@ -106,12 +39,13 @@ export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_p
|
|
|
106
39
|
* It can be set to null if `verify` is false.
|
|
107
40
|
* Otherwise the caller needs to give the following JS object.
|
|
108
41
|
* Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
|
|
42
|
+
* The signature field is not needed.
|
|
109
43
|
* ```
|
|
110
44
|
* {
|
|
111
|
-
* signature:
|
|
45
|
+
* signature: undefined,
|
|
112
46
|
* client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
|
|
113
47
|
* enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
|
|
114
|
-
*
|
|
48
|
+
* ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
|
|
115
49
|
* eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
|
|
116
50
|
* }
|
|
117
51
|
* ```
|
|
@@ -153,16 +87,8 @@ export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_p
|
|
|
153
87
|
*
|
|
154
88
|
* * `verify` - Whether to perform signature verification for the response.
|
|
155
89
|
* It is insecure if `verify = false`!
|
|
156
|
-
* @param {Client} client
|
|
157
|
-
* @param {any} request
|
|
158
|
-
* @param {any} eip712_domain
|
|
159
|
-
* @param {any} agg_resp
|
|
160
|
-
* @param {PublicEncKey} enc_pk
|
|
161
|
-
* @param {PrivateEncKey} enc_sk
|
|
162
|
-
* @param {boolean} verify
|
|
163
|
-
* @returns {Uint8Array}
|
|
164
90
|
*/
|
|
165
|
-
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):
|
|
91
|
+
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): (TypedPlaintext)[];
|
|
166
92
|
/**
|
|
167
93
|
* Process the reencryption response from Rust objects.
|
|
168
94
|
* Consider using [process_reencryption_resp_from_js]
|
|
@@ -185,18 +111,10 @@ export function process_reencryption_resp_from_js(client: Client, request: any,
|
|
|
185
111
|
*
|
|
186
112
|
* * `verify` - Whether to perform signature verification for the response.
|
|
187
113
|
* It is insecure if `verify = false`!
|
|
188
|
-
* @param {Client} client
|
|
189
|
-
* @param {ParsedReencryptionRequest | undefined} request
|
|
190
|
-
* @param {Eip712DomainMsg | undefined} eip712_domain
|
|
191
|
-
* @param {(ReencryptionResponse)[]} agg_resp
|
|
192
|
-
* @param {PublicEncKey} enc_pk
|
|
193
|
-
* @param {PrivateEncKey} enc_sk
|
|
194
|
-
* @param {boolean} verify
|
|
195
|
-
* @returns {Uint8Array}
|
|
196
114
|
*/
|
|
197
|
-
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):
|
|
115
|
+
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): (TypedPlaintext)[];
|
|
198
116
|
/**
|
|
199
|
-
* The plaintext types that can be encrypted in a
|
|
117
|
+
* The plaintext types that can be encrypted in a HTTPZ ciphertext.
|
|
200
118
|
*/
|
|
201
119
|
export enum FheType {
|
|
202
120
|
Ebool = 0,
|
|
@@ -212,6 +130,10 @@ export enum FheType {
|
|
|
212
130
|
Euint1024 = 10,
|
|
213
131
|
Euint2048 = 11,
|
|
214
132
|
}
|
|
133
|
+
export class CiphertextHandle {
|
|
134
|
+
private constructor();
|
|
135
|
+
free(): void;
|
|
136
|
+
}
|
|
215
137
|
/**
|
|
216
138
|
* Core Client
|
|
217
139
|
*
|
|
@@ -220,9 +142,11 @@ export enum FheType {
|
|
|
220
142
|
* distributed across the aggregator/proxy and smart contracts.
|
|
221
143
|
*/
|
|
222
144
|
export class Client {
|
|
145
|
+
private constructor();
|
|
223
146
|
free(): void;
|
|
224
147
|
}
|
|
225
148
|
export class CryptoBoxCt {
|
|
149
|
+
private constructor();
|
|
226
150
|
free(): void;
|
|
227
151
|
}
|
|
228
152
|
/**
|
|
@@ -231,134 +155,176 @@ export class CryptoBoxCt {
|
|
|
231
155
|
* solidity types
|
|
232
156
|
*/
|
|
233
157
|
export class Eip712DomainMsg {
|
|
158
|
+
private constructor();
|
|
234
159
|
free(): void;
|
|
235
|
-
chain_id: Uint8Array;
|
|
236
160
|
name: string;
|
|
237
|
-
salt?: Uint8Array;
|
|
238
|
-
verifying_contract: string;
|
|
239
161
|
version: string;
|
|
162
|
+
chain_id: Uint8Array;
|
|
163
|
+
verifying_contract: string;
|
|
164
|
+
salt?: Uint8Array;
|
|
240
165
|
}
|
|
241
166
|
/**
|
|
242
167
|
* Validity of this struct is not checked.
|
|
243
168
|
*/
|
|
244
169
|
export class ParsedReencryptionRequest {
|
|
170
|
+
private constructor();
|
|
245
171
|
free(): void;
|
|
246
172
|
}
|
|
247
173
|
export class PrivateEncKey {
|
|
174
|
+
private constructor();
|
|
248
175
|
free(): void;
|
|
249
176
|
}
|
|
250
177
|
export class PrivateSigKey {
|
|
178
|
+
private constructor();
|
|
251
179
|
free(): void;
|
|
252
180
|
}
|
|
253
181
|
export class PublicEncKey {
|
|
182
|
+
private constructor();
|
|
254
183
|
free(): void;
|
|
255
184
|
}
|
|
256
185
|
export class PublicSigKey {
|
|
186
|
+
private constructor();
|
|
257
187
|
free(): void;
|
|
258
188
|
}
|
|
259
189
|
export class ReencryptionRequest {
|
|
190
|
+
private constructor();
|
|
260
191
|
free(): void;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
* Future queries for the result must use this request ID.
|
|
266
|
-
*/
|
|
192
|
+
/**
|
|
193
|
+
* The 32 Byte / 256 Bit ID of the user decryption request, without `0x` prefix.
|
|
194
|
+
* Future queries for the result must use this request ID.
|
|
195
|
+
*/
|
|
267
196
|
request_id?: RequestId;
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
ciphertext?: Uint8Array;
|
|
282
|
-
/**
|
|
283
|
-
* The SHA3 digest of the ciphertext above.
|
|
284
|
-
*/
|
|
285
|
-
ciphertext_digest: Uint8Array;
|
|
286
|
-
/**
|
|
287
|
-
* The client's (blockchain wallet) address,
|
|
288
|
-
* encoded using EIP-55.
|
|
289
|
-
*/
|
|
197
|
+
/**
|
|
198
|
+
* The list of ciphertexts to reencrypt.
|
|
199
|
+
*/
|
|
200
|
+
typed_ciphertexts: (TypedCiphertext)[];
|
|
201
|
+
/**
|
|
202
|
+
* The 32 Byte / 256 Bit key id to use for decryption. This is the request_id used for key
|
|
203
|
+
* generation
|
|
204
|
+
*/
|
|
205
|
+
key_id?: RequestId;
|
|
206
|
+
/**
|
|
207
|
+
* The client's (blockchain wallet) address,
|
|
208
|
+
* encoded using EIP-55.
|
|
209
|
+
*/
|
|
290
210
|
client_address: string;
|
|
291
|
-
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Encoding of the user's public encryption key for this request.
|
|
213
|
+
* Encoding using the default encoding of libsodium, i.e. the 32 bytes of a
|
|
214
|
+
* Montgomery point.
|
|
215
|
+
*/
|
|
296
216
|
enc_key: Uint8Array;
|
|
297
|
-
|
|
298
|
-
* The type of plaintext encrypted.
|
|
299
|
-
*/
|
|
300
|
-
fhe_type: number;
|
|
301
|
-
/**
|
|
302
|
-
* The key id to use for decryption. Will be the request_id used during key
|
|
303
|
-
* generation
|
|
304
|
-
*/
|
|
305
|
-
key_id?: RequestId;
|
|
306
|
-
/**
|
|
307
|
-
* Version of the request format.
|
|
308
|
-
*/
|
|
309
|
-
version: number;
|
|
217
|
+
domain?: Eip712DomainMsg;
|
|
310
218
|
}
|
|
311
219
|
export class ReencryptionResponse {
|
|
220
|
+
private constructor();
|
|
312
221
|
free(): void;
|
|
313
|
-
/**
|
|
314
|
-
* Signature of the serialization of \[ReencryptionResponsePayload\].
|
|
315
|
-
*/
|
|
316
|
-
payload?: ReencryptionResponsePayload;
|
|
317
222
|
signature: Uint8Array;
|
|
223
|
+
/**
|
|
224
|
+
* This is the external signature created from the Eip712 domain
|
|
225
|
+
* on the structure, where reencryptedShare is bincode::serialize(&payload)
|
|
226
|
+
* struct UserDecryptResponseVerification {
|
|
227
|
+
* bytes publicKey;
|
|
228
|
+
* uint256\[\] ctHandles;
|
|
229
|
+
* bytes reencryptedShare;
|
|
230
|
+
* }
|
|
231
|
+
*/
|
|
232
|
+
external_signature: Uint8Array;
|
|
233
|
+
/**
|
|
234
|
+
* The actual \[ReencryptionResponsePayload\].
|
|
235
|
+
*/
|
|
236
|
+
payload?: ReencryptionResponsePayload;
|
|
318
237
|
}
|
|
319
238
|
export class ReencryptionResponsePayload {
|
|
239
|
+
private constructor();
|
|
320
240
|
free(): void;
|
|
321
|
-
/**
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
241
|
+
/**
|
|
242
|
+
* The server's signature verification key, Encoded using SEC1.
|
|
243
|
+
* Needed to validate the response, but MUST also be linked to a list of
|
|
244
|
+
* trusted keys.
|
|
245
|
+
*/
|
|
246
|
+
verification_key: Uint8Array;
|
|
247
|
+
/**
|
|
248
|
+
* This is needed to ensure the response corresponds to the request.
|
|
249
|
+
* It is the digest of UserDecryptionLinker hashed using EIP712
|
|
250
|
+
* under the given domain in the request.
|
|
251
|
+
*/
|
|
330
252
|
digest: Uint8Array;
|
|
331
|
-
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
253
|
+
/**
|
|
254
|
+
* The resulting signcrypted ciphertexts, each ciphertext
|
|
255
|
+
* must be decrypted and then reconstructed with the other shares
|
|
256
|
+
* to produce the final plaintext.
|
|
257
|
+
*/
|
|
258
|
+
signcrypted_ciphertexts: (TypedSigncryptedCiphertext)[];
|
|
259
|
+
/**
|
|
260
|
+
* The ID of the MPC party doing the reencryption. Used for polynomial
|
|
261
|
+
* reconstruction.
|
|
262
|
+
*/
|
|
339
263
|
party_id: number;
|
|
340
|
-
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
signcrypted_ciphertext: Uint8Array;
|
|
345
|
-
/**
|
|
346
|
-
* The server's signature verification key.
|
|
347
|
-
* Encoded using SEC1.
|
|
348
|
-
* Needed to validate the response, but MUST also be linked to a list of
|
|
349
|
-
* trusted keys.
|
|
350
|
-
*/
|
|
351
|
-
verification_key: Uint8Array;
|
|
352
|
-
/**
|
|
353
|
-
* Version of the response format.
|
|
354
|
-
*/
|
|
355
|
-
version: number;
|
|
264
|
+
/**
|
|
265
|
+
* The degree of the sharing scheme used.
|
|
266
|
+
*/
|
|
267
|
+
degree: number;
|
|
356
268
|
}
|
|
357
269
|
/**
|
|
358
|
-
* Simple response to return
|
|
359
|
-
* later on.
|
|
270
|
+
* Simple response to return a 32 Byte / 256 Bit ID, to be used to retrieve the computed result
|
|
271
|
+
* later on. This string does NOT contain a `0x` prefix.
|
|
360
272
|
*/
|
|
361
273
|
export class RequestId {
|
|
274
|
+
private constructor();
|
|
362
275
|
free(): void;
|
|
363
276
|
request_id: string;
|
|
364
277
|
}
|
|
278
|
+
export class TypedCiphertext {
|
|
279
|
+
private constructor();
|
|
280
|
+
free(): void;
|
|
281
|
+
/**
|
|
282
|
+
* The actual ciphertext to decrypt, taken directly from HTTPZ.
|
|
283
|
+
*/
|
|
284
|
+
ciphertext: Uint8Array;
|
|
285
|
+
/**
|
|
286
|
+
* The type of plaintext encrypted.
|
|
287
|
+
*/
|
|
288
|
+
fhe_type: number;
|
|
289
|
+
/**
|
|
290
|
+
* The external handle of the ciphertext (the handle used in the copro).
|
|
291
|
+
*/
|
|
292
|
+
external_handle: Uint8Array;
|
|
293
|
+
/**
|
|
294
|
+
* The ciphertext format, see CiphertextFormat documentation for details.
|
|
295
|
+
* CiphertextFormat::default() is used if unspecified.
|
|
296
|
+
*/
|
|
297
|
+
ciphertext_format: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The typed plaintext type, which is the result of decryption.
|
|
301
|
+
*/
|
|
302
|
+
export class TypedPlaintext {
|
|
303
|
+
private constructor();
|
|
304
|
+
free(): void;
|
|
305
|
+
/**
|
|
306
|
+
* The actual plaintext in bytes.
|
|
307
|
+
*/
|
|
308
|
+
bytes: Uint8Array;
|
|
309
|
+
/**
|
|
310
|
+
* The type of plaintext encrypted.
|
|
311
|
+
*/
|
|
312
|
+
fhe_type: number;
|
|
313
|
+
}
|
|
314
|
+
export class TypedSigncryptedCiphertext {
|
|
315
|
+
private constructor();
|
|
316
|
+
free(): void;
|
|
317
|
+
/**
|
|
318
|
+
* The type of plaintext encrypted.
|
|
319
|
+
*/
|
|
320
|
+
fhe_type: number;
|
|
321
|
+
/**
|
|
322
|
+
* The signcrypted payload, using a hybrid encryption approach in
|
|
323
|
+
* sign-then-encrypt.
|
|
324
|
+
*/
|
|
325
|
+
signcrypted_ciphertext: Uint8Array;
|
|
326
|
+
/**
|
|
327
|
+
* The external handles that were originally in the request.
|
|
328
|
+
*/
|
|
329
|
+
external_handle: Uint8Array;
|
|
330
|
+
}
|