tkms 0.13.0-rc.1 → 0.13.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kms_lib.d.ts +57 -57
- package/kms_lib.js +228 -229
- package/kms_lib_bg.wasm +0 -0
- package/package.json +1 -1
package/kms_lib.d.ts
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export function get_client_address(client: Client): string;
|
|
4
|
+
export function ml_kem_pke_sk_len(): number;
|
|
5
|
+
export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Instantiate a new client.
|
|
7
|
+
* Process the user_decryption response from Rust objects.
|
|
8
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
9
|
+
* when using the JS API.
|
|
10
|
+
* The result is a byte array representing a plaintext of any length.
|
|
10
11
|
*
|
|
11
|
-
* * `
|
|
12
|
-
* the elements in the list can be created using [new_server_id_addr].
|
|
12
|
+
* * `client` - client that wants to perform user_decryption.
|
|
13
13
|
*
|
|
14
|
-
* * `
|
|
15
|
-
*
|
|
14
|
+
* * `request` - the initial user_decryption request.
|
|
15
|
+
* Must be given if `verify` is true.
|
|
16
16
|
*
|
|
17
|
-
* * `
|
|
18
|
-
*
|
|
17
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
18
|
+
* Must be given if `verify` is true.
|
|
19
|
+
*
|
|
20
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
21
|
+
*
|
|
22
|
+
* * `enc_pk` - The ephemeral public key.
|
|
23
|
+
*
|
|
24
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
25
|
+
*
|
|
26
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
27
|
+
* It is insecure if `verify = false`!
|
|
19
28
|
*/
|
|
20
|
-
export function
|
|
21
|
-
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
29
|
+
export function process_user_decryption_resp(client: Client, request: ParsedUserDecryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: UserDecryptionResponse[], enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
|
|
22
30
|
export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
|
|
23
|
-
export function
|
|
24
|
-
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
31
|
+
export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
|
|
25
32
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* It's just here for completeness and tests.
|
|
33
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
34
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
29
35
|
*/
|
|
30
|
-
export function
|
|
31
|
-
export function
|
|
32
|
-
export function
|
|
33
|
-
export function ml_kem_pke_pk_len(): number;
|
|
34
|
-
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
36
|
+
export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
|
|
37
|
+
export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
|
|
38
|
+
export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
|
|
35
39
|
/**
|
|
36
40
|
* Process the user_decryption response from JavaScript objects.
|
|
37
41
|
* The returned result is a byte array representing a plaintext of any length,
|
|
@@ -94,42 +98,38 @@ export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
|
94
98
|
* It is insecure if `verify = false`!
|
|
95
99
|
*/
|
|
96
100
|
export function process_user_decryption_resp_from_js(client: Client, request: any, eip712_domain: any, agg_resp: any, enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
|
|
101
|
+
export function ml_kem_pke_pk_len(): number;
|
|
102
|
+
export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
|
|
103
|
+
export function get_server_addrs(client: Client): ServerIdAddr[];
|
|
104
|
+
export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
|
|
105
|
+
export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
|
|
106
|
+
export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
|
|
97
107
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
108
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
109
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
100
110
|
*/
|
|
101
|
-
export function
|
|
102
|
-
export function ml_kem_pke_sk_len(): number;
|
|
103
|
-
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
104
|
-
export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
|
|
105
|
-
export function get_client_address(client: Client): string;
|
|
111
|
+
export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
|
|
106
112
|
/**
|
|
107
|
-
*
|
|
108
|
-
* Consider using [process_user_decryption_resp_from_js]
|
|
109
|
-
* when using the JS API.
|
|
110
|
-
* The result is a byte array representing a plaintext of any length.
|
|
111
|
-
*
|
|
112
|
-
* * `client` - client that wants to perform user_decryption.
|
|
113
|
-
*
|
|
114
|
-
* * `request` - the initial user_decryption request.
|
|
115
|
-
* Must be given if `verify` is true.
|
|
116
|
-
*
|
|
117
|
-
* * `eip712_domain` - the EIP-712 domain.
|
|
118
|
-
* Must be given if `verify` is true.
|
|
119
|
-
*
|
|
120
|
-
* * `agg_resp` - the vector of user_decryption responses.
|
|
113
|
+
* Instantiate a new client.
|
|
121
114
|
*
|
|
122
|
-
* * `
|
|
115
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
116
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
123
117
|
*
|
|
124
|
-
* * `
|
|
118
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
119
|
+
* must be prefixed with "0x".
|
|
125
120
|
*
|
|
126
|
-
* * `
|
|
127
|
-
*
|
|
121
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
122
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
128
123
|
*/
|
|
129
|
-
export function
|
|
130
|
-
export function
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
|
|
125
|
+
export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
|
|
126
|
+
/**
|
|
127
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
128
|
+
* is handled by [process_user_decryption_resp].
|
|
129
|
+
* It's just here for completeness and tests.
|
|
130
|
+
*/
|
|
131
|
+
export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
|
|
132
|
+
export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
|
|
133
133
|
export class CiphertextHandle {
|
|
134
134
|
private constructor();
|
|
135
135
|
free(): void;
|
|
@@ -391,8 +391,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
391
391
|
export interface InitOutput {
|
|
392
392
|
readonly memory: WebAssembly.Memory;
|
|
393
393
|
readonly __wbg_client_free: (a: number, b: number) => void;
|
|
394
|
-
readonly __wbg_ciphertexthandle_free: (a: number, b: number) => void;
|
|
395
|
-
readonly __wbg_parseduserdecryptionrequest_free: (a: number, b: number) => void;
|
|
396
394
|
readonly __wbg_privateenckeymlkem512_free: (a: number, b: number) => void;
|
|
397
395
|
readonly __wbg_publicenckeymlkem512_free: (a: number, b: number) => void;
|
|
398
396
|
readonly __wbg_serveridaddr_free: (a: number, b: number) => void;
|
|
@@ -417,6 +415,8 @@ export interface InitOutput {
|
|
|
417
415
|
readonly u8vec_to_ml_kem_pke_sk: (a: number, b: number) => [number, number, number];
|
|
418
416
|
readonly u8vec_to_private_sig_key: (a: number, b: number) => [number, number, number];
|
|
419
417
|
readonly u8vec_to_public_sig_key: (a: number, b: number) => [number, number, number];
|
|
418
|
+
readonly __wbg_ciphertexthandle_free: (a: number, b: number) => void;
|
|
419
|
+
readonly __wbg_parseduserdecryptionrequest_free: (a: number, b: number) => void;
|
|
420
420
|
readonly __wbg_privatesigkey_free: (a: number, b: number) => void;
|
|
421
421
|
readonly __wbg_publicsigkey_free: (a: number, b: number) => void;
|
|
422
422
|
readonly __wbg_eip712domainmsg_free: (a: number, b: number) => void;
|
|
@@ -466,10 +466,10 @@ export interface InitOutput {
|
|
|
466
466
|
readonly __wbg_userdecryptionrequest_free: (a: number, b: number) => void;
|
|
467
467
|
readonly __wbg_userdecryptionresponse_free: (a: number, b: number) => void;
|
|
468
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
469
|
readonly __wbg_set_typedsigncryptedciphertext_fhe_type: (a: number, b: number) => void;
|
|
472
470
|
readonly __wbg_set_typedsigncryptedciphertext_packing_factor: (a: number, b: number) => void;
|
|
471
|
+
readonly __wbg_get_requestid_request_id: (a: number) => [number, number];
|
|
472
|
+
readonly __wbg_get_userdecryptionrequest_client_address: (a: number) => [number, number];
|
|
473
473
|
readonly __wbg_set_requestid_request_id: (a: number, b: number, c: number) => void;
|
|
474
474
|
readonly __wbg_set_typedciphertext_ciphertext: (a: number, b: number, c: number) => void;
|
|
475
475
|
readonly __wbg_set_typedciphertext_external_handle: (a: number, b: number, c: number) => void;
|
package/kms_lib.js
CHANGED
|
@@ -167,38 +167,60 @@ 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
|
-
|
|
177
170
|
function _assertClass(instance, klass) {
|
|
178
171
|
if (!(instance instanceof klass)) {
|
|
179
172
|
throw new Error(`expected instance of ${klass.name}`);
|
|
180
173
|
}
|
|
181
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* @param {Client} client
|
|
177
|
+
* @returns {string}
|
|
178
|
+
*/
|
|
179
|
+
export function get_client_address(client) {
|
|
180
|
+
let deferred1_0;
|
|
181
|
+
let deferred1_1;
|
|
182
|
+
try {
|
|
183
|
+
_assertClass(client, Client);
|
|
184
|
+
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
185
|
+
deferred1_0 = ret[0];
|
|
186
|
+
deferred1_1 = ret[1];
|
|
187
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
188
|
+
} finally {
|
|
189
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @returns {number}
|
|
195
|
+
*/
|
|
196
|
+
export function ml_kem_pke_sk_len() {
|
|
197
|
+
const ret = wasm.ml_kem_pke_sk_len();
|
|
198
|
+
return ret >>> 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function takeFromExternrefTable0(idx) {
|
|
202
|
+
const value = wasm.__wbindgen_export_4.get(idx);
|
|
203
|
+
wasm.__externref_table_dealloc(idx);
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
182
206
|
|
|
183
207
|
function getArrayU8FromWasm0(ptr, len) {
|
|
184
208
|
ptr = ptr >>> 0;
|
|
185
209
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
186
210
|
}
|
|
187
211
|
/**
|
|
188
|
-
*
|
|
189
|
-
* happens on the KMS side. It's just here for completeness and tests.
|
|
190
|
-
* @param {Uint8Array} msg
|
|
191
|
-
* @param {PublicEncKeyMlKem512} their_pk
|
|
212
|
+
* @param {PrivateEncKeyMlKem512} sk
|
|
192
213
|
* @returns {Uint8Array}
|
|
193
214
|
*/
|
|
194
|
-
export function
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
215
|
+
export function ml_kem_pke_sk_to_u8vec(sk) {
|
|
216
|
+
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
217
|
+
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
218
|
+
if (ret[3]) {
|
|
219
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
220
|
+
}
|
|
221
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
200
222
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
201
|
-
return
|
|
223
|
+
return v1;
|
|
202
224
|
}
|
|
203
225
|
|
|
204
226
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
@@ -211,47 +233,70 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
211
233
|
return ptr;
|
|
212
234
|
}
|
|
213
235
|
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
236
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
237
|
+
ptr = ptr >>> 0;
|
|
238
|
+
const mem = getDataViewMemory0();
|
|
239
|
+
const result = [];
|
|
240
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
241
|
+
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
242
|
+
}
|
|
243
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
244
|
+
return result;
|
|
218
245
|
}
|
|
219
246
|
/**
|
|
220
|
-
*
|
|
247
|
+
* Process the user_decryption response from Rust objects.
|
|
248
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
249
|
+
* when using the JS API.
|
|
250
|
+
* The result is a byte array representing a plaintext of any length.
|
|
221
251
|
*
|
|
222
|
-
* * `
|
|
223
|
-
* the elements in the list can be created using [new_server_id_addr].
|
|
252
|
+
* * `client` - client that wants to perform user_decryption.
|
|
224
253
|
*
|
|
225
|
-
* * `
|
|
226
|
-
*
|
|
254
|
+
* * `request` - the initial user_decryption request.
|
|
255
|
+
* Must be given if `verify` is true.
|
|
227
256
|
*
|
|
228
|
-
* * `
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
257
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
258
|
+
* Must be given if `verify` is true.
|
|
259
|
+
*
|
|
260
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
261
|
+
*
|
|
262
|
+
* * `enc_pk` - The ephemeral public key.
|
|
263
|
+
*
|
|
264
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
265
|
+
*
|
|
266
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
267
|
+
* It is insecure if `verify = false`!
|
|
268
|
+
* @param {Client} client
|
|
269
|
+
* @param {ParsedUserDecryptionRequest | null | undefined} request
|
|
270
|
+
* @param {Eip712DomainMsg | null | undefined} eip712_domain
|
|
271
|
+
* @param {UserDecryptionResponse[]} agg_resp
|
|
272
|
+
* @param {PublicEncKeyMlKem512} enc_pk
|
|
273
|
+
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
274
|
+
* @param {boolean} verify
|
|
275
|
+
* @returns {TypedPlaintext[]}
|
|
234
276
|
*/
|
|
235
|
-
export function
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
277
|
+
export function process_user_decryption_resp(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
278
|
+
_assertClass(client, Client);
|
|
279
|
+
let ptr0 = 0;
|
|
280
|
+
if (!isLikeNone(request)) {
|
|
281
|
+
_assertClass(request, ParsedUserDecryptionRequest);
|
|
282
|
+
ptr0 = request.__destroy_into_raw();
|
|
283
|
+
}
|
|
284
|
+
let ptr1 = 0;
|
|
285
|
+
if (!isLikeNone(eip712_domain)) {
|
|
286
|
+
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
287
|
+
ptr1 = eip712_domain.__destroy_into_raw();
|
|
288
|
+
}
|
|
289
|
+
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
241
290
|
const len2 = WASM_VECTOR_LEN;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
291
|
+
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
292
|
+
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
293
|
+
const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
294
|
+
if (ret[3]) {
|
|
295
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
245
296
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @returns {PrivateEncKeyMlKem512}
|
|
251
|
-
*/
|
|
252
|
-
export function ml_kem_pke_keygen() {
|
|
253
|
-
const ret = wasm.ml_kem_pke_keygen();
|
|
254
|
-
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
297
|
+
var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
298
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
299
|
+
return v4;
|
|
255
300
|
}
|
|
256
301
|
|
|
257
302
|
/**
|
|
@@ -264,105 +309,69 @@ export function ml_kem_pke_get_pk(sk) {
|
|
|
264
309
|
return PublicEncKeyMlKem512.__wrap(ret);
|
|
265
310
|
}
|
|
266
311
|
|
|
312
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
313
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
314
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
315
|
+
WASM_VECTOR_LEN = arg.length;
|
|
316
|
+
return ptr;
|
|
317
|
+
}
|
|
267
318
|
/**
|
|
268
319
|
* @param {Uint8Array} v
|
|
269
|
-
* @returns {
|
|
320
|
+
* @returns {PublicEncKeyMlKem512}
|
|
270
321
|
*/
|
|
271
|
-
export function
|
|
322
|
+
export function u8vec_to_ml_kem_pke_pk(v) {
|
|
272
323
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
273
324
|
const len0 = WASM_VECTOR_LEN;
|
|
274
|
-
const ret = wasm.
|
|
325
|
+
const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
|
|
275
326
|
if (ret[2]) {
|
|
276
327
|
throw takeFromExternrefTable0(ret[1]);
|
|
277
328
|
}
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* @param {PublicSigKey} pk
|
|
283
|
-
* @returns {Uint8Array}
|
|
284
|
-
*/
|
|
285
|
-
export function public_sig_key_to_u8vec(pk) {
|
|
286
|
-
_assertClass(pk, PublicSigKey);
|
|
287
|
-
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
288
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
289
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
290
|
-
return v1;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* This function is *not* used by relayer-sdk because the decryption
|
|
295
|
-
* is handled by [process_user_decryption_resp].
|
|
296
|
-
* It's just here for completeness and tests.
|
|
297
|
-
* @param {Uint8Array} ct
|
|
298
|
-
* @param {PrivateEncKeyMlKem512} my_sk
|
|
299
|
-
* @returns {Uint8Array}
|
|
300
|
-
*/
|
|
301
|
-
export function ml_kem_pke_decrypt(ct, my_sk) {
|
|
302
|
-
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
303
|
-
const len0 = WASM_VECTOR_LEN;
|
|
304
|
-
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
305
|
-
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
306
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
307
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
308
|
-
return v2;
|
|
329
|
+
return PublicEncKeyMlKem512.__wrap(ret[0]);
|
|
309
330
|
}
|
|
310
331
|
|
|
311
332
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
333
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
334
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
335
|
+
* @param {number} id
|
|
336
|
+
* @param {string} addr
|
|
337
|
+
* @returns {ServerIdAddr}
|
|
314
338
|
*/
|
|
315
|
-
export function
|
|
316
|
-
const ptr0 =
|
|
339
|
+
export function new_server_id_addr(id, addr) {
|
|
340
|
+
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
317
341
|
const len0 = WASM_VECTOR_LEN;
|
|
318
|
-
const ret = wasm.
|
|
342
|
+
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
319
343
|
if (ret[2]) {
|
|
320
344
|
throw takeFromExternrefTable0(ret[1]);
|
|
321
345
|
}
|
|
322
|
-
return
|
|
346
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
323
347
|
}
|
|
324
348
|
|
|
325
349
|
/**
|
|
326
350
|
* @param {Uint8Array} v
|
|
327
|
-
* @returns {
|
|
351
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
328
352
|
*/
|
|
329
|
-
export function
|
|
353
|
+
export function u8vec_to_ml_kem_pke_sk(v) {
|
|
330
354
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
331
355
|
const len0 = WASM_VECTOR_LEN;
|
|
332
|
-
const ret = wasm.
|
|
356
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
333
357
|
if (ret[2]) {
|
|
334
358
|
throw takeFromExternrefTable0(ret[1]);
|
|
335
359
|
}
|
|
336
|
-
return
|
|
360
|
+
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
337
361
|
}
|
|
338
362
|
|
|
339
363
|
/**
|
|
340
|
-
* @
|
|
364
|
+
* @param {PublicEncKeyMlKem512} pk
|
|
365
|
+
* @returns {Uint8Array}
|
|
341
366
|
*/
|
|
342
|
-
export function
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
function getArrayJsValueFromWasm0(ptr, len) {
|
|
348
|
-
ptr = ptr >>> 0;
|
|
349
|
-
const mem = getDataViewMemory0();
|
|
350
|
-
const result = [];
|
|
351
|
-
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
352
|
-
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
367
|
+
export function ml_kem_pke_pk_to_u8vec(pk) {
|
|
368
|
+
_assertClass(pk, PublicEncKeyMlKem512);
|
|
369
|
+
const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
|
|
370
|
+
if (ret[3]) {
|
|
371
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
353
372
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* @param {Client} client
|
|
359
|
-
* @returns {ServerIdAddr[]}
|
|
360
|
-
*/
|
|
361
|
-
export function get_server_addrs(client) {
|
|
362
|
-
_assertClass(client, Client);
|
|
363
|
-
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
364
|
-
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
365
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
373
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
374
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
366
375
|
return v1;
|
|
367
376
|
}
|
|
368
377
|
|
|
@@ -449,165 +458,155 @@ export function process_user_decryption_resp_from_js(client, request, eip712_dom
|
|
|
449
458
|
}
|
|
450
459
|
|
|
451
460
|
/**
|
|
452
|
-
*
|
|
453
|
-
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
454
|
-
* @param {number} id
|
|
455
|
-
* @param {string} addr
|
|
456
|
-
* @returns {ServerIdAddr}
|
|
461
|
+
* @returns {number}
|
|
457
462
|
*/
|
|
458
|
-
export function
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
462
|
-
if (ret[2]) {
|
|
463
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
464
|
-
}
|
|
465
|
-
return ServerIdAddr.__wrap(ret[0]);
|
|
463
|
+
export function ml_kem_pke_pk_len() {
|
|
464
|
+
const ret = wasm.ml_kem_pke_pk_len();
|
|
465
|
+
return ret >>> 0;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
/**
|
|
469
|
-
* @
|
|
469
|
+
* @param {Client} client
|
|
470
|
+
* @returns {PrivateSigKey | undefined}
|
|
470
471
|
*/
|
|
471
|
-
export function
|
|
472
|
-
|
|
473
|
-
|
|
472
|
+
export function get_client_secret_key(client) {
|
|
473
|
+
_assertClass(client, Client);
|
|
474
|
+
const ret = wasm.get_client_secret_key(client.__wbg_ptr);
|
|
475
|
+
return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
|
|
474
476
|
}
|
|
475
477
|
|
|
476
478
|
/**
|
|
477
|
-
* @param {
|
|
478
|
-
* @returns {
|
|
479
|
+
* @param {Client} client
|
|
480
|
+
* @returns {ServerIdAddr[]}
|
|
479
481
|
*/
|
|
480
|
-
export function
|
|
481
|
-
_assertClass(
|
|
482
|
-
const ret = wasm.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
487
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
482
|
+
export function get_server_addrs(client) {
|
|
483
|
+
_assertClass(client, Client);
|
|
484
|
+
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
485
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
486
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
488
487
|
return v1;
|
|
489
488
|
}
|
|
490
489
|
|
|
491
490
|
/**
|
|
492
491
|
* @param {Uint8Array} v
|
|
493
|
-
* @returns {
|
|
492
|
+
* @returns {PublicSigKey}
|
|
494
493
|
*/
|
|
495
|
-
export function
|
|
494
|
+
export function u8vec_to_public_sig_key(v) {
|
|
496
495
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
497
496
|
const len0 = WASM_VECTOR_LEN;
|
|
498
|
-
const ret = wasm.
|
|
497
|
+
const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
|
|
499
498
|
if (ret[2]) {
|
|
500
499
|
throw takeFromExternrefTable0(ret[1]);
|
|
501
500
|
}
|
|
502
|
-
return
|
|
501
|
+
return PublicSigKey.__wrap(ret[0]);
|
|
503
502
|
}
|
|
504
503
|
|
|
505
504
|
/**
|
|
506
|
-
* @param {
|
|
507
|
-
* @returns {
|
|
505
|
+
* @param {Uint8Array} v
|
|
506
|
+
* @returns {PrivateSigKey}
|
|
508
507
|
*/
|
|
509
|
-
export function
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
deferred1_0 = ret[0];
|
|
516
|
-
deferred1_1 = ret[1];
|
|
517
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
518
|
-
} finally {
|
|
519
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
508
|
+
export function u8vec_to_private_sig_key(v) {
|
|
509
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
510
|
+
const len0 = WASM_VECTOR_LEN;
|
|
511
|
+
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
512
|
+
if (ret[2]) {
|
|
513
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
520
514
|
}
|
|
515
|
+
return PrivateSigKey.__wrap(ret[0]);
|
|
521
516
|
}
|
|
522
517
|
|
|
523
518
|
/**
|
|
524
|
-
*
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
|
|
519
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
520
|
+
*/
|
|
521
|
+
export function ml_kem_pke_keygen() {
|
|
522
|
+
const ret = wasm.ml_kem_pke_keygen();
|
|
523
|
+
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
528
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
529
|
+
* @param {Uint8Array} msg
|
|
530
|
+
* @param {PublicEncKeyMlKem512} their_pk
|
|
531
|
+
* @returns {Uint8Array}
|
|
532
|
+
*/
|
|
533
|
+
export function ml_kem_pke_encrypt(msg, their_pk) {
|
|
534
|
+
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
535
|
+
const len0 = WASM_VECTOR_LEN;
|
|
536
|
+
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
537
|
+
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
538
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
539
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
540
|
+
return v2;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Instantiate a new client.
|
|
538
545
|
*
|
|
539
|
-
* * `
|
|
546
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
547
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
540
548
|
*
|
|
541
|
-
* * `
|
|
549
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
550
|
+
* must be prefixed with "0x".
|
|
542
551
|
*
|
|
543
|
-
* * `
|
|
544
|
-
*
|
|
545
|
-
* @param {
|
|
546
|
-
* @param {
|
|
547
|
-
* @param {
|
|
548
|
-
* @
|
|
549
|
-
* @param {PublicEncKeyMlKem512} enc_pk
|
|
550
|
-
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
551
|
-
* @param {boolean} verify
|
|
552
|
-
* @returns {TypedPlaintext[]}
|
|
552
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
553
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
554
|
+
* @param {ServerIdAddr[]} server_addrs
|
|
555
|
+
* @param {string} client_address_hex
|
|
556
|
+
* @param {string} fhe_parameter
|
|
557
|
+
* @returns {Client}
|
|
553
558
|
*/
|
|
554
|
-
export function
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
let ptr1 = 0;
|
|
562
|
-
if (!isLikeNone(eip712_domain)) {
|
|
563
|
-
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
564
|
-
ptr1 = eip712_domain.__destroy_into_raw();
|
|
565
|
-
}
|
|
566
|
-
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
559
|
+
export function new_client(server_addrs, client_address_hex, fhe_parameter) {
|
|
560
|
+
const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
|
|
561
|
+
const len0 = WASM_VECTOR_LEN;
|
|
562
|
+
const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
563
|
+
const len1 = WASM_VECTOR_LEN;
|
|
564
|
+
const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
567
565
|
const len2 = WASM_VECTOR_LEN;
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (ret[3]) {
|
|
572
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
566
|
+
const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
567
|
+
if (ret[2]) {
|
|
568
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
573
569
|
}
|
|
574
|
-
|
|
575
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
576
|
-
return v4;
|
|
570
|
+
return Client.__wrap(ret[0]);
|
|
577
571
|
}
|
|
578
572
|
|
|
579
573
|
/**
|
|
580
|
-
* @param {
|
|
581
|
-
* @returns {
|
|
574
|
+
* @param {PublicSigKey} pk
|
|
575
|
+
* @returns {Uint8Array}
|
|
582
576
|
*/
|
|
583
|
-
export function
|
|
584
|
-
_assertClass(
|
|
585
|
-
const ret = wasm.
|
|
586
|
-
|
|
577
|
+
export function public_sig_key_to_u8vec(pk) {
|
|
578
|
+
_assertClass(pk, PublicSigKey);
|
|
579
|
+
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
580
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
581
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
582
|
+
return v1;
|
|
587
583
|
}
|
|
588
584
|
|
|
589
585
|
/**
|
|
590
|
-
*
|
|
586
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
587
|
+
* is handled by [process_user_decryption_resp].
|
|
588
|
+
* It's just here for completeness and tests.
|
|
589
|
+
* @param {Uint8Array} ct
|
|
590
|
+
* @param {PrivateEncKeyMlKem512} my_sk
|
|
591
591
|
* @returns {Uint8Array}
|
|
592
592
|
*/
|
|
593
|
-
export function
|
|
594
|
-
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
593
|
+
export function ml_kem_pke_decrypt(ct, my_sk) {
|
|
594
|
+
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
595
|
+
const len0 = WASM_VECTOR_LEN;
|
|
596
|
+
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
597
|
+
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
598
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
600
599
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
601
|
-
return
|
|
600
|
+
return v2;
|
|
602
601
|
}
|
|
603
602
|
|
|
604
603
|
/**
|
|
605
|
-
* @param {
|
|
604
|
+
* @param {PrivateSigKey} sk
|
|
606
605
|
* @returns {Uint8Array}
|
|
607
606
|
*/
|
|
608
|
-
export function
|
|
609
|
-
_assertClass(sk,
|
|
610
|
-
const ret = wasm.
|
|
607
|
+
export function private_sig_key_to_u8vec(sk) {
|
|
608
|
+
_assertClass(sk, PrivateSigKey);
|
|
609
|
+
const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
|
|
611
610
|
if (ret[3]) {
|
|
612
611
|
throw takeFromExternrefTable0(ret[2]);
|
|
613
612
|
}
|
package/kms_lib_bg.wasm
CHANGED
|
Binary file
|