@contentauth/c2pa-node 0.1.2 → 0.2.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.
@@ -1,42 +1,8 @@
1
- "use strict";
2
1
  // Copyright 2024 Adobe. All rights reserved.
3
2
  // This file is licensed to you under the Apache License,
4
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
4
  // or the MIT license (http://opensource.org/licenses/MIT),
6
5
  // at your option.
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
6
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
7
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
8
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,26 +12,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46
12
  step((generator = generator.apply(thisArg, _arguments || [])).next());
47
13
  });
48
14
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- // Unless required by applicable law or agreed to in writing,
54
- // this software is distributed on an "AS IS" BASIS, WITHOUT
55
- // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
56
- // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
57
- // specific language governing permissions and limitations under
58
- // each license.
59
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
60
- const index_1 = require("./index");
61
- const fs = __importStar(require("fs-extra"));
62
- const path_1 = __importDefault(require("path"));
63
- const crypto = __importStar(require("crypto"));
64
- const tempDir = path_1.default.join(__dirname, 'tmp');
15
+ import { isActionsAssertion } from "./assertions";
16
+ import { CallbackSigner, LocalSigner } from "./Signer";
17
+ import { Reader } from "./Reader";
18
+ import { Builder } from "./Builder";
19
+ import * as fs from "fs-extra";
20
+ import path from "path";
21
+ import * as crypto from "crypto";
22
+ const tempDir = path.join(__dirname, "tmp");
65
23
  class TestSigner {
66
24
  constructor(privateKey) {
67
25
  this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
68
- const sign = crypto.createSign('SHA256');
26
+ const sign = crypto.createSign("SHA256");
69
27
  sign.update(bytes);
70
28
  sign.end();
71
29
  const signature = sign.sign(this.privateKey);
@@ -73,19 +31,19 @@ class TestSigner {
73
31
  });
74
32
  this.privateKey = crypto.createPrivateKey({
75
33
  key: privateKey,
76
- format: 'pem',
34
+ format: "pem",
77
35
  });
78
36
  }
79
37
  }
80
- describe('TestSigner', () => {
81
- it('should sign data', () => __awaiter(void 0, void 0, void 0, function* () {
82
- const signer = new TestSigner(yield fs.readFile('./tests/fixtures/certs/es256.pem'));
83
- const bytes = Buffer.from('Hello, World!');
38
+ 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"));
41
+ const bytes = Buffer.from("Hello, World!");
84
42
  const signature = yield signer.sign(bytes);
85
43
  expect(signature.length).toBeGreaterThan(0);
86
44
  }));
87
45
  });
