@derec-alliance/nodejs 0.0.1-alpha.6
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/LICENSE +201 -0
- package/README.md +214 -0
- package/derec_library.d.ts +264 -0
- package/derec_library.js +961 -0
- package/derec_library_bg.wasm +0 -0
- package/derec_library_bg.wasm.d.ts +23 -0
- package/package.json +32 -0
package/derec_library.js
ADDED
|
@@ -0,0 +1,961 @@
|
|
|
1
|
+
/* @ts-self-types="./derec_library.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a serialized `ContactMessage` used to bootstrap pairing.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `channel_id` - Channel identifier associated with the generated pairing material
|
|
9
|
+
* * `transport_uri` - Transport endpoint that the peer should use for subsequent traffic
|
|
10
|
+
*
|
|
11
|
+
* # Returns
|
|
12
|
+
*
|
|
13
|
+
* A JS object with:
|
|
14
|
+
*
|
|
15
|
+
* - `wire_bytes`: serialized `ContactMessage` protobuf bytes
|
|
16
|
+
* - `secret_key_material`: serialized `PairingSecretKeyMaterial`
|
|
17
|
+
* @param {bigint} channel_id
|
|
18
|
+
* @param {string} transport_uri
|
|
19
|
+
* @returns {any}
|
|
20
|
+
*/
|
|
21
|
+
function create_contact_message(channel_id, transport_uri) {
|
|
22
|
+
const ptr0 = passStringToWasm0(transport_uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
23
|
+
const len0 = WASM_VECTOR_LEN;
|
|
24
|
+
const ret = wasm.create_contact_message(channel_id, ptr0, len0);
|
|
25
|
+
if (ret[2]) {
|
|
26
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
27
|
+
}
|
|
28
|
+
return takeFromExternrefTable0(ret[0]);
|
|
29
|
+
}
|
|
30
|
+
exports.create_contact_message = create_contact_message;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates a recovery request envelope.
|
|
34
|
+
*
|
|
35
|
+
* # Arguments
|
|
36
|
+
*
|
|
37
|
+
* * `channel_id` - Helper channel identifier
|
|
38
|
+
* * `secret_id` - Secret identifier being recovered
|
|
39
|
+
* * `version` - Share version being requested
|
|
40
|
+
* * `shared_key` - 32-byte symmetric key established during pairing
|
|
41
|
+
*
|
|
42
|
+
* # Returns
|
|
43
|
+
*
|
|
44
|
+
* Serialized outer `DeRecMessage` bytes carrying an encrypted inner
|
|
45
|
+
* `GetShareRequestMessage`.
|
|
46
|
+
* @param {bigint} channel_id
|
|
47
|
+
* @param {Uint8Array} secret_id
|
|
48
|
+
* @param {number} version
|
|
49
|
+
* @param {Uint8Array} shared_key
|
|
50
|
+
* @returns {Uint8Array}
|
|
51
|
+
*/
|
|
52
|
+
function generate_share_request(channel_id, secret_id, version, shared_key) {
|
|
53
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
54
|
+
const len0 = WASM_VECTOR_LEN;
|
|
55
|
+
const ptr1 = passArray8ToWasm0(shared_key, wasm.__wbindgen_malloc);
|
|
56
|
+
const len1 = WASM_VECTOR_LEN;
|
|
57
|
+
const ret = wasm.generate_share_request(channel_id, ptr0, len0, version, ptr1, len1);
|
|
58
|
+
if (ret[3]) {
|
|
59
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
60
|
+
}
|
|
61
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
62
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
63
|
+
return v3;
|
|
64
|
+
}
|
|
65
|
+
exports.generate_share_request = generate_share_request;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Generates a recovery response envelope.
|
|
69
|
+
*
|
|
70
|
+
* # Arguments
|
|
71
|
+
*
|
|
72
|
+
* * `secret_id` - Secret identifier being recovered
|
|
73
|
+
* * `channel_id` - Helper channel identifier
|
|
74
|
+
* * `stored_share_request_wire_bytes` - Serialized outer `DeRecMessage` bytes
|
|
75
|
+
* carrying the encrypted inner `StoreShareRequestMessage` previously produced
|
|
76
|
+
* by the sharing flow for this helper
|
|
77
|
+
* * `request_wire_bytes` - Serialized outer `DeRecMessage` bytes carrying the
|
|
78
|
+
* encrypted inner `GetShareRequestMessage`
|
|
79
|
+
* * `shared_key` - 32-byte symmetric key established during pairing
|
|
80
|
+
*
|
|
81
|
+
* # Returns
|
|
82
|
+
*
|
|
83
|
+
* Serialized outer `DeRecMessage` bytes carrying an encrypted inner
|
|
84
|
+
* `GetShareResponseMessage`.
|
|
85
|
+
* @param {Uint8Array} secret_id
|
|
86
|
+
* @param {bigint} channel_id
|
|
87
|
+
* @param {Uint8Array} stored_share_request_wire_bytes
|
|
88
|
+
* @param {Uint8Array} request_wire_bytes
|
|
89
|
+
* @param {Uint8Array} shared_key
|
|
90
|
+
* @returns {Uint8Array}
|
|
91
|
+
*/
|
|
92
|
+
function generate_share_response(secret_id, channel_id, stored_share_request_wire_bytes, request_wire_bytes, shared_key) {
|
|
93
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
94
|
+
const len0 = WASM_VECTOR_LEN;
|
|
95
|
+
const ptr1 = passArray8ToWasm0(stored_share_request_wire_bytes, wasm.__wbindgen_malloc);
|
|
96
|
+
const len1 = WASM_VECTOR_LEN;
|
|
97
|
+
const ptr2 = passArray8ToWasm0(request_wire_bytes, wasm.__wbindgen_malloc);
|
|
98
|
+
const len2 = WASM_VECTOR_LEN;
|
|
99
|
+
const ptr3 = passArray8ToWasm0(shared_key, wasm.__wbindgen_malloc);
|
|
100
|
+
const len3 = WASM_VECTOR_LEN;
|
|
101
|
+
const ret = wasm.generate_share_response(ptr0, len0, channel_id, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
102
|
+
if (ret[3]) {
|
|
103
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
104
|
+
}
|
|
105
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
106
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
107
|
+
return v5;
|
|
108
|
+
}
|
|
109
|
+
exports.generate_share_response = generate_share_response;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Generates a verification request envelope.
|
|
113
|
+
*
|
|
114
|
+
* # Arguments
|
|
115
|
+
*
|
|
116
|
+
* * `secret_id` - Secret identifier
|
|
117
|
+
* * `channel_id` - Helper channel identifier
|
|
118
|
+
* * `version` - Share-distribution version being verified
|
|
119
|
+
* * `shared_key` - 32-byte symmetric key established during pairing
|
|
120
|
+
*
|
|
121
|
+
* # Returns
|
|
122
|
+
*
|
|
123
|
+
* A JS object with:
|
|
124
|
+
*
|
|
125
|
+
* - `wire_bytes`: serialized outer `DeRecMessage` bytes carrying an encrypted
|
|
126
|
+
* inner `VerifyShareRequestMessage`
|
|
127
|
+
* @param {Uint8Array} secret_id
|
|
128
|
+
* @param {bigint} channel_id
|
|
129
|
+
* @param {number} version
|
|
130
|
+
* @param {Uint8Array} shared_key
|
|
131
|
+
* @returns {any}
|
|
132
|
+
*/
|
|
133
|
+
function generate_verification_request(secret_id, channel_id, version, shared_key) {
|
|
134
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
135
|
+
const len0 = WASM_VECTOR_LEN;
|
|
136
|
+
const ptr1 = passArray8ToWasm0(shared_key, wasm.__wbindgen_malloc);
|
|
137
|
+
const len1 = WASM_VECTOR_LEN;
|
|
138
|
+
const ret = wasm.generate_verification_request(ptr0, len0, channel_id, version, ptr1, len1);
|
|
139
|
+
if (ret[2]) {
|
|
140
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
141
|
+
}
|
|
142
|
+
return takeFromExternrefTable0(ret[0]);
|
|
143
|
+
}
|
|
144
|
+
exports.generate_verification_request = generate_verification_request;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Generates a verification response envelope.
|
|
148
|
+
*
|
|
149
|
+
* # Arguments
|
|
150
|
+
*
|
|
151
|
+
* * `secret_id` - Secret identifier
|
|
152
|
+
* * `channel_id` - Helper channel identifier
|
|
153
|
+
* * `shared_key` - 32-byte symmetric key established during pairing
|
|
154
|
+
* * `share_content` - Share bytes whose possession is being proven
|
|
155
|
+
* * `request_bytes` - Serialized outer `DeRecMessage` bytes carrying encrypted
|
|
156
|
+
* inner `VerifyShareRequestMessage`
|
|
157
|
+
*
|
|
158
|
+
* # Returns
|
|
159
|
+
*
|
|
160
|
+
* A JS object with:
|
|
161
|
+
*
|
|
162
|
+
* - `wire_bytes`: serialized outer `DeRecMessage` bytes carrying an encrypted
|
|
163
|
+
* inner `VerifyShareResponseMessage`
|
|
164
|
+
* @param {Uint8Array} secret_id
|
|
165
|
+
* @param {bigint} channel_id
|
|
166
|
+
* @param {Uint8Array} shared_key
|
|
167
|
+
* @param {Uint8Array} share_content
|
|
168
|
+
* @param {Uint8Array} request_bytes
|
|
169
|
+
* @returns {any}
|
|
170
|
+
*/
|
|
171
|
+
function generate_verification_response(secret_id, channel_id, shared_key, share_content, request_bytes) {
|
|
172
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
173
|
+
const len0 = WASM_VECTOR_LEN;
|
|
174
|
+
const ptr1 = passArray8ToWasm0(shared_key, wasm.__wbindgen_malloc);
|
|
175
|
+
const len1 = WASM_VECTOR_LEN;
|
|
176
|
+
const ptr2 = passArray8ToWasm0(share_content, wasm.__wbindgen_malloc);
|
|
177
|
+
const len2 = WASM_VECTOR_LEN;
|
|
178
|
+
const ptr3 = passArray8ToWasm0(request_bytes, wasm.__wbindgen_malloc);
|
|
179
|
+
const len3 = WASM_VECTOR_LEN;
|
|
180
|
+
const ret = wasm.generate_verification_response(ptr0, len0, channel_id, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
181
|
+
if (ret[2]) {
|
|
182
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
183
|
+
}
|
|
184
|
+
return takeFromExternrefTable0(ret[0]);
|
|
185
|
+
}
|
|
186
|
+
exports.generate_verification_response = generate_verification_response;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Processes a serialized pairing response envelope and derives the responder-side shared key.
|
|
190
|
+
*
|
|
191
|
+
* This is the **responder-side** finalization step: the party that created the pairing request
|
|
192
|
+
* processes the pairing response and derives the same final shared key.
|
|
193
|
+
*
|
|
194
|
+
* # Arguments
|
|
195
|
+
*
|
|
196
|
+
* * `contact_message_bytes` - Plain serialized `ContactMessage` bytes
|
|
197
|
+
* * `pair_response_wire_bytes` - Serialized outer `DeRecMessage` carrying encrypted inner response bytes
|
|
198
|
+
* * `pairing_secret_key_material` - Serialized responder-side `PairingSecretKeyMaterial`
|
|
199
|
+
*
|
|
200
|
+
* # Returns
|
|
201
|
+
*
|
|
202
|
+
* A JS object with:
|
|
203
|
+
*
|
|
204
|
+
* - `pairing_shared_key`: final shared pairing key
|
|
205
|
+
* @param {Uint8Array} contact_message_bytes
|
|
206
|
+
* @param {Uint8Array} pair_response_wire_bytes
|
|
207
|
+
* @param {Uint8Array} pairing_secret_key_material
|
|
208
|
+
* @returns {any}
|
|
209
|
+
*/
|
|
210
|
+
function process_pairing_response_message(contact_message_bytes, pair_response_wire_bytes, pairing_secret_key_material) {
|
|
211
|
+
const ptr0 = passArray8ToWasm0(contact_message_bytes, wasm.__wbindgen_malloc);
|
|
212
|
+
const len0 = WASM_VECTOR_LEN;
|
|
213
|
+
const ptr1 = passArray8ToWasm0(pair_response_wire_bytes, wasm.__wbindgen_malloc);
|
|
214
|
+
const len1 = WASM_VECTOR_LEN;
|
|
215
|
+
const ptr2 = passArray8ToWasm0(pairing_secret_key_material, wasm.__wbindgen_malloc);
|
|
216
|
+
const len2 = WASM_VECTOR_LEN;
|
|
217
|
+
const ret = wasm.process_pairing_response_message(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
218
|
+
if (ret[2]) {
|
|
219
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
220
|
+
}
|
|
221
|
+
return takeFromExternrefTable0(ret[0]);
|
|
222
|
+
}
|
|
223
|
+
exports.process_pairing_response_message = process_pairing_response_message;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Produces a serialized pairing request envelope from a contact message.
|
|
227
|
+
*
|
|
228
|
+
* This is the **responder-side** step: the party that received the out-of-band
|
|
229
|
+
* contact creates the pairing request.
|
|
230
|
+
*
|
|
231
|
+
* # Arguments
|
|
232
|
+
*
|
|
233
|
+
* * `kind` - Sender role encoded as:
|
|
234
|
+
* - `0` => `SharerNonRecovery`
|
|
235
|
+
* - `1` => `SharerRecovery`
|
|
236
|
+
* - `2` => `Helper`
|
|
237
|
+
* * `transport_uri` - Transport endpoint the responder can use to receive follow-up traffic
|
|
238
|
+
* * `contact_message_bytes` - Plain serialized `ContactMessage` bytes
|
|
239
|
+
*
|
|
240
|
+
* # Returns
|
|
241
|
+
*
|
|
242
|
+
* A JS object with:
|
|
243
|
+
*
|
|
244
|
+
* - `wire_bytes`: serialized outer `DeRecMessage` bytes
|
|
245
|
+
* - `secret_key_material`: serialized responder-side `PairingSecretKeyMaterial`
|
|
246
|
+
* @param {number} kind
|
|
247
|
+
* @param {string} transport_uri
|
|
248
|
+
* @param {Uint8Array} contact_message_bytes
|
|
249
|
+
* @returns {any}
|
|
250
|
+
*/
|
|
251
|
+
function produce_pairing_request_message(kind, transport_uri, contact_message_bytes) {
|
|
252
|
+
const ptr0 = passStringToWasm0(transport_uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
253
|
+
const len0 = WASM_VECTOR_LEN;
|
|
254
|
+
const ptr1 = passArray8ToWasm0(contact_message_bytes, wasm.__wbindgen_malloc);
|
|
255
|
+
const len1 = WASM_VECTOR_LEN;
|
|
256
|
+
const ret = wasm.produce_pairing_request_message(kind, ptr0, len0, ptr1, len1);
|
|
257
|
+
if (ret[2]) {
|
|
258
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
259
|
+
}
|
|
260
|
+
return takeFromExternrefTable0(ret[0]);
|
|
261
|
+
}
|
|
262
|
+
exports.produce_pairing_request_message = produce_pairing_request_message;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Produces a serialized pairing response envelope and derives the initiator-side shared key.
|
|
266
|
+
*
|
|
267
|
+
* This is the **initiator-side** step: the party that originally created the contact
|
|
268
|
+
* processes the incoming pairing request and returns the pairing response.
|
|
269
|
+
*
|
|
270
|
+
* # Arguments
|
|
271
|
+
*
|
|
272
|
+
* * `kind` - Sender role encoded as:
|
|
273
|
+
* - `0` => `SharerNonRecovery`
|
|
274
|
+
* - `1` => `SharerRecovery`
|
|
275
|
+
* - `2` => `Helper`
|
|
276
|
+
* * `pair_request_wire_bytes` - Serialized outer `DeRecMessage` carrying encrypted inner request bytes
|
|
277
|
+
* * `pairing_secret_key_material` - Serialized initiator-side `PairingSecretKeyMaterial`
|
|
278
|
+
*
|
|
279
|
+
* # Returns
|
|
280
|
+
*
|
|
281
|
+
* A JS object with:
|
|
282
|
+
*
|
|
283
|
+
* - `wire_bytes`: serialized outer `DeRecMessage` bytes carrying encrypted inner response bytes
|
|
284
|
+
* - `transport_protocol`: transport information extracted from the pairing request
|
|
285
|
+
* - `pairing_shared_key`: final shared pairing key
|
|
286
|
+
* @param {number} kind
|
|
287
|
+
* @param {Uint8Array} pair_request_wire_bytes
|
|
288
|
+
* @param {Uint8Array} pairing_secret_key_material
|
|
289
|
+
* @returns {any}
|
|
290
|
+
*/
|
|
291
|
+
function produce_pairing_response_message(kind, pair_request_wire_bytes, pairing_secret_key_material) {
|
|
292
|
+
const ptr0 = passArray8ToWasm0(pair_request_wire_bytes, wasm.__wbindgen_malloc);
|
|
293
|
+
const len0 = WASM_VECTOR_LEN;
|
|
294
|
+
const ptr1 = passArray8ToWasm0(pairing_secret_key_material, wasm.__wbindgen_malloc);
|
|
295
|
+
const len1 = WASM_VECTOR_LEN;
|
|
296
|
+
const ret = wasm.produce_pairing_response_message(kind, ptr0, len0, ptr1, len1);
|
|
297
|
+
if (ret[2]) {
|
|
298
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
299
|
+
}
|
|
300
|
+
return takeFromExternrefTable0(ret[0]);
|
|
301
|
+
}
|
|
302
|
+
exports.produce_pairing_response_message = produce_pairing_response_message;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Generates verifiable secret shares and returns one serialized outer `DeRecMessage`
|
|
306
|
+
* envelope per helper channel.
|
|
307
|
+
*
|
|
308
|
+
* # JavaScript input shape
|
|
309
|
+
*
|
|
310
|
+
* The `channels` argument must be a JS array of objects like:
|
|
311
|
+
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* [
|
|
314
|
+
* { channel_id: 1, shared_key: new Uint8Array(32) },
|
|
315
|
+
* { channel_id: 2, shared_key: new Uint8Array(32) },
|
|
316
|
+
* ]
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* Each `shared_key` must be exactly 32 bytes.
|
|
320
|
+
*
|
|
321
|
+
* The `keep_list` argument may be:
|
|
322
|
+
*
|
|
323
|
+
* - `undefined` or `null`, meaning no keep-list is provided
|
|
324
|
+
* - an array of integers, for example:
|
|
325
|
+
*
|
|
326
|
+
* ```ts
|
|
327
|
+
* [1, 2, 3]
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* The `description` argument may be:
|
|
331
|
+
*
|
|
332
|
+
* - `undefined` or `null`, meaning no description is provided
|
|
333
|
+
* - a string, for example:
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* "initial distribution"
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* # Returns
|
|
340
|
+
*
|
|
341
|
+
* A JS object of the form:
|
|
342
|
+
*
|
|
343
|
+
* ```ts
|
|
344
|
+
* {
|
|
345
|
+
* value: {
|
|
346
|
+
* [channelId: number]: Uint8Array
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* ```
|
|
350
|
+
*
|
|
351
|
+
* where each value is a serialized outer `DeRecMessage` envelope.
|
|
352
|
+
*
|
|
353
|
+
* # Arguments
|
|
354
|
+
*
|
|
355
|
+
* * `secret_id` - Secret identifier embedded into each generated share
|
|
356
|
+
* * `secret_data` - Secret bytes to split and distribute
|
|
357
|
+
* * `channels` - JS array of `{ channel_id, shared_key }` entries
|
|
358
|
+
* * `threshold` - Minimum number of shares required for reconstruction
|
|
359
|
+
* * `version` - Share-distribution version embedded into the generated messages
|
|
360
|
+
* * `keep_list` - Optional JS array of versions helpers should retain
|
|
361
|
+
* * `description` - Optional version description
|
|
362
|
+
* @param {Uint8Array} secret_id
|
|
363
|
+
* @param {Uint8Array} secret_data
|
|
364
|
+
* @param {any} channels
|
|
365
|
+
* @param {number} threshold
|
|
366
|
+
* @param {number} version
|
|
367
|
+
* @param {any} keep_list
|
|
368
|
+
* @param {string | null} [description]
|
|
369
|
+
* @returns {any}
|
|
370
|
+
*/
|
|
371
|
+
function protect_secret(secret_id, secret_data, channels, threshold, version, keep_list, description) {
|
|
372
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
373
|
+
const len0 = WASM_VECTOR_LEN;
|
|
374
|
+
const ptr1 = passArray8ToWasm0(secret_data, wasm.__wbindgen_malloc);
|
|
375
|
+
const len1 = WASM_VECTOR_LEN;
|
|
376
|
+
var ptr2 = isLikeNone(description) ? 0 : passStringToWasm0(description, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
377
|
+
var len2 = WASM_VECTOR_LEN;
|
|
378
|
+
const ret = wasm.protect_secret(ptr0, len0, ptr1, len1, channels, threshold, version, keep_list, ptr2, len2);
|
|
379
|
+
if (ret[2]) {
|
|
380
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
381
|
+
}
|
|
382
|
+
return takeFromExternrefTable0(ret[0]);
|
|
383
|
+
}
|
|
384
|
+
exports.protect_secret = protect_secret;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Recovers the original secret from helper recovery responses.
|
|
388
|
+
*
|
|
389
|
+
* # Arguments
|
|
390
|
+
*
|
|
391
|
+
* * `responses` - JS array of recovery response inputs. Each entry must contain:
|
|
392
|
+
* - `response_bytes`: serialized outer `DeRecMessage` response envelope
|
|
393
|
+
* - `shared_key`: 32-byte symmetric key for decrypting that response
|
|
394
|
+
* * `secret_id` - Secret identifier being recovered
|
|
395
|
+
* * `version` - Secret version being recovered
|
|
396
|
+
*
|
|
397
|
+
* # Returns
|
|
398
|
+
*
|
|
399
|
+
* The reconstructed secret bytes.
|
|
400
|
+
* @param {any} responses
|
|
401
|
+
* @param {Uint8Array} secret_id
|
|
402
|
+
* @param {number} version
|
|
403
|
+
* @returns {Uint8Array}
|
|
404
|
+
*/
|
|
405
|
+
function recover_from_share_responses(responses, secret_id, version) {
|
|
406
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
407
|
+
const len0 = WASM_VECTOR_LEN;
|
|
408
|
+
const ret = wasm.recover_from_share_responses(responses, ptr0, len0, version);
|
|
409
|
+
if (ret[3]) {
|
|
410
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
411
|
+
}
|
|
412
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
413
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
414
|
+
return v2;
|
|
415
|
+
}
|
|
416
|
+
exports.recover_from_share_responses = recover_from_share_responses;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Verifies a verification response envelope.
|
|
420
|
+
*
|
|
421
|
+
* # Arguments
|
|
422
|
+
*
|
|
423
|
+
* * `secret_id` - Secret identifier
|
|
424
|
+
* * `channel_id` - Helper channel identifier
|
|
425
|
+
* * `shared_key` - 32-byte symmetric key established during pairing
|
|
426
|
+
* * `share_content` - Expected share bytes
|
|
427
|
+
* * `response_bytes` - Serialized outer `DeRecMessage` bytes carrying encrypted
|
|
428
|
+
* inner `VerifyShareResponseMessage`
|
|
429
|
+
*
|
|
430
|
+
* # Returns
|
|
431
|
+
*
|
|
432
|
+
* `true` if the verification response is valid, otherwise `false`.
|
|
433
|
+
* @param {Uint8Array} secret_id
|
|
434
|
+
* @param {bigint} channel_id
|
|
435
|
+
* @param {Uint8Array} shared_key
|
|
436
|
+
* @param {Uint8Array} share_content
|
|
437
|
+
* @param {Uint8Array} response_bytes
|
|
438
|
+
* @returns {boolean}
|
|
439
|
+
*/
|
|
440
|
+
function verify_share_response(secret_id, channel_id, shared_key, share_content, response_bytes) {
|
|
441
|
+
const ptr0 = passArray8ToWasm0(secret_id, wasm.__wbindgen_malloc);
|
|
442
|
+
const len0 = WASM_VECTOR_LEN;
|
|
443
|
+
const ptr1 = passArray8ToWasm0(shared_key, wasm.__wbindgen_malloc);
|
|
444
|
+
const len1 = WASM_VECTOR_LEN;
|
|
445
|
+
const ptr2 = passArray8ToWasm0(share_content, wasm.__wbindgen_malloc);
|
|
446
|
+
const len2 = WASM_VECTOR_LEN;
|
|
447
|
+
const ptr3 = passArray8ToWasm0(response_bytes, wasm.__wbindgen_malloc);
|
|
448
|
+
const len3 = WASM_VECTOR_LEN;
|
|
449
|
+
const ret = wasm.verify_share_response(ptr0, len0, channel_id, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
450
|
+
if (ret[2]) {
|
|
451
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
452
|
+
}
|
|
453
|
+
return ret[0] !== 0;
|
|
454
|
+
}
|
|
455
|
+
exports.verify_share_response = verify_share_response;
|
|
456
|
+
|
|
457
|
+
function wasm_start() {
|
|
458
|
+
wasm.wasm_start();
|
|
459
|
+
}
|
|
460
|
+
exports.wasm_start = wasm_start;
|
|
461
|
+
|
|
462
|
+
function __wbg_get_imports() {
|
|
463
|
+
const import0 = {
|
|
464
|
+
__proto__: null,
|
|
465
|
+
__wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
|
|
466
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
467
|
+
return ret;
|
|
468
|
+
},
|
|
469
|
+
__wbg_Number_a5a435bd7bbec835: function(arg0) {
|
|
470
|
+
const ret = Number(arg0);
|
|
471
|
+
return ret;
|
|
472
|
+
},
|
|
473
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
474
|
+
const ret = String(arg1);
|
|
475
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
476
|
+
const len1 = WASM_VECTOR_LEN;
|
|
477
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
478
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
479
|
+
},
|
|
480
|
+
__wbg___wbindgen_bigint_get_as_i64_447a76b5c6ef7bda: function(arg0, arg1) {
|
|
481
|
+
const v = arg1;
|
|
482
|
+
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
483
|
+
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
484
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
485
|
+
},
|
|
486
|
+
__wbg___wbindgen_boolean_get_c0f3f60bac5a78d1: function(arg0) {
|
|
487
|
+
const v = arg0;
|
|
488
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
489
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
490
|
+
},
|
|
491
|
+
__wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
|
|
492
|
+
const ret = debugString(arg1);
|
|
493
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
494
|
+
const len1 = WASM_VECTOR_LEN;
|
|
495
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
496
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
497
|
+
},
|
|
498
|
+
__wbg___wbindgen_in_41dbb8413020e076: function(arg0, arg1) {
|
|
499
|
+
const ret = arg0 in arg1;
|
|
500
|
+
return ret;
|
|
501
|
+
},
|
|
502
|
+
__wbg___wbindgen_is_bigint_e2141d4f045b7eda: function(arg0) {
|
|
503
|
+
const ret = typeof(arg0) === 'bigint';
|
|
504
|
+
return ret;
|
|
505
|
+
},
|
|
506
|
+
__wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
|
|
507
|
+
const ret = typeof(arg0) === 'function';
|
|
508
|
+
return ret;
|
|
509
|
+
},
|
|
510
|
+
__wbg___wbindgen_is_null_0b605fc6b167c56f: function(arg0) {
|
|
511
|
+
const ret = arg0 === null;
|
|
512
|
+
return ret;
|
|
513
|
+
},
|
|
514
|
+
__wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
|
|
515
|
+
const val = arg0;
|
|
516
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
517
|
+
return ret;
|
|
518
|
+
},
|
|
519
|
+
__wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
|
|
520
|
+
const ret = typeof(arg0) === 'string';
|
|
521
|
+
return ret;
|
|
522
|
+
},
|
|
523
|
+
__wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
|
|
524
|
+
const ret = arg0 === undefined;
|
|
525
|
+
return ret;
|
|
526
|
+
},
|
|
527
|
+
__wbg___wbindgen_jsval_eq_ee31bfad3e536463: function(arg0, arg1) {
|
|
528
|
+
const ret = arg0 === arg1;
|
|
529
|
+
return ret;
|
|
530
|
+
},
|
|
531
|
+
__wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b: function(arg0, arg1) {
|
|
532
|
+
const ret = arg0 == arg1;
|
|
533
|
+
return ret;
|
|
534
|
+
},
|
|
535
|
+
__wbg___wbindgen_number_get_34bb9d9dcfa21373: function(arg0, arg1) {
|
|
536
|
+
const obj = arg1;
|
|
537
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
538
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
539
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
540
|
+
},
|
|
541
|
+
__wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
|
|
542
|
+
const obj = arg1;
|
|
543
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
544
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
545
|
+
var len1 = WASM_VECTOR_LEN;
|
|
546
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
547
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
548
|
+
},
|
|
549
|
+
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
550
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
551
|
+
},
|
|
552
|
+
__wbg_call_2d781c1f4d5c0ef8: function() { return handleError(function (arg0, arg1, arg2) {
|
|
553
|
+
const ret = arg0.call(arg1, arg2);
|
|
554
|
+
return ret;
|
|
555
|
+
}, arguments); },
|
|
556
|
+
__wbg_call_e133b57c9155d22c: function() { return handleError(function (arg0, arg1) {
|
|
557
|
+
const ret = arg0.call(arg1);
|
|
558
|
+
return ret;
|
|
559
|
+
}, arguments); },
|
|
560
|
+
__wbg_crypto_48300657fced39f9: function(arg0) {
|
|
561
|
+
const ret = arg0.crypto;
|
|
562
|
+
return ret;
|
|
563
|
+
},
|
|
564
|
+
__wbg_done_08ce71ee07e3bd17: function(arg0) {
|
|
565
|
+
const ret = arg0.done;
|
|
566
|
+
return ret;
|
|
567
|
+
},
|
|
568
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
569
|
+
let deferred0_0;
|
|
570
|
+
let deferred0_1;
|
|
571
|
+
try {
|
|
572
|
+
deferred0_0 = arg0;
|
|
573
|
+
deferred0_1 = arg1;
|
|
574
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
575
|
+
} finally {
|
|
576
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
__wbg_getRandomValues_263d0aa5464054ee: function() { return handleError(function (arg0, arg1) {
|
|
580
|
+
arg0.getRandomValues(arg1);
|
|
581
|
+
}, arguments); },
|
|
582
|
+
__wbg_getRandomValues_76dfc69825c9c552: function() { return handleError(function (arg0, arg1) {
|
|
583
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
584
|
+
}, arguments); },
|
|
585
|
+
__wbg_get_326e41e095fb2575: function() { return handleError(function (arg0, arg1) {
|
|
586
|
+
const ret = Reflect.get(arg0, arg1);
|
|
587
|
+
return ret;
|
|
588
|
+
}, arguments); },
|
|
589
|
+
__wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
|
|
590
|
+
const ret = arg0[arg1 >>> 0];
|
|
591
|
+
return ret;
|
|
592
|
+
},
|
|
593
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
594
|
+
const ret = arg0[arg1];
|
|
595
|
+
return ret;
|
|
596
|
+
},
|
|
597
|
+
__wbg_instanceof_ArrayBuffer_101e2bf31071a9f6: function(arg0) {
|
|
598
|
+
let result;
|
|
599
|
+
try {
|
|
600
|
+
result = arg0 instanceof ArrayBuffer;
|
|
601
|
+
} catch (_) {
|
|
602
|
+
result = false;
|
|
603
|
+
}
|
|
604
|
+
const ret = result;
|
|
605
|
+
return ret;
|
|
606
|
+
},
|
|
607
|
+
__wbg_instanceof_Uint8Array_740438561a5b956d: function(arg0) {
|
|
608
|
+
let result;
|
|
609
|
+
try {
|
|
610
|
+
result = arg0 instanceof Uint8Array;
|
|
611
|
+
} catch (_) {
|
|
612
|
+
result = false;
|
|
613
|
+
}
|
|
614
|
+
const ret = result;
|
|
615
|
+
return ret;
|
|
616
|
+
},
|
|
617
|
+
__wbg_isArray_33b91feb269ff46e: function(arg0) {
|
|
618
|
+
const ret = Array.isArray(arg0);
|
|
619
|
+
return ret;
|
|
620
|
+
},
|
|
621
|
+
__wbg_isSafeInteger_ecd6a7f9c3e053cd: function(arg0) {
|
|
622
|
+
const ret = Number.isSafeInteger(arg0);
|
|
623
|
+
return ret;
|
|
624
|
+
},
|
|
625
|
+
__wbg_iterator_d8f549ec8fb061b1: function() {
|
|
626
|
+
const ret = Symbol.iterator;
|
|
627
|
+
return ret;
|
|
628
|
+
},
|
|
629
|
+
__wbg_length_b3416cf66a5452c8: function(arg0) {
|
|
630
|
+
const ret = arg0.length;
|
|
631
|
+
return ret;
|
|
632
|
+
},
|
|
633
|
+
__wbg_length_ea16607d7b61445b: function(arg0) {
|
|
634
|
+
const ret = arg0.length;
|
|
635
|
+
return ret;
|
|
636
|
+
},
|
|
637
|
+
__wbg_msCrypto_8c6d45a75ef1d3da: function(arg0) {
|
|
638
|
+
const ret = arg0.msCrypto;
|
|
639
|
+
return ret;
|
|
640
|
+
},
|
|
641
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
642
|
+
const ret = new Error();
|
|
643
|
+
return ret;
|
|
644
|
+
},
|
|
645
|
+
__wbg_new_49d5571bd3f0c4d4: function() {
|
|
646
|
+
const ret = new Map();
|
|
647
|
+
return ret;
|
|
648
|
+
},
|
|
649
|
+
__wbg_new_5f486cdf45a04d78: function(arg0) {
|
|
650
|
+
const ret = new Uint8Array(arg0);
|
|
651
|
+
return ret;
|
|
652
|
+
},
|
|
653
|
+
__wbg_new_a70fbab9066b301f: function() {
|
|
654
|
+
const ret = new Array();
|
|
655
|
+
return ret;
|
|
656
|
+
},
|
|
657
|
+
__wbg_new_ab79df5bd7c26067: function() {
|
|
658
|
+
const ret = new Object();
|
|
659
|
+
return ret;
|
|
660
|
+
},
|
|
661
|
+
__wbg_new_with_length_825018a1616e9e55: function(arg0) {
|
|
662
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
663
|
+
return ret;
|
|
664
|
+
},
|
|
665
|
+
__wbg_next_11b99ee6237339e3: function() { return handleError(function (arg0) {
|
|
666
|
+
const ret = arg0.next();
|
|
667
|
+
return ret;
|
|
668
|
+
}, arguments); },
|
|
669
|
+
__wbg_next_e01a967809d1aa68: function(arg0) {
|
|
670
|
+
const ret = arg0.next;
|
|
671
|
+
return ret;
|
|
672
|
+
},
|
|
673
|
+
__wbg_node_95beb7570492fd97: function(arg0) {
|
|
674
|
+
const ret = arg0.node;
|
|
675
|
+
return ret;
|
|
676
|
+
},
|
|
677
|
+
__wbg_now_16f0c993d5dd6c27: function() {
|
|
678
|
+
const ret = Date.now();
|
|
679
|
+
return ret;
|
|
680
|
+
},
|
|
681
|
+
__wbg_process_b2fea42461d03994: function(arg0) {
|
|
682
|
+
const ret = arg0.process;
|
|
683
|
+
return ret;
|
|
684
|
+
},
|
|
685
|
+
__wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
|
|
686
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
687
|
+
},
|
|
688
|
+
__wbg_randomFillSync_ca9f178fb14c88cb: function() { return handleError(function (arg0, arg1) {
|
|
689
|
+
arg0.randomFillSync(arg1);
|
|
690
|
+
}, arguments); },
|
|
691
|
+
__wbg_require_7a9419e39d796c95: function() { return handleError(function () {
|
|
692
|
+
const ret = module.require;
|
|
693
|
+
return ret;
|
|
694
|
+
}, arguments); },
|
|
695
|
+
__wbg_set_282384002438957f: function(arg0, arg1, arg2) {
|
|
696
|
+
arg0[arg1 >>> 0] = arg2;
|
|
697
|
+
},
|
|
698
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
699
|
+
arg0[arg1] = arg2;
|
|
700
|
+
},
|
|
701
|
+
__wbg_set_bf7251625df30a02: function(arg0, arg1, arg2) {
|
|
702
|
+
const ret = arg0.set(arg1, arg2);
|
|
703
|
+
return ret;
|
|
704
|
+
},
|
|
705
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
706
|
+
const ret = arg1.stack;
|
|
707
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
708
|
+
const len1 = WASM_VECTOR_LEN;
|
|
709
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
710
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
711
|
+
},
|
|
712
|
+
__wbg_static_accessor_GLOBAL_8adb955bd33fac2f: function() {
|
|
713
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
714
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
715
|
+
},
|
|
716
|
+
__wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913: function() {
|
|
717
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
718
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
719
|
+
},
|
|
720
|
+
__wbg_static_accessor_SELF_f207c857566db248: function() {
|
|
721
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
722
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
723
|
+
},
|
|
724
|
+
__wbg_static_accessor_WINDOW_bb9f1ba69d61b386: function() {
|
|
725
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
726
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
727
|
+
},
|
|
728
|
+
__wbg_subarray_a068d24e39478a8a: function(arg0, arg1, arg2) {
|
|
729
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
730
|
+
return ret;
|
|
731
|
+
},
|
|
732
|
+
__wbg_value_21fc78aab0322612: function(arg0) {
|
|
733
|
+
const ret = arg0.value;
|
|
734
|
+
return ret;
|
|
735
|
+
},
|
|
736
|
+
__wbg_versions_215a3ab1c9d5745a: function(arg0) {
|
|
737
|
+
const ret = arg0.versions;
|
|
738
|
+
return ret;
|
|
739
|
+
},
|
|
740
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
741
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
742
|
+
const ret = arg0;
|
|
743
|
+
return ret;
|
|
744
|
+
},
|
|
745
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
746
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
747
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
748
|
+
return ret;
|
|
749
|
+
},
|
|
750
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
751
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
752
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
753
|
+
return ret;
|
|
754
|
+
},
|
|
755
|
+
__wbindgen_cast_0000000000000004: function(arg0) {
|
|
756
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
757
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
758
|
+
return ret;
|
|
759
|
+
},
|
|
760
|
+
__wbindgen_init_externref_table: function() {
|
|
761
|
+
const table = wasm.__wbindgen_externrefs;
|
|
762
|
+
const offset = table.grow(4);
|
|
763
|
+
table.set(0, undefined);
|
|
764
|
+
table.set(offset + 0, undefined);
|
|
765
|
+
table.set(offset + 1, null);
|
|
766
|
+
table.set(offset + 2, true);
|
|
767
|
+
table.set(offset + 3, false);
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
return {
|
|
771
|
+
__proto__: null,
|
|
772
|
+
"./derec_library_bg.js": import0,
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function addToExternrefTable0(obj) {
|
|
777
|
+
const idx = wasm.__externref_table_alloc();
|
|
778
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
779
|
+
return idx;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function debugString(val) {
|
|
783
|
+
// primitive types
|
|
784
|
+
const type = typeof val;
|
|
785
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
786
|
+
return `${val}`;
|
|
787
|
+
}
|
|
788
|
+
if (type == 'string') {
|
|
789
|
+
return `"${val}"`;
|
|
790
|
+
}
|
|
791
|
+
if (type == 'symbol') {
|
|
792
|
+
const description = val.description;
|
|
793
|
+
if (description == null) {
|
|
794
|
+
return 'Symbol';
|
|
795
|
+
} else {
|
|
796
|
+
return `Symbol(${description})`;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (type == 'function') {
|
|
800
|
+
const name = val.name;
|
|
801
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
802
|
+
return `Function(${name})`;
|
|
803
|
+
} else {
|
|
804
|
+
return 'Function';
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// objects
|
|
808
|
+
if (Array.isArray(val)) {
|
|
809
|
+
const length = val.length;
|
|
810
|
+
let debug = '[';
|
|
811
|
+
if (length > 0) {
|
|
812
|
+
debug += debugString(val[0]);
|
|
813
|
+
}
|
|
814
|
+
for(let i = 1; i < length; i++) {
|
|
815
|
+
debug += ', ' + debugString(val[i]);
|
|
816
|
+
}
|
|
817
|
+
debug += ']';
|
|
818
|
+
return debug;
|
|
819
|
+
}
|
|
820
|
+
// Test for built-in
|
|
821
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
822
|
+
let className;
|
|
823
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
824
|
+
className = builtInMatches[1];
|
|
825
|
+
} else {
|
|
826
|
+
// Failed to match the standard '[object ClassName]'
|
|
827
|
+
return toString.call(val);
|
|
828
|
+
}
|
|
829
|
+
if (className == 'Object') {
|
|
830
|
+
// we're a user defined class or Object
|
|
831
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
832
|
+
// easier than looping through ownProperties of `val`.
|
|
833
|
+
try {
|
|
834
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
835
|
+
} catch (_) {
|
|
836
|
+
return 'Object';
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// errors
|
|
840
|
+
if (val instanceof Error) {
|
|
841
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
842
|
+
}
|
|
843
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
844
|
+
return className;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
848
|
+
ptr = ptr >>> 0;
|
|
849
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
let cachedDataViewMemory0 = null;
|
|
853
|
+
function getDataViewMemory0() {
|
|
854
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
855
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
856
|
+
}
|
|
857
|
+
return cachedDataViewMemory0;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function getStringFromWasm0(ptr, len) {
|
|
861
|
+
ptr = ptr >>> 0;
|
|
862
|
+
return decodeText(ptr, len);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
let cachedUint8ArrayMemory0 = null;
|
|
866
|
+
function getUint8ArrayMemory0() {
|
|
867
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
868
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
869
|
+
}
|
|
870
|
+
return cachedUint8ArrayMemory0;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function handleError(f, args) {
|
|
874
|
+
try {
|
|
875
|
+
return f.apply(this, args);
|
|
876
|
+
} catch (e) {
|
|
877
|
+
const idx = addToExternrefTable0(e);
|
|
878
|
+
wasm.__wbindgen_exn_store(idx);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function isLikeNone(x) {
|
|
883
|
+
return x === undefined || x === null;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
887
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
888
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
889
|
+
WASM_VECTOR_LEN = arg.length;
|
|
890
|
+
return ptr;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
894
|
+
if (realloc === undefined) {
|
|
895
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
896
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
897
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
898
|
+
WASM_VECTOR_LEN = buf.length;
|
|
899
|
+
return ptr;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
let len = arg.length;
|
|
903
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
904
|
+
|
|
905
|
+
const mem = getUint8ArrayMemory0();
|
|
906
|
+
|
|
907
|
+
let offset = 0;
|
|
908
|
+
|
|
909
|
+
for (; offset < len; offset++) {
|
|
910
|
+
const code = arg.charCodeAt(offset);
|
|
911
|
+
if (code > 0x7F) break;
|
|
912
|
+
mem[ptr + offset] = code;
|
|
913
|
+
}
|
|
914
|
+
if (offset !== len) {
|
|
915
|
+
if (offset !== 0) {
|
|
916
|
+
arg = arg.slice(offset);
|
|
917
|
+
}
|
|
918
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
919
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
920
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
921
|
+
|
|
922
|
+
offset += ret.written;
|
|
923
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
WASM_VECTOR_LEN = offset;
|
|
927
|
+
return ptr;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function takeFromExternrefTable0(idx) {
|
|
931
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
932
|
+
wasm.__externref_table_dealloc(idx);
|
|
933
|
+
return value;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
937
|
+
cachedTextDecoder.decode();
|
|
938
|
+
function decodeText(ptr, len) {
|
|
939
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
const cachedTextEncoder = new TextEncoder();
|
|
943
|
+
|
|
944
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
945
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
946
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
947
|
+
view.set(buf);
|
|
948
|
+
return {
|
|
949
|
+
read: arg.length,
|
|
950
|
+
written: buf.length
|
|
951
|
+
};
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
let WASM_VECTOR_LEN = 0;
|
|
956
|
+
|
|
957
|
+
const wasmPath = `${__dirname}/derec_library_bg.wasm`;
|
|
958
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
959
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
960
|
+
let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
961
|
+
wasm.__wbindgen_start();
|