uhash-web 0.1.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/package.json +21 -0
- package/uhash_web.d.ts +84 -0
- package/uhash_web.js +396 -0
- package/uhash_web_bg.wasm +0 -0
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uhash-web",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "UniversalHash proof-of-work algorithm - WASM bindings for browser mining",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/cyberia-to/universal-hash"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"uhash_web_bg.wasm",
|
|
13
|
+
"uhash_web.js",
|
|
14
|
+
"uhash_web.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "uhash_web.js",
|
|
17
|
+
"types": "uhash_web.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/uhash_web.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class Benchmark {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Get algorithm parameters as JSON string
|
|
9
|
+
*/
|
|
10
|
+
get_params(): string;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Run benchmark with specified number of hashes
|
|
14
|
+
* Returns hashrate in H/s
|
|
15
|
+
*/
|
|
16
|
+
run(num_hashes: number): number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Mining struct for Web Worker usage.
|
|
21
|
+
* Reuses UniversalHash across batches to avoid 2MB re-allocation per hash.
|
|
22
|
+
*/
|
|
23
|
+
export class Miner {
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
/**
|
|
27
|
+
* Mine a batch of nonces. Returns JSON string:
|
|
28
|
+
* `{"found":true,"hash":"...","nonce":N,"count":M}` or `{"found":false,"count":M}`
|
|
29
|
+
*
|
|
30
|
+
* - `start_nonce`: first nonce to try (as f64, safe up to 2^53)
|
|
31
|
+
* - `nonce_step`: increment between nonces (for interleaved multi-worker mining)
|
|
32
|
+
* - `batch_size`: number of nonces to try in this batch
|
|
33
|
+
*/
|
|
34
|
+
mine_batch(start_nonce: number, nonce_step: number, batch_size: number): string;
|
|
35
|
+
constructor(seed_hex: string, address: string, timestamp: number, difficulty: number);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Single hash function for testing
|
|
40
|
+
*/
|
|
41
|
+
export function hash_once(input: Uint8Array): Uint8Array;
|
|
42
|
+
|
|
43
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
44
|
+
|
|
45
|
+
export interface InitOutput {
|
|
46
|
+
readonly memory: WebAssembly.Memory;
|
|
47
|
+
readonly __wbg_benchmark_free: (a: number, b: number) => void;
|
|
48
|
+
readonly __wbg_miner_free: (a: number, b: number) => void;
|
|
49
|
+
readonly benchmark_get_params: (a: number) => [number, number];
|
|
50
|
+
readonly benchmark_new: () => number;
|
|
51
|
+
readonly benchmark_run: (a: number, b: number) => number;
|
|
52
|
+
readonly hash_once: (a: number, b: number) => [number, number];
|
|
53
|
+
readonly miner_mine_batch: (a: number, b: number, c: number, d: number) => [number, number];
|
|
54
|
+
readonly miner_new: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
55
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
56
|
+
readonly __externref_table_alloc: () => number;
|
|
57
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
58
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
59
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
60
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
61
|
+
readonly __wbindgen_start: () => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
68
|
+
* a precompiled `WebAssembly.Module`.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
71
|
+
*
|
|
72
|
+
* @returns {InitOutput}
|
|
73
|
+
*/
|
|
74
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
78
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
79
|
+
*
|
|
80
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
81
|
+
*
|
|
82
|
+
* @returns {Promise<InitOutput>}
|
|
83
|
+
*/
|
|
84
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/uhash_web.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/* @ts-self-types="./uhash_web.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class Benchmark {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
BenchmarkFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_benchmark_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get algorithm parameters as JSON string
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
get_params() {
|
|
19
|
+
let deferred1_0;
|
|
20
|
+
let deferred1_1;
|
|
21
|
+
try {
|
|
22
|
+
const ret = wasm.benchmark_get_params(this.__wbg_ptr);
|
|
23
|
+
deferred1_0 = ret[0];
|
|
24
|
+
deferred1_1 = ret[1];
|
|
25
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
26
|
+
} finally {
|
|
27
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
constructor() {
|
|
31
|
+
const ret = wasm.benchmark_new();
|
|
32
|
+
this.__wbg_ptr = ret >>> 0;
|
|
33
|
+
BenchmarkFinalization.register(this, this.__wbg_ptr, this);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Run benchmark with specified number of hashes
|
|
38
|
+
* Returns hashrate in H/s
|
|
39
|
+
* @param {number} num_hashes
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
run(num_hashes) {
|
|
43
|
+
const ret = wasm.benchmark_run(this.__wbg_ptr, num_hashes);
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (Symbol.dispose) Benchmark.prototype[Symbol.dispose] = Benchmark.prototype.free;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Mining struct for Web Worker usage.
|
|
51
|
+
* Reuses UniversalHash across batches to avoid 2MB re-allocation per hash.
|
|
52
|
+
*/
|
|
53
|
+
export class Miner {
|
|
54
|
+
__destroy_into_raw() {
|
|
55
|
+
const ptr = this.__wbg_ptr;
|
|
56
|
+
this.__wbg_ptr = 0;
|
|
57
|
+
MinerFinalization.unregister(this);
|
|
58
|
+
return ptr;
|
|
59
|
+
}
|
|
60
|
+
free() {
|
|
61
|
+
const ptr = this.__destroy_into_raw();
|
|
62
|
+
wasm.__wbg_miner_free(ptr, 0);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Mine a batch of nonces. Returns JSON string:
|
|
66
|
+
* `{"found":true,"hash":"...","nonce":N,"count":M}` or `{"found":false,"count":M}`
|
|
67
|
+
*
|
|
68
|
+
* - `start_nonce`: first nonce to try (as f64, safe up to 2^53)
|
|
69
|
+
* - `nonce_step`: increment between nonces (for interleaved multi-worker mining)
|
|
70
|
+
* - `batch_size`: number of nonces to try in this batch
|
|
71
|
+
* @param {number} start_nonce
|
|
72
|
+
* @param {number} nonce_step
|
|
73
|
+
* @param {number} batch_size
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
mine_batch(start_nonce, nonce_step, batch_size) {
|
|
77
|
+
let deferred1_0;
|
|
78
|
+
let deferred1_1;
|
|
79
|
+
try {
|
|
80
|
+
const ret = wasm.miner_mine_batch(this.__wbg_ptr, start_nonce, nonce_step, batch_size);
|
|
81
|
+
deferred1_0 = ret[0];
|
|
82
|
+
deferred1_1 = ret[1];
|
|
83
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
84
|
+
} finally {
|
|
85
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @param {string} seed_hex
|
|
90
|
+
* @param {string} address
|
|
91
|
+
* @param {number} timestamp
|
|
92
|
+
* @param {number} difficulty
|
|
93
|
+
*/
|
|
94
|
+
constructor(seed_hex, address, timestamp, difficulty) {
|
|
95
|
+
const ptr0 = passStringToWasm0(seed_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
96
|
+
const len0 = WASM_VECTOR_LEN;
|
|
97
|
+
const ptr1 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
98
|
+
const len1 = WASM_VECTOR_LEN;
|
|
99
|
+
const ret = wasm.miner_new(ptr0, len0, ptr1, len1, timestamp, difficulty);
|
|
100
|
+
this.__wbg_ptr = ret >>> 0;
|
|
101
|
+
MinerFinalization.register(this, this.__wbg_ptr, this);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (Symbol.dispose) Miner.prototype[Symbol.dispose] = Miner.prototype.free;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Single hash function for testing
|
|
109
|
+
* @param {Uint8Array} input
|
|
110
|
+
* @returns {Uint8Array}
|
|
111
|
+
*/
|
|
112
|
+
export function hash_once(input) {
|
|
113
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
114
|
+
const len0 = WASM_VECTOR_LEN;
|
|
115
|
+
const ret = wasm.hash_once(ptr0, len0);
|
|
116
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
117
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
118
|
+
return v2;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function __wbg_get_imports() {
|
|
122
|
+
const import0 = {
|
|
123
|
+
__proto__: null,
|
|
124
|
+
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
|
|
125
|
+
const ret = arg0 === undefined;
|
|
126
|
+
return ret;
|
|
127
|
+
},
|
|
128
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
129
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
130
|
+
},
|
|
131
|
+
__wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
|
|
132
|
+
const ret = arg0.call(arg1);
|
|
133
|
+
return ret;
|
|
134
|
+
}, arguments); },
|
|
135
|
+
__wbg_instanceof_Window_ed49b2db8df90359: function(arg0) {
|
|
136
|
+
let result;
|
|
137
|
+
try {
|
|
138
|
+
result = arg0 instanceof Window;
|
|
139
|
+
} catch (_) {
|
|
140
|
+
result = false;
|
|
141
|
+
}
|
|
142
|
+
const ret = result;
|
|
143
|
+
return ret;
|
|
144
|
+
},
|
|
145
|
+
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
146
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
147
|
+
return ret;
|
|
148
|
+
},
|
|
149
|
+
__wbg_now_ebffdf7e580f210d: function(arg0) {
|
|
150
|
+
const ret = arg0.now();
|
|
151
|
+
return ret;
|
|
152
|
+
},
|
|
153
|
+
__wbg_performance_06f12ba62483475d: function(arg0) {
|
|
154
|
+
const ret = arg0.performance;
|
|
155
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
156
|
+
},
|
|
157
|
+
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
158
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
159
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
160
|
+
},
|
|
161
|
+
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
|
|
162
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
163
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
164
|
+
},
|
|
165
|
+
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
|
|
166
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
167
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
168
|
+
},
|
|
169
|
+
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
|
|
170
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
171
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
172
|
+
},
|
|
173
|
+
__wbindgen_init_externref_table: function() {
|
|
174
|
+
const table = wasm.__wbindgen_externrefs;
|
|
175
|
+
const offset = table.grow(4);
|
|
176
|
+
table.set(0, undefined);
|
|
177
|
+
table.set(offset + 0, undefined);
|
|
178
|
+
table.set(offset + 1, null);
|
|
179
|
+
table.set(offset + 2, true);
|
|
180
|
+
table.set(offset + 3, false);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
__proto__: null,
|
|
185
|
+
"./uhash_web_bg.js": import0,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const BenchmarkFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
190
|
+
? { register: () => {}, unregister: () => {} }
|
|
191
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_benchmark_free(ptr >>> 0, 1));
|
|
192
|
+
const MinerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
193
|
+
? { register: () => {}, unregister: () => {} }
|
|
194
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_miner_free(ptr >>> 0, 1));
|
|
195
|
+
|
|
196
|
+
function addToExternrefTable0(obj) {
|
|
197
|
+
const idx = wasm.__externref_table_alloc();
|
|
198
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
199
|
+
return idx;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
203
|
+
ptr = ptr >>> 0;
|
|
204
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getStringFromWasm0(ptr, len) {
|
|
208
|
+
ptr = ptr >>> 0;
|
|
209
|
+
return decodeText(ptr, len);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let cachedUint8ArrayMemory0 = null;
|
|
213
|
+
function getUint8ArrayMemory0() {
|
|
214
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
215
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
216
|
+
}
|
|
217
|
+
return cachedUint8ArrayMemory0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function handleError(f, args) {
|
|
221
|
+
try {
|
|
222
|
+
return f.apply(this, args);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
const idx = addToExternrefTable0(e);
|
|
225
|
+
wasm.__wbindgen_exn_store(idx);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function isLikeNone(x) {
|
|
230
|
+
return x === undefined || x === null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
234
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
235
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
236
|
+
WASM_VECTOR_LEN = arg.length;
|
|
237
|
+
return ptr;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
241
|
+
if (realloc === undefined) {
|
|
242
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
243
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
244
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
245
|
+
WASM_VECTOR_LEN = buf.length;
|
|
246
|
+
return ptr;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let len = arg.length;
|
|
250
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
251
|
+
|
|
252
|
+
const mem = getUint8ArrayMemory0();
|
|
253
|
+
|
|
254
|
+
let offset = 0;
|
|
255
|
+
|
|
256
|
+
for (; offset < len; offset++) {
|
|
257
|
+
const code = arg.charCodeAt(offset);
|
|
258
|
+
if (code > 0x7F) break;
|
|
259
|
+
mem[ptr + offset] = code;
|
|
260
|
+
}
|
|
261
|
+
if (offset !== len) {
|
|
262
|
+
if (offset !== 0) {
|
|
263
|
+
arg = arg.slice(offset);
|
|
264
|
+
}
|
|
265
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
266
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
267
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
268
|
+
|
|
269
|
+
offset += ret.written;
|
|
270
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
WASM_VECTOR_LEN = offset;
|
|
274
|
+
return ptr;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
278
|
+
cachedTextDecoder.decode();
|
|
279
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
280
|
+
let numBytesDecoded = 0;
|
|
281
|
+
function decodeText(ptr, len) {
|
|
282
|
+
numBytesDecoded += len;
|
|
283
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
284
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
285
|
+
cachedTextDecoder.decode();
|
|
286
|
+
numBytesDecoded = len;
|
|
287
|
+
}
|
|
288
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const cachedTextEncoder = new TextEncoder();
|
|
292
|
+
|
|
293
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
294
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
295
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
296
|
+
view.set(buf);
|
|
297
|
+
return {
|
|
298
|
+
read: arg.length,
|
|
299
|
+
written: buf.length
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let WASM_VECTOR_LEN = 0;
|
|
305
|
+
|
|
306
|
+
let wasmModule, wasm;
|
|
307
|
+
function __wbg_finalize_init(instance, module) {
|
|
308
|
+
wasm = instance.exports;
|
|
309
|
+
wasmModule = module;
|
|
310
|
+
cachedUint8ArrayMemory0 = null;
|
|
311
|
+
wasm.__wbindgen_start();
|
|
312
|
+
return wasm;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async function __wbg_load(module, imports) {
|
|
316
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
317
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
318
|
+
try {
|
|
319
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
320
|
+
} catch (e) {
|
|
321
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
322
|
+
|
|
323
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
324
|
+
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);
|
|
325
|
+
|
|
326
|
+
} else { throw e; }
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const bytes = await module.arrayBuffer();
|
|
331
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
332
|
+
} else {
|
|
333
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
334
|
+
|
|
335
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
336
|
+
return { instance, module };
|
|
337
|
+
} else {
|
|
338
|
+
return instance;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function expectedResponseType(type) {
|
|
343
|
+
switch (type) {
|
|
344
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function initSync(module) {
|
|
351
|
+
if (wasm !== undefined) return wasm;
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
if (module !== undefined) {
|
|
355
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
356
|
+
({module} = module)
|
|
357
|
+
} else {
|
|
358
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const imports = __wbg_get_imports();
|
|
363
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
364
|
+
module = new WebAssembly.Module(module);
|
|
365
|
+
}
|
|
366
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
367
|
+
return __wbg_finalize_init(instance, module);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function __wbg_init(module_or_path) {
|
|
371
|
+
if (wasm !== undefined) return wasm;
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
if (module_or_path !== undefined) {
|
|
375
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
376
|
+
({module_or_path} = module_or_path)
|
|
377
|
+
} else {
|
|
378
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (module_or_path === undefined) {
|
|
383
|
+
module_or_path = new URL('uhash_web_bg.wasm', import.meta.url);
|
|
384
|
+
}
|
|
385
|
+
const imports = __wbg_get_imports();
|
|
386
|
+
|
|
387
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
388
|
+
module_or_path = fetch(module_or_path);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
392
|
+
|
|
393
|
+
return __wbg_finalize_init(instance, module);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|