@contentauth/c2pa-node 0.4.2 → 0.5.1
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 +472 -352
- package/Cargo.toml +1 -1
- package/README.md +120 -24
- package/dist/Builder.js +21 -6
- package/dist/Builder.spec.js +32 -40
- package/dist/Reader.js +6 -4
- package/dist/Reader.spec.js +23 -0
- package/dist/Settings.js +82 -160
- package/dist/Settings.spec.js +257 -285
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +4 -4
- package/dist/types/Reader.d.ts +3 -3
- package/dist/types/Settings.d.ts +30 -54
- package/dist/types/types.d.ts +47 -0
- package/package.json +2 -2
- package/src/lib.rs +0 -19
- package/src/neon_builder.rs +42 -25
- package/src/neon_reader.rs +30 -4
- package/src/runtime.rs +4 -31
- package/src/utils.rs +41 -1
- package/src/settings.rs +0 -520
package/dist/Settings.js
CHANGED
|
@@ -19,190 +19,112 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
19
|
// specific language governing permissions and limitations under
|
|
20
20
|
// each license.
|
|
21
21
|
import * as fs from "fs-extra";
|
|
22
|
-
import path from "path";
|
|
23
22
|
import fetch from "node-fetch";
|
|
24
|
-
import { getNeonBinary } from "./binary.js";
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
24
|
+
* Create a Settings object with trust configuration.
|
|
25
|
+
* @param trustConfig The trust configuration
|
|
26
|
+
* @returns Settings object that can be passed to Reader/Builder
|
|
28
27
|
*/
|
|
29
|
-
export function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Load settings from a TOML or JSON file path and apply them globally.
|
|
41
|
-
* The file format is determined by the file extension (.toml for TOML, otherwise JSON).
|
|
42
|
-
* @param filePath The path to the settings file
|
|
43
|
-
*/
|
|
44
|
-
export function loadSettingsFromFile(filePath) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
47
|
-
const content = yield fs.readFile(filePath, "utf8");
|
|
48
|
-
if (ext === ".toml") {
|
|
49
|
-
loadC2paSettingsToml(content);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Assume JSON (or JSON5 that is valid JSON) otherwise
|
|
53
|
-
// If needed, callers can ensure the content is valid JSON.
|
|
54
|
-
loadC2paSettings(content);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Load settings from a URL and apply them globally.
|
|
59
|
-
* The format is determined by the content-type header or file extension (.toml for TOML, otherwise JSON).
|
|
60
|
-
* @param url The URL to fetch the settings from
|
|
61
|
-
*/
|
|
62
|
-
export function loadSettingsFromUrl(url) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const res = yield fetch(url);
|
|
65
|
-
if (!res.ok) {
|
|
66
|
-
throw new Error(`Failed to fetch settings from URL: ${res.status} ${res.statusText}`);
|
|
67
|
-
}
|
|
68
|
-
const contentType = res.headers.get("content-type") || "";
|
|
69
|
-
const text = yield res.text();
|
|
70
|
-
const isToml = contentType.includes("toml") || url.toLowerCase().endsWith(".toml");
|
|
71
|
-
if (isToml) {
|
|
72
|
-
loadC2paSettingsToml(text);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// Treat as JSON by default
|
|
76
|
-
loadC2paSettings(text);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get the current settings as a JSON string.
|
|
81
|
-
* @returns The JSON representation of the current settings
|
|
82
|
-
*/
|
|
83
|
-
export function getSettingsJson() {
|
|
84
|
-
return getNeonBinary().getSettingsJson();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Load trust configuration into the main trust settings.
|
|
88
|
-
* @param trustConfig The trust configuration object
|
|
89
|
-
*/
|
|
90
|
-
export function loadTrustConfig(trustConfig) {
|
|
91
|
-
var _a, _b, _c, _d;
|
|
92
|
-
// Convert settings to snake_case for the neon Rust code.
|
|
93
|
-
// Explicitly set undefined fields to null to ensure they are cleared
|
|
94
|
-
const config = {
|
|
95
|
-
verify_trust_list: trustConfig.verifyTrustList,
|
|
96
|
-
user_anchors: (_a = trustConfig.userAnchors) !== null && _a !== void 0 ? _a : null,
|
|
97
|
-
trust_anchors: (_b = trustConfig.trustAnchors) !== null && _b !== void 0 ? _b : null,
|
|
98
|
-
trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
|
|
99
|
-
allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
|
|
100
|
-
};
|
|
101
|
-
getNeonBinary().loadTrustConfig(JSON.stringify(config));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Load trust configuration into the CAWG trust settings.
|
|
105
|
-
* @param trustConfig The trust configuration object
|
|
106
|
-
*/
|
|
107
|
-
export function loadCawgTrustConfig(trustConfig) {
|
|
108
|
-
var _a, _b, _c, _d;
|
|
109
|
-
// Convert settings to snake_case for the neon Rust code
|
|
110
|
-
// Explicitly set undefined fields to null to ensure they are cleared
|
|
111
|
-
const config = {
|
|
112
|
-
verify_trust_list: trustConfig.verifyTrustList,
|
|
113
|
-
user_anchors: (_a = trustConfig.userAnchors) !== null && _a !== void 0 ? _a : null,
|
|
114
|
-
trust_anchors: (_b = trustConfig.trustAnchors) !== null && _b !== void 0 ? _b : null,
|
|
115
|
-
trust_config: (_c = trustConfig.trustConfig) !== null && _c !== void 0 ? _c : null,
|
|
116
|
-
allowed_list: (_d = trustConfig.allowedList) !== null && _d !== void 0 ? _d : null,
|
|
28
|
+
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
|
+
},
|
|
117
37
|
};
|
|
118
|
-
getNeonBinary().loadCawgTrustConfig(JSON.stringify(config));
|
|
119
38
|
}
|
|
120
39
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
40
|
+
* Create a settings object with CAWG trust configuration.
|
|
41
|
+
* @param trustConfig The CAWG trust configuration
|
|
42
|
+
* @returns Settings object that can be passed to Reader/Builder
|
|
123
43
|
*/
|
|
124
|
-
export function
|
|
125
|
-
var _a, _b, _c, _d;
|
|
126
|
-
const json = getNeonBinary().getTrustConfig();
|
|
127
|
-
const parsed = JSON.parse(json);
|
|
128
|
-
// Convert snake_case to camelCase to match TrustConfig interface
|
|
129
|
-
// Handle undefined values by converting them to null
|
|
44
|
+
export function createCawgTrustSettings(trustConfig) {
|
|
130
45
|
return {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
},
|
|
136
53
|
};
|
|
137
54
|
}
|
|
138
55
|
/**
|
|
139
|
-
*
|
|
140
|
-
* @
|
|
56
|
+
* Create a settings object with verify configuration.
|
|
57
|
+
* @param verifyConfig The verify configuration
|
|
58
|
+
* @returns Settings object that can be passed to Reader/Builder
|
|
141
59
|
*/
|
|
142
|
-
export function
|
|
143
|
-
var _a, _b, _c, _d;
|
|
144
|
-
const json = getNeonBinary().getCawgTrustConfig();
|
|
145
|
-
const parsed = JSON.parse(json);
|
|
146
|
-
// Convert snake_case to camelCase to match TrustConfig interface
|
|
147
|
-
// Handle undefined values by converting them to null
|
|
60
|
+
export function createVerifySettings(verifyConfig) {
|
|
148
61
|
return {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
+
},
|
|
154
72
|
};
|
|
155
73
|
}
|
|
156
74
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
75
|
+
* Merge multiple settings objects into one.
|
|
76
|
+
* Later settings override earlier ones.
|
|
77
|
+
* @param settings Settings objects to merge
|
|
78
|
+
* @returns Merged settings object
|
|
159
79
|
*/
|
|
160
|
-
export function
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
80
|
+
export function mergeSettings(...settings) {
|
|
81
|
+
const merged = {};
|
|
82
|
+
for (const setting of settings) {
|
|
83
|
+
if (setting.trust) {
|
|
84
|
+
merged.trust = Object.assign(Object.assign({}, merged.trust), setting.trust);
|
|
85
|
+
}
|
|
86
|
+
if (setting.cawg_trust) {
|
|
87
|
+
merged.cawg_trust = Object.assign(Object.assign({}, merged.cawg_trust), setting.cawg_trust);
|
|
88
|
+
}
|
|
89
|
+
if (setting.verify) {
|
|
90
|
+
merged.verify = Object.assign(Object.assign({}, merged.verify), setting.verify);
|
|
91
|
+
}
|
|
92
|
+
if (setting.builder) {
|
|
93
|
+
merged.builder = Object.assign(Object.assign({}, merged.builder), setting.builder);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return merged;
|
|
173
97
|
}
|
|
174
98
|
/**
|
|
175
|
-
*
|
|
176
|
-
* @param
|
|
99
|
+
* Convert a settings object to a JSON string.
|
|
100
|
+
* @param settings The settings object
|
|
101
|
+
* @returns JSON string representation
|
|
177
102
|
*/
|
|
178
|
-
export function
|
|
179
|
-
|
|
180
|
-
const updated = Object.assign(Object.assign({}, current), patch);
|
|
181
|
-
loadVerifyConfig(updated);
|
|
103
|
+
export function settingsToJson(settings) {
|
|
104
|
+
return JSON.stringify(settings);
|
|
182
105
|
}
|
|
183
106
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @
|
|
107
|
+
* Load settings from a TOML or JSON file.
|
|
108
|
+
* @param filePath The path to the settings file
|
|
109
|
+
* @returns Settings as a string (TOML or JSON depending on file extension)
|
|
186
110
|
*/
|
|
187
|
-
export function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
verifyAfterReading: parsed.verify_after_reading,
|
|
193
|
-
verifyAfterSign: parsed.verify_after_sign,
|
|
194
|
-
verifyTrust: parsed.verify_trust,
|
|
195
|
-
verifyTimestampTrust: parsed.verify_timestamp_trust,
|
|
196
|
-
ocspFetch: parsed.ocsp_fetch,
|
|
197
|
-
remoteManifestFetch: parsed.remote_manifest_fetch,
|
|
198
|
-
skipIngredientConflictResolution: parsed.skip_ingredient_conflict_resolution,
|
|
199
|
-
strictV1Validation: parsed.strict_v1_validation,
|
|
200
|
-
};
|
|
111
|
+
export function loadSettingsFromFile(filePath) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const content = yield fs.readFile(filePath, "utf8");
|
|
114
|
+
return content;
|
|
115
|
+
});
|
|
201
116
|
}
|
|
202
117
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
118
|
+
* Load settings from a URL.
|
|
119
|
+
* @param url The URL to fetch the settings from
|
|
120
|
+
* @returns Settings as a string
|
|
205
121
|
*/
|
|
206
|
-
export function
|
|
207
|
-
|
|
122
|
+
export function loadSettingsFromUrl(url) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const res = yield fetch(url);
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
throw new Error(`Failed to fetch settings from URL: ${res.status} ${res.statusText}`);
|
|
127
|
+
}
|
|
128
|
+
return yield res.text();
|
|
129
|
+
});
|
|
208
130
|
}
|