@contentauth/c2pa-wasm 0.9.1 → 0.10.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.1",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/pkg/c2pa.d.ts CHANGED
@@ -47,6 +47,32 @@ export class WasmBuilder {
47
47
  * Add a [`Blob`] to the manifest as a resource. The ID must match an identifier in the manifest.
48
48
  */
49
49
  addResourceFromBlob(id: string, blob: Blob): void;
50
+ /**
51
+ * Retains only the actions at the given 0-based indices into the actions currently returned
52
+ * by [`Self::get_definition`]'s `c2pa.actions` assertion.
53
+ *
54
+ * The inception action, `c2pa.created` or `c2pa.opened`, is always kept regardless of
55
+ * `indices`, and is moved to index 0 if needed, so the manifest stays valid per the C2PA
56
+ * spec. Sets `allActionsIncluded = false` when anything is removed.
57
+ *
58
+ * Indices are resolved on the JS side, rather than accepting a predicate here, because the
59
+ * builder lives in a worker and JS callbacks can't be invoked synchronously across that
60
+ * boundary.
61
+ *
62
+ * This does not touch ingredients. Call [`Self::filter_ingredients_at`] with an empty list
63
+ * to drop all orphans afterwards if you also want to drop ingredients now orphaned by the
64
+ * removed actions.
65
+ */
66
+ filterActionsAt(indices: Uint32Array): void;
67
+ /**
68
+ * Retains ingredients, rescuing an otherwise-orphaned ingredient when its 0-based index into
69
+ * [`Self::get_definition`]'s `ingredients` array is present in `indices`. Referenced and
70
+ * `parentOf` ingredients are always kept, per `Builder::filter_ingredients`; `indices` can
71
+ * only rescue an orphan, never drop a referenced or lineage ingredient.
72
+ *
73
+ * See [`Self::filter_actions_at`] for why this takes indices rather than a predicate.
74
+ */
75
+ filterIngredientsAt(indices: Uint32Array): void;
50
76
  /**
51
77
  * Attempts to create a new `WasmBuilder` from a builder archive.
52
78
  * Optionally accepts a context JSON string to configure the builder.
@@ -176,14 +202,16 @@ export interface InitOutput {
176
202
  readonly __wbg_wasmsigner_free: (a: number, b: number) => void;
177
203
  readonly wasmsigner_fromDefinition: (a: any) => [number, number, number];
178
204
  readonly loadSettings: (a: number, b: number) => [number, number];
205
+ readonly run: () => void;
179
206
  readonly __wbg_wasmbuilder_free: (a: number, b: number) => void;
180
207
  readonly __wbg_wasmreader_free: (a: number, b: number) => void;
181
- readonly run: () => void;
182
208
  readonly wasmbuilder_addAction: (a: number, b: any) => [number, number];
183
209
  readonly wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
184
210
  readonly wasmbuilder_addIngredientFromBlob: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
185
211
  readonly wasmbuilder_addRedaction: (a: number, b: number, c: number, d: any) => [number, number];
186
212
  readonly wasmbuilder_addResourceFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
213
+ readonly wasmbuilder_filterActionsAt: (a: number, b: number, c: number) => [number, number];
214
+ readonly wasmbuilder_filterIngredientsAt: (a: number, b: number, c: number) => [number, number];
187
215
  readonly wasmbuilder_fromArchive: (a: any, b: number, c: number) => [number, number, number];
188
216
  readonly wasmbuilder_fromJson: (a: number, b: number, c: number, d: number) => [number, number, number];
189
217
  readonly wasmbuilder_getDefinition: (a: number) => [number, number, number];
package/pkg/c2pa.js CHANGED
@@ -94,6 +94,48 @@ export class WasmBuilder {
94
94
  throw takeFromExternrefTable0(ret[0]);
95
95
  }
96
96
  }
97
+ /**
98
+ * Retains only the actions at the given 0-based indices into the actions currently returned
99
+ * by [`Self::get_definition`]'s `c2pa.actions` assertion.
100
+ *
101
+ * The inception action, `c2pa.created` or `c2pa.opened`, is always kept regardless of
102
+ * `indices`, and is moved to index 0 if needed, so the manifest stays valid per the C2PA
103
+ * spec. Sets `allActionsIncluded = false` when anything is removed.
104
+ *
105
+ * Indices are resolved on the JS side, rather than accepting a predicate here, because the
106
+ * builder lives in a worker and JS callbacks can't be invoked synchronously across that
107
+ * boundary.
108
+ *
109
+ * This does not touch ingredients. Call [`Self::filter_ingredients_at`] with an empty list
110
+ * to drop all orphans afterwards if you also want to drop ingredients now orphaned by the
111
+ * removed actions.
112
+ * @param {Uint32Array} indices
113
+ */
114
+ filterActionsAt(indices) {
115
+ const ptr0 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
116
+ const len0 = WASM_VECTOR_LEN;
117
+ const ret = wasm.wasmbuilder_filterActionsAt(this.__wbg_ptr, ptr0, len0);
118
+ if (ret[1]) {
119
+ throw takeFromExternrefTable0(ret[0]);
120
+ }
121
+ }
122
+ /**
123
+ * Retains ingredients, rescuing an otherwise-orphaned ingredient when its 0-based index into
124
+ * [`Self::get_definition`]'s `ingredients` array is present in `indices`. Referenced and
125
+ * `parentOf` ingredients are always kept, per `Builder::filter_ingredients`; `indices` can
126
+ * only rescue an orphan, never drop a referenced or lineage ingredient.
127
+ *
128
+ * See [`Self::filter_actions_at`] for why this takes indices rather than a predicate.
129
+ * @param {Uint32Array} indices
130
+ */
131
+ filterIngredientsAt(indices) {
132
+ const ptr0 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ const ret = wasm.wasmbuilder_filterIngredientsAt(this.__wbg_ptr, ptr0, len0);
135
+ if (ret[1]) {
136
+ throw takeFromExternrefTable0(ret[0]);
137
+ }
138
+ }
97
139
  /**
98
140
  * Attempts to create a new `WasmBuilder` from a builder archive.
99
141
  * Optionally accepts a context JSON string to configure the builder.
@@ -1105,6 +1147,14 @@ function getStringFromWasm0(ptr, len) {
1105
1147
  return decodeText(ptr >>> 0, len);
1106
1148
  }
1107
1149
 
1150
+ let cachedUint32ArrayMemory0 = null;
1151
+ function getUint32ArrayMemory0() {
1152
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1153
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1154
+ }
1155
+ return cachedUint32ArrayMemory0;
1156
+ }
1157
+
1108
1158
  let cachedUint8ArrayMemory0 = null;
1109
1159
  function getUint8ArrayMemory0() {
1110
1160
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -1154,6 +1204,13 @@ function makeMutClosure(arg0, arg1, f) {
1154
1204
  return real;
1155
1205
  }
1156
1206
 
1207
+ function passArray32ToWasm0(arg, malloc) {
1208
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1209
+ getUint32ArrayMemory0().set(arg, ptr / 4);
1210
+ WASM_VECTOR_LEN = arg.length;
1211
+ return ptr;
1212
+ }
1213
+
1157
1214
  function passStringToWasm0(arg, malloc, realloc) {
1158
1215
  if (realloc === undefined) {
1159
1216
  const buf = cachedTextEncoder.encode(arg);
@@ -1232,6 +1289,7 @@ function __wbg_finalize_init(instance, module) {
1232
1289
  wasm = instance.exports;
1233
1290
  wasmModule = module;
1234
1291
  cachedDataViewMemory0 = null;
1292
+ cachedUint32ArrayMemory0 = null;
1235
1293
  cachedUint8ArrayMemory0 = null;
1236
1294
  wasm.__wbindgen_start();
1237
1295
  return wasm;
@@ -1317,4 +1375,4 @@ async function __wbg_init(module_or_path) {
1317
1375
  }
1318
1376
 
1319
1377
  export { initSync, __wbg_init as default };
1320
- export const WASM_SRI = "sha512-voSOOyHsrvQK2/D0J6307GDfT7bAESyeIq+Tm89cJZoq31FMZUC7aCT1TXDmRO+LU/y0dxXBotVkJKxWv0n6Ng==";
1378
+ export const WASM_SRI = "sha512-DZ+Rq1NEKCKRFfM08e5yAqUFOkoHd7k+TJxqxAehIQxow6YtDsiWj5c58OzMKHhCbgbSN3y0xxxcPLJ+922VMA==";
package/pkg/c2pa_bg.wasm CHANGED
Binary file
@@ -4,14 +4,16 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_wasmsigner_free: (a: number, b: number) => void;
5
5
  export const wasmsigner_fromDefinition: (a: any) => [number, number, number];
6
6
  export const loadSettings: (a: number, b: number) => [number, number];
7
+ export const run: () => void;
7
8
  export const __wbg_wasmbuilder_free: (a: number, b: number) => void;
8
9
  export const __wbg_wasmreader_free: (a: number, b: number) => void;
9
- export const run: () => void;
10
10
  export const wasmbuilder_addAction: (a: number, b: any) => [number, number];
11
11
  export const wasmbuilder_addIngredient: (a: number, b: number, c: number) => [number, number];
12
12
  export const wasmbuilder_addIngredientFromBlob: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
13
13
  export const wasmbuilder_addRedaction: (a: number, b: number, c: number, d: any) => [number, number];
14
14
  export const wasmbuilder_addResourceFromBlob: (a: number, b: number, c: number, d: any) => [number, number];
15
+ export const wasmbuilder_filterActionsAt: (a: number, b: number, c: number) => [number, number];
16
+ export const wasmbuilder_filterIngredientsAt: (a: number, b: number, c: number) => [number, number];
15
17
  export const wasmbuilder_fromArchive: (a: any, b: number, c: number) => [number, number, number];
16
18
  export const wasmbuilder_fromJson: (a: number, b: number, c: number, d: number) => [number, number, number];
17
19
  export const wasmbuilder_getDefinition: (a: number) => [number, number, number];