ecash-lib 4.12.0 → 4.13.0

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.
Files changed (43) hide show
  1. package/README.md +5 -0
  2. package/dist/ffi/ecash_lib_wasm_bg_browser.js +22074 -22085
  3. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/initWasm.d.ts +2 -0
  9. package/dist/initWasm.d.ts.map +1 -0
  10. package/dist/{initBrowser.js → initWasm.js} +7 -1
  11. package/dist/initWasm.js.map +1 -0
  12. package/package.json +51 -49
  13. package/src/ffi/ecash_lib_wasm_bg_browser.js +22074 -22085
  14. package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  15. package/src/index.ts +2 -0
  16. package/src/{initBrowser.ts → initWasm.ts} +6 -0
  17. package/.nycrc +0 -4
  18. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  19. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +0 -40
  20. package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +0 -180
  21. package/dist/ffi/ecash_lib_wasm_nodejs.js +0 -727
  22. package/dist/indexBrowser.d.ts +0 -3
  23. package/dist/indexBrowser.d.ts.map +0 -1
  24. package/dist/indexBrowser.js +0 -22
  25. package/dist/indexBrowser.js.map +0 -1
  26. package/dist/indexNodeJs.d.ts +0 -3
  27. package/dist/indexNodeJs.d.ts.map +0 -1
  28. package/dist/indexNodeJs.js +0 -22
  29. package/dist/indexNodeJs.js.map +0 -1
  30. package/dist/initBrowser.d.ts +0 -2
  31. package/dist/initBrowser.d.ts.map +0 -1
  32. package/dist/initBrowser.js.map +0 -1
  33. package/dist/initNodeJs.d.ts +0 -2
  34. package/dist/initNodeJs.d.ts.map +0 -1
  35. package/dist/initNodeJs.js +0 -56
  36. package/dist/initNodeJs.js.map +0 -1
  37. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  38. package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +0 -40
  39. package/src/ffi/ecash_lib_wasm_nodejs.d.ts +0 -180
  40. package/src/ffi/ecash_lib_wasm_nodejs.js +0 -727
  41. package/src/indexBrowser.ts +0 -6
  42. package/src/indexNodeJs.ts +0 -6
  43. package/src/initNodeJs.ts +0 -22
