Skip to content

Commit c22f837

Browse files
authored
feat: Import types, fix CAWG signing
- Use types from @contentauth/toolkit - Add Settings. Settings are treated as a global across all threads. When settings are updated all existing threads are dropped and will not be reused when they have completed their task. - Neon Types refactored. Interfaces for classes should not be used for Neon Objects.
2 parents 836a78a + cf65197 commit c22f837

File tree

112 files changed

+4616
-2148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4616
-2148
lines changed

Cargo.lock

Lines changed: 237 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
async-trait = "0.1.77"
1313
ciborium = "0.2.2"
14-
c2pa = { version = "0.58", features = ["file_io", "pdf", "fetch_remote_manifests"] }
14+
c2pa = { version = "0.64", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto"] }
1515
futures = "0.3"
1616
image = "0.25.6"
1717
neon = { version = "1.0.0", default-features = false, features = [
@@ -29,6 +29,7 @@ reqwest = { version = "0.12.2", features = [
2929
serde = { version = "1.0.203", features = ["derive"] }
3030
serde_bytes = "0.11.15"
3131
serde_json = "1.0.117"
32+
toml = "0.8"
3233
thiserror = "1.0.61"
3334
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
3435
tokio-util = "0.7.13"

README.md

Lines changed: 206 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,209 @@ This command will download precompiled binaries for the following systems:
4545
- Windows x86
4646
- Windows ARM
4747

48-
All other platforms require building a custom binary as described below, since the `postinstall` step builds the Rust library into a native Node.js module on your machine.
48+
## Components
49+
50+
### Reader
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.
53+
54+
```javascript
55+
import { Reader } from '@contentauth/c2pa-node';
56+
57+
// Read from an asset file
58+
const reader = await Reader.fromAsset(inputAsset);
59+
60+
// Read from manifest data and asset
61+
const reader = await Reader.fromManifestDataAndAsset(manifestData, asset);
62+
63+
// Get the manifest store as JSON
64+
const manifestStore = reader.json();
65+
66+
// Get the active manifest
67+
const activeManifest = reader.getActive();
68+
69+
// Check if manifest is embedded
70+
const isEmbedded = reader.isEmbedded();
71+
72+
// Get remote URL if applicable
73+
const remoteUrl = reader.remoteUrl();
74+
```
75+
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+
99+
### Signers
100+
101+
The library provides several types of signers for different use cases:
102+
103+
#### LocalSigner
104+
105+
For local signing with certificates and private keys:
106+
107+
```javascript
108+
import { LocalSigner } from '@contentauth/c2pa-node';
109+
110+
// Create a local signer with certificate and private key
111+
const signer = LocalSigner.newSigner(
112+
certificateBuffer,
113+
privateKeyBuffer,
114+
'es256', // signing algorithm
115+
'https://timestamp.example.com' // optional TSA URL
116+
);
117+
118+
// Sign data
119+
const signature = signer.sign(dataBuffer);
120+
```
121+
122+
#### CallbackSigner
123+
124+
For custom signing implementations using callbacks:
125+
126+
```javascript
127+
import { CallbackSigner } from '@contentauth/c2pa-node';
128+
129+
// Create a callback signer
130+
const signer = CallbackSigner.newSigner(
131+
{
132+
alg: 'es256',
133+
certs: [certificateBuffer],
134+
reserveSize: 1024, // Reserved size in bytes for the C2PA Claim Signature box.
135+
tsaUrl: 'https://timestamp.example.com'
136+
},
137+
async (data) => {
138+
// Custom signing logic
139+
return await customSigningFunction(data);
140+
}
141+
);
142+
```
143+
144+
### Identity Assertion Components
145+
146+
For working with identity assertions and CAWG (Content Authenticity Working Group) identities:
147+
148+
#### IdentityAssertionBuilder
149+
150+
Builds identity assertions with roles and referenced assertions:
151+
152+
```javascript
153+
import { IdentityAssertionBuilder, CallbackCredentialHolder } from '@contentauth/c2pa-node';
154+
155+
// Create a credential holder
156+
const credentialHolder = CallbackCredentialHolder.newCallbackCredentialHolder(
157+
1024, // reserveSize
158+
'es256', // sigType
159+
async (payload) => {
160+
// Custom signing logic for identity assertions
161+
return await signIdentityPayload(payload);
162+
}
163+
);
164+
165+
// Create an identity assertion builder
166+
const identityBuilder = await IdentityAssertionBuilder.identityBuilderForCredentialHolder(
167+
credentialHolder
168+
);
169+
170+
// Add roles and referenced assertions
171+
identityBuilder.addRoles(['photographer', 'editor']);
172+
identityBuilder.addReferencedAssertions(['c2pa.actions']);
173+
```
174+
175+
#### IdentityAssertionSigner
176+
177+
Signs manifests with identity assertions:
178+
179+
```javascript
180+
import { IdentityAssertionSigner } from '@contentauth/c2pa-node';
181+
182+
// Create an identity assertion signer
183+
const identitySigner = IdentityAssertionSigner.new(callbackSigner);
184+
185+
// Add identity assertion
186+
identitySigner.addIdentityAssertion(identityBuilder);
187+
188+
// Use with Builder for signing
189+
const manifest = await builder.signAsync(identitySigner, inputAsset, outputAsset);
190+
```
191+
192+
### Trustmark
193+
194+
The `Trustmark` class provides functionality for encoding and decoding trustmarks in images:
195+
196+
```javascript
197+
import { Trustmark } from '@contentauth/c2pa-node';
198+
199+
// Create a trustmark instance
200+
const trustmark = await Trustmark.newTrustmark({
201+
// trustmark configuration
202+
});
203+
204+
// Encode a trustmark into an image
205+
const encodedImage = await trustmark.encode(
206+
imageBuffer,
207+
0.5, // strength
208+
'watermark-text' // optional watermark
209+
);
210+
211+
// Decode a trustmark from an image
212+
const decodedData = await trustmark.decode(imageBuffer);
213+
```
214+
215+
### Settings and Configuration
216+
217+
The library provides comprehensive settings management for trust configuration, verification settings, and global C2PA settings:
218+
219+
```javascript
220+
import {
221+
loadC2paSettings,
222+
loadTrustConfig,
223+
loadVerifyConfig,
224+
loadSettingsFromFile,
225+
loadSettingsFromUrl
226+
} from '@contentauth/c2pa-node';
227+
228+
// Load settings from JSON string
229+
loadC2paSettings('{"trust": {"verify_trust_list": true}}');
230+
231+
// Load settings from file
232+
await loadSettingsFromFile('./c2pa-settings.json');
233+
234+
// Load settings from URL
235+
await loadSettingsFromUrl('https://example.com/c2pa-settings.json');
236+
237+
// Configure trust settings
238+
loadTrustConfig({
239+
verifyTrustList: true,
240+
userAnchors: ['anchor1', 'anchor2'],
241+
trustAnchors: ['trust-anchor1'],
242+
allowedList: ['allowed-cert1']
243+
});
244+
245+
// Configure verification settings
246+
loadVerifyConfig({
247+
verifyAfterReading: true,
248+
verifyAfterSign: true,
249+
verifyTrust: true,
250+
ocspFetch: true,
251+
remoteManifestFetch: true
252+
});
253+
```

docs/README.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Classes
88

99
- [Builder](classes/Builder.md)
10+
- [CallbackCredentialHolder](classes/CallbackCredentialHolder.md)
1011
- [CallbackSigner](classes/CallbackSigner.md)
1112
- [IdentityAssertionBuilder](classes/IdentityAssertionBuilder.md)
1213
- [IdentityAssertionSigner](classes/IdentityAssertionSigner.md)
@@ -16,48 +17,55 @@
1617

1718
## Interfaces
1819

19-
- [Actor](interfaces/Actor.md)
20-
- [AssertionDefinition](interfaces/AssertionDefinition.md)
21-
- [AssetType](interfaces/AssetType.md)
2220
- [BuilderInterface](interfaces/BuilderInterface.md)
21+
- [CallbackCredentialHolderInterface](interfaces/CallbackCredentialHolderInterface.md)
2322
- [CallbackSignerInterface](interfaces/CallbackSignerInterface.md)
24-
- [ClaimGeneratorInfo](interfaces/ClaimGeneratorInfo.md)
25-
- [DataSource](interfaces/DataSource.md)
2623
- [DestinationBufferAsset](interfaces/DestinationBufferAsset.md)
2724
- [FileAsset](interfaces/FileAsset.md)
2825
- [HashedUri](interfaces/HashedUri.md)
2926
- [IdentityAssertionBuilderInterface](interfaces/IdentityAssertionBuilderInterface.md)
3027
- [IdentityAssertionSignerInterface](interfaces/IdentityAssertionSignerInterface.md)
31-
- [Ingredient](interfaces/Ingredient.md)
32-
- [IngredientOptions](interfaces/IngredientOptions.md)
33-
- [IngredientThumbnail](interfaces/IngredientThumbnail.md)
3428
- [JsCallbackSignerConfig](interfaces/JsCallbackSignerConfig.md)
3529
- [LocalSignerInterface](interfaces/LocalSignerInterface.md)
36-
- [Manifest](interfaces/Manifest.md)
37-
- [ManifestAssertion](interfaces/ManifestAssertion.md)
38-
- [ManifestDefinition](interfaces/ManifestDefinition.md)
39-
- [ManifestStore](interfaces/ManifestStore.md)
40-
- [Metadata](interfaces/Metadata.md)
4130
- [ReaderInterface](interfaces/ReaderInterface.md)
42-
- [ResourceRef](interfaces/ResourceRef.md)
43-
- [ResourceStore](interfaces/ResourceStore.md)
44-
- [ReviewRating](interfaces/ReviewRating.md)
45-
- [SignatureInfo](interfaces/SignatureInfo.md)
31+
- [SignerPayload](interfaces/SignerPayload.md)
4632
- [SourceBufferAsset](interfaces/SourceBufferAsset.md)
33+
- [TrustConfig](interfaces/TrustConfig.md)
4734
- [TrustmarkConfig](interfaces/TrustmarkConfig.md)
4835
- [TrustmarkInterface](interfaces/TrustmarkInterface.md)
49-
- [ValidationStatus](interfaces/ValidationStatus.md)
36+
- [VerifyConfig](interfaces/VerifyConfig.md)
5037

5138
## Type Aliases
5239

5340
- [CallbackSignerConfig](type-aliases/CallbackSignerConfig.md)
5441
- [ClaimVersion](type-aliases/ClaimVersion.md)
55-
- [DateT](type-aliases/DateT.md)
5642
- [DestinationAsset](type-aliases/DestinationAsset.md)
5743
- [ManifestAssertionKind](type-aliases/ManifestAssertionKind.md)
58-
- [Relationship](type-aliases/Relationship.md)
44+
- [NeonBuilderHandle](type-aliases/NeonBuilderHandle.md)
45+
- [NeonCallbackCredentialHolderHandle](type-aliases/NeonCallbackCredentialHolderHandle.md)
46+
- [NeonCallbackSignerHandle](type-aliases/NeonCallbackSignerHandle.md)
47+
- [NeonIdentityAssertionBuilderHandle](type-aliases/NeonIdentityAssertionBuilderHandle.md)
48+
- [NeonIdentityAssertionSignerHandle](type-aliases/NeonIdentityAssertionSignerHandle.md)
49+
- [NeonLocalSignerHandle](type-aliases/NeonLocalSignerHandle.md)
50+
- [NeonReaderHandle](type-aliases/NeonReaderHandle.md)
51+
- [NeonTrustmarkHandle](type-aliases/NeonTrustmarkHandle.md)
5952
- [SigningAlg](type-aliases/SigningAlg.md)
6053
- [SourceAsset](type-aliases/SourceAsset.md)
6154
- [TrustmarkVariant](type-aliases/TrustmarkVariant.md)
6255
- [TrustmarkVersion](type-aliases/TrustmarkVersion.md)
63-
- [UriOrResource](type-aliases/UriOrResource.md)
56+
57+
## Functions
58+
59+
- [getCawgTrustConfig](functions/getCawgTrustConfig.md)
60+
- [getSettingsJson](functions/getSettingsJson.md)
61+
- [getTrustConfig](functions/getTrustConfig.md)
62+
- [getVerifyConfig](functions/getVerifyConfig.md)
63+
- [isActionsAssertion](functions/isActionsAssertion.md)
64+
- [loadC2paSettings](functions/loadC2paSettings.md)
65+
- [loadC2paSettingsToml](functions/loadC2paSettingsToml.md)
66+
- [loadCawgTrustConfig](functions/loadCawgTrustConfig.md)
67+
- [loadSettingsFromFile](functions/loadSettingsFromFile.md)
68+
- [loadSettingsFromUrl](functions/loadSettingsFromUrl.md)
69+
- [loadTrustConfig](functions/loadTrustConfig.md)
70+
- [loadVerifyConfig](functions/loadVerifyConfig.md)
71+
- [patchVerifyConfig](functions/patchVerifyConfig.md)

0 commit comments

Comments
 (0)