node-tkms 0.10.0-rc1 → 0.11.0-rc13

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 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,89 +13,39 @@ 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
- * * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`.
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
- */
44
- export function get_server_addrs(client: Client): (string)[];
45
- /**
46
- * @param {Client} client
47
- * @returns {PrivateSigKey | undefined}
48
18
  */
19
+ export function new_client(server_addrs: string[], client_address_hex: string, fhe_parameter: string): Client;
20
+ export function get_server_addrs(client: Client): string[];
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
- * Process the reencryption response from JavaScript objects.
32
+ * Process the user_decryption response from JavaScript objects.
100
33
  * The returned result is a byte array representing a plaintext of any length,
101
34
  * postprocessing is returned to turn it into an integer.
102
35
  *
103
- * * `client` - client that wants to perform reencryption.
36
+ * * `client` - client that wants to perform user_decryption.
104
37
  *
105
- * * `request` - the initial reencryption request JS object.
38
+ * * `request` - the initial user_decryption request JS object.
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: '15a4f9a8eb61459cfba7d103d8f911fb04ce91ecf841b34c49c0d56a70b896d20cbc31986188f91efc3842b7df215cee8acb40178daedb8b63d0ba5d199bce121c',
45
+ * signature: undefined,
112
46
  * client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
113
47
  * enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
114
- * ciphertext_handle: '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358',
48
+ * ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
115
49
  * eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
116
50
  * }
117
51
  * ```
@@ -153,31 +87,23 @@ 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): Uint8Array;
91
+ export function process_user_decryption_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
- * Process the reencryption response from Rust objects.
168
- * Consider using [process_reencryption_resp_from_js]
93
+ * Process the user_decryption response from Rust objects.
94
+ * Consider using [process_user_decryption_resp_from_js]
169
95
  * when using the JS API.
170
96
  * The result is a byte array representing a plaintext of any length.
171
97
  *
172
- * * `client` - client that wants to perform reencryption.
98
+ * * `client` - client that wants to perform user_decryption.
173
99
  *
174
- * * `request` - the initial reencryption request.
100
+ * * `request` - the initial user_decryption request.
175
101
  * Must be given if `verify` is true.
176
102
  *
177
103
  * * `eip712_domain` - the EIP-712 domain.
178
104
  * Must be given if `verify` is true.
179
105
  *
180
- * * `agg_resp` - the vector of reencryption responses.
106
+ * * `agg_resp` - the vector of user_decryption responses.
181
107
  *
182
108
  * * `enc_pk` - The ephemeral public key.
183
109
  *
@@ -185,32 +111,11 @@ 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
- */
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): Uint8Array;
198
- /**
199
- * The plaintext types that can be encrypted in a fhevm ciphertext.
200
114
  */
