ecash-lib 1.2.2-rc9 → 1.4.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.
- package/README.md +2 -1
- package/dist/ecc.d.ts +12 -0
- package/dist/ecc.d.ts.map +1 -1
- package/dist/ecc.js +9 -47
- package/dist/ecc.js.map +1 -1
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +18 -4
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +18 -4
- package/dist/ffi/ecash_lib_wasm_browser.d.ts +95 -4
- package/dist/ffi/ecash_lib_wasm_browser.js +245 -14
- package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +77 -0
- package/dist/ffi/ecash_lib_wasm_nodejs.js +247 -14
- package/dist/hash.d.ts +21 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +16 -10
- package/dist/hash.js.map +1 -1
- package/dist/hdwallet.d.ts +33 -0
- package/dist/hdwallet.d.ts.map +1 -0
- package/dist/hdwallet.js +148 -0
- package/dist/hdwallet.js.map +1 -0
- package/dist/hmac.d.ts +13 -0
- package/dist/hmac.d.ts.map +1 -0
- package/dist/hmac.js +63 -0
- package/dist/hmac.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/initBrowser.d.ts.map +1 -1
- package/dist/initBrowser.js +3 -0
- package/dist/initBrowser.js.map +1 -1
- package/dist/initNodeJs.d.ts.map +1 -1
- package/dist/initNodeJs.js +3 -0
- package/dist/initNodeJs.js.map +1 -1
- package/dist/io/bytes.d.ts +5 -3
- package/dist/io/bytes.d.ts.map +1 -1
- package/dist/io/bytes.js +15 -7
- package/dist/io/bytes.js.map +1 -1
- package/dist/io/writer.d.ts +4 -3
- package/dist/io/writer.d.ts.map +1 -1
- package/dist/io/writerbytes.d.ts +4 -3
- package/dist/io/writerbytes.d.ts.map +1 -1
- package/dist/io/writerbytes.js +7 -6
- package/dist/io/writerbytes.js.map +1 -1
- package/dist/io/writerlength.d.ts +4 -3
- package/dist/io/writerlength.d.ts.map +1 -1
- package/dist/io/writerlength.js +3 -3
- package/dist/io/writerlength.js.map +1 -1
- package/dist/mnemonic.d.ts +14 -0
- package/dist/mnemonic.d.ts.map +1 -0
- package/dist/mnemonic.js +123 -0
- package/dist/mnemonic.js.map +1 -0
- package/dist/pbkdf2.d.ts +11 -0
- package/dist/pbkdf2.d.ts.map +1 -0
- package/dist/pbkdf2.js +36 -0
- package/dist/pbkdf2.js.map +1 -0
- package/dist/script.d.ts +4 -0
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +6 -0
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/address/address.ts +346 -0
- package/src/address/legacyaddr.ts +129 -0
- package/src/consts.ts +8 -0
- package/src/ecc.ts +61 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +32 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +32 -0
- package/src/ffi/ecash_lib_wasm_browser.d.ts +183 -0
- package/src/ffi/ecash_lib_wasm_browser.js +571 -0
- package/src/ffi/ecash_lib_wasm_nodejs.d.ts +127 -0
- package/src/ffi/ecash_lib_wasm_nodejs.js +498 -0
- package/src/hash.ts +46 -0
- package/src/hdwallet.ts +181 -0
- package/src/hmac.ts +74 -0
- package/src/index.ts +29 -0
- package/src/indexBrowser.ts +6 -0
- package/src/indexNodeJs.ts +6 -0
- package/src/initBrowser.ts +21 -0
- package/src/initNodeJs.ts +20 -0
- package/src/io/bytes.ts +80 -0
- package/src/io/hex.ts +69 -0
- package/src/io/int.ts +6 -0
- package/src/io/str.ts +16 -0
- package/src/io/varsize.ts +49 -0
- package/src/io/writer.ts +20 -0
- package/src/io/writerbytes.ts +87 -0
- package/src/io/writerlength.ts +44 -0
- package/src/mnemonic.ts +153 -0
- package/src/op.ts +162 -0
- package/src/opcode.ts +154 -0
- package/src/pbkdf2.ts +52 -0
- package/src/script.ts +195 -0
- package/src/sigHashType.ts +190 -0
- package/src/test/testRunner.ts +209 -0
- package/src/token/alp.ts +146 -0
- package/src/token/common.ts +32 -0
- package/src/token/empp.ts +29 -0
- package/src/token/slp.ts +212 -0
- package/src/tx.ts +180 -0
- package/src/txBuilder.ts +262 -0
- package/src/unsignedTx.ts +359 -0
- package/tsconfig.json +2 -1
- package/wordlists/english.json +2053 -0
- package/.nyc_output/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
- package/.nyc_output/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
- package/.nyc_output/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
- package/.nyc_output/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
- package/.nyc_output/processinfo/0fc40ca6-d52c-45eb-b31b-2601ce70b887.json +0 -1
- package/.nyc_output/processinfo/ac5be6db-4e40-41f8-8b84-7598d4747e57.json +0 -1
- package/.nyc_output/processinfo/b316d46f-5ea0-4e98-884a-bfbf9cc1d0f8.json +0 -1
- package/.nyc_output/processinfo/f965566b-9422-4874-b45e-9eefda9c769c.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/dist/address/cashaddr.d.ts +0 -78
- package/dist/address/cashaddr.d.ts.map +0 -1
- package/dist/address/cashaddr.js +0 -543
- package/dist/address/cashaddr.js.map +0 -1
- package/dist/cashaddr/cashaddr.d.ts +0 -23
- package/dist/cashaddr/cashaddr.d.ts.map +0 -1
- package/dist/cashaddr/cashaddr.js +0 -325
- package/dist/cashaddr/cashaddr.js.map +0 -1
- package/global.d.ts +0 -64
- package/test.log +0 -82
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
|
+
|
|
5
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
6
|
+
|
|
7
|
+
let cachedUint8Memory0 = null;
|
|
8
|
+
|
|
9
|
+
function getUint8Memory0() {
|
|
10
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
11
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
12
|
+
}
|
|
13
|
+
return cachedUint8Memory0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStringFromWasm0(ptr, len) {
|
|
17
|
+
ptr = ptr >>> 0;
|
|
18
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const heap = new Array(128).fill(undefined);
|
|
22
|
+
|
|
23
|
+
heap.push(undefined, null, true, false);
|
|
24
|
+
|
|
25
|
+
let heap_next = heap.length;
|
|
26
|
+
|
|
27
|
+
function addHeapObject(obj) {
|
|
28
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
29
|
+
const idx = heap_next;
|
|
30
|
+
heap_next = heap[idx];
|
|
31
|
+
|
|
32
|
+
heap[idx] = obj;
|
|
33
|
+
return idx;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let WASM_VECTOR_LEN = 0;
|
|
37
|
+
|
|
38
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
39
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
40
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
41
|
+
WASM_VECTOR_LEN = arg.length;
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let cachedInt32Memory0 = null;
|
|
46
|
+
|
|
47
|
+
function getInt32Memory0() {
|
|
48
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
|
49
|
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
50
|
+
}
|
|
51
|
+
return cachedInt32Memory0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
55
|
+
ptr = ptr >>> 0;
|
|
56
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calculate SHA512(data).
|
|
60
|
+
* @param {Uint8Array} data
|
|
61
|
+
* @returns {Uint8Array}
|
|
62
|
+
*/
|
|
63
|
+
export function sha512(data) {
|
|
64
|
+
try {
|
|
65
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
66
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
67
|
+
const len0 = WASM_VECTOR_LEN;
|
|
68
|
+
wasm.sha512(retptr, ptr0, len0);
|
|
69
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
70
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
71
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
72
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
73
|
+
return v2;
|
|
74
|
+
} finally {
|
|
75
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Calculate SHA256(SHA256(data)).
|
|
81
|
+
* @param {Uint8Array} data
|
|
82
|
+
* @returns {Uint8Array}
|
|
83
|
+
*/
|
|
84
|
+
export function sha256d(data) {
|
|
85
|
+
try {
|
|
86
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
87
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
88
|
+
const len0 = WASM_VECTOR_LEN;
|
|
89
|
+
wasm.sha256d(retptr, ptr0, len0);
|
|
90
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
91
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
92
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
93
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
94
|
+
return v2;
|
|
95
|
+
} finally {
|
|
96
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Calculate SHA256(data).
|
|
102
|
+
* @param {Uint8Array} data
|
|
103
|
+
* @returns {Uint8Array}
|
|
104
|
+
*/
|
|
105
|
+
export function sha256(data) {
|
|
106
|
+
try {
|
|
107
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
108
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
109
|
+
const len0 = WASM_VECTOR_LEN;
|
|
110
|
+
wasm.sha256(retptr, ptr0, len0);
|
|
111
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
112
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
113
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
114
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
115
|
+
return v2;
|
|
116
|
+
} finally {
|
|
117
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Calculate RIPEMD160(SHA256(data)), commonly used as address hash.
|
|
123
|
+
* @param {Uint8Array} data
|
|
124
|
+
* @returns {Uint8Array}
|
|
125
|
+
*/
|
|
126
|
+
export function shaRmd160(data) {
|
|
127
|
+
try {
|
|
128
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
129
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
130
|
+
const len0 = WASM_VECTOR_LEN;
|
|
131
|
+
wasm.shaRmd160(retptr, ptr0, len0);
|
|
132
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
133
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
134
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
135
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
136
|
+
return v2;
|
|
137
|
+
} finally {
|
|
138
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function getObject(idx) { return heap[idx]; }
|
|
143
|
+
|
|
144
|
+
function dropObject(idx) {
|
|
145
|
+
if (idx < 132) return;
|
|
146
|
+
heap[idx] = heap_next;
|
|
147
|
+
heap_next = idx;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function takeObject(idx) {
|
|
151
|
+
const ret = getObject(idx);
|
|
152
|
+
dropObject(idx);
|
|
153
|
+
return ret;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const EccFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
157
|
+
? { register: () => {}, unregister: () => {} }
|
|
158
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_ecc_free(ptr >>> 0));
|
|
159
|
+
/**
|
|
160
|
+
* ECC signatures with libsecp256k1.
|
|
161
|
+
*/
|
|
162
|
+
export class Ecc {
|
|
163
|
+
|
|
164
|
+
__destroy_into_raw() {
|
|
165
|
+
const ptr = this.__wbg_ptr;
|
|
166
|
+
this.__wbg_ptr = 0;
|
|
167
|
+
EccFinalization.unregister(this);
|
|
168
|
+
return ptr;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
free() {
|
|
172
|
+
const ptr = this.__destroy_into_raw();
|
|
173
|
+
wasm.__wbg_ecc_free(ptr);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a new Ecc instance.
|
|
177
|
+
*/
|
|
178
|
+
constructor() {
|
|
179
|
+
const ret = wasm.ecc_new();
|
|
180
|
+
this.__wbg_ptr = ret >>> 0;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Derive a public key from secret key.
|
|
185
|
+
* @param {Uint8Array} seckey
|
|
186
|
+
* @returns {Uint8Array}
|
|
187
|
+
*/
|
|
188
|
+
derivePubkey(seckey) {
|
|
189
|
+
try {
|
|
190
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
191
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
192
|
+
const len0 = WASM_VECTOR_LEN;
|
|
193
|
+
wasm.ecc_derivePubkey(retptr, this.__wbg_ptr, ptr0, len0);
|
|
194
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
195
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
196
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
197
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
198
|
+
if (r3) {
|
|
199
|
+
throw takeObject(r2);
|
|
200
|
+
}
|
|
201
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
202
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
203
|
+
return v2;
|
|
204
|
+
} finally {
|
|
205
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Sign an ECDSA signature.
|
|
210
|
+
* @param {Uint8Array} seckey
|
|
211
|
+
* @param {Uint8Array} msg
|
|
212
|
+
* @returns {Uint8Array}
|
|
213
|
+
*/
|
|
214
|
+
ecdsaSign(seckey, msg) {
|
|
215
|
+
try {
|
|
216
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
217
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
218
|
+
const len0 = WASM_VECTOR_LEN;
|
|
219
|
+
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
220
|
+
const len1 = WASM_VECTOR_LEN;
|
|
221
|
+
wasm.ecc_ecdsaSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
222
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
223
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
224
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
225
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
226
|
+
if (r3) {
|
|
227
|
+
throw takeObject(r2);
|
|
228
|
+
}
|
|
229
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
230
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
231
|
+
return v3;
|
|
232
|
+
} finally {
|
|
233
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Sign a Schnorr signature.
|
|
238
|
+
* @param {Uint8Array} seckey
|
|
239
|
+
* @param {Uint8Array} msg
|
|
240
|
+
* @returns {Uint8Array}
|
|
241
|
+
*/
|
|
242
|
+
schnorrSign(seckey, msg) {
|
|
243
|
+
try {
|
|
244
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
245
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
246
|
+
const len0 = WASM_VECTOR_LEN;
|
|
247
|
+
const ptr1 = passArray8ToWasm0(msg, wasm.__wbindgen_export_0);
|
|
248
|
+
const len1 = WASM_VECTOR_LEN;
|
|
249
|
+
wasm.ecc_schnorrSign(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
250
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
251
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
252
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
253
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
254
|
+
if (r3) {
|
|
255
|
+
throw takeObject(r2);
|
|
256
|
+
}
|
|
257
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
258
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
259
|
+
return v3;
|
|
260
|
+
} finally {
|
|
261
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Return whether the given secret key is valid, i.e. whether is of correct
|
|
266
|
+
* length (32 bytes) and is on the curve.
|
|
267
|
+
* @param {Uint8Array} seckey
|
|
268
|
+
* @returns {boolean}
|
|
269
|
+
*/
|
|
270
|
+
isValidSeckey(seckey) {
|
|
271
|
+
const ptr0 = passArray8ToWasm0(seckey, wasm.__wbindgen_export_0);
|
|
272
|
+
const len0 = WASM_VECTOR_LEN;
|
|
273
|
+
const ret = wasm.ecc_isValidSeckey(this.__wbg_ptr, ptr0, len0);
|
|
274
|
+
return ret !== 0;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Add a scalar to a secret key.
|
|
278
|
+
* @param {Uint8Array} a
|
|
279
|
+
* @param {Uint8Array} b
|
|
280
|
+
* @returns {Uint8Array}
|
|
281
|
+
*/
|
|
282
|
+
seckeyAdd(a, b) {
|
|
283
|
+
try {
|
|
284
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
285
|
+
const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
|
|
286
|
+
const len0 = WASM_VECTOR_LEN;
|
|
287
|
+
const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
|
|
288
|
+
const len1 = WASM_VECTOR_LEN;
|
|
289
|
+
wasm.ecc_seckeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
290
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
291
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
292
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
293
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
294
|
+
if (r3) {
|
|
295
|
+
throw takeObject(r2);
|
|
296
|
+
}
|
|
297
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
298
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
299
|
+
return v3;
|
|
300
|
+
} finally {
|
|
301
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Add a scalar to a public key (adding G*b).
|
|
306
|
+
* @param {Uint8Array} a
|
|
307
|
+
* @param {Uint8Array} b
|
|
308
|
+
* @returns {Uint8Array}
|
|
309
|
+
*/
|
|
310
|
+
pubkeyAdd(a, b) {
|
|
311
|
+
try {
|
|
312
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
313
|
+
const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_export_0);
|
|
314
|
+
const len0 = WASM_VECTOR_LEN;
|
|
315
|
+
const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_export_0);
|
|
316
|
+
const len1 = WASM_VECTOR_LEN;
|
|
317
|
+
wasm.ecc_pubkeyAdd(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
318
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
319
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
320
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
321
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
322
|
+
if (r3) {
|
|
323
|
+
throw takeObject(r2);
|
|
324
|
+
}
|
|
325
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
326
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
327
|
+
return v3;
|
|
328
|
+
} finally {
|
|
329
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const Sha256HFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
335
|
+
? { register: () => {}, unregister: () => {} }
|
|
336
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_sha256h_free(ptr >>> 0));
|
|
337
|
+
/**
|
|
338
|
+
* Instance to calculate SHA256 in a streaming fashion
|
|
339
|
+
*/
|
|
340
|
+
export class Sha256H {
|
|
341
|
+
|
|
342
|
+
static __wrap(ptr) {
|
|
343
|
+
ptr = ptr >>> 0;
|
|
344
|
+
const obj = Object.create(Sha256H.prototype);
|
|
345
|
+
obj.__wbg_ptr = ptr;
|
|
346
|
+
Sha256HFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
347
|
+
return obj;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
__destroy_into_raw() {
|
|
351
|
+
const ptr = this.__wbg_ptr;
|
|
352
|
+
this.__wbg_ptr = 0;
|
|
353
|
+
Sha256HFinalization.unregister(this);
|
|
354
|
+
return ptr;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
free() {
|
|
358
|
+
const ptr = this.__destroy_into_raw();
|
|
359
|
+
wasm.__wbg_sha256h_free(ptr);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Create new hasher instance
|
|
363
|
+
*/
|
|
364
|
+
constructor() {
|
|
365
|
+
const ret = wasm.sha256h_new();
|
|
366
|
+
this.__wbg_ptr = ret >>> 0;
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Feed bytes into the hasher
|
|
371
|
+
* @param {Uint8Array} data
|
|
372
|
+
*/
|
|
373
|
+
update(data) {
|
|
374
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
375
|
+
const len0 = WASM_VECTOR_LEN;
|
|
376
|
+
wasm.sha256h_update(this.__wbg_ptr, ptr0, len0);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Finalize the hash and return the result
|
|
380
|
+
* @returns {Uint8Array}
|
|
381
|
+
*/
|
|
382
|
+
finalize() {
|
|
383
|
+
try {
|
|
384
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
385
|
+
wasm.sha256h_finalize(retptr, this.__wbg_ptr);
|
|
386
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
387
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
388
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
389
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
390
|
+
return v1;
|
|
391
|
+
} finally {
|
|
392
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Clone the hasher
|
|
397
|
+
* @returns {Sha256H}
|
|
398
|
+
*/
|
|
399
|
+
clone() {
|
|
400
|
+
const ret = wasm.sha256h_clone(this.__wbg_ptr);
|
|
401
|
+
return Sha256H.__wrap(ret);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const Sha512HFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
406
|
+
? { register: () => {}, unregister: () => {} }
|
|
407
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_sha512h_free(ptr >>> 0));
|
|
408
|
+
/**
|
|
409
|
+
* Instance to calculate SHA512 in a streaming fashion
|
|
410
|
+
*/
|
|
411
|
+
export class Sha512H {
|
|
412
|
+
|
|
413
|
+
static __wrap(ptr) {
|
|
414
|
+
ptr = ptr >>> 0;
|
|
415
|
+
const obj = Object.create(Sha512H.prototype);
|
|
416
|
+
obj.__wbg_ptr = ptr;
|
|
417
|
+
Sha512HFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
418
|
+
return obj;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
__destroy_into_raw() {
|
|
422
|
+
const ptr = this.__wbg_ptr;
|
|
423
|
+
this.__wbg_ptr = 0;
|
|
424
|
+
Sha512HFinalization.unregister(this);
|
|
425
|
+
return ptr;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
free() {
|
|
429
|
+
const ptr = this.__destroy_into_raw();
|
|
430
|
+
wasm.__wbg_sha512h_free(ptr);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Create new hasher instance
|
|
434
|
+
*/
|
|
435
|
+
constructor() {
|
|
436
|
+
const ret = wasm.sha512h_new();
|
|
437
|
+
this.__wbg_ptr = ret >>> 0;
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Feed bytes into the hasher
|
|
442
|
+
* @param {Uint8Array} data
|
|
443
|
+
*/
|
|
444
|
+
update(data) {
|
|
445
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
|
|
446
|
+
const len0 = WASM_VECTOR_LEN;
|
|
447
|
+
wasm.sha512h_update(this.__wbg_ptr, ptr0, len0);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Finalize the hash and return the result
|
|
451
|
+
* @returns {Uint8Array}
|
|
452
|
+
*/
|
|
453
|
+
finalize() {
|
|
454
|
+
try {
|
|
455
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
456
|
+
wasm.sha512h_finalize(retptr, this.__wbg_ptr);
|
|
457
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
458
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
459
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
460
|
+
wasm.__wbindgen_export_1(r0, r1 * 1, 1);
|
|
461
|
+
return v1;
|
|
462
|
+
} finally {
|
|
463
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Clone the hasher
|
|
468
|
+
* @returns {Sha512H}
|
|
469
|
+
*/
|
|
470
|
+
clone() {
|
|
471
|
+
const ret = wasm.sha512h_clone(this.__wbg_ptr);
|
|
472
|
+
return Sha512H.__wrap(ret);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async function __wbg_load(module, imports) {
|
|
477
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
478
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
479
|
+
try {
|
|
480
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
481
|
+
|
|
482
|
+
} catch (e) {
|
|
483
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
484
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
485
|
+
|
|
486
|
+
} else {
|
|
487
|
+
throw e;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const bytes = await module.arrayBuffer();
|
|
493
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
494
|
+
|
|
495
|
+
} else {
|
|
496
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
497
|
+
|
|
498
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
499
|
+
return { instance, module };
|
|
500
|
+
|
|
501
|
+
} else {
|
|
502
|
+
return instance;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function __wbg_get_imports() {
|
|
508
|
+
const imports = {};
|
|
509
|
+
imports.wbg = {};
|
|
510
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
511
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
512
|
+
return addHeapObject(ret);
|
|
513
|
+
};
|
|
514
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
515
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
return imports;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function __wbg_init_memory(imports, maybe_memory) {
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function __wbg_finalize_init(instance, module) {
|
|
526
|
+
wasm = instance.exports;
|
|
527
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
528
|
+
cachedInt32Memory0 = null;
|
|
529
|
+
cachedUint8Memory0 = null;
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
return wasm;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function initSync(module) {
|
|
536
|
+
if (wasm !== undefined) return wasm;
|
|
537
|
+
|
|
538
|
+
const imports = __wbg_get_imports();
|
|
539
|
+
|
|
540
|
+
__wbg_init_memory(imports);
|
|
541
|
+
|
|
542
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
543
|
+
module = new WebAssembly.Module(module);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
547
|
+
|
|
548
|
+
return __wbg_finalize_init(instance, module);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
async function __wbg_init(input) {
|
|
552
|
+
if (wasm !== undefined) return wasm;
|
|
553
|
+
|
|
554
|
+
if (typeof input === 'undefined') {
|
|
555
|
+
input = new URL('ecash_lib_wasm_bg_browser.wasm', import.meta.url);
|
|
556
|
+
}
|
|
557
|
+
const imports = __wbg_get_imports();
|
|
558
|
+
|
|
559
|
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
560
|
+
input = fetch(input);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
__wbg_init_memory(imports);
|
|
564
|
+
|
|
565
|
+
const { instance, module } = await __wbg_load(await input, imports);
|
|
566
|
+
|
|
567
|
+
return __wbg_finalize_init(instance, module);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export { initSync }
|
|
571
|
+
export default __wbg_init;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Calculate SHA512(data).
|
|
5
|
+
* @param {Uint8Array} data
|
|
6
|
+
* @returns {Uint8Array}
|
|
7
|
+
*/
|
|
8
|
+
export function sha512(data: Uint8Array): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate SHA256(SHA256(data)).
|
|
11
|
+
* @param {Uint8Array} data
|
|
12
|
+
* @returns {Uint8Array}
|
|
13
|
+
*/
|
|
14
|
+
export function sha256d(data: Uint8Array): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Calculate SHA256(data).
|
|
17
|
+
* @param {Uint8Array} data
|
|
18
|
+
* @returns {Uint8Array}
|
|
19
|
+
*/
|
|
20
|
+
export function sha256(data: Uint8Array): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Calculate RIPEMD160(SHA256(data)), commonly used as address hash.
|
|
23
|
+
* @param {Uint8Array} data
|
|
24
|
+
* @returns {Uint8Array}
|
|
25
|
+
*/
|
|
26
|
+
export function shaRmd160(data: Uint8Array): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* ECC signatures with libsecp256k1.
|
|
29
|
+
*/
|
|
30
|
+
export class Ecc {
|
|
31
|
+
free(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new Ecc instance.
|
|
34
|
+
*/
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Derive a public key from secret key.
|
|
38
|
+
* @param {Uint8Array} seckey
|
|
39
|
+
* @returns {Uint8Array}
|
|
40
|
+
*/
|
|
41
|
+
derivePubkey(seckey: Uint8Array): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* Sign an ECDSA signature.
|
|
44
|
+
* @param {Uint8Array} seckey
|
|
45
|
+
* @param {Uint8Array} msg
|
|
46
|
+
* @returns {Uint8Array}
|
|
47
|
+
*/
|
|
48
|
+
ecdsaSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* Sign a Schnorr signature.
|
|
51
|
+
* @param {Uint8Array} seckey
|
|
52
|
+
* @param {Uint8Array} msg
|
|
53
|
+
* @returns {Uint8Array}
|
|
54
|
+
*/
|
|
55
|
+
schnorrSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
56
|
+
/**
|
|
57
|
+
* Return whether the given secret key is valid, i.e. whether is of correct
|
|
58
|
+
* length (32 bytes) and is on the curve.
|
|
59
|
+
* @param {Uint8Array} seckey
|
|
60
|
+
* @returns {boolean}
|
|
61
|
+
*/
|
|
62
|
+
isValidSeckey(seckey: Uint8Array): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Add a scalar to a secret key.
|
|
65
|
+
* @param {Uint8Array} a
|
|
66
|
+
* @param {Uint8Array} b
|
|
67
|
+
* @returns {Uint8Array}
|
|
68
|
+
*/
|
|
69
|
+
seckeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
70
|
+
/**
|
|
71
|
+
* Add a scalar to a public key (adding G*b).
|
|
72
|
+
* @param {Uint8Array} a
|
|
73
|
+
* @param {Uint8Array} b
|
|
74
|
+
* @returns {Uint8Array}
|
|
75
|
+
*/
|
|
76
|
+
pubkeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Instance to calculate SHA256 in a streaming fashion
|
|
80
|
+
*/
|
|
81
|
+
export class Sha256H {
|
|
82
|
+
free(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Create new hasher instance
|
|
85
|
+
*/
|
|
86
|
+
constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Feed bytes into the hasher
|
|
89
|
+
* @param {Uint8Array} data
|
|
90
|
+
*/
|
|
91
|
+
update(data: Uint8Array): void;
|
|
92
|
+
/**
|
|
93
|
+
* Finalize the hash and return the result
|
|
94
|
+
* @returns {Uint8Array}
|
|
95
|
+
*/
|
|
96
|
+
finalize(): Uint8Array;
|
|
97
|
+
/**
|
|
98
|
+
* Clone the hasher
|
|
99
|
+
* @returns {Sha256H}
|
|
100
|
+
*/
|
|
101
|
+
clone(): Sha256H;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Instance to calculate SHA512 in a streaming fashion
|
|
105
|
+
*/
|
|
106
|
+
export class Sha512H {
|
|
107
|
+
free(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Create new hasher instance
|
|
110
|
+
*/
|
|
111
|
+
constructor();
|
|
112
|
+
/**
|
|
113
|
+
* Feed bytes into the hasher
|
|
114
|
+
* @param {Uint8Array} data
|
|
115
|
+
*/
|
|
116
|
+
update(data: Uint8Array): void;
|
|
117
|
+
/**
|
|
118
|
+
* Finalize the hash and return the result
|
|
119
|
+
* @returns {Uint8Array}
|
|
120
|
+
*/
|
|
121
|
+
finalize(): Uint8Array;
|
|
122
|
+
/**
|
|
123
|
+
* Clone the hasher
|
|
124
|
+
* @returns {Sha512H}
|
|
125
|
+
*/
|
|
126
|
+
clone(): Sha512H;
|
|
127
|
+
}
|