@tychosdk/disasm 0.2.0 → 0.2.1

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.
@@ -25,29 +25,35 @@ function handleError(f, args) {
25
25
  wasm.__wbindgen_exn_store(idx);
26
26
  }
27
27
  }
28
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available'); } });
29
- if (typeof TextDecoder !== 'undefined') {
30
- cachedTextDecoder.decode();
28
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
29
+ cachedTextDecoder.decode();
30
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
31
+ let numBytesDecoded = 0;
32
+ function decodeText(ptr, len) {
33
+ numBytesDecoded += len;
34
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
35
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
36
+ cachedTextDecoder.decode();
37
+ numBytesDecoded = len;
38
+ }
39
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
31
40
  }
32
- ;
33
41
  function getStringFromWasm0(ptr, len) {
34
42
  ptr = ptr >>> 0;
35
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
43
+ return decodeText(ptr, len);
36
44
  }
37
45
  let WASM_VECTOR_LEN = 0;
38
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available'); } });
39
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
40
- ? function (arg, view) {
41
- return cachedTextEncoder.encodeInto(arg, view);
42
- }
43
- : function (arg, view) {
46
+ const cachedTextEncoder = new TextEncoder();
47
+ if (!('encodeInto' in cachedTextEncoder)) {
48
+ cachedTextEncoder.encodeInto = function (arg, view) {
44
49
  const buf = cachedTextEncoder.encode(arg);
45
50
  view.set(buf);
46
51
  return {
47
52
  read: arg.length,
48
53
  written: buf.length
49
54
  };
50
- });
55
+ };
56
+ }
51
57
  function passStringToWasm0(arg, malloc, realloc) {
52
58
  if (realloc === undefined) {
53
59
  const buf = cachedTextEncoder.encode(arg);
@@ -72,7 +78,7 @@ function passStringToWasm0(arg, malloc, realloc) {
72
78
  }
73
79
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
74
80
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
75
- const ret = encodeString(arg, view);
81
+ const ret = cachedTextEncoder.encodeInto(arg, view);
76
82
  offset += ret.written;
77
83
  ptr = realloc(ptr, len, offset, 1) >>> 0;
78
84
  }
@@ -97,6 +103,7 @@ export function disasm_structured(code) {
97
103
  }
98
104
  return takeFromExternrefTable0(ret[0]);
99
105
  }
