@contentauth/c2pa-node 0.1.0 → 0.1.2

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.
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ // Copyright 2024 Adobe. All rights reserved.
3
+ // This file is licensed to you under the Apache License,
4
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
+ // or the MIT license (http://opensource.org/licenses/MIT),
6
+ // 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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ // Unless required by applicable law or agreed to in writing,
51
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
52
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
53
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
54
+ // specific language governing permissions and limitations under
55
+ // each license.
56
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
57
+ const index_1 = require("./index");
58
+ const fs = __importStar(require("fs-extra"));
59
+ const crypto = __importStar(require("crypto"));
60
+ // TODO: move to a separate test file
61
+ class TestSigner {
62
+ constructor(privateKey) {
63
+ this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
64
+ return crypto.sign(null, bytes, this.privateKey);
65
+ });
66
+ this.privateKey = crypto.createPrivateKey({
67
+ key: privateKey,
68
+ format: 'pem',
69
+ });
70
+ }
71
+ }
72
+ describe('IdentityAssertionBuilder', () => {
73
+ const manifestDefinition = {
74
+ vendor: 'test',
75
+ claim_version: 2,
76
+ claim_generator_info: [
77
+ {
78
+ name: 'c2pa_test',
79
+ version: '2.0.0',
80
+ },
81
+ ],
82
+ metadata: [
83
+ {
84
+ dateTime: '1985-04-12T23:20:50.52Z',
85
+ my_custom_metadata: 'my custom metatdata value',
86
+ },
87
+ ],
88
+ title: 'Test_Manifest',
89
+ format: 'image/jpeg',
90
+ instance_id: '1234',
91
+ ingredients: [
92
+ {
93
+ title: 'Test',
94
+ format: 'image/jpeg',
95
+ instance_id: '12345',
96
+ relationship: 'componentOf',
97
+ },
98
+ ],
99
+ assertions: [
100
+ {
101
+ label: 'c2pa.actions',
102
+ data: {
103
+ actions: [
104
+ {
105
+ action: 'c2pa.created',
106
+ digitalSourceType: 'http://cv.iptc.org/newscodes/digitalsourcetype/digitalCapture',
107
+ },
108
+ ],
109
+ },
110
+ },
111
+ {
112
+ label: 'cawg.training-mining',
113
+ data: {
114
+ entries: {
115
+ 'cawg.ai_inference': {
116
+ use: 'notAllowed',
117
+ },
118
+ 'cawg.ai_generative_training': {
119
+ use: 'notAllowed',
120
+ },
121
+ },
122
+ },
123
+ },
124
+ ],
125
+ };
126
+ it('should build an Identity Assertion Signer', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ // Read certificate files once
128
+ const c2paPrivateKey = yield fs.readFile('./tests/fixtures/certs/es256.pem');
129
+ const c2paPublicKey = yield fs.readFile('./tests/fixtures/certs/es256.pub');
130
+ const cawgPrivateKey = yield fs.readFile('./tests/fixtures/certs/ed25519.pem');
131
+ const cawgPublicKey = yield fs.readFile('./tests/fixtures/certs/ed25519.pub');
132
+ // Create signer configurations
133
+ const c2paConfig = {
134
+ alg: 'es256',
135
+ certs: [c2paPublicKey],
136
+ reserveSize: 10000,
137
+ tsaUrl: undefined,
138
+ tsaHeaders: undefined,
139
+ tsaBody: undefined,
140
+ };
141
+ const cawgConfig = {
142
+ alg: 'ed25519',
143
+ certs: [cawgPublicKey],
144
+ reserveSize: 10000,
145
+ tsaUrl: undefined,
146
+ tsaHeaders: undefined,
147
+ tsaBody: undefined,
148
+ };
149
+ // Create signers
150
+ const c2paTestSigner = new TestSigner(c2paPrivateKey);
151
+ const cawgTestSigner = new TestSigner(cawgPrivateKey);
152
+ const c2paSigner = index_1.CallbackSigner.newSigner(c2paConfig, c2paTestSigner.sign);
153
+ const cawgSigner = index_1.CallbackSigner.newSigner(cawgConfig, cawgTestSigner.sign);
154
+ const source = {
155
+ buffer: yield fs.readFile('./tests/fixtures/CA.jpg'),
156
+ mimeType: 'jpeg',
157
+ };
158
+ const dest = {
159
+ buffer: null,
160
+ };
161
+ // Create the manifest builder
162
+ const builder = index_1.Builder.withJson(manifestDefinition);
163
+ // Create and configure the identity assertion
164
+ const ia_signer = index_1.IdentityAssertionSigner.new(c2paSigner);
165
+ const iab = yield index_1.IdentityAssertionBuilder.identityBuilderForCredentialHolder(cawgSigner);
166
+ iab.addReferencedAssertions(['cawg.training-mining']);
167
+ ia_signer.addIdentityAssertion(iab);
168
+ // Sign the manifest
169
+ yield builder.signAsync(c2paSigner, source, dest);
170
+ // Verify the manifest
171
+ const reader = yield index_1.Reader.fromAsset({
172
+ buffer: dest.buffer,
173
+ mimeType: 'jpeg',
174
+ });
175
+ yield reader.postValidateCawg();
176
+ }));
177
+ });
package/dist/Reader.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // Copyright 2024 Adobe. All rights reserved.
3
+ // This file is licensed to you under the Apache License,
4
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
+ // or the MIT license (http://opensource.org/licenses/MIT),
6
+ // 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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Reader = void 0;
51
+ // Unless required by applicable law or agreed to in writing,
52
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
53
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
54
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
55
+ // specific language governing permissions and limitations under
56
+ // each license.
57
+ const neon = __importStar(require("index.node"));
58
+ class Reader {
59
+ constructor(reader) {
60
+ this.reader = reader;
61
+ }
62
+ json() {
63
+ return JSON.parse(neon.readerJson.call(this.reader));
64
+ }
65
+ remoteUrl() {
66
+ return neon.readerRemoteUrl.call(this.reader);
67
+ }
68
+ isEmbedded() {
69
+ return neon.readerIsEmbedded.call(this.reader);
70
+ }
71
+ resourceToAsset(uri, asset) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return neon.readerResourceToAsset.call(this.reader, uri, asset);
74
+ });
75
+ }
76
+ static fromAsset(asset) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const reader = yield neon.readerFromAsset(asset);
79
+ return new Reader(reader);
80
+ });
81
+ }
82
+ static fromManifestDataAndAsset(manifestData, asset) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const reader = yield neon.readerFromManifestDataAndAsset(manifestData, asset);
85
+ return new Reader(reader);
86
+ });
87
+ }
88
+ // Non-neon methods, copied from c2pa-js
89
+ activeLabel() {
90
+ var _a;
91
+ const manifestStore = this.json();
92
+ return (_a = manifestStore.active_manifest) !== null && _a !== void 0 ? _a : undefined;
93
+ }
94
+ getActive() {
95
+ const manifestStore = this.json();
96
+ const activeManifest = manifestStore.active_manifest;
97
+ if (!activeManifest) {
98
+ return undefined;
99
+ }
100
+ return manifestStore.manifests[activeManifest];
101
+ }
102
+ postValidateCawg() {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return neon.readerPostValidateCawg.call(this.reader);
105
+ });
106
+ }
107
+ }
108
+ exports.Reader = Reader;
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ // Copyright 2024 Adobe. All rights reserved.
3
+ // This file is licensed to you under the Apache License,
4
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
+ // or the MIT license (http://opensource.org/licenses/MIT),
6
+ // 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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
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
+ const index_1 = require("./index");
60
+ const path_1 = __importDefault(require("path"));
61
+ const fs = __importStar(require("fs-extra"));
62
+ const tempDir = path_1.default.join(__dirname, "tmp");
63
+ describe("Reader", () => {
64
+ const manifestStore = JSON.parse(`{
65
+ "active_manifest": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4",
66
+ "manifests": {
67
+ "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4": {
68
+ "claim_generator": "make_test_images/0.36.1",
69
+ "claim_generator_info": [
70
+ {
71
+ "name": "make_test_images",
72
+ "version": "0.36.1",
73
+ "org.cai.c2pa_rs": "0.42.0"
74
+ }
75
+ ],
76
+ "title": "CAI.jpg",
77
+ "format": "image/jpeg",
78
+ "instance_id": "xmp:iid:099bb0ad-5c66-4ad9-b0b6-6824fb26a198",
79
+ "thumbnail": {
80
+ "format": "image/jpeg",
81
+ "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
82
+ },
83
+ "ingredients": [
84
+ {
85
+ "title": "A.jpg",
86
+ "format": "image/jpeg",
87
+ "document_id": "xmp.did:813ee422-9736-4cdc-9be6-4e35ed8e41cb",
88
+ "instance_id": "xmp.iid:813ee422-9736-4cdc-9be6-4e35ed8e41cb",
89
+ "thumbnail": {
90
+ "format": "image/jpeg",
91
+ "identifier": "self#jumbf=c2pa.assertions/c2pa.thumbnail.ingredient.jpeg"
92
+ },
93
+ "relationship": "parentOf",
94
+ "label": "c2pa.ingredient"
95
+ },
96
+ {
97
+ "title": "I.jpg",
98
+ "format": "image/jpeg",
99
+ "document_id": "xmp.did:8a00de7a-e694-43b2-a7e6-ed950421a21a",
100
+ "instance_id": "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a",
101
+ "thumbnail": {
102
+ "format": "image/jpeg",
103
+ "identifier": "self#jumbf=c2pa.assertions/c2pa.thumbnail.ingredient__1.jpeg"
104
+ },
105
+ "relationship": "componentOf",
106
+ "label": "c2pa.ingredient__1"
107
+ }
108
+ ],
109
+ "assertions": [
110
+ {
111
+ "label": "stds.schema-org.CreativeWork",
112
+ "data": {
113
+ "@context": "http://schema.org/",
114
+ "@type": "CreativeWork",
115
+ "author": [
116
+ {
117
+ "name": "John Doe",
118
+ "@type": "Person"
119
+ }
120
+ ]
121
+ },
122
+ "kind": "Json"
123
+ },
124
+ {
125
+ "label": "c2pa.actions.v2",
126
+ "data": {
127
+ "actions": [
128
+ {
129
+ "action": "c2pa.opened",
130
+ "parameters": {
131
+ "org.cai.ingredientIds": [
132
+ "xmp.iid:813ee422-9736-4cdc-9be6-4e35ed8e41cb"
133
+ ],
134
+ "ingredient": [
135
+ {
136
+ "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
137
+ "hash": "tTBD4/E0R0AjLUdJFpsVz3lE/KJUq22Vz0UGqzhEpVs="
138
+ }
139
+ ]
140
+ }
141
+ },
142
+ {
143
+ "action": "c2pa.color_adjustments",
144
+ "parameters": {
145
+ "name": "brightnesscontrast"
146
+ }
147
+ },
148
+ {
149
+ "action": "c2pa.placed",
150
+ "parameters": {
151
+ "org.cai.ingredientIds": [
152
+ "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a"
153
+ ],
154
+ "ingredient": [
155
+ {
156
+ "url": "self#jumbf=c2pa.assertions/c2pa.ingredient__1",
157
+ "hash": "EMeeY5a+lvy1msl+9i5DOcOoeQowrqD7NyV0d8fwAX0="
158
+ }
159
+ ]
160
+ }
161
+ },
162
+ {
163
+ "action": "c2pa.resized"
164
+ }
165
+ ]
166
+ }
167
+ }
168
+ ],
169
+ "signature_info": {
170
+ "alg": "Ps256",
171
+ "issuer": "C2PA Test Signing Cert",
172
+ "cert_serial_number": "720724073027128164015125666832722375746636448153",
173
+ "time": "2025-02-04T17:38:01+00:00"
174
+ },
175
+ "label": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4"
176
+ }
177
+ }
178
+ }`);
179
+ beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
180
+ yield fs.ensureDir(tempDir);
181
+ }));
182
+ afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
183
+ yield fs.remove(tempDir);
184
+ }));
185
+ it("should read from an ArrayBuffer", () => __awaiter(void 0, void 0, void 0, function* () {
186
+ const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
187
+ const reader = yield index_1.Reader.fromAsset({ buffer, mimeType: "jpeg" });
188
+ const json = reader.json();
189
+ expect(json.manifests).toEqual(manifestStore.manifests);
190
+ expect(json.active_manifest).toEqual(manifestStore.active_manifest);
191
+ }));
192
+ it("should read from a file", () => __awaiter(void 0, void 0, void 0, function* () {
193
+ const reader = yield index_1.Reader.fromAsset({ path: "./tests/fixtures/CAI.jpg" });
194
+ const json = reader.json();
195
+ expect(json.manifests).toEqual(manifestStore.manifests);
196
+ expect(json.active_manifest).toEqual(manifestStore.active_manifest);
197
+ }));
198
+ it("should read from manifest data and buffer", () => __awaiter(void 0, void 0, void 0, function* () {
199
+ const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
200
+ const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
201
+ const reader = yield index_1.Reader.fromManifestDataAndAsset(manifestData, {
202
+ buffer,
203
+ mimeType: "jpeg",
204
+ });
205
+ const json = reader.json();
206
+ expect(json.manifests).toEqual(manifestStore.manifests);
207
+ expect(json.active_manifest).toEqual(manifestStore.active_manifest);
208
+ }));
209
+ it("should read from manifest data and file", () => __awaiter(void 0, void 0, void 0, function* () {
210
+ const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
211
+ const reader = yield index_1.Reader.fromManifestDataAndAsset(manifestData, {
212
+ path: "./tests/fixtures/CAI.jpg",
213
+ });
214
+ const json = reader.json();
215
+ expect(json.manifests).toEqual(manifestStore.manifests);
216
+ }));
217
+ it("should write to a file", () => __awaiter(void 0, void 0, void 0, function* () {
218
+ var _a;
219
+ let bytesWritten = 0;
220
+ const outputPath = path_1.default.join(tempDir, "thumbnail.jpg");
221
+ const reader = yield index_1.Reader.fromAsset({ path: "./tests/fixtures/CAI.jpg" });
222
+ const activeManifest = reader.getActive();
223
+ const uri = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.thumbnail) === null || _a === void 0 ? void 0 : _a.identifier;
224
+ if (uri !== undefined) {
225
+ bytesWritten = yield reader.resourceToAsset(uri, {
226
+ path: outputPath,
227
+ });
228
+ }
229
+ expect(bytesWritten).toBe(85281);
230
+ expect(fs.existsSync(outputPath));
231
+ }));
232
+ it("should report manifest is embedded", () => __awaiter(void 0, void 0, void 0, function* () {
233
+ const reader = yield index_1.Reader.fromAsset({ path: "./tests/fixtures/CAI.jpg" });
234
+ expect(reader.remoteUrl()).toEqual("");
235
+ expect(reader.isEmbedded()).toBeTruthy();
236
+ }));
237
+ it("should report manifest is not embedded", () => __awaiter(void 0, void 0, void 0, function* () {
238
+ const reader = yield index_1.Reader.fromAsset({
239
+ path: "./tests/fixtures/cloud.jpg",
240
+ });
241
+ expect(reader.remoteUrl()).toEqual("https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391");
242
+ expect(reader.isEmbedded()).toBeFalsy();
243
+ }));
244
+ });
package/dist/Signer.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ // Copyright 2024 Adobe. All rights reserved.
3
+ // This file is licensed to you under the Apache License,
4
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
+ // or the MIT license (http://opensource.org/licenses/MIT),
6
+ // 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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.CallbackSigner = exports.LocalSigner = void 0;
51
+ // Unless required by applicable law or agreed to in writing,
52
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
53
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
54
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
55
+ // specific language governing permissions and limitations under
56
+ // each license.
57
+ const neon = __importStar(require("index.node"));
58
+ class LocalSigner {
59
+ constructor(localSigner) {
60
+ this.localSigner = localSigner;
61
+ }
62
+ static newSigner(certificate, privateKey, algorithm, tsaUrl) {
63
+ const signer = neon.localSignerNew(certificate, privateKey, algorithm, tsaUrl);
64
+ return new LocalSigner(signer);
65
+ }
66
+ sign(data) {
67
+ return neon.localSignerSign.call(this.localSigner, data);
68
+ }
69
+ alg() {
70
+ return neon.localSignerAlg.call(this.localSigner);
71
+ }
72
+ certs() {
73
+ return neon.localSignerCerts.call(this.localSigner);
74
+ }
75
+ reserveSize() {
76
+ return neon.localSignerReserveSize.call(this.localSigner);
77
+ }
78
+ timeAuthorityUrl() {
79
+ return neon.localSignerTimeAuthorityUrl.call(this.localSigner);
80
+ }
81
+ signer() {
82
+ return this.localSigner;
83
+ }
84
+ }
85
+ exports.LocalSigner = LocalSigner;
86
+ class CallbackSigner {
87
+ constructor(callbackSigner) {
88
+ this.callbackSigner = callbackSigner;
89
+ }
90
+ signer() {
91
+ return this.callbackSigner;
92
+ }
93
+ static newSigner(config, callback) {
94
+ // Convert the config object to a JsBox<CallbackSignerConfig>
95
+ const configBox = neon.callbackSignerConfigFromJs(config);
96
+ const signer = neon.callbackSignerFromConfig(configBox, callback);
97
+ return new CallbackSigner(signer);
98
+ }
99
+ sign(data) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ return neon.callbackSignerSign.call(this.callbackSigner, data);
102
+ });
103
+ }
104
+ alg() {
105
+ return neon.callbackSignerAlg.call(this.callbackSigner);
106
+ }
107
+ certs() {
108
+ return neon.callbackSignerCerts.call(this.callbackSigner);
109
+ }
110
+ reserveSize() {
111
+ return neon.callbackSignerReserveSize.call(this.callbackSigner);
112
+ }
113
+ timeAuthorityUrl() {
114
+ return neon.callbackSignerTimeAuthorityUrl.call(this.callbackSigner);
115
+ }
116
+ }
117
+ exports.CallbackSigner = CallbackSigner;