@contentauth/c2pa-node 0.2.2 → 0.3.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.
@@ -12,35 +12,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13
13
  });
14
14
  };
15
- // Unless required by applicable law or agreed to in writing,
16
- // this software is distributed on an "AS IS" BASIS, WITHOUT
17
- // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
18
- // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
- // specific language governing permissions and limitations under
20
- // each license.
21
- import { Reader } from "./Reader";
22
15
  import path from "path";
23
16
  import * as fs from "fs-extra";
17
+ import { Reader } from "./Reader.js";
18
+ import { patchVerifyConfig } from "./Settings.js";
24
19
  const tempDir = path.join(__dirname, "tmp");
25
20
  describe("Reader", () => {
26
21
  const manifestStore = JSON.parse(`{
27
- "active_manifest": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4",
22
+ "active_manifest": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf",
28
23
  "manifests": {
29
- "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4": {
30
- "claim_generator": "make_test_images/0.36.1",
24
+ "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf": {
25
+ "claim_generator": "make_test_images/0.33.1 c2pa-rs/0.33.1",
31
26
  "claim_generator_info": [
32
27
  {
33
28
  "name": "make_test_images",
34
- "version": "0.36.1",
35
- "org.cai.c2pa_rs": "0.42.0"
29
+ "version": "0.33.1"
30
+ },
31
+ {
32
+ "name": "c2pa-rs",
33
+ "version": "0.33.1"
36
34
  }
37
35
  ],
38
- "title": "CAI.jpg",
36
+ "title": "CA.jpg",
39
37
  "format": "image/jpeg",
40
- "instance_id": "xmp:iid:099bb0ad-5c66-4ad9-b0b6-6824fb26a198",
38
+ "instance_id": "xmp:iid:ba572347-db0e-4619-b6eb-d38e487da238",
41
39
  "thumbnail": {
42
40
  "format": "image/jpeg",
43
- "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
41
+ "identifier": "self#jumbf=/c2pa/contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf/c2pa.assertions/c2pa.thumbnail.claim.jpeg"
44
42
  },
45
43
  "ingredients": [
46
44
  {
@@ -54,18 +52,6 @@ describe("Reader", () => {
54
52
  },
55
53
  "relationship": "parentOf",
56
54
  "label": "c2pa.ingredient"
57
- },
58
- {
59
- "title": "I.jpg",
60
- "format": "image/jpeg",
61
- "document_id": "xmp.did:8a00de7a-e694-43b2-a7e6-ed950421a21a",
62
- "instance_id": "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a",
63
- "thumbnail": {
64
- "format": "image/jpeg",
65
- "identifier": "self#jumbf=c2pa.assertions/c2pa.thumbnail.ingredient__1.jpeg"
66
- },
67
- "relationship": "componentOf",
68
- "label": "c2pa.ingredient__1"
69
55
  }
70
56
  ],
71
57
  "assertions": [
@@ -90,15 +76,10 @@ describe("Reader", () => {
90
76
  {
91
77
  "action": "c2pa.opened",
92
78
  "parameters": {
93
- "org.cai.ingredientIds": [
94
- "xmp.iid:813ee422-9736-4cdc-9be6-4e35ed8e41cb"
95
- ],
96
- "ingredient": [
97
- {
98
- "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
99
- "hash": "tTBD4/E0R0AjLUdJFpsVz3lE/KJUq22Vz0UGqzhEpVs="
100
- }
101
- ]
79
+ "ingredient": {
80
+ "url": "self#jumbf=c2pa.assertions/c2pa.ingredient",
81
+ "hash": "5dNlxTKe4afGAicpJa1hF1R3mBZKE+Bl0xmh0McXuO4="
82
+ }
102
83
  }
103
84
  },
104
85
  {
@@ -106,23 +87,6 @@ describe("Reader", () => {
106
87
  "parameters": {
107
88
  "name": "brightnesscontrast"
108
89
  }
109
- },
110
- {
111
- "action": "c2pa.placed",
112
- "parameters": {
113
- "org.cai.ingredientIds": [
114
- "xmp.iid:8a00de7a-e694-43b2-a7e6-ed950421a21a"
115
- ],
116
- "ingredient": [
117
- {
118
- "url": "self#jumbf=c2pa.assertions/c2pa.ingredient__1",
119
- "hash": "EMeeY5a+lvy1msl+9i5DOcOoeQowrqD7NyV0d8fwAX0="
120
- }
121
- ]
122
- }
123
- },
124
- {
125
- "action": "c2pa.resized"
126
90
  }
127
91
  ]
128
92
  }
@@ -133,20 +97,21 @@ describe("Reader", () => {
133
97
  "issuer": "C2PA Test Signing Cert",
134
98
  "common_name": "C2PA Signer",
135
99
  "cert_serial_number": "720724073027128164015125666832722375746636448153",
136
- "time": "2025-02-04T17:38:01+00:00"
100
+ "time": "2024-08-06T21:53:37+00:00"
137
101
  },
138
- "label": "contentauth:urn:uuid:e8ce52bc-df72-4ba5-ba37-52c360e76ba4"
102
+ "label": "contentauth:urn:uuid:c2677d4b-0a93-4444-876f-ed2f2d40b8cf"
139
103
  }
140
104
  }
141
105
  }`);
142
106
  beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
107
+ patchVerifyConfig({ verifyTrust: false });
143
108
  yield fs.ensureDir(tempDir);
144
109
  }));