88
- describe('Builder', () => {
46
+ describe("Builder", () => {
89
47
  const parent_json = `{
90
48
  "title": "c2pa-bindings Test",
91
49
  "format": "image/jpeg",
@@ -93,44 +51,42 @@ describe('Builder', () => {
93
51
  "relationship": "parentOf"
94
52
  }`;
95
53
  const thumbnail_ref = {
96
- format: 'ingredient/jpeg',
97
- identifier: '5678',
54
+ format: "ingredient/jpeg",
55
+ identifier: "5678",
98
56
  };
99
57
  const manifestDefinition = {
100
- vendor: 'test',
58
+ vendor: "test",
59
+ claim_generator: "test-generator",
101
60
  claim_generator_info: [
102
61
  {
103
- name: 'c2pa_test',
104
- version: '1.0.0',
105
- },
106
- ],
107
- metadata: [
108
- {
109
- dateTime: '1985-04-12T23:20:50.52Z',
110
- my_custom_metadata: 'my custom metatdata value',
62
+ name: "c2pa_test",
63
+ version: "1.0.0",
111
64
  },
112
65
  ],
113
- title: 'Test_Manifest',
114
- format: 'image/tiff',
115
- instance_id: '1234',
66
+ title: "Test_Manifest",
67
+ format: "image/jpeg",
68
+ instance_id: "1234",
116
69
  thumbnail: {
117
- format: 'image/jpeg',
118
- identifier: 'thumbnail.jpg',
70
+ format: "image/jpeg",
71
+ identifier: "thumbnail.jpg",
119
72
  },
120
73
  ingredients: [
121
74
  {
122
- title: 'Test',
123
- format: 'image/jpeg',
124
- instance_id: '12345',
125
- relationship: 'componentOf',
75
+ title: "Test",
76
+ format: "image/jpeg",
77
+ instance_id: "12345",
78
+ relationship: "componentOf",
79
+ thumbnail: { format: "image/jpeg", identifier: "ingredient-thumb.jpg" },
80
+ resources: { resources: {} },
126
81
  },
127
82
  ],
128
83
  assertions: [
129
84
  {
130
- label: 'org.test.assertion',
131
- data: 'assertion',
85
+ label: "org.test.assertion",
86
+ data: {},
132
87
  },
133
88
  ],
89
+ resources: { resources: {} },
134
90
  };
135
91
  let testAssertion;
136
92
  let testThumbnail;
@@ -141,168 +97,297 @@ describe('Builder', () => {
141
97
  yield fs.ensureDir(tempDir);
142
98
  // Read all test files once
143
99
  source = {
144
- buffer: yield fs.readFile('./tests/fixtures/CA.jpg'),
145
- mimeType: 'jpeg',
100
+ buffer: yield fs.readFile("./tests/fixtures/CA.jpg"),
101
+ mimeType: "image/jpeg",
146
102
  };
147
- testThumbnail = yield fs.readFile('./tests/fixtures/thumbnail.jpg');
148
- publicKey = yield fs.readFile('./tests/fixtures/certs/es256.pub');
149
- privateKey = yield fs.readFile('./tests/fixtures/certs/es256.pem');
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");
150
106
  testAssertion = JSON.stringify({ answer: 42 });
151
107
  }));
152
108
  afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
153
109
  yield fs.remove(tempDir);
154
110
  }));
