@contentauth/c2pa-node 0.1.0 → 0.1.2

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.
@@ -0,0 +1,893 @@
1
+ // Copyright 2024 Adobe. All rights reserved.
2
+ // This file is licensed to you under the Apache License,
3
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
+ // or the MIT license (http://opensource.org/licenses/MIT),
5
+ // at your option.
6
+
7
+ // Unless required by applicable law or agreed to in writing,
8
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
9
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
10
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
11
+ // specific language governing permissions and limitations under
12
+ // each license.
13
+
14
+ import { Buffer } from "buffer";
15
+ /**
16
+ * Assertions in C2PA can be stored in several formats
17
+ */
18
+ export type ManifestAssertionKind = "Cbor" | "Json";
19
+ export type UriOrResource = ResourceRef | HashedUri;
20
+ export type DateT = string;
21
+ export type Relationship = "parentOf" | "componentOf" | "inputTo";
22
+ /**
23
+ * Describes the digital signature algorithms allowed by the C2PA spec
24
+ *
25
+ * Per <https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_digital_signatures>:
26
+ *
27
+ * > All digital signatures that are stored in a C2PA Manifest shall > be generated using one of the digital signature algorithms and > key types listed as described in this section
28
+ */
29
+ export type SigningAlg =
30
+ | "es256"
31
+ | "es384"
32
+ | "es512"
33
+ | "ps256"
34
+ | "ps384"
35
+ | "ps512"
36
+ | "ed25519";
37
+
38
+ // A claim_version field is now allowed in a manifest definition for Builder and, if set to 2 will generate v2 claims
39
+ export type ClaimVersion = 1 | 2;
40
+
41
+ // Trustmark Versions
42
+ export type TrustmarkVersion =
43
+ // Tolerates 8 bit flips
44
+ | "BchSuper"
45
+ // Tolerates 5 bit flips
46
+ | "Bch5"
47
+ // Tolerates 4 bit flips
48
+ | "Bch4"
49
+ // Tolerates 3 bit flips
50
+ | "Bch3";
51
+
52
+ // Trustmark Variants. See https://github.com/adobe/trustmark/blob/main/FAQ.md for more
53
+ export type TrustmarkVariant =
54
+ // Original Trustmark model
55
+ | "B"
56
+ // Compact Trustmark model
57
+ | "C"
58
+ // Perceptual model
59
+ | "P"
60
+ // Quality Trustmark model
61
+ | "Q";
62
+
63
+ /**
64
+ * A Container for a set of Manifests and a ValidationStatus list
65
+ */
66
+ export interface ManifestStore {
67
+ /**
68
+ * A label for the active (most recent) manifest in the store
69
+ */
70
+ active_manifest?: string | undefined;
71
+ /**
72
+ * A HashMap of Manifests
73
+ */
74
+ manifests: {
75
+ [k: string]: Manifest;
76
+ };
77
+ /**
78
+ * ValidationStatus generated when loading the ManifestStore from an asset
79
+ */
80
+ validation_status?: ValidationStatus[] | undefined;
81
+ [k: string]: unknown;
82
+ }
83
+
84
+ /**
85
+ * A Manifest represents all the information in a c2pa manifest
86
+ */
87
+ export interface Manifest {
88
+ /**
89
+ * A list of assertions
90
+ */
91
+ assertions?: ManifestAssertion[];
92
+ /**
93
+ * A User Agent formatted string identifying the software/hardware/system produced this claim Spaces are not allowed in names, versions can be specified with product/1.0 syntax
94
+ */
95
+ claim_generator?: string;
96
+ claim_generator_hints?:
97
+ | {
98
+ [k: string]: unknown;
99
+ }
100
+ | undefined;
101
+ /**
102
+ * A list of claim generator info data identifying the software/hardware/system produced this claim
103
+ */
104
+ claim_generator_info?: ClaimGeneratorInfo[] | undefined;
105
+ /**
106
+ * A List of verified credentials
107
+ */
108
+ credentials?: unknown[] | undefined;
109
+ /**
110
+ * The format of the source file as a MIME type
111
+ */
112
+ format?: string;
113
+ /**
114
+ * A List of ingredients
115
+ */
116
+ ingredients?: Ingredient[];
117
+ /**
118
+ * Instance ID from `xmpMM:InstanceID` in XMP metadata
119
+ */
120
+ instance_id?: string;
121
+ label?: string | undefined;
122
+ /**
123
+ * A list of redactions - URIs to a redacted assertions
124
+ */
125
+ redactions?: string[] | undefined;
126
+ /**
127
+ * container for binary assets (like thumbnails)
128
+ */
129
+ resources?: ResourceStore;
130
+ /**
131
+ * Signature data (only used for reporting)
132
+ */
133
+ signature_info?: SignatureInfo | undefined;
134
+ thumbnail?: ResourceRef | undefined;
135
+ /**
136
+ * A human-readable title, generally source filename
137
+ */
138
+ title?: string | undefined;
139
+ /**
140
+ * Optional prefix added to the generated Manifest Label This is typically Internet domain name for the vendor (i.e. `adobe`)
141
+ */
142
+ vendor?: string | undefined;
143
+ [k: string]: unknown;
144
+ }
145
+
146
+ /**
147
+ * A labeled container for an Assertion value in a Manifest
148
+ */
149
+ export interface ManifestAssertion {
150
+ data: unknown;
151
+ /**
152
+ * There can be more than one assertion for any label
153
+ */
154
+ instance?: number | undefined;
155
+ /**
156
+ * The [ManifestAssertionKind] for this assertion (as stored in c2pa content)
157
+ */
158
+ kind?: ManifestAssertionKind | undefined;
159
+ /**
160
+ * An assertion label in reverse domain format
161
+ */
162
+ label: string;
163
+ [k: string]: unknown;
164
+ }
165
+
166
+ /**
167
+ * Description of the claim generator, or the software used in generating the claim
168
+ *
169
+ * This structure is also used for actions softwareAgent
170
+ */
171
+ export interface ClaimGeneratorInfo {
172
+ /**
173
+ * hashed URI to the icon (either embedded or remote)
174
+ */
175
+ icon?: UriOrResource | undefined;
176
+ /**
177
+ * A human readable string naming the claim_generator
178
+ */
179
+ name: string;
180
+ /**
181
+ * A human readable string of the product's version
182
+ */
183
+ version?: string | undefined;
184
+ [k: string]: unknown;
185
+ }
186
+
187
+ /**
188
+ * A reference to a resource to be used in JSON serialization
189
+ */
190
+ export interface ResourceRef {
191
+ /**
192
+ * The algorithm used to hash the resource (if applicable)
193
+ */
194
+ alg?: string | undefined;
195
+ /**
196
+ * More detailed data types as defined in the C2PA spec
197
+ */
198
+ data_types?: AssetType[] | undefined;
199
+ /**
200
+ * The mime type of the referenced resource
201
+ */
202
+ format: string;
203
+ /**
204
+ * The hash of the resource (if applicable)
205
+ */
206
+ hash?: string | undefined;
207
+ /**
208
+ * A URI that identifies the resource as referenced from the manifest
209
+ *
210
+ * This may be a JUMBF URI, a file path, a URL or any other string. Relative JUMBF URIs will be resolved with the manifest label. Relative file paths will be resolved with the base path if provided
211
+ */
212
+ identifier: string;
213
+ [k: string]: unknown;
214
+ }
215
+
216
+ export interface AssetType {
217
+ type: string;
218
+ version?: string | undefined;
219
+ [k: string]: unknown;
220
+ }
221
+
222
+ /**
223
+ * Hashed Uri structure as defined by C2PA spec It is annotated to produce the correctly tagged cbor serialization
224
+ */
225
+ export interface HashedUri {
226
+ alg?: string | undefined;
227
+ hash: number[];
228
+ url: string;
229
+ [k: string]: unknown;
230
+ }
231
+
232
+ /**
233
+ * An `Ingredient` is any external asset that has been used in the creation of an image
234
+ */
235
+ export interface Ingredient {
236
+ /**
237
+ * The active manifest label (if one exists)
238
+ *
239
+ * If this ingredient has a [`ManifestStore`], this will hold the label of the active [`Manifest`]
240
+ *
241
+ * [`Manifest`]: crate::Manifest [`ManifestStore`]: crate::ManifestStore
242
+ */
243
+ active_manifest?: string | undefined;
244
+ /**
245
+ * A reference to the actual data of the ingredient
246
+ */
247
+ data?: ResourceRef | undefined;
248
+ /**
249
+ * Additional description of the ingredient
250
+ */
251
+ description?: string | undefined;
252
+ /**
253
+ * Document ID from `xmpMM:DocumentID` in XMP metadata
254
+ */
255
+ document_id?: string | undefined;
256
+ /**
257
+ * The format of the source file as a MIME type
258
+ */
259
+ format?: string;
260
+ /**
261
+ * An optional hash of the asset to prevent duplicates
262
+ */
263
+ hash?: string | undefined;
264
+ /**
265
+ * URI to an informational page about the ingredient or its data
266
+ */
267
+ informational_URI?: string | undefined;
268
+ /**
269
+ * Instance ID from `xmpMM:InstanceID` in XMP metadata
270
+ */
271
+ instance_id?: string | undefined;
272
+ /**
273
+ * A [`ManifestStore`] from the source asset extracted as a binary C2PA blob
274
+ *
275
+ * [`ManifestStore`]: crate::ManifestStore
276
+ */
277
+ manifest_data?: ResourceRef | undefined;
278
+ /**
279
+ * Any additional [`Metadata`] as defined in the C2PA spec
280
+ *
281
+ * [`Manifest`]: crate::Manifest
282
+ */
283
+ metadata?: Metadata | undefined;
284
+ /**
285
+ * URI from `dcterms:provenance` in XMP metadata
286
+ */
287
+ provenance?: string | undefined;
288
+ /**
289
+ * Set to `ParentOf` if this is the parent ingredient
290
+ *
291
+ * There can only be one parent ingredient in the ingredients
292
+ */
293
+ relationship?: Relationship & string;
294
+ resources?: ResourceStore;
295
+ /**
296
+ * A thumbnail image capturing the visual state at the time of import
297
+ *
298
+ * A tuple of thumbnail MIME format (i.e. `image/jpeg`) and binary bits of the image
299
+ */
300
+ thumbnail?: ResourceRef | undefined;
301
+ /**
302
+ * A human-readable title, generally source filename
303
+ */
304
+ title: string;
305
+ /**
306
+ * Validation results
307
+ */
308
+ validation_status?: ValidationStatus[] | undefined;
309
+ [k: string]: unknown;
310
+ }
311
+
312
+ /**
313
+ * The Metadata structure can be used as part of other assertions or on its own to reference others
314
+ */
315
+ export interface Metadata {
316
+ data_source?: DataSource | undefined;
317
+ dateTime?: DateT | undefined;
318
+ reference?: HashedUri | undefined;
319
+ reviewRatings?: ReviewRating[] | undefined;
320
+ [k: string]: unknown;
321
+ }
322
+
323
+ /**
324
+ * A description of the source for assertion data
325
+ */
326
+ export interface DataSource {
327
+ /**
328
+ * A list of [`Actor`]s associated with this source
329
+ */
330
+ actors?: Actor[] | undefined;
331
+ /**
332
+ * A human-readable string giving details about the source of the assertion data
333
+ */
334
+ details?: string | undefined;
335
+ /**
336
+ * A value from among the enumerated list indicating the source of the assertion
337
+ */
338
+ type: string;
339
+ [k: string]: unknown;
340
+ }
341
+
342
+ /**
343
+ * Identifies a person responsible for an action
344
+ */
345
+ export interface Actor {
346
+ /**
347
+ * List of references to W3C Verifiable Credentials
348
+ */
349
+ credentials?: HashedUri[] | undefined;
350
+ /**
351
+ * An identifier for a human actor, used when the "type" is `humanEntry.identified`
352
+ */
353
+ identifier?: string | undefined;
354
+ [k: string]: unknown;
355
+ }
356
+
357
+ /**
358
+ * A rating on an Assertion
359
+ *
360
+ * See <https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_claim_review>
361
+ */
362
+ export interface ReviewRating {
363
+ code?: string | undefined;
364
+ explanation: string;
365
+ value: number;
366
+ [k: string]: unknown;
367
+ }
368
+
369
+ /**
370
+ * Resource store to contain binary objects referenced from JSON serializable structures
371
+ */
372
+ export interface ResourceStore {
373
+ label?: string | undefined;
374
+ resources: {
375
+ [k: string]: number[];
376
+ };
377
+ [k: string]: unknown;
378
+ }
379
+
380
+ /**
381
+ * A `ValidationStatus` struct describes the validation status of a specific part of a manifest
382
+ *
383
+ * See <https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_existing_manifests>
384
+ */
385
+ export interface ValidationStatus {
386
+ code: string;
387
+ explanation?: string | undefined;
388
+ url?: string | undefined;
389
+ [k: string]: unknown;
390
+ }
391
+
392
+ /**
393
+ * Holds information about a signature
394
+ */
395
+ export interface SignatureInfo {
396
+ /**
397
+ * human readable issuing authority for this signature
398
+ */
399
+ alg?: SigningAlg | undefined;
400
+ /**
401
+ * The serial number of the certificate
402
+ */
403
+ cert_serial_number?: string | undefined;
404
+ /**
405
+ * human readable issuing authority for this signature
406
+ */
407
+ issuer?: string | undefined;
408
+ /**
409
+ * revocation status of the certificate
410
+ */
411
+ revocation_status?: boolean | undefined;
412
+ /**
413
+ * the time the signature was created
414
+ */
415
+ time?: string | undefined;
416
+ [k: string]: unknown;
417
+ }
418
+
419
+ /**
420
+ * From ManifestDefinition.d.ts
421
+ * A Manifest Definition This is used to define a manifest and is used to build a ManifestStore A Manifest is a collection of ingredients and assertions It is used to define a claim that can be signed and embedded into a file
422
+ */
423
+ export interface ManifestDefinition {
424
+ /**
425
+ * A list of assertions
426
+ */
427
+ assertions?: AssertionDefinition[];
428
+ /**
429
+ * Clam Generator Info is always required with at least one entry
430
+ */
431
+ claim_generator_info?: ClaimGeneratorInfo[];
432
+ /**
433
+ * The format of the source file as a MIME type
434
+ */
435
+ format?: string;
436
+ /**
437
+ * A List of ingredients
438
+ */
439
+ ingredients?: Ingredient[];
440
+ /**
441
+ * Instance ID from `xmpMM:InstanceID` in XMP metadata
442
+ */
443
+ instance_id?: string;
444
+ label?: string | undefined;
445
+ /**
446
+ * A list of redactions - URIs to a redacted assertions
447
+ */
448
+ redactions?: string[] | undefined;
449
+ thumbnail?: ResourceRef | undefined;
450
+ /**
451
+ * A human-readable title, generally source filename
452
+ */
453
+ title?: string | undefined;
454
+ /**
455
+ * Optional prefix added to the generated Manifest Label This is typically Internet domain name for the vendor (i.e. `adobe`)
456
+ */
457
+ vendor?: string | undefined;
458
+ [k: string]: unknown;
459
+ }
460
+
461
+ export interface AssertionDefinition {
462
+ data: unknown;
463
+ label: string;
464
+ [k: string]: unknown;
465
+ }
466
+
467
+ /**
468
+ * Types unique to index.node
469
+ */
470
+ export interface IngredientThumbnail {
471
+ format: string;
472
+ data: Uint8Array;
473
+ }
474
+
475
+ export interface IngredientOptions {
476
+ isParent: boolean;
477
+ thumbnail?: IngredientThumbnail;
478
+ }
479
+
480
+ /**
481
+ * A buffer for the source asset
482
+ */
483
+ export interface SourceBufferAsset {
484
+ // A buffer containing the asset data
485
+ buffer: Buffer;
486
+ // The MIME type of the asset, for instance `image/jpeg`
487
+ mimeType: string;
488
+ }
489
+
490
+ /**
491
+ * A buffer for the destination asset
492
+ */
493
+ export interface DestinationBufferAsset {
494
+ // An initially empty buffer that will be filled with the signed asset
495
+ buffer: Buffer | null;
496
+ }
497
+
498
+ /**
499
+ * A file that can be used either the source or destination
500
+ */
501
+ export interface FileAsset {
502
+ // The path to the asset
503
+ path: string;
504
+ // The optional MIME type of the asset, for instance `image/jpeg`.
505
+ // If not supplied, the MIME type will be inferred from the file extension, if available.
506
+ mimeType?: string;
507
+ }
508
+
509
+ /**
510
+ * A source asset that can either be in memory or on disk
511
+ * This is a workaround since Neon does not support streams
512
+ */
513
+ export type SourceAsset = SourceBufferAsset | FileAsset;
514
+
515
+ /**
516
+ * An destination asset that can either be in memory or on disk
517
+ * This is a workaround since Neon does not support streams
518
+ */
519
+ export type DestinationAsset = DestinationBufferAsset | FileAsset;
520
+
521
+ /**
522
+ * A signer that uses a local certificate and private key to sign data
523
+ */
524
+ export interface LocalSigner {
525
+ sign(data: Buffer): Buffer;
526
+ alg(): SigningAlg;
527
+ certs(): Array<Buffer>;
528
+ reserveSize(): number;
529
+ timeAuthorityUrl(): string | undefined;
530
+ signer(): LocalSigner;
531
+ }
532
+
533
+ /**
534
+ * A signer that uses a callback to sign data.
535
+ */
536
+ export interface CallbackSigner {
537
+ sign(data: Buffer): Promise<Buffer>;
538
+ alg(): SigningAlg;
539
+ certs(): Array<Buffer>;
540
+ reserveSize(): number;
541
+ timeAuthorityUrl(): string | undefined;
542
+ signer(): CallbackSigner;
543
+ }
544
+
545
+ /**
546
+ * @internal
547
+ * Internal type used for Rust/Node.js interop
548
+ */
549
+ export type CallbackSignerConfig = unknown;
550
+
551
+ /*
552
+ * Configuration for an asynchronous signer.
553
+ * This allows signing without passing a private key.
554
+ */
555
+ export interface JsCallbackSignerConfig {
556
+ alg: SigningAlg;
557
+ certs: Buffer[];
558
+ reserveSize: number;
559
+ tsaUrl?: string;
560
+ tsaHeaders?: Array<[string, string]>;
561
+ tsaBody?: Buffer;
562
+ }
563
+
564
+ export interface Builder {
565
+ /**
566
+ * Set the no embed flag of the manifest
567
+ * @param noEmbed The no embed flag of the manifest
568
+ */
569
+ setNoEmbed(noEmbed: boolean): void;
570
+ /**
571
+ * Set the remote URL of the manifest
572
+ * @param url The remote URL of the manifest
573
+ */
574
+ setRemoteUrl(url: string): void;
575
+ /**
576
+ * Add CBOR assertion to the builder
577
+ * @param label The label of the assertion
578
+ * @param assertion The CBOR encoded assertion
579
+ */
580
+ addAssertion(
581
+ label: string,
582
+ assertion: string,
583
+ assertionKind?: ManifestAssertionKind,
584
+ ): void;
585
+ /**
586
+ * Add a resource from a buffer or file
587
+ * @param uri The URI of the resource
588
+ * @param resource The source and format of the resource
589
+ */
590
+ addResource(uri: string, resource: SourceAsset): Promise<void>;
591
+
592
+ /**
593
+ * Add an ingredient from a buffer or file
594
+ * @param ingredientJson The JSON representation of the ingredient
595
+ * @param ingredient The source and format of the ingredient
596
+ */
597
+ addIngredient(
598
+ ingredientJson: string,
599
+ ingredient: SourceAsset,
600
+ ): Promise<void>;
601
+
602
+ /**
603
+ * Convert the Builder into a archive formatted buffer or file
604
+ * @param asset The file or buffer for the archive
605
+ */
606
+ toArchive(asset: DestinationAsset): Promise<void>;
607
+
608
+ /**
609
+ * Sign an asset from a buffer or file
610
+ * @param signer The local signer to use
611
+ * @param source The file or buffer containing the asset
612
+ * @param dest The file or buffer to write the asset to
613
+ * @returns the bytes of the c2pa_manifest that was embedded
614
+ */
615
+ sign(
616
+ signer: LocalSigner,
617
+ input: SourceAsset,
618
+ output: DestinationAsset,
619
+ ): Buffer;
620
+
621
+ /**
622
+ * Sign an asset from a buffer or file asynchronously, using a callback
623
+ * and not passing a private key
624
+ * @param signerConfig The configuration for the signer
625
+ * @param callback The callback function to sign the asset
626
+ * @param source The file or buffer containing the asset
627
+ * @param dest The file or buffer to write the asset to
628
+ * @returns the bytes of the c2pa_manifest that was embedded
629
+ */
630
+ signConfigAsync(
631
+ callback: (data: Buffer) => Promise<Buffer>,
632
+ signerConfig: JsCallbackSignerConfig,
633
+ input: SourceAsset,
634
+ output: DestinationAsset,
635
+ ): Promise<Buffer>;
636
+
637
+ /**
638
+ * Sign an asset from a buffer or file asynchronously, using a
639
+ * CallbackSigner
640
+ * @param callbackSigner The CallbackSigner
641
+ * @param source The file or buffer containing the asset
642
+ * @param dest The file or buffer to write the asset to
643
+ * @returns the bytes of the c2pa_manifest that was embedded
644
+ */
645
+ signAsync(
646
+ callbackSigner: CallbackSigner,
647
+ input: SourceAsset,
648
+ output: DestinationAsset,
649
+ ): Promise<Buffer>;
650
+
651
+ /**
652
+ * Embed a signed manifest into a stream using the LocalSigner
653
+ * @param signer The local signer to use
654
+ * @param source The file or buffer containing the asset
655
+ * @param dest The file or buffer to write the asset to
656
+ * @returns the bytes of the c2pa_manifest that was embedded
657
+ */
658
+ signFile(
659
+ signer: LocalSigner,
660
+ filePath: string,
661
+ output: DestinationAsset,
662
+ ): Buffer;
663
+
664
+ /**
665
+ * Sign an asset from a buffer or file asynchronously, using an
666
+ * IdentityAssertionSigner
667
+ * @param signer The IdentityAssertionSigner
668
+ * @param source The file or buffer containing the asset
669
+ * @param dest The file or buffer to write the asset to
670
+ * @returns the bytes of the c2pa_manifest that was embedded
671
+ */
672
+ identitySignAsync(
673
+ callbackSigner: IdentityAssertionSigner,
674
+ input: SourceAsset,
675
+ output: DestinationAsset,
676
+ ): Promise<Buffer>;
677
+
678
+ /**
679
+ * Getter for the builder's manifest definition
680
+ * @returns The manifest definition
681
+ */
682
+ getManifestDefinition(): ManifestDefinition;
683
+
684
+ /**
685
+ * Update a string property of the manifest
686
+ * @returns The manifest definition
687
+ */
688
+ updateManifestProperty(
689
+ property: string,
690
+ value: string | ClaimVersion,
691
+ ): void;
692
+ }
693
+
694
+ export interface Reader {
695
+ /**
696
+ * Get the JSON representation of the manifest
697
+ */
698
+ json(): ManifestStore;
699
+
700
+ /**
701
+ * Get the remote url of the manifest if this reader obtained the manifest remotely
702
+ */
703
+ remoteUrl(): string;
704
+
705
+ /**
706
+ * Returns true if the the reader was created from an embedded manifest
707
+ */
708
+ isEmbedded(): boolean;
709
+
710
+ /**
711
+ * Write a resource to a buffer or file
712
+ * @param uri The URI of the resource
713
+ * @param filePath The path to the file
714
+ */
715
+ resourceToAsset(uri: string, output: DestinationAsset): Promise<number>;
716
+
717
+ /**
718
+ * Run CAWG validation
719
+ */
720
+ postValidateCawg(): Promise<void>;
721
+ }
722
+
723
+ export interface IdentityAssertionSigner {
724
+ /** Add a IdentityAssertionBuilder to be used when signing the
725
+ * next Manifest
726
+ *
727
+ * IMPORTANT: When sign() is called, the list of
728
+ * IdentityAssertionBuilders will be cleared.
729
+ */
730
+ addIdentityAssertion(
731
+ identityAssertionBuilder: IdentityAssertionBuilder,
732
+ ): void;
733
+ }
734
+
735
+ export interface IdentityAssertionBuilder {
736
+ /**
737
+ * Add assertion labels to consider as referenced_assertions.
738
+ * If any of these labels match assertions that are present in the partial
739
+ * claim submitted during signing, they will be added to the
740
+ * `referenced_assertions` list for this identity assertion.
741
+ * @param referencedAssertions The list of assertion labels to add
742
+ */
743
+ addReferencedAssertions(referencedAssertions: string[]): void;
744
+ /**
745
+ * Add roles to attach to the named actor for this identity assertion.
746
+ * @param roles Named actor roles
747
+ */
748
+ addRoles(roles: string[]): void;
749
+
750
+ /**
751
+ * Get the underlying IdentityAssertionBuilder
752
+ */
753
+ builder(): IdentityAssertionBuilder;
754
+ }
755
+
756
+ export interface Trustmark {
757
+ /**
758
+ * Encode a watermark into an image.
759
+ * @param image image to be watermarked
760
+ * @param strength number between 0 and 1 indicating how strongly the watermark should be applied
761
+ * @param watermark optional bitstring to be encoded, automatically generated if not provided
762
+ * @returns raw pixel data in RGB8 format (width * height * 3 bytes)
763
+ */
764
+ encode(
765
+ image: Buffer,
766
+ strength: number,
767
+ watermark?: string,
768
+ ): Promise<Buffer>;
769
+
770
+ /**
771
+ * Decode a watermark from an image.
772
+ * @param image image to extract the watermark from (must be in a supported image format like JPEG, PNG, etc.)
773
+ */
774
+ decode(image: Buffer): Promise<string>;
775
+ }
776
+
777
+ export interface TrustmarkConfig {
778
+ variant: TrustmarkVariant;
779
+ version: TrustmarkVersion;
780
+ modelPath?: string;
781
+ }
782
+
783
+ // Builder methods
784
+ export function builderNew(): Builder;
785
+ export function builderWithJson(json: string): Builder;
786
+ export function builderSetNoEmbed(noEmbed: boolean): void;
787
+ export function builderSetRemoteUrl(url: string): void;
788
+ export function builderAddAssertion(
789
+ label: string,
790
+ assertion: string,
791
+ assertionKind?: ManifestAssertionKind,
792
+ ): void;
793
+ export function builderAddResource(
794
+ uri: string,
795
+ resource: SourceAsset,
796
+ ): Promise<void>;
797
+ export function builderAddIngredient(
798
+ ingredientJson: string,
799
+ resource: SourceAsset,
800
+ ): Promise<void>;
801
+ export function builderToArchive(asset: DestinationAsset): Promise<void>;
802
+ export function builderFromArchive(asset: SourceAsset): Promise<Builder>;
803
+ export function builderSign(
804
+ signer: LocalSigner,
805
+ input: SourceAsset,
806
+ output: DestinationAsset,
807
+ ): Buffer;
808
+ export function builderSignConfigAsync(
809
+ callback: (data: Buffer) => Promise<Buffer>,
810
+ signerConfig: JsCallbackSignerConfig,
811
+ input: SourceAsset,
812
+ output: DestinationAsset,
813
+ ): Promise<Buffer | { manifest: Buffer; signedAsset: Buffer }>;
814
+ export function builderSignAsync(
815
+ signer: CallbackSigner,
816
+ input: SourceAsset,
817
+ output: DestinationAsset,
818
+ ): Promise<Buffer | { manifest: Buffer; signedAsset: Buffer }>;
819
+ export function builderIdentitySignAsync(
820
+ signer: IdentityAssertionSigner,
821
+ input: SourceAsset,
822
+ output: DestinationAsset,
823
+ ): Promise<Buffer | { manifest: Buffer; signedAsset: Buffer }>;
824
+ export function builderManifestDefinition(): string;
825
+ export function builderUpdateManifestProperty(
826
+ property: string,
827
+ value: string | ClaimVersion,
828
+ ): void;
829
+
830
+ // Reader methods
831
+ export function readerFromAsset(asset: SourceAsset): Promise<Reader>;
832
+ export function readerFromManifestDataAndAsset(
833
+ manifestData: Buffer,
834
+ asset: SourceAsset,
835
+ ): Promise<Reader>;
836
+ export function readerJson(): string;
837
+ export function readerRemoteUrl(): string;
838
+ export function readerIsEmbedded(): boolean;
839
+ export function readerResourceToAsset(
840
+ uri: string,
841
+ output: DestinationAsset,
842
+ ): Promise<number>;
843
+ export function readerPostValidateCawg(): Promise<void>;
844
+
845
+ // Signers
846
+ export function localSignerNew(
847
+ signcert: Buffer,
848
+ pkey: Buffer,
849
+ signingAlg: SigningAlg,
850
+ tsaUrl?: string,
851
+ ): LocalSigner;
852
+ export function localSignerSign(data: Buffer): Buffer;
853
+ export function localSignerAlg(): SigningAlg;
854
+ export function localSignerCerts(): Array<Buffer>;
855
+ export function localSignerReserveSize(): number;
856
+ export function localSignerTimeAuthorityUrl(): string | undefined;
857
+
858
+ export function callbackSignerFromConfig(
859
+ config: CallbackSignerConfig,
860
+ callback: (data: Buffer) => Promise<Buffer>,
861
+ ): CallbackSigner;
862
+ export function callbackSignerConfigFromJs(
863
+ config: JsCallbackSignerConfig,
864
+ ): CallbackSignerConfig;
865
+ export function callbackSignerSign(data: Buffer): Promise<Buffer>;
866
+ export function callbackSignerAlg(): SigningAlg;
867
+ export function callbackSignerCerts(): Array<Buffer>;
868
+ export function callbackSignerReserveSize(): number;
869
+ export function callbackSignerTimeAuthorityUrl(): string | undefined;
870
+
871
+ // CAWG Identity
872
+ export function identitySignerNew(
873
+ signer: CallbackSigner,
874
+ ): IdentityAssertionSigner;
875
+ export function identitySignerAddIdentityAssertion(
876
+ identityAssertionBuilder: IdentityAssertionBuilder,
877
+ ): void;
878
+ export function identityBuilderForCredentialHolder(
879
+ credentialHolder: CallbackSigner,
880
+ ): IdentityAssertionBuilder;
881
+ export function identityBuilderAddReferencedAssertions(
882
+ referenced_assertions: Array<string>,
883
+ ): void;
884
+ export function identityBuilderAddRoles(roles: Array<string>): void;
885
+
886
+ // Trustmark
887
+ export function trustmarkNew(config: TrustmarkConfig): Promise<Trustmark>;
888
+ export function trustmarkEncode(
889
+ image: Buffer,
890
+ strength: number,
891
+ watermark?: string,
892
+ ): Promise<Buffer>;
893
+ export function trustmarkDecode(image: Buffer): Promise<string>;