145
110
  afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
146
111
  yield fs.remove(tempDir);
147
112
  }));
148
113
  it("should read from an ArrayBuffer", () => __awaiter(void 0, void 0, void 0, function* () {
149
- const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
114
+ const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
150
115
  const reader = yield Reader.fromAsset({
151
116
  buffer,
152
117
  mimeType: "jpeg",
@@ -157,15 +122,15 @@ describe("Reader", () => {
157
122
  }));
158
123
  it("should read from a file", () => __awaiter(void 0, void 0, void 0, function* () {
159
124
  const reader = yield Reader.fromAsset({
160
- path: "./tests/fixtures/CAI.jpg",
125
+ path: "./tests/fixtures/CA.jpg",
161
126
  });
162
127
  const json = reader.json();
163
128
  expect(json.manifests).toEqual(manifestStore.manifests);
164
129
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
165
130
  }));
166
131
  it("should read from manifest data and buffer", () => __awaiter(void 0, void 0, void 0, function* () {
167
- const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
168
- const buffer = yield fs.readFile("./tests/fixtures/CAI.jpg");
132
+ const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
133
+ const buffer = yield fs.readFile("./tests/fixtures/CA.jpg");
169
134
  const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
170
135
  buffer,
171
136
  mimeType: "jpeg",
@@ -175,9 +140,9 @@ describe("Reader", () => {
175
140
  expect(json.active_manifest).toEqual(manifestStore.active_manifest);
176
141
  }));
177
142
  it("should read from manifest data and file", () => __awaiter(void 0, void 0, void 0, function* () {
178
- const manifestData = yield fs.readFile("./tests/fixtures/CAI/manifest_data.c2pa");
143
+ const manifestData = yield fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
179
144
  const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
180
- path: "./tests/fixtures/CAI.jpg",
145
+ path: "./tests/fixtures/CA.jpg",
181
146
  });
182
147
  const json = reader.json();
183
148
  expect(json.manifests).toEqual(manifestStore.manifests);
@@ -187,7 +152,7 @@ describe("Reader", () => {
187
152
  let bytesWritten = 0;
188
153
  const outputPath = path.join(tempDir, "thumbnail.jpg");
189
154
  const reader = yield Reader.fromAsset({
190
- path: "./tests/fixtures/CAI.jpg",
155
+ path: "./tests/fixtures/CA.jpg",
191
156
  });
192
157
  const activeManifest = reader.getActive();
193
158
  const uri = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.thumbnail) === null || _a === void 0 ? void 0 : _a.identifier;
@@ -196,12 +161,12 @@ describe("Reader", () => {
196
161
  path: outputPath,
197
162
  });
198
163
  }
199
- expect(bytesWritten).toBe(85281);
164
+ expect(bytesWritten).toBe(49690);
200
165
  expect(fs.existsSync(outputPath));
201
166
  }));
202
167
  it("should report manifest is embedded", () => __awaiter(void 0, void 0, void 0, function* () {
203
168
  const reader = yield Reader.fromAsset({
204
- path: "./tests/fixtures/CAI.jpg",
169
+ path: "./tests/fixtures/CA.jpg",
205
170
  });
206
171
  expect(reader.remoteUrl()).toEqual("");
207
172
  expect(reader.isEmbedded()).toBeTruthy();
@@ -213,4 +178,39 @@ describe("Reader", () => {
213
178
  expect(reader.remoteUrl()).toEqual("https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391");
214
179
  expect(reader.isEmbedded()).toBeFalsy();
215
180
  }));
181
+ it("should decode CAWG identity assertion with signature_info", () => __awaiter(void 0, void 0, void 0, function* () {
182
+ var _a;
183
+ // This test verifies that postValidateCawg() properly decodes CAWG assertions
184
+ // and extracts signature_info from the signature data, matching c2pa-js behavior
185
+ const reader = yield Reader.fromAsset({
186
+ path: "./tests/fixtures/C_with_CAWG_data.jpg",
187
+ });
188
+ // Call postValidateCawg to decode CAWG assertions
189
+ yield reader.postValidateCawg();
190
+ const activeManifest = reader.getActive();
191
+ // Find the cawg.identity assertion
192
+ const cawgIdentityAssertion = (_a = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions) === null || _a === void 0 ? void 0 : _a.find((assertion) => assertion.label === "cawg.identity");
193
+ expect(cawgIdentityAssertion).toBeDefined();
194
+ expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data).toBeDefined();
195
+ expect(cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info).toBeDefined();
196
+ // Verify signature_info structure matches c2pa-js behavior
197
+ const signatureInfo = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signature_info;
198
+ const signerPayload = cawgIdentityAssertion === null || cawgIdentityAssertion === void 0 ? void 0 : cawgIdentityAssertion.data.signer_payload;
199
+ // Verify signature_info values
200
+ expect(signatureInfo.alg).toBe("Ed25519");
201
+ expect(signatureInfo.issuer).toBe("C2PA Test Signing Cert");
202
+ expect(signatureInfo.cert_serial_number).toBe("638838410810235485828984295321338730070538954823");
203
+ expect(signatureInfo.revocation_status).toBe(true);
204
+ // Verify signer_payload values
205
+ expect(signerPayload.sig_type).toBe("cawg.x509.cose");
206
+ expect(signerPayload.referenced_assertions).toHaveLength(2);
207
+ expect(signerPayload.referenced_assertions[0]).toEqual({
208
+ url: "self#jumbf=c2pa.assertions/cawg.training-mining",
209
+ hash: "rBBgURB+/0Bc2Uk3+blNpYTGQTxOwzXQ2xhjA3gsqI4=",
210
+ });
211
+ expect(signerPayload.referenced_assertions[1]).toEqual({
212
+ url: "self#jumbf=c2pa.assertions/c2pa.hash.data",
213
+ hash: "sASozh9KFSkW+cyMI0Pw5KYoD2qn7MkUEq9jUUhe/sM=",
214
+ });
215
+ }));
216
216
  });
package/dist/Settings.js CHANGED
@@ -18,23 +18,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
- const neon = require("./index.node");
22
21
  import * as fs from "fs-extra";
23
22
  import path from "path";
24
23
  import fetch from "node-fetch";
24
+ import { getNeonBinary } from "./binary.js";
25
25
  /**
26
26
  * Load settings from a JSON string and apply them globally.
27
27
  * @param json The JSON string containing the settings configuration
28
28
  */
29
29
  export function loadC2paSettings(json) {
30
- neon.loadSettings(json);
30
+ getNeonBinary().loadSettings(json);
31
31
  }
32
32
  /**
33
33
  * Load settings from a TOML string and apply them globally.
34
34
  * @param toml The TOML string containing the settings configuration
35
35
  */
36
36
  export function loadC2paSettingsToml(toml) {
37
- neon.loadSettingsToml(toml);
37
+ getNeonBinary().loadSettingsToml(toml);
38
38
  }
39
39
  /**
40
40
  * Load settings from a TOML or JSON file path and apply them globally.
@@ -81,7 +81,7 @@ export function loadSettingsFromUrl(url) {
81
81
  * @returns The JSON representation of the current settings
82
82
  */
83
83
  export function getSettingsJson() {
84
- return neon.getSettingsJson();
84
+ return getNeonBinary().getSettingsJson();
85
85
  }
86
86
  /**
87
87
  * Load trust configuration into the main trust settings.
@@ -98,7 +98,7 @@ export function loadTrustConfig(trustConfig) {
98
98
  trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
99
99
  allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
100
100
  };
101
- neon.loadTrustConfig(JSON.stringify(config));
101
+ getNeonBinary().loadTrustConfig(JSON.stringify(config));
102
102
  }
103
103
  /**
104
104
  * Load trust configuration into the CAWG trust settings.
@@ -115,7 +115,7 @@ export function loadCawgTrustConfig(trustConfig) {
115
115
  trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
116
116
  allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
117
117
  };
118
- neon.loadCawgTrustConfig(JSON.stringify(config));
118
+ getNeonBinary().loadCawgTrustConfig(JSON.stringify(config));
119
119
  }
120
120
  /**
121
121
  * Get the current trust configuration.
@@ -123,7 +123,7 @@ export function loadCawgTrustConfig(trustConfig) {
123
123
  */
124
124
  export function getTrustConfig() {
125
125
  var _a, _b, _c, _d;
126
- const json = neon.getTrustConfig();
126
+ const json = getNeonBinary().getTrustConfig();
127
127
  const parsed = JSON.parse(json);
128
128
  // Convert snake_case to camelCase to match TrustConfig interface
129
129
  // Handle undefined values by converting them to null
@@ -141,7 +141,7 @@ export function getTrustConfig() {
141
141
  */
142
142
  export function getCawgTrustConfig() {
143
143
  var _a, _b, _c, _d;
144
- const json = neon.getCawgTrustConfig();
144
+ const json = getNeonBinary().getCawgTrustConfig();
145
145
  const parsed = JSON.parse(json);
146
146
  // Convert snake_case to camelCase to match TrustConfig interface
147
147
  // Handle undefined values by converting them to null
@@ -170,7 +170,7 @@ export function loadVerifyConfig(verifyConfig) {
170
170
  skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
171
171
  strict_v1_validation: verifyConfig.strictV1Validation,
172
172
  };
173
- neon.loadVerifyConfig(JSON.stringify(config));
173
+ getNeonBinary().loadVerifyConfig(JSON.stringify(config));
174
174
  }
175
175
  /**
176
176
  * Patch the verify configuration with any subset of fields.
@@ -186,7 +186,7 @@ export function patchVerifyConfig(patch) {
186
186
  * @returns The current verify configuration object
187
187
  */
188
188
  export function getVerifyConfig() {
189
- const json = neon.getVerifyConfig();
189
+ const json = getNeonBinary().getVerifyConfig();
190
190
  const parsed = JSON.parse(json);
191
191
  // Convert snake_case to camelCase to match VerifyConfig interface
192
192
  return {
@@ -3,7 +3,7 @@
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
- import { loadC2paSettings, loadTrustConfig, loadCawgTrustConfig, getSettingsJson, getTrustConfig, getCawgTrustConfig, loadVerifyConfig, getVerifyConfig, patchVerifyConfig, } from "./Settings";
6
+ import { loadC2paSettings, loadTrustConfig, loadCawgTrustConfig, getSettingsJson, getTrustConfig, getCawgTrustConfig, loadVerifyConfig, getVerifyConfig, patchVerifyConfig, } from "./Settings.js";
7
7
  describe("Settings", () => {
8
8
  it("loads a trustlist-shaped JSON and returns JSON via getSettingsJson", () => {
9
9
  var _a, _b;
@@ -98,7 +98,7 @@ describe("Settings", () => {
98
98
  expect(() => loadTrustConfig(emptyTrustConfig)).not.toThrow();
99
99
  // Verify settings are still intact
100
100
  const currentSettings = JSON.parse(getSettingsJson());
101
- expect(currentSettings.core.hash_alg).toBe("sha256");
101
+ expect(currentSettings.core.merkle_tree_max_proofs).toBe(5);
102
102
  expect(currentSettings.verify.verify_trust).toBe(true);
103
103
  expect(currentSettings.trust.verify_trust_list).toBe(true);
104
104
  });
package/dist/Signer.js CHANGED
@@ -18,29 +18,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
- const neon = require("./index.node");
21
+ import { getNeonBinary } from "./binary.js";
22
22
  export class LocalSigner {
23
23
  constructor(localSigner) {
24
24
  this.localSigner = localSigner;
25
25
  }
26
26
  static newSigner(certificate, privateKey, algorithm, tsaUrl) {
27
- const signer = neon.localSignerNew(certificate, privateKey, algorithm, tsaUrl);
27
+ const signer = getNeonBinary().localSignerNew(certificate, privateKey, algorithm, tsaUrl);
28
28
  return new LocalSigner(signer);
29
29
  }
30
30
  sign(data) {
31
- return neon.localSignerSign.call(this.localSigner, data);
31
+ return getNeonBinary().localSignerSign.call(this.localSigner, data);
32
32
  }
33
33
  alg() {
34
- return neon.localSignerAlg.call(this.localSigner);
34
+ return getNeonBinary().localSignerAlg.call(this.localSigner);
35
35
  }
36
36
  certs() {
37
- return neon.localSignerCerts.call(this.localSigner);
37
+ return getNeonBinary().localSignerCerts.call(this.localSigner);
38
38
  }
39
39
  reserveSize() {
40
- return neon.localSignerReserveSize.call(this.localSigner);
40
+ return getNeonBinary().localSignerReserveSize.call(this.localSigner);
41
41
  }
42
42
  timeAuthorityUrl() {
43
- return neon.localSignerTimeAuthorityUrl.call(this.localSigner);
43
+ return getNeonBinary().localSignerTimeAuthorityUrl.call(this.localSigner);
44
44
  }
45
45
  signer() {
46
46
  return this.localSigner;
@@ -55,25 +55,28 @@ export class CallbackSigner {
55
55
  }
56
56
  static newSigner(config, callback) {
57
57
  // Convert the config object to a JsBox<CallbackSignerConfig>
58
- const configBox = neon.callbackSignerConfigFromJs(config);
59
- const signer = neon.callbackSignerFromConfig(configBox, callback);
58
+ const configBox = getNeonBinary().callbackSignerConfigFromJs(config);
59
+ const signer = getNeonBinary().callbackSignerFromConfig(configBox, callback);
60
60
  return new CallbackSigner(signer);
61
61
  }
62
62
  sign(data) {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
- return neon.callbackSignerSign.call(this.callbackSigner, data);
64
+ return getNeonBinary().callbackSignerSign.call(this.callbackSigner, data);
65
65
  });
66
66
  }
67
67
  alg() {
68
- return neon.callbackSignerAlg.call(this.callbackSigner);
68
+ return getNeonBinary().callbackSignerAlg.call(this.callbackSigner);
69
69
  }
70
70
  certs() {
71
- return neon.callbackSignerCerts.call(this.callbackSigner);
71
+ return getNeonBinary().callbackSignerCerts.call(this.callbackSigner);
72
72
  }
73
73
  reserveSize() {
74
- return neon.callbackSignerReserveSize.call(this.callbackSigner);
74
+ return getNeonBinary().callbackSignerReserveSize.call(this.callbackSigner);
75
75
  }
76
76
  timeAuthorityUrl() {
77
- return neon.callbackSignerTimeAuthorityUrl.call(this.callbackSigner);
77
+ return getNeonBinary().callbackSignerTimeAuthorityUrl.call(this.callbackSigner);
78
+ }
79
+ directCoseHandling() {
80
+ return getNeonBinary().callbackSignerDirectCoseHandling.call(this.callbackSigner);
78
81
  }
79
82
  }
@@ -18,9 +18,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
- import { CallbackSigner } from "./Signer";
22
21
  import * as fs from "fs-extra";
23
22
  import * as crypto from "crypto";
23
+ import { CallbackSigner } from "./Signer.js";
24
+ import { Builder } from "./Builder.js";
25
+ import { Reader } from "./Reader.js";
24
26
  class TestSigner {
25
27
  constructor(privateKey) {
26
28
  this.sign = (bytes) => __awaiter(this, void 0, void 0, function* () {
@@ -96,4 +98,65 @@ describe("CallbackSigner", () => {
96
98
  const signer = CallbackSigner.newSigner(config, (data) => __awaiter(void 0, void 0, void 0, function* () { return data; }));
97
99
  expect(signer.timeAuthorityUrl()).toBeUndefined();
98
100
  }));
101
+ it("should create valid COSE signature with buffer output", () => __awaiter(void 0, void 0, void 0, function* () {
102
+ const testSigner = new TestSigner(yield fs.readFile("./tests/fixtures/certs/es256.pem"));
103
+ const createRawSignatureCallback = () => {
104
+ return (data) => __awaiter(void 0, void 0, void 0, function* () {
105
+ // For directCoseHandling: false, return raw signature data
106
+ // The c2pa SDK will handle COSE wrapping internally
107
+ return yield testSigner.sign(data);
108
+ });
109
+ };
110
+ // Create a simple manifest
111
+ const manifestDefinition = {
112
+ vendor: "test",
113
+ claim_generator: "test-generator",
114
+ claim_generator_info: [
115
+ {
116
+ name: "c2pa_test",
117
+ version: "1.0.0",
118
+ },
119
+ ],
120
+ title: "Test_Manifest_Buffer",
121
+ format: "image/jpeg",
122
+ instance_id: "5678",
123
+ assertions: [
124
+ {
125
+ label: "org.test.assertion",
126
+ data: { message: "Buffer test with directCoseHandling: false" },
127
+ },
128
+ ],
129
+ resources: { resources: {} },
130
+ };
131
+ const builder = Builder.withJson(manifestDefinition);
132
+ const source = {
133
+ buffer: yield fs.readFile("./tests/fixtures/CA.jpg"),
134
+ mimeType: "image/jpeg",
135
+ };
136
+ const config = {
137
+ alg: "es256",
138
+ certs: [fs.readFileSync("./tests/fixtures/certs/es256.pub")],
139
+ reserveSize: 10000,
140
+ tsaUrl: undefined,
141
+ directCoseHandling: false,
142
+ };
143
+ const callback = createRawSignatureCallback();
144
+ const signer = CallbackSigner.newSigner(config, callback);
145
+ // Sign the manifest to buffer
146
+ const dest = { buffer: null };
147
+ yield builder.signAsync(signer, source, dest);
148
+ // Read the signed manifest back and verify signature is valid
149
+ const reader = yield Reader.fromAsset({
150
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151
+ buffer: dest.buffer,
152
+ mimeType: "image/jpeg",
153
+ });
154
+ const manifestStore = reader.json();
155
+ const activeManifest = reader.getActive();
156
+ // If validation_status is undefined, the signature is valid
157
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
+ expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
159
+ expect(manifestStore.active_manifest).not.toBeUndefined();
160
+ expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest_Buffer");
161
+ }));
99
162
  });
package/dist/Trustmark.js CHANGED
@@ -18,25 +18,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
- const neon = require("./index.node");
21
+ import { getNeonBinary } from "./binary.js";
22
22
  export class Trustmark {
23
23
  constructor(trustmark) {
24
24
  this.trustmark = trustmark;
25
25
  }
26
26
  static newTrustmark(config) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- const trustmark = yield neon.trustmarkNew(config);
28
+ const trustmark = yield getNeonBinary().trustmarkNew(config);
29
29
  return new Trustmark(trustmark);
30
30
  });
31
31
  }
32
32
  encode(image, strength, watermark) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- return neon.trustmarkEncode.call(this.trustmark, image, strength, watermark);
34
+ return getNeonBinary().trustmarkEncode.call(this.trustmark, image, strength, watermark);
35
35
  });
36
36
  }
37
37
  decode(image) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- return neon.trustmarkDecode.call(this.trustmark, image);
39
+ return getNeonBinary().trustmarkDecode.call(this.trustmark, image);
40
40
  });
41
41
  }
42
42
  }
@@ -18,10 +18,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
19
19
  // specific language governing permissions and limitations under
20
20
  // each license.
21
- import { Trustmark } from "./Trustmark";
22
21
  import path from "path";
23
22
  import * as fs from "fs-extra";
24
23
  import sharp from "sharp";
24
+ import { Trustmark } from "./Trustmark.js";
25
25
  const tempDir = path.join(__dirname, "..", "tmp");
26
26
  // Helper function to convert raw RGB pixel data to JPEG format
27
27
  function rawRgbToJpeg(rawRgbData, width, height) {
package/dist/binary.js ADDED
@@ -0,0 +1,24 @@
1
+ // Copyright 2025 Adobe. All rights reserved.
2
+ // This file is licensed to you under the Apache License,
3
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
+ // or the MIT license (http://opensource.org/licenses/MIT),
5
+ // at your option.
6
+ // Unless required by applicable law or agreed to in writing,
7
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
8
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
9
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
10
+ // specific language governing permissions and limitations under
11
+ // each license.
12
+ import { createRequire } from "module";
13
+ // Create a require function for the current module to load the .node file
14
+ const require = createRequire(import.meta.url);
15
+ // Dynamically import the binary module
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ let neon = null;
18
+ // Get the binary module (loads synchronously on first access)
19
+ export function getNeonBinary() {
20
+ if (neon === null) {
21
+ neon = require("./index.node");
22
+ }
23
+ return neon;
24
+ }
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@
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
- export { Builder } from "./Builder";
7
- export { Reader } from "./Reader";
8
- export { LocalSigner, CallbackSigner } from "./Signer";
9
- export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion";
10
- export { Trustmark } from "./Trustmark";
11
- export { isActionsAssertion } from "./assertions";
12
- export * from "./Settings";
6
+ export { Builder } from "./Builder.js";
7
+ export { Reader } from "./Reader.js";
8
+ export { LocalSigner, CallbackSigner } from "./Signer.js";
9
+ export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion.js";
10
+ export { Trustmark } from "./Trustmark.js";
11
+ export { isActionsAssertion } from "./assertions.js";
12
+ export * from "./Settings.js";
package/dist/index.node CHANGED
Binary file
@@ -1,10 +1,11 @@
1
- import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, SourceAsset } from "./types";
2
- import type { Manifest } from "@contentauth/c2pa-types";
1
+ import type { BuilderIntent, Manifest } from "@contentauth/c2pa-types";
2
+ import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, SourceAsset } from "./types.d.ts";
3
3
  export declare class Builder implements BuilderInterface {
4
4
  private builder;
5
5
  private constructor();
6
6
  static new(): Builder;
7
7
  static withJson(json: Manifest): Builder;
8
+ setIntent(intent: BuilderIntent): void;
8
9
  setNoEmbed(noEmbed?: boolean): void;
9
10
  setRemoteUrl(remoteUrl: string): void;
10
11
  addAssertion(label: string, assertion: unknown, assertionKind?: ManifestAssertionKind): void;
@@ -1,4 +1,4 @@
1
- import type { CallbackCredentialHolderInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface, NeonCallbackCredentialHolderHandle, NeonIdentityAssertionSignerHandle, NeonIdentityAssertionBuilderHandle, SignerPayload, NeonCallbackSignerHandle } from "./types";
1
+ import type { CallbackCredentialHolderInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface, NeonCallbackCredentialHolderHandle, NeonIdentityAssertionSignerHandle, NeonIdentityAssertionBuilderHandle, SignerPayload, NeonCallbackSignerHandle } from "./types.d.ts";
2
2
  export declare class IdentityAssertionBuilder implements IdentityAssertionBuilderInterface {
3
3
  private _builder;
4
4
  constructor(_builder: NeonIdentityAssertionBuilderHandle);
@@ -1,5 +1,5 @@
1
- import type { DestinationAsset, ReaderInterface, SourceAsset, NeonReaderHandle } from "./types";
2
1
  import type { Manifest, ManifestStore } from "@contentauth/c2pa-types";
2
+ import type { DestinationAsset, ReaderInterface, SourceAsset, NeonReaderHandle } from "./types.d.ts";
3
3
  export declare class Reader implements ReaderInterface {
4
4
  private reader;
5
5
  constructor(reader: NeonReaderHandle);
@@ -1,4 +1,4 @@
1
- import type { TrustConfig, VerifyConfig } from "./types";
1
+ import type { TrustConfig, VerifyConfig } from "./types.d.ts";
2
2
  /**
3
3
  * Load settings from a JSON string and apply them globally.
4
4
  * @param json The JSON string containing the settings configuration
@@ -1,4 +1,4 @@
1
- import type { CallbackSignerInterface, JsCallbackSignerConfig, NeonCallbackSignerHandle, NeonLocalSignerHandle, LocalSignerInterface, SigningAlg } from "./types";
1
+ import type { CallbackSignerInterface, JsCallbackSignerConfig, NeonCallbackSignerHandle, NeonLocalSignerHandle, LocalSignerInterface, SigningAlg } from "./types.d.ts";
2
2
  export declare class LocalSigner implements LocalSignerInterface {
3
3
  private localSigner;
4
4
  constructor(localSigner: NeonLocalSignerHandle);
@@ -20,4 +20,5 @@ export declare class CallbackSigner implements CallbackSignerInterface {
20
20
  certs(): Array<Buffer>;
21
21
  reserveSize(): number;
22
22
  timeAuthorityUrl(): string | undefined;
23
+ directCoseHandling(): boolean;
23
24
  }
@@ -1,4 +1,4 @@
1
- import type { TrustmarkInterface, TrustmarkConfig, NeonTrustmarkHandle } from "./types";
1
+ import type { TrustmarkInterface, TrustmarkConfig, NeonTrustmarkHandle } from "./types.d.ts";
2
2
  export declare class Trustmark implements TrustmarkInterface {
3
3
  private trustmark;
4
4
  constructor(trustmark: NeonTrustmarkHandle);
@@ -0,0 +1 @@
1
+ export declare function getNeonBinary(): any;