ckb-vm-js 0.0.0-bootstrap.0 → 0.2.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.
@@ -0,0 +1,222 @@
1
+ let wasm;
2
+
3
+ let cachedUint8ArrayMemory0 = null;
4
+
5
+ function getUint8ArrayMemory0() {
6
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
7
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
8
+ }
9
+ return cachedUint8ArrayMemory0;
10
+ }
11
+
12
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
13
+
14
+ cachedTextDecoder.decode();
15
+
16
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
17
+ let numBytesDecoded = 0;
18
+ function decodeText(ptr, len) {
19
+ numBytesDecoded += len;
20
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
21
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
22
+ cachedTextDecoder.decode();
23
+ numBytesDecoded = len;
24
+ }
25
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
26
+ }
27
+
28
+ function getStringFromWasm0(ptr, len) {
29
+ ptr = ptr >>> 0;
30
+ return decodeText(ptr, len);
31
+ }
32
+
33
+ let WASM_VECTOR_LEN = 0;
34
+
35
+ const cachedTextEncoder = new TextEncoder();
36
+
37
+ if (!('encodeInto' in cachedTextEncoder)) {
38
+ cachedTextEncoder.encodeInto = function (arg, view) {
39
+ const buf = cachedTextEncoder.encode(arg);
40
+ view.set(buf);
41
+ return {
42
+ read: arg.length,
43
+ written: buf.length
44
+ };
45
+ }
46
+ }
47
+
48
+ function passStringToWasm0(arg, malloc, realloc) {
49
+
50
+ if (realloc === undefined) {
51
+ const buf = cachedTextEncoder.encode(arg);
52
+ const ptr = malloc(buf.length, 1) >>> 0;
53
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
54
+ WASM_VECTOR_LEN = buf.length;
55
+ return ptr;
56
+ }
57
+
58
+ let len = arg.length;
59
+ let ptr = malloc(len, 1) >>> 0;
60
+
61
+ const mem = getUint8ArrayMemory0();
62
+
63
+ let offset = 0;
64
+
65
+ for (; offset < len; offset++) {
66
+ const code = arg.charCodeAt(offset);
67
+ if (code > 0x7F) break;
68
+ mem[ptr + offset] = code;
69
+ }
70
+
71
+ if (offset !== len) {
72
+ if (offset !== 0) {
73
+ arg = arg.slice(offset);
74
+ }
75
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
76
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
77
+ const ret = cachedTextEncoder.encodeInto(arg, view);
78
+
79
+ offset += ret.written;
80
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
81
+ }
82
+
83
+ WASM_VECTOR_LEN = offset;
84
+ return ptr;
85
+ }
86
+ /**
87
+ * Returns structured JSON on both success and failure. Numbers are lossless hex strings.
88
+ * `scope=transaction` means validity relative to supplied context, not network acceptance.
89
+ * @param {string} request_json
90
+ * @returns {string}
91
+ */
92
+ export function verify(request_json) {
93
+ let deferred2_0;
94
+ let deferred2_1;
95
+ try {
96
+ const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
97
+ const len0 = WASM_VECTOR_LEN;
98
+ const ret = wasm.verify(ptr0, len0);
99
+ deferred2_0 = ret[0];
100
+ deferred2_1 = ret[1];
101
+ return getStringFromWasm0(ret[0], ret[1]);
102
+ } finally {
103
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
104
+ }
105
+ }
106
+
107
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
108
+
109
+ async function __wbg_load(module, imports) {
110
+ if (typeof Response === 'function' && module instanceof Response) {
111
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
112
+ try {
113
+ return await WebAssembly.instantiateStreaming(module, imports);
114
+
115
+ } catch (e) {
116
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
117
+
118
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
119
+ 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);
120
+
121
+ } else {
122
+ throw e;
123
+ }
124
+ }
125
+ }
126
+
127
+ const bytes = await module.arrayBuffer();
128
+ return await WebAssembly.instantiate(bytes, imports);
129
+
130
+ } else {
131
+ const instance = await WebAssembly.instantiate(module, imports);
132
+
133
+ if (instance instanceof WebAssembly.Instance) {
134
+ return { instance, module };
135
+
136
+ } else {
137
+ return instance;
138
+ }
139
+ }
140
+ }
141
+
142
+ function __wbg_get_imports() {
143
+ const imports = {};
144
+ imports.wbg = {};
145
+ imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
146
+ throw new Error(getStringFromWasm0(arg0, arg1));
147
+ };
148
+ imports.wbg.__wbindgen_init_externref_table = function() {
149
+ const table = wasm.__wbindgen_externrefs;
150
+ const offset = table.grow(4);
151
+ table.set(0, undefined);
152
+ table.set(offset + 0, undefined);
153
+ table.set(offset + 1, null);
154
+ table.set(offset + 2, true);
155
+ table.set(offset + 3, false);
156
+ ;
157
+ };
158
+
159
+ return imports;
160
+ }
161
+
162
+ function __wbg_finalize_init(instance, module) {
163
+ wasm = instance.exports;
164
+ __wbg_init.__wbindgen_wasm_module = module;
165
+ cachedUint8ArrayMemory0 = null;
166
+
167
+
168
+ wasm.__wbindgen_start();
169
+ return wasm;
170
+ }
171
+
172
+ function initSync(module) {
173
+ if (wasm !== undefined) return wasm;
174
+
175
+
176
+ if (typeof module !== 'undefined') {
177
+ if (Object.getPrototypeOf(module) === Object.prototype) {
178
+ ({module} = module)
179
+ } else {
180
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
181
+ }
182
+ }
183
+
184
+ const imports = __wbg_get_imports();
185
+
186
+ if (!(module instanceof WebAssembly.Module)) {
187
+ module = new WebAssembly.Module(module);
188
+ }
189
+
190
+ const instance = new WebAssembly.Instance(module, imports);
191
+
192
+ return __wbg_finalize_init(instance, module);
193
+ }
194
+
195
+ async function __wbg_init(module_or_path) {
196
+ if (wasm !== undefined) return wasm;
197
+
198
+
199
+ if (typeof module_or_path !== 'undefined') {
200
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
201
+ ({module_or_path} = module_or_path)
202
+ } else {
203
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
204
+ }
205
+ }
206
+
207
+ if (typeof module_or_path === 'undefined') {
208
+ module_or_path = new URL('ckb_wasm_verifier_bg.wasm', import.meta.url);
209
+ }
210
+ const imports = __wbg_get_imports();
211
+
212
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
213
+ module_or_path = fetch(module_or_path);
214
+ }
215
+
216
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
217
+
218
+ return __wbg_finalize_init(instance, module);
219
+ }
220
+
221
+ export { initSync };
222
+ export default __wbg_init;
Binary file
@@ -0,0 +1,13 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const verify: (a: number, b: number) => [number, number];
5
+ export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
6
+ export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
7
+ export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
8
+ export const rustsecp256k1_v0_10_0_default_illegal_callback_fn: (a: number, b: number) => void;
9
+ export const __wbindgen_externrefs: WebAssembly.Table;
10
+ export const __wbindgen_malloc: (a: number, b: number) => number;
11
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_start: () => void;