@contentauth/c2pa-wasm 0.9.2 → 0.11.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.9.2",
3
+ "version": "0.11.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/pkg/c2pa.d.ts CHANGED
@@ -20,6 +20,10 @@ export class WasmBuilder {
20
20
  * Add an action to the manifest's `Actions` assertion.
21
21
  */
22
22
  addAction(action: any): void;
23
+ /**
24
+ * Add an assertion to the manifest under `label` with the given `data`.
25
+ */
26
+ addAssertion(label: string, data: any): void;
23
27
  /**
24
28
  * Add an ingredient to the manifest from a JSON ingredient definition without a blob
25
29
  *
@@ -47,6 +51,32 @@ export class WasmBuilder {
47
51
  * Add a [`Blob`] to the manifest as a resource. The ID must match an identifier in the manifest.
48
52
  */
49
53
  addResourceFromBlob(id: string, blob: Blob): void;
54
+ /**
55
+ * Retains only the actions at the given 0-based indices into the actions currently returned
56
+ * by [`Self::get_definition`]'s `c2pa.actions` assertion.
57
+ *
58
+ * The inception action, `c2pa.created` or `c2pa.opened`, is always kept regardless of
59
+ * `indices`, and is moved to index 0 if needed, so the manifest stays valid per the C2PA
60
+ * spec. Sets `allActionsIncluded = false` when anything is removed.
61
+ *
62
+ * Indices are resolved on the JS side, rather than accepting a predicate here, because the
63
+ * builder lives in a worker and JS callbacks can't be invoked synchronously across that
64
+ * boundary.
65
+ *
66
+ * This does not touch ingredients. Call [`Self::filter_ingredients_at`] with an empty list
67
+ * to drop all orphans afterwards if you also want to drop ingredients now orphaned by the
68
+ * removed actions.
69
+ */
70
+ filterActionsAt(indices: Uint32Array): void;
71
+ /**
72
+ * Retains ingredients, rescuing an otherwise-orphaned ingredient when its 0-based index into
73
+ * [`Self::get_definition`]'s `ingredients` array is present in `indices`. Referenced and
74
+ * `parentOf` ingredients are always kept, per `Builder::filter_ingredients`; `indices` can
75
+ * only rescue an orphan, never drop a referenced or lineage ingredient.
76
+ *
77
+ * See [`Self::filter_actions_at`] for why this takes indices rather than a predicate.
78
+ */
79
+ filterIngredientsAt(indices: Uint32Array): void;
50
80
  /**
51
81
  * Attempts to create a new `WasmBuilder` from a builder archive.
52
82
  * Optionally accepts a context JSON string to configure the builder.
@@ -180,10 +210,13 @@ export interface InitOutput {
180
210
  readonly __wbg_wasmreader_free: (a: number, b: number) => void;
181
211
  readonly run: () => void;
182
212
  readonly wasmbuilder_addAction: (a: number, b: any) => [number, number];
213
+ readonly wasmbuilder_addAssertion: (a: number, b: number, c: number, d: any) => [number, number];
183
214
  readonly wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
184
215
  readonly wasmbuilder_addIngredientFromBlob: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
185
216
  readonly wasmbuilder_addRedaction: (a: number, b: number, c: number, d: any) => [number, number];
186
217
  readonly wasmbuilder_addResourceFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
218
+ readonly wasmbuilder_filterActionsAt: (a: number, b: number, c: number) => [number, number];
219
+ readonly wasmbuilder_filterIngredientsAt: (a: number, b: number, c: number) => [number, number];
187
220
  readonly wasmbuilder_fromArchive: (a: any, b: number, c: number) => [number, number, number];
188
221
  readonly wasmbuilder_fromJson: (a: number, b: number, c: number, d: number) => [number, number, number];
189
222
  readonly wasmbuilder_getDefinition: (a: number) => [number, number, number];
package/pkg/c2pa.js CHANGED
@@ -30,6 +30,19 @@ export class WasmBuilder {
30
30
  throw takeFromExternrefTable0(ret[0]);
31
31
  }
32
32
  }
33
+ /**
34
+ * Add an assertion to the manifest under `label` with the given `data`.
35
+ * @param {string} label
36
+ * @param {any} data
37
+ */
38
+ addAssertion(label, data) {
39
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
40
+ const len0 = WASM_VECTOR_LEN;
41
+ const ret = wasm.wasmbuilder_addAssertion(this.__wbg_ptr, ptr0, len0, data);
42
+ if (ret[1]) {
43
+ throw takeFromExternrefTable0(ret[0]);
44
+ }
45
+ }
33
46
  /**
34
47
  * Add an ingredient to the manifest from a JSON ingredient definition without a blob
35
48
  *
@@ -94,6 +107,48 @@ export class WasmBuilder {
94
107
  throw takeFromExternrefTable0(ret[0]);
95
108
  }
96
109
  }
110
+ /**
111
+ * Retains only the actions at the given 0-based indices into the actions currently returned
112
+ * by [`Self::get_definition`]'s `c2pa.actions` assertion.
113
+ *
114
+ * The inception action, `c2pa.created` or `c2pa.opened`, is always kept regardless of
115
+ * `indices`, and is moved to index 0 if needed, so the manifest stays valid per the C2PA
116
+ * spec. Sets `allActionsIncluded = false` when anything is removed.
117
+ *
118
+ * Indices are resolved on the JS side, rather than accepting a predicate here, because the
119
+ * builder lives in a worker and JS callbacks can't be invoked synchronously across that
120
+ * boundary.
121
+ *
122
+ * This does not touch ingredients. Call [`Self::filter_ingredients_at`] with an empty list
123
+ * to drop all orphans afterwards if you also want to drop ingredients now orphaned by the
124
+ * removed actions.
125
+ * @param {Uint32Array} indices
126
+ */
127
+ filterActionsAt(indices) {
128
+ const ptr0 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ret = wasm.wasmbuilder_filterActionsAt(this.__wbg_ptr, ptr0, len0);
131
+ if (ret[1]) {
132
+ throw takeFromExternrefTable0(ret[0]);
133
+ }
134
+ }
135
+ /**
136
+ * Retains ingredients, rescuing an otherwise-orphaned ingredient when its 0-based index into
137
+ * [`Self::get_definition`]'s `ingredients` array is present in `indices`. Referenced and
138
+ * `parentOf` ingredients are always kept, per `Builder::filter_ingredients`; `indices` can
139
+ * only rescue an orphan, never drop a referenced or lineage ingredient.
140
+ *
141
+ * See [`Self::filter_actions_at`] for why this takes indices rather than a predicate.
142
+ * @param {Uint32Array} indices
143
+ */
144
+ filterIngredientsAt(indices) {
145
+ const ptr0 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
146
+ const len0 = WASM_VECTOR_LEN;
147
+ const ret = wasm.wasmbuilder_filterIngredientsAt(this.__wbg_ptr, ptr0, len0);
148
+ if (ret[1]) {
149
+ throw takeFromExternrefTable0(ret[0]);
150
+ }
151
+ }
97
152
  /**
98
153
  * Attempts to create a new `WasmBuilder` from a builder archive.
99
154
  * Optionally accepts a context JSON string to configure the builder.
@@ -923,12 +978,12 @@ function __wbg_get_imports() {
923
978
  return ret;
924
979
  },
925
980
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
926
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3154, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
981
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3153, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
927
982
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_304c265eb9e6f0af___convert__closures_____invoke___wasm_bindgen_304c265eb9e6f0af___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_304c265eb9e6f0af___JsError___true_);
928
983
  return ret;
929
984
  },
930
985
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
931
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1911, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
986
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1910, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
932
987
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_304c265eb9e6f0af___convert__closures_____invoke_______true_);
933
988
  return ret;
934
989
  },
@@ -1105,6 +1160,14 @@ function getStringFromWasm0(ptr, len) {
1105
1160
  return decodeText(ptr >>> 0, len);
1106
1161
  }
1107
1162
 
1163
+ let cachedUint32ArrayMemory0 = null;
1164
+ function getUint32ArrayMemory0() {
1165
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1166
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1167
+ }
1168
+ return cachedUint32ArrayMemory0;
1169
+ }
1170
+
1108
1171
  let cachedUint8ArrayMemory0 = null;
1109
1172
  function getUint8ArrayMemory0() {
1110
1173
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -1154,6 +1217,13 @@ function makeMutClosure(arg0, arg1, f) {
1154
1217
  return real;
1155
1218
  }
1156
1219
 
1220
+ function passArray32ToWasm0(arg, malloc) {
1221
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1222
+ getUint32ArrayMemory0().set(arg, ptr / 4);
1223
+ WASM_VECTOR_LEN = arg.length;
1224
+ return ptr;
1225
+ }
1226
+
1157
1227
  function passStringToWasm0(arg, malloc, realloc) {
1158
1228
  if (realloc === undefined) {
1159
1229
  const buf = cachedTextEncoder.encode(arg);
@@ -1232,6 +1302,7 @@ function __wbg_finalize_init(instance, module) {
1232
1302
  wasm = instance.exports;
1233
1303
  wasmModule = module;
1234
1304
  cachedDataViewMemory0 = null;
1305
+ cachedUint32ArrayMemory0 = null;
1235
1306
  cachedUint8ArrayMemory0 = null;
1236
1307
  wasm.__wbindgen_start();
1237
1308
  return wasm;
@@ -1317,4 +1388,4 @@ async function __wbg_init(module_or_path) {
1317
1388
  }
1318
1389
 
1319
1390
  export { initSync, __wbg_init as default };
1320
- export const WASM_SRI = "sha512-ErrUz6A2ldqIdi5Avc5WdNkzIJvWFlfoA8tGPw6ctn1X1MNBhLi7wtloVeQzBB1ozTPV92M9lio2Y0uA4wq5UQ==";
1391
+ export const WASM_SRI = "sha512-NsX4t/kdoAAEqcVRXG5oYJKSHNKo+sgsxrb9Y4vJnpMhgkMP7hoAa8G1draflgtUXI7hjMDd9dPNkKVfUynv+A==";
package/pkg/c2pa_bg.wasm CHANGED
Binary file
@@ -8,10 +8,13 @@ export const __wbg_wasmbuilder_free: (a: number, b: number) => void;
8
8
  export const __wbg_wasmreader_free: (a: number, b: number) => void;
9
9
  export const run: () => void;
10
10
  export const wasmbuilder_addAction: (a: number, b: any) => [number, number];
11
+ export const wasmbuilder_addAssertion: (a: number, b: number, c: number, d: any) => [number, number];
11
12
  export const wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
12
13
  export const wasmbuilder_addIngredientFromBlob: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
13
14
  export const wasmbuilder_addRedaction: (a: number, b: number, c: number, d: any) => [number, number];
14
15
  export const wasmbuilder_addResourceFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
16
+ export const wasmbuilder_filterActionsAt: (a: number, b: number, c: number) => [number, number];
17
+ export const wasmbuilder_filterIngredientsAt: (a: number, b: number, c: number) => [number, number];
15
18
  export const wasmbuilder_fromArchive: (a: any, b: number, c: number) => [number, number, number];
16
19
  export const wasmbuilder_fromJson: (a: number, b: number, c: number, d: number) => [number, number, number];
17
20
  export const wasmbuilder_getDefinition: (a: number) => [number, number, number];