@contentauth/c2pa-wasm 0.12.0 → 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.12.0",
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
  */
@@ -227,11 +268,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
227
268
 
228
269
  export interface InitOutput {
229
270
  readonly memory: WebAssembly.Memory;
230
- readonly __wbg_wasmsigner_free: (a: number, b: number) => void;
231
- readonly wasmsigner_fromDefinition: (a: any) => [number, number, number];
232
271
  readonly __wbg_wasmbuilder_free: (a: number, b: number) => void;
233
- readonly __wbg_wasmreader_free: (a: number, b: number) => void;
234
- readonly run: () => void;
235
272
  readonly wasmbuilder_addAction: (a: number, b: any) => [number, number];
236
273
  readonly wasmbuilder_addAssertion: (a: number, b: number, c: number, d: any) => [number, number];
237
274
  readonly wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
@@ -249,18 +286,23 @@ export interface InitOutput {
249
286
  readonly wasmbuilder_setNoEmbed: (a: number, b: number) => void;
250
287
  readonly wasmbuilder_setRemoteUrl: (a: number, b: number, c: number) => void;
251
288
  readonly wasmbuilder_setThumbnailFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
252
- readonly wasmbuilder_sign: (a: number, b: any, c: number, d: number, e: any) => any;
253
- 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;
254
291
  readonly wasmbuilder_toArchive: (a: number) => [number, number, number];
255
292
  readonly wasmbuilder_updateActionsAt: (a: number, b: any) => [number, number];
293
+ readonly run: () => void;
294
+ readonly __wbg_wasmreader_free: (a: number, b: number) => void;
256
295
  readonly wasmreader_activeLabel: (a: number) => [number, number];
257
296
  readonly wasmreader_activeManifest: (a: number) => [number, number, number];
258
297
  readonly wasmreader_crJson: (a: number) => [number, number];
259
298
  readonly wasmreader_fromBlob: (a: number, b: number, c: any, d: number, e: number) => any;
260
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;
261
301
  readonly wasmreader_json: (a: number) => [number, number];
262
302
  readonly wasmreader_manifestStore: (a: number) => [number, number, number];
263
303
  readonly wasmreader_resourceToBytes: (a: number, b: number, c: number) => [number, number, number];
304
+ readonly __wbg_wasmsigner_free: (a: number, b: number) => void;
305
+ readonly wasmsigner_fromDefinition: (a: any) => [number, number, number];
264
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];
265
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;
266
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}
@@ -530,6 +562,13 @@ function __wbg_get_imports() {
530
562
  const ret = Number(arg0);
531
563
  return ret;
532
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
+ },
533
572
  __wbg___wbindgen_bigint_get_as_i64_38130e98eecd467d: function(arg0, arg1) {
534
573
  const v = arg1;
535
574
  const ret = typeof(v) === 'bigint' ? v : undefined;
@@ -560,6 +599,10 @@ function __wbg_get_imports() {
560
599
  const ret = typeof(arg0) === 'function';
561
600
  return ret;
562
601
  },
602
+ __wbg___wbindgen_is_null_87c3bfe968c6a5ad: function(arg0) {
603
+ const ret = arg0 === null;
604
+ return ret;
605
+ },
563
606
  __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
564
607
  const val = arg0;
565
608
  const ret = typeof(val) === 'object' && val !== null;
@@ -1011,12 +1054,12 @@ function __wbg_get_imports() {
1011
1054
  return ret;
1012
1055
  },
1013
1056
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1014
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3090, 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`.
1015
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_);
1016
1059
  return ret;
1017
1060
  },
1018
1061
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1019
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1862, 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`.
1020
1063
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke_______true_);
1021
1064
  return ret;
1022
1065
  },
@@ -1257,6 +1300,13 @@ function passArray32ToWasm0(arg, malloc) {
1257
1300
  return ptr;
1258
1301
  }
1259
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
+
1260
1310
  function passStringToWasm0(arg, malloc, realloc) {
1261
1311
  if (realloc === undefined) {
1262
1312
  const buf = cachedTextEncoder.encode(arg);
@@ -1421,4 +1471,4 @@ async function __wbg_init(module_or_path) {
1421
1471
  }
1422
1472
 
1423
1473
  export { initSync, __wbg_init as default };
1424
- export const WASM_SRI = "sha512-sY8Kfs0hgY1uKvgI9KwU9YMZUUQmQ+76LLbFfkRmkB0r/EAVr6B/fJNYEP2Ej/6gT5qQrTYJZYaFJ4KFNUOrwA==";
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,18 +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];
37
+ export const __wbg_wasmsigner_free: (a: number, b: number) => void;
38
+ export const wasmsigner_fromDefinition: (a: any) => [number, number, number];
38
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];
39
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;
40
41
  export const wasm_bindgen_4d7940e3be85a6dc___convert__closures_____invoke_______true_: (a: number, b: number) => void;