@pezkuwi/wasm-crypto 7.5.13 → 7.5.15
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/Cargo.toml +50 -0
- package/Xargo.toml +2 -0
- package/build/README.md +29 -0
- package/build/bundle-pezkuwi-wasm-crypto.js +2092 -0
- package/build/bundle.d.ts +40 -0
- package/build/bundle.js +505 -0
- package/build/cjs/bundle.d.ts +40 -0
- package/build/cjs/bundle.js +544 -0
- package/{index.d.ts → build/cjs/index.d.ts} +0 -1
- package/build/cjs/index.js +4 -0
- package/build/cjs/init.js +21 -0
- package/build/cjs/initNone.js +20 -0
- package/build/cjs/initOnlyAsm.js +20 -0
- package/build/cjs/initOnlyWasm.js +20 -0
- package/build/cjs/initWasmAsm.js +20 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/init.d.ts +16 -0
- package/build/init.js +17 -0
- package/build/initNone.d.ts +10 -0
- package/build/initNone.js +17 -0
- package/build/initOnlyAsm.d.ts +10 -0
- package/build/initOnlyAsm.js +17 -0
- package/build/initOnlyWasm.d.ts +10 -0
- package/build/initOnlyWasm.js +17 -0
- package/build/initWasmAsm.d.ts +10 -0
- package/build/initWasmAsm.js +17 -0
- package/build/package.json +208 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +8 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build-deno/README.md +25 -0
- package/build-deno/bundle.ts +597 -0
- package/build-deno/index.ts +2 -0
- package/build-deno/init.ts +23 -0
- package/build-deno/initNone.ts +21 -0
- package/build-deno/initOnlyAsm.ts +21 -0
- package/build-deno/initOnlyWasm.ts +21 -0
- package/build-deno/initWasmAsm.ts +21 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +12 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/rs/.editorconfig +10 -0
- package/build-tsc/bundle.d.ts +40 -0
- package/{cjs → build-tsc}/index.d.ts +0 -1
- package/build-tsc-cjs/bundle.js +544 -0
- package/{cjs → build-tsc-cjs}/index.js +0 -1
- package/build-tsc-cjs/packageDetect.js +10 -0
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/build-tsc-esm/bundle.js +505 -0
- package/{index.js → build-tsc-esm/index.js} +0 -1
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/package.json +89 -87
- package/src/bundle.ts +613 -0
- package/src/index.ts +5 -0
- package/src/init.ts +25 -0
- package/src/initNone.ts +23 -0
- package/src/initOnlyAsm.ts +23 -0
- package/src/initOnlyWasm.ts +23 -0
- package/src/initWasmAsm.ts +23 -0
- package/src/lib.rs +24 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +16 -0
- package/src/packageInfo.ts +6 -0
- package/src/rs/.editorconfig +10 -0
- package/src/rs/bip39.rs +139 -0
- package/src/rs/ed25519.rs +142 -0
- package/src/rs/hashing.rs +322 -0
- package/src/rs/secp256k1.rs +150 -0
- package/src/rs/sr25519.rs +331 -0
- package/src/rs/vrf.rs +144 -0
- package/test/all/bip39.js +86 -0
- package/test/all/ed25519.js +84 -0
- package/test/all/hashing.js +138 -0
- package/test/all/index.js +126 -0
- package/test/all/secp256k1.js +105 -0
- package/test/all/sr25519.js +211 -0
- package/test/all/vrf.js +74 -0
- package/test/asm.js +10 -0
- package/test/deno.ts +38 -0
- package/test/jest.spec.ts +25 -0
- package/test/loader-build.js +39 -0
- package/test/wasm.js +8 -0
- package/tsconfig.build.json +19 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +16 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
- package/bundle-pezkuwi-wasm-crypto.js +0 -825
- package/bundle.d.ts +0 -37
- package/bundle.js +0 -165
- package/cjs/bundle.d.ts +0 -37
- package/cjs/bundle.js +0 -171
- /package/{LICENSE → build/LICENSE} +0 -0
- /package/{init.d.ts → build/cjs/init.d.ts} +0 -0
- /package/{initNone.d.ts → build/cjs/initNone.d.ts} +0 -0
- /package/{initOnlyAsm.d.ts → build/cjs/initOnlyAsm.d.ts} +0 -0
- /package/{initOnlyWasm.d.ts → build/cjs/initOnlyWasm.d.ts} +0 -0
- /package/{initWasmAsm.d.ts → build/cjs/initWasmAsm.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{cjs → build/cjs}/packageDetect.js +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{cjs → build-tsc}/init.d.ts +0 -0
- /package/{cjs → build-tsc}/initNone.d.ts +0 -0
- /package/{cjs → build-tsc}/initOnlyAsm.d.ts +0 -0
- /package/{cjs → build-tsc}/initOnlyWasm.d.ts +0 -0
- /package/{cjs → build-tsc}/initWasmAsm.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/init.js +0 -0
- /package/{cjs → build-tsc-cjs}/initNone.js +0 -0
- /package/{cjs → build-tsc-cjs}/initOnlyAsm.js +0 -0
- /package/{cjs → build-tsc-cjs}/initOnlyWasm.js +0 -0
- /package/{cjs → build-tsc-cjs}/initWasmAsm.js +0 -0
- /package/{init.js → build-tsc-esm/init.js} +0 -0
- /package/{initNone.js → build-tsc-esm/initNone.js} +0 -0
- /package/{initOnlyAsm.js → build-tsc-esm/initOnlyAsm.js} +0 -0
- /package/{initOnlyWasm.js → build-tsc-esm/initOnlyWasm.js} +0 -0
- /package/{initWasmAsm.js → build-tsc-esm/initWasmAsm.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bridge = exports.packageInfo = void 0;
|
|
4
|
+
exports.isReady = isReady;
|
|
5
|
+
exports.waitReady = waitReady;
|
|
6
|
+
exports.getSigningContext = getSigningContext;
|
|
7
|
+
exports.sr25519KeypairFromSeed = sr25519KeypairFromSeed;
|
|
8
|
+
exports.sr25519Sign = sr25519Sign;
|
|
9
|
+
exports.sr25519Verify = sr25519Verify;
|
|
10
|
+
exports.bip39Validate = bip39Validate;
|
|
11
|
+
exports.bip39Generate = bip39Generate;
|
|
12
|
+
exports.bip39ToEntropy = bip39ToEntropy;
|
|
13
|
+
exports.bip39ToMiniSecret = bip39ToMiniSecret;
|
|
14
|
+
exports.bip39ToSeed = bip39ToSeed;
|
|
15
|
+
exports.ed25519KeypairFromSeed = ed25519KeypairFromSeed;
|
|
16
|
+
exports.ed25519Sign = ed25519Sign;
|
|
17
|
+
exports.ed25519Verify = ed25519Verify;
|
|
18
|
+
exports.sr25519Agree = sr25519Agree;
|
|
19
|
+
exports.sr25519DeriveKeypairHard = sr25519DeriveKeypairHard;
|
|
20
|
+
exports.sr25519DeriveKeypairSoft = sr25519DeriveKeypairSoft;
|
|
21
|
+
exports.sr25519DerivePublicSoft = sr25519DerivePublicSoft;
|
|
22
|
+
exports.vrfSign = vrfSign;
|
|
23
|
+
exports.vrfVerify = vrfVerify;
|
|
24
|
+
exports.secp256k1FromSeed = secp256k1FromSeed;
|
|
25
|
+
exports.secp256k1Compress = secp256k1Compress;
|
|
26
|
+
exports.secp256k1Expand = secp256k1Expand;
|
|
27
|
+
exports.secp256k1Recover = secp256k1Recover;
|
|
28
|
+
exports.secp256k1Sign = secp256k1Sign;
|
|
29
|
+
exports.blake2b = blake2b;
|
|
30
|
+
exports.hmacSha256 = hmacSha256;
|
|
31
|
+
exports.hmacSha512 = hmacSha512;
|
|
32
|
+
exports.keccak256 = keccak256;
|
|
33
|
+
exports.keccak512 = keccak512;
|
|
34
|
+
exports.pbkdf2 = pbkdf2;
|
|
35
|
+
exports.scrypt = scrypt;
|
|
36
|
+
exports.sha256 = sha256;
|
|
37
|
+
exports.sha512 = sha512;
|
|
38
|
+
exports.twox = twox;
|
|
39
|
+
const wasm_crypto_wasm_1 = require("@pezkuwi/wasm-crypto-wasm");
|
|
40
|
+
var packageInfo_js_1 = require("./packageInfo.js");
|
|
41
|
+
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
42
|
+
let wasm = null;
|
|
43
|
+
let cachedUint8ArrayMemory = null;
|
|
44
|
+
let cachedTextDecoder = null;
|
|
45
|
+
let _isReady = false;
|
|
46
|
+
let initPromise = null;
|
|
47
|
+
let WASM_VECTOR_LEN = 0;
|
|
48
|
+
function getUint8ArrayMemory() {
|
|
49
|
+
if (cachedUint8ArrayMemory === null || cachedUint8ArrayMemory.byteLength === 0) {
|
|
50
|
+
cachedUint8ArrayMemory = new Uint8Array(wasm['memory'].buffer);
|
|
51
|
+
}
|
|
52
|
+
return cachedUint8ArrayMemory;
|
|
53
|
+
}
|
|
54
|
+
function getStringFromWasm(ptr, len) {
|
|
55
|
+
if (!cachedTextDecoder) {
|
|
56
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
57
|
+
cachedTextDecoder.decode();
|
|
58
|
+
}
|
|
59
|
+
ptr = ptr >>> 0;
|
|
60
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory().subarray(ptr, ptr + len));
|
|
61
|
+
}
|
|
62
|
+
function getArrayU8FromWasm(ptr, len) {
|
|
63
|
+
ptr = ptr >>> 0;
|
|
64
|
+
return getUint8ArrayMemory().subarray(ptr / 1, ptr / 1 + len);
|
|
65
|
+
}
|
|
66
|
+
function passArray8ToWasm(arg, malloc) {
|
|
67
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
68
|
+
getUint8ArrayMemory().set(arg, ptr / 1);
|
|
69
|
+
WASM_VECTOR_LEN = arg.length;
|
|
70
|
+
return ptr;
|
|
71
|
+
}
|
|
72
|
+
function addToExternrefTable(obj) {
|
|
73
|
+
const idx = wasm['__externref_table_alloc']();
|
|
74
|
+
wasm['__wbindgen_externrefs'].set(idx, obj);
|
|
75
|
+
return idx;
|
|
76
|
+
}
|
|
77
|
+
function takeFromExternrefTable(idx) {
|
|
78
|
+
const value = wasm['__wbindgen_externrefs'].get(idx);
|
|
79
|
+
wasm['__externref_table_dealloc'](idx);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
function isLikeNone(x) {
|
|
83
|
+
return x === undefined || x === null;
|
|
84
|
+
}
|
|
85
|
+
function handleError(f, args) {
|
|
86
|
+
try {
|
|
87
|
+
return f.apply(null, args);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
const idx = addToExternrefTable(e);
|
|
91
|
+
wasm['__wbindgen_exn_store'](idx);
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function createImports() {
|
|
96
|
+
const import0 = {
|
|
97
|
+
__proto__: null,
|
|
98
|
+
__wbg___wbindgen_is_function_0095a73b8b156f76: function (arg0) {
|
|
99
|
+
return typeof (arg0) === 'function';
|
|
100
|
+
},
|
|
101
|
+
__wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function (arg0) {
|
|
102
|
+
const val = arg0;
|
|
103
|
+
return typeof (val) === 'object' && val !== null;
|
|
104
|
+
},
|
|
105
|
+
__wbg___wbindgen_is_string_cd444516edc5b180: function (arg0) {
|
|
106
|
+
return typeof (arg0) === 'string';
|
|
107
|
+
},
|
|
108
|
+
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function (arg0) {
|
|
109
|
+
return arg0 === undefined;
|
|
110
|
+
},
|
|
111
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function (arg0, arg1) {
|
|
112
|
+
throw new Error(getStringFromWasm(arg0, arg1));
|
|
113
|
+
},
|
|
114
|
+
__wbg_call_389efe28435a9388: function () {
|
|
115
|
+
return handleError(function (arg0, arg1) {
|
|
116
|
+
return arg0.call(arg1);
|
|
117
|
+
}, arguments);
|
|
118
|
+
},
|
|
119
|
+
__wbg_call_4708e0c13bdc8e95: function () {
|
|
120
|
+
return handleError(function (arg0, arg1, arg2) {
|
|
121
|
+
return arg0.call(arg1, arg2);
|
|
122
|
+
}, arguments);
|
|
123
|
+
},
|
|
124
|
+
__wbg_crypto_86f2631e91b51511: function (arg0) {
|
|
125
|
+
return arg0.crypto;
|
|
126
|
+
},
|
|
127
|
+
__wbg_getRandomValues_b3f15fcbfabb0f8b: function () {
|
|
128
|
+
return handleError(function (arg0, arg1) {
|
|
129
|
+
arg0.getRandomValues(arg1);
|
|
130
|
+
}, arguments);
|
|
131
|
+
},
|
|
132
|
+
__wbg_length_32ed9a279acd054c: function (arg0) {
|
|
133
|
+
return arg0.length;
|
|
134
|
+
},
|
|
135
|
+
__wbg_msCrypto_d562bbe83e0d4b91: function (arg0) {
|
|
136
|
+
return arg0.msCrypto;
|
|
137
|
+
},
|
|
138
|
+
__wbg_new_no_args_1c7c842f08d00ebb: function (arg0, arg1) {
|
|
139
|
+
return new Function(getStringFromWasm(arg0, arg1));
|
|
140
|
+
},
|
|
141
|
+
__wbg_new_with_length_a2c39cbe88fd8ff1: function (arg0) {
|
|
142
|
+
return new Uint8Array(arg0 >>> 0);
|
|
143
|
+
},
|
|
144
|
+
__wbg_node_e1f24f89a7336c2e: function (arg0) {
|
|
145
|
+
return arg0.node;
|
|
146
|
+
},
|
|
147
|
+
__wbg_process_3975fd6c72f520aa: function (arg0) {
|
|
148
|
+
return arg0.process;
|
|
149
|
+
},
|
|
150
|
+
__wbg_prototypesetcall_bdcdcc5842e4d77d: function (arg0, arg1, arg2) {
|
|
151
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm(arg0, arg1), arg2);
|
|
152
|
+
},
|
|
153
|
+
__wbg_randomFillSync_f8c153b79f285817: function () {
|
|
154
|
+
return handleError(function (arg0, arg1) {
|
|
155
|
+
arg0.randomFillSync(arg1);
|
|
156
|
+
}, arguments);
|
|
157
|
+
},
|
|
158
|
+
__wbg_require_b74f47fc2d022fd6: function () {
|
|
159
|
+
return handleError(function () {
|
|
160
|
+
return typeof module !== 'undefined' ? module.require : undefined;
|
|
161
|
+
}, arguments);
|
|
162
|
+
},
|
|
163
|
+
__wbg_static_accessor_GLOBAL_12837167ad935116: function () {
|
|
164
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
165
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable(ret);
|
|
166
|
+
},
|
|
167
|
+
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function () {
|
|
168
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
169
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable(ret);
|
|
170
|
+
},
|
|
171
|
+
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function () {
|
|
172
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
173
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable(ret);
|
|
174
|
+
},
|
|
175
|
+
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function () {
|
|
176
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
177
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable(ret);
|
|
178
|
+
},
|
|
179
|
+
__wbg_subarray_a96e1fef17ed23cb: function (arg0, arg1, arg2) {
|
|
180
|
+
return arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
181
|
+
},
|
|
182
|
+
__wbg_versions_4e31226f5e8dc909: function (arg0) {
|
|
183
|
+
return arg0.versions;
|
|
184
|
+
},
|
|
185
|
+
__wbindgen_cast_0000000000000001: function (arg0, arg1) {
|
|
186
|
+
return getArrayU8FromWasm(arg0, arg1);
|
|
187
|
+
},
|
|
188
|
+
__wbindgen_cast_0000000000000002: function (arg0, arg1) {
|
|
189
|
+
return getStringFromWasm(arg0, arg1);
|
|
190
|
+
},
|
|
191
|
+
__wbindgen_init_externref_table: function () {
|
|
192
|
+
const table = wasm['__wbindgen_externrefs'];
|
|
193
|
+
const offset = table.grow(4);
|
|
194
|
+
table.set(0, undefined);
|
|
195
|
+
table.set(offset + 0, undefined);
|
|
196
|
+
table.set(offset + 1, null);
|
|
197
|
+
table.set(offset + 2, true);
|
|
198
|
+
table.set(offset + 3, false);
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
__proto__: null,
|
|
203
|
+
'./pezkuwi_wasm_crypto_bg.js': import0,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function initWasm() {
|
|
207
|
+
if (_isReady)
|
|
208
|
+
return true;
|
|
209
|
+
try {
|
|
210
|
+
// wasmBytes is already decompressed by @pezkuwi/wasm-crypto-wasm
|
|
211
|
+
const imports = createImports();
|
|
212
|
+
const result = await WebAssembly.instantiate(wasm_crypto_wasm_1.wasmBytes, imports);
|
|
213
|
+
wasm = result.instance.exports;
|
|
214
|
+
// Initialize the module
|
|
215
|
+
if (typeof wasm['__wbindgen_start'] === 'function') {
|
|
216
|
+
wasm['__wbindgen_start']();
|
|
217
|
+
}
|
|
218
|
+
_isReady = true;
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
console.error('FATAL: Unable to initialize @pezkuwi/wasm-crypto:', error.message);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.bridge = {
|
|
227
|
+
wasm: null,
|
|
228
|
+
type: 'wasm'
|
|
229
|
+
};
|
|
230
|
+
function isReady() {
|
|
231
|
+
return _isReady;
|
|
232
|
+
}
|
|
233
|
+
async function waitReady() {
|
|
234
|
+
if (!initPromise) {
|
|
235
|
+
initPromise = initWasm();
|
|
236
|
+
}
|
|
237
|
+
return initPromise;
|
|
238
|
+
}
|
|
239
|
+
function getSigningContext() {
|
|
240
|
+
if (!wasm)
|
|
241
|
+
throw new Error('WASM not initialized');
|
|
242
|
+
const ret = wasm['get_signing_context']();
|
|
243
|
+
const str = getStringFromWasm(ret[0], ret[1]);
|
|
244
|
+
wasm['__wbindgen_free'](ret[0], ret[1], 1);
|
|
245
|
+
return str;
|
|
246
|
+
}
|
|
247
|
+
function sr25519KeypairFromSeed(seed) {
|
|
248
|
+
if (!wasm)
|
|
249
|
+
throw new Error('WASM not initialized');
|
|
250
|
+
const ptr0 = passArray8ToWasm(seed, wasm['__wbindgen_malloc']);
|
|
251
|
+
const len0 = WASM_VECTOR_LEN;
|
|
252
|
+
const ret = wasm['sr25519_keypair_from_seed'](ptr0, len0);
|
|
253
|
+
if (ret[3]) {
|
|
254
|
+
throw takeFromExternrefTable(ret[2]);
|
|
255
|
+
}
|
|
256
|
+
const v2 = getArrayU8FromWasm(ret[0], ret[1]).slice();
|
|
257
|
+
wasm['__wbindgen_free'](ret[0], ret[1] * 1, 1);
|
|
258
|
+
return v2;
|
|
259
|
+
}
|
|
260
|
+
function sr25519Sign(publicKey, secretKey, message) {
|
|
261
|
+
if (!wasm)
|
|
262
|
+
throw new Error('WASM not initialized');
|
|
263
|
+
const ptr0 = passArray8ToWasm(publicKey, wasm['__wbindgen_malloc']);
|
|
264
|
+
const len0 = WASM_VECTOR_LEN;
|
|
265
|
+
const ptr1 = passArray8ToWasm(secretKey, wasm['__wbindgen_malloc']);
|
|
266
|
+
const len1 = WASM_VECTOR_LEN;
|
|
267
|
+
const ptr2 = passArray8ToWasm(message, wasm['__wbindgen_malloc']);
|
|
268
|
+
const len2 = WASM_VECTOR_LEN;
|
|
269
|
+
const ret = wasm['sr25519_sign'](ptr0, len0, ptr1, len1, ptr2, len2);
|
|
270
|
+
if (ret[3]) {
|
|
271
|
+
throw takeFromExternrefTable(ret[2]);
|
|
272
|
+
}
|
|
273
|
+
const v4 = getArrayU8FromWasm(ret[0], ret[1]).slice();
|
|
274
|
+
wasm['__wbindgen_free'](ret[0], ret[1] * 1, 1);
|
|
275
|
+
return v4;
|
|
276
|
+
}
|
|
277
|
+
function sr25519Verify(signature, message, publicKey) {
|
|
278
|
+
if (!wasm)
|
|
279
|
+
throw new Error('WASM not initialized');
|
|
280
|
+
const ptr0 = passArray8ToWasm(signature, wasm['__wbindgen_malloc']);
|
|
281
|
+
const len0 = WASM_VECTOR_LEN;
|
|
282
|
+
const ptr1 = passArray8ToWasm(message, wasm['__wbindgen_malloc']);
|
|
283
|
+
const len1 = WASM_VECTOR_LEN;
|
|
284
|
+
const ptr2 = passArray8ToWasm(publicKey, wasm['__wbindgen_malloc']);
|
|
285
|
+
const len2 = WASM_VECTOR_LEN;
|
|
286
|
+
const ret = wasm['sr25519_verify'](ptr0, len0, ptr1, len1, ptr2, len2);
|
|
287
|
+
return ret !== 0;
|
|
288
|
+
}
|
|
289
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
290
|
+
const sha512_1 = require("@noble/hashes/sha512");
|
|
291
|
+
const pbkdf2_1 = require("@noble/hashes/pbkdf2");
|
|
292
|
+
const blake2b_1 = require("@noble/hashes/blake2b");
|
|
293
|
+
const hmac_1 = require("@noble/hashes/hmac");
|
|
294
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
295
|
+
function normalizeString(str) {
|
|
296
|
+
return (str || '').normalize('NFKD');
|
|
297
|
+
}
|
|
298
|
+
function bip39Validate(phrase) {
|
|
299
|
+
try {
|
|
300
|
+
const words = normalizeString(phrase).split(' ');
|
|
301
|
+
return [12, 15, 18, 21, 24].includes(words.length);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const BIP39_WORDLIST = 'abandon|ability|able|about|above|absent|absorb|abstract|absurd|abuse|access|accident|account|accuse|achieve|acid|acoustic|acquire|across|act|action|actor|actress|actual|adapt|add|addict|address|adjust|admit|adult|advance|advice|aerobic|affair|afford|afraid|again|age|agent|agree|ahead|aim|air|airport|aisle|alarm|album|alcohol|alert|alien|all|alley|allow|almost|alone|alpha|already|also|alter|always|amateur|amazing|among|amount|amused|analyst|anchor|ancient|anger|angle|angry|animal|ankle|announce|annual|another|answer|antenna|antique|anxiety|any|apart|apology|appear|apple|approve|april|arch|arctic|area|arena|argue|arm|armed|armor|army|around|arrange|arrest|arrive|arrow|art|artefact|artist|artwork|ask|aspect|assault|asset|assist|assume|asthma|athlete|atom|attack|attend|attitude|attract|auction|audit|august|aunt|author|auto|autumn|average|avocado|avoid|awake|aware|away|awesome|awful|awkward|axis|baby|bachelor|bacon|badge|bag|balance|balcony|ball|bamboo|banana|banner|bar|barely|bargain|barrel|base|basic|basket|battle|beach|bean|beauty|because|become|beef|before|begin|behave|behind|believe|below|belt|bench|benefit|best|betray|better|between|beyond|bicycle|bid|bike|bind|biology|bird|birth|bitter|black|blade|blame|blanket|blast|bleak|bless|blind|blood|blossom|blouse|blue|blur|blush|board|boat|body|boil|bomb|bone|bonus|book|boost|border|boring|borrow|boss|bottom|bounce|box|boy|bracket|brain|brand|brass|brave|bread|breeze|brick|bridge|brief|bright|bring|brisk|broccoli|broken|bronze|broom|brother|brown|brush|bubble|buddy|budget|buffalo|build|bulb|bulk|bullet|bundle|bunker|burden|burger|burst|bus|business|busy|butter|buyer|buzz|cabbage|cabin|cable|cactus|cage|cake|call|calm|camera|camp|can|canal|cancel|candy|cannon|canoe|canvas|canyon|capable|capital|captain|car|carbon|card|cargo|carpet|carry|cart|case|cash|casino|castle|casual|cat|catalog|catch|category|cattle|caught|cause|caution|cave|ceiling|celery|cement|census|century|cereal|certain|chair|chalk|champion|change|chaos|chapter|charge|chase|chat|cheap|check|cheese|chef|cherry|chest|chicken|chief|child|chimney|choice|choose|chronic|chuckle|chunk|churn|cigar|cinnamon|circle|citizen|city|civil|claim|clap|clarify|claw|clay|clean|clerk|clever|click|client|cliff|climb|clinic|clip|clock|clog|close|cloth|cloud|clown|club|clump|cluster|clutch|coach|coast|coconut|code|coffee|coil|coin|collect|color|column|combine|come|comfort|comic|common|company|concert|conduct|confirm|congress|connect|consider|control|convince|cook|cool|copper|copy|coral|core|corn|correct|cost|cotton|couch|country|couple|course|cousin|cover|coyote|crack|cradle|craft|cram|crane|crash|crater|crawl|crazy|cream|credit|creek|crew|cricket|crime|crisp|critic|crop|cross|crouch|crowd|crucial|cruel|cruise|crumble|crunch|crush|cry|crystal|cube|culture|cup|cupboard|curious|current|curtain|curve|cushion|custom|cute|cycle|dad|damage|damp|dance|danger|daring|dash|daughter|dawn|day|deal|debate|debris|decade|december|decide|decline|decorate|decrease|deer|defense|define|defy|degree|delay|deliver|demand|demise|denial|dentist|deny|depart|depend|deposit|depth|deputy|derive|describe|desert|design|desk|despair|destroy|detail|detect|develop|device|devote|diagram|dial|diamond|diary|dice|diesel|diet|differ|digital|dignity|dilemma|dinner|dinosaur|direct|dirt|disagree|discover|disease|dish|dismiss|disorder|display|distance|divert|divide|divorce|dizzy|doctor|document|dog|doll|dolphin|domain|donate|donkey|donor|door|dose|double|dove|draft|dragon|drama|drastic|draw|dream|dress|drift|drill|drink|drip|drive|drop|drum|dry|duck|dumb|dune|during|dust|dutch|duty|dwarf|dynamic|eager|eagle|early|earn|earth|easily|east|easy|echo|ecology|economy|edge|edit|educate|effort|egg|eight|either|elbow|elder|electric|elegant|element|elephant|elevator|elite|else|embark|embody|embrace|emerge|emotion|employ|empower|empty|enable|enact|end|endless|endorse|enemy|energy|enforce|engage|engine|enhance|enjoy|enlist|enough|enrich|enroll|ensure|enter|entire|entry|envelope|episode|equal|equip|era|erase|erode|erosion|error|erupt|escape|essay|essence|estate|eternal|ethics|evidence|evil|evoke|evolve|exact|example|excess|exchange|excite|exclude|excuse|execute|exercise|exhaust|exhibit|exile|exist|exit|exotic|expand|expect|expire|explain|expose|express|extend|extra|eye|eyebrow|fabric|face|faculty|fade|faint|faith|fall|false|fame|family|famous|fan|fancy|fantasy|farm|fashion|fat|fatal|father|fatigue|fault|favorite|feature|february|federal|fee|feed|feel|female|fence|festival|fetch|fever|few|fiber|fiction|field|figure|file|film|filter|final|find|fine|finger|finish|fire|firm|first|fiscal|fish|fit|fitness|fix|flag|flame|flash|flat|flavor|flee|flight|flip|float|flock|floor|flower|fluid|flush|fly|foam|focus|fog|foil|fold|follow|food|foot|force|forest|forget|fork|fortune|forum|forward|fossil|foster|found|fox|fragile|frame|frequent|fresh|friend|fringe|frog|front|frost|frown|frozen|fruit|fuel|fun|funny|furnace|fury|future|gadget|gain|galaxy|gallery|game|gap|garage|garbage|garden|garlic|garment|gas|gasp|gate|gather|gauge|gaze|general|genius|genre|gentle|genuine|gesture|ghost|giant|gift|giggle|ginger|giraffe|girl|give|glad|glance|glare|glass|glide|glimpse|globe|gloom|glory|glove|glow|glue|goat|goddess|gold|good|goose|gorilla|gospel|gossip|govern|gown|grab|grace|grain|grant|grape|grass|gravity|great|green|grid|grief|grit|grocery|group|grow|grunt|guard|guess|guide|guilt|guitar|gun|gym|habit|hair|half|hammer|hamster|hand|happy|harbor|hard|harsh|harvest|hat|have|hawk|hazard|head|health|heart|heavy|hedgehog|height|hello|helmet|help|hen|hero|hidden|high|hill|hint|hip|hire|history|hobby|hockey|hold|hole|holiday|hollow|home|honey|hood|hope|horn|horror|horse|hospital|host|hotel|hour|hover|hub|huge|human|humble|humor|hundred|hungry|hunt|hurdle|hurry|hurt|husband|hybrid|ice|icon|idea|identify|idle|ignore|ill|illegal|illness|image|imitate|immense|immune|impact|impose|improve|impulse|inch|include|income|increase|index|indicate|indoor|industry|infant|inflict|inform|inhale|inherit|initial|inject|injury|inmate|inner|innocent|input|inquiry|insane|insect|inside|inspire|install|intact|interest|into|invest|invite|involve|iron|island|isolate|issue|item|ivory|jacket|jaguar|jar|jazz|jealous|jeans|jelly|jewel|job|join|joke|journey|joy|judge|juice|jump|jungle|junior|junk|just|kangaroo|keen|keep|ketchup|key|kick|kid|kidney|kind|kingdom|kiss|kit|kitchen|kite|kitten|kiwi|knee|knife|knock|know|lab|label|labor|ladder|lady|lake|lamp|language|laptop|large|later|latin|laugh|laundry|lava|law|lawn|lawsuit|layer|lazy|leader|leaf|learn|leave|lecture|left|leg|legal|legend|leisure|lemon|lend|length|lens|leopard|lesson|letter|level|liar|liberty|library|license|life|lift|light|like|limb|limit|link|lion|liquid|list|little|live|lizard|load|loan|lobster|local|lock|logic|lonely|long|loop|lottery|loud|lounge|love|loyal|lucky|luggage|lumber|lunar|lunch|luxury|lyrics|machine|mad|magic|magnet|maid|mail|main|major|make|mammal|man|manage|mandate|mango|mansion|manual|maple|marble|march|margin|marine|market|marriage|mask|mass|master|match|material|math|matrix|matter|maximum|maze|meadow|mean|measure|meat|mechanic|medal|media|melody|melt|member|memory|mention|menu|mercy|merge|merit|merry|mesh|message|metal|method|middle|midnight|milk|million|mimic|mind|minimum|minor|minute|miracle|mirror|misery|miss|mistake|mix|mixed|mixture|mobile|model|modify|mom|moment|monitor|monkey|monster|month|moon|moral|more|morning|mosquito|mother|motion|motor|mountain|mouse|move|movie|much|muffin|mule|multiply|muscle|museum|mushroom|music|must|mutual|myself|mystery|myth|naive|name|napkin|narrow|nasty|nation|nature|near|neck|need|negative|neglect|neither|nephew|nerve|nest|net|network|neutral|never|news|next|nice|night|noble|noise|nominee|noodle|normal|north|nose|notable|note|nothing|notice|novel|now|nuclear|number|nurse|nut|oak|obey|object|oblige|obscure|observe|obtain|obvious|occur|ocean|october|odor|off|offer|office|often|oil|okay|old|olive|olympic|omit|once|one|onion|online|only|open|opera|opinion|oppose|option|orange|orbit|orchard|order|ordinary|organ|orient|original|orphan|ostrich|other|outdoor|outer|output|outside|oval|oven|over|own|owner|oxygen|oyster|ozone|pact|paddle|page|pair|palace|palm|panda|panel|panic|panther|paper|parade|parent|park|parrot|party|pass|patch|path|patient|patrol|pattern|pause|pave|payment|peace|peanut|pear|peasant|pelican|pen|penalty|pencil|people|pepper|perfect|permit|person|pet|phone|photo|phrase|physical|piano|picnic|picture|piece|pig|pigeon|pill|pilot|pink|pioneer|pipe|pistol|pitch|pizza|place|planet|plastic|plate|play|please|pledge|pluck|plug|plunge|poem|poet|point|polar|pole|police|pond|pony|pool|popular|portion|position|possible|post|potato|pottery|poverty|powder|power|practice|praise|predict|prefer|prepare|present|pretty|prevent|price|pride|primary|print|priority|prison|private|prize|problem|process|produce|profit|program|project|promote|proof|property|prosper|protect|proud|provide|public|pudding|pull|pulp|pulse|pumpkin|punch|pupil|puppy|purchase|purity|purpose|purse|push|put|puzzle|pyramid|quality|quantum|quarter|question|quick|quit|quiz|quote|rabbit|raccoon|race|rack|radar|radio|rail|rain|raise|rally|ramp|ranch|random|range|rapid|rare|rate|rather|raven|raw|razor|ready|real|reason|rebel|rebuild|recall|receive|recipe|record|recycle|reduce|reflect|reform|refuse|region|regret|regular|reject|relax|release|relief|rely|remain|remember|remind|remove|render|renew|rent|reopen|repair|repeat|replace|report|require|rescue|resemble|resist|resource|response|result|retire|retreat|return|reunion|reveal|review|reward|rhythm|rib|ribbon|rice|rich|ride|ridge|rifle|right|rigid|ring|riot|ripple|risk|ritual|rival|river|road|roast|robot|robust|rocket|romance|roof|rookie|room|rose|rotate|rough|round|route|royal|rubber|rude|rug|rule|run|runway|rural|sad|saddle|sadness|safe|sail|salad|salmon|salon|salt|salute|same|sample|sand|satisfy|satoshi|sauce|sausage|save|say|scale|scan|scare|scatter|scene|scheme|school|science|scissors|scorpion|scout|scrap|screen|script|scrub|sea|search|season|seat|second|secret|section|security|seed|seek|segment|select|sell|seminar|senior|sense|sentence|series|service|session|settle|setup|seven|shadow|shaft|shallow|share|shed|shell|sheriff|shield|shift|shine|ship|shiver|shock|shoe|shoot|shop|short|shoulder|shove|shrimp|shrug|shuffle|shy|sibling|sick|side|siege|sight|sign|silent|silk|silly|silver|similar|simple|since|sing|siren|sister|situate|six|size|skate|sketch|ski|skill|skin|skirt|skull|slab|slam|sleep|slender|slice|slide|slight|slim|slogan|slot|slow|slush|small|smart|smile|smoke|smooth|snack|snake|snap|sniff|snow|soap|soccer|social|sock|soda|soft|solar|soldier|solid|solution|solve|someone|song|soon|sorry|sort|soul|sound|soup|source|south|space|spare|spatial|spawn|speak|special|speed|spell|spend|sphere|spice|spider|spike|spin|spirit|split|spoil|sponsor|spoon|sport|spot|spray|spread|spring|spy|square|squeeze|squirrel|stable|stadium|staff|stage|stairs|stamp|stand|start|state|stay|steak|steel|stem|step|stereo|stick|still|sting|stock|stomach|stone|stool|story|stove|strategy|street|strike|strong|struggle|student|stuff|stumble|style|subject|submit|subway|success|such|sudden|suffer|sugar|suggest|suit|summer|sun|sunny|sunset|super|supply|supreme|sure|surface|surge|surprise|surround|survey|suspect|sustain|swallow|swamp|swap|swarm|swear|sweet|swift|swim|swing|switch|sword|symbol|symptom|syrup|system|table|tackle|tag|tail|talent|talk|tank|tape|target|task|taste|tattoo|taxi|teach|team|tell|ten|tenant|tennis|tent|term|test|text|thank|that|theme|then|theory|there|they|thing|this|thought|three|thrive|throw|thumb|thunder|ticket|tide|tiger|tilt|timber|time|tiny|tip|tired|tissue|title|toast|tobacco|today|toddler|toe|together|toilet|token|tomato|tomorrow|tone|tongue|tonight|tool|tooth|top|topic|topple|torch|tornado|tortoise|toss|total|tourist|toward|tower|town|toy|track|trade|traffic|tragic|train|transfer|trap|trash|travel|tray|treat|tree|trend|trial|tribe|trick|trigger|trim|trip|trophy|trouble|truck|true|truly|trumpet|trust|truth|try|tube|tuition|tumble|tuna|tunnel|turkey|turn|turtle|twelve|twenty|twice|twin|twist|two|type|typical|ugly|umbrella|unable|unaware|uncle|uncover|under|undo|unfair|unfold|unhappy|uniform|unique|unit|universe|unknown|unlock|until|unusual|unveil|update|upgrade|uphold|upon|upper|upset|urban|urge|usage|use|used|useful|useless|usual|utility|vacant|vacuum|vague|valid|valley|valve|van|vanish|vapor|various|vast|vault|vehicle|velvet|vendor|venture|venue|verb|verify|version|very|vessel|veteran|viable|vibrant|vicious|victory|video|view|village|vintage|violin|virtual|virus|visa|visit|visual|vital|vivid|vocal|voice|void|volcano|volume|vote|voyage|wage|wagon|wait|walk|wall|walnut|want|warfare|warm|warrior|wash|wasp|waste|water|wave|way|wealth|weapon|wear|weasel|weather|web|wedding|weekend|weird|welcome|west|wet|whale|what|wheat|wheel|when|where|whip|whisper|wide|width|wife|wild|will|win|window|wine|wing|wink|winner|winter|wire|wisdom|wise|wish|witness|wolf|woman|wonder|wood|wool|word|work|world|worry|worth|wrap|wreck|wrestle|wrist|write|wrong|yard|year|yellow|you|young|youth|zebra|zero|zone|zoo'.split('|');
|
|
308
|
+
function binaryToByte(bin) {
|
|
309
|
+
return parseInt(bin, 2);
|
|
310
|
+
}
|
|
311
|
+
function bytesToBinary(bytes) {
|
|
312
|
+
return bytes.map((x) => x.toString(2).padStart(8, '0')).join('');
|
|
313
|
+
}
|
|
314
|
+
function deriveChecksumBits(entropyBuffer) {
|
|
315
|
+
const hash = (0, sha256_1.sha256)(entropyBuffer);
|
|
316
|
+
return bytesToBinary(Array.from(hash)).slice(0, (entropyBuffer.length * 8) / 32);
|
|
317
|
+
}
|
|
318
|
+
function bip39Generate(_words) {
|
|
319
|
+
throw new Error('bip39Generate: use @pezkuwi/util-crypto mnemonicGenerate instead');
|
|
320
|
+
}
|
|
321
|
+
function bip39ToEntropy(phrase) {
|
|
322
|
+
const words = normalizeString(phrase).split(' ');
|
|
323
|
+
if (words.length % 3 !== 0) {
|
|
324
|
+
throw new Error('Invalid mnemonic');
|
|
325
|
+
}
|
|
326
|
+
// convert word indices to 11 bit binary strings
|
|
327
|
+
const bits = words
|
|
328
|
+
.map((word) => {
|
|
329
|
+
const index = BIP39_WORDLIST.indexOf(word);
|
|
330
|
+
if (index === -1) {
|
|
331
|
+
throw new Error('Invalid mnemonic');
|
|
332
|
+
}
|
|
333
|
+
return index.toString(2).padStart(11, '0');
|
|
334
|
+
})
|
|
335
|
+
.join('');
|
|
336
|
+
// split the binary string into ENT/CS
|
|
337
|
+
const dividerIndex = Math.floor(bits.length / 33) * 32;
|
|
338
|
+
const entropyBits = bits.slice(0, dividerIndex);
|
|
339
|
+
const checksumBits = bits.slice(dividerIndex);
|
|
340
|
+
// calculate the checksum and compare
|
|
341
|
+
const matched = entropyBits.match(/(.{1,8})/g);
|
|
342
|
+
const entropyBytes = matched?.map(binaryToByte);
|
|
343
|
+
if (!entropyBytes || (entropyBytes.length % 4 !== 0) || (entropyBytes.length < 16) || (entropyBytes.length > 32)) {
|
|
344
|
+
throw new Error('Invalid entropy');
|
|
345
|
+
}
|
|
346
|
+
const entropy = new Uint8Array(entropyBytes);
|
|
347
|
+
if (deriveChecksumBits(entropy) !== checksumBits) {
|
|
348
|
+
throw new Error('Invalid mnemonic checksum');
|
|
349
|
+
}
|
|
350
|
+
return entropy;
|
|
351
|
+
}
|
|
352
|
+
function bip39ToMiniSecret(phrase, password) {
|
|
353
|
+
// Substrate uses entropy-based derivation (not BIP39's mnemonic string PBKDF2)
|
|
354
|
+
const entropy = bip39ToEntropy(phrase);
|
|
355
|
+
const salt = new TextEncoder().encode(`mnemonic${normalizeString(password)}`);
|
|
356
|
+
// PBKDF2 on the entropy, not the mnemonic string
|
|
357
|
+
return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, entropy, salt, { c: 2048, dkLen: 64 }).slice(0, 32);
|
|
358
|
+
}
|
|
359
|
+
function bip39ToSeed(phrase, password) {
|
|
360
|
+
const salt = new TextEncoder().encode(`mnemonic${normalizeString(password)}`);
|
|
361
|
+
const input = new TextEncoder().encode(normalizeString(phrase));
|
|
362
|
+
return (0, pbkdf2_1.pbkdf2)(sha256_1.sha256, input, salt, { c: 2048, dkLen: 64 });
|
|
363
|
+
}
|
|
364
|
+
function ed25519KeypairFromSeed(_seed) {
|
|
365
|
+
throw new Error('ed25519KeypairFromSeed not yet implemented');
|
|
366
|
+
}
|
|
367
|
+
function ed25519Sign(_publicKey, _secretKey, _message) {
|
|
368
|
+
throw new Error('ed25519Sign not yet implemented');
|
|
369
|
+
}
|
|
370
|
+
function ed25519Verify(_signature, _message, _publicKey) {
|
|
371
|
+
throw new Error('ed25519Verify not yet implemented');
|
|
372
|
+
}
|
|
373
|
+
function sr25519Agree(_publicKey, _secretKey) {
|
|
374
|
+
throw new Error('sr25519Agree not yet implemented');
|
|
375
|
+
}
|
|
376
|
+
function sr25519DeriveKeypairHard(_pair, _cc) {
|
|
377
|
+
throw new Error('sr25519DeriveKeypairHard not yet implemented');
|
|
378
|
+
}
|
|
379
|
+
function sr25519DeriveKeypairSoft(_pair, _cc) {
|
|
380
|
+
throw new Error('sr25519DeriveKeypairSoft not yet implemented');
|
|
381
|
+
}
|
|
382
|
+
function sr25519DerivePublicSoft(_publicKey, _cc) {
|
|
383
|
+
throw new Error('sr25519DerivePublicSoft not yet implemented');
|
|
384
|
+
}
|
|
385
|
+
function vrfSign(_secretKey, _context, _message, _extra) {
|
|
386
|
+
throw new Error('vrfSign not yet implemented');
|
|
387
|
+
}
|
|
388
|
+
function vrfVerify(_publicKey, _context, _message, _extra, _outAndProof) {
|
|
389
|
+
throw new Error('vrfVerify not yet implemented');
|
|
390
|
+
}
|
|
391
|
+
function secp256k1FromSeed(_seed) {
|
|
392
|
+
throw new Error('secp256k1FromSeed not yet implemented');
|
|
393
|
+
}
|
|
394
|
+
function secp256k1Compress(_publicKey) {
|
|
395
|
+
throw new Error('secp256k1Compress not yet implemented');
|
|
396
|
+
}
|
|
397
|
+
function secp256k1Expand(_publicKey) {
|
|
398
|
+
throw new Error('secp256k1Expand not yet implemented');
|
|
399
|
+
}
|
|
400
|
+
function secp256k1Recover(_msgHash, _signature, _recoveryId) {
|
|
401
|
+
throw new Error('secp256k1Recover not yet implemented');
|
|
402
|
+
}
|
|
403
|
+
function secp256k1Sign(_msgHash, _secretKey) {
|
|
404
|
+
throw new Error('secp256k1Sign not yet implemented');
|
|
405
|
+
}
|
|
406
|
+
function blake2b(data, key, size) {
|
|
407
|
+
// size is already in bytes (passed by util-crypto's blake2AsU8a)
|
|
408
|
+
if (key && key.length > 0) {
|
|
409
|
+
return (0, blake2b_1.blake2b)(data, { dkLen: size, key });
|
|
410
|
+
}
|
|
411
|
+
return (0, blake2b_1.blake2b)(data, { dkLen: size });
|
|
412
|
+
}
|
|
413
|
+
function hmacSha256(key, data) {
|
|
414
|
+
return (0, hmac_1.hmac)(sha256_1.sha256, key, data);
|
|
415
|
+
}
|
|
416
|
+
function hmacSha512(key, data) {
|
|
417
|
+
return (0, hmac_1.hmac)(sha512_1.sha512, key, data);
|
|
418
|
+
}
|
|
419
|
+
function keccak256(data) {
|
|
420
|
+
return (0, sha3_1.keccak_256)(data);
|
|
421
|
+
}
|
|
422
|
+
function keccak512(data) {
|
|
423
|
+
return (0, sha3_1.keccak_512)(data);
|
|
424
|
+
}
|
|
425
|
+
function pbkdf2(data, salt, rounds) {
|
|
426
|
+
return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, data, salt, { c: rounds, dkLen: 64 });
|
|
427
|
+
}
|
|
428
|
+
function scrypt(_password, _salt, _log2n, _r, _p) {
|
|
429
|
+
// scrypt is rarely used - defer to @noble/hashes/scrypt if needed
|
|
430
|
+
throw new Error('scrypt not yet implemented - use @pezkuwi/util-crypto scryptSync instead');
|
|
431
|
+
}
|
|
432
|
+
function sha256(data) {
|
|
433
|
+
return (0, sha256_1.sha256)(data);
|
|
434
|
+
}
|
|
435
|
+
function sha512(data) {
|
|
436
|
+
return (0, sha512_1.sha512)(data);
|
|
437
|
+
}
|
|
438
|
+
const P64_1 = BigInt('11400714785074694791');
|
|
439
|
+
const P64_2 = BigInt('14029467366897019727');
|
|
440
|
+
const P64_3 = BigInt('1609587929392839161');
|
|
441
|
+
const P64_4 = BigInt('9650029242287828579');
|
|
442
|
+
const P64_5 = BigInt('2870177450012600261');
|
|
443
|
+
const U64 = BigInt('0xffffffffffffffff');
|
|
444
|
+
const _0n = BigInt(0);
|
|
445
|
+
const _1n = BigInt(1);
|
|
446
|
+
const _7n = BigInt(7);
|
|
447
|
+
const _11n = BigInt(11);
|
|
448
|
+
const _12n = BigInt(12);
|
|
449
|
+
const _16n = BigInt(16);
|
|
450
|
+
const _18n = BigInt(18);
|
|
451
|
+
const _23n = BigInt(23);
|
|
452
|
+
const _27n = BigInt(27);
|
|
453
|
+
const _29n = BigInt(29);
|
|
454
|
+
const _31n = BigInt(31);
|
|
455
|
+
const _32n = BigInt(32);
|
|
456
|
+
const _33n = BigInt(33);
|
|
457
|
+
const _64n = BigInt(64);
|
|
458
|
+
const _256n = BigInt(256);
|
|
459
|
+
function rotl(a, b) {
|
|
460
|
+
const c = a & U64;
|
|
461
|
+
return ((c << b) | (c >> (_64n - b))) & U64;
|
|
462
|
+
}
|
|
463
|
+
function fromU8a(u8a, p, count) {
|
|
464
|
+
const bigints = new Array(count);
|
|
465
|
+
let offset = 0;
|
|
466
|
+
for (let i = 0; i < count; i++, offset += 2) {
|
|
467
|
+
bigints[i] = BigInt(u8a[p + offset] | (u8a[p + 1 + offset] << 8));
|
|
468
|
+
}
|
|
469
|
+
let result = _0n;
|
|
470
|
+
for (let i = count - 1; i >= 0; i--) {
|
|
471
|
+
result = (result << _16n) + bigints[i];
|
|
472
|
+
}
|
|
473
|
+
return result;
|
|
474
|
+
}
|
|
475
|
+
function xxhashInit(seed, input) {
|
|
476
|
+
const state = {
|
|
477
|
+
seed,
|
|
478
|
+
u8a: new Uint8Array(32),
|
|
479
|
+
u8asize: 0,
|
|
480
|
+
v1: seed + P64_1 + P64_2,
|
|
481
|
+
v2: seed + P64_2,
|
|
482
|
+
v3: seed,
|
|
483
|
+
v4: seed - P64_1
|
|
484
|
+
};
|
|
485
|
+
if (input.length < 32) {
|
|
486
|
+
state.u8a.set(input);
|
|
487
|
+
state.u8asize = input.length;
|
|
488
|
+
return state;
|
|
489
|
+
}
|
|
490
|
+
const limit = input.length - 32;
|
|
491
|
+
let p = 0;
|
|
492
|
+
if (limit >= 0) {
|
|
493
|
+
const adjustV = (v) => P64_1 * rotl(v + P64_2 * fromU8a(input, p, 4), _31n);
|
|
494
|
+
do {
|
|
495
|
+
state.v1 = adjustV(state.v1);
|
|
496
|
+
p += 8;
|
|
497
|
+
state.v2 = adjustV(state.v2);
|
|
498
|
+
p += 8;
|
|
499
|
+
state.v3 = adjustV(state.v3);
|
|
500
|
+
p += 8;
|
|
501
|
+
state.v4 = adjustV(state.v4);
|
|
502
|
+
p += 8;
|
|
503
|
+
} while (p <= limit);
|
|
504
|
+
}
|
|
505
|
+
if (p < input.length) {
|
|
506
|
+
state.u8a.set(input.subarray(p, input.length));
|
|
507
|
+
state.u8asize = input.length - p;
|
|
508
|
+
}
|
|
509
|
+
return state;
|
|
510
|
+
}
|
|
511
|
+
function xxhash64(input, initSeed) {
|
|
512
|
+
const { seed, u8a, u8asize, v1, v2, v3, v4 } = xxhashInit(BigInt(initSeed), input);
|
|
513
|
+
let p = 0;
|
|
514
|
+
let h64 = U64 & (BigInt(input.length) + (input.length >= 32
|
|
515
|
+
? (((((((((rotl(v1, _1n) + rotl(v2, _7n) + rotl(v3, _12n) + rotl(v4, _18n)) ^ (P64_1 * rotl(v1 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v2 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v3 * P64_2, _31n))) * P64_1 + P64_4) ^ (P64_1 * rotl(v4 * P64_2, _31n))) * P64_1 + P64_4)
|
|
516
|
+
: (seed + P64_5)));
|
|
517
|
+
while (p <= (u8asize - 8)) {
|
|
518
|
+
h64 = U64 & (P64_4 + P64_1 * rotl(h64 ^ (P64_1 * rotl(P64_2 * fromU8a(u8a, p, 4), _31n)), _27n));
|
|
519
|
+
p += 8;
|
|
520
|
+
}
|
|
521
|
+
if ((p + 4) <= u8asize) {
|
|
522
|
+
h64 = U64 & (P64_3 + P64_2 * rotl(h64 ^ (P64_1 * fromU8a(u8a, p, 2)), _23n));
|
|
523
|
+
p += 4;
|
|
524
|
+
}
|
|
525
|
+
while (p < u8asize) {
|
|
526
|
+
h64 = U64 & (P64_1 * rotl(h64 ^ (P64_5 * BigInt(u8a[p++])), _11n));
|
|
527
|
+
}
|
|
528
|
+
h64 = U64 & (P64_2 * (h64 ^ (h64 >> _33n)));
|
|
529
|
+
h64 = U64 & (P64_3 * (h64 ^ (h64 >> _29n)));
|
|
530
|
+
h64 = U64 & (h64 ^ (h64 >> _32n));
|
|
531
|
+
const result = new Uint8Array(8);
|
|
532
|
+
for (let i = 7; i >= 0; i--) {
|
|
533
|
+
result[i] = Number(h64 % _256n);
|
|
534
|
+
h64 = h64 / _256n;
|
|
535
|
+
}
|
|
536
|
+
return result;
|
|
537
|
+
}
|
|
538
|
+
function twox(data, rounds) {
|
|
539
|
+
const result = new Uint8Array(rounds * 8);
|
|
540
|
+
for (let seed = 0; seed < rounds; seed++) {
|
|
541
|
+
result.set(xxhash64(data, seed).reverse(), seed * 8);
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("@pezkuwi/util");
|
|
4
|
+
const packageInfo_1 = require("@pezkuwi/wasm-bridge/packageInfo");
|
|
5
|
+
const packageInfo_2 = require("@pezkuwi/wasm-crypto-asmjs/packageInfo");
|
|
6
|
+
const packageInfo_3 = require("@pezkuwi/wasm-crypto-init/packageInfo");
|
|
7
|
+
const packageInfo_4 = require("@pezkuwi/wasm-crypto-wasm/packageInfo");
|
|
8
|
+
const packageInfo_5 = require("@pezkuwi/wasm-util/packageInfo");
|
|
9
|
+
const packageInfo_js_1 = require("./packageInfo.js");
|
|
10
|
+
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_2.packageInfo, packageInfo_1.packageInfo, packageInfo_3.packageInfo, packageInfo_5.packageInfo, packageInfo_4.packageInfo]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@pezkuwi/wasm-crypto', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '7.5.
|
|
4
|
+
exports.packageInfo = { name: '@pezkuwi/wasm-crypto', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '7.5.15' };
|