node-tkms 0.11.0-rc8 → 0.11.0

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,14 +1,21 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ export function ml_kem_pke_pk_len(): number;
4
+ export function ml_kem_pke_sk_len(): number;
3
5
  export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
4
6
  export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
5
7
  export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
6
8
  export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
9
+ /**
10
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
11
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
12
+ */
13
+ export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
7
14
  /**
8
15
  * Instantiate a new client.
9
16
  *
10
- * * `server_addrs` - a list of KMS server EIP-55 addresses,
11
- * must be prefixed with "0x".
17
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
18
+ * the elements in the list can be created using [new_server_id_addr].
12
19
  *
13
20
  * * `client_address_hex` - the client (wallet) address in hex,
14
21
  * must be prefixed with "0x".
@@ -16,26 +23,35 @@ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
16
23
  * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
17
24
  * The "default" parameter choice is selected if no matching string is found.
18
25
  */
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[];
26
+ export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
27
+ export function get_server_addrs(client: Client): ServerIdAddr[];
21
28
  export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
22
29
  export function get_client_address(client: Client): string;
23
- export function cryptobox_keygen(): PrivateEncKey;
24
- export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey;
25
- export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array;
26
- export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array;
27
- export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey;
28
- export function u8vec_to_cryptobox_sk(v: Uint8Array): PrivateEncKey;
29
- export function cryptobox_encrypt(msg: Uint8Array, their_pk: PublicEncKey, my_sk: PrivateEncKey): CryptoBoxCt;
30
- export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array;
30
+ export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
31
+ export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
32
+ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
33
+ export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
34
+ export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
35
+ export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
36
+ /**
37
+ * This function is *not* used by relayer-sdk because the encryption
38
+ * happens on the KMS side. It's just here for completeness and tests.
39
+ */
40
+ export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
31
41
  /**
32
- * Process the reencryption response from JavaScript objects.
42
+ * This function is *not* used by relayer-sdk because the decryption
43
+ * is handled by [process_user_decryption_resp].
44
+ * It's just here for completeness and tests.
45
+ */
46
+ export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
47
+ /**
48
+ * Process the user_decryption response from JavaScript objects.
33
49
  * The returned result is a byte array representing a plaintext of any length,
34
50
  * postprocessing is returned to turn it into an integer.
35
51
  *
36
- * * `client` - client that wants to perform reencryption.
52
+ * * `client` - client that wants to perform user_decryption.
37
53
  *
38
- * * `request` - the initial reencryption request JS object.
54
+ * * `request` - the initial user_decryption request JS object.
39
55
  * It can be set to null if `verify` is false.
40
56
  * Otherwise the caller needs to give the following JS object.
41
57
  * Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
@@ -76,7 +92,8 @@ export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_p
76
92
  * [
77
93
  * {
78
94
  * signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
79
- * payload: '0100000029...'
95
+ * payload: '0100000029...',
96
+ * extra_data: '01234...',
80
97
  * }
81
98
  * ]
82
99
  * ```
@@ -88,22 +105,22 @@ export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_p
88
105
  * * `verify` - Whether to perform signature verification for the response.
89
106
  * It is insecure if `verify = false`!
90
107
  */
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[];
108
+ export function process_user_decryption_resp_from_js(client: Client, request: any, eip712_domain: any, agg_resp: any, enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
92
109
  /**
93
- * Process the reencryption response from Rust objects.
94
- * Consider using [process_reencryption_resp_from_js]
110
+ * Process the user_decryption response from Rust objects.
111
+ * Consider using [process_user_decryption_resp_from_js]
95
112
  * when using the JS API.
96
113
  * The result is a byte array representing a plaintext of any length.
97
114
  *
98
- * * `client` - client that wants to perform reencryption.
115
+ * * `client` - client that wants to perform user_decryption.
99
116
  *
100
- * * `request` - the initial reencryption request.
117
+ * * `request` - the initial user_decryption request.
101
118
  * Must be given if `verify` is true.
102
119
  *
103
120
  * * `eip712_domain` - the EIP-712 domain.
104
121
  * Must be given if `verify` is true.
105
122
  *
106
- * * `agg_resp` - the vector of reencryption responses.
123
+ * * `agg_resp` - the vector of user_decryption responses.
107
124
  *
108
125
  * * `enc_pk` - The ephemeral public key.
109
126
  *
@@ -112,7 +129,7 @@ export function process_reencryption_resp_from_js(client: Client, request: any,
112
129
  * * `verify` - Whether to perform signature verification for the response.
113
130
  * It is insecure if `verify = false`!
114
131
  */
115
- export function process_reencryption_resp(client: Client, request: ParsedReencryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: ReencryptionResponse[], enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): TypedPlaintext[];
132
+ export function process_user_decryption_resp(client: Client, request: ParsedUserDecryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: UserDecryptionResponse[], enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
116
133
  export class CiphertextHandle {
117
134
  private constructor();
118
135
  free(): void;
@@ -128,14 +145,10 @@ export class Client {
128
145
  private constructor();
129
146
  free(): void;
130
147
  }
131
- export class CryptoBoxCt {
132
- private constructor();
133
- free(): void;
134
- }
135
148
  /**
136
- * <https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator>
137
- * eventually chain_id, verifying_contract and salt will be parsed in to
138
- * solidity types
149
+ * Eip712 domain information.
150
+ * Any constraints specified in the [standard](<https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator>) _must_ be fulfilled.
151
+ * Furthermore, be aware that all parameters will eventually be parsed into Solidity types.
139
152
  */
140
153
  export class Eip712DomainMsg {
141
154
  private constructor();
@@ -150,11 +163,11 @@ export class Eip712DomainMsg {
150
163
  /**
151
164
  * Validity of this struct is not checked.
152
165
  */
153
- export class ParsedReencryptionRequest {
166
+ export class ParsedUserDecryptionRequest {
154
167
  private constructor();
155
168
  free(): void;
156
169
  }
157
- export class PrivateEncKey {
170
+ export class PrivateEncKeyMlKem512 {
158
171
  private constructor();
159
172
  free(): void;
160
173
  }
@@ -162,7 +175,7 @@ export class PrivateSigKey {
162
175
  private constructor();
163
176
  free(): void;
164
177
  }
165
- export class PublicEncKey {
178
+ export class PublicEncKeyMlKem512 {
166
179
  private constructor();
167
180
  free(): void;
168
181
  }
@@ -170,7 +183,79 @@ export class PublicSigKey {
170
183
  private constructor();
171
184
  free(): void;
172
185
  }
173
- export class ReencryptionRequest {
186
+ /**
187
+ * / A unique 32 Byte / 256 Bit ID, to be used to identify a request and
188
+ * / for retrieving the computed result later on.
189
+ * / Must be encoded in lower-case hex. The string must NOT contain a `0x` prefix.
190
+ */
191
+ export class RequestId {
192
+ private constructor();
193
+ free(): void;
194
+ request_id: string;
195
+ }
196
+ export class ServerIdAddr {
197
+ private constructor();
198
+ free(): void;
199
+ }
200
+ export class TypedCiphertext {
201
+ private constructor();
202
+ free(): void;
203
+ /**
204
+ * The actual ciphertext to decrypt, taken directly from fhevm.
205
+ */
206
+ ciphertext: Uint8Array;
207
+ /**
208
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
209
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
210
+ */
211
+ fhe_type: number;
212
+ /**
213
+ * The external handle of the ciphertext (the handle used in the copro).
214
+ */
215
+ external_handle: Uint8Array;
216
+ /**
217
+ * The ciphertext format, see CiphertextFormat documentation for details.
218
+ * CiphertextFormat::default() is used if unspecified.
219
+ */
220
+ ciphertext_format: number;
221
+ }
222
+ export class TypedPlaintext {
223
+ private constructor();
224
+ free(): void;
225
+ /**
226
+ * The actual plaintext in bytes.
227
+ */
228
+ bytes: Uint8Array;
229
+ /**
230
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
231
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
232
+ */
233
+ fhe_type: number;
234
+ }
235
+ export class TypedSigncryptedCiphertext {
236
+ private constructor();
237
+ free(): void;
238
+ /**
239
+ * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
240
+ * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
241
+ */
242
+ fhe_type: number;
243
+ /**
244
+ * The signcrypted payload, using a hybrid encryption approach in
245
+ * sign-then-encrypt.
246
+ */
247
+ signcrypted_ciphertext: Uint8Array;
248
+ /**
249
+ * The external handles that were originally in the request.
250
+ */
251
+ external_handle: Uint8Array;
252
+ /**
253
+ * The packing factor determines whether the decrypted plaintext
254
+ * has a different way of packing compared to what is specified in the plaintext modulus.
255
+ */
256
+ packing_factor: number;
257
+ }
258
+ export class UserDecryptionRequest {
174
259
  private constructor();
175
260
  free(): void;
176
261
  /**
@@ -184,7 +269,7 @@ export class ReencryptionRequest {
184
269
  */
185
270
  set request_id(value: RequestId | null | undefined);
186
271
  /**
187
- * The list of ciphertexts to reencrypt.
272
+ * The list of ciphertexts to decrypt for the user.
188
273
  */
189
274
  typed_ciphertexts: TypedCiphertext[];
190
275
  /**
@@ -198,43 +283,56 @@ export class ReencryptionRequest {
198
283
  */
199
284
  set key_id(value: RequestId | null | undefined);
200
285
  /**
201
- * The client's (blockchain wallet) address,
202
- * encoded using EIP-55.
286
+ * The client's (blockchain wallet) address, encoded using EIP-55. I.e. including `0x`.
203
287
  */
204
288
  client_address: string;
205
289
  /**
206
290
  * Encoding of the user's public encryption key for this request.
207
- * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a
208
- * Montgomery point.
291
+ * This must be a bincode (v.1) encoded ML-KEM 512 key.
209
292
  */
210
293
  enc_key: Uint8Array;
294
+ /**
295
+ * The user's EIP712 domain. This MUST be present. Furthermore, the `verifying_contract` MUST be set and be distinct from `client_address`.
296
+ */
211
297
  get domain(): Eip712DomainMsg | undefined;
298
+ /**
299
+ * The user's EIP712 domain. This MUST be present. Furthermore, the `verifying_contract` MUST be set and be distinct from `client_address`.
300
+ */
212
301
  set domain(value: Eip712DomainMsg | null | undefined);
302
+ /**
303
+ * Extra data from the gateway.
304
+ */
305
+ extra_data: Uint8Array;
213
306
  }
214
- export class ReencryptionResponse {
307
+ export class UserDecryptionResponse {
215
308
  private constructor();
216
309
  free(): void;
217
310
  signature: Uint8Array;
218
311
  /**
219
312
  * This is the external signature created from the Eip712 domain
220
- * on the structure, where reencryptedShare is bincode::serialize(&payload)
313
+ * on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
221
314
  * struct UserDecryptResponseVerification {
222
315
  * bytes publicKey;
223
316
  * uint256\[\] ctHandles;
224
- * bytes reencryptedShare;
317
+ * bytes userDecryptedShare; // serialization of payload
318
+ * bytes extraData;
225
319
  * }
226
320
  */
227
321
  external_signature: Uint8Array;
228
322
  /**
229
- * The actual \[ReencryptionResponsePayload\].
323
+ * The actual \[UserDecryptionResponsePayload\].
230
324
  */
231
- get payload(): ReencryptionResponsePayload | undefined;
325
+ get payload(): UserDecryptionResponsePayload | undefined;
232
326
  /**
233
- * The actual \[ReencryptionResponsePayload\].
327
+ * The actual \[UserDecryptionResponsePayload\].
234
328
  */
235
- set payload(value: ReencryptionResponsePayload | null | undefined);
329
+ set payload(value: UserDecryptionResponsePayload | null | undefined);
330
+ /**
331
+ * Extra data used in the EIP712 signature - external_signature.
332
+ */
333
+ extra_data: Uint8Array;
236
334
  }
237
- export class ReencryptionResponsePayload {
335
+ export class UserDecryptionResponsePayload {
238
336
  private constructor();
239
337
  free(): void;
240
338
  /**
@@ -256,7 +354,7 @@ export class ReencryptionResponsePayload {
256
354
  */
257
355
  signcrypted_ciphertexts: TypedSigncryptedCiphertext[];
258
356
  /**
259
- * The ID of the MPC party doing the reencryption. Used for polynomial
357
+ * The ID of the MPC party doing the user decryption. Used for polynomial
260
358
  * reconstruction.
261
359
  */
262
360
  party_id: number;
@@ -265,73 +363,3 @@ export class ReencryptionResponsePayload {
265
363
  */
266
364
  degree: number;
267
365
  }
268
- /**
269
- * Simple response to return a 32 Byte / 256 Bit ID, to be used to retrieve the
270
- * computed result later on. This string does NOT contain a `0x` prefix.
271
- */
272
- export class RequestId {
273
- private constructor();
274
- free(): void;
275
- request_id: string;
276
- }
277
- export class TypedCiphertext {
278
- private constructor();
279
- free(): void;
280
- /**
281
- * The actual ciphertext to decrypt, taken directly from fhevm.
282
- */
283
- ciphertext: Uint8Array;
284
- /**
285
- * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
286
- * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
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. The type should match FheType from tfhe-rs:
311
- * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
312
- */
313
- fhe_type: number;
314
- }
315
- export class TypedSigncryptedCiphertext {
316
- private constructor();
317
- free(): void;
318
- /**
319
- * The type of plaintext encrypted. The type should match FheType from tfhe-rs:
320
- * <https://github.com/zama-ai/tfhe-rs/blob/main/tfhe/src/high_level_api/mod.rs>
321
- */
322
- fhe_type: number;
323
- /**
324
- * The signcrypted payload, using a hybrid encryption approach in
325
- * sign-then-encrypt.
326
- */
327
- signcrypted_ciphertext: Uint8Array;
328
- /**
329
- * The external handles that were originally in the request.
330
- */
331
- external_handle: Uint8Array;
332
- /**
333
- * The packing factor determines whether the decrypted plaintext
334
- * has a different way of packing compared to what is specified in the plaintext modulus.
335
- */
336
- packing_factor: number;
337
- }