@contentauth/c2pa-node 0.5.5 → 0.6.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.
@@ -3,15 +3,6 @@
3
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
4
  // or the MIT license (http://opensource.org/licenses/MIT),
5
5
  // at your option.
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
6
  import * as fs from "fs-extra";
16
7
  import path from "path";
17
8
  import * as crypto from "crypto";
@@ -21,27 +12,28 @@ import { Reader } from "./Reader.js";
21
12
  import { Builder } from "./Builder.js";
22
13
  const tempDir = path.join(__dirname, "tmp");
23
14
  class TestSigner {
15
+ privateKey;
24
16
  constructor(privateKey) {
25
- this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
26
- const sign = crypto.createSign("SHA256");
27
- sign.update(bytes);
28
- sign.end();
29
- const signature = sign.sign(this.privateKey);
30
- return signature;
31
- });
32
17
  this.privateKey = crypto.createPrivateKey({
33
18
  key: privateKey,
34
19
  format: "pem",
35
20
  });
36
21
  }
22
+ sign = async (bytes) => {
23
+ const sign = crypto.createSign("SHA256");
24
+ sign.update(bytes);
25
+ sign.end();
26
+ const signature = sign.sign(this.privateKey);
27
+ return signature;
28
+ };
37
29
  }
38
30
  describe("TestSigner", () => {
39
- it("should sign data", () => __awaiter(void 0, void 0, void 0, function* () {
40
- const signer = new TestSigner(yield fs.readFile("./tests/fixtures/certs/es256.pem"));
31
+ it("should sign data", async () => {
32
+ const signer = new TestSigner(await fs.readFile("./tests/fixtures/certs/es256.pem"));
41
33
  const bytes = Buffer.from("Hello, World!");
42
- const signature = yield signer.sign(bytes);
34
+ const signature = await signer.sign(bytes);
43
35
  expect(signature.length).toBeGreaterThan(0);
44
- }));
36
+ });
45
37
  });
