wickra-verify-wasm 0.1.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,63 @@
1
+ # Wickra Verify — WASM
2
+
3
+ Recompute a claimed backtest report with the deterministic Wickra engine and
4
+ confirm or refute it, compiled to WebAssembly for the browser (and any WASM
5
+ host). A doctored `claimed_report` cannot pass, because verification recomputes
6
+ rather than trusting the supplied numbers. Built with [wasm-bindgen].
7
+
8
+ The backtest engine runs sequentially under WASM (no thread pool in a browser
9
+ sandbox), which is byte-identical to the native run — the exact cross-language
10
+ golden check.
11
+
12
+ ## Build
13
+
14
+ ```sh
15
+ wasm-pack build --target web # for browsers / bundlers
16
+ wasm-pack build --target nodejs # for Node.js
17
+ ```
18
+
19
+ The `pkg/` output (the `.wasm` binary plus the JS glue and TypeScript types) is
20
+ generated, not committed.
21
+
22
+ ## Usage
23
+
24
+ Everything goes through a `Verifier` driven by JSON commands — the same command
25
+ protocol every Wickra binding shares.
26
+
27
+ ```js
28
+ import init, { Verifier } from "./pkg/wickra_verify_wasm.js";
29
+
30
+ await init(); // load the .wasm module (web target)
31
+
32
+ const verifier = new Verifier(); // default tolerances; new Verifier('{"atol":1e-9,"rtol":1e-6}') to override
33
+
34
+ const claim = {
35
+ strategy: {/* a wickra-backtest StrategySpec */},
36
+ dataset_ref: { kind: "inline", data: { BTCUSDT: [/* candles */] } },
37
+ claimed_report: {/* the report being checked (untrusted) */},
38
+ };
39
+
40
+ const verdict = JSON.parse(verifier.command(JSON.stringify({ cmd: "verify", claim })));
41
+ console.log(verdict.matches ? "VERIFIED" : verdict.mismatches);
42
+ ```
43
+
44
+ ## Commands
45
+
46
+ | `cmd` | Payload | Response |
47
+ |----------------|--------------------|-----------------------------------------|
48
+ | `verify` | `{claim, data?}` | the full `Verdict` |
49
+ | `explain` | `{verdict}` | `{ok:true,text:...}` |
50
+ | `canonicalize` | `{value}` | `{ok:true,canonical:...}` |
51
+ | `version` | — | `{version:...,engine_version:...}` |
52
+
53
+ For `files`-kind claims, supply the candle data under a top-level `data` key;
54
+ `inline` claims carry their data already.
55
+
56
+ Domain errors (a bad claim, an unknown command) come back in-band as
57
+ `{ok:false,error:...}`; a malformed command envelope throws a JS error.
58
+
59
+ ## License
60
+
61
+ MIT OR Apache-2.0.
62
+
63
+ [wasm-bindgen]: https://github.com/rustwasm/wasm-bindgen
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "wickra-verify-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "wickra-lib"
6
+ ],
7
+ "description": "WebAssembly bindings for wickra-verify — recompute a claimed backtest report and confirm or refute it, in the browser.",
8
+ "version": "0.1.0",
9
+ "license": "MIT OR Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/wickra-lib/wickra-verify"
13
+ },
14
+ "files": [
15
+ "wickra_verify_wasm_bg.wasm",
16
+ "wickra_verify_wasm.js",
17
+ "wickra_verify_wasm_bg.js",
18
+ "wickra_verify_wasm.d.ts"
19
+ ],
20
+ "main": "wickra_verify_wasm.js",
21
+ "homepage": "https://github.com/wickra-lib/wickra-verify",
22
+ "types": "wickra_verify_wasm.d.ts",
23
+ "sideEffects": [
24
+ "./wickra_verify_wasm.js",
25
+ "./snippets/*"
26
+ ],
27
+ "author": "kingchenc <support@wickra.org>",
28
+ "bugs": {
29
+ "url": "https://github.com/wickra-lib/wickra-verify/issues"
30
+ }
31
+ }
@@ -0,0 +1,29 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A verifier driven by JSON commands.
6
+ */
7
+ export class Verifier {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ /**
11
+ * Apply a command JSON and return the resulting response JSON.
12
+ */
13
+ command(cmd_json: string): string;
14
+ /**
15
+ * Create a verifier from a config JSON (`{"atol":..,"rtol":..}`); missing
16
+ * fields fall back to the defaults. Pass `undefined` (or `"{}"`) for the
17
+ * default tolerances.
18
+ */
19
+ constructor(config_json?: string | null);
20
+ /**
21
+ * The library version.
22
+ */
23
+ version(): string;
24
+ }
25
+
26
+ /**
27
+ * The library version.
28
+ */
29
+ export function version(): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./wickra_verify_wasm.d.ts" */
2
+ import * as wasm from "./wickra_verify_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./wickra_verify_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ Verifier, version
9
+ } from "./wickra_verify_wasm_bg.js";
@@ -0,0 +1,247 @@
1
+ /**
2
+ * A verifier driven by JSON commands.
3
+ */
4
+ export class Verifier {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ VerifierFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_verifier_free(ptr, 0);
14
+ }
15
+ /**
16
+ * Apply a command JSON and return the resulting response JSON.
17
+ * @param {string} cmd_json
18
+ * @returns {string}
19
+ */
20
+ command(cmd_json) {
21
+ let deferred3_0;
22
+ let deferred3_1;
23
+ try {
24
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
25
+ const ptr0 = passStringToWasm0(cmd_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
26
+ const len0 = WASM_VECTOR_LEN;
27
+ wasm.verifier_command(retptr, this.__wbg_ptr, ptr0, len0);
28
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
29
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
30
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
31
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
32
+ var ptr2 = r0;
33
+ var len2 = r1;
34
+ if (r3) {
35
+ ptr2 = 0; len2 = 0;
36
+ throw takeObject(r2);
37
+ }
38
+ deferred3_0 = ptr2;
39
+ deferred3_1 = len2;
40
+ return getStringFromWasm0(ptr2, len2);
41
+ } finally {
42
+ wasm.__wbindgen_add_to_stack_pointer(16);
43
+ wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
44
+ }
45
+ }
46
+ /**
47
+ * Create a verifier from a config JSON (`{"atol":..,"rtol":..}`); missing
48
+ * fields fall back to the defaults. Pass `undefined` (or `"{}"`) for the
49
+ * default tolerances.
50
+ * @param {string | null} [config_json]
51
+ */
52
+ constructor(config_json) {
53
+ try {
54
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
55
+ var ptr0 = isLikeNone(config_json) ? 0 : passStringToWasm0(config_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
56
+ var len0 = WASM_VECTOR_LEN;
57
+ wasm.verifier_new(retptr, ptr0, len0);
58
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
59
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
60
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
61
+ if (r2) {
62
+ throw takeObject(r1);
63
+ }
64
+ this.__wbg_ptr = r0;
65
+ VerifierFinalization.register(this, this.__wbg_ptr, this);
66
+ return this;
67
+ } finally {
68
+ wasm.__wbindgen_add_to_stack_pointer(16);
69
+ }
70
+ }
71
+ /**
72
+ * The library version.
73
+ * @returns {string}
74
+ */
75
+ version() {
76
+ let deferred1_0;
77
+ let deferred1_1;
78
+ try {
79
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
80
+ wasm.verifier_version(retptr, this.__wbg_ptr);
81
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
82
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
83
+ deferred1_0 = r0;
84
+ deferred1_1 = r1;
85
+ return getStringFromWasm0(r0, r1);
86
+ } finally {
87
+ wasm.__wbindgen_add_to_stack_pointer(16);
88
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
89
+ }
90
+ }
91
+ }
92
+ if (Symbol.dispose) Verifier.prototype[Symbol.dispose] = Verifier.prototype.free;
93
+
94
+ /**
95
+ * The library version.
96
+ * @returns {string}
97
+ */
98
+ export function version() {
99
+ let deferred1_0;
100
+ let deferred1_1;
101
+ try {
102
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
103
+ wasm.version(retptr);
104
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
105
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
106
+ deferred1_0 = r0;
107
+ deferred1_1 = r1;
108
+ return getStringFromWasm0(r0, r1);
109
+ } finally {
110
+ wasm.__wbindgen_add_to_stack_pointer(16);
111
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
112
+ }
113
+ }
114
+ export function __wbg_Error_67e7344beaa85059(arg0, arg1) {
115
+ const ret = Error(getStringFromWasm0(arg0, arg1));
116
+ return addHeapObject(ret);
117
+ }
118
+ export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
119
+ throw new Error(getStringFromWasm0(arg0, arg1));
120
+ }
121
+ const VerifierFinalization = (typeof FinalizationRegistry === 'undefined')
122
+ ? { register: () => {}, unregister: () => {} }
123
+ : new FinalizationRegistry(ptr => wasm.__wbg_verifier_free(ptr, 1));
124
+
125
+ function addHeapObject(obj) {
126
+ if (heap_next === heap.length) heap.push(heap.length + 1);
127
+ const idx = heap_next;
128
+ heap_next = heap[idx];
129
+
130
+ heap[idx] = obj;
131
+ return idx;
132
+ }
133
+
134
+ function dropObject(idx) {
135
+ if (idx < 1028) return;
136
+ heap[idx] = heap_next;
137
+ heap_next = idx;
138
+ }
139
+
140
+ let cachedDataViewMemory0 = null;
141
+ function getDataViewMemory0() {
142
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
143
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
144
+ }
145
+ return cachedDataViewMemory0;
146
+ }
147
+
148
+ function getStringFromWasm0(ptr, len) {
149
+ return decodeText(ptr >>> 0, len);
150
+ }
151
+
152
+ let cachedUint8ArrayMemory0 = null;
153
+ function getUint8ArrayMemory0() {
154
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
155
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
156
+ }
157
+ return cachedUint8ArrayMemory0;
158
+ }
159
+
160
+ function getObject(idx) { return heap[idx]; }
161
+
162
+ let heap = new Array(1024).fill(undefined);
163
+ heap.push(undefined, null, true, false);
164
+
165
+ let heap_next = heap.length;
166
+
167
+ function isLikeNone(x) {
168
+ return x === undefined || x === null;
169
+ }
170
+
171
+ function passStringToWasm0(arg, malloc, realloc) {
172
+ if (realloc === undefined) {
173
+ const buf = cachedTextEncoder.encode(arg);
174
+ const ptr = malloc(buf.length, 1) >>> 0;
175
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
176
+ WASM_VECTOR_LEN = buf.length;
177
+ return ptr;
178
+ }
179
+
180
+ let len = arg.length;
181
+ let ptr = malloc(len, 1) >>> 0;
182
+
183
+ const mem = getUint8ArrayMemory0();
184
+
185
+ let offset = 0;
186
+
187
+ for (; offset < len; offset++) {
188
+ const code = arg.charCodeAt(offset);
189
+ if (code > 0x7F) break;
190
+ mem[ptr + offset] = code;
191
+ }
192
+ if (offset !== len) {
193
+ if (offset !== 0) {
194
+ arg = arg.slice(offset);
195
+ }
196
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
197
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
198
+ const ret = cachedTextEncoder.encodeInto(arg, view);
199
+
200
+ offset += ret.written;
201
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
202
+ }
203
+
204
+ WASM_VECTOR_LEN = offset;
205
+ return ptr;
206
+ }
207
+
208
+ function takeObject(idx) {
209
+ const ret = getObject(idx);
210
+ dropObject(idx);
211
+ return ret;
212
+ }
213
+
214
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
215
+ cachedTextDecoder.decode();
216
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
217
+ let numBytesDecoded = 0;
218
+ function decodeText(ptr, len) {
219
+ numBytesDecoded += len;
220
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
221
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
222
+ cachedTextDecoder.decode();
223
+ numBytesDecoded = len;
224
+ }
225
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
226
+ }
227
+
228
+ const cachedTextEncoder = new TextEncoder();
229
+
230
+ if (!('encodeInto' in cachedTextEncoder)) {
231
+ cachedTextEncoder.encodeInto = function (arg, view) {
232
+ const buf = cachedTextEncoder.encode(arg);
233
+ view.set(buf);
234
+ return {
235
+ read: arg.length,
236
+ written: buf.length
237
+ };
238
+ };
239
+ }
240
+
241
+ let WASM_VECTOR_LEN = 0;
242
+
243
+
244
+ let wasm;
245
+ export function __wbg_set_wasm(val) {
246
+ wasm = val;
247
+ }
Binary file