node-tkms 0.13.0-rc.0 → 0.13.0-rc.2
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 +43 -43
- package/kms_lib.js +201 -201
- package/kms_lib_bg.wasm +0 -0
- package/package.json +1 -1
package/kms_lib.d.ts
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export function
|
|
3
|
+
export function get_client_address(client: Client): string;
|
|
4
4
|
export function ml_kem_pke_sk_len(): number;
|
|
5
|
+
export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Process the user_decryption response from Rust objects.
|
|
8
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
9
|
+
* when using the JS API.
|
|
10
|
+
* The result is a byte array representing a plaintext of any length.
|
|
11
|
+
*
|
|
12
|
+
* * `client` - client that wants to perform user_decryption.
|
|
13
|
+
*
|
|
14
|
+
* * `request` - the initial user_decryption request.
|
|
15
|
+
* Must be given if `verify` is true.
|
|
16
|
+
*
|
|
17
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
18
|
+
* Must be given if `verify` is true.
|
|
19
|
+
*
|
|
20
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
21
|
+
*
|
|
22
|
+
* * `enc_pk` - The ephemeral public key.
|
|
23
|
+
*
|
|
24
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
25
|
+
*
|
|
26
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
27
|
+
* It is insecure if `verify = false`!
|
|
28
|
+
*/
|
|
29
|
+
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[];
|
|
30
|
+
export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
|
|
5
31
|
export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
34
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
35
|
+
*/
|
|
36
|
+
export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
|
|
37
|
+
export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
|
|
6
38
|
export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
|
|
7
39
|
/**
|
|
8
40
|
* Process the user_decryption response from JavaScript objects.
|
|
@@ -67,45 +99,16 @@ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
|
|
|
67
99
|
*/
|
|
68
100
|
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[];
|
|
69
101
|
export function ml_kem_pke_pk_len(): number;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
76
|
-
export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
|
|
102
|
+
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
103
|
+
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
104
|
+
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
105
|
+
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
106
|
+
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
77
107
|
/**
|
|
78
108
|
* This function is *not* used by relayer-sdk because the encryption
|
|
79
109
|
* happens on the KMS side. It's just here for completeness and tests.
|
|
80
110
|
*/
|
|
81
111
|
export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
|
|
82
|
-
/**
|
|
83
|
-
* Process the user_decryption response from Rust objects.
|
|
84
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
85
|
-
* when using the JS API.
|
|
86
|
-
* The result is a byte array representing a plaintext of any length.
|
|
87
|
-
*
|
|
88
|
-
* * `client` - client that wants to perform user_decryption.
|
|
89
|
-
*
|
|
90
|
-
* * `request` - the initial user_decryption request.
|
|
91
|
-
* Must be given if `verify` is true.
|
|
92
|
-
*
|
|
93
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
94
|
-
* Must be given if `verify` is true.
|
|
95
|
-
*
|
|
96
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
97
|
-
*
|
|
98
|
-
* * `enc_pk` - The ephemeral public key.
|
|
99
|
-
*
|
|
100
|
-
* * `enc_sk` - The ephemeral secret key.
|
|
101
|
-
*
|
|
102
|
-
* * `verify` - Whether to perform signature verification for the response.
|
|
103
|
-
* It is insecure if `verify = false`!
|
|
104
|
-
*/
|
|
105
|
-
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[];
|
|
106
|
-
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
107
|
-
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
108
|
-
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
109
112
|
/**
|
|
110
113
|
* Instantiate a new client.
|
|
111
114
|
*
|
|
@@ -120,16 +123,13 @@ export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
|
120
123
|
*/
|
|
121
124
|
export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
|
|
122
125
|
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
123
|
-
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
124
|
-
export function get_client_address(client: Client): string;
|
|
125
|
-
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
126
|
-
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
127
126
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
127
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
128
|
+
* is handled by [process_user_decryption_resp].
|
|
129
|
+
* It's just here for completeness and tests.
|
|
130
130
|
*/
|
|
131
|
-
export function
|
|
132
|
-
export function
|
|
131
|
+
export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
132
|
+
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
133
133
|
export class CiphertextHandle {
|
|
134
134
|
private constructor();
|
|
135
135
|
free(): void;
|
package/kms_lib.js
CHANGED
|
@@ -176,6 +176,31 @@ function _assertClass(instance, klass) {
|
|
|
176
176
|
throw new Error(`expected instance of ${klass.name}`);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* @param {Client} client
|
|
181
|
+
* @returns {string}
|
|
182
|
+
*/
|
|
183
|
+
module.exports.get_client_address = function(client) {
|
|
184
|
+
let deferred1_0;
|
|
185
|
+
let deferred1_1;
|
|
186
|
+
try {
|
|
187
|
+
_assertClass(client, Client);
|
|
188
|
+
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
189
|
+
deferred1_0 = ret[0];
|
|
190
|
+
deferred1_1 = ret[1];
|
|
191
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
192
|
+
} finally {
|
|
193
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @returns {number}
|
|
199
|
+
*/
|
|
200
|
+
module.exports.ml_kem_pke_sk_len = function() {
|
|
201
|
+
const ret = wasm.ml_kem_pke_sk_len();
|
|
202
|
+
return ret >>> 0;
|
|
203
|
+
};
|
|
179
204
|
|
|
180
205
|
function takeFromExternrefTable0(idx) {
|
|
181
206
|
const value = wasm.__wbindgen_export_4.get(idx);
|
|
@@ -202,12 +227,90 @@ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
|
202
227
|
return v1;
|
|
203
228
|
};
|
|
204
229
|
|
|
230
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
231
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
232
|
+
for (let i = 0; i < array.length; i++) {
|
|
233
|
+
const add = addToExternrefTable0(array[i]);
|
|
234
|
+
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
235
|
+
}
|
|
236
|
+
WASM_VECTOR_LEN = array.length;
|
|
237
|
+
return ptr;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
241
|
+
ptr = ptr >>> 0;
|
|
242
|
+
const mem = getDataViewMemory0();
|
|
243
|
+
const result = [];
|
|
244
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
245
|
+
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
246
|
+
}
|
|
247
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
205
250
|
/**
|
|
206
|
-
*
|
|
251
|
+
* Process the user_decryption response from Rust objects.
|
|
252
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
253
|
+
* when using the JS API.
|
|
254
|
+
* The result is a byte array representing a plaintext of any length.
|
|
255
|
+
*
|
|
256
|
+
* * `client` - client that wants to perform user_decryption.
|
|
257
|
+
*
|
|
258
|
+
* * `request` - the initial user_decryption request.
|
|
259
|
+
* Must be given if `verify` is true.
|
|
260
|
+
*
|
|
261
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
262
|
+
* Must be given if `verify` is true.
|
|
263
|
+
*
|
|
264
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
265
|
+
*
|
|
266
|
+
* * `enc_pk` - The ephemeral public key.
|
|
267
|
+
*
|
|
268
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
269
|
+
*
|
|
270
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
271
|
+
* It is insecure if `verify = false`!
|
|
272
|
+
* @param {Client} client
|
|
273
|
+
* @param {ParsedUserDecryptionRequest | null | undefined} request
|
|
274
|
+
* @param {Eip712DomainMsg | null | undefined} eip712_domain
|
|
275
|
+
* @param {UserDecryptionResponse[]} agg_resp
|
|
276
|
+
* @param {PublicEncKeyMlKem512} enc_pk
|
|
277
|
+
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
278
|
+
* @param {boolean} verify
|
|
279
|
+
* @returns {TypedPlaintext[]}
|
|
207
280
|
*/
|
|
208
|
-
module.exports.
|
|
209
|
-
|
|
210
|
-
|
|
281
|
+
module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
282
|
+
_assertClass(client, Client);
|
|
283
|
+
let ptr0 = 0;
|
|
284
|
+
if (!isLikeNone(request)) {
|
|
285
|
+
_assertClass(request, ParsedUserDecryptionRequest);
|
|
286
|
+
ptr0 = request.__destroy_into_raw();
|
|
287
|
+
}
|
|
288
|
+
let ptr1 = 0;
|
|
289
|
+
if (!isLikeNone(eip712_domain)) {
|
|
290
|
+
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
291
|
+
ptr1 = eip712_domain.__destroy_into_raw();
|
|
292
|
+
}
|
|
293
|
+
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
294
|
+
const len2 = WASM_VECTOR_LEN;
|
|
295
|
+
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
296
|
+
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
297
|
+
const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
298
|
+
if (ret[3]) {
|
|
299
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
300
|
+
}
|
|
301
|
+
var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
302
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
303
|
+
return v4;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @param {PrivateEncKeyMlKem512} sk
|
|
308
|
+
* @returns {PublicEncKeyMlKem512}
|
|
309
|
+
*/
|
|
310
|
+
module.exports.ml_kem_pke_get_pk = function(sk) {
|
|
311
|
+
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
312
|
+
const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
|
|
313
|
+
return PublicEncKeyMlKem512.__wrap(ret);
|
|
211
314
|
};
|
|
212
315
|
|
|
213
316
|
function passArray8ToWasm0(arg, malloc) {
|
|
@@ -230,6 +333,37 @@ module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
|
|
|
230
333
|
return PublicEncKeyMlKem512.__wrap(ret[0]);
|
|
231
334
|
};
|
|
232
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
338
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
339
|
+
* @param {number} id
|
|
340
|
+
* @param {string} addr
|
|
341
|
+
* @returns {ServerIdAddr}
|
|
342
|
+
*/
|
|
343
|
+
module.exports.new_server_id_addr = function(id, addr) {
|
|
344
|
+
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
345
|
+
const len0 = WASM_VECTOR_LEN;
|
|
346
|
+
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
347
|
+
if (ret[2]) {
|
|
348
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
349
|
+
}
|
|
350
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @param {Uint8Array} v
|
|
355
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
356
|
+
*/
|
|
357
|
+
module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
|
|
358
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
359
|
+
const len0 = WASM_VECTOR_LEN;
|
|
360
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
361
|
+
if (ret[2]) {
|
|
362
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
363
|
+
}
|
|
364
|
+
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
365
|
+
};
|
|
366
|
+
|
|
233
367
|
/**
|
|
234
368
|
* @param {PublicEncKeyMlKem512} pk
|
|
235
369
|
* @returns {Uint8Array}
|
|
@@ -245,16 +379,6 @@ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
|
|
|
245
379
|
return v1;
|
|
246
380
|
};
|
|
247
381
|
|
|
248
|
-
function getArrayJsValueFromWasm0(ptr, len) {
|
|
249
|
-
ptr = ptr >>> 0;
|
|
250
|
-
const mem = getDataViewMemory0();
|
|
251
|
-
const result = [];
|
|
252
|
-
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
253
|
-
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
254
|
-
}
|
|
255
|
-
wasm.__externref_drop_slice(ptr, len);
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
382
|
/**
|
|
259
383
|
* Process the user_decryption response from JavaScript objects.
|
|
260
384
|
* The returned result is a byte array representing a plaintext of any length,
|
|
@@ -345,116 +469,6 @@ module.exports.ml_kem_pke_pk_len = function() {
|
|
|
345
469
|
return ret >>> 0;
|
|
346
470
|
};
|
|
347
471
|
|
|
348
|
-
/**
|
|
349
|
-
* This function is *not* used by relayer-sdk because the decryption
|
|
350
|
-
* is handled by [process_user_decryption_resp].
|
|
351
|
-
* It's just here for completeness and tests.
|
|
352
|
-
* @param {Uint8Array} ct
|
|
353
|
-
* @param {PrivateEncKeyMlKem512} my_sk
|
|
354
|
-
* @returns {Uint8Array}
|
|
355
|
-
*/
|
|
356
|
-
module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
357
|
-
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
358
|
-
const len0 = WASM_VECTOR_LEN;
|
|
359
|
-
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
360
|
-
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
361
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
362
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
363
|
-
return v2;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* @param {PrivateEncKeyMlKem512} sk
|
|
368
|
-
* @returns {PublicEncKeyMlKem512}
|
|
369
|
-
*/
|
|
370
|
-
module.exports.ml_kem_pke_get_pk = function(sk) {
|
|
371
|
-
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
372
|
-
const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
|
|
373
|
-
return PublicEncKeyMlKem512.__wrap(ret);
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* This function is *not* used by relayer-sdk because the encryption
|
|
378
|
-
* happens on the KMS side. It's just here for completeness and tests.
|
|
379
|
-
* @param {Uint8Array} msg
|
|
380
|
-
* @param {PublicEncKeyMlKem512} their_pk
|
|
381
|
-
* @returns {Uint8Array}
|
|
382
|
-
*/
|
|
383
|
-
module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
|
|
384
|
-
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
385
|
-
const len0 = WASM_VECTOR_LEN;
|
|
386
|
-
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
387
|
-
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
388
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
389
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
390
|
-
return v2;
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
function passArrayJsValueToWasm0(array, malloc) {
|
|
394
|
-
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
395
|
-
for (let i = 0; i < array.length; i++) {
|
|
396
|
-
const add = addToExternrefTable0(array[i]);
|
|
397
|
-
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
398
|
-
}
|
|
399
|
-
WASM_VECTOR_LEN = array.length;
|
|
400
|
-
return ptr;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Process the user_decryption response from Rust objects.
|
|
404
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
405
|
-
* when using the JS API.
|
|
406
|
-
* The result is a byte array representing a plaintext of any length.
|
|
407
|
-
*
|
|
408
|
-
* * `client` - client that wants to perform user_decryption.
|
|
409
|
-
*
|
|
410
|
-
* * `request` - the initial user_decryption request.
|
|
411
|
-
* Must be given if `verify` is true.
|
|
412
|
-
*
|
|
413
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
414
|
-
* Must be given if `verify` is true.
|
|
415
|
-
*
|
|
416
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
417
|
-
*
|
|
418
|
-
* * `enc_pk` - The ephemeral public key.
|
|
419
|
-
*
|
|
420
|
-
* * `enc_sk` - The ephemeral secret key.
|
|
421
|
-
*
|
|
422
|
-
* * `verify` - Whether to perform signature verification for the response.
|
|
423
|
-
* It is insecure if `verify = false`!
|
|
424
|
-
* @param {Client} client
|
|
425
|
-
* @param {ParsedUserDecryptionRequest | null | undefined} request
|
|
426
|
-
* @param {Eip712DomainMsg | null | undefined} eip712_domain
|
|
427
|
-
* @param {UserDecryptionResponse[]} agg_resp
|
|
428
|
-
* @param {PublicEncKeyMlKem512} enc_pk
|
|
429
|
-
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
430
|
-
* @param {boolean} verify
|
|
431
|
-
* @returns {TypedPlaintext[]}
|
|
432
|
-
*/
|
|
433
|
-
module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
434
|
-
_assertClass(client, Client);
|
|
435
|
-
let ptr0 = 0;
|
|
436
|
-
if (!isLikeNone(request)) {
|
|
437
|
-
_assertClass(request, ParsedUserDecryptionRequest);
|
|
438
|
-
ptr0 = request.__destroy_into_raw();
|
|
439
|
-
}
|
|
440
|
-
let ptr1 = 0;
|
|
441
|
-
if (!isLikeNone(eip712_domain)) {
|
|
442
|
-
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
443
|
-
ptr1 = eip712_domain.__destroy_into_raw();
|
|
444
|
-
}
|
|
445
|
-
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
446
|
-
const len2 = WASM_VECTOR_LEN;
|
|
447
|
-
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
448
|
-
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
449
|
-
const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
450
|
-
if (ret[3]) {
|
|
451
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
452
|
-
}
|
|
453
|
-
var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
454
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
455
|
-
return v4;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
472
|
/**
|
|
459
473
|
* @param {Client} client
|
|
460
474
|
* @returns {PrivateSigKey | undefined}
|
|
@@ -477,6 +491,34 @@ module.exports.get_server_addrs = function(client) {
|
|
|
477
491
|
return v1;
|
|
478
492
|
};
|
|
479
493
|
|
|
494
|
+
/**
|
|
495
|
+
* @param {Uint8Array} v
|
|
496
|
+
* @returns {PublicSigKey}
|
|
497
|
+
*/
|
|
498
|
+
module.exports.u8vec_to_public_sig_key = function(v) {
|
|
499
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
500
|
+
const len0 = WASM_VECTOR_LEN;
|
|
501
|
+
const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
|
|
502
|
+
if (ret[2]) {
|
|
503
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
504
|
+
}
|
|
505
|
+
return PublicSigKey.__wrap(ret[0]);
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* @param {Uint8Array} v
|
|
510
|
+
* @returns {PrivateSigKey}
|
|
511
|
+
*/
|
|
512
|
+
module.exports.u8vec_to_private_sig_key = function(v) {
|
|
513
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
514
|
+
const len0 = WASM_VECTOR_LEN;
|
|
515
|
+
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
516
|
+
if (ret[2]) {
|
|
517
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
518
|
+
}
|
|
519
|
+
return PrivateSigKey.__wrap(ret[0]);
|
|
520
|
+
};
|
|
521
|
+
|
|
480
522
|
/**
|
|
481
523
|
* @returns {PrivateEncKeyMlKem512}
|
|
482
524
|
*/
|
|
@@ -485,6 +527,23 @@ module.exports.ml_kem_pke_keygen = function() {
|
|
|
485
527
|
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
486
528
|
};
|
|
487
529
|
|
|
530
|
+
/**
|
|
531
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
532
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
533
|
+
* @param {Uint8Array} msg
|
|
534
|
+
* @param {PublicEncKeyMlKem512} their_pk
|
|
535
|
+
* @returns {Uint8Array}
|
|
536
|
+
*/
|
|
537
|
+
module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
|
|
538
|
+
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
539
|
+
const len0 = WASM_VECTOR_LEN;
|
|
540
|
+
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
541
|
+
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
542
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
543
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
544
|
+
return v2;
|
|
545
|
+
};
|
|
546
|
+
|
|
488
547
|
/**
|
|
489
548
|
* Instantiate a new client.
|
|
490
549
|
*
|
|
@@ -527,6 +586,24 @@ module.exports.public_sig_key_to_u8vec = function(pk) {
|
|
|
527
586
|
return v1;
|
|
528
587
|
};
|
|
529
588
|
|
|
589
|
+
/**
|
|
590
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
591
|
+
* is handled by [process_user_decryption_resp].
|
|
592
|
+
* It's just here for completeness and tests.
|
|
593
|
+
* @param {Uint8Array} ct
|
|
594
|
+
* @param {PrivateEncKeyMlKem512} my_sk
|
|
595
|
+
* @returns {Uint8Array}
|
|
596
|
+
*/
|
|
597
|
+
module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
598
|
+
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
599
|
+
const len0 = WASM_VECTOR_LEN;
|
|
600
|
+
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
601
|
+
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
602
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
603
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
604
|
+
return v2;
|
|
605
|
+
};
|
|
606
|
+
|
|
530
607
|
/**
|
|
531
608
|
* @param {PrivateSigKey} sk
|
|
532
609
|
* @returns {Uint8Array}
|
|
@@ -542,83 +619,6 @@ module.exports.private_sig_key_to_u8vec = function(sk) {
|
|
|
542
619
|
return v1;
|
|
543
620
|
};
|
|
544
621
|
|
|
545
|
-
/**
|
|
546
|
-
* @param {Client} client
|
|
547
|
-
* @returns {string}
|
|
548
|
-
*/
|
|
549
|
-
module.exports.get_client_address = function(client) {
|
|
550
|
-
let deferred1_0;
|
|
551
|
-
let deferred1_1;
|
|
552
|
-
try {
|
|
553
|
-
_assertClass(client, Client);
|
|
554
|
-
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
555
|
-
deferred1_0 = ret[0];
|
|
556
|
-
deferred1_1 = ret[1];
|
|
557
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
558
|
-
} finally {
|
|
559
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* @param {Uint8Array} v
|
|
565
|
-
* @returns {PublicSigKey}
|
|
566
|
-
*/
|
|
567
|
-
module.exports.u8vec_to_public_sig_key = function(v) {
|
|
568
|
-
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
569
|
-
const len0 = WASM_VECTOR_LEN;
|
|
570
|
-
const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
|
|
571
|
-
if (ret[2]) {
|
|
572
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
573
|
-
}
|
|
574
|
-
return PublicSigKey.__wrap(ret[0]);
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* @param {Uint8Array} v
|
|
579
|
-
* @returns {PrivateSigKey}
|
|
580
|
-
*/
|
|
581
|
-
module.exports.u8vec_to_private_sig_key = function(v) {
|
|
582
|
-
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
583
|
-
const len0 = WASM_VECTOR_LEN;
|
|
584
|
-
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
585
|
-
if (ret[2]) {
|
|
586
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
587
|
-
}
|
|
588
|
-
return PrivateSigKey.__wrap(ret[0]);
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
593
|
-
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
594
|
-
* @param {number} id
|
|
595
|
-
* @param {string} addr
|
|
596
|
-
* @returns {ServerIdAddr}
|
|
597
|
-
*/
|
|
598
|
-
module.exports.new_server_id_addr = function(id, addr) {
|
|
599
|
-
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
600
|
-
const len0 = WASM_VECTOR_LEN;
|
|
601
|
-
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
602
|
-
if (ret[2]) {
|
|
603
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
604
|
-
}
|
|
605
|
-
return ServerIdAddr.__wrap(ret[0]);
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* @param {Uint8Array} v
|
|
610
|
-
* @returns {PrivateEncKeyMlKem512}
|
|
611
|
-
*/
|
|
612
|
-
module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
|
|
613
|
-
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
614
|
-
const len0 = WASM_VECTOR_LEN;
|
|
615
|
-
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
616
|
-
if (ret[2]) {
|
|
617
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
618
|
-
}
|
|
619
|
-
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
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
|