@tari-project/ootle-wasm-bor 0.0.0-stage → 0.48.0-rc.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 CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # @tari-project/ootle-wasm-bor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 engine values in their CBOR encoding, as base64 strings. These decode one into its JSON, in the
8
+ shape of the type of the same name 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
+ ### `decodeTransactionReceipt`, `decodeEvent`, `decodeResource`, `decodeUtxo`
27
+
28
+ ```typescript
29
+ import { decodeEvent, decodeTransactionReceipt } from "@tari-project/ootle-wasm-bor";
30
+
31
+ const receipt = JSON.parse(decodeTransactionReceipt(response.receipt));
32
+ const events = response.events.map(([transactionId, event]) => [transactionId, JSON.parse(decodeEvent(event))]);
33
+ ```
34
+
35
+ `decodeTransactionReceipt` reads `/transaction-receipts`, `decodeEvent` the `/transactions/events` query and stream,
36
+ `decodeResource` `/resources/{address}` and `decodeUtxo` `/utxos`.
37
+
38
+ All throw if `encoded` is not base64 or its bytes are not a complete encoding of the value.
39
+
40
+ ## License
41
+
42
+ BSD-3-Clause
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decode an `Event` as the indexer serves it (its CBOR encoding, base64) → JSON string.
6
+ */
7
+ export function decodeEvent(encoded: string): string;
8
+
9
+ /**
10
+ * Decode an `ExecuteResult` as the indexer serves it (its CBOR encoding, base64) → JSON string.
11
+ */
12
+ export function decodeExecuteResult(encoded: string): string;
13
+
14
+ /**
15
+ * Decode a `Resource` as the indexer serves it (its CBOR encoding, base64) → JSON string.
16
+ */
17
+ export function decodeResource(encoded: string): string;
18
+
19
+ /**
20
+ * Decode a `SubstateValue` as the indexer serves it (its CBOR encoding, base64) → JSON string.
21
+ */
22
+ export function decodeSubstateValue(encoded: string): string;
23
+
24
+ /**
25
+ * Decode a `TransactionReceipt` as the indexer serves it (its CBOR encoding, base64) → JSON string.
26
+ */
27
+ export function decodeTransactionReceipt(encoded: string): string;
28
+
29
+ /**
30
+ * Decode a `Utxo` as the indexer serves it (its CBOR encoding, base64) → JSON string.
31
+ */
32
+ export function decodeUtxo(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
+ decodeEvent, decodeExecuteResult, decodeResource, decodeSubstateValue, decodeTransactionReceipt, decodeUtxo
9
+ } from "./ootle_wasm_bor_bg.js";
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Decode an `Event` as the indexer serves it (its CBOR encoding, base64) → JSON string.
3
+ * @param {string} encoded
4
+ * @returns {string}
5
+ */
6
+ export function decodeEvent(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.decodeEvent(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 an `ExecuteResult` as the indexer serves it (its CBOR encoding, base64) → JSON string.
29
+ * @param {string} encoded
30
+ * @returns {string}
31
+ */
32
+ export function decodeExecuteResult(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.decodeExecuteResult(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
+
53
+ /**
54
+ * Decode a `Resource` as the indexer serves it (its CBOR encoding, base64) → JSON string.
55
+ * @param {string} encoded
56
+ * @returns {string}
57
+ */
58
+ export function decodeResource(encoded) {
59
+ let deferred3_0;
60
+ let deferred3_1;
61
+ try {
62
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
63
+ const len0 = WASM_VECTOR_LEN;
64
+ const ret = wasm.decodeResource(ptr0, len0);
65
+ var ptr2 = ret[0];
66
+ var len2 = ret[1];
67
+ if (ret[3]) {
68
+ ptr2 = 0; len2 = 0;
69
+ throw takeFromExternrefTable0(ret[2]);
70
+ }
71
+ deferred3_0 = ptr2;
72
+ deferred3_1 = len2;
73
+ return getStringFromWasm0(ptr2, len2);
74
+ } finally {
75
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Decode a `SubstateValue` as the indexer serves it (its CBOR encoding, base64) → JSON string.
81
+ * @param {string} encoded
82
+ * @returns {string}
83
+ */
84
+ export function decodeSubstateValue(encoded) {
85
+ let deferred3_0;
86
+ let deferred3_1;
87
+ try {
88
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
89
+ const len0 = WASM_VECTOR_LEN;
90
+ const ret = wasm.decodeSubstateValue(ptr0, len0);
91
+ var ptr2 = ret[0];
92
+ var len2 = ret[1];
93
+ if (ret[3]) {
94
+ ptr2 = 0; len2 = 0;
95
+ throw takeFromExternrefTable0(ret[2]);
96
+ }
97
+ deferred3_0 = ptr2;
98
+ deferred3_1 = len2;
99
+ return getStringFromWasm0(ptr2, len2);
100
+ } finally {
101
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Decode a `TransactionReceipt` as the indexer serves it (its CBOR encoding, base64) → JSON string.
107
+ * @param {string} encoded
108
+ * @returns {string}
109
+ */
110
+ export function decodeTransactionReceipt(encoded) {
111
+ let deferred3_0;
112
+ let deferred3_1;
113
+ try {
114
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
115
+ const len0 = WASM_VECTOR_LEN;
116
+ const ret = wasm.decodeTransactionReceipt(ptr0, len0);
117
+ var ptr2 = ret[0];
118
+ var len2 = ret[1];
119
+ if (ret[3]) {
120
+ ptr2 = 0; len2 = 0;
121
+ throw takeFromExternrefTable0(ret[2]);
122
+ }
123
+ deferred3_0 = ptr2;
124
+ deferred3_1 = len2;
125
+ return getStringFromWasm0(ptr2, len2);
126
+ } finally {
127
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Decode a `Utxo` as the indexer serves it (its CBOR encoding, base64) → JSON string.
133
+ * @param {string} encoded
134
+ * @returns {string}
135
+ */
136
+ export function decodeUtxo(encoded) {
137
+ let deferred3_0;
138
+ let deferred3_1;
139
+ try {
140
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
141
+ const len0 = WASM_VECTOR_LEN;
142
+ const ret = wasm.decodeUtxo(ptr0, len0);
143
+ var ptr2 = ret[0];
144
+ var len2 = ret[1];
145
+ if (ret[3]) {
146
+ ptr2 = 0; len2 = 0;
147
+ throw takeFromExternrefTable0(ret[2]);
148
+ }
149
+ deferred3_0 = ptr2;
150
+ deferred3_1 = len2;
151
+ return getStringFromWasm0(ptr2, len2);
152
+ } finally {
153
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
154
+ }
155
+ }
156
+ export function __wbg_Error_67e7344beaa85059(arg0, arg1) {
157
+ const ret = Error(getStringFromWasm0(arg0, arg1));
158
+ return ret;
159
+ }
160
+ export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
161
+ throw new Error(getStringFromWasm0(arg0, arg1));
162
+ }
163
+ export function __wbindgen_init_externref_table() {
164
+ const table = wasm.__wbindgen_externrefs;
165
+ const offset = table.grow(4);
166
+ table.set(0, undefined);
167
+ table.set(offset + 0, undefined);
168
+ table.set(offset + 1, null);
169
+ table.set(offset + 2, true);
170
+ table.set(offset + 3, false);
171
+ }
172
+ function getStringFromWasm0(ptr, len) {
173
+ return decodeText(ptr >>> 0, len);
174
+ }
175
+
176
+ let cachedUint8ArrayMemory0 = null;
177
+ function getUint8ArrayMemory0() {
178
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
179
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
180
+ }
181
+ return cachedUint8ArrayMemory0;
182
+ }
183
+
184
+ function passStringToWasm0(arg, malloc, realloc) {
185
+ if (realloc === undefined) {
186
+ const buf = cachedTextEncoder.encode(arg);
187
+ const ptr = malloc(buf.length, 1) >>> 0;
188
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
189
+ WASM_VECTOR_LEN = buf.length;
190
+ return ptr;
191
+ }
192
+
193
+ let len = arg.length;
194
+ let ptr = malloc(len, 1) >>> 0;
195
+
196
+ const mem = getUint8ArrayMemory0();
197
+
198
+ let offset = 0;
199
+
200
+ for (; offset < len; offset++) {
201
+ const code = arg.charCodeAt(offset);
202
+ if (code > 0x7F) break;
203
+ mem[ptr + offset] = code;
204
+ }
205
+ if (offset !== len) {
206
+ if (offset !== 0) {
207
+ arg = arg.slice(offset);
208
+ }
209
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
210
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
211
+ const ret = cachedTextEncoder.encodeInto(arg, view);
212
+
213
+ offset += ret.written;
214
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
215
+ }
216
+
217
+ WASM_VECTOR_LEN = offset;
218
+ return ptr;
219
+ }
220
+
221
+ function takeFromExternrefTable0(idx) {
222
+ const value = wasm.__wbindgen_externrefs.get(idx);
223
+ wasm.__externref_table_dealloc(idx);
224
+ return value;
225
+ }
226
+
227
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
228
+ cachedTextDecoder.decode();
229
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
230
+ let numBytesDecoded = 0;
231
+ function decodeText(ptr, len) {
232
+ numBytesDecoded += len;
233
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
234
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
235
+ cachedTextDecoder.decode();
236
+ numBytesDecoded = len;
237
+ }
238
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
239
+ }
240
+
241
+ const cachedTextEncoder = new TextEncoder();
242
+
243
+ if (!('encodeInto' in cachedTextEncoder)) {
244
+ cachedTextEncoder.encodeInto = function (arg, view) {
245
+ const buf = cachedTextEncoder.encode(arg);
246
+ view.set(buf);
247
+ return {
248
+ read: arg.length,
249
+ written: buf.length
250
+ };
251
+ };
252
+ }
253
+
254
+ let WASM_VECTOR_LEN = 0;
255
+
256
+
257
+ let wasm;
258
+ export function __wbg_set_wasm(val) {
259
+ wasm = val;
260
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@tari-project/ootle-wasm-bor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
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.48.0-rc.0",
9
+ "license": "BSD-3-Clause",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/tari-project/tari-ootle"
13
+ },
14
+ "files": [
15
+ "ootle_wasm_bor_bg.wasm",
16
+ "ootle_wasm_bor.js",
17
+ "ootle_wasm_bor_bg.js",
18
+ "ootle_wasm_bor.d.ts",
19
+ "README.md"
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
+ }