rootchain-wasm 1.0.1 → 1.0.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 RootChain
3
+ Copyright (c) 2026 RootChain Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### WebAssembly Cryptographic Primitives for the RootChain Ecosystem
4
4
 
5
- `rootchain-wasm` provides the core cryptographic and transaction-processing logic for RootChain, compiled to highly-optimized WebAssembly. It is designed to be used in performance-critical environments like the **@rootchain/sdk** to handle secure key derivation and offline transaction signing.
5
+ `rootchain-wasm` provides the core cryptographic and transaction-processing logic for RootChain, compiled to highly-optimized WebAssembly. It is designed to be used in performance-critical environments like the **rootchain-sdk** to handle secure key derivation and offline transaction signing.
6
6
 
7
7
  ## ⚡ Core Functions
8
8
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Charles Bronzon"
6
6
  ],
7
7
  "description": "WebAssembly primitives for RootChain: transaction signing, account derivation, and cryptography.",
8
- "version": "1.0.1",
8
+ "version": "1.0.2",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -14,13 +14,11 @@
14
14
  "files": [
15
15
  "rootchain_wasm_bg.wasm",
16
16
  "rootchain_wasm.js",
17
- "rootchain_wasm_bg.js",
18
17
  "rootchain_wasm.d.ts"
19
18
  ],
20
19
  "main": "rootchain_wasm.js",
21
20
  "types": "rootchain_wasm.d.ts",
22
21
  "sideEffects": [
23
- "./rootchain_wasm.js",
24
22
  "./snippets/*"
25
23
  ],
