node-tkms 0.12.4 → 0.12.5
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 +48 -48
- package/kms_lib.js +224 -223
- package/kms_lib_bg.wasm +0 -0
- package/package.json +1 -1
package/kms_lib.d.ts
CHANGED
|
@@ -1,49 +1,60 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export function
|
|
4
|
-
export function
|
|
5
|
-
export function
|
|
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
6
|
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
7
7
|
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
8
|
-
export function
|
|
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;
|
|
9
22
|
/**
|
|
10
23
|
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
11
24
|
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
12
25
|
*/
|
|
13
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;
|
|
14
31
|
/**
|
|
15
|
-
*
|
|
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.
|
|
16
36
|
*
|
|
17
|
-
* * `
|
|
18
|
-
* the elements in the list can be created using [new_server_id_addr].
|
|
37
|
+
* * `client` - client that wants to perform user_decryption.
|
|
19
38
|
*
|
|
20
|
-
* * `
|
|
21
|
-
*
|
|
39
|
+
* * `request` - the initial user_decryption request.
|
|
40
|
+
* Must be given if `verify` is true.
|
|
22
41
|
*
|
|
23
|
-
* * `
|
|
24
|
-
*
|
|
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`!
|
|
25
53
|
*/
|
|
26
|
-
export function
|
|
27
|
-
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
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[];
|
|
28
55
|
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
29
|
-
export function get_client_address(client: Client): string;
|
|
30
56
|
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
57
|
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;
|
|
41
|
-
/**
|
|
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
58
|
/**
|
|
48
59
|
* Process the user_decryption response from JavaScript objects.
|
|
49
60
|
* The returned result is a byte array representing a plaintext of any length,
|
|
@@ -107,29 +118,18 @@ export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512)
|
|
|
107
118
|
*/
|
|
108
119
|
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[];
|
|
109
120
|
/**
|
|
110
|
-
*
|
|
111
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
112
|
-
* when using the JS API.
|
|
113
|
-
* The result is a byte array representing a plaintext of any length.
|
|
114
|
-
*
|
|
115
|
-
* * `client` - client that wants to perform user_decryption.
|
|
116
|
-
*
|
|
117
|
-
* * `request` - the initial user_decryption request.
|
|
118
|
-
* Must be given if `verify` is true.
|
|
119
|
-
*
|
|
120
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
121
|
-
* Must be given if `verify` is true.
|
|
122
|
-
*
|
|
123
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
121
|
+
* Instantiate a new client.
|
|
124
122
|
*
|
|
125
|
-
* * `
|
|
123
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
124
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
126
125
|
*
|
|
127
|
-
* * `
|
|
126
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
127
|
+
* must be prefixed with "0x".
|
|
128
128
|
*
|
|
129
|
-
* * `
|
|
130
|
-
*
|
|
129
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
130
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
131
131
|
*/
|
|
132
|
-
export function
|
|
132
|
+
export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
|
|
133
133
|
export class CiphertextHandle {
|
|
134
134
|
private constructor();
|
|
135
135
|
free(): void;
|
package/kms_lib.js
CHANGED
|
@@ -170,21 +170,6 @@ function debugString(val) {
|
|
|
170
170
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
171
171
|
return className;
|
|
172
172
|
}
|
|
173
|
-
/**
|
|
174
|
-
* @returns {number}
|
|
175
|
-
*/
|
|
176
|
-
module.exports.ml_kem_pke_pk_len = function() {
|
|
177
|
-
const ret = wasm.ml_kem_pke_pk_len();
|
|
178
|
-
return ret >>> 0;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @returns {number}
|
|
183
|
-
*/
|
|
184
|
-
module.exports.ml_kem_pke_sk_len = function() {
|
|
185
|
-
const ret = wasm.ml_kem_pke_sk_len();
|
|
186
|
-
return ret >>> 0;
|
|
187
|
-
};
|
|
188
173
|
|
|
189
174
|
function _assertClass(instance, klass) {
|
|
190
175
|
if (!(instance instanceof klass)) {
|
|
@@ -192,34 +177,77 @@ function _assertClass(instance, klass) {
|
|
|
192
177
|
}
|
|
193
178
|
}
|
|
194
179
|
|
|
180
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
181
|
+
ptr = ptr >>> 0;
|
|
182
|
+
const mem = getDataViewMemory0();
|
|
183
|
+
const result = [];
|
|
184
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
185
|
+
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
186
|
+
}
|
|
187
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @param {Client} client
|
|
192
|
+
* @returns {ServerIdAddr[]}
|
|
193
|
+
*/
|
|
194
|
+
module.exports.get_server_addrs = function(client) {
|
|
195
|
+
_assertClass(client, Client);
|
|
196
|
+
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
197
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
198
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
199
|
+
return v1;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
function takeFromExternrefTable0(idx) {
|
|
203
|
+
const value = wasm.__wbindgen_export_4.get(idx);
|
|
204
|
+
wasm.__externref_table_dealloc(idx);
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
|
|
195
208
|
function getArrayU8FromWasm0(ptr, len) {
|
|
196
209
|
ptr = ptr >>> 0;
|
|
197
210
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
198
211
|
}
|
|
199
212
|
/**
|
|
200
|
-
* @param {
|
|
213
|
+
* @param {PrivateEncKeyMlKem512} sk
|
|
201
214
|
* @returns {Uint8Array}
|
|
202
215
|
*/
|
|
203
|
-
module.exports.
|
|
204
|
-
_assertClass(
|
|
205
|
-
const ret = wasm.
|
|
216
|
+
module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
217
|
+
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
218
|
+
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
219
|
+
if (ret[3]) {
|
|
220
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
221
|
+
}
|
|
206
222
|
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
207
223
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
208
224
|
return v1;
|
|
209
225
|
};
|
|
210
226
|
|
|
227
|
+
/**
|
|
228
|
+
* @param {Client} client
|
|
229
|
+
* @returns {string}
|
|
230
|
+
*/
|
|
231
|
+
module.exports.get_client_address = function(client) {
|
|
232
|
+
let deferred1_0;
|
|
233
|
+
let deferred1_1;
|
|
234
|
+
try {
|
|
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
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
211
245
|
function passArray8ToWasm0(arg, malloc) {
|
|
212
246
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
213
247
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
214
248
|
WASM_VECTOR_LEN = arg.length;
|
|
215
249
|
return ptr;
|
|
216
250
|
}
|
|
217
|
-
|
|
218
|
-
function takeFromExternrefTable0(idx) {
|
|
219
|
-
const value = wasm.__wbindgen_export_4.get(idx);
|
|
220
|
-
wasm.__externref_table_dealloc(idx);
|
|
221
|
-
return value;
|
|
222
|
-
}
|
|
223
251
|
/**
|
|
224
252
|
* @param {Uint8Array} v
|
|
225
253
|
* @returns {PublicSigKey}
|
|
@@ -250,131 +278,97 @@ module.exports.private_sig_key_to_u8vec = function(sk) {
|
|
|
250
278
|
};
|
|
251
279
|
|
|
252
280
|
/**
|
|
253
|
-
* @param {
|
|
254
|
-
* @returns {
|
|
281
|
+
* @param {PublicSigKey} pk
|
|
282
|
+
* @returns {Uint8Array}
|
|
255
283
|
*/
|
|
256
|
-
module.exports.
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
return PrivateSigKey.__wrap(ret[0]);
|
|
284
|
+
module.exports.public_sig_key_to_u8vec = function(pk) {
|
|
285
|
+
_assertClass(pk, PublicSigKey);
|
|
286
|
+
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
287
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
288
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
289
|
+
return v1;
|
|
264
290
|
};
|
|
265
291
|
|
|
266
292
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* @param {
|
|
271
|
-
* @
|
|
293
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
294
|
+
* is handled by [process_user_decryption_resp].
|
|
295
|
+
* It's just here for completeness and tests.
|
|
296
|
+
* @param {Uint8Array} ct
|
|
297
|
+
* @param {PrivateEncKeyMlKem512} my_sk
|
|
298
|
+
* @returns {Uint8Array}
|
|
272
299
|
*/
|
|
273
|
-
module.exports.
|
|
274
|
-
const ptr0 =
|
|
300
|
+
module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
301
|
+
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
275
302
|
const len0 = WASM_VECTOR_LEN;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return
|
|
303
|
+
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
304
|
+
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
305
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
306
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
307
|
+
return v2;
|
|
281
308
|
};
|
|
282
309
|
|
|
283
|
-
function passArrayJsValueToWasm0(array, malloc) {
|
|
284
|
-
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
285
|
-
for (let i = 0; i < array.length; i++) {
|
|
286
|
-
const add = addToExternrefTable0(array[i]);
|
|
287
|
-
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
288
|
-
}
|
|
289
|
-
WASM_VECTOR_LEN = array.length;
|
|
290
|
-
return ptr;
|
|
291
|
-
}
|
|
292
310
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
296
|
-
* the elements in the list can be created using [new_server_id_addr].
|
|
297
|
-
*
|
|
298
|
-
* * `client_address_hex` - the client (wallet) address in hex,
|
|
299
|
-
* must be prefixed with "0x".
|
|
300
|
-
*
|
|
301
|
-
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
302
|
-
* The "default" parameter choice is selected if no matching string is found.
|
|
303
|
-
* @param {ServerIdAddr[]} server_addrs
|
|
304
|
-
* @param {string} client_address_hex
|
|
305
|
-
* @param {string} fhe_parameter
|
|
306
|
-
* @returns {Client}
|
|
311
|
+
* @returns {number}
|
|
307
312
|
*/
|
|
308
|
-
module.exports.
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
312
|
-
const len1 = WASM_VECTOR_LEN;
|
|
313
|
-
const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
314
|
-
const len2 = WASM_VECTOR_LEN;
|
|
315
|
-
const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
316
|
-
if (ret[2]) {
|
|
317
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
318
|
-
}
|
|
319
|
-
return Client.__wrap(ret[0]);
|
|
313
|
+
module.exports.ml_kem_pke_sk_len = function() {
|
|
314
|
+
const ret = wasm.ml_kem_pke_sk_len();
|
|
315
|
+
return ret >>> 0;
|
|
320
316
|
};
|
|
321
317
|
|
|
322
|
-
function getArrayJsValueFromWasm0(ptr, len) {
|
|
323
|
-
ptr = ptr >>> 0;
|
|
324
|
-
const mem = getDataViewMemory0();
|
|
325
|
-
const result = [];
|
|
326
|
-
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
327
|
-
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
328
|
-
}
|
|
329
|
-
wasm.__externref_drop_slice(ptr, len);
|
|
330
|
-
return result;
|
|
331
|
-
}
|
|
332
318
|
/**
|
|
333
|
-
* @
|
|
334
|
-
* @returns {ServerIdAddr[]}
|
|
319
|
+
* @returns {number}
|
|
335
320
|
*/
|
|
336
|
-
module.exports.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
340
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
341
|
-
return v1;
|
|
321
|
+
module.exports.ml_kem_pke_pk_len = function() {
|
|
322
|
+
const ret = wasm.ml_kem_pke_pk_len();
|
|
323
|
+
return ret >>> 0;
|
|
342
324
|
};
|
|
343
325
|
|
|
344
326
|
/**
|
|
345
|
-
*
|
|
346
|
-
*
|
|
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}
|
|
347
332
|
*/
|
|
348
|
-
module.exports.
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
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;
|
|
352
341
|
};
|
|
353
342
|
|
|
354
343
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
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}
|
|
357
349
|
*/
|
|
358
|
-
module.exports.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
deferred1_0 = ret[0];
|
|
365
|
-
deferred1_1 = ret[1];
|
|
366
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
367
|
-
} finally {
|
|
368
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
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]);
|
|
369
356
|
}
|
|
357
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
370
358
|
};
|
|
371
359
|
|
|
372
360
|
/**
|
|
361
|
+
* @param {Uint8Array} v
|
|
373
362
|
* @returns {PrivateEncKeyMlKem512}
|
|
374
363
|
*/
|
|
375
|
-
module.exports.
|
|
376
|
-
const
|
|
377
|
-
|
|
364
|
+
module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
|
|
365
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
366
|
+
const len0 = WASM_VECTOR_LEN;
|
|
367
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
368
|
+
if (ret[2]) {
|
|
369
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
370
|
+
}
|
|
371
|
+
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
378
372
|
};
|
|
379
373
|
|
|
380
374
|
/**
|
|
@@ -402,82 +396,115 @@ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
|
|
|
402
396
|
return v1;
|
|
403
397
|
};
|
|
404
398
|
|
|
405
|
-
/**
|
|
406
|
-
* @param {PrivateEncKeyMlKem512} sk
|
|
407
|
-
* @returns {Uint8Array}
|
|
408
|
-
*/
|
|
409
|
-
module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
410
|
-
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
411
|
-
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
412
|
-
if (ret[3]) {
|
|
413
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
414
|
-
}
|
|
415
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
416
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
417
|
-
return v1;
|
|
418
|
-
};
|
|
419
|
-
|
|
420
399
|
/**
|
|
421
400
|
* @param {Uint8Array} v
|
|
422
|
-
* @returns {
|
|
401
|
+
* @returns {PrivateSigKey}
|
|
423
402
|
*/
|
|
424
|
-
module.exports.
|
|
403
|
+
module.exports.u8vec_to_private_sig_key = function(v) {
|
|
425
404
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
426
405
|
const len0 = WASM_VECTOR_LEN;
|
|
427
|
-
const ret = wasm.
|
|
406
|
+
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
428
407
|
if (ret[2]) {
|
|
429
408
|
throw takeFromExternrefTable0(ret[1]);
|
|
430
409
|
}
|
|
431
|
-
return
|
|
410
|
+
return PrivateSigKey.__wrap(ret[0]);
|
|
432
411
|
};
|
|
433
412
|
|
|
413
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
414
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
415
|
+
for (let i = 0; i < array.length; i++) {
|
|
416
|
+
const add = addToExternrefTable0(array[i]);
|
|
417
|
+
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
418
|
+
}
|
|
419
|
+
WASM_VECTOR_LEN = array.length;
|
|
420
|
+
return ptr;
|
|
421
|
+
}
|
|
434
422
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
423
|
+
* Process the user_decryption response from Rust objects.
|
|
424
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
425
|
+
* when using the JS API.
|
|
426
|
+
* The result is a byte array representing a plaintext of any length.
|
|
427
|
+
*
|
|
428
|
+
* * `client` - client that wants to perform user_decryption.
|
|
429
|
+
*
|
|
430
|
+
* * `request` - the initial user_decryption request.
|
|
431
|
+
* Must be given if `verify` is true.
|
|
432
|
+
*
|
|
433
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
434
|
+
* Must be given if `verify` is true.
|
|
435
|
+
*
|
|
436
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
437
|
+
*
|
|
438
|
+
* * `enc_pk` - The ephemeral public key.
|
|
439
|
+
*
|
|
440
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
441
|
+
*
|
|
442
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
443
|
+
* It is insecure if `verify = false`!
|
|
444
|
+
* @param {Client} client
|
|
445
|
+
* @param {ParsedUserDecryptionRequest | null | undefined} request
|
|
446
|
+
* @param {Eip712DomainMsg | null | undefined} eip712_domain
|
|
447
|
+
* @param {UserDecryptionResponse[]} agg_resp
|
|
448
|
+
* @param {PublicEncKeyMlKem512} enc_pk
|
|
449
|
+
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
450
|
+
* @param {boolean} verify
|
|
451
|
+
* @returns {TypedPlaintext[]}
|
|
437
452
|
*/
|
|
438
|
-
module.exports.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
453
|
+
module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
454
|
+
_assertClass(client, Client);
|
|
455
|
+
let ptr0 = 0;
|
|
456
|
+
if (!isLikeNone(request)) {
|
|
457
|
+
_assertClass(request, ParsedUserDecryptionRequest);
|
|
458
|
+
ptr0 = request.__destroy_into_raw();
|
|
444
459
|
}
|
|
445
|
-
|
|
460
|
+
let ptr1 = 0;
|
|
461
|
+
if (!isLikeNone(eip712_domain)) {
|
|
462
|
+
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
463
|
+
ptr1 = eip712_domain.__destroy_into_raw();
|
|
464
|
+
}
|
|
465
|
+
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
466
|
+
const len2 = WASM_VECTOR_LEN;
|
|
467
|
+
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
468
|
+
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
469
|
+
const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
470
|
+
if (ret[3]) {
|
|
471
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
472
|
+
}
|
|
473
|
+
var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
474
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
475
|
+
return v4;
|
|
446
476
|
};
|
|
447
477
|
|
|
448
478
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* @param {Uint8Array} msg
|
|
452
|
-
* @param {PublicEncKeyMlKem512} their_pk
|
|
453
|
-
* @returns {Uint8Array}
|
|
479
|
+
* @param {Client} client
|
|
480
|
+
* @returns {PrivateSigKey | undefined}
|
|
454
481
|
*/
|
|
455
|
-
module.exports.
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
460
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
461
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
462
|
-
return v2;
|
|
482
|
+
module.exports.get_client_secret_key = function(client) {
|
|
483
|
+
_assertClass(client, Client);
|
|
484
|
+
const ret = wasm.get_client_secret_key(client.__wbg_ptr);
|
|
485
|
+
return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
|
|
463
486
|
};
|
|
464
487
|
|
|
465
488
|
/**
|
|
466
|
-
*
|
|
467
|
-
* is handled by [process_user_decryption_resp].
|
|
468
|
-
* It's just here for completeness and tests.
|
|
469
|
-
* @param {Uint8Array} ct
|
|
470
|
-
* @param {PrivateEncKeyMlKem512} my_sk
|
|
471
|
-
* @returns {Uint8Array}
|
|
489
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
472
490
|
*/
|
|
473
|
-
module.exports.
|
|
474
|
-
const
|
|
491
|
+
module.exports.ml_kem_pke_keygen = function() {
|
|
492
|
+
const ret = wasm.ml_kem_pke_keygen();
|
|
493
|
+
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* @param {Uint8Array} v
|
|
498
|
+
* @returns {PublicEncKeyMlKem512}
|
|
499
|
+
*/
|
|
500
|
+
module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
|
|
501
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
475
502
|
const len0 = WASM_VECTOR_LEN;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return
|
|
503
|
+
const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
|
|
504
|
+
if (ret[2]) {
|
|
505
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
506
|
+
}
|
|
507
|
+
return PublicEncKeyMlKem512.__wrap(ret[0]);
|
|
481
508
|
};
|
|
482
509
|
|
|
483
510
|
/**
|
|
@@ -563,59 +590,33 @@ module.exports.process_user_decryption_resp_from_js = function(client, request,
|
|
|
563
590
|
};
|
|
564
591
|
|
|
565
592
|
/**
|
|
566
|
-
*
|
|
567
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
568
|
-
* when using the JS API.
|
|
569
|
-
* The result is a byte array representing a plaintext of any length.
|
|
570
|
-
*
|
|
571
|
-
* * `client` - client that wants to perform user_decryption.
|
|
572
|
-
*
|
|
573
|
-
* * `request` - the initial user_decryption request.
|
|
574
|
-
* Must be given if `verify` is true.
|
|
575
|
-
*
|
|
576
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
577
|
-
* Must be given if `verify` is true.
|
|
578
|
-
*
|
|
579
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
593
|
+
* Instantiate a new client.
|
|
580
594
|
*
|
|
581
|
-
* * `
|
|
595
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
596
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
582
597
|
*
|
|
583
|
-
* * `
|
|
598
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
599
|
+
* must be prefixed with "0x".
|
|
584
600
|
*
|
|
585
|
-
* * `
|
|
586
|
-
*
|
|
587
|
-
* @param {
|
|
588
|
-
* @param {
|
|
589
|
-
* @param {
|
|
590
|
-
* @
|
|
591
|
-
* @param {PublicEncKeyMlKem512} enc_pk
|
|
592
|
-
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
593
|
-
* @param {boolean} verify
|
|
594
|
-
* @returns {TypedPlaintext[]}
|
|
601
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
602
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
603
|
+
* @param {ServerIdAddr[]} server_addrs
|
|
604
|
+
* @param {string} client_address_hex
|
|
605
|
+
* @param {string} fhe_parameter
|
|
606
|
+
* @returns {Client}
|
|
595
607
|
*/
|
|
596
|
-
module.exports.
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
let ptr1 = 0;
|
|
604
|
-
if (!isLikeNone(eip712_domain)) {
|
|
605
|
-
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
606
|
-
ptr1 = eip712_domain.__destroy_into_raw();
|
|
607
|
-
}
|
|
608
|
-
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
608
|
+
module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
|
|
609
|
+
const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
|
|
610
|
+
const len0 = WASM_VECTOR_LEN;
|
|
611
|
+
const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
612
|
+
const len1 = WASM_VECTOR_LEN;
|
|
613
|
+
const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
609
614
|
const len2 = WASM_VECTOR_LEN;
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
if (ret[3]) {
|
|
614
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
615
|
+
const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
616
|
+
if (ret[2]) {
|
|
617
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
615
618
|
}
|
|
616
|
-
|
|
617
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
618
|
-
return v4;
|
|
619
|
+
return Client.__wrap(ret[0]);
|
|
619
620
|
};
|
|
620
621
|
|
|
621
622
|
const CiphertextHandleFinalization = (typeof FinalizationRegistry === 'undefined')
|
package/kms_lib_bg.wasm
CHANGED
|
Binary file
|