106
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
100
107
  async function __wbg_load(module, imports) {
101
108
  if (typeof Response === 'function' && module instanceof Response) {
102
109
  if (typeof WebAssembly.instantiateStreaming === 'function') {
@@ -104,7 +111,8 @@ async function __wbg_load(module, imports) {
104
111
  return await WebAssembly.instantiateStreaming(module, imports);
105
112
  }
106
113
  catch (e) {
107
- if (module.headers.get('Content-Type') != 'application/wasm') {
114
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
115
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
108
116
  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);
109
117
  }
110
118
  else {
@@ -133,6 +141,14 @@ function __wbg_get_imports() {
133
141
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
134
142
  }, arguments);
135
143
  };
144
+ imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function (arg0, arg1) {
145
+ throw new Error(getStringFromWasm0(arg0, arg1));
146
+ };
147
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function (arg0, arg1) {
148
+ // Cast intrinsic for `Ref(String) -> Externref`.
149
+ const ret = getStringFromWasm0(arg0, arg1);
150
+ return ret;
151
+ };
136
152
  imports.wbg.__wbindgen_init_externref_table = function () {
137
153
  const table = wasm.__wbindgen_export_2;
138
154
  const offset = table.grow(4);
@@ -143,13 +159,6 @@ function __wbg_get_imports() {
143
159
  table.set(offset + 3, false);
144
160
  ;
145
161
  };
146
- imports.wbg.__wbindgen_string_new = function (arg0, arg1) {
147
- const ret = getStringFromWasm0(arg0, arg1);
148
- return ret;
149
- };
150
- imports.wbg.__wbindgen_throw = function (arg0, arg1) {
151
- throw new Error(getStringFromWasm0(arg0, arg1));
152
- };
153
162
  return imports;
154
163
  }
155
164
  function __wbg_init_memory(imports, memory) {
Binary file
@@ -1,7 +1,6 @@
1
1
  export function disasm_structured(code: string): string;
2
2
  export function __wbg_getRandomValues_3c9c0d586e575a16(...args: any[]): any;
3
+ export function __wbg_wbindgenthrow_451ec1a8469d7eb6(arg0: any, arg1: any): never;
4
+ export function __wbindgen_cast_2241b6af4c4b2941(arg0: any, arg1: any): string;
3
5
  export function __wbindgen_init_externref_table(): void;
4
- export function __wbindgen_string_new(arg0: any, arg1: any): string;
5
- export function __wbindgen_throw(arg0: any, arg1: any): never;
6
- export { wasm as __wasm };
7
- declare let wasm: any;
6
+ export const __wasm: WebAssembly.Exports;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  let imports = {};
3
3
  imports['wbg'] = module.exports;
4
- let wasm;
5
- const { TextDecoder, TextEncoder } = require(`util`);
6
4
  let cachedUint8ArrayMemory0 = null;
7
5
  function getUint8ArrayMemory0() {
8
6
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -30,24 +28,25 @@ function handleError(f, args) {
30
28
  }
31
29
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
32
30
  cachedTextDecoder.decode();
31
+ function decodeText(ptr, len) {
32
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
33
+ }
33
34
  function getStringFromWasm0(ptr, len) {
34
35
  ptr = ptr >>> 0;
35
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
36
+ return decodeText(ptr, len);
36
37
  }
37
38
  let WASM_VECTOR_LEN = 0;
38
- let cachedTextEncoder = new TextEncoder('utf-8');
39
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
40
- ? function (arg, view) {
41
- return cachedTextEncoder.encodeInto(arg, view);
42
- }
43
- : function (arg, view) {
39
+ const cachedTextEncoder = new TextEncoder();
40
+ if (!('encodeInto' in cachedTextEncoder)) {
41
+ cachedTextEncoder.encodeInto = function (arg, view) {
44
42
  const buf = cachedTextEncoder.encode(arg);
45
43
  view.set(buf);
46
44
  return {
47
45
  read: arg.length,
48
46
  written: buf.length
49
47
  };
50
- });
48
+ };
49
+ }
51
50
  function passStringToWasm0(arg, malloc, realloc) {
52
51
  if (realloc === undefined) {
53
52
  const buf = cachedTextEncoder.encode(arg);
@@ -72,7 +71,7 @@ function passStringToWasm0(arg, malloc, realloc) {
72
71
  }
73
72
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
74
73
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
75
- const ret = encodeString(arg, view);
74
+ const ret = cachedTextEncoder.encodeInto(arg, view);
76
75
  offset += ret.written;
77
76
  ptr = realloc(ptr, len, offset, 1) >>> 0;
78
77
  }
@@ -88,7 +87,7 @@ function takeFromExternrefTable0(idx) {
88
87
  * @param {string} code
89
88
  * @returns {string}
90
89
  */
91
- module.exports.disasm_structured = function (code) {
90
+ exports.disasm_structured = function (code) {
92
91
  const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
93
92
  const len0 = WASM_VECTOR_LEN;
94
93
  const ret = wasm.disasm_structured(ptr0, len0);
@@ -97,12 +96,20 @@ module.exports.disasm_structured = function (code) {
97
96
  }
98
97
  return takeFromExternrefTable0(ret[0]);
99
98
  };
100
- module.exports.__wbg_getRandomValues_3c9c0d586e575a16 = function () {
99
+ exports.__wbg_getRandomValues_3c9c0d586e575a16 = function () {
101
100
  return handleError(function (arg0, arg1) {
102
101
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
103
102
  }, arguments);
104
103
  };
105
- module.exports.__wbindgen_init_externref_table = function () {
104
+ exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function (arg0, arg1) {
105
+ throw new Error(getStringFromWasm0(arg0, arg1));
106
+ };
107
+ exports.__wbindgen_cast_2241b6af4c4b2941 = function (arg0, arg1) {
108
+ // Cast intrinsic for `Ref(String) -> Externref`.
109
+ const ret = getStringFromWasm0(arg0, arg1);
110
+ return ret;
111
+ };
112
+ exports.__wbindgen_init_externref_table = function () {
106
113
  const table = wasm.__wbindgen_export_2;
107
114
  const offset = table.grow(4);
108
115
  table.set(0, undefined);
@@ -112,17 +119,8 @@ module.exports.__wbindgen_init_externref_table = function () {
112
119
  table.set(offset + 3, false);
113
120
  ;
114
121
  };
115
- module.exports.__wbindgen_string_new = function (arg0, arg1) {
116
- const ret = getStringFromWasm0(arg0, arg1);
117
- return ret;
118
- };
119
- module.exports.__wbindgen_throw = function (arg0, arg1) {
120
- throw new Error(getStringFromWasm0(arg0, arg1));
121
- };
122
- const path = require('path').join(__dirname, 'tycho_disasm_bg.wasm');
123
- const bytes = require('fs').readFileSync(path);
124
- const wasmModule = new WebAssembly.Module(bytes);
125
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
126
- wasm = wasmInstance.exports;
127
- module.exports.__wasm = wasm;
122
+ const wasmPath = `${__dirname}/tycho_disasm_bg.wasm`;
123
+ const wasmBytes = require('fs').readFileSync(wasmPath);
124
+ const wasmModule = new WebAssembly.Module(wasmBytes);
125
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
128
126
  wasm.__wbindgen_start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tychosdk/disasm",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Tycho TVM disasm",
5
5
  "main": "dist/index.js",
6
6
  "browser": {
@@ -26,7 +26,8 @@
26
26
  "typescript": "^5.8.3"
27
27
  },
28
28
  "peerDependencies": {
29
- "@ton/crypto": ">=3.2.0"
29
+ "@ton/core": ">=0.61.0",
30
+ "@ton/crypto": ">=3.3.0"
30
31
  },
31
32
  "scripts": {
32
33
  "wasm:build": "./scripts/build-wasm.sh",