26
24
  "keywords": [
@@ -10,3 +10,44 @@ export function get_address_from_key(private_key_hex: string): string;
10
10
  export function get_contract_address(from_hex: string, nonce: bigint): string;
11
11
 
12
12
  export function sign_transaction(tx_json: string, private_key_hex: string): string;
13
+
14
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
15
+
16
+ export interface InitOutput {
17
+ readonly memory: WebAssembly.Memory;
18
+ readonly derive_account: (a: number, b: number, c: number) => [number, number, number];
19
+ readonly generate_mnemonic: () => [number, number];
20
+ readonly get_address_from_key: (a: number, b: number) => [number, number, number, number];
21
+ readonly get_contract_address: (a: number, b: number, c: bigint) => [number, number, number, number];
22
+ readonly sign_transaction: (a: number, b: number, c: number, d: number) => [number, number, number, number];
23
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
24
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
25
+ readonly __wbindgen_exn_store: (a: number) => void;
26
+ readonly __externref_table_alloc: () => number;
27
+ readonly __wbindgen_externrefs: WebAssembly.Table;
28
+ readonly __externref_table_dealloc: (a: number) => void;
29
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
30
+ readonly __wbindgen_start: () => void;
31
+ }
32
+
33
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
34
+
35
+ /**
36
+ * Instantiates the given `module`, which can either be bytes or
37
+ * a precompiled `WebAssembly.Module`.
38
+ *
39
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
40
+ *
41
+ * @returns {InitOutput}
42
+ */
43
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
44
+
45
+ /**
46
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
47
+ * for everything else, calls `WebAssembly.instantiate` directly.
48
+ *
49
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
50
+ *
51
+ * @returns {Promise<InitOutput>}
52
+ */
53
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/rootchain_wasm.js CHANGED
@@ -1,9 +1,449 @@
1
1
  /* @ts-self-types="./rootchain_wasm.d.ts" */
2
2
 
3
- import * as wasm from "./rootchain_wasm_bg.wasm";
4
- import { __wbg_set_wasm } from "./rootchain_wasm_bg.js";
5
- __wbg_set_wasm(wasm);
6
- wasm.__wbindgen_start();
7
- export {
8
- derive_account, generate_mnemonic, get_address_from_key, get_contract_address, sign_transaction
9
- } from "./rootchain_wasm_bg.js";
3
+ /**
4
+ * @param {string} phrase
5
+ * @param {number} index
6
+ * @returns {any}
7
+ */
8
+ export function derive_account(phrase, index) {
9
+ const ptr0 = passStringToWasm0(phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ret = wasm.derive_account(ptr0, len0, index);
12
+ if (ret[2]) {
13
+ throw takeFromExternrefTable0(ret[1]);
14
+ }
15
+ return takeFromExternrefTable0(ret[0]);
16
+ }
17
+
18
+ /**
19
+ * @returns {string}
20
+ */
21
+ export function generate_mnemonic() {
22
+ let deferred1_0;
23
+ let deferred1_1;
24
+ try {
25
+ const ret = wasm.generate_mnemonic();
26
+ deferred1_0 = ret[0];
27
+ deferred1_1 = ret[1];
28
+ return getStringFromWasm0(ret[0], ret[1]);
29
+ } finally {
30
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @param {string} private_key_hex
36
+ * @returns {string}
37
+ */
38
+ export function get_address_from_key(private_key_hex) {
39
+ let deferred3_0;
40
+ let deferred3_1;
41
+ try {
42
+ const ptr0 = passStringToWasm0(private_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
43
+ const len0 = WASM_VECTOR_LEN;
44
+ const ret = wasm.get_address_from_key(ptr0, len0);
45
+ var ptr2 = ret[0];
46
+ var len2 = ret[1];
47
+ if (ret[3]) {
48
+ ptr2 = 0; len2 = 0;
49
+ throw takeFromExternrefTable0(ret[2]);
50
+ }
51
+ deferred3_0 = ptr2;
52
+ deferred3_1 = len2;
53
+ return getStringFromWasm0(ptr2, len2);
54
+ } finally {
55
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * @param {string} from_hex
61
+ * @param {bigint} nonce
62
+ * @returns {string}
63
+ */
64
+ export function get_contract_address(from_hex, nonce) {
65
+ let deferred3_0;
66
+ let deferred3_1;
67
+ try {
68
+ const ptr0 = passStringToWasm0(from_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
69
+ const len0 = WASM_VECTOR_LEN;
70
+ const ret = wasm.get_contract_address(ptr0, len0, nonce);
71
+ var ptr2 = ret[0];
72
+ var len2 = ret[1];
73
+ if (ret[3]) {
74
+ ptr2 = 0; len2 = 0;
75
+ throw takeFromExternrefTable0(ret[2]);
76
+ }
77
+ deferred3_0 = ptr2;
78
+ deferred3_1 = len2;
79
+ return getStringFromWasm0(ptr2, len2);
80
+ } finally {
81
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
82
+ }
83
+ }
84
+
85
+ /**
86
+ * @param {string} tx_json
87
+ * @param {string} private_key_hex
88
+ * @returns {string}
89
+ */
90
+ export function sign_transaction(tx_json, private_key_hex) {
91
+ let deferred4_0;
92
+ let deferred4_1;
93
+ try {
94
+ const ptr0 = passStringToWasm0(tx_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ptr1 = passStringToWasm0(private_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
97
+ const len1 = WASM_VECTOR_LEN;
98
+ const ret = wasm.sign_transaction(ptr0, len0, ptr1, len1);
99
+ var ptr3 = ret[0];
100
+ var len3 = ret[1];
101
+ if (ret[3]) {
102
+ ptr3 = 0; len3 = 0;
103
+ throw takeFromExternrefTable0(ret[2]);
104
+ }
105
+ deferred4_0 = ptr3;
106
+ deferred4_1 = len3;
107
+ return getStringFromWasm0(ptr3, len3);
108
+ } finally {
109
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
110
+ }
111
+ }
112
+
113
+ function __wbg_get_imports() {
114
+ const import0 = {
115
+ __proto__: null,
116
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
117
+ const ret = String(arg1);
118
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
119
+ const len1 = WASM_VECTOR_LEN;
120
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
121
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
122
+ },
123
+ __wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
124
+ const ret = typeof(arg0) === 'function';
125
+ return ret;
126
+ },
127
+ __wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
128
+ const val = arg0;
129
+ const ret = typeof(val) === 'object' && val !== null;
130
+ return ret;
131
+ },
132
+ __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
133
+ const ret = typeof(arg0) === 'string';
134
+ return ret;
135
+ },
136
+ __wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
137
+ const ret = arg0 === undefined;
138
+ return ret;
139
+ },
140
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
141
+ throw new Error(getStringFromWasm0(arg0, arg1));
142
+ },
143
+ __wbg_call_2d781c1f4d5c0ef8: function() { return handleError(function (arg0, arg1, arg2) {
144
+ const ret = arg0.call(arg1, arg2);
145
+ return ret;
146
+ }, arguments); },
147
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
148
+ const ret = arg0.crypto;
149
+ return ret;
150
+ },
151
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
152
+ arg0.getRandomValues(arg1);
153
+ }, arguments); },
154
+ __wbg_length_ea16607d7b61445b: function(arg0) {
155
+ const ret = arg0.length;
156
+ return ret;
157
+ },
158
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
159
+ const ret = arg0.msCrypto;
160
+ return ret;
161
+ },
162
+ __wbg_new_ab79df5bd7c26067: function() {
163
+ const ret = new Object();
164
+ return ret;
165
+ },
166
+ __wbg_new_with_length_825018a1616e9e55: function(arg0) {
167
+ const ret = new Uint8Array(arg0 >>> 0);
168
+ return ret;
169
+ },
170
+ __wbg_node_84ea875411254db1: function(arg0) {
171
+ const ret = arg0.node;
172
+ return ret;
173
+ },
174
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
175
+ const ret = arg0.process;
176
+ return ret;
177
+ },
178
+ __wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
179
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
180
+ },
181
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
182
+ arg0.randomFillSync(arg1);
183
+ }, arguments); },
184
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
185
+ const ret = module.require;
186
+ return ret;
187
+ }, arguments); },
188
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
189
+ arg0[arg1] = arg2;
190
+ },
191
+ __wbg_static_accessor_GLOBAL_8adb955bd33fac2f: function() {
192
+ const ret = typeof global === 'undefined' ? null : global;
193
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
194
+ },
195
+ __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913: function() {
196
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
197
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
198
+ },
199
+ __wbg_static_accessor_SELF_f207c857566db248: function() {
200
+ const ret = typeof self === 'undefined' ? null : self;
201
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
202
+ },
203
+ __wbg_static_accessor_WINDOW_bb9f1ba69d61b386: function() {
204
+ const ret = typeof window === 'undefined' ? null : window;
205
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
206
+ },
207
+ __wbg_subarray_a068d24e39478a8a: function(arg0, arg1, arg2) {
208
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
209
+ return ret;
210
+ },
211
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
212
+ const ret = arg0.versions;
213
+ return ret;
214
+ },
215
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
216
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
217
+ const ret = getArrayU8FromWasm0(arg0, arg1);
218
+ return ret;
219
+ },
220
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
221
+ // Cast intrinsic for `Ref(String) -> Externref`.
222
+ const ret = getStringFromWasm0(arg0, arg1);
223
+ return ret;
224
+ },
225
+ __wbindgen_init_externref_table: function() {
226
+ const table = wasm.__wbindgen_externrefs;
227
+ const offset = table.grow(4);
228
+ table.set(0, undefined);
229
+ table.set(offset + 0, undefined);
230
+ table.set(offset + 1, null);
231
+ table.set(offset + 2, true);
232
+ table.set(offset + 3, false);
233
+ },
234
+ };
235
+ return {
236
+ __proto__: null,
237
+ "./rootchain_wasm_bg.js": import0,
238
+ };
239
+ }
240
+
241
+ function addToExternrefTable0(obj) {
242
+ const idx = wasm.__externref_table_alloc();
243
+ wasm.__wbindgen_externrefs.set(idx, obj);
244
+ return idx;
245
+ }
246
+
247
+ function getArrayU8FromWasm0(ptr, len) {
248
+ ptr = ptr >>> 0;
249
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
250
+ }
251
+
252
+ let cachedDataViewMemory0 = null;
253
+ function getDataViewMemory0() {
254
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
255
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
256
+ }
257
+ return cachedDataViewMemory0;
258
+ }
259
+
260
+ function getStringFromWasm0(ptr, len) {
261
+ ptr = ptr >>> 0;
262
+ return decodeText(ptr, len);
263
+ }
264
+
265
+ let cachedUint8ArrayMemory0 = null;
266
+ function getUint8ArrayMemory0() {
267
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
268
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
269
+ }
270
+ return cachedUint8ArrayMemory0;
271
+ }
272
+
273
+ function handleError(f, args) {
274
+ try {
275
+ return f.apply(this, args);
276
+ } catch (e) {
277
+ const idx = addToExternrefTable0(e);
278
+ wasm.__wbindgen_exn_store(idx);
279
+ }
280
+ }
281
+
282
+ function isLikeNone(x) {
283
+ return x === undefined || x === null;
284
+ }
285
+
286
+ function passStringToWasm0(arg, malloc, realloc) {
287
+ if (realloc === undefined) {
288
+ const buf = cachedTextEncoder.encode(arg);
289
+ const ptr = malloc(buf.length, 1) >>> 0;
290
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
291
+ WASM_VECTOR_LEN = buf.length;
292
+ return ptr;
293
+ }
294
+
295
+ let len = arg.length;
296
+ let ptr = malloc(len, 1) >>> 0;
297
+
298
+ const mem = getUint8ArrayMemory0();
299
+
300
+ let offset = 0;
301
+
302
+ for (; offset < len; offset++) {
303
+ const code = arg.charCodeAt(offset);
304
+ if (code > 0x7F) break;
305
+ mem[ptr + offset] = code;
306
+ }
307
+ if (offset !== len) {
308
+ if (offset !== 0) {
309
+ arg = arg.slice(offset);
310
+ }
311
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
312
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
313
+ const ret = cachedTextEncoder.encodeInto(arg, view);
314
+
315
+ offset += ret.written;
316
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
317
+ }
318
+
319
+ WASM_VECTOR_LEN = offset;
320
+ return ptr;
321
+ }
322
+
323
+ function takeFromExternrefTable0(idx) {
324
+ const value = wasm.__wbindgen_externrefs.get(idx);
325
+ wasm.__externref_table_dealloc(idx);
326
+ return value;
327
+ }
328
+
329
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
330
+ cachedTextDecoder.decode();
331
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
332
+ let numBytesDecoded = 0;
333
+ function decodeText(ptr, len) {
334
+ numBytesDecoded += len;
335
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
336
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
337
+ cachedTextDecoder.decode();
338
+ numBytesDecoded = len;
339
+ }
340
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
341
+ }
342
+
343
+ const cachedTextEncoder = new TextEncoder();
344
+
345
+ if (!('encodeInto' in cachedTextEncoder)) {
346
+ cachedTextEncoder.encodeInto = function (arg, view) {
347
+ const buf = cachedTextEncoder.encode(arg);
348
+ view.set(buf);
349
+ return {
350
+ read: arg.length,
351
+ written: buf.length
352
+ };
353
+ };
354
+ }
355
+
356
+ let WASM_VECTOR_LEN = 0;
357
+
358
+ let wasmModule, wasm;
359
+ function __wbg_finalize_init(instance, module) {
360
+ wasm = instance.exports;
361
+ wasmModule = module;
362
+ cachedDataViewMemory0 = null;
363
+ cachedUint8ArrayMemory0 = null;
364
+ wasm.__wbindgen_start();
365
+ return wasm;
366
+ }
367
+
368
+ async function __wbg_load(module, imports) {
369
+ if (typeof Response === 'function' && module instanceof Response) {
370
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
371
+ try {
372
+ return await WebAssembly.instantiateStreaming(module, imports);
373
+ } catch (e) {
374
+ const validResponse = module.ok && expectedResponseType(module.type);
375
+
376
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
377
+ 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);
378
+
379
+ } else { throw e; }
380
+ }
381
+ }
382
+
383
+ const bytes = await module.arrayBuffer();
384
+ return await WebAssembly.instantiate(bytes, imports);
385
+ } else {
386
+ const instance = await WebAssembly.instantiate(module, imports);
387
+
388
+ if (instance instanceof WebAssembly.Instance) {
389
+ return { instance, module };
390
+ } else {
391
+ return instance;
392
+ }
393
+ }
394
+
395
+ function expectedResponseType(type) {
396
+ switch (type) {
397
+ case 'basic': case 'cors': case 'default': return true;
398
+ }
399
+ return false;
400
+ }
401
+ }
402
+
403
+ function initSync(module) {
404
+ if (wasm !== undefined) return wasm;
405
+
406
+
407
+ if (module !== undefined) {
408
+ if (Object.getPrototypeOf(module) === Object.prototype) {
409
+ ({module} = module)
410
+ } else {
411
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
412
+ }
413
+ }
414
+
415
+ const imports = __wbg_get_imports();
416
+ if (!(module instanceof WebAssembly.Module)) {
417
+ module = new WebAssembly.Module(module);
418
+ }
419
+ const instance = new WebAssembly.Instance(module, imports);
420
+ return __wbg_finalize_init(instance, module);
421
+ }
422
+
423
+ async function __wbg_init(module_or_path) {
424
+ if (wasm !== undefined) return wasm;
425
+
426
+
427
+ if (module_or_path !== undefined) {
428
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
429
+ ({module_or_path} = module_or_path)
430
+ } else {
431
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
432
+ }
433
+ }
434
+
435
+ if (module_or_path === undefined) {
436
+ module_or_path = new URL('rootchain_wasm_bg.wasm', import.meta.url);
437
+ }
438
+ const imports = __wbg_get_imports();
439
+
440
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
441
+ module_or_path = fetch(module_or_path);
442
+ }
443
+
444
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
445
+
446
+ return __wbg_finalize_init(instance, module);
447
+ }
448
+
449
+ export { initSync, __wbg_init as default };
Binary file
@@ -1,349 +0,0 @@
1
- /**
2
- * @param {string} phrase
3
- * @param {number} index
4
- * @returns {any}
5
- */
6
- export function derive_account(phrase, index) {
7
- const ptr0 = passStringToWasm0(phrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
8
- const len0 = WASM_VECTOR_LEN;
9
- const ret = wasm.derive_account(ptr0, len0, index);
10
- if (ret[2]) {
11
- throw takeFromExternrefTable0(ret[1]);
12
- }
13
- return takeFromExternrefTable0(ret[0]);
14
- }
15
-
16
- /**
17
- * @returns {string}
18
- */
19
- export function generate_mnemonic() {
20
- let deferred1_0;
21
- let deferred1_1;
22
- try {
23
- const ret = wasm.generate_mnemonic();
24
- deferred1_0 = ret[0];
25
- deferred1_1 = ret[1];
26
- return getStringFromWasm0(ret[0], ret[1]);
27
- } finally {
28
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
29
- }
30
- }
31
-
32
- /**
33
- * @param {string} private_key_hex
34
- * @returns {string}
35
- */
36
- export function get_address_from_key(private_key_hex) {
37
- let deferred3_0;
38
- let deferred3_1;
39
- try {
40
- const ptr0 = passStringToWasm0(private_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
41
- const len0 = WASM_VECTOR_LEN;
42
- const ret = wasm.get_address_from_key(ptr0, len0);
43
- var ptr2 = ret[0];
44
- var len2 = ret[1];
45
- if (ret[3]) {
46
- ptr2 = 0; len2 = 0;
47
- throw takeFromExternrefTable0(ret[2]);
48
- }
49
- deferred3_0 = ptr2;
50
- deferred3_1 = len2;
51
- return getStringFromWasm0(ptr2, len2);
52
- } finally {
53
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
54
- }
55
- }
56
-
57
- /**
58
- * @param {string} from_hex
59
- * @param {bigint} nonce
60
- * @returns {string}
61
- */
62
- export function get_contract_address(from_hex, nonce) {
63
- let deferred3_0;
64
- let deferred3_1;
65
- try {
66
- const ptr0 = passStringToWasm0(from_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
67
- const len0 = WASM_VECTOR_LEN;
68
- const ret = wasm.get_contract_address(ptr0, len0, nonce);
69
- var ptr2 = ret[0];
70
- var len2 = ret[1];
71
- if (ret[3]) {
72
- ptr2 = 0; len2 = 0;
73
- throw takeFromExternrefTable0(ret[2]);
74
- }
75
- deferred3_0 = ptr2;
76
- deferred3_1 = len2;
77
- return getStringFromWasm0(ptr2, len2);
78
- } finally {
79
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
80
- }
81
- }
82
-
83
- /**
84
- * @param {string} tx_json
85
- * @param {string} private_key_hex
86
- * @returns {string}
87
- */
88
- export function sign_transaction(tx_json, private_key_hex) {
89
- let deferred4_0;
90
- let deferred4_1;
91
- try {
92
- const ptr0 = passStringToWasm0(tx_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
93
- const len0 = WASM_VECTOR_LEN;
94
- const ptr1 = passStringToWasm0(private_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
- const len1 = WASM_VECTOR_LEN;
96
- const ret = wasm.sign_transaction(ptr0, len0, ptr1, len1);
97
- var ptr3 = ret[0];
98
- var len3 = ret[1];
99
- if (ret[3]) {
100
- ptr3 = 0; len3 = 0;
101
- throw takeFromExternrefTable0(ret[2]);
102
- }
103
- deferred4_0 = ptr3;
104
- deferred4_1 = len3;
105
- return getStringFromWasm0(ptr3, len3);
106
- } finally {
107
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
108
- }
109
- }
110
- export function __wbg_String_8564e559799eccda(arg0, arg1) {
111
- const ret = String(arg1);
112
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
113
- const len1 = WASM_VECTOR_LEN;
114
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
115
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
116
- }
117
- export function __wbg___wbindgen_is_function_3c846841762788c1(arg0) {
118
- const ret = typeof(arg0) === 'function';
119
- return ret;
120
- }
121
- export function __wbg___wbindgen_is_object_781bc9f159099513(arg0) {
122
- const val = arg0;
123
- const ret = typeof(val) === 'object' && val !== null;
124
- return ret;
125
- }
126
- export function __wbg___wbindgen_is_string_7ef6b97b02428fae(arg0) {
127
- const ret = typeof(arg0) === 'string';
128
- return ret;
129
- }
130
- export function __wbg___wbindgen_is_undefined_52709e72fb9f179c(arg0) {
131
- const ret = arg0 === undefined;
132
- return ret;
133
- }
134
- export function __wbg___wbindgen_throw_6ddd609b62940d55(arg0, arg1) {
135
- throw new Error(getStringFromWasm0(arg0, arg1));
136
- }
137
- export function __wbg_call_2d781c1f4d5c0ef8() { return handleError(function (arg0, arg1, arg2) {
138
- const ret = arg0.call(arg1, arg2);
139
- return ret;
140
- }, arguments); }
141
- export function __wbg_crypto_38df2bab126b63dc(arg0) {
142
- const ret = arg0.crypto;
143
- return ret;
144
- }
145
- export function __wbg_getRandomValues_c44a50d8cfdaebeb() { return handleError(function (arg0, arg1) {
146
- arg0.getRandomValues(arg1);
147
- }, arguments); }
148
- export function __wbg_length_ea16607d7b61445b(arg0) {
149
- const ret = arg0.length;
150
- return ret;
151
- }
152
- export function __wbg_msCrypto_bd5a034af96bcba6(arg0) {
153
- const ret = arg0.msCrypto;
154
- return ret;
155
- }
156
- export function __wbg_new_ab79df5bd7c26067() {
157
- const ret = new Object();
158
- return ret;
159
- }
160
- export function __wbg_new_with_length_825018a1616e9e55(arg0) {
161
- const ret = new Uint8Array(arg0 >>> 0);
162
- return ret;
163
- }
164
- export function __wbg_node_84ea875411254db1(arg0) {
165
- const ret = arg0.node;
166
- return ret;
167
- }
168
- export function __wbg_process_44c7a14e11e9f69e(arg0) {
169
- const ret = arg0.process;
170
- return ret;
171
- }
172
- export function __wbg_prototypesetcall_d62e5099504357e6(arg0, arg1, arg2) {
173
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
174
- }
175
- export function __wbg_randomFillSync_6c25eac9869eb53c() { return handleError(function (arg0, arg1) {
176
- arg0.randomFillSync(arg1);
177
- }, arguments); }
178
- export function __wbg_require_b4edbdcf3e2a1ef0() { return handleError(function () {
179
- const ret = module.require;
180
- return ret;
181
- }, arguments); }
182
- export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
183
- arg0[arg1] = arg2;
184
- }
185
- export function __wbg_static_accessor_GLOBAL_8adb955bd33fac2f() {
186
- const ret = typeof global === 'undefined' ? null : global;
187
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
188
- }
189
- export function __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913() {
190
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
191
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
192
- }
193
- export function __wbg_static_accessor_SELF_f207c857566db248() {
194
- const ret = typeof self === 'undefined' ? null : self;
195
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
196
- }
197
- export function __wbg_static_accessor_WINDOW_bb9f1ba69d61b386() {
198
- const ret = typeof window === 'undefined' ? null : window;
199
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
200
- }
201
- export function __wbg_subarray_a068d24e39478a8a(arg0, arg1, arg2) {
202
- const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
203
- return ret;
204
- }
205
- export function __wbg_versions_276b2795b1c6a219(arg0) {
206
- const ret = arg0.versions;
207
- return ret;
208
- }
209
- export function __wbindgen_cast_0000000000000001(arg0, arg1) {
210
- // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
211
- const ret = getArrayU8FromWasm0(arg0, arg1);
212
- return ret;
213
- }
214
- export function __wbindgen_cast_0000000000000002(arg0, arg1) {
215
- // Cast intrinsic for `Ref(String) -> Externref`.
216
- const ret = getStringFromWasm0(arg0, arg1);
217
- return ret;
218
- }
219
- export function __wbindgen_init_externref_table() {
220
- const table = wasm.__wbindgen_externrefs;
221
- const offset = table.grow(4);
222
- table.set(0, undefined);
223
- table.set(offset + 0, undefined);
224
- table.set(offset + 1, null);
225
- table.set(offset + 2, true);
226
- table.set(offset + 3, false);
227
- }
228
- function addToExternrefTable0(obj) {
229
- const idx = wasm.__externref_table_alloc();
230
- wasm.__wbindgen_externrefs.set(idx, obj);
231
- return idx;
232
- }
233
-
234
- function getArrayU8FromWasm0(ptr, len) {
235
- ptr = ptr >>> 0;
236
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
237
- }
238
-
239
- let cachedDataViewMemory0 = null;
240
- function getDataViewMemory0() {
241
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
242
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
243
- }
244
- return cachedDataViewMemory0;
245
- }
246
-
247
- function getStringFromWasm0(ptr, len) {
248
- ptr = ptr >>> 0;
249
- return decodeText(ptr, len);
250
- }
251
-
252
- let cachedUint8ArrayMemory0 = null;
253
- function getUint8ArrayMemory0() {
254
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
255
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
256
- }
257
- return cachedUint8ArrayMemory0;
258
- }
259
-
260
- function handleError(f, args) {
261
- try {
262
- return f.apply(this, args);
263
- } catch (e) {
264
- const idx = addToExternrefTable0(e);
265
- wasm.__wbindgen_exn_store(idx);
266
- }
267
- }
268
-
269
- function isLikeNone(x) {
270
- return x === undefined || x === null;
271
- }
272
-
273
- function passStringToWasm0(arg, malloc, realloc) {
274
- if (realloc === undefined) {
275
- const buf = cachedTextEncoder.encode(arg);
276
- const ptr = malloc(buf.length, 1) >>> 0;
277
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
278
- WASM_VECTOR_LEN = buf.length;
279
- return ptr;
280
- }
281
-
282
- let len = arg.length;
283
- let ptr = malloc(len, 1) >>> 0;
284
-
285
- const mem = getUint8ArrayMemory0();
286
-
287
- let offset = 0;
288
-
289
- for (; offset < len; offset++) {
290
- const code = arg.charCodeAt(offset);
291
- if (code > 0x7F) break;
292
- mem[ptr + offset] = code;
293
- }
294
- if (offset !== len) {
295
- if (offset !== 0) {
296
- arg = arg.slice(offset);
297
- }
298
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
299
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
300
- const ret = cachedTextEncoder.encodeInto(arg, view);
301
-
302
- offset += ret.written;
303
- ptr = realloc(ptr, len, offset, 1) >>> 0;
304
- }
305
-
306
- WASM_VECTOR_LEN = offset;
307
- return ptr;
308
- }
309
-
310
- function takeFromExternrefTable0(idx) {
311
- const value = wasm.__wbindgen_externrefs.get(idx);
312
- wasm.__externref_table_dealloc(idx);
313
- return value;
314
- }
315
-
316
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
317
- cachedTextDecoder.decode();
318
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
319
- let numBytesDecoded = 0;
320
- function decodeText(ptr, len) {
321
- numBytesDecoded += len;
322
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
323
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
324
- cachedTextDecoder.decode();
325
- numBytesDecoded = len;
326
- }
327
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
328
- }
329
-
330
- const cachedTextEncoder = new TextEncoder();
331
-
332
- if (!('encodeInto' in cachedTextEncoder)) {
333
- cachedTextEncoder.encodeInto = function (arg, view) {
334
- const buf = cachedTextEncoder.encode(arg);
335
- view.set(buf);
336
- return {
337
- read: arg.length,
338
- written: buf.length
339
- };
340
- };
341
- }
342
-
343
- let WASM_VECTOR_LEN = 0;
344
-
345
-
346
- let wasm;
347
- export function __wbg_set_wasm(val) {
348
- wasm = val;
349
- }