@contentauth/c2pa-node 0.5.3 → 0.5.4
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/Cargo.lock +2 -2
- package/Cargo.toml +1 -1
- package/dist/Settings.js +18 -34
- package/dist/Settings.spec.js +34 -39
- package/dist/index.node +0 -0
- package/dist/types/Settings.d.ts +2 -1
- package/dist/types/types.d.ts +11 -32
- package/package.json +1 -1
package/Cargo.lock
CHANGED
|
@@ -495,9 +495,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
|
|
495
495
|
|
|
496
496
|
[[package]]
|
|
497
497
|
name = "c2pa"
|
|
498
|
-
version = "0.
|
|
498
|
+
version = "0.78.4"
|
|
499
499
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
500
|
-
checksum = "
|
|
500
|
+
checksum = "7cae87cdb2ae6070bf628f889d745797071b194ecb31c711b452617308075c5e"
|
|
501
501
|
dependencies = [
|
|
502
502
|
"asn1-rs",
|
|
503
503
|
"async-generic",
|
package/Cargo.toml
CHANGED
|
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
|
|
|
11
11
|
[dependencies]
|
|
12
12
|
async-trait = "0.1.77"
|
|
13
13
|
ciborium = "0.2.2"
|
|
14
|
-
c2pa = { version = "0.
|
|
14
|
+
c2pa = { version = "0.78.4", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto", "default_http"] }
|
|
15
15
|
futures = "0.3"
|
|
16
16
|
image = "0.25.6"
|
|
17
17
|
neon = { version = "1.0.0", default-features = false, features = [
|
package/dist/Settings.js
CHANGED
|
@@ -20,21 +20,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
// each license.
|
|
21
21
|
import * as fs from "fs-extra";
|
|
22
22
|
import fetch from "node-fetch";
|
|
23
|
+
function snakeCaseify(object) {
|
|
24
|
+
return Object.entries(object).reduce((result, [key, val]) => {
|
|
25
|
+
result[snakeCase(key)] =
|
|
26
|
+
typeof val === "object" && val !== null ? snakeCaseify(val) : val;
|
|
27
|
+
return result;
|
|
28
|
+
}, {});
|
|
29
|
+
}
|
|
30
|
+
function snakeCase(str) {
|
|
31
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
32
|
+
}
|
|
23
33
|
/**
|
|
24
34
|
* Create a Settings object with trust configuration.
|
|
25
35
|
* @param trustConfig The trust configuration
|
|
26
36
|
* @returns Settings object that can be passed to Reader/Builder
|
|
27
37
|
*/
|
|
28
38
|
export function createTrustSettings(trustConfig) {
|
|
29
|
-
return {
|
|
30
|
-
trust: {
|
|
31
|
-
verify_trust_list: trustConfig.verifyTrustList,
|
|
32
|
-
user_anchors: trustConfig.userAnchors,
|
|
33
|
-
trust_anchors: trustConfig.trustAnchors,
|
|
34
|
-
trust_config: trustConfig.trustConfig,
|
|
35
|
-
allowed_list: trustConfig.allowedList,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
39
|
+
return { trust: Object.assign({}, trustConfig) };
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Create a settings object with CAWG trust configuration.
|
|
@@ -42,15 +44,7 @@ export function createTrustSettings(trustConfig) {
|
|
|
42
44
|
* @returns Settings object that can be passed to Reader/Builder
|
|
43
45
|
*/
|
|
44
46
|
export function createCawgTrustSettings(trustConfig) {
|
|
45
|
-
return {
|
|
46
|
-
cawg_trust: {
|
|
47
|
-
verify_trust_list: trustConfig.verifyTrustList,
|
|
48
|
-
user_anchors: trustConfig.userAnchors,
|
|
49
|
-
trust_anchors: trustConfig.trustAnchors,
|
|
50
|
-
trust_config: trustConfig.trustConfig,
|
|
51
|
-
allowed_list: trustConfig.allowedList,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
47
|
+
return { cawgTrust: Object.assign({}, trustConfig) };
|
|
54
48
|
}
|
|
55
49
|
/**
|
|
56
50
|
* Create a settings object with verify configuration.
|
|
@@ -58,18 +52,7 @@ export function createCawgTrustSettings(trustConfig) {
|
|
|
58
52
|
* @returns Settings object that can be passed to Reader/Builder
|
|
59
53
|
*/
|
|
60
54
|
export function createVerifySettings(verifyConfig) {
|
|
61
|
-
return {
|
|
62
|
-
verify: {
|
|
63
|
-
verify_after_reading: verifyConfig.verifyAfterReading,
|
|
64
|
-
verify_after_sign: verifyConfig.verifyAfterSign,
|
|
65
|
-
verify_trust: verifyConfig.verifyTrust,
|
|
66
|
-
verify_timestamp_trust: verifyConfig.verifyTimestampTrust,
|
|
67
|
-
ocsp_fetch: verifyConfig.ocspFetch,
|
|
68
|
-
remote_manifest_fetch: verifyConfig.remoteManifestFetch,
|
|
69
|
-
skip_ingredient_conflict_resolution: verifyConfig.skipIngredientConflictResolution,
|
|
70
|
-
strict_v1_validation: verifyConfig.strictV1Validation,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
55
|
+
return { verify: Object.assign({}, verifyConfig) };
|
|
73
56
|
}
|
|
74
57
|
/**
|
|
75
58
|
* Merge multiple settings objects into one.
|
|
@@ -83,8 +66,8 @@ export function mergeSettings(...settings) {
|
|
|
83
66
|
if (setting.trust) {
|
|
84
67
|
merged.trust = Object.assign(Object.assign({}, merged.trust), setting.trust);
|
|
85
68
|
}
|
|
86
|
-
if (setting.
|
|
87
|
-
merged.
|
|
69
|
+
if (setting.cawgTrust) {
|
|
70
|
+
merged.cawgTrust = Object.assign(Object.assign({}, merged.cawgTrust), setting.cawgTrust);
|
|
88
71
|
}
|
|
89
72
|
if (setting.verify) {
|
|
90
73
|
merged.verify = Object.assign(Object.assign({}, merged.verify), setting.verify);
|
|
@@ -97,11 +80,12 @@ export function mergeSettings(...settings) {
|
|
|
97
80
|
}
|
|
98
81
|
/**
|
|
99
82
|
* Convert a settings object to a JSON string.
|
|
83
|
+
* Converts camelCase keys to snake_case to match the c2pa-rs settings format.
|
|
100
84
|
* @param settings The settings object
|
|
101
|
-
* @returns JSON string representation
|
|
85
|
+
* @returns JSON string representation with snake_case keys
|
|
102
86
|
*/
|
|
103
87
|
export function settingsToJson(settings) {
|
|
104
|
-
return JSON.stringify(settings);
|
|
88
|
+
return JSON.stringify(snakeCaseify(settings));
|
|
105
89
|
}
|
|
106
90
|
/**
|
|
107
91
|
* Load settings from a TOML or JSON file.
|
package/dist/Settings.spec.js
CHANGED
|
@@ -31,9 +31,9 @@ describe("Settings", () => {
|
|
|
31
31
|
};
|
|
32
32
|
const settings = createTrustSettings(trustConfig);
|
|
33
33
|
expect(settings.trust).toBeDefined();
|
|
34
|
-
expect((_a = settings.trust) === null || _a === void 0 ? void 0 : _a.
|
|
35
|
-
expect((_b = settings.trust) === null || _b === void 0 ? void 0 : _b.
|
|
36
|
-
expect((_c = settings.trust) === null || _c === void 0 ? void 0 : _c.
|
|
34
|
+
expect((_a = settings.trust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(true);
|
|
35
|
+
expect((_b = settings.trust) === null || _b === void 0 ? void 0 : _b.userAnchors).toBe("test");
|
|
36
|
+
expect((_c = settings.trust) === null || _c === void 0 ? void 0 : _c.allowedList).toBe("allowed");
|
|
37
37
|
});
|
|
38
38
|
it("creates CAWG trust settings", () => {
|
|
39
39
|
var _a, _b;
|
|
@@ -42,9 +42,9 @@ describe("Settings", () => {
|
|
|
42
42
|
trustAnchors: "anchors",
|
|
43
43
|
};
|
|
44
44
|
const settings = createCawgTrustSettings(trustConfig);
|
|
45
|
-
expect(settings.
|
|
46
|
-
expect((_a = settings.
|
|
47
|
-
expect((_b = settings.
|
|
45
|
+
expect(settings.cawgTrust).toBeDefined();
|
|
46
|
+
expect((_a = settings.cawgTrust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(false);
|
|
47
|
+
expect((_b = settings.cawgTrust) === null || _b === void 0 ? void 0 : _b.trustAnchors).toBe("anchors");
|
|
48
48
|
});
|
|
49
49
|
it("creates verify settings", () => {
|
|
50
50
|
var _a, _b, _c, _d;
|
|
@@ -60,10 +60,20 @@ describe("Settings", () => {
|
|
|
60
60
|
};
|
|
61
61
|
const settings = createVerifySettings(verifyConfig);
|
|
62
62
|
expect(settings.verify).toBeDefined();
|
|
63
|
-
expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.
|
|
64
|
-
expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.
|
|
65
|
-
expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.
|
|
66
|
-
expect((_d = settings.verify) === null || _d === void 0 ? void 0 : _d.
|
|
63
|
+
expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(true);
|
|
64
|
+
expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterSign).toBe(false);
|
|
65
|
+
expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.verifyTrust).toBe(true);
|
|
66
|
+
expect((_d = settings.verify) === null || _d === void 0 ? void 0 : _d.ocspFetch).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it("creates verify settings with partial config", () => {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const settings = createVerifySettings({
|
|
71
|
+
verifyAfterReading: false,
|
|
72
|
+
});
|
|
73
|
+
expect(settings.verify).toBeDefined();
|
|
74
|
+
expect((_a = settings.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(false);
|
|
75
|
+
expect((_b = settings.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterSign).toBeUndefined();
|
|
76
|
+
expect((_c = settings.verify) === null || _c === void 0 ? void 0 : _c.verifyTrust).toBeUndefined();
|
|
67
77
|
});
|
|
68
78
|
it("merges multiple settings", () => {
|
|
69
79
|
var _a, _b;
|
|
@@ -84,10 +94,10 @@ describe("Settings", () => {
|
|
|
84
94
|
const merged = mergeSettings(trustSettings, verifySettings);
|
|
85
95
|
expect(merged.trust).toBeDefined();
|
|
86
96
|
expect(merged.verify).toBeDefined();
|
|
87
|
-
expect((_a = merged.trust) === null || _a === void 0 ? void 0 : _a.
|
|
88
|
-
expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.
|
|
97
|
+
expect((_a = merged.trust) === null || _a === void 0 ? void 0 : _a.verifyTrustList).toBe(true);
|
|
98
|
+
expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verifyAfterReading).toBe(false);
|
|
89
99
|
});
|
|
90
|
-
it("converts settings to JSON", () => {
|
|
100
|
+
it("converts settings to JSON with snake_case keys", () => {
|
|
91
101
|
const settings = createVerifySettings({
|
|
92
102
|
verifyAfterReading: true,
|
|
93
103
|
verifyAfterSign: true,
|
|
@@ -101,22 +111,17 @@ describe("Settings", () => {
|
|
|
101
111
|
const json = settingsToJson(settings);
|
|
102
112
|
expect(json).toContain("verify");
|
|
103
113
|
expect(json).toContain("verify_after_reading");
|
|
104
|
-
// Should be parseable
|
|
114
|
+
// Should be parseable with snake_case keys
|
|
105
115
|
const parsed = JSON.parse(json);
|
|
106
116
|
expect(parsed.verify.verify_after_reading).toBe(true);
|
|
107
117
|
});
|
|
108
118
|
it("does not include undefined values in trust settings JSON", () => {
|
|
109
119
|
const trustConfig = {
|
|
110
120
|
verifyTrustList: true,
|
|
111
|
-
// userAnchors is undefined
|
|
112
|
-
// trustAnchors is undefined
|
|
113
|
-
// trustConfig is undefined
|
|
114
|
-
// allowedList is undefined
|
|
115
121
|
};
|
|
116
122
|
const settings = createTrustSettings(trustConfig);
|
|
117
123
|
const json = settingsToJson(settings);
|
|
118
124
|
const parsed = JSON.parse(json);
|
|
119
|
-
// JSON.stringify automatically excludes undefined values
|
|
120
125
|
expect(parsed.trust.verify_trust_list).toBe(true);
|
|
121
126
|
expect("user_anchors" in parsed.trust).toBe(false);
|
|
122
127
|
expect("trust_anchors" in parsed.trust).toBe(false);
|
|
@@ -126,12 +131,10 @@ describe("Settings", () => {
|
|
|
126
131
|
it("does not include undefined values in CAWG trust settings JSON", () => {
|
|
127
132
|
const trustConfig = {
|
|
128
133
|
verifyTrustList: false,
|
|
129
|
-
// Only verifyTrustList is defined
|
|
130
134
|
};
|
|
131
135
|
const settings = createCawgTrustSettings(trustConfig);
|
|
132
136
|
const json = settingsToJson(settings);
|
|
133
137
|
const parsed = JSON.parse(json);
|
|
134
|
-
// JSON.stringify automatically excludes undefined values
|
|
135
138
|
expect(parsed.cawg_trust.verify_trust_list).toBe(false);
|
|
136
139
|
expect("user_anchors" in parsed.cawg_trust).toBe(false);
|
|
137
140
|
expect("trust_anchors" in parsed.cawg_trust).toBe(false);
|
|
@@ -140,18 +143,10 @@ describe("Settings", () => {
|
|
|
140
143
|
const verifyConfig = {
|
|
141
144
|
verifyAfterReading: true,
|
|
142
145
|
verifyAfterSign: false,
|
|
143
|
-
// Only first two are defined, rest are undefined
|
|
144
|
-
verifyTrust: undefined,
|
|
145
|
-
verifyTimestampTrust: undefined,
|
|
146
|
-
ocspFetch: undefined,
|
|
147
|
-
remoteManifestFetch: undefined,
|
|
148
|
-
skipIngredientConflictResolution: undefined,
|
|
149
|
-
strictV1Validation: undefined,
|
|
150
146
|
};
|
|
151
147
|
const settings = createVerifySettings(verifyConfig);
|
|
152
148
|
const json = settingsToJson(settings);
|
|
153
149
|
const parsed = JSON.parse(json);
|
|
154
|
-
// JSON.stringify automatically excludes undefined values
|
|
155
150
|
expect(parsed.verify.verify_after_reading).toBe(true);
|
|
156
151
|
expect(parsed.verify.verify_after_sign).toBe(false);
|
|
157
152
|
expect("verify_trust" in parsed.verify).toBe(false);
|
|
@@ -162,22 +157,22 @@ describe("Settings", () => {
|
|
|
162
157
|
it("does not include undefined values when merging settings", () => {
|
|
163
158
|
const settings1 = {
|
|
164
159
|
trust: {
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
verifyTrustList: true,
|
|
161
|
+
userAnchors: "test",
|
|
167
162
|
},
|
|
168
163
|
};
|
|
169
164
|
const settings2 = {
|
|
170
165
|
trust: {
|
|
171
|
-
|
|
166
|
+
verifyTrustList: true,
|
|
167
|
+
allowedList: undefined,
|
|
172
168
|
},
|
|
173
169
|
verify: {
|
|
174
|
-
|
|
170
|
+
verifyAfterReading: false,
|
|
175
171
|
},
|
|
176
172
|
};
|
|
177
173
|
const merged = mergeSettings(settings1, settings2);
|
|
178
174
|
const json = settingsToJson(merged);
|
|
179
175
|
const parsed = JSON.parse(json);
|
|
180
|
-
// JSON.stringify automatically excludes undefined values
|
|
181
176
|
expect(parsed.trust.verify_trust_list).toBe(true);
|
|
182
177
|
expect(parsed.trust.user_anchors).toBe("test");
|
|
183
178
|
expect("allowed_list" in parsed.trust).toBe(false);
|
|
@@ -197,14 +192,14 @@ describe("Settings", () => {
|
|
|
197
192
|
});
|
|
198
193
|
const settings2 = {
|
|
199
194
|
verify: {
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
verifyTrust: true,
|
|
196
|
+
ocspFetch: true,
|
|
202
197
|
},
|
|
203
198
|
};
|
|
204
199
|
const merged = mergeSettings(settings1, settings2);
|
|
205
|
-
expect((_a = merged.verify) === null || _a === void 0 ? void 0 : _a.
|
|
206
|
-
expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.
|
|
207
|
-
expect((_c = merged.verify) === null || _c === void 0 ? void 0 : _c.
|
|
200
|
+
expect((_a = merged.verify) === null || _a === void 0 ? void 0 : _a.verifyAfterReading).toBe(true); // from settings1
|
|
201
|
+
expect((_b = merged.verify) === null || _b === void 0 ? void 0 : _b.verifyTrust).toBe(true); // overridden by settings2
|
|
202
|
+
expect((_c = merged.verify) === null || _c === void 0 ? void 0 : _c.ocspFetch).toBe(true); // overridden by settings2
|
|
208
203
|
});
|
|
209
204
|
describe("loadSettingsFromFile", () => {
|
|
210
205
|
let tempDir;
|
package/dist/index.node
CHANGED
|
Binary file
|
package/dist/types/Settings.d.ts
CHANGED
|
@@ -26,8 +26,9 @@ export declare function createVerifySettings(verifyConfig: VerifyConfig): Settin
|
|
|
26
26
|
export declare function mergeSettings(...settings: SettingsContext[]): SettingsContext;
|
|
27
27
|
/**
|
|
28
28
|
* Convert a settings object to a JSON string.
|
|
29
|
+
* Converts camelCase keys to snake_case to match the c2pa-rs settings format.
|
|
29
30
|
* @param settings The settings object
|
|
30
|
-
* @returns JSON string representation
|
|
31
|
+
* @returns JSON string representation with snake_case keys
|
|
31
32
|
*/
|
|
32
33
|
export declare function settingsToJson(settings: SettingsContext): string;
|
|
33
34
|
/**
|
package/dist/types/types.d.ts
CHANGED
|
@@ -453,21 +453,21 @@ export interface TrustConfig {
|
|
|
453
453
|
*/
|
|
454
454
|
export interface VerifyConfig {
|
|
455
455
|
/** Whether to verify after reading a manifest */
|
|
456
|
-
verifyAfterReading
|
|
456
|
+
verifyAfterReading?: boolean;
|
|
457
457
|
/** Whether to verify after signing a manifest */
|
|
458
|
-
verifyAfterSign
|
|
458
|
+
verifyAfterSign?: boolean;
|
|
459
459
|
/** Whether to verify trust during validation */
|
|
460
|
-
verifyTrust
|
|
460
|
+
verifyTrust?: boolean;
|
|
461
461
|
/** Whether to verify timestamp trust */
|
|
462
|
-
verifyTimestampTrust
|
|
462
|
+
verifyTimestampTrust?: boolean;
|
|
463
463
|
/** Whether to fetch OCSP responses */
|
|
464
|
-
ocspFetch
|
|
464
|
+
ocspFetch?: boolean;
|
|
465
465
|
/** Whether to fetch remote manifests */
|
|
466
|
-
remoteManifestFetch
|
|
466
|
+
remoteManifestFetch?: boolean;
|
|
467
467
|
/** Whether to skip ingredient conflict resolution */
|
|
468
|
-
skipIngredientConflictResolution
|
|
468
|
+
skipIngredientConflictResolution?: boolean;
|
|
469
469
|
/** Whether to use strict v1 validation */
|
|
470
|
-
strictV1Validation
|
|
470
|
+
strictV1Validation?: boolean;
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
/**
|
|
@@ -477,32 +477,11 @@ export interface VerifyConfig {
|
|
|
477
477
|
*/
|
|
478
478
|
export interface SettingsContext {
|
|
479
479
|
/** C2PA trust configuration */
|
|
480
|
-
trust?:
|
|
481
|
-
verify_trust_list?: boolean;
|
|
482
|
-
user_anchors?: string;
|
|
483
|
-
trust_anchors?: string;
|
|
484
|
-
trust_config?: string;
|
|
485
|
-
allowed_list?: string;
|
|
486
|
-
};
|
|
480
|
+
trust?: TrustConfig;
|
|
487
481
|
/** CAWG trust configuration */
|
|
488
|
-
|
|
489
|
-
verify_trust_list?: boolean;
|
|
490
|
-
user_anchors?: string;
|
|
491
|
-
trust_anchors?: string;
|
|
492
|
-
trust_config?: string;
|
|
493
|
-
allowed_list?: string;
|
|
494
|
-
};
|
|
482
|
+
cawgTrust?: TrustConfig;
|
|
495
483
|
/** Verification configuration */
|
|
496
|
-
verify?:
|
|
497
|
-
verify_after_reading?: boolean;
|
|
498
|
-
verify_after_sign?: boolean;
|
|
499
|
-
verify_trust?: boolean;
|
|
500
|
-
verify_timestamp_trust?: boolean;
|
|
501
|
-
ocsp_fetch?: boolean;
|
|
502
|
-
remote_manifest_fetch?: boolean;
|
|
503
|
-
skip_ingredient_conflict_resolution?: boolean;
|
|
504
|
-
strict_v1_validation?: boolean;
|
|
505
|
-
};
|
|
484
|
+
verify?: VerifyConfig;
|
|
506
485
|
/** Builder configuration */
|
|
507
486
|
builder?: {
|
|
508
487
|
thumbnail?: {
|