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