@tari-project/ootle-wasm-bor 0.0.0-bootstrap.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/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @tari-project/ootle-wasm-bor
2
+
3
+ WASM decoders for Tari Ootle values in their CBOR encoding. It carries only the decoders, so it is a fraction of the
4
+ size of [`@tari-project/ootle-wasm`](https://www.npmjs.com/package/@tari-project/ootle-wasm), which builds and signs
5
+ transactions.
6
+
7
+ The indexer serves substate values and execution results in their CBOR encoding, as base64 strings. These decode
8
+ one into its JSON, in the shape of the `SubstateValue` and `ExecuteResult` types in `@tari-project/ootle-ts-bindings`.
9
+
10
+ ### `decodeSubstateValue(encoded)`
11
+
12
+ ```typescript
13
+ import { decodeSubstateValue } from "@tari-project/ootle-wasm-bor";
14
+
15
+ const value = JSON.parse(decodeSubstateValue(response.state.up.substate));
16
+ ```
17
+
18
+ ### `decodeExecuteResult(encoded)`
19
+
20
+ ```typescript
21
+ import { decodeExecuteResult } from "@tari-project/ootle-wasm-bor";
22
+
23
+ const result = JSON.parse(decodeExecuteResult(finalized.execution_result));
24
+ ```
25
+
26
+ Both throw if `encoded` is not base64 or its bytes are not a complete encoding of the value.
27
+
28
+ ## License
29
+
30
+ BSD-3-Clause
@@ -0,0 +1,12 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decode an `ExecuteResult` as the indexer serves it (its CBOR encoding, base64) → JSON string.
6
+ */
7
+ export function decodeExecuteResult(encoded: string): string;
8
+
9
+ /**
10
+ * Decode a `SubstateValue` as the indexer serves it (its CBOR encoding, base64) → JSON string.
11
+ */
12
+ export function decodeSubstateValue(encoded: string): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./ootle_wasm_bor.d.ts" */
2
+ import * as wasm from "./ootle_wasm_bor_bg.wasm";
3
+ import { __wbg_set_wasm } from "./ootle_wasm_bor_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ decodeExecuteResult, decodeSubstateValue
9
+ } from "./ootle_wasm_bor_bg.js";
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Decode an `ExecuteResult` as the indexer serves it (its CBOR encoding, base64) → JSON string.
3
+ * @param {string} encoded
4
+ * @returns {string}
5
+ */
6
+ export function decodeExecuteResult(encoded) {
7
+ let deferred3_0;
8
+ let deferred3_1;
9
+ try {
10
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ret = wasm.decodeExecuteResult(ptr0, len0);
13
+ var ptr2 = ret[0];
14
+ var len2 = ret[1];
15
+ if (ret[3]) {
16
+ ptr2 = 0; len2 = 0;
17
+ throw takeFromExternrefTable0(ret[2]);
18
+ }
19
+ deferred3_0 = ptr2;
20
+ deferred3_1 = len2;
21
+ return getStringFromWasm0(ptr2, len2);
22
+ } finally {
23
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Decode a `SubstateValue` as the indexer serves it (its CBOR encoding, base64) → JSON string.
29
+ * @param {string} encoded
30
+ * @returns {string}
31
+ */
32
+ export function decodeSubstateValue(encoded) {
33
+ let deferred3_0;
34
+ let deferred3_1;
35
+ try {
36
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
37
+ const len0 = WASM_VECTOR_LEN;
38
+ const ret = wasm.decodeSubstateValue(ptr0, len0);
39
+ var ptr2 = ret[0];
40
+ var len2 = ret[1];
41
+ if (ret[3]) {
42
+ ptr2 = 0; len2 = 0;
43
+ throw takeFromExternrefTable0(ret[2]);
44
+ }
45
+ deferred3_0 = ptr2;
46
+ deferred3_1 = len2;
47
+ return getStringFromWasm0(ptr2, len2);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
50
+ }
51
+ }
52
+ export function __wbg_Error_67e7344beaa85059(arg0, arg1) {
53
+ const ret = Error(getStringFromWasm0(arg0, arg1));
54
+ return ret;
55
+ }
56
+ export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
57
+ throw new Error(getStringFromWasm0(arg0, arg1));
58
+ }
59
+ export function __wbindgen_init_externref_table() {
60
+ const table = wasm.__wbindgen_externrefs;
61
+ const offset = table.grow(4);
62
+ table.set(0, undefined);
63
+ table.set(offset + 0, undefined);
64
+ table.set(offset + 1, null);
65
+ table.set(offset + 2, true);
66
+ table.set(offset + 3, false);
67
+ }
68
+ function getStringFromWasm0(ptr, len) {
69
+ return decodeText(ptr >>> 0, len);
70
+ }
71
+
72
+ let cachedUint8ArrayMemory0 = null;
73
+ function getUint8ArrayMemory0() {
74
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
75
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
76
+ }
77
+ return cachedUint8ArrayMemory0;
78
+ }
79
+
80
+ function passStringToWasm0(arg, malloc, realloc) {
81
+ if (realloc === undefined) {
82
+ const buf = cachedTextEncoder.encode(arg);
83
+ const ptr = malloc(buf.length, 1) >>> 0;
84
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
85
+ WASM_VECTOR_LEN = buf.length;
86
+ return ptr;
87
+ }
88
+
89
+ let len = arg.length;
90
+ let ptr = malloc(len, 1) >>> 0;
91
+
92
+ const mem = getUint8ArrayMemory0();
93
+
94
+ let offset = 0;
95
+
96
+ for (; offset < len; offset++) {
97
+ const code = arg.charCodeAt(offset);
98
+ if (code > 0x7F) break;
99
+ mem[ptr + offset] = code;
100
+ }
101
+ if (offset !== len) {
102
+ if (offset !== 0) {
103
+ arg = arg.slice(offset);
104
+ }
105
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
106
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
107
+ const ret = cachedTextEncoder.encodeInto(arg, view);
108
+
109
+ offset += ret.written;
110
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
111
+ }
112
+
113
+ WASM_VECTOR_LEN = offset;
114
+ return ptr;
115
+ }
116
+
117
+ function takeFromExternrefTable0(idx) {
118
+ const value = wasm.__wbindgen_externrefs.get(idx);
119
+ wasm.__externref_table_dealloc(idx);
120
+ return value;
121
+ }
122
+
123
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
124
+ cachedTextDecoder.decode();
125
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
126
+ let numBytesDecoded = 0;
127
+ function decodeText(ptr, len) {
128
+ numBytesDecoded += len;
129
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
130
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
131
+ cachedTextDecoder.decode();
132
+ numBytesDecoded = len;
133
+ }
134
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
135
+ }
136
+
137
+ const cachedTextEncoder = new TextEncoder();
138
+
139
+ if (!('encodeInto' in cachedTextEncoder)) {
140
+ cachedTextEncoder.encodeInto = function (arg, view) {
141
+ const buf = cachedTextEncoder.encode(arg);
142
+ view.set(buf);
143
+ return {
144
+ read: arg.length,
145
+ written: buf.length
146
+ };
147
+ };
148
+ }
149
+
150
+ let WASM_VECTOR_LEN = 0;
151
+
152
+
153
+ let wasm;
154
+ export function __wbg_set_wasm(val) {
155
+ wasm = val;
156
+ }
Binary file
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tari-project/ootle-wasm-bor",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "The Tari Development Community"
6
+ ],
7
+ "description": "WASM decoders for the Tari Ootle values the indexer serves in their CBOR encoding",
8
+ "version": "0.0.0-bootstrap.0",
9
+ "license": "BSD-3-Clause",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/tari-project/tari-ootle"
13
+ },
14
+ "files": [
15
+ "README.md",
16
+ "ootle_wasm_bor.d.ts",
17
+ "ootle_wasm_bor.js",
18
+ "ootle_wasm_bor_bg.js",
19
+ "ootle_wasm_bor_bg.wasm"
20
+ ],
21
+ "main": "ootle_wasm_bor.js",
22
+ "types": "ootle_wasm_bor.d.ts",
23
+ "sideEffects": [
24
+ "./ootle_wasm_bor.js",
25
+ "./snippets/*"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }