@contentauth/c2pa-wasm 0.11.6 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentauth/c2pa-wasm",
3
- "version": "0.11.6",
3
+ "version": "0.13.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/pkg/c2pa.d.ts CHANGED
@@ -1,6 +1,30 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ interface HashedUri {
5
+ url: string;
6
+ hash: Uint8Array<ArrayBuffer>;
7
+ alg?: string;
8
+ }
9
+
10
+ interface SignerPayload {
11
+ referencedAssertions: HashedUri[];
12
+ sigType: string;
13
+ roles: string[];
14
+ }
15
+
16
+
17
+
18
+ interface IdentityAssertionDefinition {
19
+ sigType: string;
20
+ reserveSize: number;
21
+ referencedAssertions: string[];
22
+ roles: string[];
23
+ sign: (payload: SignerPayload) => Promise<Uint8Array<ArrayBuffer>>;
24
+ }
25
+
26
+
27
+
4
28
  interface SignerDefinition {
5
29
  sign: (bytes: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>;
6
30
  reserveSize: number;
@@ -128,13 +152,19 @@ export class WasmBuilder {
128
152
  setThumbnailFromBlob(format: string, blob: Blob): void;
129
153
  /**
130
154
  * Sign an asset using the provided SignerDefinition, format, and source Blob.
155
+ *
156
+ * `identity_assertions` is an array of `IdentityAssertionDefinition` (see
157
+ * `wasm_identity_assertion`'s typescript_custom_section); pass an empty
158
+ * array when no CAWG identity assertions are requested.
131
159
  */
132
- sign(signer_definition: SignerDefinition, format: string, source: Blob): Promise<Uint8Array>;
160
+ sign(signer_definition: SignerDefinition, identity_assertions: any, format: string, source: Blob): Promise<Uint8Array>;
133
161
  /**
134
162
  * Sign an asset using the provided SignerDefinition, format, and source Blob.
135
163
  * Use this method to get both the manifest bytes and the bytes of the signed asset.
164
+ *
165
+ * See [`Self::sign`] for `identity_assertions`.
136
166
  */
137
- signAndGetManifestBytes(signer_definition: SignerDefinition, format: string, source: Blob): Promise<any>;
167
+ signAndGetManifestBytes(signer_definition: SignerDefinition, identity_assertions: any, format: string, source: Blob): Promise<any>;
138
168
  /**
139
169
  * "Save" a builder to an archive.
140
170
  */
@@ -194,6 +224,17 @@ export class WasmReader {
194
224
  * Optionally accepts a context JSON string to configure the reader.
195
225
  */
196
226
  static fromBlobFragment(format: string, init: Blob, fragment: Blob, context_json?: string | null): Promise<WasmReader>;
227
+ /**
228
+ * Attempts to create a new `WasmReader` from an asset format and the asset's raw bytes.
229
+ *
230
+ * Unlike [`WasmReader::from_blob`], this entry point does not use any browser-only Web
231
+ * APIs (`Blob`, `FileReaderSync`). The bytes are read from an in-memory [`Cursor`], which
232
+ * implements [`Read`] + [`Seek`], so this can be called from non-browser JavaScript
233
+ * runtimes such as Node.js, Deno, Bun, and Cloudflare Workers (workerd).
234
+ *
235
+ * Optionally accepts a context JSON string to configure the reader.
236
+ */
237
+ static fromBytes(format: string, bytes: Uint8Array, context_json?: string | null): Promise<WasmReader>;
197
238
  /**
198
239
  * Returns a JSON representation of the asset's manifest store.
199
240
  */
@@ -218,17 +259,6 @@ export class WasmSigner {
218
259
  static fromDefinition(def: SignerDefinition): WasmSigner;
219
260
  }
220
261
 
221
- /**
222
- *
223
- * * NOTE: we can only return Err(JsString) or Err(JsValue) as error types here, because for some as-of-yet unknown
224
- * * reason, wasm-bindgen appears to mishandle JsErrors when created in a Firefox web worker.
225
- * *
226
- * * See: https://github.com/wasm-bindgen/wasm-bindgen/issues/4961
227
- *
228
- * Accepts a JSON-serialized string to be loaded as c2pa-rs settings.
229
- */
230
- export function loadSettings(settings: string): void;
231
-
232
262
  /**
233
263
  * Called when the WASM binary is initialized.
234
264
  */
@@ -238,11 +268,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
238
268
 
239
269
  export interface InitOutput {
240
270
  readonly memory: WebAssembly.Memory;
241
- readonly __wbg_wasmsigner_free: (a: number, b: number) => void;
242
- readonly wasmsigner_fromDefinition: (a: any) => [number, number, number];
243
271
  readonly __wbg_wasmbuilder_free: (a: number, b: number) => void;
244
- readonly __wbg_wasmreader_free: (a: number, b: number) => void;
245
- readonly run: () => void;
246
272
  readonly wasmbuilder_addAction: (a: number, b: any) => [number, number];
247
273
  readonly wasmbuilder_addAssertion: (a: number, b: number, c: number, d: any) => [number, number];
248
274
  readonly wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
@@ -260,19 +286,23 @@ export interface InitOutput {
260
286
  readonly wasmbuilder_setNoEmbed: (a: number, b: number) => void;
261
287
  readonly wasmbuilder_setRemoteUrl: (a: number, b: number, c: number) => void;
262
288
  readonly wasmbuilder_setThumbnailFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
263
- readonly wasmbuilder_sign: (a: number, b: any, c: number, d: number, e: any) => any;
264
- readonly wasmbuilder_signAndGetManifestBytes: (a: number, b: any, c: number, d: number, e: any) => any;
289
+ readonly wasmbuilder_sign: (a: number, b: any, c: any, d: number, e: number, f: any) => any;
290
+ readonly wasmbuilder_signAndGetManifestBytes: (a: number, b: any, c: any, d: number, e: number, f: any) => any;
265
291
  readonly wasmbuilder_toArchive: (a: number) => [number, number, number];
266
292
  readonly wasmbuilder_updateActionsAt: (a: number, b: any) => [number, number];
293
+ readonly run: () => void;
294
+ readonly __wbg_wasmreader_free: (a: number, b: number) => void;
267
295
  readonly wasmreader_activeLabel: (a: number) => [number, number];
268
296
  readonly wasmreader_activeManifest: (a: number) => [number, number, number];
269
297
  readonly wasmreader_crJson: (a: number) => [number, number];
270
298
  readonly wasmreader_fromBlob: (a: number, b: number, c: any, d: number, e: number) => any;
271
299
  readonly wasmreader_fromBlobFragment: (a: number, b: number, c: any, d: any, e: number, f: number) => any;
300
+ readonly wasmreader_fromBytes: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
272
301
  readonly wasmreader_json: (a: number) => [number, number];
273
302
  readonly wasmreader_manifestStore: (a: number) => [number, number, number];
274
303
  readonly wasmreader_resourceToBytes: (a: number, b: number, c: number) => [number, number, number];
275
- readonly loadSettings: (a: number, b: number) => [number, number];
304
+ readonly __wbg_wasmsigner_free: (a: number, b: number) => void;
305
+ readonly wasmsigner_fromDefinition: (a: any) => [number, number, number];
276
306
  readonly wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke___wasm_bindgen_4d7940e3be85a6dc___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_4d7940e3be85a6dc___JsError___true_: (a: number, b: number, c: any) => [number, number];
277
307
  readonly wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke___js_sys_a576b80f2209464___Function_fn_wasm_bindgen_4d7940e3be85a6dc___JsValue_____wasm_bindgen_4d7940e3be85a6dc___sys__Undefined___js_sys_a576b80f2209464___Function_fn_wasm_bindgen_4d7940e3be85a6dc___JsValue_____wasm_bindgen_4d7940e3be85a6dc___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
278
308
  readonly wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke_______true_: (a: number, b: number) => void;
package/pkg/c2pa.js CHANGED
@@ -275,29 +275,37 @@ export class WasmBuilder {
275
275
  }
276
276
  /**
277
277
  * Sign an asset using the provided SignerDefinition, format, and source Blob.
278
+ *
279
+ * `identity_assertions` is an array of `IdentityAssertionDefinition` (see
280
+ * `wasm_identity_assertion`'s typescript_custom_section); pass an empty
281
+ * array when no CAWG identity assertions are requested.
278
282
  * @param {SignerDefinition} signer_definition
283
+ * @param {any} identity_assertions
279
284
  * @param {string} format
280
285
  * @param {Blob} source
281
286
  * @returns {Promise<Uint8Array>}
282
287
  */
283
- sign(signer_definition, format, source) {
288
+ sign(signer_definition, identity_assertions, format, source) {
284
289
  const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
290
  const len0 = WASM_VECTOR_LEN;
286
- const ret = wasm.wasmbuilder_sign(this.__wbg_ptr, signer_definition, ptr0, len0, source);
291
+ const ret = wasm.wasmbuilder_sign(this.__wbg_ptr, signer_definition, identity_assertions, ptr0, len0, source);
287
292
  return ret;
288
293
  }
289
294
  /**
290
295
  * Sign an asset using the provided SignerDefinition, format, and source Blob.
291
296
  * Use this method to get both the manifest bytes and the bytes of the signed asset.
297
+ *
298
+ * See [`Self::sign`] for `identity_assertions`.
292
299
  * @param {SignerDefinition} signer_definition
300
+ * @param {any} identity_assertions
293
301
  * @param {string} format
294
302
  * @param {Blob} source
295
303
  * @returns {Promise<any>}
296
304
  */
297
- signAndGetManifestBytes(signer_definition, format, source) {
305
+ signAndGetManifestBytes(signer_definition, identity_assertions, format, source) {
298
306
  const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
299
307
  const len0 = WASM_VECTOR_LEN;
300
- const ret = wasm.wasmbuilder_signAndGetManifestBytes(this.__wbg_ptr, signer_definition, ptr0, len0, source);
308
+ const ret = wasm.wasmbuilder_signAndGetManifestBytes(this.__wbg_ptr, signer_definition, identity_assertions, ptr0, len0, source);
301
309
  return ret;
302
310
  }
303
311
  /**
@@ -437,6 +445,30 @@ export class WasmReader {
437
445
  const ret = wasm.wasmreader_fromBlobFragment(ptr0, len0, init, fragment, ptr1, len1);
438
446
  return ret;
439
447
  }
448
+ /**
449
+ * Attempts to create a new `WasmReader` from an asset format and the asset's raw bytes.
450
+ *
451
+ * Unlike [`WasmReader::from_blob`], this entry point does not use any browser-only Web
452
+ * APIs (`Blob`, `FileReaderSync`). The bytes are read from an in-memory [`Cursor`], which
453
+ * implements [`Read`] + [`Seek`], so this can be called from non-browser JavaScript
454
+ * runtimes such as Node.js, Deno, Bun, and Cloudflare Workers (workerd).
455
+ *
456
+ * Optionally accepts a context JSON string to configure the reader.
457
+ * @param {string} format
458
+ * @param {Uint8Array} bytes
459
+ * @param {string | null} [context_json]
460
+ * @returns {Promise<WasmReader>}
461
+ */
462
+ static fromBytes(format, bytes, context_json) {
463
+ const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
464
+ const len0 = WASM_VECTOR_LEN;
465
+ const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
466
+ const len1 = WASM_VECTOR_LEN;
467
+ var ptr2 = isLikeNone(context_json) ? 0 : passStringToWasm0(context_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
468
+ var len2 = WASM_VECTOR_LEN;
469
+ const ret = wasm.wasmreader_fromBytes(ptr0, len0, ptr1, len1, ptr2, len2);
470
+ return ret;
471
+ }
440
472
  /**
441
473
  * Returns a JSON representation of the asset's manifest store.
442
474
  * @returns {string}
@@ -513,25 +545,6 @@ export class WasmSigner {
513
545
  }
514
546
  if (Symbol.dispose) WasmSigner.prototype[Symbol.dispose] = WasmSigner.prototype.free;
515
547
 
516
- /**
517
- *
518
- * * NOTE: we can only return Err(JsString) or Err(JsValue) as error types here, because for some as-of-yet unknown
519
- * * reason, wasm-bindgen appears to mishandle JsErrors when created in a Firefox web worker.
520
- * *
521
- * * See: https://github.com/wasm-bindgen/wasm-bindgen/issues/4961
522
- *
523
- * Accepts a JSON-serialized string to be loaded as c2pa-rs settings.
524
- * @param {string} settings
525
- */
526
- export function loadSettings(settings) {
527
- const ptr0 = passStringToWasm0(settings, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
528
- const len0 = WASM_VECTOR_LEN;
529
- const ret = wasm.loadSettings(ptr0, len0);
530
- if (ret[1]) {
531
- throw takeFromExternrefTable0(ret[0]);
532
- }
533
- }
534
-
535
548
  /**
536
549
  * Called when the WASM binary is initialized.
537
550
  */
@@ -549,6 +562,13 @@ function __wbg_get_imports() {
549
562
  const ret = Number(arg0);
550
563
  return ret;
551
564
  },
565
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
566
+ const ret = String(arg1);
567
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
568
+ const len1 = WASM_VECTOR_LEN;
569
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
570
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
571
+ },
552
572
  __wbg___wbindgen_bigint_get_as_i64_38130e98eecd467d: function(arg0, arg1) {
553
573
  const v = arg1;
554
574
  const ret = typeof(v) === 'bigint' ? v : undefined;
@@ -579,6 +599,10 @@ function __wbg_get_imports() {
579
599
  const ret = typeof(arg0) === 'function';
580
600
  return ret;
581
601
  },
602
+ __wbg___wbindgen_is_null_87c3bfe968c6a5ad: function(arg0) {
603
+ const ret = arg0 === null;
604
+ return ret;
605
+ },
582
606
  __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
583
607
  const val = arg0;
584
608
  const ret = typeof(val) === 'object' && val !== null;
@@ -1030,12 +1054,12 @@ function __wbg_get_imports() {
1030
1054
  return ret;
1031
1055
  },
1032
1056
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1033
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3130, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1057
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3150, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1034
1058
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke___wasm_bindgen_4d7940e3be85a6dc___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_4d7940e3be85a6dc___JsError___true_);
1035
1059
  return ret;
1036
1060
  },
1037
1061
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1038
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1902, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1062
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1922, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1039
1063
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke_______true_);
1040
1064
  return ret;
1041
1065
  },
@@ -1276,6 +1300,13 @@ function passArray32ToWasm0(arg, malloc) {
1276
1300
  return ptr;
1277
1301
  }
1278
1302
 
1303
+ function passArray8ToWasm0(arg, malloc) {
1304
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1305
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1306
+ WASM_VECTOR_LEN = arg.length;
1307
+ return ptr;
1308
+ }
1309
+
1279
1310
  function passStringToWasm0(arg, malloc, realloc) {
1280
1311
  if (realloc === undefined) {
1281
1312
  const buf = cachedTextEncoder.encode(arg);
@@ -1440,4 +1471,4 @@ async function __wbg_init(module_or_path) {
1440
1471
  }
1441
1472
 
1442
1473
  export { initSync, __wbg_init as default };
1443
- export const WASM_SRI = "sha512-D4WD7SggBtpWKu+MH0DUoK7sQZp3lnYomn1sabzI9HuT4d20L1jrH3URyaUoBl9xas1x+AoQNDCvJhg2z7nnOw==";
1474
+ export const WASM_SRI = "sha512-dy+y/WRGgJP0600LxgBD8aQ6GKZr631fVXf06RNemy3HRyKkx6vVvx1BQvUgqr4f5DjumkBRO6QOttSv9NwwWA==";
package/pkg/c2pa_bg.wasm CHANGED
Binary file
@@ -1,11 +1,7 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export const __wbg_wasmsigner_free: (a: number, b: number) => void;
5
- export const wasmsigner_fromDefinition: (a: any) => [number, number, number];
6
4
  export const __wbg_wasmbuilder_free: (a: number, b: number) => void;
7
- export const __wbg_wasmreader_free: (a: number, b: number) => void;
8
- export const run: () => void;
9
5
  export const wasmbuilder_addAction: (a: number, b: any) => [number, number];
10
6
  export const wasmbuilder_addAssertion: (a: number, b: number, c: number, d: any) => [number, number];
11
7
  export const wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
@@ -23,19 +19,23 @@ export const wasmbuilder_setIntent: (a: number, b: any) => [number, number];
23
19
  export const wasmbuilder_setNoEmbed: (a: number, b: number) => void;
24
20
  export const wasmbuilder_setRemoteUrl: (a: number, b: number, c: number) => void;
25
21
  export const wasmbuilder_setThumbnailFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
26
- export const wasmbuilder_sign: (a: number, b: any, c: number, d: number, e: any) => any;
27
- export const wasmbuilder_signAndGetManifestBytes: (a: number, b: any, c: number, d: number, e: any) => any;
22
+ export const wasmbuilder_sign: (a: number, b: any, c: any, d: number, e: number, f: any) => any;
23
+ export const wasmbuilder_signAndGetManifestBytes: (a: number, b: any, c: any, d: number, e: number, f: any) => any;
28
24
  export const wasmbuilder_toArchive: (a: number) => [number, number, number];
29
25
  export const wasmbuilder_updateActionsAt: (a: number, b: any) => [number, number];
26
+ export const run: () => void;
27
+ export const __wbg_wasmreader_free: (a: number, b: number) => void;
30
28
  export const wasmreader_activeLabel: (a: number) => [number, number];
31
29
  export const wasmreader_activeManifest: (a: number) => [number, number, number];
32
30
  export const wasmreader_crJson: (a: number) => [number, number];
33
31
  export const wasmreader_fromBlob: (a: number, b: number, c: any, d: number, e: number) => any;
34
32
  export const wasmreader_fromBlobFragment: (a: number, b: number, c: any, d: any, e: number, f: number) => any;
33
+ export const wasmreader_fromBytes: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
35
34
  export const wasmreader_json: (a: number) => [number, number];
36
35
  export const wasmreader_manifestStore: (a: number) => [number, number, number];
37
36
  export const wasmreader_resourceToBytes: (a: number, b: number, c: number) => [number, number, number];
38
- export const loadSettings: (a: number, b: number) => [number, number];
37
+ export const __wbg_wasmsigner_free: (a: number, b: number) => void;
38
+ export const wasmsigner_fromDefinition: (a: any) => [number, number, number];
39
39
  export const wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke___wasm_bindgen_4d7940e3be85a6dc___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_4d7940e3be85a6dc___JsError___true_: (a: number, b: number, c: any) => [number, number];
40
40
  export const wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke___js_sys_a576b80f2209464___Function_fn_wasm_bindgen_4d7940e3be85a6dc___JsValue_____wasm_bindgen_4d7940e3be85a6dc___sys__Undefined___js_sys_a576b80f2209464___Function_fn_wasm_bindgen_4d7940e3be85a6dc___JsValue_____wasm_bindgen_4d7940e3be85a6dc___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
41
41
  export const wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke_______true_: (a: number, b: number) => void;