node-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 +53 -53
- 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;
|
package/kms_lib.js
CHANGED
|
@@ -171,38 +171,60 @@ 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
|
-
|
|
181
174
|
function _assertClass(instance, klass) {
|
|
182
175
|
if (!(instance instanceof klass)) {
|
|
183
176
|
throw new Error(`expected instance of ${klass.name}`);
|
|
184
177
|
}
|
|
185
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* @param {Client} client
|
|
181
|
+
* @returns {string}
|
|
182
|
+
*/
|
|
183
|
+
module.exports.get_client_address = function(client) {
|
|
184
|
+
let deferred1_0;
|
|
185
|
+
let deferred1_1;
|
|
186
|
+
try {
|
|
187
|
+
_assertClass(client, Client);
|
|
188
|
+
const ret = wasm.get_client_address(client.__wbg_ptr);
|
|
189
|
+
deferred1_0 = ret[0];
|
|
190
|
+
deferred1_1 = ret[1];
|
|
191
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
192
|
+
} finally {
|
|
193
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @returns {number}
|
|
199
|
+
*/
|
|
200
|
+
module.exports.ml_kem_pke_sk_len = function() {
|
|
201
|
+
const ret = wasm.ml_kem_pke_sk_len();
|
|
202
|
+
return ret >>> 0;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
function takeFromExternrefTable0(idx) {
|
|
206
|
+
const value = wasm.__wbindgen_export_4.get(idx);
|
|
207
|
+
wasm.__externref_table_dealloc(idx);
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
186
210
|
|
|
187
211
|
function getArrayU8FromWasm0(ptr, len) {
|
|
188
212
|
ptr = ptr >>> 0;
|
|
189
213
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
190
214
|
}
|
|
191
215
|
/**
|
|
192
|
-
*
|
|
193
|
-
* happens on the KMS side. It's just here for completeness and tests.
|
|
194
|
-
* @param {Uint8Array} msg
|
|
195
|
-
* @param {PublicEncKeyMlKem512} their_pk
|
|
216
|
+
* @param {PrivateEncKeyMlKem512} sk
|
|
196
217
|
* @returns {Uint8Array}
|
|
197
218
|
*/
|
|
198
|
-
module.exports.
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
219
|
+
module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
|
|
220
|
+
_assertClass(sk, PrivateEncKeyMlKem512);
|
|
221
|
+
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
222
|
+
if (ret[3]) {
|
|
223
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
224
|
+
}
|
|
225
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
204
226
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
205
|
-
return
|
|
227
|
+
return v1;
|
|
206
228
|
};
|
|
207
229
|
|
|
208
230
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
@@ -215,47 +237,70 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
215
237
|
return ptr;
|
|
216
238
|
}
|
|
217
239
|
|
|
218
|
-
function
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
240
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
241
|
+
ptr = ptr >>> 0;
|
|
242
|
+
const mem = getDataViewMemory0();
|
|
243
|
+
const result = [];
|
|
244
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
245
|
+
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
246
|
+
}
|
|
247
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
248
|
+
return result;
|
|
222
249
|
}
|
|
223
250
|
/**
|
|
224
|
-
*
|
|
251
|
+
* Process the user_decryption response from Rust objects.
|
|
252
|
+
* Consider using [process_user_decryption_resp_from_js]
|
|
253
|
+
* when using the JS API.
|
|
254
|
+
* The result is a byte array representing a plaintext of any length.
|
|
225
255
|
*
|
|
226
|
-
* * `
|
|
227
|
-
* the elements in the list can be created using [new_server_id_addr].
|
|
256
|
+
* * `client` - client that wants to perform user_decryption.
|
|
228
257
|
*
|
|
229
|
-
* * `
|
|
230
|
-
*
|
|
258
|
+
* * `request` - the initial user_decryption request.
|
|
259
|
+
* Must be given if `verify` is true.
|
|
231
260
|
*
|
|
232
|
-
* * `
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
261
|
+
* * `eip712_domain` - the EIP-712 domain.
|
|
262
|
+
* Must be given if `verify` is true.
|
|
263
|
+
*
|
|
264
|
+
* * `agg_resp` - the vector of user_decryption responses.
|
|
265
|
+
*
|
|
266
|
+
* * `enc_pk` - The ephemeral public key.
|
|
267
|
+
*
|
|
268
|
+
* * `enc_sk` - The ephemeral secret key.
|
|
269
|
+
*
|
|
270
|
+
* * `verify` - Whether to perform signature verification for the response.
|
|
271
|
+
* It is insecure if `verify = false`!
|
|
272
|
+
* @param {Client} client
|
|
273
|
+
* @param {ParsedUserDecryptionRequest | null | undefined} request
|
|
274
|
+
* @param {Eip712DomainMsg | null | undefined} eip712_domain
|
|
275
|
+
* @param {UserDecryptionResponse[]} agg_resp
|
|
276
|
+
* @param {PublicEncKeyMlKem512} enc_pk
|
|
277
|
+
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
278
|
+
* @param {boolean} verify
|
|
279
|
+
* @returns {TypedPlaintext[]}
|
|
238
280
|
*/
|
|
239
|
-
module.exports.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
281
|
+
module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
|
|
282
|
+
_assertClass(client, Client);
|
|
283
|
+
let ptr0 = 0;
|
|
284
|
+
if (!isLikeNone(request)) {
|
|
285
|
+
_assertClass(request, ParsedUserDecryptionRequest);
|
|
286
|
+
ptr0 = request.__destroy_into_raw();
|
|
287
|
+
}
|
|
288
|
+
let ptr1 = 0;
|
|
289
|
+
if (!isLikeNone(eip712_domain)) {
|
|
290
|
+
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
291
|
+
ptr1 = eip712_domain.__destroy_into_raw();
|
|
292
|
+
}
|
|
293
|
+
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
245
294
|
const len2 = WASM_VECTOR_LEN;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
295
|
+
_assertClass(enc_pk, PublicEncKeyMlKem512);
|
|
296
|
+
_assertClass(enc_sk, PrivateEncKeyMlKem512);
|
|
297
|
+
const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
|
|
298
|
+
if (ret[3]) {
|
|
299
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
249
300
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* @returns {PrivateEncKeyMlKem512}
|
|
255
|
-
*/
|
|
256
|
-
module.exports.ml_kem_pke_keygen = function() {
|
|
257
|
-
const ret = wasm.ml_kem_pke_keygen();
|
|
258
|
-
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
301
|
+
var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
302
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
303
|
+
return v4;
|
|
259
304
|
};
|
|
260
305
|
|
|
261
306
|
/**
|
|
@@ -268,105 +313,69 @@ module.exports.ml_kem_pke_get_pk = function(sk) {
|
|
|
268
313
|
return PublicEncKeyMlKem512.__wrap(ret);
|
|
269
314
|
};
|
|
270
315
|
|
|
316
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
317
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
318
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
319
|
+
WASM_VECTOR_LEN = arg.length;
|
|
320
|
+
return ptr;
|
|
321
|
+
}
|
|
271
322
|
/**
|
|
272
323
|
* @param {Uint8Array} v
|
|
273
|
-
* @returns {
|
|
324
|
+
* @returns {PublicEncKeyMlKem512}
|
|
274
325
|
*/
|
|
275
|
-
module.exports.
|
|
326
|
+
module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
|
|
276
327
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
277
328
|
const len0 = WASM_VECTOR_LEN;
|
|
278
|
-
const ret = wasm.
|
|
329
|
+
const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
|
|
279
330
|
if (ret[2]) {
|
|
280
331
|
throw takeFromExternrefTable0(ret[1]);
|
|
281
332
|
}
|
|
282
|
-
return
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* @param {PublicSigKey} pk
|
|
287
|
-
* @returns {Uint8Array}
|
|
288
|
-
*/
|
|
289
|
-
module.exports.public_sig_key_to_u8vec = function(pk) {
|
|
290
|
-
_assertClass(pk, PublicSigKey);
|
|
291
|
-
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
292
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
293
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
294
|
-
return v1;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* This function is *not* used by relayer-sdk because the decryption
|
|
299
|
-
* is handled by [process_user_decryption_resp].
|
|
300
|
-
* It's just here for completeness and tests.
|
|
301
|
-
* @param {Uint8Array} ct
|
|
302
|
-
* @param {PrivateEncKeyMlKem512} my_sk
|
|
303
|
-
* @returns {Uint8Array}
|
|
304
|
-
*/
|
|
305
|
-
module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
306
|
-
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
307
|
-
const len0 = WASM_VECTOR_LEN;
|
|
308
|
-
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
309
|
-
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
310
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
311
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
312
|
-
return v2;
|
|
333
|
+
return PublicEncKeyMlKem512.__wrap(ret[0]);
|
|
313
334
|
};
|
|
314
335
|
|
|
315
336
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
337
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
338
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
339
|
+
* @param {number} id
|
|
340
|
+
* @param {string} addr
|
|
341
|
+
* @returns {ServerIdAddr}
|
|
318
342
|
*/
|
|
319
|
-
module.exports.
|
|
320
|
-
const ptr0 =
|
|
343
|
+
module.exports.new_server_id_addr = function(id, addr) {
|
|
344
|
+
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
321
345
|
const len0 = WASM_VECTOR_LEN;
|
|
322
|
-
const ret = wasm.
|
|
346
|
+
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
323
347
|
if (ret[2]) {
|
|
324
348
|
throw takeFromExternrefTable0(ret[1]);
|
|
325
349
|
}
|
|
326
|
-
return
|
|
350
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
327
351
|
};
|
|
328
352
|
|
|
329
353
|
/**
|
|
330
354
|
* @param {Uint8Array} v
|
|
331
|
-
* @returns {
|
|
355
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
332
356
|
*/
|
|
333
|
-
module.exports.
|
|
357
|
+
module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
|
|
334
358
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
335
359
|
const len0 = WASM_VECTOR_LEN;
|
|
336
|
-
const ret = wasm.
|
|
360
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
337
361
|
if (ret[2]) {
|
|
338
362
|
throw takeFromExternrefTable0(ret[1]);
|
|
339
363
|
}
|
|
340
|
-
return
|
|
364
|
+
return PrivateEncKeyMlKem512.__wrap(ret[0]);
|
|
341
365
|
};
|
|
342
366
|
|
|
343
367
|
/**
|
|
344
|
-
* @
|
|
368
|
+
* @param {PublicEncKeyMlKem512} pk
|
|
369
|
+
* @returns {Uint8Array}
|
|
345
370
|
*/
|
|
346
|
-
module.exports.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
function getArrayJsValueFromWasm0(ptr, len) {
|
|
352
|
-
ptr = ptr >>> 0;
|
|
353
|
-
const mem = getDataViewMemory0();
|
|
354
|
-
const result = [];
|
|
355
|
-
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
356
|
-
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
371
|
+
module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
|
|
372
|
+
_assertClass(pk, PublicEncKeyMlKem512);
|
|
373
|
+
const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
|
|
374
|
+
if (ret[3]) {
|
|
375
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
357
376
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* @param {Client} client
|
|
363
|
-
* @returns {ServerIdAddr[]}
|
|
364
|
-
*/
|
|
365
|
-
module.exports.get_server_addrs = function(client) {
|
|
366
|
-
_assertClass(client, Client);
|
|
367
|
-
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
368
|
-
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
369
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
377
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
378
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
370
379
|
return v1;
|
|
371
380
|
};
|
|
372
381
|
|
|
@@ -453,165 +462,155 @@ module.exports.process_user_decryption_resp_from_js = function(client, request,
|
|
|
453
462
|
};
|
|
454
463
|
|
|
455
464
|
/**
|
|
456
|
-
*
|
|
457
|
-
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
458
|
-
* @param {number} id
|
|
459
|
-
* @param {string} addr
|
|
460
|
-
* @returns {ServerIdAddr}
|
|
465
|
+
* @returns {number}
|
|
461
466
|
*/
|
|
462
|
-
module.exports.
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
466
|
-
if (ret[2]) {
|
|
467
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
468
|
-
}
|
|
469
|
-
return ServerIdAddr.__wrap(ret[0]);
|
|
467
|
+
module.exports.ml_kem_pke_pk_len = function() {
|
|
468
|
+
const ret = wasm.ml_kem_pke_pk_len();
|
|
469
|
+
return ret >>> 0;
|
|
470
470
|
};
|
|
471
471
|
|
|
472
472
|
/**
|
|
473
|
-
* @
|
|
473
|
+
* @param {Client} client
|
|
474
|
+
* @returns {PrivateSigKey | undefined}
|
|
474
475
|
*/
|
|
475
|
-
module.exports.
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
module.exports.get_client_secret_key = function(client) {
|
|
477
|
+
_assertClass(client, Client);
|
|
478
|
+
const ret = wasm.get_client_secret_key(client.__wbg_ptr);
|
|
479
|
+
return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
|
|
478
480
|
};
|
|
479
481
|
|
|
480
482
|
/**
|
|
481
|
-
* @param {
|
|
482
|
-
* @returns {
|
|
483
|
+
* @param {Client} client
|
|
484
|
+
* @returns {ServerIdAddr[]}
|
|
483
485
|
*/
|
|
484
|
-
module.exports.
|
|
485
|
-
_assertClass(
|
|
486
|
-
const ret = wasm.
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
491
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
486
|
+
module.exports.get_server_addrs = function(client) {
|
|
487
|
+
_assertClass(client, Client);
|
|
488
|
+
const ret = wasm.get_server_addrs(client.__wbg_ptr);
|
|
489
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
490
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
492
491
|
return v1;
|
|
493
492
|
};
|
|
494
493
|
|
|
495
494
|
/**
|
|
496
495
|
* @param {Uint8Array} v
|
|
497
|
-
* @returns {
|
|
496
|
+
* @returns {PublicSigKey}
|
|
498
497
|
*/
|
|
499
|
-
module.exports.
|
|
498
|
+
module.exports.u8vec_to_public_sig_key = function(v) {
|
|
500
499
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
501
500
|
const len0 = WASM_VECTOR_LEN;
|
|
502
|
-
const ret = wasm.
|
|
501
|
+
const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
|
|
503
502
|
if (ret[2]) {
|
|
504
503
|
throw takeFromExternrefTable0(ret[1]);
|
|
505
504
|
}
|
|
506
|
-
return
|
|
505
|
+
return PublicSigKey.__wrap(ret[0]);
|
|
507
506
|
};
|
|
508
507
|
|
|
509
508
|
/**
|
|
510
|
-
* @param {
|
|
511
|
-
* @returns {
|
|
509
|
+
* @param {Uint8Array} v
|
|
510
|
+
* @returns {PrivateSigKey}
|
|
512
511
|
*/
|
|
513
|
-
module.exports.
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
deferred1_0 = ret[0];
|
|
520
|
-
deferred1_1 = ret[1];
|
|
521
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
522
|
-
} finally {
|
|
523
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
512
|
+
module.exports.u8vec_to_private_sig_key = function(v) {
|
|
513
|
+
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
514
|
+
const len0 = WASM_VECTOR_LEN;
|
|
515
|
+
const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
|
|
516
|
+
if (ret[2]) {
|
|
517
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
524
518
|
}
|
|
519
|
+
return PrivateSigKey.__wrap(ret[0]);
|
|
525
520
|
};
|
|
526
521
|
|
|
527
522
|
/**
|
|
528
|
-
*
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
|
|
523
|
+
* @returns {PrivateEncKeyMlKem512}
|
|
524
|
+
*/
|
|
525
|
+
module.exports.ml_kem_pke_keygen = function() {
|
|
526
|
+
const ret = wasm.ml_kem_pke_keygen();
|
|
527
|
+
return PrivateEncKeyMlKem512.__wrap(ret);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* This function is *not* used by relayer-sdk because the encryption
|
|
532
|
+
* happens on the KMS side. It's just here for completeness and tests.
|
|
533
|
+
* @param {Uint8Array} msg
|
|
534
|
+
* @param {PublicEncKeyMlKem512} their_pk
|
|
535
|
+
* @returns {Uint8Array}
|
|
536
|
+
*/
|
|
537
|
+
module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
|
|
538
|
+
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
539
|
+
const len0 = WASM_VECTOR_LEN;
|
|
540
|
+
_assertClass(their_pk, PublicEncKeyMlKem512);
|
|
541
|
+
const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
|
|
542
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
543
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
544
|
+
return v2;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Instantiate a new client.
|
|
542
549
|
*
|
|
543
|
-
* * `
|
|
550
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
551
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
544
552
|
*
|
|
545
|
-
* * `
|
|
553
|
+
* * `client_address_hex` - the client (wallet) address in hex,
|
|
554
|
+
* must be prefixed with "0x".
|
|
546
555
|
*
|
|
547
|
-
* * `
|
|
548
|
-
*
|
|
549
|
-
* @param {
|
|
550
|
-
* @param {
|
|
551
|
-
* @param {
|
|
552
|
-
* @
|
|
553
|
-
* @param {PublicEncKeyMlKem512} enc_pk
|
|
554
|
-
* @param {PrivateEncKeyMlKem512} enc_sk
|
|
555
|
-
* @param {boolean} verify
|
|
556
|
-
* @returns {TypedPlaintext[]}
|
|
556
|
+
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
557
|
+
* The "default" parameter choice is selected if no matching string is found.
|
|
558
|
+
* @param {ServerIdAddr[]} server_addrs
|
|
559
|
+
* @param {string} client_address_hex
|
|
560
|
+
* @param {string} fhe_parameter
|
|
561
|
+
* @returns {Client}
|
|
557
562
|
*/
|
|
558
|
-
module.exports.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
let ptr1 = 0;
|
|
566
|
-
if (!isLikeNone(eip712_domain)) {
|
|
567
|
-
_assertClass(eip712_domain, Eip712DomainMsg);
|
|
568
|
-
ptr1 = eip712_domain.__destroy_into_raw();
|
|
569
|
-
}
|
|
570
|
-
const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
|
|
563
|
+
module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
|
|
564
|
+
const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
|
|
565
|
+
const len0 = WASM_VECTOR_LEN;
|
|
566
|
+
const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
567
|
+
const len1 = WASM_VECTOR_LEN;
|
|
568
|
+
const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
571
569
|
const len2 = WASM_VECTOR_LEN;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (ret[3]) {
|
|
576
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
570
|
+
const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
571
|
+
if (ret[2]) {
|
|
572
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
577
573
|
}
|
|
578
|
-
|
|
579
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
580
|
-
return v4;
|
|
574
|
+
return Client.__wrap(ret[0]);
|
|
581
575
|
};
|
|
582
576
|
|
|
583
577
|
/**
|
|
584
|
-
* @param {
|
|
585
|
-
* @returns {
|
|
578
|
+
* @param {PublicSigKey} pk
|
|
579
|
+
* @returns {Uint8Array}
|
|
586
580
|
*/
|
|
587
|
-
module.exports.
|
|
588
|
-
_assertClass(
|
|
589
|
-
const ret = wasm.
|
|
590
|
-
|
|
581
|
+
module.exports.public_sig_key_to_u8vec = function(pk) {
|
|
582
|
+
_assertClass(pk, PublicSigKey);
|
|
583
|
+
const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
|
|
584
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
585
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
586
|
+
return v1;
|
|
591
587
|
};
|
|
592
588
|
|
|
593
589
|
/**
|
|
594
|
-
*
|
|
590
|
+
* This function is *not* used by relayer-sdk because the decryption
|
|
591
|
+
* is handled by [process_user_decryption_resp].
|
|
592
|
+
* It's just here for completeness and tests.
|
|
593
|
+
* @param {Uint8Array} ct
|
|
594
|
+
* @param {PrivateEncKeyMlKem512} my_sk
|
|
595
595
|
* @returns {Uint8Array}
|
|
596
596
|
*/
|
|
597
|
-
module.exports.
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
597
|
+
module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
|
|
598
|
+
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
599
|
+
const len0 = WASM_VECTOR_LEN;
|
|
600
|
+
_assertClass(my_sk, PrivateEncKeyMlKem512);
|
|
601
|
+
const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
|
|
602
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
604
603
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
605
|
-
return
|
|
604
|
+
return v2;
|
|
606
605
|
};
|
|
607
606
|
|
|
608
607
|
/**
|
|
609
|
-
* @param {
|
|
608
|
+
* @param {PrivateSigKey} sk
|
|
610
609
|
* @returns {Uint8Array}
|
|
611
610
|
*/
|
|
612
|
-
module.exports.
|
|
613
|
-
_assertClass(sk,
|
|
614
|
-
const ret = wasm.
|
|
611
|
+
module.exports.private_sig_key_to_u8vec = function(sk) {
|
|
612
|
+
_assertClass(sk, PrivateSigKey);
|
|
613
|
+
const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
|
|
615
614
|
if (ret[3]) {
|
|
616
615
|
throw takeFromExternrefTable0(ret[2]);
|
|
617
616
|
}
|
package/kms_lib_bg.wasm
CHANGED
|
Binary file
|