Skip to content

Commit 8ed9a96

Browse files
committed
fix: Comment incorporation
1 parent 8edfa11 commit 8ed9a96

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,6 @@ This command will download precompiled binaries for the following systems:
4747

4848
## Components
4949

50-
### Builder
51-
52-
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.
53-
54-
```javascript
55-
import { Builder } from '@contentauth/c2pa-node';
56-
57-
// Create a new builder
58-
const builder = Builder.new();
59-
60-
// Or create from an existing manifest definition
61-
const builder = Builder.withJson(manifestDefinition);
62-
63-
// Add assertions to the manifest
64-
builder.addAssertion('c2pa.actions', actionsAssertion);
65-
66-
// Add resources
67-
await builder.addResource('resource://example', resourceAsset);
68-
69-
// Sign the manifest
70-
const manifest = builder.sign(signer, inputAsset, outputAsset);
71-
```
72-
7350
### Reader
7451

7552
The `Reader` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests.
@@ -96,6 +73,29 @@ const isEmbedded = reader.isEmbedded();
9673
const remoteUrl = reader.remoteUrl();
9774
```
9875

76+
### Builder
77+
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.
79+
80+
```javascript
81+
import { Builder } from '@contentauth/c2pa-node';
82+
83+
// Create a new builder
84+
const builder = Builder.new();
85+
86+
// Or create from an existing manifest definition
87+
const builder = Builder.withJson(manifestDefinition);
88+
89+
// Add assertions to the manifest
90+
builder.addAssertion('c2pa.actions', actionsAssertion);
91+
92+
// Add resources
93+
await builder.addResource('resource://example', resourceAsset);
94+
95+
// Sign the manifest
96+
const manifest = builder.sign(signer, inputAsset, outputAsset);
97+
```
98+
9999
### Signers
100100

101101
The library provides several types of signers for different use cases:
@@ -131,7 +131,7 @@ const signer = CallbackSigner.newSigner(
131131
{
132132
alg: 'es256',
133133
certs: [certificateBuffer],
134-
reserveSize: 1024,
134+
reserveSize: 1024, // Reserved size in bytes for the C2PA Claim Signature box.
135135
tsaUrl: 'https://timestamp.example.com'
136136
},
137137
async (data) => {
@@ -154,8 +154,8 @@ import { IdentityAssertionBuilder, CallbackCredentialHolder } from '@contentauth
154154

155155
// Create a credential holder
156156
const credentialHolder = CallbackCredentialHolder.newCallbackCredentialHolder(
157-
1024,
158-
'es256',
157+
1024, // reserveSize
158+
'es256', // sigType
159159
async (payload) => {
160160
// Custom signing logic for identity assertions
161161
return await signIdentityPayload(payload);

js-src/Settings.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,33 @@ export function getSettingsJson(): string {
8888
* @param trustConfig The trust configuration object
8989
*/
9090
export function loadTrustConfig(trustConfig: TrustConfig): void {
91-
// Convert camelCase to snake_case for Rust compatibility
91+
// Convert settings to snake_case for the neon Rust code.
9292
// Explicitly set undefined fields to null to ensure they are cleared
93-
const rustConfig = {
93+
const config = {
9494
verify_trust_list: trustConfig.verifyTrustList,
9595
user_anchors: trustConfig.userAnchors ?? null,
9696
trust_anchors: trustConfig.trustAnchors ?? null,
9797
trust_config: trustConfig.trustConfig ?? null,
9898
allowed_list: trustConfig.allowedList ?? null,
9999
};
100-
neon.loadTrustConfig(JSON.stringify(rustConfig));
100+
neon.loadTrustConfig(JSON.stringify(config));
101101
}
102102

103103
/**
104104
* Load trust configuration into the CAWG trust settings.
105105
* @param trustConfig The trust configuration object
106106
*/
107107
export function loadCawgTrustConfig(trustConfig: TrustConfig): void {
108-
// Convert camelCase to snake_case for Rust compatibility
108+
// Convert settings to snake_case for the neon Rust code
109109
// Explicitly set undefined fields to null to ensure they are cleared
110-
const rustConfig = {
110+
const config = {
111111
verify_trust_list: trustConfig.verifyTrustList,
112112
user_anchors: trustConfig.userAnchors ?? null,
113113
trust_anchors: trustConfig.trustAnchors ?? null,
114114
trust_config: trustConfig.trustConfig ?? null,
115115
allowed_list: trustConfig.allowedList ?? null,
116116
};
117-
neon.loadCawgTrustConfig(JSON.stringify(rustConfig));
117+
neon.loadCawgTrustConfig(JSON.stringify(config));
118118
}
119119

120120
/**
@@ -160,8 +160,8 @@ export function getCawgTrustConfig(): TrustConfig {
160160
* @param verifyConfig The verify configuration object
161161
*/
162162
export function loadVerifyConfig(verifyConfig: VerifyConfig): void {
163-
// Convert camelCase to snake_case for Rust compatibility
164-
const rustConfig = {
163+
// Convert camelCase to snake_case for the neon Rust code
164+
const config = {
165165
verify_after_reading: verifyConfig.verifyAfterReading,
166166
verify_after_sign: verifyConfig.verifyAfterSign,
167167
verify_trust: verifyConfig.verifyTrust,
@@ -173,7 +173,7 @@ export function loadVerifyConfig(verifyConfig: VerifyConfig): void {
173173
verifyConfig.skipIngredientConflictResolution,
174174
strict_v1_validation: verifyConfig.strictV1Validation,
175175
};
176-
neon.loadVerifyConfig(JSON.stringify(rustConfig));
176+
neon.loadVerifyConfig(JSON.stringify(config));
177177
}
178178

179179
/**

js-src/assertions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
export function isActionsAssertion(
1717
obj: unknown,
18-
): obj is { data: { actions: Array<{ action: string }> } } {
18+
): obj is { label: string; data: { actions: Array<{ action: string }> } } {
1919
return (
2020
typeof obj === "object" &&
2121
obj !== null &&
22+
"label" in obj &&
2223
"data" in obj &&
24+
typeof (obj as any).label === "string" &&
25+
((obj as any).label === "c2pa.actions" || (obj as any).label === "c2pa.actions.v2") &&
2326
typeof (obj as any).data === "object" &&
2427
(obj as any).data !== null &&
2528
Array.isArray((obj as any).data.actions)

0 commit comments

Comments
 (0)