155
- it('should build a manifest store', () => __awaiter(void 0, void 0, void 0, function* () {
111
+ it("should build a manifest store", () => __awaiter(void 0, void 0, void 0, function* () {
156
112
  const test_definition = {
113
+ claim_generator: "test-generator",
157
114
  claim_generator_info: [
158
115
  {
159
- name: 'c2pa-js tests',
160
- version: '1.0.0',
116
+ name: "c2pa-js tests",
117
+ version: "1.0.0",
161
118
  },
162
119
  ],
163
- format: 'image/tiff',
164
- instance_id: '1234',
165
- title: 'builder-test-manifest',
166
- vendor: 'test',
120
+ format: "image/tiff",
121
+ instance_id: "1234",
122
+ title: "builder-test-manifest",
123
+ vendor: "test",
167
124
  thumbnail: thumbnail_ref,
168
- label: 'ABCDE',
125
+ label: "ABCDE",
126
+ ingredients: [],
127
+ assertions: [],
128
+ resources: { resources: {} },
169
129
  };
170
- const builder = index_1.Builder.withJson(test_definition);
130
+ const builder = Builder.withJson(test_definition);
171
131
  yield builder.addIngredient(parent_json, source);
172
- builder.addAssertion('org.test.assertion', 'assertion');
132
+ builder.addAssertion("org.test.assertion", "assertion");
173
133
  yield builder.addResource(thumbnail_ref.identifier, {
174
- buffer: Buffer.from('12345'),
175
- mimeType: 'jpeg',
134
+ buffer: Buffer.from("12345"),
135
+ mimeType: "jpeg",
176
136
  });
177
137
  // Wait for any pending async operations
178
138
  yield Promise.resolve();
179
139
  const definition = builder.getManifestDefinition();
180
- expect(definition.vendor).toBe('test');
181
- expect(definition.title).toBe('builder-test-manifest');
182
- expect(definition.format).toBe('image/tiff');
183
- expect(definition.instance_id).toBe('1234');
184
- expect(definition.ingredients[0].title).toStrictEqual('c2pa-bindings Test');
185
- expect(definition.assertions[0].label).toBe('org.test.assertion');
186
- expect(definition.label).toBe('ABCDE');
140
+ expect(definition.vendor).toBe("test");
141
+ expect(definition.title).toBe("builder-test-manifest");
142
+ expect(definition.format).toBe("image/tiff");
143
+ expect(definition.instance_id).toBe("1234");
144
+ expect(definition.ingredients[0].title).toStrictEqual("c2pa-bindings Test");
145
+ expect(definition.assertions[0].label).toBe("org.test.assertion");
146
+ expect(definition.label).toBe("ABCDE");
187
147
  }));
188
- describe('Sign and Archive', () => {
148
+ describe("Sign and Archive", () => {
189
149
  let builder;
190
150
  beforeEach(() => {
191
- builder = index_1.Builder.withJson(manifestDefinition);
192
- builder.updateManifestProperty('claim_version', 1);
151
+ builder = Builder.withJson(manifestDefinition);
152
+ builder.updateManifestProperty("claim_version", 2);
193
153
  });
194
154
  beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
195
155
  // Add ingredients and resources after builder is initialized
196
156
  yield builder.addIngredient(parent_json, source);
197
- yield builder.addResource('thumbnail.jpg', {
198
- mimeType: 'jpeg',
157
+ yield builder.addResource("thumbnail.jpg", {
158
+ mimeType: "jpeg",
159
+ buffer: testThumbnail,
160
+ });
161
+ yield builder.addResource("ingredient-thumb.jpg", {
162
+ mimeType: "jpeg",
199
163
  buffer: testThumbnail,
200
164
  });
201
- yield builder.addResource('prompt.txt', {
202
- buffer: Buffer.from('a random prompt'),
203
- mimeType: 'text/plain',
165
+ yield builder.addResource("prompt.txt", {
166
+ buffer: Buffer.from("a random prompt"),
167
+ mimeType: "text/plain",
204
168
  });
205
- builder.addAssertion('org.life.meaning', testAssertion);
206
- builder.addAssertion('org.life.meaning.json', testAssertion, 'Json');
169
+ builder.addAssertion("org.life.meaning", testAssertion);
170
+ builder.addAssertion("org.life.meaning.json", testAssertion, "Json");
207
171
  // Wait for any pending operations
208
172
  yield Promise.resolve();
209
173
  }));
210
- it('should sign data', () => __awaiter(void 0, void 0, void 0, function* () {
211
- const dest = { path: path_1.default.join(tempDir, 'signed.jpg') };
212
- const signer = index_1.LocalSigner.newSigner(publicKey, privateKey, 'es256');
174
+ it("should sign data", () => __awaiter(void 0, void 0, void 0, function* () {
175
+ const dest = { path: path.join(tempDir, "signed.jpg") };
176
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
213
177
  const bytes = builder.sign(signer, source, dest);
214
178
  expect(bytes.length).toBeGreaterThan(0);
215
- const reader = yield index_1.Reader.fromAsset(dest);
179
+ const reader = yield Reader.fromAsset(dest);
216
180
  const manifestStore = reader.json();
217
181
  const activeManifest = reader.getActive();
218
182
  expect(manifestStore.validation_status).toBeUndefined();
219
183
  expect(manifestStore.active_manifest).not.toBeUndefined();
220
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
184
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
185
+ }));
186
+ it("should add a CBOR assertion, sign, and verify it in the signed manifest", () => __awaiter(void 0, void 0, void 0, function* () {
187
+ var _a;
188
+ // Add the c2pa.watermarked action as a CBOR assertion
189
+ const actionsAssertion = {
190
+ actions: [
191
+ {
192
+ action: "c2pa.watermarked",
193
+ },
194
+ ],
195
+ };
196
+ builder.addAssertion("c2pa.actions", actionsAssertion, "Cbor");
197
+ // Sign the manifest
198
+ const dest = { path: path.join(tempDir, "cbor_signed.jpg") };
199
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
200
+ builder.sign(signer, source, dest);
201
+ // Read and verify the assertion in the signed manifest
202
+ const reader = yield Reader.fromAsset(dest);
203
+ const activeManifest = reader.getActive();
204
+ 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");
205
+ expect(cborAssertion).toBeDefined();
206
+ if (isActionsAssertion(cborAssertion)) {
207
+ const actions = cborAssertion.data.actions.map((a) => a.action);
208
+ expect(actions).toContain("c2pa.watermarked");
209
+ }
210
+ else {
211
+ throw new Error("CBOR assertion does not have the expected structure");
212
+ }
221
213
  }));
222
- it('should archive and construct from archive', () => __awaiter(void 0, void 0, void 0, function* () {
214
+ it("should archive and construct from archive", () => __awaiter(void 0, void 0, void 0, function* () {
223
215
  const dest = {
224
216
  buffer: null,
225
217
  };
226
- const signer = index_1.LocalSigner.newSigner(publicKey, privateKey, 'es256');
227
- const outputPath = path_1.default.join(tempDir, 'archive.zip');
218
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
219
+ const outputPath = path.join(tempDir, "archive.zip");
228
220
  const archive = { path: outputPath };
229
221
  yield builder.toArchive(archive);
230
- const builder2 = yield index_1.Builder.fromArchive(archive);
222
+ const builder2 = yield Builder.fromArchive(archive);
231
223
  builder2.sign(signer, source, dest);
232
- const reader = yield index_1.Reader.fromAsset({
224
+ const reader = yield Reader.fromAsset({
233
225
  buffer: dest.buffer,
234
- mimeType: 'jpeg',
226
+ mimeType: "jpeg",
235
227
  });
236
228
  const manifestStore = reader.json();
237
229
  const activeManifest = reader.getActive();
238
230
  expect(manifestStore.validation_status).toBeUndefined();
239
231
  expect(manifestStore.active_manifest).not.toBeUndefined();
240
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
232
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
241
233
  }));
242
- it('should sign data with callback to file', () => __awaiter(void 0, void 0, void 0, function* () {
243
- const dest = { path: path_1.default.join(tempDir, 'callback_signed.jpg') };
234
+ it("should sign data with callback to file", () => __awaiter(void 0, void 0, void 0, function* () {
235
+ const dest = {
236
+ path: path.join(tempDir, "callback_signed.jpg"),
237
+ };
244
238
  const signerConfig = {
245
- alg: 'es256',
239
+ alg: "es256",
246
240
  certs: [publicKey],
247
241
  reserveSize: 10000,
248
242
  tsaUrl: undefined,
243
+ directCoseHandling: false,
249
244
  };
250
245
  const signer = new TestSigner(privateKey);
251
246
  const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
252
247
  expect(bytes.length).toBeGreaterThan(0);
253
- const reader = yield index_1.Reader.fromAsset(dest);
248
+ const reader = yield Reader.fromAsset(dest);
254
249
  const manifestStore = reader.json();
255
250
  const activeManifest = reader.getActive();
256
251
  expect(manifestStore.validation_status).toBeUndefined();
257
252
  expect(manifestStore.active_manifest).not.toBeUndefined();
258
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
253
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
259
254
  }));
260
- it('should sign data with callback to buffer', () => __awaiter(void 0, void 0, void 0, function* () {
255
+ it("should sign data with callback to buffer", () => __awaiter(void 0, void 0, void 0, function* () {
261
256
  const dest = {
262
257
  buffer: null,
263
258
  };
264
259
  const signerConfig = {
265
- alg: 'es256',
260
+ alg: "es256",
266
261
  certs: [publicKey],
267
262
  reserveSize: 10000,
268
263
  tsaUrl: undefined,
264
+ directCoseHandling: false,
269
265
  };
270
266
  const signer = new TestSigner(privateKey);
271
267
  const bytes = yield builder.signConfigAsync(signer.sign, signerConfig, source, dest);
272
268
  expect(bytes.length).toBeGreaterThan(0);
273
- const reader = yield index_1.Reader.fromAsset({
269
+ const reader = yield Reader.fromAsset({
274
270
  buffer: dest.buffer,
275
- mimeType: 'jpeg',
271
+ mimeType: "jpeg",
276
272
  });
277
273
  const manifestStore = reader.json();
278
274
  const activeManifest = reader.getActive();
279
275
  expect(manifestStore.validation_status).toBeUndefined();
280
276
  expect(manifestStore.active_manifest).not.toBeUndefined();
281
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
277
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
282
278
  }));
283
- it('should sign data with callback signer to buffer', () => __awaiter(void 0, void 0, void 0, function* () {
279
+ it("should sign data with callback signer to buffer", () => __awaiter(void 0, void 0, void 0, function* () {
284
280
  const dest = {
285
281
  buffer: null,
286
282
  };
287
283
  const signerConfig = {
288
- alg: 'es256',
284
+ alg: "es256",
289
285
  certs: [publicKey],
290
286
  reserveSize: 10000,
291
287
  tsaUrl: undefined,
288
+ directCoseHandling: false,
292
289
  };
293
290
  const testSigner = new TestSigner(privateKey);
294
- const signer = index_1.CallbackSigner.newSigner(signerConfig, testSigner.sign);
291
+ const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
295
292
  const bytes = yield builder.signAsync(signer, source, dest);
296
293
  expect(bytes.length).toBeGreaterThan(0);
297
- const reader = yield index_1.Reader.fromAsset({
294
+ const reader = yield Reader.fromAsset({
298
295
  buffer: dest.buffer,
299
- mimeType: 'jpeg',
296
+ mimeType: "jpeg",
300
297
  });
301
298
  const manifestStore = reader.json();
302
299
  const activeManifest = reader.getActive();
303
300
  expect(manifestStore.validation_status).toBeUndefined();
304
301
  expect(manifestStore.active_manifest).not.toBeUndefined();
305
- expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe('Test_Manifest');
302
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
303
+ }));
304
+ it("should preserve JSON assertion characters without escaping", () => __awaiter(void 0, void 0, void 0, function* () {
305
+ var _a;
306
+ const fingerprintAssertion = JSON.stringify({
307
+ alg: "sha256",
308
+ blocks: [
309
+ {
310
+ scope: {},
311
+ value: "test-fingerprint-data",
312
+ },
313
+ ],
314
+ });
315
+ builder.addAssertion("org.contentauth.fingerprint", fingerprintAssertion, "Json");
316
+ const dest = { path: path.join(tempDir, "json_test.jpg") };
317
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
318
+ builder.sign(signer, source, dest);
319
+ const reader = yield Reader.fromAsset(dest);
320
+ const manifest = reader.json();
321
+ // Check that our specific JSON assertion doesn't have escaped characters
322
+ const activeManifest = manifest.manifests[manifest.active_manifest];
323
+ 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");
324
+ expect(fingerprintAssertionData).toBeDefined();
325
+ expect(fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data).toEqual({
326
+ alg: "sha256",
327
+ blocks: [
328
+ {
329
+ scope: {},
330
+ value: "test-fingerprint-data",
331
+ },
332
+ ],
333
+ });
334
+ // The assertion data should not be a string with escaped quotes
335
+ expect(typeof (fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data)).toBe("object");
336
+ expect(JSON.stringify(fingerprintAssertionData === null || fingerprintAssertionData === void 0 ? void 0 : fingerprintAssertionData.data)).not.toContain("\\");
337
+ }));
338
+ it("should archive and restore builder with ingredient thumbnail", () => __awaiter(void 0, void 0, void 0, function* () {
339
+ const manifestDefinition = {
340
+ claim_generator_info: [
341
+ {
342
+ name: "c2pa_test",
343
+ version: "1.0.0",
344
+ },
345
+ ],
346
+ title: "Test_Manifest",
347
+ format: "image/jpeg",
348
+ ingredients: [],
349
+ assertions: [
350
+ {
351
+ label: "c2pa.actions",
352
+ data: {
353
+ actions: [
354
+ {
355
+ action: "c2pa.created",
356
+ digitalSourceType: "http://c2pa.org/digitalsourcetype/empty",
357
+ },
358
+ ],
359
+ },
360
+ },
361
+ ],
362
+ resources: { resources: {} },
363
+ };
364
+ const builder = Builder.withJson(manifestDefinition);
365
+ const ingredientJson = '{"title": "Test Ingredient"}';
366
+ const testThumbnail = yield fs.readFile("./tests/fixtures/thumbnail.jpg");
367
+ yield builder.addIngredient(ingredientJson, {
368
+ buffer: testThumbnail,
369
+ mimeType: "jpeg",
370
+ });
371
+ // Archive the builder
372
+ const archivePath = path.join(tempDir, `ingredient_thumb_archive_${Date.now()}.zip`);
373
+ yield builder.toArchive({ path: archivePath });
374
+ // Ensure the file is written to disk before proceeding
375
+ yield fs.access(archivePath);
376
+ // Restore from archive
377
+ const builder2 = yield Builder.fromArchive({ path: archivePath });
378
+ // Sign with restored builder
379
+ const dest = { buffer: null };
380
+ const publicKey = yield fs.readFile("./tests/fixtures/certs/es256.pub");
381
+ const privateKey = yield fs.readFile("./tests/fixtures/certs/es256.pem");
382
+ const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
383
+ builder2.sign(signer, source, dest);
384
+ const reader = yield Reader.fromAsset({
385
+ buffer: dest.buffer,
386
+ mimeType: "jpeg",
387
+ });
388
+ const manifestStore = reader.json();
389
+ expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
390
+ expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
306
391
  }));
307
392
  });
308
393
  });
@@ -1,42 +1,8 @@
1
- "use strict";
2
1
  // Copyright 2024 Adobe. All rights reserved.
3
2
  // This file is licensed to you under the Apache License,
4
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
4
  // or the MIT license (http://opensource.org/licenses/MIT),
6
5
  // at your option.
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
6
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
7
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
8
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,16 +12,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46
12
  step((generator = generator.apply(thisArg, _arguments || [])).next());
47
13
  });
48
14
  };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.IdentityAssertionSigner = exports.IdentityAssertionBuilder = void 0;
51
15
  // Unless required by applicable law or agreed to in writing,
52
16
  // this software is distributed on an "AS IS" BASIS, WITHOUT
53
17
  // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
54
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
55
19
  // specific language governing permissions and limitations under
56
20
  // each license.
57
- const neon = __importStar(require("index.node"));
58
- class IdentityAssertionBuilder {
21
+ const neon = require("./index.node");
22
+ export class IdentityAssertionBuilder {
59
23
  constructor(_builder) {
60
24
  this._builder = _builder;
61
25
  }
@@ -75,13 +39,12 @@ class IdentityAssertionBuilder {
75
39
  return this._builder;
76
40
  }
77
41
  }
78
- exports.IdentityAssertionBuilder = IdentityAssertionBuilder;
79
- class IdentityAssertionSigner {
42
+ export class IdentityAssertionSigner {
80
43
  constructor(_signer) {
81
44
  this._signer = _signer;
82
45
  }
83
46
  static new(signer) {
84
- const identitySigner = neon.identitySignerNew(signer.signer());
47
+ const identitySigner = neon.identitySignerNew(signer);
85
48
  return new IdentityAssertionSigner(identitySigner);
86
49
  }
87
50
  addIdentityAssertion(identityAssertionBuilder) {
@@ -91,4 +54,26 @@ class IdentityAssertionSigner {
91
54
  return this._signer;
92
55
  }
93
56
  }
94
- exports.IdentityAssertionSigner = IdentityAssertionSigner;
57
+ export class CallbackCredentialHolder {
58
+ constructor(callbackCredentialHolder) {
59
+ this.callbackCredentialHolder = callbackCredentialHolder;
60
+ }
61
+ signer() {
62
+ return this.callbackCredentialHolder;
63
+ }
64
+ static newCallbackCredentialHolder(reserveSize, sigType, callback) {
65
+ const credentialHolder = neon.newCallbackCredentialHolder(reserveSize, sigType, callback);
66
+ return new CallbackCredentialHolder(credentialHolder);
67
+ }
68
+ sign(payload) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ return neon.callbackSignerSignPayload.call(this.callbackCredentialHolder, payload);
71
+ });
72
+ }
73
+ reserveSize() {
74
+ return neon.callbackCredentialHolderReserveSize.call(this.callbackCredentialHolder);
75
+ }
76
+ sigType() {
77
+ return neon.callbackCredentialHolderSigType.call(this.callbackCredentialHolder);
78
+ }
79
+ }