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