201
- export enum FheType {
202
- Ebool = 0,
203
- Euint4 = 1,
204
- Euint8 = 2,
205
- Euint16 = 3,
206
- Euint32 = 4,
207
- Euint64 = 5,
208
- Euint128 = 6,
209
- Euint160 = 7,
210
- Euint256 = 8,
211
- Euint512 = 9,
212
- Euint1024 = 10,
213
- Euint2048 = 11,
115
+ export function process_user_decryption_resp(client: Client, request: ParsedUserDecryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: UserDecryptionResponse[], enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): TypedPlaintext[];
116
+ export class CiphertextHandle {
117
+ private constructor();
118
+ free(): void;
214
119
  }
215
120
  /**
216
121
  * Core Client
@@ -220,9 +125,11 @@ export enum FheType {
220
125
  * distributed across the aggregator/proxy and smart contracts.
221
126
  */
222
127
  export class Client {
128
+ private constructor();
223
129
  free(): void;
224
130
  }
225
131
  export class CryptoBoxCt {
132
+ private constructor();
226
133
  free(): void;
227
134
  }
228
135
  /**
@@ -231,134 +138,197 @@ export class CryptoBoxCt {
231
138
  * solidity types
232
139
  */
233
140
  export class Eip712DomainMsg {
141
+ private constructor();
234
142
  free(): void;
235
- chain_id: Uint8Array;
236
143
  name: string;
237
- salt?: Uint8Array;
238
- verifying_contract: string;
239
144
  version: string;
145
+ chain_id: Uint8Array;
146
+ verifying_contract: string;
147
+ get salt(): Uint8Array | undefined;
148
+ set salt(value: Uint8Array | null | undefined);
240
149
  }
241
150
  /**
242
151
  * Validity of this struct is not checked.
243
152
  */
244
- export class ParsedReencryptionRequest {
153
+ export class ParsedUserDecryptionRequest {
154
+ private constructor();
245
155
  free(): void;
246
156
  }
247
157
  export class PrivateEncKey {
158
+ private constructor();
248
159
  free(): void;
249
160
  }
250
161
  export class PrivateSigKey {
162
+ private constructor();
251
163
  free(): void;
252
164
  }
253
165
  export class PublicEncKey {
166
+ private constructor();
254
167
  free(): void;
255
168
  }
256
169
  export class PublicSigKey {
170
+ private constructor();
257
171
  free(): void;
258
172
  }
259
- export class ReencryptionRequest {
260
- free(): void;
261
- domain?: Eip712DomainMsg;
262
- payload?: ReencryptionRequestPayload;
263
- /**
264
- * The ID that identifies this request.
265
- * Future queries for the result must use this request ID.
266
- */
267
- request_id?: RequestId;
268
173
  /**
269
- * Signature of the serialization of \[ReencryptionRequestPayload\].
174
+ * Simple response to return a 32 Byte / 256 Bit ID, to be used to retrieve the
175
+ * computed result later on. This string does NOT contain a `0x` prefix.
270
176
  */
271
- signature: Uint8Array;
177
+ export class RequestId {
178
+ private constructor();
179
+ free(): void;
180
+ request_id: string;
272
181
  }
273
- export class ReencryptionRequestPayload {
182
+ export class TypedCiphertext {
183
+ private constructor();
274
184
  free(): void;
275
- /**
276
- * The actual ciphertext to decrypt, taken directly from the fhevm.
277
- * When creating the payload, this field may be empty,
278
- * it is the responsibility of the gateway to fetch the
279
- * ciphertext for the given digest below.
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
- */
290
- client_address: string;
291
- /**
292
- * Encoding of the user's public encryption key for this request.
293
- * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a
294
- * Montgomery point.
295
- */
296
- enc_key: Uint8Array;
297
- /**
298
- * The type of plaintext encrypted.
299
- */
185
+ /**
186
+ * The actual ciphertext to decrypt, taken directly from fhevm.
187
+ */
188
+ ciphertext: Uint8Array;
189
+ /**
190
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
191
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
192
+ */
300
193
  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;
194
+ /**
195
+ * The external handle of the ciphertext (the handle used in the copro).
196
+ */
197
+ external_handle: Uint8Array;
198
+ /**
199
+ * The ciphertext format, see CiphertextFormat documentation for details.
200
+ * CiphertextFormat::default() is used if unspecified.
201
+ */
202
+ ciphertext_format: number;
310
203
  }
311
- export class ReencryptionResponse {
204
+ export class TypedPlaintext {
205
+ private constructor();
312
206
  free(): void;
313
- /**
314
- * Signature of the serialization of \[ReencryptionResponsePayload\].
315
- */
316
- payload?: ReencryptionResponsePayload;
317
- signature: Uint8Array;
207
+ /**
208
+ * The actual plaintext in bytes.
209
+ */
210
+ bytes: Uint8Array;
211
+ /**
212
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
213
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
214
+ */
215
+ fhe_type: number;
318
216
  }
319
- export class ReencryptionResponsePayload {
217
+ export class TypedSigncryptedCiphertext {
218
+ private constructor();
320
219
  free(): void;
321
- /**
322
- * The degree of the sharing scheme used.
323
- */
324
- degree: number;
325
- /**
326
- * The concatenation of two digests:
327
- * (eip712_signing_hash(pk, domain) || ciphertext digest).
328
- * This is needed to ensure the response corresponds to the request.
329
- */
330
- digest: Uint8Array;
331
- /**
332
- * The type of plaintext encrypted.
333
- */
220
+ /**
221
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
222
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
223
+ */
334
224
  fhe_type: number;
335
- /**
336
- * The ID of the MPC party doing the reencryption. Used for polynomial
337
- * reconstruction.
338
- */
339
- party_id: number;
340
- /**
341
- * The signcrypted payload, using a hybrid encryption approach in
342
- * sign-then-encrypt.
343
- */
225
+ /**
226
+ * The signcrypted payload, using a hybrid encryption approach in
227
+ * sign-then-encrypt.
228
+ */
344
229
  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;
230
+ /**
231
+ * The external handles that were originally in the request.
232
+ */
233
+ external_handle: Uint8Array;
234
+ /**
235
+ * The packing factor determines whether the decrypted plaintext
236
+ * has a different way of packing compared to what is specified in the plaintext modulus.
237
+ */
238
+ packing_factor: number;
356
239
  }
357
- /**
358
- * Simple response to return an ID, to be used to retrieve the computed result
359
- * later on.
360
- */
361
- export class RequestId {
240
+ export class UserDecryptionRequest {
241
+ private constructor();
362
242
  free(): void;
363
- request_id: string;
243
+ /**
244
+ * The 32 Byte / 256 Bit ID of the user decryption request, without `0x`
245
+ * prefix. Future queries for the result must use this request ID.
246
+ */
247
+ get request_id(): RequestId | undefined;
248
+ /**
249
+ * The 32 Byte / 256 Bit ID of the user decryption request, without `0x`
250
+ * prefix. Future queries for the result must use this request ID.
251
+ */
252
+ set request_id(value: RequestId | null | undefined);
253
+ /**
254
+ * The list of ciphertexts to decrypt for the user.
255
+ */
256
+ typed_ciphertexts: TypedCiphertext[];
257
+ /**
258
+ * The 32 Byte / 256 Bit key id to use for decryption. This is the request_id
259
+ * used for key generation
260
+ */
261
+ get key_id(): RequestId | undefined;
262
+ /**
263
+ * The 32 Byte / 256 Bit key id to use for decryption. This is the request_id
264
+ * used for key generation
265
+ */
266
+ set key_id(value: RequestId | null | undefined);
267
+ /**
268
+ * The client's (blockchain wallet) address,
269
+ * encoded using EIP-55.
270
+ */
271
+ client_address: string;
272
+ /**
273
+ * Encoding of the user's public encryption key for this request.
274
+ * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a
275
+ * Montgomery point.
276
+ */
277
+ enc_key: Uint8Array;
278
+ get domain(): Eip712DomainMsg | undefined;
279
+ set domain(value: Eip712DomainMsg | null | undefined);
280
+ }
281
+ export class UserDecryptionResponse {
282
+ private constructor();
283
+ free(): void;
284
+ signature: Uint8Array;
285
+ /**
286
+ * This is the external signature created from the Eip712 domain
287
+ * on the structure, where userDecryptedShare is bincode::serialize(&payload)
288
+ * struct UserDecryptResponseVerification {
289
+ * bytes publicKey;
290
+ * uint256\[\] ctHandles;
291
+ * bytes userDecryptedShare;
292
+ * }
293
+ */
294
+ external_signature: Uint8Array;
295
+ /**
296
+ * The actual \[UserDecryptionResponsePayload\].
297
+ */
298
+ get payload(): UserDecryptionResponsePayload | undefined;
299
+ /**
300
+ * The actual \[UserDecryptionResponsePayload\].
301
+ */
302
+ set payload(value: UserDecryptionResponsePayload | null | undefined);
303
+ }
304
+ export class UserDecryptionResponsePayload {
305
+ private constructor();
306
+ free(): void;
307
+ /**
308
+ * The server's signature verification key, Encoded using SEC1.
309
+ * Needed to validate the response, but MUST also be linked to a list of
310
+ * trusted keys.
311
+ */
312
+ verification_key: Uint8Array;
313
+ /**
314
+ * This is needed to ensure the response corresponds to the request.
315
+ * It is the digest of UserDecryptionLinker hashed using EIP712
316
+ * under the given domain in the request.
317
+ */
318
+ digest: Uint8Array;
319
+ /**
320
+ * The resulting signcrypted ciphertexts, each ciphertext
321
+ * must be decrypted and then reconstructed with the other shares
322
+ * to produce the final plaintext.
323
+ */
324
+ signcrypted_ciphertexts: TypedSigncryptedCiphertext[];
325
+ /**
326
+ * The ID of the MPC party doing the user decryption. Used for polynomial
327
+ * reconstruction.
328
+ */
329
+ party_id: number;
330
+ /**
331
+ * The degree of the sharing scheme used.
332
+ */
333
+ degree: number;
364
334
  }