46
38
  describe("Builder", () => {
47
39
  const parent_json = `{
@@ -93,22 +85,22 @@ describe("Builder", () => {
93
85
  let source;
94
86
  let publicKey;
95
87
  let privateKey;
96
- beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
97
- yield fs.ensureDir(tempDir);
88
+ beforeAll(async () => {
89
+ await fs.ensureDir(tempDir);
98
90
  // Read all test files once
99
91
  source = {
100
- buffer: yield fs.readFile("./tests/fixtures/CA.jpg"),
92
+ buffer: await fs.readFile("./tests/fixtures/CA.jpg"),
101
93
  mimeType: "image/jpeg",
102
94
  };
103
- testThumbnail = yield fs.readFile("./tests/fixtures/thumbnail.jpg");
104
- publicKey = yield fs.readFile("./tests/fixtures/certs/es256.pub");
105
- privateKey = yield fs.readFile("./tests/fixtures/certs/es256.pem");
95
+ testThumbnail = await fs.readFile("./tests/fixtures/thumbnail.jpg");
96
+ publicKey = await fs.readFile("./tests/fixtures/certs/es256.pub");
97
+ privateKey = await fs.readFile("./tests/fixtures/certs/es256.pem");
106
98
  testAssertion = JSON.stringify({ answer: 42 });
107
- }));
108
- afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
109
- yield fs.remove(tempDir);
110
- }));
111
- it("should build a manifest store", () => __awaiter(void 0, void 0, void 0, function* () {
99
+ });
100
+ afterAll(async () => {
101
+ await fs.remove(tempDir);
102
+ });
103
+ it("should build a manifest store", async () => {
112
104
  const test_definition = {
113
105
  claim_generator: "test-generator",
114
106
  claim_generator_info: [
@@ -128,14 +120,14 @@ describe("Builder", () => {
128
120
  resources: { resources: {} },
129
121
  };
130
122
  const builder = Builder.withJson(test_definition);
131
- yield builder.addIngredient(parent_json, source);
123
+ await builder.addIngredient(parent_json, source);
132
124
  builder.addAssertion("org.test.assertion", "assertion");
133
- yield builder.addResource(thumbnail_ref.identifier, {
125
+ await builder.addResource(thumbnail_ref.identifier, {
134
126
  buffer: Buffer.from("12345"),
135
127
  mimeType: "jpeg",
136
128
  });
137
129
  // Wait for any pending async operations
138
- yield Promise.resolve();
130
+ await Promise.resolve();
139
131
  const definition = builder.getManifestDefinition();
140
132
  expect(definition.vendor).toBe("test");
141
133
  expect(definition.title).toBe("builder-test-manifest");
@@ -144,48 +136,47 @@ describe("Builder", () => {
144
136
  expect(definition.ingredients[0].title).toStrictEqual("c2pa-bindings Test");
145
137
  expect(definition.assertions[0].label).toBe("org.test.assertion");
146
138
  expect(definition.label).toBe("ABCDE");
147
- }));
139
+ });
148
140
  describe("Sign and Archive", () => {
149
141
  let builder;
150
142
  beforeEach(() => {
151
143
  builder = Builder.withJson(manifestDefinition);
152
144
  builder.updateManifestProperty("claim_version", 2);
153
145
  });
154
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
146
+ beforeEach(async () => {
155
147
  // Add ingredients and resources after builder is initialized
156
- yield builder.addIngredient(parent_json, source);
157
- yield builder.addResource("thumbnail.jpg", {
148
+ await builder.addIngredient(parent_json, source);
149
+ await builder.addResource("thumbnail.jpg", {
158
150
  mimeType: "jpeg",
159
151
  buffer: testThumbnail,
160
152
  });
161
- yield builder.addResource("ingredient-thumb.jpg", {
153
+ await builder.addResource("ingredient-thumb.jpg", {
162
154
  mimeType: "jpeg",
163
155
  buffer: testThumbnail,
164
156
  });
165
- yield builder.addResource("prompt.txt", {
157
+ await builder.addResource("prompt.txt", {
166
158
  buffer: Buffer.from("a random prompt"),
167
159
  mimeType: "text/plain",
168
160
  });
169
161
  builder.addAssertion("org.life.meaning", testAssertion);
170
162
  builder.addAssertion("org.life.meaning.json", testAssertion, "Json");
171
163
  // Wait for any pending operations
172
- yield Promise.resolve();
173
- }));
174
- it("should sign data", () => __awaiter(void 0, void 0, void 0, function* () {
164
+ await Promise.resolve();
165
+ });
166
+ it("should sign data", async () => {
175
167
  const dest = { path: path.join(tempDir, "signed.jpg") };
176
168
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
177
169
  const bytes = builder.sign(signer, source, dest);
178
170
  expect(bytes.length).toBeGreaterThan(0);
179
- const reader = yield Reader.fromAsset(dest);
171
+ const reader = await Reader.fromAsset(dest);
180
172
  expect(reader).not.toBeNull();
181
173
  const manifestStore = reader.json();
182
174
  const activeManifest = reader.getActive();
183
175
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
184
176
  expect(manifestStore.active_manifest).not.toBeUndefined();
185
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
186
- }));
187
- it("should add a CBOR assertion, sign, and verify it in the signed manifest", () => __awaiter(void 0, void 0, void 0, function* () {
188
- var _a;
177
+ expect(activeManifest?.title).toBe("Test_Manifest");
178
+ });
179
+ it("should add a CBOR assertion, sign, and verify it in the signed manifest", async () => {
189
180
  // Add the c2pa.watermarked action as a CBOR assertion
190
181
  const actionsAssertion = {
191
182
  actions: [
@@ -200,10 +191,10 @@ describe("Builder", () => {
200
191
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
201
192
  builder.sign(signer, source, dest);
202
193
  // Read and verify the assertion in the signed manifest
203
- const reader = yield Reader.fromAsset(dest);
194
+ const reader = await Reader.fromAsset(dest);
204
195
  expect(reader).not.toBeNull();
205
196
  const activeManifest = reader.getActive();
206
- const cborAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((a) => a.label === "c2pa.actions.v2");
197
+ const cborAssertion = activeManifest?.assertions?.find((a) => a.label === "c2pa.actions.v2");
207
198
  expect(cborAssertion).toBeDefined();
208
199
  if (isActionsAssertion(cborAssertion)) {
209
200
  const actions = cborAssertion.data.actions.map((a) => a.action);
@@ -212,18 +203,18 @@ describe("Builder", () => {
212
203
  else {
213
204
  throw new Error("CBOR assertion does not have the expected structure");
214
205
  }
215
- }));
216
- it("should archive and construct from archive", () => __awaiter(void 0, void 0, void 0, function* () {
206
+ });
207
+ it("should archive and construct from archive", async () => {
217
208
  const dest = {
218
209
  buffer: null,
219
210
  };
220
211
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
221
212
  const outputPath = path.join(tempDir, "archive.zip");
222
213
  const archive = { path: outputPath };
223
- yield builder.toArchive(archive);
224
- const builder2 = yield Builder.fromArchive(archive);
214
+ await builder.toArchive(archive);
215
+ const builder2 = await Builder.fromArchive(archive);
225
216
  builder2.sign(signer, source, dest);
226
- const reader = yield Reader.fromAsset({
217
+ const reader = await Reader.fromAsset({
227
218
  buffer: dest.buffer,
228
219
  mimeType: "jpeg",
229
220
  });
@@ -232,26 +223,26 @@ describe("Builder", () => {
232
223
  const activeManifest = reader.getActive();
233
224
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
234
225
  expect(manifestStore.active_manifest).not.toBeUndefined();
235
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
236
- }));
237
- it("should populate buffer when archiving to buffer", () => __awaiter(void 0, void 0, void 0, function* () {
226
+ expect(activeManifest?.title).toBe("Test_Manifest");
227
+ });
228
+ it("should populate buffer when archiving to buffer", async () => {
238
229
  const archive = {
239
230
  buffer: null,
240
231
  };
241
- yield builder.toArchive(archive);
232
+ await builder.toArchive(archive);
242
233
  expect(archive.buffer).not.toBeNull();
243
234
  expect(archive.buffer.length).toBeGreaterThan(0);
244
- }));
245
- it("should write archive to file", () => __awaiter(void 0, void 0, void 0, function* () {
235
+ });
236
+ it("should write archive to file", async () => {
246
237
  const archivePath = path.join(tempDir, "archive_file_test.zip");
247
238
  const archive = { path: archivePath };
248
- yield builder.toArchive(archive);
239
+ await builder.toArchive(archive);
249
240
  // Verify file was created and has content
250
- expect(yield fs.pathExists(archivePath)).toBe(true);
251
- const stats = yield fs.stat(archivePath);
241
+ expect(await fs.pathExists(archivePath)).toBe(true);
242
+ const stats = await fs.stat(archivePath);
252
243
  expect(stats.size).toBeGreaterThan(0);
253
- }));
254
- it("should construct reader directly from builder archive buffer", () => __awaiter(void 0, void 0, void 0, function* () {
244
+ });
245
+ it("should construct reader directly from builder archive buffer", async () => {
255
246
  const settings = JSON.stringify({
256
247
  builder: {
257
248
  generate_c2pa_archive: true,
@@ -275,23 +266,23 @@ describe("Builder", () => {
275
266
  };
276
267
  const testBuilder = Builder.withJson(simpleManifestDefinition, settings);
277
268
  // Add an ingredient
278
- yield testBuilder.addIngredient(parent_json, source);
269
+ await testBuilder.addIngredient(parent_json, source);
279
270
  // Create an archive from the builder written to a buffer
280
271
  const archive = {
281
272
  buffer: null,
282
273
  };
283
- yield testBuilder.toArchive(archive);
274
+ await testBuilder.toArchive(archive);
284
275
  // Verify buffer was populated
285
276
  expect(archive.buffer).not.toBeNull();
286
277
  expect(archive.buffer.length).toBeGreaterThan(0);
287
278
  // Construct a reader from the builder archive with mime-type "application/c2pa"
288
- const reader = yield Reader.fromAsset({
279
+ const reader = await Reader.fromAsset({
289
280
  buffer: archive.buffer,
290
281
  mimeType: "application/c2pa",
291
282
  }, settings);
292
283
  expect(reader).not.toBeNull();
293
- }));
294
- it("should sign data with callback to file", () => __awaiter(void 0, void 0, void 0, function* () {
284
+ });
285
+ it("should sign data with callback to file", async () => {
295
286
  const dest = {
296
287
  path: path.join(tempDir, "callback_signed.jpg"),
297
288
  };
@@ -303,17 +294,17 @@ describe("Builder", () => {
303
294
  directCoseHandling: false,
304
295
  };
305
296
  const signer = new TestSigner(privateKey);
306
- const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
297
+ const bytes = await builder.signConfigAsync(signer.sign, signerConfig, source, dest);
307
298
  expect(bytes.length).toBeGreaterThan(0);
308
- const reader = yield Reader.fromAsset(dest);
299
+ const reader = await Reader.fromAsset(dest);
309
300
  expect(reader).not.toBeNull();
310
301
  const manifestStore = reader.json();
311
302
  const activeManifest = reader.getActive();
312
303
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
313
304
  expect(manifestStore.active_manifest).not.toBeUndefined();
314
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
315
- }));
316
- it("should sign data with callback to buffer", () => __awaiter(void 0, void 0, void 0, function* () {
305
+ expect(activeManifest?.title).toBe("Test_Manifest");
306
+ });
307
+ it("should sign data with callback to buffer", async () => {
317
308
  const dest = {
318
309
  buffer: null,
319
310
  };
@@ -325,9 +316,9 @@ describe("Builder", () => {
325
316
  directCoseHandling: false,
326
317
  };
327
318
  const signer = new TestSigner(privateKey);
328
- const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
319
+ const bytes = await builder.signConfigAsync(signer.sign, signerConfig, source, dest);
329
320
  expect(bytes.length).toBeGreaterThan(0);
330
- const reader = yield Reader.fromAsset({
321
+ const reader = await Reader.fromAsset({
331
322
  buffer: dest.buffer,
332
323
  mimeType: "jpeg",
333
324
  });
@@ -336,9 +327,9 @@ describe("Builder", () => {
336
327
  const activeManifest = reader.getActive();
337
328
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
338
329
  expect(manifestStore.active_manifest).not.toBeUndefined();
339
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
340
- }));
341
- it("should sign data with callback signer to buffer", () => __awaiter(void 0, void 0, void 0, function* () {
330
+ expect(activeManifest?.title).toBe("Test_Manifest");
331
+ });
332
+ it("should sign data with callback signer to buffer", async () => {
342
333
  const dest = {
343
334
  buffer: null,
344
335
  };
@@ -351,9 +342,9 @@ describe("Builder", () => {
351
342
  };
352
343
  const testSigner = new TestSigner(privateKey);
353
344
  const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
354
- const bytes = yield builder.signAsync(signer, source, dest);
345
+ const bytes = await builder.signAsync(signer, source, dest);
355
346
  expect(bytes.length).toBeGreaterThan(0);
356
- const reader = yield Reader.fromAsset({
347
+ const reader = await Reader.fromAsset({
357
348
  buffer: dest.buffer,
358
349
  mimeType: "jpeg",
359
350
  });
@@ -362,10 +353,9 @@ describe("Builder", () => {
362
353
  const activeManifest = reader.getActive();
363
354
  expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
364
355
  expect(manifestStore.active_manifest).not.toBeUndefined();
365
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
366
- }));
367
- it("should preserve JSON assertion characters without escaping", () => __awaiter(void 0, void 0, void 0, function* () {
368
- var _a;
356
+ expect(activeManifest?.title).toBe("Test_Manifest");
357
+ });
358
+ it("should preserve JSON assertion characters without escaping", async () => {
369
359
  const fingerprintAssertion = JSON.stringify({
370
360
  alg: "sha256",
371
361
  blocks: [
@@ -379,14 +369,14 @@ describe("Builder", () => {
379
369
  const dest = { path: path.join(tempDir, "json_test.jpg") };
380
370
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
381
371
  builder.sign(signer, source, dest);
382
- const reader = yield Reader.fromAsset(dest);
372
+ const reader = await Reader.fromAsset(dest);
383
373
  expect(reader).not.toBeNull();
384
374
  const manifest = reader.json();
385
375
  // Check that our specific JSON assertion doesn't have escaped characters
386
376
  const activeManifest = manifest.manifests[manifest.active_manifest];
387
- const fingerprintAssertionData = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((a) => a.label === "org.contentauth.fingerprint");
377
+ const fingerprintAssertionData = activeManifest?.assertions?.find((a) => a.label === "org.contentauth.fingerprint");
388
378
  expect(fingerprintAssertionData).toBeDefined();
389
- expect(fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data).toEqual({
379
+ expect(fingerprintAssertionData?.data).toEqual({
390
380
  alg: "sha256",
391
381
  blocks: [
392
382
  {
@@ -396,10 +386,10 @@ describe("Builder", () => {
396
386
  ],
397
387
  });
398
388
  // The assertion data should not be a string with escaped quotes
399
- expect(typeof (fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data)).toBe("object");
400
- expect(JSON.stringify(fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data)).not.toContain("\\");
401
- }));
402
- it("should archive and restore builder with ingredient thumbnail", () => __awaiter(void 0, void 0, void 0, function* () {
389
+ expect(typeof fingerprintAssertionData?.data).toBe("object");
390
+ expect(JSON.stringify(fingerprintAssertionData?.data)).not.toContain("\\");
391
+ });
392
+ it("should archive and restore builder with ingredient thumbnail", async () => {
403
393
  const manifestDefinition = {
404
394
  claim_generator_info: [
405
395
  {
@@ -427,25 +417,25 @@ describe("Builder", () => {
427
417
  };
428
418
  const builder = Builder.withJson(manifestDefinition);
429
419
  const ingredientJson = '{"title": "Test Ingredient"}';
430
- const testThumbnail = yield fs.readFile("./tests/fixtures/thumbnail.jpg");
431
- yield builder.addIngredient(ingredientJson, {
420
+ const testThumbnail = await fs.readFile("./tests/fixtures/thumbnail.jpg");
421
+ await builder.addIngredient(ingredientJson, {
432
422
  buffer: testThumbnail,
433
423
  mimeType: "jpeg",
434
424
  });
435
425
  // Archive the builder
436
426
  const archivePath = path.join(tempDir, `ingredient_thumb_archive_${Date.now()}.zip`);
437
- yield builder.toArchive({ path: archivePath });
427
+ await builder.toArchive({ path: archivePath });
438
428
  // Ensure the file is written to disk before proceeding
439
- yield fs.access(archivePath);
429
+ await fs.access(archivePath);
440
430
  // Restore from archive
441
- const builder2 = yield Builder.fromArchive({ path: archivePath });
431
+ const builder2 = await Builder.fromArchive({ path: archivePath });
442
432
  // Sign with restored builder
443
433
  const dest = { buffer: null };
444
- const publicKey = yield fs.readFile("./tests/fixtures/certs/es256.pub");
445
- const privateKey = yield fs.readFile("./tests/fixtures/certs/es256.pem");
434
+ const publicKey = await fs.readFile("./tests/fixtures/certs/es256.pub");
435
+ const privateKey = await fs.readFile("./tests/fixtures/certs/es256.pem");
446
436
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
447
437
  builder2.sign(signer, source, dest);
448
- const reader = yield Reader.fromAsset({
438
+ const reader = await Reader.fromAsset({
449
439
  buffer: dest.buffer,
450
440
  mimeType: "jpeg",
451
441
  });
@@ -453,8 +443,8 @@ describe("Builder", () => {
453
443
  const manifestStore = reader.json();
454
444
  expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
455
445
  expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
456
- }));
457
- it("should add ingredient with custom metadata", () => __awaiter(void 0, void 0, void 0, function* () {
446
+ });
447
+ it("should add ingredient with custom metadata", async () => {
458
448
  const builder = Builder.new();
459
449
  const ingredient = {
460
450
  title: "Test Ingredient",
@@ -472,13 +462,12 @@ describe("Builder", () => {
472
462
  customArray: ["item1", "item2", "item3"],
473
463
  },
474
464
  };
475
- yield builder.addIngredient(JSON.stringify(ingredient));
465
+ await builder.addIngredient(JSON.stringify(ingredient));
476
466
  const definition = builder.getManifestDefinition();
477
467
  expect(definition.ingredients).toHaveLength(1);
478
468
  expect(definition.ingredients[0]).toMatchObject(ingredient);
479
- }));
480
- it("should redact a thumbnail from an ingredient manifest", () => __awaiter(void 0, void 0, void 0, function* () {
481
- var _a;
469
+ });
470
+ it("should redact a thumbnail from an ingredient manifest", async () => {
482
471
  const signerConfig = {
483
472
  alg: "es256",
484
473
  certs: [publicKey],
@@ -496,24 +485,24 @@ describe("Builder", () => {
496
485
  instance_id: "thumb-step1-1234",
497
486
  thumbnail: { format: "image/jpeg", identifier: "thumbnail.jpg" },
498
487
  });
499
- yield step1Builder.addResource("thumbnail.jpg", {
488
+ await step1Builder.addResource("thumbnail.jpg", {
500
489
  mimeType: "image/jpeg",
501
490
  buffer: testThumbnail,
502
491
  });
503
492
  const step1Dest = { buffer: null };
504
- yield step1Builder.signAsync(signer, source, step1Dest);
493
+ await step1Builder.signAsync(signer, source, step1Dest);
505
494
  const step1Asset = {
506
495
  buffer: step1Dest.buffer,
507
496
  mimeType: "image/jpeg",
508
497
  };
509
498
  // Verify thumbnail exists in original manifest
510
- const originalReader = yield Reader.fromAsset(step1Asset);
499
+ const originalReader = await Reader.fromAsset(step1Asset);
511
500
  expect(originalReader).not.toBeNull();
512
501
  const parentLabel = originalReader.activeLabel();
513
502
  expect(parentLabel).toBeDefined();
514
503
  const originalManifest = originalReader.getActive();
515
- expect(originalManifest === null || originalManifest === void 0 ? void 0 : originalManifest.thumbnail).toBeDefined();
516
- expect(originalManifest === null || originalManifest === void 0 ? void 0 : originalManifest.thumbnail).not.toBeNull();
504
+ expect(originalManifest?.thumbnail).toBeDefined();
505
+ expect(originalManifest?.thumbnail).not.toBeNull();
517
506
  // Redact the thumbnail
518
507
  const thumbnailUri = `self#jumbf=/c2pa/${parentLabel}/c2pa.assertions/c2pa.thumbnail.claim`;
519
508
  const redactionBuilder = Builder.withJson({
@@ -525,19 +514,18 @@ describe("Builder", () => {
525
514
  redactionBuilder.setIntent("update");
526
515
  redactionBuilder.addRedaction(thumbnailUri, "c2pa.PII.present");
527
516
  const step2Dest = { buffer: null };
528
- yield redactionBuilder.signAsync(signer, step1Asset, step2Dest);
529
- const finalReader = yield Reader.fromAsset({
517
+ await redactionBuilder.signAsync(signer, step1Asset, step2Dest);
518
+ const finalReader = await Reader.fromAsset({
530
519
  buffer: step2Dest.buffer,
531
520
  mimeType: "image/jpeg",
532
521
  });
533
522
  expect(finalReader).not.toBeNull();
534
523
  const store = finalReader.json();
535
- const parentManifest = (_a = store.manifests) === null || _a === void 0 ? void 0 : _a[parentLabel];
524
+ const parentManifest = store.manifests?.[parentLabel];
536
525
  expect(parentManifest).toBeDefined();
537
- expect(parentManifest === null || parentManifest === void 0 ? void 0 : parentManifest.thumbnail).toBeUndefined();
538
- }));
539
- it("should redact an assertion from an ingredient manifest", () => __awaiter(void 0, void 0, void 0, function* () {
540
- var _a, _b;
526
+ expect(parentManifest?.thumbnail).toBeUndefined();
527
+ });
528
+ it("should redact an assertion from an ingredient manifest", async () => {
541
529
  const signerConfig = {
542
530
  alg: "es256",
543
531
  certs: [publicKey],
@@ -571,13 +559,13 @@ describe("Builder", () => {
571
559
  ],
572
560
  });
573
561
  const step1Dest = { buffer: null };
574
- yield step1Builder.signAsync(signer, source, step1Dest);
562
+ await step1Builder.signAsync(signer, source, step1Dest);
575
563
  const step1Asset = {
576
564
  buffer: step1Dest.buffer,
577
565
  mimeType: "image/jpeg",
578
566
  };
579
567
  // Verify both assertions exist in original manifest
580
- const originalReader = yield Reader.fromAsset(step1Asset);
568
+ const originalReader = await Reader.fromAsset(step1Asset);
581
569
  expect(originalReader).not.toBeNull();
582
570
  const parentLabel = originalReader.activeLabel();
583
571
  expect(parentLabel).toBeDefined();
@@ -596,20 +584,20 @@ describe("Builder", () => {
596
584
  redactionBuilder.setIntent("update");
597
585
  redactionBuilder.addRedaction(redactionUri, "c2pa.PII.present");
598
586
  const step2Dest = { buffer: null };
599
- yield redactionBuilder.signAsync(signer, step1Asset, step2Dest);
600
- const finalReader = yield Reader.fromAsset({
587
+ await redactionBuilder.signAsync(signer, step1Asset, step2Dest);
588
+ const finalReader = await Reader.fromAsset({
601
589
  buffer: step2Dest.buffer,
602
590
  mimeType: "image/jpeg",
603
591
  });
604
592
  expect(finalReader).not.toBeNull();
605
593
  const store = finalReader.json();
606
- const parentManifest = (_a = store.manifests) === null || _a === void 0 ? void 0 : _a[parentLabel];
594
+ const parentManifest = store.manifests?.[parentLabel];
607
595
  expect(parentManifest).toBeDefined();
608
- const assertionLabels = (_b = parentManifest === null || parentManifest === void 0 ? void 0 : parentManifest.assertions) === null || _b === void 0 ? void 0 : _b.map((a) => a.label);
596
+ const assertionLabels = parentManifest?.assertions?.map((a) => a.label);
609
597
  // PII assertion removed, retained assertion still present
610
598
  expect(assertionLabels).not.toContain(piiLabel);
611
599
  expect(assertionLabels).toContain(retainedLabel);
612
- }));
600
+ });
613
601
  it("should add redactions via addRedaction method", () => {
614
602
  const uri1 = "self#jumbf=/c2pa/test-label/c2pa.assertions/cawg.identity";
615
603
  const uri2 = "self#jumbf=/c2pa/test-label/c2pa.assertions/stds.schema-org.CreativeWork";
@@ -619,7 +607,7 @@ describe("Builder", () => {
619
607
  const definition = builder.getManifestDefinition();
620
608
  expect(definition.redactions).toEqual([uri1, uri2]);
621
609
  });
622
- it("should test builder remote url", () => __awaiter(void 0, void 0, void 0, function* () {
610
+ it("should test builder remote url", async () => {
623
611
  // This test mirrors the Rust test_builder_remote_url test
624
612
  // Create a simple manifest definition similar to simple_manifest_json()
625
613
  const simpleManifestDefinition = {
@@ -660,12 +648,12 @@ describe("Builder", () => {
660
648
  const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
661
649
  // Sign the Builder and write it to the output stream
662
650
  const dest = { buffer: null };
663
- const manifestData = yield builder.signAsync(signer, source, dest);
651
+ const manifestData = await builder.signAsync(signer, source, dest);
664
652
  // Check to make sure we have a remote url and no manifest data embedded
665
653
  // Reading the image directly should fail since no_embed = true
666
654
  // Note: This might fail due to remote URL fetch, which is expected behavior
667
655
  try {
668
- yield Reader.fromAsset({
656
+ await Reader.fromAsset({
669
657
  buffer: dest.buffer,
670
658
  mimeType: "image/jpeg",
671
659
  });
@@ -677,17 +665,16 @@ describe("Builder", () => {
677
665
  expect(error).toBeDefined();
678
666
  }
679
667
  // Now validate the manifest against the written asset using the separate manifest data
680
- const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
668
+ const reader = await Reader.fromManifestDataAndAsset(manifestData, {
681
669
  buffer: dest.buffer,
682
670
  mimeType: "image/jpeg",
683
671
  });
684
672
  // Check if the manifest has the expected structure
685
673
  const activeManifest = reader.getActive();
686
674
  expect(activeManifest).toBeDefined();
687
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
688
- }));
689
- it("should add action using addAction method", () => __awaiter(void 0, void 0, void 0, function* () {
690
- var _a;
675
+ expect(activeManifest?.title).toBe("Test_Manifest");
676
+ });
677
+ it("should add action using addAction method", async () => {
691
678
  const simpleManifestDefinition = {
692
679
  claim_generator_info: [
693
680
  {
@@ -712,23 +699,22 @@ describe("Builder", () => {
712
699
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
713
700
  builder.sign(signer, source, dest);
714
701
  // Verify the action was added
715
- const reader = yield Reader.fromAsset(dest);
702
+ const reader = await Reader.fromAsset(dest);
716
703
  expect(reader).not.toBeNull();
717
704
  const activeManifest = reader.getActive();
718
- const actionsAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((a) => a.label === "c2pa.actions.v2");
705
+ const actionsAssertion = activeManifest?.assertions?.find((a) => a.label === "c2pa.actions.v2");
719
706
  expect(actionsAssertion).toBeDefined();
720
707
  if (isActionsAssertion(actionsAssertion)) {
721
708
  const actions = actionsAssertion.data.actions;
722
709
  const editedAction = actions.find((a) => a.action === "c2pa.edited");
723
710
  expect(editedAction).toBeDefined();
724
- expect(editedAction === null || editedAction === void 0 ? void 0 : editedAction.action).toBe("c2pa.edited");
711
+ expect(editedAction?.action).toBe("c2pa.edited");
725
712
  }
726
713
  else {
727
714
  throw new Error("Actions assertion does not have the expected structure");
728
715
  }
729
- }));
730
- it("should add ingredient using addIngredient method", () => __awaiter(void 0, void 0, void 0, function* () {
731
- var _a, _b;
716
+ });
717
+ it("should add ingredient using addIngredient method", async () => {
732
718
  const simpleManifestDefinition = {
733
719
  claim_generator_info: [
734
720
  {
@@ -768,18 +754,17 @@ describe("Builder", () => {
768
754
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
769
755
  builder.sign(signer, source, dest);
770
756
  // Verify the ingredient was added
771
- const reader = yield Reader.fromAsset(dest);
757
+ const reader = await Reader.fromAsset(dest);
772
758
  expect(reader).not.toBeNull();
773
759
  const activeManifest = reader.getActive();
774
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients).toBeDefined();
775
- expect((_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _a === void 0 ? void 0 : _a.length).toBeGreaterThan(0);
776
- const addedIngredient = (_b = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _b === void 0 ? void 0 : _b.find((ing) => ing.title === "Test Ingredient via addIngredient");
760
+ expect(activeManifest?.ingredients).toBeDefined();
761
+ expect(activeManifest?.ingredients?.length).toBeGreaterThan(0);
762
+ const addedIngredient = activeManifest?.ingredients?.find((ing) => ing.title === "Test Ingredient via addIngredient");
777
763
  expect(addedIngredient).toBeDefined();
778
- expect(addedIngredient === null || addedIngredient === void 0 ? void 0 : addedIngredient.instance_id).toBe("ingredient-12345");
779
- expect(addedIngredient === null || addedIngredient === void 0 ? void 0 : addedIngredient.relationship).toBe("componentOf");
780
- }));
781
- it("should add ingredient from reader", () => __awaiter(void 0, void 0, void 0, function* () {
782
- var _a;
764
+ expect(addedIngredient?.instance_id).toBe("ingredient-12345");
765
+ expect(addedIngredient?.relationship).toBe("componentOf");
766
+ });
767
+ it("should add ingredient from reader", async () => {
783
768
  const builder1 = Builder.new();
784
769
  builder1.setIntent("edit");
785
770
  const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
@@ -788,7 +773,7 @@ describe("Builder", () => {
788
773
  };
789
774
  builder1.sign(signer, source, dest1);
790
775
  // Read the signed file back with Reader
791
- const reader = yield Reader.fromAsset({
776
+ const reader = await Reader.fromAsset({
792
777
  buffer: dest1.buffer,
793
778
  mimeType: "image/jpeg",
794
779
  });
@@ -807,14 +792,14 @@ describe("Builder", () => {
807
792
  };
808
793
  builder2.sign(signer, source, dest2);
809
794
  // Verify the ingredient is in the signed manifest
810
- const reader2 = yield Reader.fromAsset({
795
+ const reader2 = await Reader.fromAsset({
811
796
  buffer: dest2.buffer,
812
797
  mimeType: "image/jpeg",
813
798
  });
814
799
  expect(reader2).not.toBeNull();
815
800
  const activeManifest = reader2.getActive();
816
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients).toBeDefined();
817
- expect((_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.ingredients) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
818
- }));
801
+ expect(activeManifest?.ingredients).toBeDefined();
802
+ expect(activeManifest?.ingredients?.length).toBe(1);
803
+ });
819
804
  });
820
805
  });