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