@@ -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+ ### 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+
73+ ### Reader
74+
75+ The ` Reader ` class is used to read and validate C2PA manifests from media files. It can parse embedded manifests or fetch remote manifests.
76+
77+ ``` javascript
78+ import { Reader } from ' @contentauth/c2pa-node' ;
79+
80+ // Read from an asset file
81+ const reader = await Reader .fromAsset (inputAsset);
82+
83+ // Read from manifest data and asset
84+ const reader = await Reader .fromManifestDataAndAsset (manifestData, asset);
85+
86+ // Get the manifest store as JSON
87+ const manifestStore = reader .json ();
88+
89+ // Get the active manifest
90+ const activeManifest = reader .getActive ();
91+
92+ // Check if manifest is embedded
93+ const isEmbedded = reader .isEmbedded ();
94+
95+ // Get remote URL if applicable
96+ const remoteUrl = reader .remoteUrl ();
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 ,
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 ,
158+ ' es256' ,
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+ ```
0 commit comments