@contentauth/c2pa-node 0.4.2 → 0.5.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/Cargo.lock +261 -253
- 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/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 +38 -24
- package/src/neon_reader.rs +25 -1
- package/src/runtime.rs +4 -31
- package/src/utils.rs +41 -1
- package/src/settings.rs +0 -520
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.74.0", 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/README.md
CHANGED
|
@@ -49,7 +49,7 @@ This command will download precompiled binaries for the following systems:
|
|
|
49
49
|
|
|
50
50
|
### Reader
|
|
51
51
|
|
|
52
|
-
The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests.
|
|
52
|
+
The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
|
|
53
53
|
|
|
54
54
|
```javascript
|
|
55
55
|
import { Reader } from '@contentauth/c2pa-node';
|
|
@@ -57,6 +57,15 @@ import { Reader } from '@contentauth/c2pa-node';
|
|
|
57
57
|
// Read from an asset file
|
|
58
58
|
const reader = await Reader.fromAsset(inputAsset);
|
|
59
59
|
|
|
60
|
+
// Read with custom settings
|
|
61
|
+
const settings = {
|
|
62
|
+
verify: {
|
|
63
|
+
verify_after_reading: false,
|
|
64
|
+
verify_trust: true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const reader = await Reader.fromAsset(inputAsset, settings);
|
|
68
|
+
|
|
60
69
|
// Read from manifest data and asset
|
|
61
70
|
const reader = await Reader.fromManifestDataAndAsset(manifestData, asset);
|
|
62
71
|
|
|
@@ -75,7 +84,7 @@ const remoteUrl = reader.remoteUrl();
|
|
|
75
84
|
|
|
76
85
|
### Builder
|
|
77
86
|
|
|
78
|
-
The `Builder` class is the main component for creating and signing C2PA manifests. It provides methods to add assertions, resources, and ingredients to manifests, and handles the signing process. Use the `Signer` class to sign the manifests.
|
|
87
|
+
The `Builder` class is the main component for creating and signing C2PA manifests. It provides methods to add assertions, resources, and ingredients to manifests, and handles the signing process. Use the `Signer` class to sign the manifests. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
|
|
79
88
|
|
|
80
89
|
```javascript
|
|
81
90
|
import { Builder } from '@contentauth/c2pa-node';
|
|
@@ -83,9 +92,20 @@ import { Builder } from '@contentauth/c2pa-node';
|
|
|
83
92
|
// Create a new builder
|
|
84
93
|
const builder = Builder.new();
|
|
85
94
|
|
|
95
|
+
// Create with custom settings
|
|
96
|
+
const settings = {
|
|
97
|
+
builder: {
|
|
98
|
+
generate_c2pa_archive: true
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const builder = Builder.new(settings);
|
|
102
|
+
|
|
86
103
|
// Or create from an existing manifest definition
|
|
87
104
|
const builder = Builder.withJson(manifestDefinition);
|
|
88
105
|
|
|
106
|
+
// Or create with both manifest and settings
|
|
107
|
+
const builder = Builder.withJson(manifestDefinition, settings);
|
|
108
|
+
|
|
89
109
|
// Add assertions to the manifest
|
|
90
110
|
builder.addAssertion('c2pa.actions', actionsAssertion);
|
|
91
111
|
|
|
@@ -214,40 +234,116 @@ const decodedData = await trustmark.decode(imageBuffer);
|
|
|
214
234
|
|
|
215
235
|
### Settings and Configuration
|
|
216
236
|
|
|
217
|
-
The library provides comprehensive settings management for
|
|
237
|
+
The library provides comprehensive settings management that can be configured per Reader/Builder instance or using helper functions. Refer to the [Rust SDK](https://github.com/contentauth/c2pa-rs) for the list of settings and their effects.
|
|
238
|
+
|
|
239
|
+
#### Per-Instance Settings
|
|
240
|
+
|
|
241
|
+
Settings can be passed directly to `Reader` and `Builder` constructors:
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
import { Reader, Builder } from '@contentauth/c2pa-node';
|
|
245
|
+
|
|
246
|
+
// Create settings object
|
|
247
|
+
const settings = {
|
|
248
|
+
verify: {
|
|
249
|
+
verify_after_reading: false,
|
|
250
|
+
verify_after_sign: false,
|
|
251
|
+
verify_trust: true,
|
|
252
|
+
ocsp_fetch: true
|
|
253
|
+
},
|
|
254
|
+
trust: {
|
|
255
|
+
verify_trust_list: true,
|
|
256
|
+
trust_anchors: "path/to/anchors.pem"
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// Pass settings to Reader
|
|
261
|
+
const reader = await Reader.fromAsset(inputAsset, settings);
|
|
262
|
+
|
|
263
|
+
// Pass settings to Builder
|
|
264
|
+
const builder = Builder.new(settings);
|
|
265
|
+
|
|
266
|
+
// Settings can also be JSON strings
|
|
267
|
+
const settingsJson = JSON.stringify(settings);
|
|
268
|
+
const builder2 = Builder.new(settingsJson);
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
#### Settings Helper Functions
|
|
272
|
+
|
|
273
|
+
The library provides helper functions to create and manage settings objects:
|
|
218
274
|
|
|
219
275
|
```javascript
|
|
220
276
|
import {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
277
|
+
createTrustSettings,
|
|
278
|
+
createCawgTrustSettings,
|
|
279
|
+
createVerifySettings,
|
|
280
|
+
mergeSettings,
|
|
281
|
+
settingsToJson,
|
|
224
282
|
loadSettingsFromFile,
|
|
225
283
|
loadSettingsFromUrl
|
|
226
284
|
} from '@contentauth/c2pa-node';
|
|
227
285
|
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
|
|
286
|
+
// Create trust settings
|
|
287
|
+
const trustSettings = createTrustSettings({
|
|
288
|
+
verifyTrustList: true,
|
|
289
|
+
userAnchors: "path/to/user-anchors.pem",
|
|
290
|
+
trustAnchors: "path/to/trust-anchors.pem",
|
|
291
|
+
allowedList: "path/to/allowed-list.pem"
|
|
292
|
+
});
|
|
236
293
|
|
|
237
|
-
//
|
|
238
|
-
|
|
294
|
+
// Create CAWG trust settings
|
|
295
|
+
const cawgTrustSettings = createCawgTrustSettings({
|
|
239
296
|
verifyTrustList: true,
|
|
240
|
-
|
|
241
|
-
trustAnchors: ['trust-anchor1'],
|
|
242
|
-
allowedList: ['allowed-cert1']
|
|
297
|
+
trustAnchors: "path/to/cawg-anchors.pem"
|
|
243
298
|
});
|
|
244
299
|
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
verifyAfterReading:
|
|
248
|
-
verifyAfterSign:
|
|
300
|
+
// Create verify settings
|
|
301
|
+
const verifySettings = createVerifySettings({
|
|
302
|
+
verifyAfterReading: false,
|
|
303
|
+
verifyAfterSign: false,
|
|
249
304
|
verifyTrust: true,
|
|
305
|
+
verifyTimestampTrust: true,
|
|
250
306
|
ocspFetch: true,
|
|
251
|
-
remoteManifestFetch: true
|
|
307
|
+
remoteManifestFetch: true,
|
|
308
|
+
skipIngredientConflictResolution: false,
|
|
309
|
+
strictV1Validation: false
|
|
252
310
|
});
|
|
311
|
+
|
|
312
|
+
// Merge multiple settings
|
|
313
|
+
const combinedSettings = mergeSettings(trustSettings, verifySettings);
|
|
314
|
+
|
|
315
|
+
// Convert settings to JSON string
|
|
316
|
+
const jsonString = settingsToJson(combinedSettings);
|
|
317
|
+
|
|
318
|
+
// Load settings from file (JSON or TOML)
|
|
319
|
+
const fileSettings = await loadSettingsFromFile('./c2pa-settings.toml');
|
|
320
|
+
const reader = await Reader.fromAsset(inputAsset, fileSettings);
|
|
321
|
+
|
|
322
|
+
// Load settings from URL
|
|
323
|
+
const urlSettings = await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
|
|
324
|
+
const builder = Builder.new(urlSettings);
|
|
253
325
|
```
|
|
326
|
+
|
|
327
|
+
#### Available Settings
|
|
328
|
+
|
|
329
|
+
**Trust Settings:**
|
|
330
|
+
- `verifyTrustList` - Whether to verify against the trust list
|
|
331
|
+
- `userAnchors` - User-provided trust anchors (PEM format or path)
|
|
332
|
+
- `trustAnchors` - Trust anchors for validation (PEM format or path)
|
|
333
|
+
- `trustConfig` - Path to trust configuration file
|
|
334
|
+
- `allowedList` - Allowed list of certificates (PEM format or path)
|
|
335
|
+
|
|
336
|
+
**Verify Settings:**
|
|
337
|
+
- `verifyAfterReading` - Whether to verify after reading a manifest
|
|
338
|
+
- `verifyAfterSign` - Whether to verify after signing a manifest
|
|
339
|
+
- `verifyTrust` - Whether to verify trust during validation
|
|
340
|
+
- `verifyTimestampTrust` - Whether to verify timestamp trust
|
|
341
|
+
- `ocspFetch` - Whether to fetch OCSP responses
|
|
342
|
+
- `remoteManifestFetch` - Whether to fetch remote manifests
|
|
343
|
+
- `skipIngredientConflictResolution` - Whether to skip ingredient conflict resolution
|
|
344
|
+
- `strictV1Validation` - Whether to use strict v1 validation
|
|
345
|
+
|
|
346
|
+
**Builder Settings:**
|
|
347
|
+
- `generate_c2pa_archive` - Whether to generate C2PA archive format
|
|
348
|
+
|
|
349
|
+
**Note:** Settings are passed as per-instance configuration. There are no global settings that affect all Readers and Builders.
|
package/dist/Builder.js
CHANGED
|
@@ -18,11 +18,16 @@ export class Builder {
|
|
|
18
18
|
constructor(builder) {
|
|
19
19
|
this.builder = builder;
|
|
20
20
|
}
|
|
21
|
-
static new() {
|
|
22
|
-
const
|
|
21
|
+
static new(settings) {
|
|
22
|
+
const settingsStr = settings
|
|
23
|
+
? typeof settings === "string"
|
|
24
|
+
? settings
|
|
25
|
+
: JSON.stringify(settings)
|
|
26
|
+
: undefined;
|
|
27
|
+
const builder = getNeonBinary().builderNew(settingsStr);
|
|
23
28
|
return new Builder(builder);
|
|
24
29
|
}
|
|
25
|
-
static withJson(json) {
|
|
30
|
+
static withJson(json, settings) {
|
|
26
31
|
let jsonString;
|
|
27
32
|
try {
|
|
28
33
|
jsonString = JSON.stringify(json);
|
|
@@ -34,7 +39,12 @@ export class Builder {
|
|
|
34
39
|
}
|
|
35
40
|
throw new Error("Failed to stringify JSON Manifest Definition: Unknown error");
|
|
36
41
|
}
|
|
37
|
-
const
|
|
42
|
+
const settingsStr = settings
|
|
43
|
+
? typeof settings === "string"
|
|
44
|
+
? settings
|
|
45
|
+
: JSON.stringify(settings)
|
|
46
|
+
: undefined;
|
|
47
|
+
const builder = getNeonBinary().builderWithJson(jsonString, settingsStr);
|
|
38
48
|
return new Builder(builder);
|
|
39
49
|
}
|
|
40
50
|
setIntent(intent) {
|
|
@@ -78,9 +88,14 @@ export class Builder {
|
|
|
78
88
|
return getNeonBinary().builderToArchive.call(this.builder, asset);
|
|
79
89
|
});
|
|
80
90
|
}
|
|
81
|
-
static fromArchive(asset) {
|
|
91
|
+
static fromArchive(asset, settings) {
|
|
82
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
93
|
+
const settingsStr = settings
|
|
94
|
+
? typeof settings === "string"
|
|
95
|
+
? settings
|
|
96
|
+
: JSON.stringify(settings)
|
|
97
|
+
: undefined;
|
|
98
|
+
return new Builder(yield getNeonBinary().builderFromArchive(asset, settingsStr));
|
|
84
99
|
});
|
|
85
100
|
}
|
|
86
101
|
sign(signer, input, output) {
|
package/dist/Builder.spec.js
CHANGED
|
@@ -19,7 +19,6 @@ import { isActionsAssertion } from "./assertions.js";
|
|
|
19
19
|
import { CallbackSigner, LocalSigner } from "./Signer.js";
|
|
20
20
|
import { Reader } from "./Reader.js";
|
|
21
21
|
import { Builder } from "./Builder.js";
|
|
22
|
-
import { loadC2paSettings, resetSettings } from "./Settings.js";
|
|
23
22
|
const tempDir = path.join(__dirname, "tmp");
|
|
24
23
|
class TestSigner {
|
|
25
24
|
constructor(privateKey) {
|
|
@@ -253,51 +252,44 @@ describe("Builder", () => {
|
|
|
253
252
|
expect(stats.size).toBeGreaterThan(0);
|
|
254
253
|
}));
|
|
255
254
|
it("should construct reader directly from builder archive buffer", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
|
-
|
|
257
|
-
loadC2paSettings(JSON.stringify({
|
|
255
|
+
const settings = JSON.stringify({
|
|
258
256
|
builder: {
|
|
259
257
|
generate_c2pa_archive: true,
|
|
260
258
|
},
|
|
261
259
|
verify: {
|
|
262
260
|
verify_after_reading: false,
|
|
263
261
|
},
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
expect(reader).not.toBeNull();
|
|
296
|
-
}
|
|
297
|
-
finally {
|
|
298
|
-
// Reset settings to defaults
|
|
299
|
-
resetSettings();
|
|
300
|
-
}
|
|
262
|
+
});
|
|
263
|
+
// Create a builder
|
|
264
|
+
const simpleManifestDefinition = {
|
|
265
|
+
claim_generator_info: [
|
|
266
|
+
{
|
|
267
|
+
name: "c2pa_test",
|
|
268
|
+
version: "1.0.0",
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
title: "Test_Manifest",
|
|
272
|
+
format: "image/jpeg",
|
|
273
|
+
assertions: [],
|
|
274
|
+
resources: { resources: {} },
|
|
275
|
+
};
|
|
276
|
+
const testBuilder = Builder.withJson(simpleManifestDefinition, settings);
|
|
277
|
+
// Add an ingredient
|
|
278
|
+
yield testBuilder.addIngredient(parent_json, source);
|
|
279
|
+
// Create an archive from the builder written to a buffer
|
|
280
|
+
const archive = {
|
|
281
|
+
buffer: null,
|
|
282
|
+
};
|
|
283
|
+
yield testBuilder.toArchive(archive);
|
|
284
|
+
// Verify buffer was populated
|
|
285
|
+
expect(archive.buffer).not.toBeNull();
|
|
286
|
+
expect(archive.buffer.length).toBeGreaterThan(0);
|
|
287
|
+
// Construct a reader from the builder archive with mime-type "application/c2pa"
|
|
288
|
+
const reader = yield Reader.fromAsset({
|
|
289
|
+
buffer: archive.buffer,
|
|
290
|
+
mimeType: "application/c2pa",
|
|
291
|
+
}, settings);
|
|
292
|
+
expect(reader).not.toBeNull();
|
|
301
293
|
}));
|
|
302
294
|
it("should sign data with callback to file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
303
295
|
const dest = {
|
package/dist/Reader.js
CHANGED
|
@@ -31,15 +31,17 @@ export class Reader {
|
|
|
31
31
|
return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
static fromAsset(asset) {
|
|
34
|
+
static fromAsset(asset, settings) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const
|
|
36
|
+
const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
|
|
37
|
+
const reader = yield getNeonBinary().readerFromAsset(asset, settingsStr);
|
|
37
38
|
return reader ? new Reader(reader) : null;
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
static fromManifestDataAndAsset(manifestData, asset) {
|
|
41
|
+
static fromManifestDataAndAsset(manifestData, asset, settings) {
|
|
41
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const
|
|
43
|
+
const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
|
|
44
|
+
const reader = yield getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
|
|
43
45
|
return new Reader(reader);
|
|
44
46
|
});
|
|
45
47
|
}
|
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
|
}
|