build(pow-solver): add wasm-pack pkg artifacts
ZhenYi committed
Added lib/pow-solver/pkg/pow_solver.d.ts lib/pow-solver/pkg/pow_solver.d.ts +42 −0 View lib/pow-solver/pkg/pow_solver.d.ts
@@ -0,0 +1,42 @@
1/* tslint:disable */
2/* eslint-disable */
3
4export function check(nonce: string, difficulty: number, answer: string): boolean;
5
6export function solve(nonce: string, difficulty: number, max_attempts: number): string;
7
8export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
9
10export interface InitOutput {
11 readonly memory: WebAssembly.Memory;
12 readonly check: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
13 readonly solve: (a: number, b: number, c: number, d: number) => [number, number, number, number];
14 readonly __wbindgen_externrefs: WebAssembly.Table;
15 readonly __wbindgen_malloc: (a: number, b: number) => number;
16 readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
17 readonly __externref_table_dealloc: (a: number) => void;
18 readonly __wbindgen_free: (a: number, b: number, c: number) => void;
19 readonly __wbindgen_start: () => void;
20}
21
22export type SyncInitInput = BufferSource | WebAssembly.Module;
23
24/**
25 * Instantiates the given `module`, which can either be bytes or
26 * a precompiled `WebAssembly.Module`.
27 *
28 * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
29 *
30 * @returns {InitOutput}
31 */
32export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
33
34/**
35 * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
36 * for everything else, calls `WebAssembly.instantiate` directly.
37 *
38 * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
39 *
40 * @returns {Promise<InitOutput>}
41 */
42export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
Added lib/pow-solver/pkg/pow_solver.js lib/pow-solver/pkg/pow_solver.js +249 −0 View lib/pow-solver/pkg/pow_solver.js
@@ -0,0 +1,249 @@
1/* @ts-self-types="./pow_solver.d.ts" */
2
3/**
4 * @param {string} nonce
5 * @param {number} difficulty
6 * @param {string} answer
7 * @returns {boolean}
8 */
9export function check(nonce, difficulty, answer) {
10 const ptr0 = passStringToWasm0(nonce, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
11 const len0 = WASM_VECTOR_LEN;
12 const ptr1 = passStringToWasm0(answer, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13 const len1 = WASM_VECTOR_LEN;
14 const ret = wasm.check(ptr0, len0, difficulty, ptr1, len1);
15 if (ret[2]) {
16 throw takeFromExternrefTable0(ret[1]);
17 }
18 return ret[0] !== 0;
19}
20
21/**
22 * @param {string} nonce
23 * @param {number} difficulty
24 * @param {number} max_attempts
25 * @returns {string}
26 */
27export function solve(nonce, difficulty, max_attempts) {
28 let deferred3_0;
29 let deferred3_1;
30 try {
31 const ptr0 = passStringToWasm0(nonce, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
32 const len0 = WASM_VECTOR_LEN;
33 const ret = wasm.solve(ptr0, len0, difficulty, max_attempts);
34 var ptr2 = ret[0];
35 var len2 = ret[1];
36 if (ret[3]) {
37 ptr2 = 0; len2 = 0;
38 throw takeFromExternrefTable0(ret[2]);
39 }
40 deferred3_0 = ptr2;
41 deferred3_1 = len2;
42 return getStringFromWasm0(ptr2, len2);
43 } finally {
44 wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
45 }
46}
47function __wbg_get_imports() {
48 const import0 = {
49 __proto__: null,
50 __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
51 const ret = Error(getStringFromWasm0(arg0, arg1));
52 return ret;
53 },
54 __wbindgen_init_externref_table: function() {
55 const table = wasm.__wbindgen_externrefs;
56 const offset = table.grow(4);
57 table.set(0, undefined);
58 table.set(offset + 0, undefined);
59 table.set(offset + 1, null);
60 table.set(offset + 2, true);
61 table.set(offset + 3, false);
62 },
63 };
64 return {
65 __proto__: null,
66 "./pow_solver_bg.js": import0,
67 };
68}
69
70function getStringFromWasm0(ptr, len) {
71 return decodeText(ptr >>> 0, len);
72}
73
74let cachedUint8ArrayMemory0 = null;
75function getUint8ArrayMemory0() {
76 if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
77 cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
78 }
79 return cachedUint8ArrayMemory0;
80}
81
82function passStringToWasm0(arg, malloc, realloc) {
83 if (realloc === undefined) {
84 const buf = cachedTextEncoder.encode(arg);
85 const ptr = malloc(buf.length, 1) >>> 0;
86 getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
87 WASM_VECTOR_LEN = buf.length;
88 return ptr;
89 }
90
91 let len = arg.length;
92 let ptr = malloc(len, 1) >>> 0;
93
94 const mem = getUint8ArrayMemory0();
95
96 let offset = 0;
97
98 for (; offset < len; offset++) {
99 const code = arg.charCodeAt(offset);
100 if (code > 0x7F) break;
101 mem[ptr + offset] = code;
102 }
103 if (offset !== len) {
104 if (offset !== 0) {
105 arg = arg.slice(offset);
106 }
107 ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
108 const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
109 const ret = cachedTextEncoder.encodeInto(arg, view);
110
111 offset += ret.written;
112 ptr = realloc(ptr, len, offset, 1) >>> 0;
113 }
114
115 WASM_VECTOR_LEN = offset;
116 return ptr;
117}
118
119function takeFromExternrefTable0(idx) {
120 const value = wasm.__wbindgen_externrefs.get(idx);
121 wasm.__externref_table_dealloc(idx);
122 return value;
123}
124
125let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
126cachedTextDecoder.decode();
127const MAX_SAFARI_DECODE_BYTES = 2146435072;
128let numBytesDecoded = 0;
129function decodeText(ptr, len) {
130 numBytesDecoded += len;
131 if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
132 cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
133 cachedTextDecoder.decode();
134 numBytesDecoded = len;
135 }
136 return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
137}
138
139const cachedTextEncoder = new TextEncoder();
140
141if (!('encodeInto' in cachedTextEncoder)) {
142 cachedTextEncoder.encodeInto = function (arg, view) {
143 const buf = cachedTextEncoder.encode(arg);
144 view.set(buf);
145 return {
146 read: arg.length,
147 written: buf.length
148 };
149 };
150}
151
152let WASM_VECTOR_LEN = 0;
153
154let wasmModule, wasmInstance, wasm;
155function __wbg_finalize_init(instance, module) {
156 wasmInstance = instance;
157 wasm = instance.exports;
158 wasmModule = module;
159 cachedUint8ArrayMemory0 = null;
160 wasm.__wbindgen_start();
161 return wasm;
162}
163
164async function __wbg_load(module, imports) {
165 if (typeof Response === 'function' && module instanceof Response) {
166 if (!module.ok) {
167 throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
168 }
169
170 if (typeof WebAssembly.instantiateStreaming === 'function') {
171 try {
172 return await WebAssembly.instantiateStreaming(module, imports);
173 } catch (e) {
174 const validResponse = expectedResponseType(module.type);
175
176 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
177 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);
178
179 } else { throw e; }
180 }
181 }
182
183 const bytes = await module.arrayBuffer();
184 return await WebAssembly.instantiate(bytes, imports);
185 } else {
186 const instance = await WebAssembly.instantiate(module, imports);
187
188 if (instance instanceof WebAssembly.Instance) {
189 return { instance, module };
190 } else {
191 return instance;
192 }
193 }
194
195 function expectedResponseType(type) {
196 switch (type) {
197 case 'basic': case 'cors': case 'default': return true;
198 }
199 return false;
200 }
201}
202
203function initSync(module) {
204 if (wasm !== undefined) return wasm;
205
206
207 if (module !== undefined) {
208 if (Object.getPrototypeOf(module) === Object.prototype) {
209 ({module} = module)
210 } else {
211 console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
212 }
213 }
214
215 const imports = __wbg_get_imports();
216 if (!(module instanceof WebAssembly.Module)) {
217 module = new WebAssembly.Module(module);
218 }
219 const instance = new WebAssembly.Instance(module, imports);
220 return __wbg_finalize_init(instance, module);
221}
222
223async function __wbg_init(module_or_path) {
224 if (wasm !== undefined) return wasm;
225
226
227 if (module_or_path !== undefined) {
228 if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
229 ({module_or_path} = module_or_path)
230 } else {
231 console.warn('using deprecated parameters for the initialization function; pass a single object instead')
232 }
233 }
234
235 if (module_or_path === undefined) {
236 module_or_path = new URL('pow_solver_bg.wasm', import.meta.url);
237 }
238 const imports = __wbg_get_imports();
239
240 if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
241 module_or_path = fetch(module_or_path);
242 }
243
244 const { instance, module } = await __wbg_load(await module_or_path, imports);
245
246 return __wbg_finalize_init(instance, module);
247}
248
249export { initSync, __wbg_init as default };
Added lib/pow-solver/pkg/pow_solver_bg.wasm lib/pow-solver/pkg/pow_solver_bg.wasm +0 −0 View lib/pow-solver/pkg/pow_solver_bg.wasm
Binary file not shown.
Added lib/pow-solver/pkg/pow_solver_bg.wasm.d.ts lib/pow-solver/pkg/pow_solver_bg.wasm.d.ts +11 −0 View lib/pow-solver/pkg/pow_solver_bg.wasm.d.ts
@@ -0,0 +1,11 @@
1/* tslint:disable */
2/* eslint-disable */
3export const memory: WebAssembly.Memory;
4export const check: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
5export const solve: (a: number, b: number, c: number, d: number) => [number, number, number, number];
6export const __wbindgen_externrefs: WebAssembly.Table;
7export const __wbindgen_malloc: (a: number, b: number) => number;
8export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
9export const __externref_table_dealloc: (a: number) => void;
10export const __wbindgen_free: (a: number, b: number, c: number) => void;
11export const __wbindgen_start: () => void;