@trufo/validator-core-wasm 0.1.0-pre.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,23 @@
1
+ # validator-core
2
+
3
+ The policy and verdict engine that powers `verify.trufo.ai`. See the [repo-level README](../../README.md) for the conceptual layering and the open-source rationale.
4
+
5
+ This crate consumes the upstream [`c2pa-rs`](https://github.com/contentauth/c2pa-rs) implementation of the C2PA specification and applies Trufo's verdict policy on top.
6
+
7
+ ## Targets
8
+
9
+ - `cargo build --release` produces a native `rlib` + `cdylib`. Used by `trufo-validator-server` and any other native consumer.
10
+ - `wasm-pack build --release --target web --scope trufo` (run from the [`/wasm`](../../wasm) directory) produces the `@trufo/validator-core-wasm` npm package consumed by `trufo-web/client`.
11
+
12
+ Both targets produce **bit-identical verdict JSON** for the same inputs, trust list version, and validator-core version. This is enforced by a fixture-based equivalence harness in [`fixtures`](../fixtures).
13
+
14
+ ## Status
15
+
16
+ Phase 0 / pre-0.1.0. The public API is intentionally tiny and the verdict is a placeholder. Phase 1 fills in:
17
+
18
+ - Per-spec-version (C2PA 1.3 / 1.4 / 2.0 / 2.1) rule sets
19
+ - Three-tier conformance classification (spec / registered extension / unrecognized)
20
+ - Per-assertion attribution
21
+ - Inherited CAWG findings
22
+ - Trust list policy enforcement (CAI default, Trufo-curated additive)
23
+ - Reproducibility metadata pinning
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@trufo/validator-core-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Trufo, Inc. <oss@trufo.ai>"
6
+ ],
7
+ "description": "Trufo's policy and verdict engine on top of c2pa-rs. Powers verify.trufo.ai.",
8
+ "version": "0.1.0-pre.0",
9
+ "license": "Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/trufo-ai/validator-core"
13
+ },
14
+ "files": [
15
+ "validator_core_bg.wasm",
16
+ "validator_core.js",
17
+ "validator_core.d.ts"
18
+ ],
19
+ "main": "validator_core.js",
20
+ "homepage": "https://verify.trufo.ai",
21
+ "types": "validator_core.d.ts",
22
+ "sideEffects": [
23
+ "./snippets/*"
24
+ ],
25
+ "keywords": [
26
+ "c2pa",
27
+ "content-credentials",
28
+ "provenance",
29
+ "validator"
30
+ ]
31
+ }
@@ -0,0 +1,49 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Verify a single asset from JS / WASM.
6
+ *
7
+ * Returns the verdict as a JS object (parsed from JSON, not a string)
8
+ * to keep the JS API ergonomic. Throws on input errors.
9
+ */
10
+ export function verify_bytes(input: Uint8Array): any;
11
+
12
+ /**
13
+ * Returns the validator-core version this WASM bundle was built from.
14
+ */
15
+ export function version(): string;
16
+
17
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
18
+
19
+ export interface InitOutput {
20
+ readonly memory: WebAssembly.Memory;
21
+ readonly verify_bytes: (a: number, b: number, c: number) => void;
22
+ readonly version: (a: number) => void;
23
+ readonly __wbindgen_export: (a: number, b: number) => number;
24
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
25
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
26
+ readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
27
+ }
28
+
29
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
30
+
31
+ /**
32
+ * Instantiates the given `module`, which can either be bytes or
33
+ * a precompiled `WebAssembly.Module`.
34
+ *
35
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
36
+ *
37
+ * @returns {InitOutput}
38
+ */
39
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
40
+
41
+ /**
42
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
43
+ * for everything else, calls `WebAssembly.instantiate` directly.
44
+ *
45
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
46
+ *
47
+ * @returns {Promise<InitOutput>}
48
+ */
49
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,312 @@
1
+ /* @ts-self-types="./validator_core.d.ts" */
2
+
3
+ /**
4
+ * Verify a single asset from JS / WASM.
5
+ *
6
+ * Returns the verdict as a JS object (parsed from JSON, not a string)
7
+ * to keep the JS API ergonomic. Throws on input errors.
8
+ * @param {Uint8Array} input
9
+ * @returns {any}
10
+ */
11
+ export function verify_bytes(input) {
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
14
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ wasm.verify_bytes(retptr, ptr0, len0);
17
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
18
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
19
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
20
+ if (r2) {
21
+ throw takeObject(r1);
22
+ }
23
+ return takeObject(r0);
24
+ } finally {
25
+ wasm.__wbindgen_add_to_stack_pointer(16);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Returns the validator-core version this WASM bundle was built from.
31
+ * @returns {string}
32
+ */
33
+ export function version() {
34
+ let deferred1_0;
35
+ let deferred1_1;
36
+ try {
37
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
38
+ wasm.version(retptr);
39
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
40
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
41
+ deferred1_0 = r0;
42
+ deferred1_1 = r1;
43
+ return getStringFromWasm0(r0, r1);
44
+ } finally {
45
+ wasm.__wbindgen_add_to_stack_pointer(16);
46
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
47
+ }
48
+ }
49
+ function __wbg_get_imports() {
50
+ const import0 = {
51
+ __proto__: null,
52
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
53
+ const ret = String(getObject(arg1));
54
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
55
+ const len1 = WASM_VECTOR_LEN;
56
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
57
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
58
+ },
59
+ __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
60
+ throw new Error(getStringFromWasm0(arg0, arg1));
61
+ },
62
+ __wbg_new_02d162bc6cf02f60: function() {
63
+ const ret = new Object();
64
+ return addHeapObject(ret);
65
+ },
66
+ __wbg_new_310879b66b6e95e1: function() {
67
+ const ret = new Array();
68
+ return addHeapObject(ret);
69
+ },
70
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
71
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
72
+ },
73
+ __wbg_set_78ea6a19f4818587: function(arg0, arg1, arg2) {
74
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
75
+ },
76
+ __wbindgen_cast_0000000000000001: function(arg0) {
77
+ // Cast intrinsic for `F64 -> Externref`.
78
+ const ret = arg0;
79
+ return addHeapObject(ret);
80
+ },
81
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
82
+ // Cast intrinsic for `Ref(String) -> Externref`.
83
+ const ret = getStringFromWasm0(arg0, arg1);
84
+ return addHeapObject(ret);
85
+ },
86
+ __wbindgen_object_clone_ref: function(arg0) {
87
+ const ret = getObject(arg0);
88
+ return addHeapObject(ret);
89
+ },
90
+ __wbindgen_object_drop_ref: function(arg0) {
91
+ takeObject(arg0);
92
+ },
93
+ };
94
+ return {
95
+ __proto__: null,
96
+ "./validator_core_bg.js": import0,
97
+ };
98
+ }
99
+
100
+ function addHeapObject(obj) {
101
+ if (heap_next === heap.length) heap.push(heap.length + 1);
102
+ const idx = heap_next;
103
+ heap_next = heap[idx];
104
+
105
+ heap[idx] = obj;
106
+ return idx;
107
+ }
108
+
109
+ function dropObject(idx) {
110
+ if (idx < 1028) return;
111
+ heap[idx] = heap_next;
112
+ heap_next = idx;
113
+ }
114
+
115
+ let cachedDataViewMemory0 = null;
116
+ function getDataViewMemory0() {
117
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
118
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
119
+ }
120
+ return cachedDataViewMemory0;
121
+ }
122
+
123
+ function getStringFromWasm0(ptr, len) {
124
+ return decodeText(ptr >>> 0, len);
125
+ }
126
+
127
+ let cachedUint8ArrayMemory0 = null;
128
+ function getUint8ArrayMemory0() {
129
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
130
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
131
+ }
132
+ return cachedUint8ArrayMemory0;
133
+ }
134
+
135
+ function getObject(idx) { return heap[idx]; }
136
+
137
+ let heap = new Array(1024).fill(undefined);
138
+ heap.push(undefined, null, true, false);
139
+
140
+ let heap_next = heap.length;
141
+
142
+ function passArray8ToWasm0(arg, malloc) {
143
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
144
+ getUint8ArrayMemory0().set(arg, ptr / 1);
145
+ WASM_VECTOR_LEN = arg.length;
146
+ return ptr;
147
+ }
148
+
149
+ function passStringToWasm0(arg, malloc, realloc) {
150
+ if (realloc === undefined) {
151
+ const buf = cachedTextEncoder.encode(arg);
152
+ const ptr = malloc(buf.length, 1) >>> 0;
153
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
154
+ WASM_VECTOR_LEN = buf.length;
155
+ return ptr;
156
+ }
157
+
158
+ let len = arg.length;
159
+ let ptr = malloc(len, 1) >>> 0;
160
+
161
+ const mem = getUint8ArrayMemory0();
162
+
163
+ let offset = 0;
164
+
165
+ for (; offset < len; offset++) {
166
+ const code = arg.charCodeAt(offset);
167
+ if (code > 0x7F) break;
168
+ mem[ptr + offset] = code;
169
+ }
170
+ if (offset !== len) {
171
+ if (offset !== 0) {
172
+ arg = arg.slice(offset);
173
+ }
174
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
175
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
176
+ const ret = cachedTextEncoder.encodeInto(arg, view);
177
+
178
+ offset += ret.written;
179
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
180
+ }
181
+
182
+ WASM_VECTOR_LEN = offset;
183
+ return ptr;
184
+ }
185
+
186
+ function takeObject(idx) {
187
+ const ret = getObject(idx);
188
+ dropObject(idx);
189
+ return ret;
190
+ }
191
+
192
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
193
+ cachedTextDecoder.decode();
194
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
195
+ let numBytesDecoded = 0;
196
+ function decodeText(ptr, len) {
197
+ numBytesDecoded += len;
198
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
199
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
200
+ cachedTextDecoder.decode();
201
+ numBytesDecoded = len;
202
+ }
203
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
204
+ }
205
+
206
+ const cachedTextEncoder = new TextEncoder();
207
+
208
+ if (!('encodeInto' in cachedTextEncoder)) {
209
+ cachedTextEncoder.encodeInto = function (arg, view) {
210
+ const buf = cachedTextEncoder.encode(arg);
211
+ view.set(buf);
212
+ return {
213
+ read: arg.length,
214
+ written: buf.length
215
+ };
216
+ };
217
+ }
218
+
219
+ let WASM_VECTOR_LEN = 0;
220
+
221
+ let wasmModule, wasmInstance, wasm;
222
+ function __wbg_finalize_init(instance, module) {
223
+ wasmInstance = instance;
224
+ wasm = instance.exports;
225
+ wasmModule = module;
226
+ cachedDataViewMemory0 = null;
227
+ cachedUint8ArrayMemory0 = null;
228
+ return wasm;
229
+ }
230
+
231
+ async function __wbg_load(module, imports) {
232
+ if (typeof Response === 'function' && module instanceof Response) {
233
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
234
+ try {
235
+ return await WebAssembly.instantiateStreaming(module, imports);
236
+ } catch (e) {
237
+ const validResponse = module.ok && expectedResponseType(module.type);
238
+
239
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
240
+ 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);
241
+
242
+ } else { throw e; }
243
+ }
244
+ }
245
+
246
+ const bytes = await module.arrayBuffer();
247
+ return await WebAssembly.instantiate(bytes, imports);
248
+ } else {
249
+ const instance = await WebAssembly.instantiate(module, imports);
250
+
251
+ if (instance instanceof WebAssembly.Instance) {
252
+ return { instance, module };
253
+ } else {
254
+ return instance;
255
+ }
256
+ }
257
+
258
+ function expectedResponseType(type) {
259
+ switch (type) {
260
+ case 'basic': case 'cors': case 'default': return true;
261
+ }
262
+ return false;
263
+ }
264
+ }
265
+
266
+ function initSync(module) {
267
+ if (wasm !== undefined) return wasm;
268
+
269
+
270
+ if (module !== undefined) {
271
+ if (Object.getPrototypeOf(module) === Object.prototype) {
272
+ ({module} = module)
273
+ } else {
274
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
275
+ }
276
+ }
277
+
278
+ const imports = __wbg_get_imports();
279
+ if (!(module instanceof WebAssembly.Module)) {
280
+ module = new WebAssembly.Module(module);
281
+ }
282
+ const instance = new WebAssembly.Instance(module, imports);
283
+ return __wbg_finalize_init(instance, module);
284
+ }
285
+
286
+ async function __wbg_init(module_or_path) {
287
+ if (wasm !== undefined) return wasm;
288
+
289
+
290
+ if (module_or_path !== undefined) {
291
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
292
+ ({module_or_path} = module_or_path)
293
+ } else {
294
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
295
+ }
296
+ }
297
+
298
+ if (module_or_path === undefined) {
299
+ module_or_path = new URL('validator_core_bg.wasm', import.meta.url);
300
+ }
301
+ const imports = __wbg_get_imports();
302
+
303
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
304
+ module_or_path = fetch(module_or_path);
305
+ }
306
+
307
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
308
+
309
+ return __wbg_finalize_init(instance, module);
310
+ }
311
+
312
+ export { initSync, __wbg_init as default };
Binary file