node-tkms 0.12.5 → 0.12.7
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 +55 -55
- package/kms_lib.js +205 -205
- package/kms_lib_bg.wasm +0 -0
- package/package.json +1 -1
package/kms_lib.d.ts
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
4
|
-
export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
5
|
-
export function get_client_address(client: Client): string;
|
|
6
|
-
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
7
|
-
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
8
|
-
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
9
|
-
/**
|
|
10
|
-
* This function is *not* used by relayer-sdk because the decryption
|
|
11
|
-
* is handled by [process_user_decryption_resp].
|
|
12
|
-
* It's just here for completeness and tests.
|
|
13
|
-
*/
|
|
14
|
-
export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
15
|
-
export function ml_kem_pke_sk_len(): number;
|
|
16
|
-
export function ml_kem_pke_pk_len(): number;
|
|
17
|
-
/**
|
|
18
|
-
* This function is *not* used by relayer-sdk because the encryption
|
|
19
|
-
* happens on the KMS side. It's just here for completeness and tests.
|
|
20
|
-
*/
|
|
21
|
-
export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
|
|
22
|
-
/**
|
|
23
|
-
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
24
|
-
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
25
|
-
*/
|
|
26
|
-
export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
|
|
27
|
-
export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
|
|
28
|
-
export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
|
|
29
|
-
export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
|
|
30
|
-
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
31
|
-
/**
|
|
32
|
-
* Process the user_decryption response from Rust objects.
|
|
33
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
34
|
-
* when using the JS API.
|
|
35
|
-
* The result is a byte array representing a plaintext of any length.
|
|
36
|
-
*
|
|
37
|
-
* * `client` - client that wants to perform user_decryption.
|
|
38
|
-
*
|
|
39
|
-
* * `request` - the initial user_decryption request.
|
|
40
|
-
* Must be given if `verify` is true.
|
|
41
|
-
*
|
|
42
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
43
|
-
* Must be given if `verify` is true.
|
|
44
|
-
*
|
|
45
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
46
|
-
*
|
|
47
|
-
* * `enc_pk` - The ephemeral public key.
|
|
48
|
-
*
|
|
49
|
-
* * `enc_sk` - The ephemeral secret key.
|
|
50
|
-
*
|
|
51
|
-
* * `verify` - Whether to perform signature verification for the response.
|
|
52
|
-
* It is insecure if `verify = false`!
|
|
53
|
-
*/
|
|
54
|
-
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[];
|
|
55
|
-
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
56
|
-
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
57
|
-
export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
|
|
58
3
|
/**
|
|
59
4
|
* Process the user_decryption response from JavaScript objects.
|
|
60
5
|
* The returned result is a byte array representing a plaintext of any length,
|
|
@@ -117,6 +62,60 @@ export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
|
|
|
117
62
|
* It is insecure if `verify = false`!
|
|
118
63
|
*/
|
|
119
64
|
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[];
|
|
65
|
+
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
68
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
69
|
+
*/
|
|
70
|
+
export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
|
|
71
|
+
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
72
|
+
export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
|
|
73
|
+
export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
|
|
74
|
+
export function ml_kem_pke_sk_len(): number;
|
|
75
|
+
/**
|
|
76
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
77
|
+
* is handled by [process_user_decryption_resp].
|
|
78
|
+
* It's just here for completeness and tests.
|
|
79
|
+
*/
|
|
80
|
+
export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
81
|
+
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
82
|
+
export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
83
|
+
export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
|
|
84
|
+
export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
|
|
85
|
+
export function ml_kem_pke_pk_len(): number;
|
|
86
|
+
/**
|
|
87
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
88
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
89
|
+
*/
|
|
90
|
+
export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
|
|
91
|
+
/**
|
|
92
|
+
* Process the user_decryption response from Rust objects.
|
|
93
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
94
|
+
* when using the JS API.
|
|
95
|
+
* The result is a byte array representing a plaintext of any length.
|
|
96
|
+
*
|
|
97
|
+
* * `client` - client that wants to perform user_decryption.
|
|
98
|
+
*
|
|
99
|
+
* * `request` - the initial user_decryption request.
|
|
100
|
+
* Must be given if `verify` is true.
|
|
101
|
+
*
|
|
102
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
103
|
+
* Must be given if `verify` is true.
|
|
104
|
+
*
|
|
105
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
106
|
+
*
|
|
107
|
+
* * `enc_pk` - The ephemeral public key.
|
|
108
|
+
*
|
|
109
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
110
|
+
*
|
|
111
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
112
|
+
* It is insecure if `verify = false`!
|
|
113
|
+
*/
|
|
114
|
+
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[];
|
|
115
|
+
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
116
|
+
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
117
|
+
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
118
|
+
export function get_client_address(client: Client): string;
|
|
120
119
|
/**
|
|
121
120
|
* Instantiate a new client.
|
|
122
121
|
*
|
|
@@ -130,6 +129,7 @@ export function process_user_decryption_resp_from_js(client: Client, request: an
|
|
|
130
129
|
* The "default" parameter choice is selected if no matching string is found.
|
|
131
130
|
*/
|
|
132
131
|
export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
|
|
132
|
+
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
133
133
|
export class CiphertextHandle {
|
|
134
134
|
private constructor();
|
|
135
135
|
free(): void;
|
package/kms_lib.js
CHANGED
|
@@ -177,6 +177,12 @@ function _assertClass(instance, klass) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
function takeFromExternrefTable0(idx) {
|
|
181
|
+
const value = wasm.__wbindgen_export_4.get(idx);
|
|
182
|
+
wasm.__externref_table_dealloc(idx);
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
|
|
180
186
|
function getArrayJsValueFromWasm0(ptr, len) {
|
|
181
187
|
ptr = ptr >>> 0;
|
|
182
188
|
const mem = getDataViewMemory0();
|
|
@@ -188,34 +194,123 @@ function getArrayJsValueFromWasm0(ptr, len) {
|
|
|
188
194
|
return result;
|
|
189
195
|
}
|
|
190
196
|
/**
|
|
197
|
+
* Process the user_decryption response from JavaScript objects.
|
|
198
|
+
* The returned result is a byte array representing a plaintext of any length,
|
|
199
|
+
* postprocessing is returned to turn it into an integer.
|
|
200
|
+
*
|
|
201
|
+
* * `client` - client that wants to perform user_decryption.
|
|
202
|
+
*
|
|
203
|
+
* * `request` - the initial user_decryption request JS object.
|
|
204
|
+
* It can be set to null if `verify` is false.
|
|
205
|
+
* Otherwise the caller needs to give the following JS object.
|
|
206
|
+
* Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
|
|
207
|
+
* The signature field is not needed.
|
|
208
|
+
* ```
|
|
209
|
+
* {
|
|
210
|
+
* signature: undefined,
|
|
211
|
+
* client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
|
|
212
|
+
* enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
|
|
213
|
+
* ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
|
|
214
|
+
* eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* * `eip712_domain` - the EIP-712 domain JS object.
|
|
219
|
+
* It can be set to null if `verify` is false.
|
|
220
|
+
* Otherwise the caller needs to give the following JS object.
|
|
221
|
+
* Note that `salt` is optional and `verifying_contract` follows EIP-55,
|
|
222
|
+
* additionally, `chain_id` is an array of u8.
|
|
223
|
+
* ```
|
|
224
|
+
* {
|
|
225
|
+
* name: 'Authorization token',
|
|
226
|
+
* version: '1',
|
|
227
|
+
* chain_id: [
|
|
228
|
+
* 70, 31, 0, 0, 0, 0, 0, 0, 0,
|
|
229
|
+
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
230
|
+
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
231
|
+
* 0, 0, 0, 0, 0
|
|
232
|
+
* ],
|
|
233
|
+
* verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
|
|
234
|
+
* salt: []
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* * `agg_resp` - the response JS object from the gateway.
|
|
239
|
+
* It has two fields like so, both are hex encoded byte arrays.
|
|
240
|
+
* ```
|
|
241
|
+
* [
|
|
242
|
+
* {
|
|
243
|
+
* signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
|
|
244
|
+
* payload: '0100000029...',
|
|
245
|
+
* extra_data: '01234...',
|
|
246
|
+
* }
|
|
247
|
+
* ]
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* * `enc_pk` - The ephemeral public key.
|
|
251
|
+
*
|
|
252
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
253
|
+
*
|
|
254
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
255
|
+
* It is insecure if `verify = false`!
|
|
191
256
|
* @param {Client} client
|
|
192
|
-
* @
|
|
257
|
+
* @param {any} request
|
|
258
|
+
* @param {any} eip712_domain
|
|
259
|
+
* @param {any} agg_resp
|
|
260
|
+
* @param {PublicEncKeyMlKem512} enc_pk
|
|
261
|
+
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
262
|
+
* @param {boolean} verify
|
|
263
|
+
* @returns {TypedPlaintext[]}
|
|
193
264
|
*/
|
|
194
|
-
module.exports.
|
|
265
|
+
module.exports.process_user_decryption_resp_from_js = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
195
266
|
_assertClass(client, Client);
|
|
196
|
-
|
|
267
|
+
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
268
|
+
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
269
|
+
const ret = wasm.process_user_decryption_resp_from_js(client.__wbg_ptr, request, eip712_domain, agg_resp, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
270
|
+
if (ret[3]) {
|
|
271
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
272
|
+
}
|
|
197
273
|
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
198
274
|
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
199
275
|
return v1;
|
|
200
276
|
};
|
|
201
277
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
278
|
+
/**
|
|
279
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
280
|
+
*/
|
|
281
|
+
module.exports.ml_kem_pke_keygen = function() {
|
|
282
|
+
const ret = wasm.ml_kem_pke_keygen();
|
|
283
|
+
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
288
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
289
|
+
* @param {number} id
|
|
290
|
+
* @param {string} addr
|
|
291
|
+
* @returns {ServerIdAddr}
|
|
292
|
+
*/
|
|
293
|
+
module.exports.new_server_id_addr = function(id, addr) {
|
|
294
|
+
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
295
|
+
const len0 = WASM_VECTOR_LEN;
|
|
296
|
+
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
297
|
+
if (ret[2]) {
|
|
298
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
299
|
+
}
|
|
300
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
301
|
+
};
|
|
207
302
|
|
|
208
303
|
function getArrayU8FromWasm0(ptr, len) {
|
|
209
304
|
ptr = ptr >>> 0;
|
|
210
305
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
211
306
|
}
|
|
212
307
|
/**
|
|
213
|
-
* @param {
|
|
308
|
+
* @param {PrivateSigKey} sk
|
|
214
309
|
* @returns {Uint8Array}
|
|
215
310
|
*/
|
|
216
|
-
module.exports.
|
|
217
|
-
_assertClass(sk,
|
|
218
|
-
const ret = wasm.
|
|
311
|
+
module.exports.private_sig_key_to_u8vec = function(sk) {
|
|
312
|
+
_assertClass(sk, PrivateSigKey);
|
|
313
|
+
const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
|
|
219
314
|
if (ret[3]) {
|
|
220
315
|
throw takeFromExternrefTable0(ret[2]);
|
|
221
316
|
}
|
|
@@ -225,21 +320,13 @@ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
|
225
320
|
};
|
|
226
321
|
|
|
227
322
|
/**
|
|
228
|
-
* @param {
|
|
229
|
-
* @returns {
|
|
323
|
+
* @param {PrivateEncKeyMlKem512} sk
|
|
324
|
+
* @returns {PublicEncKeyMlKem512}
|
|
230
325
|
*/
|
|
231
|
-
module.exports.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
_assertClass(client, Client);
|
|
236
|
-
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
237
|
-
deferred1_0 = ret[0];
|
|
238
|
-
deferred1_1 = ret[1];
|
|
239
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
240
|
-
} finally {
|
|
241
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
242
|
-
}
|
|
326
|
+
module.exports.ml_kem_pke_get_pk = function(sk) {
|
|
327
|
+
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
328
|
+
const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
|
|
329
|
+
return PublicEncKeyMlKem512.__wrap(ret);
|
|
243
330
|
};
|
|
244
331
|
|
|
245
332
|
function passArray8ToWasm0(arg, malloc) {
|
|
@@ -250,43 +337,24 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
250
337
|
}
|
|
251
338
|
/**
|
|
252
339
|
* @param {Uint8Array} v
|
|
253
|
-
* @returns {
|
|
340
|
+
* @returns {PublicEncKeyMlKem512}
|
|
254
341
|
*/
|
|
255
|
-
module.exports.
|
|
342
|
+
module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
|
|
256
343
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
257
344
|
const len0 = WASM_VECTOR_LEN;
|
|
258
|
-
const ret = wasm.
|
|
345
|
+
const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
|
|
259
346
|
if (ret[2]) {
|
|
260
347
|
throw takeFromExternrefTable0(ret[1]);
|
|
261
348
|
}
|
|
262
|
-
return
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @param {PrivateSigKey} sk
|
|
267
|
-
* @returns {Uint8Array}
|
|
268
|
-
*/
|
|
269
|
-
module.exports.private_sig_key_to_u8vec = function(sk) {
|
|
270
|
-
_assertClass(sk, PrivateSigKey);
|
|
271
|
-
const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
|
|
272
|
-
if (ret[3]) {
|
|
273
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
274
|
-
}
|
|
275
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
276
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
277
|
-
return v1;
|
|
349
|
+
return PublicEncKeyMlKem512.__wrap(ret[0]);
|
|
278
350
|
};
|
|
279
351
|
|
|
280
352
|
/**
|
|
281
|
-
* @
|
|
282
|
-
* @returns {Uint8Array}
|
|
353
|
+
* @returns {number}
|
|
283
354
|
*/
|
|
284
|
-
module.exports.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
288
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
289
|
-
return v1;
|
|
355
|
+
module.exports.ml_kem_pke_sk_len = function() {
|
|
356
|
+
const ret = wasm.ml_kem_pke_sk_len();
|
|
357
|
+
return ret >>> 0;
|
|
290
358
|
};
|
|
291
359
|
|
|
292
360
|
/**
|
|
@@ -307,78 +375,33 @@ module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
|
307
375
|
return v2;
|
|
308
376
|
};
|
|
309
377
|
|
|
310
|
-
/**
|
|
311
|
-
* @returns {number}
|
|
312
|
-
*/
|
|
313
|
-
module.exports.ml_kem_pke_sk_len = function() {
|
|
314
|
-
const ret = wasm.ml_kem_pke_sk_len();
|
|
315
|
-
return ret >>> 0;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* @returns {number}
|
|
320
|
-
*/
|
|
321
|
-
module.exports.ml_kem_pke_pk_len = function() {
|
|
322
|
-
const ret = wasm.ml_kem_pke_pk_len();
|
|
323
|
-
return ret >>> 0;
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* This function is *not* used by relayer-sdk because the encryption
|
|
328
|
-
* happens on the KMS side. It's just here for completeness and tests.
|
|
329
|
-
* @param {Uint8Array} msg
|
|
330
|
-
* @param {PublicEncKeyMlKem512} their_pk
|
|
331
|
-
* @returns {Uint8Array}
|
|
332
|
-
*/
|
|
333
|
-
module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
|
|
334
|
-
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
335
|
-
const len0 = WASM_VECTOR_LEN;
|
|
336
|
-
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
337
|
-
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
338
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
339
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
340
|
-
return v2;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
345
|
-
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
346
|
-
* @param {number} id
|
|
347
|
-
* @param {string} addr
|
|
348
|
-
* @returns {ServerIdAddr}
|
|
349
|
-
*/
|
|
350
|
-
module.exports.new_server_id_addr = function(id, addr) {
|
|
351
|
-
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
352
|
-
const len0 = WASM_VECTOR_LEN;
|
|
353
|
-
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
354
|
-
if (ret[2]) {
|
|
355
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
356
|
-
}
|
|
357
|
-
return ServerIdAddr.__wrap(ret[0]);
|
|
358
|
-
};
|
|
359
|
-
|
|
360
378
|
/**
|
|
361
379
|
* @param {Uint8Array} v
|
|
362
|
-
* @returns {
|
|
380
|
+
* @returns {PublicSigKey}
|
|
363
381
|
*/
|
|
364
|
-
module.exports.
|
|
382
|
+
module.exports.u8vec_to_public_sig_key = function(v) {
|
|
365
383
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
366
384
|
const len0 = WASM_VECTOR_LEN;
|
|
367
|
-
const ret = wasm.
|
|
385
|
+
const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
|
|
368
386
|
if (ret[2]) {
|
|
369
387
|
throw takeFromExternrefTable0(ret[1]);
|
|
370
388
|
}
|
|
371
|
-
return
|
|
389
|
+
return PublicSigKey.__wrap(ret[0]);
|
|
372
390
|
};
|
|
373
391
|
|
|
374
392
|
/**
|
|
375
393
|
* @param {PrivateEncKeyMlKem512} sk
|
|
376
|
-
* @returns {
|
|
394
|
+
* @returns {Uint8Array}
|
|
377
395
|
*/
|
|
378
|
-
module.exports.
|
|
396
|
+
module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
379
397
|
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
380
|
-
const ret = wasm.
|
|
381
|
-
|
|
398
|
+
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
399
|
+
if (ret[3]) {
|
|
400
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
401
|
+
}
|
|
402
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
403
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
404
|
+
return v1;
|
|
382
405
|
};
|
|
383
406
|
|
|
384
407
|
/**
|
|
@@ -398,16 +421,41 @@ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
|
|
|
398
421
|
|
|
399
422
|
/**
|
|
400
423
|
* @param {Uint8Array} v
|
|
401
|
-
* @returns {
|
|
424
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
402
425
|
*/
|
|
403
|
-
module.exports.
|
|
426
|
+
module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
|
|
404
427
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
405
428
|
const len0 = WASM_VECTOR_LEN;
|
|
406
|
-
const ret = wasm.
|
|
429
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
407
430
|
if (ret[2]) {
|
|
408
431
|
throw takeFromExternrefTable0(ret[1]);
|
|
409
432
|
}
|
|
410
|
-
return
|
|
433
|
+
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* @returns {number}
|
|
438
|
+
*/
|
|
439
|
+
module.exports.ml_kem_pke_pk_len = function() {
|
|
440
|
+
const ret = wasm.ml_kem_pke_pk_len();
|
|
441
|
+
return ret >>> 0;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
446
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
447
|
+
* @param {Uint8Array} msg
|
|
448
|
+
* @param {PublicEncKeyMlKem512} their_pk
|
|
449
|
+
* @returns {Uint8Array}
|
|
450
|
+
*/
|
|
451
|
+
module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
|
|
452
|
+
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
453
|
+
const len0 = WASM_VECTOR_LEN;
|
|
454
|
+
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
455
|
+
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
456
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
457
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
458
|
+
return v2;
|
|
411
459
|
};
|
|
412
460
|
|
|
413
461
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
@@ -476,117 +524,59 @@ module.exports.process_user_decryption_resp = function(client, request, eip712_d
|
|
|
476
524
|
};
|
|
477
525
|
|
|
478
526
|
/**
|
|
479
|
-
* @param {
|
|
480
|
-
* @returns {
|
|
527
|
+
* @param {PublicSigKey} pk
|
|
528
|
+
* @returns {Uint8Array}
|
|
481
529
|
*/
|
|
482
|
-
module.exports.
|
|
483
|
-
_assertClass(
|
|
484
|
-
const ret = wasm.
|
|
485
|
-
|
|
530
|
+
module.exports.public_sig_key_to_u8vec = function(pk) {
|
|
531
|
+
_assertClass(pk, PublicSigKey);
|
|
532
|
+
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
533
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
534
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
535
|
+
return v1;
|
|
486
536
|
};
|
|
487
537
|
|
|
488
538
|
/**
|
|
489
|
-
* @
|
|
539
|
+
* @param {Client} client
|
|
540
|
+
* @returns {ServerIdAddr[]}
|
|
490
541
|
*/
|
|
491
|
-
module.exports.
|
|
492
|
-
|
|
493
|
-
|
|
542
|
+
module.exports.get_server_addrs = function(client) {
|
|
543
|
+
_assertClass(client, Client);
|
|
544
|
+
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
545
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
546
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
547
|
+
return v1;
|
|
494
548
|
};
|
|
495
549
|
|
|
496
550
|
/**
|
|
497
551
|
* @param {Uint8Array} v
|
|
498
|
-
* @returns {
|
|
552
|
+
* @returns {PrivateSigKey}
|
|
499
553
|
*/
|
|
500
|
-
module.exports.
|
|
554
|
+
module.exports.u8vec_to_private_sig_key = function(v) {
|
|
501
555
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
502
556
|
const len0 = WASM_VECTOR_LEN;
|
|
503
|
-
const ret = wasm.
|
|
557
|
+
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
504
558
|
if (ret[2]) {
|
|
505
559
|
throw takeFromExternrefTable0(ret[1]);
|
|
506
560
|
}
|
|
507
|
-
return
|
|
561
|
+
return PrivateSigKey.__wrap(ret[0]);
|
|
508
562
|
};
|
|
509
563
|
|
|
510
564
|
/**
|
|
511
|
-
* Process the user_decryption response from JavaScript objects.
|
|
512
|
-
* The returned result is a byte array representing a plaintext of any length,
|
|
513
|
-
* postprocessing is returned to turn it into an integer.
|
|
514
|
-
*
|
|
515
|
-
* * `client` - client that wants to perform user_decryption.
|
|
516
|
-
*
|
|
517
|
-
* * `request` - the initial user_decryption request JS object.
|
|
518
|
-
* It can be set to null if `verify` is false.
|
|
519
|
-
* Otherwise the caller needs to give the following JS object.
|
|
520
|
-
* Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
|
|
521
|
-
* The signature field is not needed.
|
|
522
|
-
* ```
|
|
523
|
-
* {
|
|
524
|
-
* signature: undefined,
|
|
525
|
-
* client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
|
|
526
|
-
* enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
|
|
527
|
-
* ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
|
|
528
|
-
* eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
|
|
529
|
-
* }
|
|
530
|
-
* ```
|
|
531
|
-
*
|
|
532
|
-
* * `eip712_domain` - the EIP-712 domain JS object.
|
|
533
|
-
* It can be set to null if `verify` is false.
|
|
534
|
-
* Otherwise the caller needs to give the following JS object.
|
|
535
|
-
* Note that `salt` is optional and `verifying_contract` follows EIP-55,
|
|
536
|
-
* additionally, `chain_id` is an array of u8.
|
|
537
|
-
* ```
|
|
538
|
-
* {
|
|
539
|
-
* name: 'Authorization token',
|
|
540
|
-
* version: '1',
|
|
541
|
-
* chain_id: [
|
|
542
|
-
* 70, 31, 0, 0, 0, 0, 0, 0, 0,
|
|
543
|
-
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
544
|
-
* 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
545
|
-
* 0, 0, 0, 0, 0
|
|
546
|
-
* ],
|
|
547
|
-
* verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
|
|
548
|
-
* salt: []
|
|
549
|
-
* }
|
|
550
|
-
* ```
|
|
551
|
-
*
|
|
552
|
-
* * `agg_resp` - the response JS object from the gateway.
|
|
553
|
-
* It has two fields like so, both are hex encoded byte arrays.
|
|
554
|
-
* ```
|
|
555
|
-
* [
|
|
556
|
-
* {
|
|
557
|
-
* signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
|
|
558
|
-
* payload: '0100000029...',
|
|
559
|
-
* extra_data: '01234...',
|
|
560
|
-
* }
|
|
561
|
-
* ]
|
|
562
|
-
* ```
|
|
563
|
-
*
|
|
564
|
-
* * `enc_pk` - The ephemeral public key.
|
|
565
|
-
*
|
|
566
|
-
* * `enc_sk` - The ephemeral secret key.
|
|
567
|
-
*
|
|
568
|
-
* * `verify` - Whether to perform signature verification for the response.
|
|
569
|
-
* It is insecure if `verify = false`!
|
|
570
565
|
* @param {Client} client
|
|
571
|
-
* @
|
|
572
|
-
* @param {any} eip712_domain
|
|
573
|
-
* @param {any} agg_resp
|
|
574
|
-
* @param {PublicEncKeyMlKem512} enc_pk
|
|
575
|
-
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
576
|
-
* @param {boolean} verify
|
|
577
|
-
* @returns {TypedPlaintext[]}
|
|
566
|
+
* @returns {string}
|
|
578
567
|
*/
|
|
579
|
-
module.exports.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
568
|
+
module.exports.get_client_address = function(client) {
|
|
569
|
+
let deferred1_0;
|
|
570
|
+
let deferred1_1;
|
|
571
|
+
try {
|
|
572
|
+
_assertClass(client, Client);
|
|
573
|
+
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
574
|
+
deferred1_0 = ret[0];
|
|
575
|
+
deferred1_1 = ret[1];
|
|
576
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
577
|
+
} finally {
|
|
578
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
586
579
|
}
|
|
587
|
-
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
588
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
589
|
-
return v1;
|
|
590
580
|
};
|
|
591
581
|
|
|
592
582
|
/**
|
|
@@ -619,6 +609,16 @@ module.exports.new_client = function(server_addrs, client_address_hex, fhe_param
|
|
|
619
609
|
return Client.__wrap(ret[0]);
|
|
620
610
|
};
|
|
621
611
|
|
|
612
|
+
/**
|
|
613
|
+
* @param {Client} client
|
|
614
|
+
* @returns {PrivateSigKey | undefined}
|
|
615
|
+
*/
|
|
616
|
+
module.exports.get_client_secret_key = function(client) {
|
|
617
|
+
_assertClass(client, Client);
|
|
618
|
+
const ret = wasm.get_client_secret_key(client.__wbg_ptr);
|
|
619
|
+
return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
|
|
620
|
+
};
|
|
621
|
+
|
|
622
622
|
const CiphertextHandleFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
623
623
|
? { register: () => {}, unregister: () => {} }
|
|
624
624
|
: new FinalizationRegistry(ptr => wasm.__wbg_ciphertexthandle_free(ptr >>> 0, 1));
|
package/kms_lib_bg.wasm
CHANGED
|
Binary file
|