@contentauth/c2pa-node 0.9.11 → 0.10.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 +11 -38
- package/dist/Builder.js +8 -10
- package/dist/Builder.spec.js +103 -0
- package/dist/IdentityAssertion.js +20 -0
- package/dist/IdentityAssertion.spec.js +32 -2
- package/dist/Reader.js +5 -5
- package/dist/Reader.spec.js +4 -0
- package/dist/Settings.js +27 -8
- package/dist/Settings.spec.js +63 -18
- package/dist/SignerPayload.spec.js +180 -0
- package/dist/assetSize.js +10 -4
- package/dist/assetSize.spec.js +55 -0
- package/dist/index.js +1 -1
- package/dist/index.node +2 -2
- package/dist/types/Builder.d.ts +3 -5
- package/dist/types/IdentityAssertion.d.ts +19 -1
- package/dist/types/Settings.d.ts +17 -7
- package/dist/types/SignerPayload.spec.d.ts +1 -0
- package/dist/types/assetSize.d.ts +7 -1
- package/dist/types/assetSize.spec.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +7 -2
- package/package.json +3 -3
- package/src/lib.rs +4 -0
- package/src/neon_credential_holder.rs +27 -4
- package/src/neon_signer.rs +13 -1
package/README.md
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
To use the c2pa-node library, you need Node.js 22 or later. Use a patched release: v22.23.4+ on v22, v24.22.1+ on v24, or v26.12.1+ on v26. The binary installer and JavaScript fetch paths use Node's TLS stack independently of the Rust SDK; see [TLS trust stores](../../README.md#tls-trust-stores). If you need to manage multiple versions of Node on your machine, use a tool such as [nvm](https://github.com/nvm-sh/nvm).
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Rust is not required when installing the package normally: precompiled binaries
|
|
13
|
+
are downloaded automatically. For source builds, see
|
|
14
|
+
[Contributing to c2pa-node](https://github.com/contentauth/c2pa-js/blob/main/docs/project-contributions.md#contributing-to-c2pa-node).
|
|
15
|
+
|
|
16
|
+
|
|
13
17
|
|
|
14
18
|
## Installation
|
|
15
19
|
|
|
@@ -50,35 +54,8 @@ versions of `@contentauth/c2pa-node`. Use the version selector to switch release
|
|
|
50
54
|
The [multi-package documentation](https://contentauth.github.io/c2pa-js/) remains
|
|
51
55
|
available at the existing root URL.
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
pnpm ci:docs:node
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
This requires npm and network access to the public npm registry, but no Rust build,
|
|
61
|
-
native binaries, or GitHub authentication. Packages are installed in isolated
|
|
62
|
-
temporary directories with lifecycle scripts disabled, and only their TypeScript
|
|
63
|
-
declarations are parsed. Temporary installs are removed after the build.
|
|
64
|
-
|
|
65
|
-
The first version in [node-versions.json](../../api-docs/node-versions.json) is
|
|
66
|
-
served at `docs/node/index.html`. Each selected release is also available at
|
|
67
|
-
`docs/node/versions/<version>/index.html`, published at
|
|
68
|
-
`https://contentauth.github.io/c2pa-js/node/versions/<version>/`.
|
|
69
|
-
Versions must be exact npm releases, not tags such as `latest` or version ranges.
|
|
70
|
-
Adding a release does not automatically change the default: put the desired
|
|
71
|
-
default first in the list.
|
|
72
|
-
|
|
73
|
-
Run `pnpm ci:docs:releases` to build the versioned Node and web docs, or
|
|
74
|
-
`pnpm ci:docs` to build the existing multi-package site and both versioned sites.
|
|
75
|
-
Node and web have independent version lists, and rebuilding one does not remove
|
|
76
|
-
the other. Generated HTML under `docs/` is not checked into version control.
|
|
77
|
-
The release workflow publishes the complete site after a new package release;
|
|
78
|
-
run that workflow manually to rebuild documentation without publishing packages.
|
|
79
|
-
Publishing a package does not automatically add it to the configured docs versions.
|
|
80
|
-
|
|
81
|
-
Run `pnpm test:docs` for the documentation tooling tests.
|
|
57
|
+
For documentation builds and version-list maintenance, see
|
|
58
|
+
[Building API documentation](https://github.com/contentauth/c2pa-js/blob/main/docs/project-contributions.md#building-api-documentation).
|
|
82
59
|
|
|
83
60
|
## Components
|
|
84
61
|
|
|
@@ -590,7 +567,7 @@ const builder3 = await Builder.fromArchive(archiveAsset, context);
|
|
|
590
567
|
```
|
|
591
568
|
|
|
592
569
|
> [!NOTE]
|
|
593
|
-
>
|
|
570
|
+
> As in `c2pa-web`, URLs in a `Context`'s trust-anchor settings are fetched and resolved before the Reader or Builder is created. The deprecated raw-settings API does not resolve URLs; use a `Context` for URL-based trust anchors.
|
|
594
571
|
|
|
595
572
|
#### Per-instance settings (deprecated)
|
|
596
573
|
|
|
@@ -711,13 +688,9 @@ const builder = Builder.new(urlSettings);
|
|
|
711
688
|
|
|
712
689
|
### Build and use custom binary
|
|
713
690
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
pnpm run build:rust
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
**Use custom Rust binary:**
|
|
691
|
+
For instructions on building a Rust binary, see
|
|
692
|
+
[Contributing to c2pa-node](https://github.com/contentauth/c2pa-js/blob/main/docs/project-contributions.md#contributing-to-c2pa-node).
|
|
693
|
+
To use a custom binary:
|
|
721
694
|
|
|
722
695
|
```bash
|
|
723
696
|
export C2PA_LIBRARY_PATH=<path-to-binary-folder>/index.node
|
package/dist/Builder.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// at your option.
|
|
6
6
|
import { Context } from "@contentauth/c2pa-utilities";
|
|
7
7
|
import { getNeonBinary } from "./binary.js";
|
|
8
|
-
import { resolveSettingsForNeon } from "./Settings.js";
|
|
8
|
+
import { resolveRawSettingsForNeon, resolveSettingsForNeon } from "./Settings.js";
|
|
9
9
|
import { IdentityAssertionSigner } from "./IdentityAssertion.js";
|
|
10
10
|
function stringifyManifestDefinition(json) {
|
|
11
11
|
try {
|
|
@@ -30,7 +30,7 @@ export class Builder {
|
|
|
30
30
|
* @param settings A raw `C2paSettings` string/object.
|
|
31
31
|
*/
|
|
32
32
|
static new(settings) {
|
|
33
|
-
const settingsStr =
|
|
33
|
+
const settingsStr = resolveRawSettingsForNeon(settings);
|
|
34
34
|
const builder = getNeonBinary().builderNew(settingsStr);
|
|
35
35
|
return new Builder(builder);
|
|
36
36
|
}
|
|
@@ -38,14 +38,13 @@ export class Builder {
|
|
|
38
38
|
* Create a Builder with a minimal manifest definition, configured by a `Context`.
|
|
39
39
|
* Prefer this over the deprecated {@link Builder.new}.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
* resolution at construction time.
|
|
41
|
+
* Resolves trust-anchor URLs in the Context before constructing the Builder.
|
|
43
42
|
*
|
|
44
43
|
* @param context A `Context` object containing configuration settings for this Builder.
|
|
45
44
|
* Defaults to an empty `Context` using default settings if one is not provided.
|
|
46
45
|
*/
|
|
47
46
|
static async newAsync(context = new Context()) {
|
|
48
|
-
const settingsStr = resolveSettingsForNeon(context);
|
|
47
|
+
const settingsStr = await resolveSettingsForNeon(context);
|
|
49
48
|
const builder = getNeonBinary().builderNew(settingsStr);
|
|
50
49
|
return new Builder(builder);
|
|
51
50
|
}
|
|
@@ -56,7 +55,7 @@ export class Builder {
|
|
|
56
55
|
*/
|
|
57
56
|
static withJson(json, settings) {
|
|
58
57
|
const jsonString = stringifyManifestDefinition(json);
|
|
59
|
-
const settingsStr =
|
|
58
|
+
const settingsStr = resolveRawSettingsForNeon(settings);
|
|
60
59
|
const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
|
|
61
60
|
return new Builder(builder);
|
|
62
61
|
}
|
|
@@ -64,8 +63,7 @@ export class Builder {
|
|
|
64
63
|
* Create a Builder from a manifest definition, configured by a `Context`. Prefer this over
|
|
65
64
|
* the deprecated {@link Builder.withJson}.
|
|
66
65
|
*
|
|
67
|
-
*
|
|
68
|
-
* to resolve trust anchors at construction time.
|
|
66
|
+
* Resolves trust-anchor URLs in the Context before constructing the Builder.
|
|
69
67
|
*
|
|
70
68
|
* @param json The manifest JSON.
|
|
71
69
|
* @param context A `Context` object containing configuration settings for this Builder.
|
|
@@ -73,7 +71,7 @@ export class Builder {
|
|
|
73
71
|
*/
|
|
74
72
|
static async withJsonAsync(json, context = new Context()) {
|
|
75
73
|
const jsonString = stringifyManifestDefinition(json);
|
|
76
|
-
const settingsStr = resolveSettingsForNeon(context);
|
|
74
|
+
const settingsStr = await resolveSettingsForNeon(context);
|
|
77
75
|
const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
|
|
78
76
|
return new Builder(builder);
|
|
79
77
|
}
|
|
@@ -118,7 +116,7 @@ export class Builder {
|
|
|
118
116
|
* the same as `undefined`.
|
|
119
117
|
*/
|
|
120
118
|
static async fromArchive(asset, settingsOrContext) {
|
|
121
|
-
const settingsStr = resolveSettingsForNeon(settingsOrContext);
|
|
119
|
+
const settingsStr = await resolveSettingsForNeon(settingsOrContext);
|
|
122
120
|
return new Builder(await getNeonBinary().builderFromArchive(asset, settingsStr));
|
|
123
121
|
}
|
|
124
122
|
sign(signer, input, output) {
|
package/dist/Builder.spec.js
CHANGED
|
@@ -7,6 +7,8 @@ import { Context } from "@contentauth/c2pa-utilities";
|
|
|
7
7
|
import fs from "fs-extra";
|
|
8
8
|
import path from "path";
|
|
9
9
|
import * as crypto from "crypto";
|
|
10
|
+
import { vi } from "vitest";
|
|
11
|
+
import http from "http";
|
|
10
12
|
import { isActionsAssertion } from "./assertions.js";
|
|
11
13
|
import { CallbackSigner, LocalSigner } from "./Signer.js";
|
|
12
14
|
import { Reader } from "./Reader.js";
|
|
@@ -356,6 +358,64 @@ describe("Builder", () => {
|
|
|
356
358
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
357
359
|
expect(activeManifest?.title).toBe("Test_Manifest");
|
|
358
360
|
});
|
|
361
|
+
it("should send a time-stamp request to the callback signer's tsaUrl", async () => {
|
|
362
|
+
// A local TSA that records each request and refuses it.
|
|
363
|
+
const tsaRequests = [];
|
|
364
|
+
const tsa = http.createServer((req, res) => {
|
|
365
|
+
tsaRequests.push(req.headers);
|
|
366
|
+
req.resume();
|
|
367
|
+
req.on("end", () => {
|
|
368
|
+
res.writeHead(503);
|
|
369
|
+
res.end();
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
await new Promise((resolve) => tsa.listen(0, "127.0.0.1", resolve));
|
|
373
|
+
const { port } = tsa.address();
|
|
374
|
+
try {
|
|
375
|
+
const signerConfig = {
|
|
376
|
+
alg: "es256",
|
|
377
|
+
certs: [publicKey],
|
|
378
|
+
reserveSize: 20000,
|
|
379
|
+
tsaUrl: `http://127.0.0.1:${port}/tsa`,
|
|
380
|
+
tsaHeaders: [["x-c2pa-test", "tsa-header"]],
|
|
381
|
+
directCoseHandling: false,
|
|
382
|
+
};
|
|
383
|
+
const testSigner = new TestSigner(privateKey);
|
|
384
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
385
|
+
// The TSA refuses, so signing must fail instead of silently
|
|
386
|
+
// producing a manifest without a time-stamp.
|
|
387
|
+
await expect(builder.signAsync(signer, source, { buffer: null })).rejects.toThrow();
|
|
388
|
+
expect(tsaRequests.length).toBeGreaterThan(0);
|
|
389
|
+
expect(tsaRequests[0]["content-type"]).toBe("application/timestamp-query");
|
|
390
|
+
expect(tsaRequests[0]["x-c2pa-test"]).toBe("tsa-header");
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
tsa.closeAllConnections();
|
|
394
|
+
await new Promise((resolve) => tsa.close(() => resolve()));
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
// Needs network access to a real RFC 3161 TSA, e.g.
|
|
398
|
+
// C2PA_TEST_TSA_URL=http://timestamp.digicert.com
|
|
399
|
+
it.skipIf(!process.env.C2PA_TEST_TSA_URL)("should time-stamp a manifest signed with a callback signer", async () => {
|
|
400
|
+
const dest = {
|
|
401
|
+
buffer: null,
|
|
402
|
+
};
|
|
403
|
+
const signerConfig = {
|
|
404
|
+
alg: "es256",
|
|
405
|
+
certs: [publicKey],
|
|
406
|
+
reserveSize: 20000,
|
|
407
|
+
tsaUrl: process.env.C2PA_TEST_TSA_URL,
|
|
408
|
+
directCoseHandling: false,
|
|
409
|
+
};
|
|
410
|
+
const testSigner = new TestSigner(privateKey);
|
|
411
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
412
|
+
await builder.signAsync(signer, source, dest);
|
|
413
|
+
const reader = await Reader.fromAsset({
|
|
414
|
+
buffer: dest.buffer,
|
|
415
|
+
mimeType: "jpeg",
|
|
416
|
+
});
|
|
417
|
+
expect(reader.getActive()?.signature_info?.time).toBeTruthy();
|
|
418
|
+
}, 30000);
|
|
359
419
|
it("should preserve JSON assertion characters without escaping", async () => {
|
|
360
420
|
const fingerprintAssertion = JSON.stringify({
|
|
361
421
|
alg: "sha256",
|
|
@@ -614,6 +674,12 @@ describe("Builder", () => {
|
|
|
614
674
|
const definition = builder.getManifestDefinition();
|
|
615
675
|
expect(definition.redactions).toEqual([uri1, uri2]);
|
|
616
676
|
});
|
|
677
|
+
it("should set a label", () => {
|
|
678
|
+
const label = "urn:c2pa:00000000-0000-4000-8000-000000000000";
|
|
679
|
+
const builder = Builder.new();
|
|
680
|
+
builder.updateManifestProperty("label", label);
|
|
681
|
+
expect(builder.getManifestDefinition().label).toBe(label);
|
|
682
|
+
});
|
|
617
683
|
it("should test builder remote url", async () => {
|
|
618
684
|
// This test mirrors the Rust test_builder_remote_url test
|
|
619
685
|
// Create a simple manifest definition similar to simple_manifest_json()
|
|
@@ -836,6 +902,43 @@ describe("Builder", () => {
|
|
|
836
902
|
const manifestStore = reader.json();
|
|
837
903
|
expect(manifestStore.validation_status ?? []).not.toContainEqual(expect.objectContaining({ code: "signingCredential.untrusted" }));
|
|
838
904
|
});
|
|
905
|
+
it("newAsync(context) fetches trust-anchor URLs before creating the Builder", async () => {
|
|
906
|
+
const pem = "-----BEGIN CERTIFICATE-----\nanchor\n-----END CERTIFICATE-----";
|
|
907
|
+
const fetch = vi.fn(async () => new Response(pem));
|
|
908
|
+
vi.stubGlobal("fetch", fetch);
|
|
909
|
+
try {
|
|
910
|
+
const context = new Context({
|
|
911
|
+
trust: { trustAnchors: "https://example.com/anchors.pem" },
|
|
912
|
+
});
|
|
913
|
+
await Builder.newAsync(context);
|
|
914
|
+
expect(fetch).toHaveBeenCalledOnce();
|
|
915
|
+
const resolvedSettings = JSON.parse(await context.toJson());
|
|
916
|
+
expect(resolvedSettings.trust.anchors[0].trust_anchors).toBe(pem);
|
|
917
|
+
}
|
|
918
|
+
finally {
|
|
919
|
+
vi.unstubAllGlobals();
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
it("newAsync(context) retries failed trust-anchor fetches", async () => {
|
|
923
|
+
const pem = "-----BEGIN CERTIFICATE-----\nanchor\n-----END CERTIFICATE-----";
|
|
924
|
+
const fetch = vi
|
|
925
|
+
.fn()
|
|
926
|
+
.mockResolvedValueOnce(new Response("", { status: 503 }))
|
|
927
|
+
.mockResolvedValueOnce(new Response(pem));
|
|
928
|
+
vi.stubGlobal("fetch", fetch);
|
|
929
|
+
try {
|
|
930
|
+
const context = new Context({
|
|
931
|
+
trust: { trustAnchors: "https://example.com/anchors.pem" },
|
|
932
|
+
});
|
|
933
|
+
await Builder.newAsync(context);
|
|
934
|
+
expect(fetch).toHaveBeenCalledTimes(2);
|
|
935
|
+
const resolvedSettings = JSON.parse(await context.toJson());
|
|
936
|
+
expect(resolvedSettings.trust.anchors[0].trust_anchors).toBe(pem);
|
|
937
|
+
}
|
|
938
|
+
finally {
|
|
939
|
+
vi.unstubAllGlobals();
|
|
940
|
+
}
|
|
941
|
+
});
|
|
839
942
|
it("withJsonAsync(json, context) applies the Context's settings", async () => {
|
|
840
943
|
const dest = { path: path.join(tempDir, "context_withjson_signed.jpg") };
|
|
841
944
|
const signer = LocalSigner.newSigner(publicKey, privateKey, "es256");
|
|
@@ -10,6 +10,26 @@
|
|
|
10
10
|
// specific language governing permissions and limitations under
|
|
11
11
|
// each license.
|
|
12
12
|
import { getNeonBinary } from "./binary.js";
|
|
13
|
+
/**
|
|
14
|
+
* Encode a CAWG SignerPayload using c2pa_cbor. Hashes become CBOR byte strings;
|
|
15
|
+
* the wire keys are referenced_assertions, sig_type, and (when nonempty) role.
|
|
16
|
+
*
|
|
17
|
+
* Input names are case-sensitive: referencedAssertions, sigType, roles, and each
|
|
18
|
+
* reference's url, hash, and alg. Wire-format names are not aliases. Missing or
|
|
19
|
+
* incorrectly cased required fields are rejected; unknown data properties are
|
|
20
|
+
* ignored, including incorrectly cased optional fields. Omitted, undefined, or
|
|
21
|
+
* empty roles are omitted on the wire; null roles are rejected.
|
|
22
|
+
*
|
|
23
|
+
* Use plain data objects with Uint8Array hashes for portability between bindings
|
|
24
|
+
* (Node Buffer hashes are also supported here). Validation failures throw
|
|
25
|
+
* synchronously. The Web counterpart rejects its Promise and additionally
|
|
26
|
+
* requires the entire payload, including unknown properties, to be
|
|
27
|
+
* structured-cloneable: an unknown function property is ignored here but cannot
|
|
28
|
+
* be sent to the Web worker. Error types and messages are binding-specific.
|
|
29
|
+
*/
|
|
30
|
+
export function encodeSignerPayload(payload) {
|
|
31
|
+
return getNeonBinary().encodeSignerPayload(payload);
|
|
32
|
+
}
|
|
13
33
|
export class IdentityAssertionBuilder {
|
|
14
34
|
_builder;
|
|
15
35
|
constructor(_builder) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// at your option.
|
|
6
6
|
import fs from "fs-extra";
|
|
7
7
|
import * as crypto from "crypto";
|
|
8
|
-
import {
|
|
8
|
+
import { spawnSync } from "child_process";
|
|
9
|
+
import { encodeSignerPayload } from "./index.js";
|
|
9
10
|
class TestSigner {
|
|
10
11
|
privateKey;
|
|
11
12
|
constructor(privateKey) {
|
|
@@ -27,7 +28,7 @@ class TestCawgSigner {
|
|
|
27
28
|
this.manifestSigner = manifestSigner;
|
|
28
29
|
}
|
|
29
30
|
sign = async (payload) => {
|
|
30
|
-
const cborBytes = Buffer.from(
|
|
31
|
+
const cborBytes = Buffer.from(encodeSignerPayload(payload));
|
|
31
32
|
return this.manifestSigner.sign(cborBytes);
|
|
32
33
|
};
|
|
33
34
|
}
|
|
@@ -174,6 +175,35 @@ describe("CallbackCredentialHolder accessors", () => {
|
|
|
174
175
|
expect(payload.referencedAssertions[0].url).toBe("self#jumbf=c2pa.assertions/cawg.training-mining");
|
|
175
176
|
expect(Buffer.from(payload.referencedAssertions[0].hash)).toEqual(Buffer.from([9, 8, 7]));
|
|
176
177
|
});
|
|
178
|
+
it("releases main loop when idle", () => {
|
|
179
|
+
// Note: Runs in a child process, since tests a potential hang.
|
|
180
|
+
const scriptEntrypoint = new URL("../dist/index.js", import.meta.url).href;
|
|
181
|
+
// Check the run of the script releases channels, to free up main loop.
|
|
182
|
+
const testScript = `
|
|
183
|
+
import {
|
|
184
|
+
CallbackCredentialHolder,
|
|
185
|
+
CallbackSigner,
|
|
186
|
+
IdentityAssertionSigner,
|
|
187
|
+
} from ${JSON.stringify(scriptEntrypoint)};
|
|
188
|
+
const signer = CallbackSigner.newSigner(
|
|
189
|
+
{ alg: "es256", certs: [Buffer.alloc(1)], reserveSize: 1000, directCoseHandling: false },
|
|
190
|
+
async () => Buffer.alloc(64),
|
|
191
|
+
);
|
|
192
|
+
globalThis.kept = [
|
|
193
|
+
signer,
|
|
194
|
+
IdentityAssertionSigner.new(signer.getHandle()),
|
|
195
|
+
CallbackCredentialHolder.newCallbackCredentialHolder(
|
|
196
|
+
1000,
|
|
197
|
+
"cawg.x509.cose",
|
|
198
|
+
async () => Buffer.alloc(1),
|
|
199
|
+
),
|
|
200
|
+
];
|
|
201
|
+
`;
|
|
202
|
+
const runResult = spawnSync(process.execPath, ["--input-type=module", "-e", testScript], { timeout: 5_000, encoding: "utf8" });
|
|
203
|
+
expect(runResult.stderr).not.toMatch(/Error/);
|
|
204
|
+
expect(runResult.signal).toBeNull();
|
|
205
|
+
expect(runResult.status).toBe(0);
|
|
206
|
+
});
|
|
177
207
|
});
|
|
178
208
|
describe("handles reserveSize", () => {
|
|
179
209
|
async function signWithReserveSize(reserveSize) {
|
package/dist/Reader.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// at your option.
|
|
6
6
|
import { getNeonBinary } from "./binary.js";
|
|
7
7
|
import { validateSourceAssetSize } from "./assetSize.js";
|
|
8
|
-
import { resolveSettingsForNeon } from "./Settings.js";
|
|
8
|
+
import { resolveSdkConfig, resolveSettingsForNeon } from "./Settings.js";
|
|
9
9
|
export class Reader {
|
|
10
10
|
reader;
|
|
11
11
|
constructor(reader) {
|
|
@@ -29,8 +29,8 @@ export class Reader {
|
|
|
29
29
|
* the same as `undefined`.
|
|
30
30
|
*/
|
|
31
31
|
static async fromAsset(asset, settingsOrContext) {
|
|
32
|
-
await validateSourceAssetSize(asset);
|
|
33
|
-
const settingsStr = resolveSettingsForNeon(settingsOrContext);
|
|
32
|
+
await validateSourceAssetSize(asset, resolveSdkConfig(settingsOrContext));
|
|
33
|
+
const settingsStr = await resolveSettingsForNeon(settingsOrContext);
|
|
34
34
|
const reader = await getNeonBinary().readerFromAsset(asset, settingsStr);
|
|
35
35
|
return reader ? new Reader(reader) : null;
|
|
36
36
|
}
|
|
@@ -40,8 +40,8 @@ export class Reader {
|
|
|
40
40
|
* the same as `undefined`.
|
|
41
41
|
*/
|
|
42
42
|
static async fromManifestDataAndAsset(manifestData, asset, settingsOrContext) {
|
|
43
|
-
await validateSourceAssetSize(asset);
|
|
44
|
-
const settingsStr = resolveSettingsForNeon(settingsOrContext);
|
|
43
|
+
await validateSourceAssetSize(asset, resolveSdkConfig(settingsOrContext));
|
|
44
|
+
const settingsStr = await resolveSettingsForNeon(settingsOrContext);
|
|
45
45
|
const reader = await getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
|
|
46
46
|
return new Reader(reader);
|
|
47
47
|
}
|
package/dist/Reader.spec.js
CHANGED
|
@@ -151,6 +151,10 @@ describe("Reader", () => {
|
|
|
151
151
|
await fs.truncate(oversizedPath, MAX_SIZE_IN_BYTES + 1);
|
|
152
152
|
await expect(Reader.fromAsset({ path: oversizedPath })).rejects.toThrow(AssetTooLargeError);
|
|
153
153
|
});
|
|
154
|
+
it("should honor a lower max size from a Context", async () => {
|
|
155
|
+
const context = new Context(undefined, { maxSizeInBytes: 1 });
|
|
156
|
+
await expect(Reader.fromAsset({ path: "./tests/fixtures/A.jpg" }, context)).rejects.toThrow(AssetTooLargeError);
|
|
157
|
+
});
|
|
154
158
|
it("should read from manifest data and buffer", async () => {
|
|
155
159
|
const manifestData = await fs.readFile("./tests/fixtures/CA/manifest_data.c2pa");
|
|
156
160
|
const buffer = await fs.readFile("./tests/fixtures/CA.jpg");
|
package/dist/Settings.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// specific language governing permissions and limitations under
|
|
11
11
|
// each license.
|
|
12
12
|
import fs from "fs-extra";
|
|
13
|
-
import { Context
|
|
13
|
+
import { Context } from "@contentauth/c2pa-utilities";
|
|
14
14
|
/**
|
|
15
15
|
* This file contains only Settings functions that are unique to the Node SDK.
|
|
16
16
|
*
|
|
@@ -27,21 +27,40 @@ export async function loadSettingsFromFile(filePath) {
|
|
|
27
27
|
return content;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* a JSON string that can be passed into the native library.
|
|
30
|
+
* Reads the SDK config out of a settings argument.
|
|
32
31
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* Only a `Context` carries an SDK config so the deprecated raw `C2paSettings` forms always
|
|
33
|
+
* resolve to `undefined`, leaving this package's defaults in place.
|
|
34
|
+
*
|
|
35
|
+
* @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object.
|
|
36
|
+
* @returns The `Context`'s SDK config, or `undefined` if there is none.
|
|
36
37
|
*/
|
|
37
|
-
export function
|
|
38
|
+
export function resolveSdkConfig(settingsOrContext) {
|
|
39
|
+
return settingsOrContext instanceof Context
|
|
40
|
+
? settingsOrContext.sdkConfig
|
|
41
|
+
: undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolves Context settings, including any trust-anchor URLs, before passing them to the native
|
|
45
|
+
* library. Deprecated raw settings retain their existing pass-through behavior.
|
|
46
|
+
*/
|
|
47
|
+
export async function resolveSettingsForNeon(settingsOrContext) {
|
|
38
48
|
if (settingsOrContext == null) {
|
|
39
49
|
return undefined;
|
|
40
50
|
}
|
|
41
51
|
if (settingsOrContext instanceof Context) {
|
|
42
|
-
return
|
|
52
|
+
return settingsOrContext.toJson();
|
|
43
53
|
}
|
|
44
54
|
return typeof settingsOrContext === "string"
|
|
45
55
|
? settingsOrContext
|
|
46
56
|
: JSON.stringify(settingsOrContext);
|
|
47
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves deprecated raw settings for the synchronous Builder factories.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveRawSettingsForNeon(settings) {
|
|
62
|
+
if (settings == null) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return typeof settings === "string" ? settings : JSON.stringify(settings);
|
|
66
|
+
}
|
package/dist/Settings.spec.js
CHANGED
|
@@ -7,7 +7,8 @@ import fs from "fs-extra";
|
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import * as os from "os";
|
|
9
9
|
import { Context, DEFAULT_SETTINGS, mergeSettings, settingsToJson, } from "@contentauth/c2pa-utilities";
|
|
10
|
-
import {
|
|
10
|
+
import { vi } from "vitest";
|
|
11
|
+
import { loadSettingsFromFile, resolveRawSettingsForNeon, resolveSdkConfig, resolveSettingsForNeon, } from "./Settings.js";
|
|
11
12
|
describe("Settings", () => {
|
|
12
13
|
describe("loadSettingsFromFile", () => {
|
|
13
14
|
let tempDir;
|
|
@@ -47,36 +48,80 @@ verify_after_sign = false`;
|
|
|
47
48
|
await expect(loadSettingsFromFile(filePath)).rejects.toThrow();
|
|
48
49
|
});
|
|
49
50
|
});
|
|
50
|
-
describe("
|
|
51
|
+
describe("resolveRawSettingsForNeon", () => {
|
|
51
52
|
it("returns undefined when omitted", () => {
|
|
52
|
-
expect(
|
|
53
|
+
expect(resolveRawSettingsForNeon(undefined)).toBeUndefined();
|
|
53
54
|
});
|
|
54
55
|
it("returns undefined when null is passed in", () => {
|
|
55
56
|
// A plain-JS caller can pass `null` explicitly.
|
|
56
57
|
// It must not fall through to JSON.stringify(null), which would send the
|
|
57
58
|
// native library the literal string "null" instead of "no settings".
|
|
58
|
-
expect(
|
|
59
|
+
expect(resolveRawSettingsForNeon(null)).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
it("passes raw settings through unchanged", () => {
|
|
62
|
+
const rawSettings = { verify: { verify_trust: false } };
|
|
63
|
+
const result = resolveRawSettingsForNeon(rawSettings);
|
|
64
|
+
expect(JSON.parse(result)).toEqual(rawSettings);
|
|
65
|
+
});
|
|
66
|
+
it("passes raw settings JSON through unchanged", () => {
|
|
67
|
+
const json = JSON.stringify({ verify: { verify_trust: false } });
|
|
68
|
+
expect(resolveRawSettingsForNeon(json)).toBe(json);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("resolveSettingsForNeon", () => {
|
|
72
|
+
it("returns undefined when omitted", async () => {
|
|
73
|
+
expect(await resolveSettingsForNeon(undefined)).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
it("returns undefined when null is passed in", async () => {
|
|
76
|
+
expect(await resolveSettingsForNeon(null)).toBeUndefined();
|
|
59
77
|
});
|
|
60
|
-
it("applies defaults for an empty Context", () => {
|
|
61
|
-
const result = resolveSettingsForNeon(new Context());
|
|
78
|
+
it("applies defaults for an empty Context", async () => {
|
|
79
|
+
const result = await resolveSettingsForNeon(new Context());
|
|
62
80
|
expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(DEFAULT_SETTINGS)));
|
|
63
81
|
});
|
|
64
|
-
it("
|
|
82
|
+
it("does not serialize a Context's SDK config", async () => {
|
|
83
|
+
const result = await resolveSettingsForNeon(new Context(undefined, { maxSizeInBytes: 42 }));
|
|
84
|
+
expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(DEFAULT_SETTINGS)));
|
|
85
|
+
});
|
|
86
|
+
it("merges a Context's settings with defaults", async () => {
|
|
65
87
|
const settings = { verify: { verifyTrust: false } };
|
|
66
|
-
const result = resolveSettingsForNeon(new Context(settings));
|
|
88
|
+
const result = await resolveSettingsForNeon(new Context(settings));
|
|
67
89
|
expect(JSON.parse(result)).toEqual(JSON.parse(settingsToJson(mergeSettings(DEFAULT_SETTINGS, settings))));
|
|
68
90
|
});
|
|
69
|
-
it("
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
it("fetches trust-anchor URLs before returning Context settings", async () => {
|
|
92
|
+
const pem = "-----BEGIN CERTIFICATE-----\nanchor\n-----END CERTIFICATE-----";
|
|
93
|
+
const fetch = vi.fn(async () => new Response(pem));
|
|
94
|
+
vi.stubGlobal("fetch", fetch);
|
|
95
|
+
try {
|
|
96
|
+
const result = await resolveSettingsForNeon(new Context({
|
|
97
|
+
trust: { trustAnchors: "https://example.com/anchors.pem" },
|
|
98
|
+
}));
|
|
99
|
+
expect(fetch).toHaveBeenCalledOnce();
|
|
100
|
+
expect(JSON.parse(result).trust.anchors[0].trust_anchors).toBe(pem);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
vi.unstubAllGlobals();
|
|
104
|
+
}
|
|
76
105
|
});
|
|
77
|
-
it("
|
|
78
|
-
const
|
|
79
|
-
|
|
106
|
+
it("keeps deprecated raw settings unchanged", async () => {
|
|
107
|
+
const rawSettings = { verify: { verify_trust: false } };
|
|
108
|
+
const result = await resolveSettingsForNeon(rawSettings);
|
|
109
|
+
expect(JSON.parse(result)).toEqual(rawSettings);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("resolveSdkConfig", () => {
|
|
113
|
+
it("returns a Context's SDK config", () => {
|
|
114
|
+
const sdkConfig = { maxSizeInBytes: 42 };
|
|
115
|
+
expect(resolveSdkConfig(new Context(undefined, sdkConfig))).toEqual(sdkConfig);
|
|
116
|
+
});
|
|
117
|
+
it("returns undefined when a Context carries no SDK config", () => {
|
|
118
|
+
expect(resolveSdkConfig(new Context())).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
it("returns undefined for the deprecated raw settings forms", () => {
|
|
121
|
+
expect(resolveSdkConfig(undefined)).toBeUndefined();
|
|
122
|
+
expect(resolveSdkConfig(null)).toBeUndefined();
|
|
123
|
+
expect(resolveSdkConfig({ verify: { verifyTrust: false } })).toBeUndefined();
|
|
124
|
+
expect(resolveSdkConfig('{"verify":{"verify_trust":false}}')).toBeUndefined();
|
|
80
125
|
});
|
|
81
126
|
});
|
|
82
127
|
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Copyright 2026 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 { encodeSignerPayload } from "./index.js";
|
|
13
|
+
const toHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
14
|
+
describe("encodeSignerPayload", () => {
|
|
15
|
+
it("encodes roles, alg, and non-ASCII URLs to the golden CBOR bytes", () => {
|
|
16
|
+
const hash = Uint8Array.of(1, 2, 3);
|
|
17
|
+
const payload = {
|
|
18
|
+
referencedAssertions: [
|
|
19
|
+
{
|
|
20
|
+
url: "self#jumbf=/c2pa/assertions/c2pa.actions",
|
|
21
|
+
hash,
|
|
22
|
+
alg: "sha256",
|
|
23
|
+
},
|
|
24
|
+
{ url: "second/日本語", hash: Uint8Array.of(0, 127, 128, 255) },
|
|
25
|
+
],
|
|
26
|
+
sigType: "cawg.x509.cose",
|
|
27
|
+
roles: ["cawg.creator", "cawg.publisher"],
|
|
28
|
+
};
|
|
29
|
+
const bytes = encodeSignerPayload(payload);
|
|
30
|
+
expect(bytes).toBeInstanceOf(Uint8Array);
|
|
31
|
+
expect(toHex(bytes)).toBe("a3757265666572656e6365645f617373657274696f6e7382a36375726c782873656c66236a756d62663d2f633270612f617373657274696f6e732f633270612e616374696f6e7363616c6766736861323536646861736843010203a26375726c707365636f6e642fe697a5e69cace8aa9e646861736844007f80ff687369675f747970656e636177672e783530392e636f736564726f6c65826c636177672e63726561746f726e636177672e7075626c6973686572");
|
|
32
|
+
expect(payload.referencedAssertions[0].hash).toEqual(hash);
|
|
33
|
+
});
|
|
34
|
+
it.each([undefined, []])("omits an absent or empty role (%j) and encodes empty assertions", (roles) => {
|
|
35
|
+
const bytes = encodeSignerPayload({
|
|
36
|
+
referencedAssertions: [],
|
|
37
|
+
sigType: "cawg.x509.cose",
|
|
38
|
+
roles,
|
|
39
|
+
});
|
|
40
|
+
expect(toHex(bytes)).toBe("a2757265666572656e6365645f617373657274696f6e7380687369675f747970656e636177672e783530392e636f7365");
|
|
41
|
+
});
|
|
42
|
+
it("accepts explicit undefined roles and rejects null roles", () => {
|
|
43
|
+
const base = { referencedAssertions: [], sigType: "test" };
|
|
44
|
+
expect(toHex(encodeSignerPayload({ ...base, roles: undefined }))).toBe(toHex(encodeSignerPayload(base)));
|
|
45
|
+
expect(() => encodeSignerPayload({ ...base, roles: null })).toThrow();
|
|
46
|
+
});
|
|
47
|
+
it.each([
|
|
48
|
+
[0, "40"],
|
|
49
|
+
[1, "41"],
|
|
50
|
+
[23, "57"],
|
|
51
|
+
[24, "5818"],
|
|
52
|
+
[255, "58ff"],
|
|
53
|
+
[256, "590100"],
|
|
54
|
+
[65535, "59ffff"],
|
|
55
|
+
[65536, "5a00010000"],
|
|
56
|
+
])("encodes a %i-byte hash with the correct header and respects typed array offsets", (length, header) => {
|
|
57
|
+
const backing = new Uint8Array(length + 4).fill(255);
|
|
58
|
+
const hash = backing.subarray(2, length + 2);
|
|
59
|
+
hash.fill(128);
|
|
60
|
+
const bytes = encodeSignerPayload({
|
|
61
|
+
referencedAssertions: [{ url: "a", hash }],
|
|
62
|
+
sigType: "test",
|
|
63
|
+
});
|
|
64
|
+
expect(toHex(bytes)).toBe("a2757265666572656e6365645f617373657274696f6e7381a26375726c61616468617368" +
|
|
65
|
+
header +
|
|
66
|
+
"80".repeat(length) +
|
|
67
|
+
"687369675f747970656474657374");
|
|
68
|
+
expect(backing[0]).toBe(255);
|
|
69
|
+
});
|
|
70
|
+
it("accepts a Node Buffer hash", () => {
|
|
71
|
+
const payload = {
|
|
72
|
+
referencedAssertions: [{ url: "a", hash: Buffer.from([1, 2]) }],
|
|
73
|
+
sigType: "test",
|
|
74
|
+
};
|
|
75
|
+
expect(encodeSignerPayload(payload)).toEqual(encodeSignerPayload({
|
|
76
|
+
...payload,
|
|
77
|
+
referencedAssertions: [{ url: "a", hash: Uint8Array.of(1, 2) }],
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
it("rejects malformed payloads instead of encoding a partial value", () => {
|
|
81
|
+
expect(() => encodeSignerPayload({ sigType: "test" })).toThrow();
|
|
82
|
+
expect(() => encodeSignerPayload({ referencedAssertions: [] })).toThrow();
|
|
83
|
+
expect(() => encodeSignerPayload({
|
|
84
|
+
referencedAssertions: [{ url: "a", hash: "not bytes" }],
|
|
85
|
+
sigType: "test",
|
|
86
|
+
})).toThrow();
|
|
87
|
+
});
|
|
88
|
+
describe("input contract", () => {
|
|
89
|
+
// Keep these cases aligned with c2pa-web's signer.spec.ts. The JS-to-Rust
|
|
90
|
+
// adapters differ even though both bindings use the same Rust serializer.
|
|
91
|
+
const hash = Uint8Array.of(1, 2);
|
|
92
|
+
const uri = { url: "a", hash };
|
|
93
|
+
const payload = { referencedAssertions: [uri], sigType: "test" };
|
|
94
|
+
const rejected = [
|
|
95
|
+
["an undefined payload", undefined],
|
|
96
|
+
["a null payload", null],
|
|
97
|
+
["missing referencedAssertions", { sigType: "test" }],
|
|
98
|
+
["missing sigType", { referencedAssertions: [uri] }],
|
|
99
|
+
[
|
|
100
|
+
"snake_case referenced_assertions",
|
|
101
|
+
{ referenced_assertions: [uri], sigType: "test" },
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"snake_case sig_type",
|
|
105
|
+
{ referencedAssertions: [uri], sig_type: "test" },
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
"case-mismatched SigType",
|
|
109
|
+
{ referencedAssertions: [uri], SigType: "test" },
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"non-array referencedAssertions",
|
|
113
|
+
{ ...payload, referencedAssertions: {} },
|
|
114
|
+
],
|
|
115
|
+
["a non-string sigType", { ...payload, sigType: 42 }],
|
|
116
|
+
["a null assertion", { ...payload, referencedAssertions: [null] }],
|
|
117
|
+
["a missing url", { ...payload, referencedAssertions: [{ hash }] }],
|
|
118
|
+
[
|
|
119
|
+
"case-mismatched Url",
|
|
120
|
+
{ ...payload, referencedAssertions: [{ Url: "a", hash }] },
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"a non-string url",
|
|
124
|
+
{ ...payload, referencedAssertions: [{ ...uri, url: 42 }] },
|
|
125
|
+
],
|
|
126
|
+
["a missing hash", { ...payload, referencedAssertions: [{ url: "a" }] }],
|
|
127
|
+
[
|
|
128
|
+
"case-mismatched Hash",
|
|
129
|
+
{ ...payload, referencedAssertions: [{ url: "a", Hash: hash }] },
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"a string hash",
|
|
133
|
+
{ ...payload, referencedAssertions: [{ ...uri, hash: "not bytes" }] },
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
"a non-string alg",
|
|
137
|
+
{ ...payload, referencedAssertions: [{ ...uri, alg: 42 }] },
|
|
138
|
+
],
|
|
139
|
+
["null roles", { ...payload, roles: null }],
|
|
140
|
+
["non-array roles", { ...payload, roles: "creator" }],
|
|
141
|
+
["a non-string role", { ...payload, roles: [42] }],
|
|
142
|
+
];
|
|
143
|
+
it.each(rejected)("rejects %s", (_name, input) => {
|
|
144
|
+
expect(() => encodeSignerPayload(input)).toThrow();
|
|
145
|
+
});
|
|
146
|
+
const ignored = [
|
|
147
|
+
["extra payload properties", { ...payload, extra: { version: 1 } }],
|
|
148
|
+
[
|
|
149
|
+
"wire-format field names alongside camelCase fields",
|
|
150
|
+
{
|
|
151
|
+
...payload,
|
|
152
|
+
referenced_assertions: [],
|
|
153
|
+
sig_type: "ignored",
|
|
154
|
+
role: ["ignored"],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
"extra assertion properties",
|
|
159
|
+
{ ...payload, referencedAssertions: [{ ...uri, extra: true }] },
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"case-mismatched optional Roles and Alg",
|
|
163
|
+
{
|
|
164
|
+
...payload,
|
|
165
|
+
Roles: ["ignored"],
|
|
166
|
+
referencedAssertions: [{ ...uri, Alg: "ignored" }],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
];
|
|
170
|
+
it.each(ignored)("ignores %s", (_name, input) => {
|
|
171
|
+
expect(encodeSignerPayload(input)).toEqual(encodeSignerPayload(payload));
|
|
172
|
+
});
|
|
173
|
+
it("ignores an unknown function property without cloning the payload", () => {
|
|
174
|
+
expect(encodeSignerPayload({
|
|
175
|
+
...payload,
|
|
176
|
+
extra: () => undefined,
|
|
177
|
+
})).toEqual(encodeSignerPayload(payload));
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
package/dist/assetSize.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// specific language governing permissions and limitations under
|
|
11
11
|
// each license.
|
|
12
12
|
import fs from "fs-extra";
|
|
13
|
-
import { validateAssetSize } from "@contentauth/c2pa-utilities";
|
|
13
|
+
import { resolveConfiguredMaxSizeInBytes, validateAssetSize, } from "@contentauth/c2pa-utilities";
|
|
14
14
|
// c2pa-node runs server-side, so it can reasonably support larger assets than c2pa-web,
|
|
15
15
|
// and may be less resource-constrained in comparison.
|
|
16
16
|
export const MAX_SIZE_IN_BYTES = 10 * 10 ** 9; // 10 GB
|
|
@@ -22,14 +22,20 @@ export const MAX_SIZE_IN_BYTES = 10 * 10 ** 9; // 10 GB
|
|
|
22
22
|
* so the memory cost isn't prevented, only reader construction is. Prefer `path`
|
|
23
23
|
* for large or untrusted assets.
|
|
24
24
|
*
|
|
25
|
+
* @param asset The asset to validate.
|
|
26
|
+
* @param sdkConfig SDK config from a `Context`. A missing `maxSizeInBytes` falls back
|
|
27
|
+
* to {@link MAX_SIZE_IN_BYTES}.
|
|
28
|
+
*
|
|
29
|
+
* @throws {RangeError} If `maxSizeInBytes` isn't a finite, positive number.
|
|
25
30
|
* @throws Error if reading the `FileAsset` fails.
|
|
26
31
|
* @throws {AssetTooLargeError} If `sizeInBytes` exceeds the resolved limit.
|
|
27
32
|
*/
|
|
28
|
-
export async function validateSourceAssetSize(asset) {
|
|
33
|
+
export async function validateSourceAssetSize(asset, sdkConfig) {
|
|
34
|
+
const maxSizeInBytes = resolveConfiguredMaxSizeInBytes(sdkConfig, MAX_SIZE_IN_BYTES);
|
|
29
35
|
if ("buffer" in asset) {
|
|
30
|
-
validateAssetSize(asset.buffer.length,
|
|
36
|
+
validateAssetSize(asset.buffer.length, maxSizeInBytes);
|
|
31
37
|
return;
|
|
32
38
|
}
|
|
33
39
|
const { size } = await fs.stat(asset.path);
|
|
34
|
-
validateAssetSize(size,
|
|
40
|
+
validateAssetSize(size, maxSizeInBytes);
|
|
35
41
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright 2026 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 fs from "fs-extra";
|
|
13
|
+
import * as os from "os";
|
|
14
|
+
import * as path from "path";
|
|
15
|
+
import { AssetTooLargeError } from "@contentauth/c2pa-utilities";
|
|
16
|
+
import { MAX_SIZE_IN_BYTES, validateSourceAssetSize } from "./assetSize.js";
|
|
17
|
+
describe("validateSourceAssetSize", () => {
|
|
18
|
+
let tempDir;
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "c2pa-asset-size-test-"));
|
|
21
|
+
});
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await fs.remove(tempDir);
|
|
24
|
+
});
|
|
25
|
+
async function createFile(sizeInBytes) {
|
|
26
|
+
const filePath = path.join(tempDir, "asset.bin");
|
|
27
|
+
await fs.ensureFile(filePath);
|
|
28
|
+
await fs.truncate(filePath, sizeInBytes);
|
|
29
|
+
return filePath;
|
|
30
|
+
}
|
|
31
|
+
it("accepts a buffer within the default limit", async () => {
|
|
32
|
+
await expect(validateSourceAssetSize({ buffer: Buffer.alloc(10), mimeType: "image/jpeg" })).resolves.toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
it("accepts a file within the default limit", async () => {
|
|
35
|
+
const filePath = await createFile(10);
|
|
36
|
+
await expect(validateSourceAssetSize({ path: filePath })).resolves.toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
it("rejects a file over the default limit", async () => {
|
|
39
|
+
const filePath = await createFile(MAX_SIZE_IN_BYTES + 1);
|
|
40
|
+
await expect(validateSourceAssetSize({ path: filePath })).rejects.toThrow(AssetTooLargeError);
|
|
41
|
+
});
|
|
42
|
+
it("accepts a file over the default limit when a higher maxSizeInBytes is given", async () => {
|
|
43
|
+
const filePath = await createFile(MAX_SIZE_IN_BYTES + 1);
|
|
44
|
+
await expect(validateSourceAssetSize({ path: filePath }, { maxSizeInBytes: MAX_SIZE_IN_BYTES + 2 })).resolves.toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
it("rejects a buffer over a lower maxSizeInBytes", async () => {
|
|
47
|
+
await expect(validateSourceAssetSize({ buffer: Buffer.alloc(10), mimeType: "image/jpeg" }, { maxSizeInBytes: 9 })).rejects.toThrow(AssetTooLargeError);
|
|
48
|
+
});
|
|
49
|
+
it("accepts a buffer exactly at maxSizeInBytes", async () => {
|
|
50
|
+
await expect(validateSourceAssetSize({ buffer: Buffer.alloc(10), mimeType: "image/jpeg" }, { maxSizeInBytes: 10 })).resolves.toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
it.each([0, -1, Number.NaN, Number.POSITIVE_INFINITY])("throws a RangeError for an invalid maxSizeInBytes of %s", async (maxSizeInBytes) => {
|
|
53
|
+
await expect(validateSourceAssetSize({ buffer: Buffer.alloc(10), mimeType: "image/jpeg" }, { maxSizeInBytes })).rejects.toThrow(RangeError);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { Builder } from "./Builder.js";
|
|
7
7
|
export { Reader } from "./Reader.js";
|
|
8
8
|
export { LocalSigner, CallbackSigner } from "./Signer.js";
|
|
9
|
-
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion.js";
|
|
9
|
+
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, encodeSignerPayload, } from "./IdentityAssertion.js";
|
|
10
10
|
export { Trustmark } from "./Trustmark.js";
|
|
11
11
|
export { isActionsAssertion } from "./assertions.js";
|
|
12
12
|
export { loadSettingsFromFile } from "./Settings.js";
|
package/dist/index.node
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/index.node
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 52232544 bytes
|
|
4
|
+
sha256: 700dc336e16341cfabe26173ab8611648a599c33b8ad163602f7c749e7da4191
|
package/dist/types/Builder.d.ts
CHANGED
|
@@ -14,8 +14,7 @@ export declare class Builder implements BuilderInterface {
|
|
|
14
14
|
* Create a Builder with a minimal manifest definition, configured by a `Context`.
|
|
15
15
|
* Prefer this over the deprecated {@link Builder.new}.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* resolution at construction time.
|
|
17
|
+
* Resolves trust-anchor URLs in the Context before constructing the Builder.
|
|
19
18
|
*
|
|
20
19
|
* @param context A `Context` object containing configuration settings for this Builder.
|
|
21
20
|
* Defaults to an empty `Context` using default settings if one is not provided.
|
|
@@ -31,8 +30,7 @@ export declare class Builder implements BuilderInterface {
|
|
|
31
30
|
* Create a Builder from a manifest definition, configured by a `Context`. Prefer this over
|
|
32
31
|
* the deprecated {@link Builder.withJson}.
|
|
33
32
|
*
|
|
34
|
-
*
|
|
35
|
-
* to resolve trust anchors at construction time.
|
|
33
|
+
* Resolves trust-anchor URLs in the Context before constructing the Builder.
|
|
36
34
|
*
|
|
37
35
|
* @param json The manifest JSON.
|
|
38
36
|
* @param context A `Context` object containing configuration settings for this Builder.
|
|
@@ -59,7 +57,7 @@ export declare class Builder implements BuilderInterface {
|
|
|
59
57
|
signConfigAsync(callback: (data: Buffer) => Promise<Buffer>, signerConfig: JsCallbackSignerConfig, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
|
|
60
58
|
signAsync(signer: CallbackSignerInterface | IdentityAssertionSignerInterface, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
|
|
61
59
|
getManifestDefinition(): Manifest;
|
|
62
|
-
updateManifestProperty(property: string, value: ClaimVersion): void;
|
|
60
|
+
updateManifestProperty(property: string, value: string | ClaimVersion): void;
|
|
63
61
|
addRedaction(uri: string, reason: C2paReason): void;
|
|
64
62
|
filterActions(keep: (action: Action) => boolean): void;
|
|
65
63
|
filterIngredients(rescue: (ingredient: Ingredient, provenance: ManifestStore | null) => boolean): void;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
import type { CallbackCredentialHolderInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface, NeonCallbackCredentialHolderHandle, NeonIdentityAssertionSignerHandle, NeonIdentityAssertionBuilderHandle, SignerPayload, NeonCallbackSignerHandle } from "./types.d.ts";
|
|
1
|
+
import type { CallbackCredentialHolderInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface, NeonCallbackCredentialHolderHandle, NeonIdentityAssertionSignerHandle, NeonIdentityAssertionBuilderHandle, SignerPayload, SignerPayloadInput, NeonCallbackSignerHandle } from "./types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Encode a CAWG SignerPayload using c2pa_cbor. Hashes become CBOR byte strings;
|
|
4
|
+
* the wire keys are referenced_assertions, sig_type, and (when nonempty) role.
|
|
5
|
+
*
|
|
6
|
+
* Input names are case-sensitive: referencedAssertions, sigType, roles, and each
|
|
7
|
+
* reference's url, hash, and alg. Wire-format names are not aliases. Missing or
|
|
8
|
+
* incorrectly cased required fields are rejected; unknown data properties are
|
|
9
|
+
* ignored, including incorrectly cased optional fields. Omitted, undefined, or
|
|
10
|
+
* empty roles are omitted on the wire; null roles are rejected.
|
|
11
|
+
*
|
|
12
|
+
* Use plain data objects with Uint8Array hashes for portability between bindings
|
|
13
|
+
* (Node Buffer hashes are also supported here). Validation failures throw
|
|
14
|
+
* synchronously. The Web counterpart rejects its Promise and additionally
|
|
15
|
+
* requires the entire payload, including unknown properties, to be
|
|
16
|
+
* structured-cloneable: an unknown function property is ignored here but cannot
|
|
17
|
+
* be sent to the Web worker. Error types and messages are binding-specific.
|
|
18
|
+
*/
|
|
19
|
+
export declare function encodeSignerPayload(payload: SignerPayloadInput): Uint8Array;
|
|
2
20
|
export declare class IdentityAssertionBuilder implements IdentityAssertionBuilderInterface {
|
|
3
21
|
private _builder;
|
|
4
22
|
constructor(_builder: NeonIdentityAssertionBuilderHandle);
|
package/dist/types/Settings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "@contentauth/c2pa-utilities";
|
|
1
|
+
import { Context, type SdkConfig } from "@contentauth/c2pa-utilities";
|
|
2
2
|
import type { C2paSettings } from "./types.d.ts";
|
|
3
3
|
/**
|
|
4
4
|
* This file contains only Settings functions that are unique to the Node SDK.
|
|
@@ -13,11 +13,21 @@ import type { C2paSettings } from "./types.d.ts";
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function loadSettingsFromFile(filePath: string): Promise<string>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* a JSON string that can be passed into the native library.
|
|
16
|
+
* Reads the SDK config out of a settings argument.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* Only a `Context` carries an SDK config so the deprecated raw `C2paSettings` forms always
|
|
19
|
+
* resolve to `undefined`, leaving this package's defaults in place.
|
|
20
|
+
*
|
|
21
|
+
* @param settingsOrContext A `Context`, or (@deprecated) a raw `C2paSettings` string/object.
|
|
22
|
+
* @returns The `Context`'s SDK config, or `undefined` if there is none.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveSdkConfig(settingsOrContext: C2paSettings | Context | null | undefined): SdkConfig | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves Context settings, including any trust-anchor URLs, before passing them to the native
|
|
27
|
+
* library. Deprecated raw settings retain their existing pass-through behavior.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveSettingsForNeon(settingsOrContext: C2paSettings | Context | null | undefined): Promise<string | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Resolves deprecated raw settings for the synchronous Builder factories.
|
|
22
32
|
*/
|
|
23
|
-
export declare function
|
|
33
|
+
export declare function resolveRawSettingsForNeon(settings: C2paSettings | null | undefined): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SdkConfig } from "@contentauth/c2pa-utilities";
|
|
1
2
|
import type { SourceAsset } from "./types.d.ts";
|
|
2
3
|
export declare const MAX_SIZE_IN_BYTES: number;
|
|
3
4
|
/**
|
|
@@ -8,7 +9,12 @@ export declare const MAX_SIZE_IN_BYTES: number;
|
|
|
8
9
|
* so the memory cost isn't prevented, only reader construction is. Prefer `path`
|
|
9
10
|
* for large or untrusted assets.
|
|
10
11
|
*
|
|
12
|
+
* @param asset The asset to validate.
|
|
13
|
+
* @param sdkConfig SDK config from a `Context`. A missing `maxSizeInBytes` falls back
|
|
14
|
+
* to {@link MAX_SIZE_IN_BYTES}.
|
|
15
|
+
*
|
|
16
|
+
* @throws {RangeError} If `maxSizeInBytes` isn't a finite, positive number.
|
|
11
17
|
* @throws Error if reading the `FileAsset` fails.
|
|
12
18
|
* @throws {AssetTooLargeError} If `sizeInBytes` exceeds the resolved limit.
|
|
13
19
|
*/
|
|
14
|
-
export declare function validateSourceAssetSize(asset: SourceAsset): Promise<void>;
|
|
20
|
+
export declare function validateSourceAssetSize(asset: SourceAsset, sdkConfig?: SdkConfig): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type * from "./types.d.ts";
|
|
|
2
2
|
export { Builder } from "./Builder.js";
|
|
3
3
|
export { Reader } from "./Reader.js";
|
|
4
4
|
export { LocalSigner, CallbackSigner } from "./Signer.js";
|
|
5
|
-
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion.js";
|
|
5
|
+
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, encodeSignerPayload, } from "./IdentityAssertion.js";
|
|
6
6
|
export { Trustmark } from "./Trustmark.js";
|
|
7
7
|
export { isActionsAssertion } from "./assertions.js";
|
|
8
8
|
export { loadSettingsFromFile } from "./Settings.js";
|
package/dist/types/types.d.ts
CHANGED
|
@@ -183,6 +183,11 @@ export interface SignerPayload {
|
|
|
183
183
|
roles: string[];
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
/** Input to `encodeSignerPayload`; absent or empty roles are omitted. */
|
|
187
|
+
export type SignerPayloadInput = Omit<SignerPayload, "roles"> & {
|
|
188
|
+
roles?: string[];
|
|
189
|
+
};
|
|
190
|
+
|
|
186
191
|
export interface HashedUri {
|
|
187
192
|
url: string;
|
|
188
193
|
hash: Uint8Array;
|
|
@@ -332,8 +337,8 @@ export interface BuilderInterface {
|
|
|
332
337
|
getManifestDefinition(): Manifest;
|
|
333
338
|
|
|
334
339
|
/**
|
|
335
|
-
* Update a
|
|
336
|
-
*
|
|
340
|
+
* Update a property of the manifest. Throws for an unsupported property or type.
|
|
341
|
+
* Calling while a signAsync is pending hangs the process: it blocks the thread the signer callback needs.
|
|
337
342
|
*/
|
|
338
343
|
updateManifestProperty(property: string, value: string | ClaimVersion): void;
|
|
339
344
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "git+https://github.com/contentauth/c2pa-js.git",
|
|
6
6
|
"directory": "packages/c2pa-node"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.10.0",
|
|
9
9
|
"description": "Node.js bindings for C2PA",
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"type": "module",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"pkg-dir": "^8.0.0",
|
|
65
65
|
"pretty-bytes": "^6.1.1",
|
|
66
66
|
"unzipper": "^0.10.14",
|
|
67
|
-
"@contentauth/c2pa-types": "0.7.
|
|
68
|
-
"@contentauth/c2pa-utilities": "0.
|
|
67
|
+
"@contentauth/c2pa-types": "0.7.8",
|
|
68
|
+
"@contentauth/c2pa-utilities": "0.4.0"
|
|
69
69
|
},
|
|
70
70
|
"nx": {
|
|
71
71
|
"tags": [
|
package/src/lib.rs
CHANGED
|
@@ -166,6 +166,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
|
166
166
|
)?;
|
|
167
167
|
|
|
168
168
|
// Identity Assertions
|
|
169
|
+
cx.export_function(
|
|
170
|
+
"encodeSignerPayload",
|
|
171
|
+
neon_credential_holder::encode_signer_payload,
|
|
172
|
+
)?;
|
|
169
173
|
cx.export_function(
|
|
170
174
|
"identitySignerNew",
|
|
171
175
|
neon_identity_assertion_signer::NeonIdentityAssertionSigner::new,
|
|
@@ -32,7 +32,7 @@ struct JsSignerPayload {
|
|
|
32
32
|
referenced_assertions: Vec<JsHashedUri>,
|
|
33
33
|
sig_type: String,
|
|
34
34
|
#[serde(default)]
|
|
35
|
-
roles: Vec<String
|
|
35
|
+
roles: Option<Vec<String>>,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
#[derive(Deserialize, Serialize)]
|
|
@@ -58,7 +58,7 @@ impl From<&SignerPayload> for JsSignerPayload {
|
|
|
58
58
|
})
|
|
59
59
|
.collect(),
|
|
60
60
|
sig_type: payload.sig_type.clone(),
|
|
61
|
-
roles: payload.roles.clone(),
|
|
61
|
+
roles: Some(payload.roles.clone()),
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -72,11 +72,33 @@ impl From<JsSignerPayload> for SignerPayload {
|
|
|
72
72
|
.map(|uri| HashedUri::new(uri.url, uri.alg, &uri.hash))
|
|
73
73
|
.collect(),
|
|
74
74
|
sig_type: payload.sig_type,
|
|
75
|
-
roles: payload.roles,
|
|
75
|
+
roles: payload.roles.unwrap_or_default(),
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/// Encode the JavaScript payload using the canonical CAWG wire representation.
|
|
81
|
+
pub fn encode_signer_payload(mut cx: FunctionContext) -> JsResult<JsUint8Array> {
|
|
82
|
+
let value = cx.argument::<JsValue>(0)?;
|
|
83
|
+
if let Ok(object) = value.downcast::<JsObject, _>(&mut cx) {
|
|
84
|
+
let roles = object.get_value(&mut cx, "roles")?;
|
|
85
|
+
if roles.is_a::<JsNull, _>(&mut cx) {
|
|
86
|
+
return cx.throw_type_error("roles must be an array of strings or undefined");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let payload: JsSignerPayload = match neon_serde4::from_value(&mut cx, value) {
|
|
90
|
+
Ok(payload) => payload,
|
|
91
|
+
Err(neon_serde4::errors::Error::Js { throw }) => return Err(throw),
|
|
92
|
+
Err(err) => return cx.throw_type_error(err.to_string()),
|
|
93
|
+
};
|
|
94
|
+
let payload: SignerPayload = payload.into();
|
|
95
|
+
let mut bytes = Vec::new();
|
|
96
|
+
if let Err(err) = c2pa_cbor::to_writer(&mut bytes, &payload) {
|
|
97
|
+
return cx.throw_error(err.to_string());
|
|
98
|
+
}
|
|
99
|
+
JsUint8Array::from_slice(&mut cx, &bytes)
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
/// NeonCallbackCredentialHolder allows JS to asynchronously sign a SignerPayload.
|
|
81
103
|
#[derive(Clone)]
|
|
82
104
|
pub struct NeonCallbackCredentialHolder {
|
|
@@ -106,7 +128,8 @@ impl NeonCallbackCredentialHolder {
|
|
|
106
128
|
let reserve_size = cx.argument::<JsNumber>(0)?.value(&mut cx) as usize;
|
|
107
129
|
let sig_type = cx.argument::<JsString>(1)?.value(&mut cx);
|
|
108
130
|
let callback = cx.argument::<JsFunction>(2)?.root(&mut cx);
|
|
109
|
-
let channel = cx.channel();
|
|
131
|
+
let mut channel = cx.channel();
|
|
132
|
+
channel.unref(&mut cx);
|
|
110
133
|
Ok(cx.boxed(Self::new(
|
|
111
134
|
channel,
|
|
112
135
|
Arc::new(callback),
|
package/src/neon_signer.rs
CHANGED
|
@@ -164,7 +164,8 @@ impl NeonCallbackSigner {
|
|
|
164
164
|
let config_handle = cx.argument::<JsBox<CallbackSignerConfig>>(0)?;
|
|
165
165
|
let config_ref: &CallbackSignerConfig = config_handle.deref();
|
|
166
166
|
let callback = cx.argument::<JsFunction>(1)?.root(&mut cx);
|
|
167
|
-
let channel = cx.channel();
|
|
167
|
+
let mut channel = cx.channel();
|
|
168
|
+
channel.unref(&mut cx);
|
|
168
169
|
Ok(cx.boxed(Self::new(channel, Arc::new(callback), config_ref.clone())))
|
|
169
170
|
}
|
|
170
171
|
|
|
@@ -319,6 +320,17 @@ impl AsyncSigner for NeonCallbackSigner {
|
|
|
319
320
|
self.config.reserve_size
|
|
320
321
|
}
|
|
321
322
|
|
|
323
|
+
// Since c2pa-rs 0.91, async signing reaches the TSA only through these
|
|
324
|
+
// `AsyncSigner` methods; without them the defaults return `None` and
|
|
325
|
+
// `tsaUrl` / `tsaHeaders` are silently ignored.
|
|
326
|
+
fn time_authority_url(&self) -> Option<String> {
|
|
327
|
+
self.config.tsa_url.clone()
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
fn timestamp_request_headers(&self) -> Option<Vec<(String, String)>> {
|
|
331
|
+
self.config.tsa_headers.clone()
|
|
332
|
+
}
|
|
333
|
+
|
|
322
334
|
fn direct_cose_handling(&self) -> bool {
|
|
323
335
|
self.config.direct_cose_handling
|
|
324
336
|
}
|