import { BaseError } from 'make-error'; import { WorkerPool } from 'workerpool'; import { WorkerPoolOptions } from 'workerpool'; export declare class ActionsAssertion extends Assertion { #private; protected readonly assertion: IActionAssertionData; static UNCATEGORIZED_ID: string; constructor(claim: Claim, data: IActionAssertionData); /** * Gets the list of actions from the claim's action assertion and runs them through the * dictionary to get information needed to render the associated categories in the * "Edits and activity" section. */ getCategories(locale?: string, iconVariant?: IconVariant): Promise; } export declare class AdobeCryptoAddressesAssertion extends Assertion { protected readonly assertion: IAdobeCryptoAddressesAssertionData; constructor(claim: Claim, data: IAdobeCryptoAddressesAssertionData); } export declare class AdobeDictionaryAssertion extends Assertion { protected readonly assertion: IAdobeDictionaryAssertionData; constructor(claim: Claim, data: IAdobeDictionaryAssertionData); } export declare class Assertion { readonly claim: Claim; readonly label: string; protected readonly assertion: IAssertionData; constructor(claim: Claim, data: IAssertionData); get data(): any; } export declare class AssertionFactory { readonly claim: Claim; readonly label: string; readonly assertion: IAssertionData; constructor(claim: Claim, data: IAssertionData); get data(): any; static from(claim: Claim, assertion: IAssertionData): Assertion; } export declare enum AssertionLabel { Actions = "c2pa.actions", AdobeCryptoAddresses = "adobe.crypto.addresses", AdobeDictionary = "adobe.dictionary", CreativeWork = "stds.schema-org.CreativeWork" } export declare class Asset { #private; readonly parent: Claim; readonly data: IAssetData; readonly type: string | undefined; readonly arrayBuffer: ArrayBuffer | undefined; constructor(parent: Claim, data: IAssetData); get blob(): Blob | undefined; computeHash(): Promise; /** * Generates a blob URL from the thumbnail data * * @returns An object with a `url` and `dispose` function */ generateThumbnailUrl(): Promise; } /** * Class that represents a claim in the asset's provenance data. * * @see {@link https://c2pa.org/public-draft/#_overview_4} * * @public */ export declare class Claim { readonly provenance: ImageProvenance; /** * An identifier string for this claim that is unique per provenance chain */ readonly id: string; /** * The underlying data for this claim, provided by the toolkit */ readonly data: IClaimData; /** * The collection of assertions linked to this claim */ readonly assertions: Map; /** * The collection of ingredients that this claim includes */ readonly ingredients: Ingredient[]; /** * The acquisition asset for this claim if it exists */ readonly asset: Asset | undefined; /** * Create a new `Claim` object. Typically these will be created by the SDK. * * @param provenance - The provenance instance this claim belongs to * @param data - The raw data for this claim from the toolkit * * @internal */ constructor(provenance: ImageProvenance, id: string, data: IClaimData); /** * Searches the claim's assertions for one matching the supplied label * * @param label - The label of the assertion you want to retrieve */ findAssertion(label: AssertionLabel | string): Assertion | null; /** * Gets the parent of this claim * * @remarks * This will give the claim that contains the ingredient that this claim belongs to */ get parent(): Claim | undefined; /** * Gets the acquisition thumbnail for this claim if it exists */ get thumbnail(): IThumbnailData | null | undefined; /** * Returns the string used to identify the item that recorded this claim (application, device, etc.) */ get recorder(): string; /** * Formats the `recorder` string * * @param format - The format to parse the string into * @returns The formatted string, if specified */ formatRecorder(format?: RecorderFormat): string; /** * Gets the title of the acquisition asset for this claim if it exists (e.g. filename) */ get title(): string | undefined; /** * Gets the signature information (issuer, date) for this claim */ get signature(): ISignature; /** * Any errors coming back from the toolkit */ get errors(): IError[]; } /** * The entry class for the SDK * * @remarks * You can create one instance of this class to process multiple images. * At a minimum, you will have to instantiate it with the URLs of the WASM and the worker: * ```ts * const sdk = new ContentAuth({ wasmSrc, workerSrc }); * const provenance = await sdk.processImage(imageUrl); * ``` * * @public */ export declare class ContentAuth { #private; /** * Creates a new ContentAuth instace that can be used to verify and read * metadata from multiple assets. * * @param cfg - Configuration object for overriding the defaults */ constructor(cfg?: Partial); /** * Processes image data from a `Blob` as input * @param data - The binary data of the image */ processImage(data: Blob): Promise; /** * Processes image data from a `File` as input. Useful for file uploads/drag-and-drop. * @param data - The binary data of the image */ processImage(file: File): Promise; /** * Processes image data from a URL * * @remarks * Note: The file referenced by the URL must either be have the same * {@link https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy | origin} * as the site referencing this code, or it needs to have * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS | CORS} enabled on the resource. * * @param url - The URL of the image to process */ processImage(url: string): Promise; /** * Processes an image from an HTML image element (``). * * @remarks * This is useful if you want to process the image returned by a `document.querySelector` call * * @param element - DOM element of the image to process */ processImage(element: HTMLImageElement): Promise; processImage(input: ImageInput): Promise; /** * Convenience function to process multiple images at once * * @param inputs Array of inputs to pass to `processImage` */ processImages(inputs: ImageInput[]): Promise; /** * Allows you to generate a report from `application/c2pa` manifest data * @param source The source image this manifest data is attributed to * @param c2paData The `application/c2pa` manifest data */ processC2pa(source: Source, c2paData: Blob): Promise; /** * Generates a URL that pre-loads the `assetUrl` into the Content Authenticity Verify site * for deeper inspection by users. * * @param assetUrl The URL of the asset you want to view in Verify */ static generateVerifyUrl(assetUrl: string): string; /** * Waits until all scheduled tasks have completed, then terminates the pool */ destroy(): Promise; } export declare class CreativeWorkAssertion extends Assertion { protected readonly assertion: ICreativeWorkAssertionData; constructor(claim: Claim, data: ICreativeWorkAssertionData); /** * Gets the author that is the producer from the CreativeWork assertion */ get producer(): ICreativeWorkAuthor | undefined; /** * Gets any social accounts that have been added */ get socialAccounts(): ICreativeWorkAuthor[]; } declare class DictionaryUrlNotFoundError extends BaseError { constructor(); } /** * Handles downloading of any assets * * @public */ export declare class Downloader { #private; constructor(pool: WorkerPool, opts?: Partial); /** * Wrapper around `fetch` to download an asset * * @remarks * This has convenience logic for range requests * * @param url - The URL to fetch * @param fetchOptions - Options for this particular request */ static download(url: string, fetchOptions?: Partial): Promise; /** * This allows us to inspect the image to see if the header contains C2PA data * * @remarks * We will request a download to the server requesting the first `inspectSize` bytes. From there: * - if the server responds with a payload less than the content-length, we will inspect that chunk and * download the rest if the content-type matches and that chunk contains metadata * - if it responds with a payload equal to or greater than the content-length, we will inspect that the * content type matches, scan the chunk, and return the data * - we'll return `null` if the content-type is invalid or if CAI data does not exist * * @param url - The URL to fetch */ inspect(url: string): Promise; /** * Fetches a JSON payload and caches it, using the requested URL as the key * * @param url - The URL to fetch and cache */ static cachedGetJson(url: string): Promise; } declare namespace Errors { export { IncompatibleBrowserError, MissingWasmSourceError, MissingWorkerSourceError, InvalidWorkerSourceError, InvalidInputError, InvalidMimeTypeError, UrlFetchError, DictionaryUrlNotFoundError } } export { Errors } declare interface IActionAssertionData extends IAssertionData { label: AssertionLabel.Actions; data: { actions: { action: string; parameters: string; }[]; }; } declare interface IAdobeCryptoAddressesAssertionData extends IAssertionData { label: AssertionLabel.AdobeCryptoAddresses; data: { [type: string]: string[]; }; } declare interface IAdobeDictionaryAssertionData extends IAssertionData { label: AssertionLabel.AdobeDictionary; data: { url: string; }; } declare interface IAssertionData { /** * Label for the assertion (i.e. cai.identity.v1) */ label: string; /** * Any value in JSON format (must match format for known assertions) */ data: any; } declare interface IAssetData { /** * A human readable title, generally source filename */ title: string; /** * The format of the source file as a mime type or extension */ format: string; /** * Document ID from `xmpMM:DocumentID` in XMP metadata */ document_id: string; /** * Instance ID from `xmpMM:InstanceID` in XMP metadata */ instance_id: string; /** * Binary thumbnail of the image */ thumbnail?: IThumbnailData | null | undefined; } /** * Interface of the claim data structure returned from the toolkit */ declare interface IClaimData { assertions: IAssertionData[]; asset: IAssetData; ingredients: IIngredientData[]; /** * A string, compatible with XMP's `stEvt:softwareAgent`, for including the name and version of the claims recorder * that created the claim. */ recorder: string; signature: ISignatureData; /** * Domain name type organization identifier (i.e. `adobe`) */ vendor: string; /** * Errors on this claim (from the toolkit) */ errors: IError[] | null | undefined; } /** * Configuration options for the `ContentAuth` constructor */ export declare interface IConfig { /** * Either the URL of the WebAssembly binary or a compiled WebAssembly module */ wasmSrc: WebAssembly.Module | string | null; /** * The URL of the web worker JavaScript file */ workerSrc: string | null; /** * Options for the web worker pool * @see {@link https://github.com/josdejong/workerpool#pool} */ poolOptions?: Partial; /** * Options for the asset downloader */ downloadOptions?: Partial; } declare enum IconVariant { Light = "light", Dark = "dark" } declare interface ICreativeWorkAssertionData extends IAssertionData { label: AssertionLabel.AdobeDictionary; data: { '@context': string; '@type': string; author: ICreativeWorkAuthor[]; }; } declare interface ICreativeWorkAuthor { '@type': string; '@id'?: string; credential?: ICreativeWorkAuthorCredential[]; identifier: string; name: string; } declare interface ICreativeWorkAuthorCredential { url: string; } export declare interface IDownloadOptions { /** * The number of bytes at the start of the image to check for C2PA metadata * before downloading the whole image (defaults to 64k) */ inspectSize: number; } export declare interface IError { code: string; description: string; } export declare interface IFetchOptions { /** * The range byte to start from (defaults to 0) */ rangeStart: number; /** * The range byte to end at (defaults to end of content) */ rangeEnd: number | undefined; /** * Options passed to the browser's `fetch` method */ fetchConfig: RequestInit; } declare interface IIngredientData extends IAssetData { /** * If this ingredient has a claim, this holds the reference to the claim info */ provenance: string | null | undefined; /** * `true` if this is a parent asset */ is_parent: boolean | null | undefined; /** * Reviews on the CAI data */ reviews: IReview[] | null | undefined; /** * Errors on this ingredient (from the toolkit) */ errors: IError[] | null | undefined; } export declare type ImageInput = string | Blob | File | HTMLImageElement; /** * A class that holds the C2PA provenance data of an asset * * @see {@link https://c2pa.org/public-draft/#_core_aspects_of_c2pa} * * @public */ export declare class ImageProvenance { #private; /** * The list of claims contained in this provenance data */ readonly claims: Map; /** * The original asset that this provenance is a part of */ readonly source: Source; /** * Create a new `ImageProvenance` object. Typically this will only be returned from * `ContentAuth` calls. * * @param toolkitResult - The result from the WebAssembly toolkit (@contentauth/ask) * * @internal */ constructor(toolkitResult: any, source: Source); /** * This resolves an ID of either a claim or an ingredient so that we can identify it globally. * * @remarks * We should be able to access every claim/ingredient in one of two ways: * * - Claims should be able to be accessed by their ID, e.g. `mEiBD6JdB/na1TIxvcw9HMkbo6stDkkiNFcy8Lsp3oW5yOw` * - Ingredients should be able to be accessed by their associated claim ID and index, * e.g. `mEiBD6JdB/na1TIxvcw9HMkbo6stDkkiNFcy8Lsp3oW5yOw[0]` * * @param id - the id of the claim or ingredient to get */ resolveId(id: string): Claim | Ingredient | undefined; /** * Returns `true` if C2PA metadata exists on this image */ get exists(): boolean; /** * Gets the active (latest) claim in the provenance data */ get activeClaim(): Claim | undefined; /** * Returns the raw claim data from the WebAssembly toolkit */ get data(): any; /** * Any errors coming back from the toolkit */ get errors(): IError[]; } declare interface IMetadata { /** * The filename of the original asset, if it exists/can be derived */ filename: string; } declare class IncompatibleBrowserError extends BaseError { constructor(); } export declare class Ingredient extends Asset { /** * A unique identifier for this ingredient */ readonly id: string; /** * The ingredient data from the toolkit */ readonly data: IIngredientData; constructor(parent: Claim, id: string, data: IIngredientData); get claim(): Claim | undefined; get asset(): this; get title(): string; /** * Any errors coming back from the toolkit */ get errors(): IError[]; } declare class InvalidInputError extends BaseError { constructor(); } declare class InvalidMimeTypeError extends BaseError { mimeType: string; constructor(mimeType: string); } declare class InvalidWorkerSourceError extends BaseError { url: string; response: Response | null; originalError: TypeError | null; constructor(url: string, res: Response | null, err?: TypeError); } /** * This is based on the [Schema.org `Review` type](https://schema.org/Review). */ declare interface IReview { code: string; explanation: string; /** * If the ingredient asset has a claim, then it's dcterms:provenance (which is the reference to the ingredient's * claim signature) shall be copied into a ingredient's data with the same name and value. Prior to copying, it is * recommended that, if it is technically able to, the processor validate the hashes provided in the claim and * provide a review of them, based on the Review schema. The most important aspect will be the reviewRating which * is either 1 (did not validate) or 5 (successfully validated). At this time, no other values are permitted. */ value: number; } declare interface ISignature { /** * The entity that issued the signature used to sign the C2PA manifest */ issuer: string; /** * The JavaScript `Date` representation corresponding to the signature time (in the local time zone) */ date: Date; /** * The original ISO-8601 date string that was parsed from the signature (in UTC) */ isoDateString: string; } declare interface ISignatureData { issuer: string; time: string; } export declare interface IThumbnail { url: string | null; dispose?: () => void; } declare interface IThumbnailData { format: ValidFormats; image: number[]; } declare class MissingWasmSourceError extends BaseError { constructor(); } declare class MissingWorkerSourceError extends BaseError { constructor(); } export declare enum RecorderFormat { Raw = 0, ProgramNameAndVersion = 1 } /** * Represents the asset that the provenance data is extracted from */ export declare class Source { #private; /** * The binary data of the source asset */ readonly blob: Blob; /** * Any metadata that we know/can derive from the asset (e.g. filename) */ readonly metadata: Partial; /** * Creates a new source instance * * @param blob - The binary data of the source asset * @param metadata - Any additional metdata to include that we know up front * * @internal */ constructor(blob: Blob, metadata?: Partial); /** * Gets the mime type of the asset */ get type(): string; /** * Gets the filename of the asset, if it is known or able to be derived */ get filename(): string | undefined; /** * Determines if the source is valid */ isValid(): boolean; /** * Gets the binary data of this asset as an array buffer */ arrayBuffer(): Promise; /** * Gets the size of this asset (in bytes) */ size(): Promise; computeHash(): Promise; /** * Generates a blob URL from the source data * * @returns An object with a `url` and `dispose` function */ generateUrl(): Promise; /** * Attempts to get additional metadata for this source from its backing `File` object, if available * * @param file - The source data as a `File` object */ static metadataFromFile(file: File): { filename: string; }; /** * Attemps to derive additional metadata (namely `filename`) from the URL * * @param url - The URL of the source data */ static metadataFromUrl(url: string): { filename: string; }; } declare class UrlFetchError extends BaseError { url: string; response: Response | null; originalError: TypeError | null; constructor(url: string, res: Response | null, err?: TypeError); } /** * Handles validation of input before processing it for C2PA metadata * * @public */ export declare class Validator { #private; static readonly VALID_MIME_TYPES: string[]; static readonly DEFAULT_DETECTION_LENGTH = 65535; constructor(pool: WorkerPool, detectionLength: number | undefined); /** * Sanitizes mime type strings for proper file type checking * * @remarks * We need to do this since some Content-Types can coming in such as `image/jpeg; charset=utf-8`. * * @param type - The mime type of the asset */ static sanitizeMimeType(type: string): string; /** * Checks if the asset has a mime type that is compatible with C2PA * * @param type - The mime type of the asset to check */ static isValidMimeType(type: string): boolean; /** * Scans an individual binary chunk for a C2PA metadata marker * * @param chunk - the chunk to check for the metadata marker * @param shouldTransfer - `true` to pass this chunk as a transferable object */ scanChunk(chunk: ArrayBuffer, shouldTransfer?: boolean): Promise; /** * Scans a buffer/Blob for a C2PA metadata marker * * @remarks * This will automatically handle both a `ArrayBuffer` or a `Blob` as input * and automatically decide if it should be passed as a transferable object or not. * It will then pass it to `scanChunk` for the actual processing. * * @param input - The buffer/blob to scan */ scanInput(input: ArrayBuffer | Blob): Promise; } declare type ValidFormats = 'image/jpeg' | 'image/png'; export { WorkerPoolOptions } export { }