@@ -1,727 +0,0 @@
1
- let imports = {};
2
- imports['__wbindgen_placeholder__'] = module.exports;
3
- let wasm;
4
- const { TextDecoder, TextEncoder } = require(`util`);
5
-
6
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
7
-
8
- cachedTextDecoder.decode();
9
-
10
- let cachedUint8Memory0 = null;
11
-
12
- function getUint8Memory0() {
13
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
14
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
15
- }
16
- return cachedUint8Memory0;
17
- }
18
-
19
- function getStringFromWasm0(ptr, len) {
20
- ptr = ptr >>> 0;
21
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
22
- }
23
-
24
- const heap = new Array(128).fill(undefined);
25
-
26
- heap.push(undefined, null, true, false);
27
-
28
- let heap_next = heap.length;
29
-
30
- function addHeapObject(obj) {
31
- if (heap_next === heap.length) heap.push(heap.length + 1);
32
- const idx = heap_next;
33
- heap_next = heap[idx];
34
-
35
- heap[idx] = obj;
36
- return idx;
37
- }
38
-
39
- let WASM_VECTOR_LEN = 0;
40
-
41
- function passArray8ToWasm0(arg, malloc) {
42
- const ptr = malloc(arg.length * 1, 1) >>> 0;
43
- getUint8Memory0().set(arg, ptr / 1);
44
- WASM_VECTOR_LEN = arg.length;
45
- return ptr;
46
- }
47
-
48
- let cachedInt32Memory0 = null;
49
-
50
- function getInt32Memory0() {
51
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
52
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
53
- }
54
- return cachedInt32Memory0;
55
- }
56
-
57
- function getObject(idx) { return heap[idx]; }
58
-
59
- function dropObject(idx) {
60
- if (idx < 132) return;
61
- heap[idx] = heap_next;
62
- heap_next = idx;
63
- }
64
-
65
- function takeObject(idx) {
66
- const ret = getObject(idx);
67
- dropObject(idx);
68
- return ret;
69
- }
70
-
71
- function getArrayU8FromWasm0(ptr, len) {
72
- ptr = ptr >>> 0;
73
- return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
74
- }
75
-
76
- let cachedTextEncoder = new TextEncoder('utf-8');
77
-
78
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
79
- ? function (arg, view) {
80
- return cachedTextEncoder.encodeInto(arg, view);
81
- }
82
- : function (arg, view) {
83
- const buf = cachedTextEncoder.encode(arg);
84
- view.set(buf);
85
- return {
86
- read: arg.length,
87
- written: buf.length
88
- };
89
- });
90
-
91
- function passStringToWasm0(arg, malloc, realloc) {
92
-
93
- if (realloc === undefined) {
94
- const buf = cachedTextEncoder.encode(arg);
95
- const ptr = malloc(buf.length, 1) >>> 0;
96
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
97
- WASM_VECTOR_LEN = buf.length;
98
- return ptr;
99
- }
100
-
101
- let len = arg.length;
102
- let ptr = malloc(len, 1) >>> 0;
103
-
104
- const mem = getUint8Memory0();
105
-
106
- let offset = 0;
107
-
108
- for (; offset < len; offset++) {
109
- const code = arg.charCodeAt(offset);
110
- if (code > 0x7F) break;
111
- mem[ptr + offset] = code;
112
- }
113
-
114
- if (offset !== len) {
115
- if (offset !== 0) {
116
- arg = arg.slice(offset);
117
- }
118
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
119
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
120
- const ret = encodeString(arg, view);
121
-
122
- offset += ret.written;
123
- ptr = realloc(ptr, len, offset, 1) >>> 0;
124
- }
125
-
126
- WASM_VECTOR_LEN = offset;
127
- return ptr;
128
- }
129
-
130
- function isLikeNone(x) {
131
- return x === undefined || x === null;
132
- }
133
- /**
134
- * Verify a signature for the given cryptographic algorithm.
135
- * Intended to be used in X509 certificate verification.
136
- * Throw an exception if the algorithm is not supported.
137
- * @param {string} algo_oid
138
- * @param {string | undefined} params
139
- * @param {Uint8Array} sig
140
- * @param {Uint8Array} msg
141
- * @param {Uint8Array} pk
142
- */
143
- module.exports.publicKeyCryptoVerify = function(algo_oid, params, sig, msg, pk) {
144
- try {
145
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
146
- const ptr0 = passStringToWasm0(algo_oid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
147
- const len0 = WASM_VECTOR_LEN;
148
- var ptr1 = isLikeNone(params) ? 0 : passStringToWasm0(params, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
149
- var len1 = WASM_VECTOR_LEN;
150
- const ptr2 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
151
- const len2 = WASM_VECTOR_LEN;
152
- const ptr3 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
153
- const len3 = WASM_VECTOR_LEN;
154
- const ptr4 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
155
- const len4 = WASM_VECTOR_LEN;
156
- wasm.publicKeyCryptoVerify(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
157
- var r0 = getInt32Memory0()[retptr / 4 + 0];
158
- var r1 = getInt32Memory0()[retptr / 4 + 1];
159
- if (r1) {
160
- throw takeObject(r0);
161
- }
162
- } finally {
163
- wasm.__wbindgen_add_to_stack_pointer(16);
164
- }
165
- };
166
-
167
- /**
168
- * Throw an exception if the given algo is not supported, otherwise do nothing.
169
- * @param {string} algo_oid
170
- * @param {string | undefined} [params]
171
- */
172
- module.exports.publicKeyCryptoAlgoSupported = function(algo_oid, params) {
173
- try {
174
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
175
- const ptr0 = passStringToWasm0(algo_oid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
176
- const len0 = WASM_VECTOR_LEN;
177
- var ptr1 = isLikeNone(params) ? 0 : passStringToWasm0(params, wasm.__wbindgen_export_0, wasm.__wbindgen_export_2);
178
- var len1 = WASM_VECTOR_LEN;
179
- wasm.publicKeyCryptoAlgoSupported(retptr, ptr0, len0, ptr1, len1);
180
- var r0 = getInt32Memory0()[retptr / 4 + 0];
181
- var r1 = getInt32Memory0()[retptr / 4 + 1];
182
- if (r1) {
183
- throw takeObject(r0);
184
- }
185
- } finally {
186
- wasm.__wbindgen_add_to_stack_pointer(16);
187
- }
188
- };
189
-
190
- /**
191
- * Calculate SHA512(data).
192
- * @param {Uint8Array} data
193
- * @returns {Uint8Array}
194
- */
195
- module.exports.sha512 = function(data) {
196
- try {
197
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
198
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
199
- const len0 = WASM_VECTOR_LEN;
200
- wasm.sha512(retptr, ptr0, len0);
201
- var r0 = getInt32Memory0()[retptr / 4 + 0];
202
- var r1 = getInt32Memory0()[retptr / 4 + 1];
203
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
204
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
205
- return v2;
206
- } finally {
207
- wasm.__wbindgen_add_to_stack_pointer(16);
208
- }
209
- };
210
-
211
- /**
212
- * Calculate SHA256(SHA256(data)).
213
- * @param {Uint8Array} data
214
- * @returns {Uint8Array}
215
- */
216
- module.exports.sha256d = function(data) {
217
- try {
218
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
219
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
220
- const len0 = WASM_VECTOR_LEN;
221
- wasm.sha256d(retptr, ptr0, len0);
222
- var r0 = getInt32Memory0()[retptr / 4 + 0];
223
- var r1 = getInt32Memory0()[retptr / 4 + 1];
224
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
225
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
226
- return v2;
227
- } finally {
228
- wasm.__wbindgen_add_to_stack_pointer(16);
229
- }
230
- };
231
-
232
- /**
233
- * Calculate SHA256(data).
234
- * @param {Uint8Array} data
235
- * @returns {Uint8Array}
236
- */
237
- module.exports.sha256 = function(data) {
238
- try {
239
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
240
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
241
- const len0 = WASM_VECTOR_LEN;
242
- wasm.sha256(retptr, ptr0, len0);
243
- var r0 = getInt32Memory0()[retptr / 4 + 0];
244
- var r1 = getInt32Memory0()[retptr / 4 + 1];
245
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
246
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
247
- return v2;
248
- } finally {
249
- wasm.__wbindgen_add_to_stack_pointer(16);
250
- }
251
- };
252
-
253
- /**
254
- * Calculate RIPEMD160(SHA256(data)), commonly used as address hash.
255
- * @param {Uint8Array} data
256
- * @returns {Uint8Array}
257
- */
258
- module.exports.shaRmd160 = function(data) {
259
- try {
260
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
261
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
262
- const len0 = WASM_VECTOR_LEN;
263
- wasm.shaRmd160(retptr, ptr0, len0);
264
- var r0 = getInt32Memory0()[retptr / 4 + 0];
265
- var r1 = getInt32Memory0()[retptr / 4 + 1];
266
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
267
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
268
- return v2;
269
- } finally {
270
- wasm.__wbindgen_add_to_stack_pointer(16);
271
- }
272
- };
273
-
274
- const EccFinalization = (typeof FinalizationRegistry === 'undefined')
275
- ? { register: () => {}, unregister: () => {} }
276
- : new FinalizationRegistry(ptr => wasm.__wbg_ecc_free(ptr >>> 0));
277
- /**
278
- * ECC signatures with libsecp256k1.
279
- */
280
- class Ecc {
281
-
282
- __destroy_into_raw() {
283
- const ptr = this.__wbg_ptr;
284
- this.__wbg_ptr = 0;
285
- EccFinalization.unregister(this);
286
- return ptr;
287
- }
288
-
289
- free() {
290
- const ptr = this.__destroy_into_raw();
291
- wasm.__wbg_ecc_free(ptr);
292
- }
293
- /**
294
- * Create a new Ecc instance.
295
- */
296
- constructor() {
297
- const ret = wasm.ecc_new();
298
- this.__wbg_ptr = ret >>> 0;
299
- return this;
300
- }
301
- /**
302
- * Derive a public key from secret key.
303
- * @param {Uint8Array} seckey
304
- * @returns {Uint8Array}
305
- */
306
- derivePubkey(seckey) {
307
- try {
308
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
309
- const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
310
- const len0 = WASM_VECTOR_LEN;
311
- wasm.ecc_derivePubkey(retptr, this.__wbg_ptr, ptr0, len0);
312
- var r0 = getInt32Memory0()[retptr / 4 + 0];
313
- var r1 = getInt32Memory0()[retptr / 4 + 1];
314
- var r2 = getInt32Memory0()[retptr / 4 + 2];
315
- var r3 = getInt32Memory0()[retptr / 4 + 3];
316
- if (r3) {
317
- throw takeObject(r2);
318
- }
319
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
320
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
321
- return v2;
322
- } finally {
323
- wasm.__wbindgen_add_to_stack_pointer(16);
324
- }
325
- }
326
- /**
327
- * Sign an ECDSA signature.
328
- * @param {Uint8Array} seckey
329
- * @param {Uint8Array} msg
330
- * @returns {Uint8Array}
331
- */
332
- ecdsaSign(seckey, msg) {
333
- try {
334
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
335
- const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
336
- const len0 = WASM_VECTOR_LEN;
337
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
338
- const len1 = WASM_VECTOR_LEN;
339
- wasm.ecc_ecdsaSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
340
- var r0 = getInt32Memory0()[retptr / 4 + 0];
341
- var r1 = getInt32Memory0()[retptr / 4 + 1];
342
- var r2 = getInt32Memory0()[retptr / 4 + 2];
343
- var r3 = getInt32Memory0()[retptr / 4 + 3];
344
- if (r3) {
345
- throw takeObject(r2);
346
- }
347
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
348
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
349
- return v3;
350
- } finally {
351
- wasm.__wbindgen_add_to_stack_pointer(16);
352
- }
353
- }
354
- /**
355
- * Verify an ECDSA signature.
356
- * @param {Uint8Array} sig
357
- * @param {Uint8Array} msg
358
- * @param {Uint8Array} pk
359
- */
360
- ecdsaVerify(sig, msg, pk) {
361
- try {
362
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
363
- const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
364
- const len0 = WASM_VECTOR_LEN;
365
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
366
- const len1 = WASM_VECTOR_LEN;
367
- const ptr2 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
368
- const len2 = WASM_VECTOR_LEN;
369
- wasm.ecc_ecdsaVerify(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
370
- var r0 = getInt32Memory0()[retptr / 4 + 0];
371
- var r1 = getInt32Memory0()[retptr / 4 + 1];
372
- if (r1) {
373
- throw takeObject(r0);
374
- }
375
- } finally {
376
- wasm.__wbindgen_add_to_stack_pointer(16);
377
- }
378
- }
379
- /**
380
- * Sign a Schnorr signature.
381
- * @param {Uint8Array} seckey
382
- * @param {Uint8Array} msg
383
- * @returns {Uint8Array}
384
- */
385
- schnorrSign(seckey, msg) {
386
- try {
387
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
388
- const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
389
- const len0 = WASM_VECTOR_LEN;
390
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
391
- const len1 = WASM_VECTOR_LEN;
392
- wasm.ecc_schnorrSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
393
- var r0 = getInt32Memory0()[retptr / 4 + 0];
394
- var r1 = getInt32Memory0()[retptr / 4 + 1];
395
- var r2 = getInt32Memory0()[retptr / 4 + 2];
396
- var r3 = getInt32Memory0()[retptr / 4 + 3];
397
- if (r3) {
398
- throw takeObject(r2);
399
- }
400
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
401
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
402
- return v3;
403
- } finally {
404
- wasm.__wbindgen_add_to_stack_pointer(16);
405
- }
406
- }
407
- /**
408
- * Verify a Schnorr signature.
409
- * @param {Uint8Array} sig
410
- * @param {Uint8Array} msg
411
- * @param {Uint8Array} pk
412
- */
413
- schnorrVerify(sig, msg, pk) {
414
- try {
415
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
416
- const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
417
- const len0 = WASM_VECTOR_LEN;
418
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
419
- const len1 = WASM_VECTOR_LEN;
420
- const ptr2 = passArray8ToWasm0(pk, wasm.__wbindgen_export_0);
421
- const len2 = WASM_VECTOR_LEN;
422
- wasm.ecc_schnorrVerify(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
423
- var r0 = getInt32Memory0()[retptr / 4 + 0];
424
- var r1 = getInt32Memory0()[retptr / 4 + 1];
425
- if (r1) {
426
- throw takeObject(r0);
427
- }
428
- } finally {
429
- wasm.__wbindgen_add_to_stack_pointer(16);
430
- }
431
- }
432
- /**
433
- * Return whether the given secret key is valid, i.e. whether is of correct
434
- * length (32 bytes) and is on the curve.
435
- * @param {Uint8Array} seckey
436
- * @returns {boolean}
437
- */
438
- isValidSeckey(seckey) {
439
- const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
440
- const len0 = WASM_VECTOR_LEN;
441
- const ret = wasm.ecc_isValidSeckey(this.__wbg_ptr, ptr0, len0);
442
- return ret !== 0;
443
- }
444
- /**
445
- * Add a scalar to a secret key.
446
- * @param {Uint8Array} a
447
- * @param {Uint8Array} b
448
- * @returns {Uint8Array}
449
- */
450
- seckeyAdd(a, b) {
451
- try {
452
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
453
- const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
454
- const len0 = WASM_VECTOR_LEN;
455
- const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
456
- const len1 = WASM_VECTOR_LEN;
457
- wasm.ecc_seckeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
458
- var r0 = getInt32Memory0()[retptr / 4 + 0];
459
- var r1 = getInt32Memory0()[retptr / 4 + 1];
460
- var r2 = getInt32Memory0()[retptr / 4 + 2];
461
- var r3 = getInt32Memory0()[retptr / 4 + 3];
462
- if (r3) {
463
- throw takeObject(r2);
464
- }
465
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
466
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
467
- return v3;
468
- } finally {
469
- wasm.__wbindgen_add_to_stack_pointer(16);
470
- }
471
- }
472
- /**
473
- * Add a scalar to a public key (adding G*b).
474
- * @param {Uint8Array} a
475
- * @param {Uint8Array} b
476
- * @returns {Uint8Array}
477
- */
478
- pubkeyAdd(a, b) {
479
- try {
480
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
481
- const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
482
- const len0 = WASM_VECTOR_LEN;
483
- const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
484
- const len1 = WASM_VECTOR_LEN;
485
- wasm.ecc_pubkeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
486
- var r0 = getInt32Memory0()[retptr / 4 + 0];
487
- var r1 = getInt32Memory0()[retptr / 4 + 1];
488
- var r2 = getInt32Memory0()[retptr / 4 + 2];
489
- var r3 = getInt32Memory0()[retptr / 4 + 3];
490
- if (r3) {
491
- throw takeObject(r2);
492
- }
493
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
494
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
495
- return v3;
496
- } finally {
497
- wasm.__wbindgen_add_to_stack_pointer(16);
498
- }
499
- }
500
- /**
501
- * Create a compact ECDSA signature (65 bytes), which allows reconstructing
502
- * the used public key.
503
- * The format is one header byte, followed by two times 32 bytes for the
504
- * serialized r and s values.
505
- * The header byte: 0x1B = first key with even y,
506
- * 0x1C = first key with odd y,
507
- * 0x1D = second key with even y,
508
- * 0x1E = second key with odd y,
509
- * add 0x04 for compressed keys.
510
- * @param {Uint8Array} seckey
511
- * @param {Uint8Array} msg
512
- * @returns {Uint8Array}
513
- */
514
- signRecoverable(seckey, msg) {
515
- try {
516
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
517
- const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
518
- const len0 = WASM_VECTOR_LEN;
519
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
520
- const len1 = WASM_VECTOR_LEN;
521
- wasm.ecc_signRecoverable(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
522
- var r0 = getInt32Memory0()[retptr / 4 + 0];
523
- var r1 = getInt32Memory0()[retptr / 4 + 1];
524
- var r2 = getInt32Memory0()[retptr / 4 + 2];
525
- var r3 = getInt32Memory0()[retptr / 4 + 3];
526
- if (r3) {
527
- throw takeObject(r2);
528
- }
529
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
530
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
531
- return v3;
532
- } finally {
533
- wasm.__wbindgen_add_to_stack_pointer(16);
534
- }
535
- }
536
- /**
537
- * Recover the public key of a signature signed by signRecoverable.
538
- * @param {Uint8Array} sig
539
- * @param {Uint8Array} msg
540
- * @returns {Uint8Array}
541
- */
542
- recoverSig(sig, msg) {
543
- try {
544
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
545
- const ptr0 = passArray8ToWasm0(sig, wasm.__wbindgen_export_0);
546
- const len0 = WASM_VECTOR_LEN;
547
- const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
548
- const len1 = WASM_VECTOR_LEN;
549
- wasm.ecc_recoverSig(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
550
- var r0 = getInt32Memory0()[retptr / 4 + 0];
551
- var r1 = getInt32Memory0()[retptr / 4 + 1];
552
- var r2 = getInt32Memory0()[retptr / 4 + 2];
553
- var r3 = getInt32Memory0()[retptr / 4 + 3];
554
- if (r3) {
555
- throw takeObject(r2);
556
- }
557
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
558
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
559
- return v3;
560
- } finally {
561
- wasm.__wbindgen_add_to_stack_pointer(16);
562
- }
563
- }
564
- }
565
- module.exports.Ecc = Ecc;
566
-
567
- const Sha256HFinalization = (typeof FinalizationRegistry === 'undefined')
568
- ? { register: () => {}, unregister: () => {} }
569
- : new FinalizationRegistry(ptr => wasm.__wbg_sha256h_free(ptr >>> 0));
570
- /**
571
- * Instance to calculate SHA256 in a streaming fashion
572
- */
573
- class Sha256H {
574
-
575
- static __wrap(ptr) {
576
- ptr = ptr >>> 0;
577
- const obj = Object.create(Sha256H.prototype);
578
- obj.__wbg_ptr = ptr;
579
- Sha256HFinalization.register(obj, obj.__wbg_ptr, obj);
580
- return obj;
581
- }
582
-
583
- __destroy_into_raw() {
584
- const ptr = this.__wbg_ptr;
585
- this.__wbg_ptr = 0;
586
- Sha256HFinalization.unregister(this);
587
- return ptr;
588
- }
589
-
590
- free() {
591
- const ptr = this.__destroy_into_raw();
592
- wasm.__wbg_sha256h_free(ptr);
593
- }
594
- /**
595
- * Create new hasher instance
596
- */
597
- constructor() {
598
- const ret = wasm.sha256h_new();
599
- this.__wbg_ptr = ret >>> 0;
600
- return this;
601
- }
602
- /**
603
- * Feed bytes into the hasher
604
- * @param {Uint8Array} data
605
- */
606
- update(data) {
607
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
608
- const len0 = WASM_VECTOR_LEN;
609
- wasm.sha256h_update(this.__wbg_ptr, ptr0, len0);
610
- }
611
- /**
612
- * Finalize the hash and return the result
613
- * @returns {Uint8Array}
614
- */
615
- finalize() {
616
- try {
617
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
618
- wasm.sha256h_finalize(retptr, this.__wbg_ptr);
619
- var r0 = getInt32Memory0()[retptr / 4 + 0];
620
- var r1 = getInt32Memory0()[retptr / 4 + 1];
621
- var v1 = getArrayU8FromWasm0(r0, r1).slice();
622
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
623
- return v1;
624
- } finally {
625
- wasm.__wbindgen_add_to_stack_pointer(16);
626
- }
627
- }
628
- /**
629
- * Clone the hasher
630
- * @returns {Sha256H}
631
- */
632
- clone() {
633
- const ret = wasm.sha256h_clone(this.__wbg_ptr);
634
- return Sha256H.__wrap(ret);
635
- }
636
- }
637
- module.exports.Sha256H = Sha256H;
638
-
639
- const Sha512HFinalization = (typeof FinalizationRegistry === 'undefined')
640
- ? { register: () => {}, unregister: () => {} }
641
- : new FinalizationRegistry(ptr => wasm.__wbg_sha512h_free(ptr >>> 0));
642
- /**
643
- * Instance to calculate SHA512 in a streaming fashion
644
- */
645
- class Sha512H {
646
-
647
- static __wrap(ptr) {
648
- ptr = ptr >>> 0;
649
- const obj = Object.create(Sha512H.prototype);
650
- obj.__wbg_ptr = ptr;
651
- Sha512HFinalization.register(obj, obj.__wbg_ptr, obj);
652
- return obj;
653
- }
654
-
655
- __destroy_into_raw() {
656
- const ptr = this.__wbg_ptr;
657
- this.__wbg_ptr = 0;
658
- Sha512HFinalization.unregister(this);
659
- return ptr;
660
- }
661
-
662
- free() {
663
- const ptr = this.__destroy_into_raw();
664
- wasm.__wbg_sha512h_free(ptr);
665
- }
666
- /**
667
- * Create new hasher instance
668
- */
669
- constructor() {
670
- const ret = wasm.sha512h_new();
671
- this.__wbg_ptr = ret >>> 0;
672
- return this;
673
- }
674
- /**
675
- * Feed bytes into the hasher
676
- * @param {Uint8Array} data
677
- */
678
- update(data) {
679
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
680
- const len0 = WASM_VECTOR_LEN;
681
- wasm.sha512h_update(this.__wbg_ptr, ptr0, len0);
682
- }
683
- /**
684
- * Finalize the hash and return the result
685
- * @returns {Uint8Array}
686
- */
687
- finalize() {
688
- try {
689
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
690
- wasm.sha512h_finalize(retptr, this.__wbg_ptr);
691
- var r0 = getInt32Memory0()[retptr / 4 + 0];
692
- var r1 = getInt32Memory0()[retptr / 4 + 1];
693
- var v1 = getArrayU8FromWasm0(r0, r1).slice();
694
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
695
- return v1;
696
- } finally {
697
- wasm.__wbindgen_add_to_stack_pointer(16);
698
- }
699
- }
700
- /**
701
- * Clone the hasher
702
- * @returns {Sha512H}
703
- */
704
- clone() {
705
- const ret = wasm.sha512h_clone(this.__wbg_ptr);
706
- return Sha512H.__wrap(ret);
707
- }
708
- }
709
- module.exports.Sha512H = Sha512H;
710
-
711
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
712
- const ret = getStringFromWasm0(arg0, arg1);
713
- return addHeapObject(ret);
714
- };
715
-
716
- module.exports.__wbindgen_throw = function(arg0, arg1) {
717
- throw new Error(getStringFromWasm0(arg0, arg1));
718
- };
719
-
720
- const path = require('path').join(__dirname, 'ecash_lib_wasm_bg_nodejs.wasm');
721
- const bytes = require('fs').readFileSync(path);
722
-
723
- const wasmModule = new WebAssembly.Module(bytes);
724
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
725
- wasm = wasmInstance.exports;
726
- module.exports.__wasm = wasm;
727
-