@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.
- package/README.md +212 -46
- package/dist/Builder.js +17 -73
- package/dist/Builder.spec.js +226 -141
- package/dist/IdentityAssertion.js +27 -42
- package/dist/IdentityAssertion.spec.js +78 -103
- package/dist/Reader.js +2 -39
- package/dist/Reader.spec.js +22 -50
- package/dist/Settings.js +203 -0
- package/dist/Settings.spec.js +314 -0
- package/dist/Signer.js +3 -41
- package/dist/Signer.spec.js +12 -45
- package/dist/Trustmark.js +2 -39
- package/dist/Trustmark.spec.js +10 -48
- package/dist/{types/index.node.d.ts → assertions.js} +13 -6
- package/dist/index.js +7 -36
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +15 -16
- package/dist/types/IdentityAssertion.d.ts +18 -10
- package/dist/types/Reader.d.ts +9 -8
- package/dist/types/Settings.d.ts +63 -0
- package/dist/types/Settings.spec.d.ts +1 -0
- package/dist/types/Signer.d.ts +11 -11
- package/dist/types/Trustmark.d.ts +4 -4
- package/dist/types/assertions.d.ts +8 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/types.d.ts +104 -584
- package/package.json +13 -8
package/dist/Builder.spec.js
CHANGED
|
@@ -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
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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(
|
|
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:
|
|
34
|
+
format: "pem",
|
|
77
35
|
});
|
|
78
36
|
}
|
|
79
37
|
}
|
|
80
|
-
describe(
|
|
81
|
-
it(
|
|
82
|
-
const signer = new TestSigner(yield fs.readFile(
|
|
83
|
-
const bytes = Buffer.from(
|
|
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(
|
|
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:
|
|
97
|
-
identifier:
|
|
54
|
+
format: "ingredient/jpeg",
|
|
55
|
+
identifier: "5678",
|
|
98
56
|
};
|
|
99
57
|
const manifestDefinition = {
|
|
100
|
-
vendor:
|
|
58
|
+
vendor: "test",
|
|
59
|
+
claim_generator: "test-generator",
|
|
101
60
|
claim_generator_info: [
|
|
102
61
|
{
|
|
103
|
-
name:
|
|
104
|
-
version:
|
|
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:
|
|
114
|
-
format:
|
|
115
|
-
instance_id:
|
|
66
|
+
title: "Test_Manifest",
|
|
67
|
+
format: "image/jpeg",
|
|
68
|
+
instance_id: "1234",
|
|
116
69
|
thumbnail: {
|
|
117
|
-
format:
|
|
118
|
-
identifier:
|
|
70
|
+
format: "image/jpeg",
|
|
71
|
+
identifier: "thumbnail.jpg",
|
|
119
72
|
},
|
|
120
73
|
ingredients: [
|
|
121
74
|
{
|
|
122
|
-
title:
|
|
123
|
-
format:
|
|
124
|
-
instance_id:
|
|
125
|
-
relationship:
|
|
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:
|
|
131
|
-
data:
|
|
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(
|
|
145
|
-
mimeType:
|
|
100
|
+
buffer: yield fs.readFile("./tests/fixtures/CA.jpg"),
|
|
101
|
+
mimeType: "image/jpeg",
|
|
146
102
|
};
|
|
147
|
-
testThumbnail = yield fs.readFile(
|
|
148
|
-
publicKey = yield fs.readFile(
|
|
149
|
-
privateKey = yield fs.readFile(
|
|
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(
|
|
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:
|
|
160
|
-
version:
|
|
116
|
+
name: "c2pa-js tests",
|
|
117
|
+
version: "1.0.0",
|
|
161
118
|
},
|
|
162
119
|
],
|
|
163
|
-
format:
|
|
164
|
-
instance_id:
|
|
165
|
-
title:
|
|
166
|
-
vendor:
|
|
120
|
+
format: "image/tiff",
|
|
121
|
+
instance_id: "1234",
|
|
122
|
+
title: "builder-test-manifest",
|
|
123
|
+
vendor: "test",
|
|
167
124
|
thumbnail: thumbnail_ref,
|
|
168
|
-
label:
|
|
125
|
+
label: "ABCDE",
|
|
126
|
+
ingredients: [],
|
|
127
|
+
assertions: [],
|
|
128
|
+
resources: { resources: {} },
|
|
169
129
|
};
|
|
170
|
-
const builder =
|
|
130
|
+
const builder = Builder.withJson(test_definition);
|
|
171
131
|
yield builder.addIngredient(parent_json, source);
|
|
172
|
-
builder.addAssertion(
|
|
132
|
+
builder.addAssertion("org.test.assertion", "assertion");
|
|
173
133
|
yield builder.addResource(thumbnail_ref.identifier, {
|
|
174
|
-
buffer: Buffer.from(
|
|
175
|
-
mimeType:
|
|
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(
|
|
181
|
-
expect(definition.title).toBe(
|
|
182
|
-
expect(definition.format).toBe(
|
|
183
|
-
expect(definition.instance_id).toBe(
|
|
184
|
-
expect(definition.ingredients[0].title).toStrictEqual(
|
|
185
|
-
expect(definition.assertions[0].label).toBe(
|
|
186
|
-
expect(definition.label).toBe(
|
|
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(
|
|
148
|
+
describe("Sign and Archive", () => {
|
|
189
149
|
let builder;
|
|
190
150
|
beforeEach(() => {
|
|
191
|
-
builder =
|
|
192
|
-
builder.updateManifestProperty(
|
|
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(
|
|
198
|
-
mimeType:
|
|
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(
|
|
202
|
-
buffer: Buffer.from(
|
|
203
|
-
mimeType:
|
|
165
|
+
yield builder.addResource("prompt.txt", {
|
|
166
|
+
buffer: Buffer.from("a random prompt"),
|
|
167
|
+
mimeType: "text/plain",
|
|
204
168
|
});
|
|
205
|
-
builder.addAssertion(
|
|
206
|
-
builder.addAssertion(
|
|
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(
|
|
211
|
-
const dest = { path:
|
|
212
|
-
const signer =
|
|
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
|
|
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(
|
|
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(
|
|
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 =
|
|
227
|
-
const outputPath =
|
|
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
|
|
222
|
+
const builder2 = yield Builder.fromArchive(archive);
|
|
231
223
|
builder2.sign(signer, source, dest);
|
|
232
|
-
const reader = yield
|
|
224
|
+
const reader = yield Reader.fromAsset({
|
|
233
225
|
buffer: dest.buffer,
|
|
234
|
-
mimeType:
|
|
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(
|
|
232
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
241
233
|
}));
|
|
242
|
-
it(
|
|
243
|
-
const dest = {
|
|
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:
|
|
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
|
|
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(
|
|
253
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
259
254
|
}));
|
|
260
|
-
it(
|
|
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:
|
|
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
|
|
269
|
+
const reader = yield Reader.fromAsset({
|
|
274
270
|
buffer: dest.buffer,
|
|
275
|
-
mimeType:
|
|
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(
|
|
277
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
282
278
|
}));
|
|
283
|
-
it(
|
|
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:
|
|
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 =
|
|
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
|
|
294
|
+
const reader = yield Reader.fromAsset({
|
|
298
295
|
buffer: dest.buffer,
|
|
299
|
-
mimeType:
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
+
}
|