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