import { Signer, SignOptions } from './signer.js'; import { Action, BuilderIntent, C2paReason, Ingredient, ManifestDefinition } from '@contentauth/c2pa-types'; import { Context } from '@contentauth/c2pa-utilities'; import { C2pa } from './c2pa.js'; /** A property {@link Builder.updateManifestProperty} can set. */ export type ManifestProperty = 'vendor' | 'title' | 'format' | 'instance_id' | 'label' | 'claim_version'; /** A claim version. */ export type ClaimVersion = 1 | 2; export interface ManifestAndAssetBytes { manifest: Uint8Array; asset: Uint8Array; } /** * The `Builder` class supports building C2PA manifests and signing assets. */ export declare class Builder { #private; private constructor(); /** * Create a {@link Builder} with a minimal manifest definition as its initial state. * * @param c2pa The `C2pa` instance (from {@link createC2pa}) to create this builder on. * @param context Optional `Context` configuring this builder's behavior. * @returns A {@link Builder} object. */ static new(c2pa: C2pa, context?: Context): Promise; /** * Create a {@link Builder} from a {@link ManifestDefinition}. * * @param c2pa The `C2pa` instance (from {@link createC2pa}) to create this builder on. * @param definition The {@link ManifestDefinition} to be used as the builder's initial state. * @param context Optional `Context` configuring this builder's behavior. * @returns A {@link Builder} object. */ static fromDefinition(c2pa: C2pa, definition: ManifestDefinition, context?: Context): Promise; /** * Create a {@link Builder} from a builder archive (created from {@link Builder.toArchive}). * * @param c2pa The `C2pa` instance (from {@link createC2pa}) to create this builder on. * @param archive Builder archive as a blob. * @param context Optional `Context` configuring this builder's behavior. * @returns A {@link Builder} object. */ static fromArchive(c2pa: C2pa, archive: Blob, context?: Context): Promise; /** * Sets the builder "intent." * * @todo Additional documentation coming soon. * * @param intent */ setIntent(intent: BuilderIntent): Promise; /** * Add an action to the manifest's actions assertion. * * @param action Object representing the action to be added. */ addAction(action: Action): Promise; /** * Add an assertion to the manifest under the given label. * * @param label The assertion label (reverse-domain format). * @param data The assertion data (any JSON-serializable value). */ addAssertion(label: string, data: unknown): Promise; /** * Replaces the data of every assertion with an exact matching label. * `transform` runs once per matching assertion in manifest order. Other assertion * fields and positions are preserved. A missing label is a no-op. * Returning null or undefined leaves that assertion unchanged. * The replacement data must be JSON-serializable and may fail validation at signing time. * * @param label The exact assertion label to update. * @param transform Receives the current data and returns its replacement. */ updateAssertion(label: string, transform: (data: unknown) => unknown): Promise; /** * Redact an assertion from an ingredient manifest. * * Adds the URI to the builder's redaction list and appends a `c2pa.redacted` action * with the given reason, as required by the C2PA spec. * * @param uri JUMBF URI of the assertion to redact. * @param reason The {@link C2paReason} for the redaction. */ addRedaction(uri: string, reason: C2paReason): Promise; /** * Sets the remote URL for a remote manifest. The manifest is expected to be available at this location. * * @param url URL pointing to the location the remote manifest will be stored. */ setRemoteUrl(url: string): Promise; /** * Sets the state of the no_embed flag. * To skip embedding a manifest (e.g. for the remote-only case), set this to `true`. * * @param noEmbed Value to set the no_embed flag. */ setNoEmbed(noEmbed: boolean): Promise; /** * Updates a (known) property in the manifest definition. * Rejects an unsupported property or value type, * or while a sign on this builder is pending. */ updateManifestProperty(property: ManifestProperty, value: string | ClaimVersion): Promise; /** * Set a thumbnail from a blob to be included in the manifest. The blob should represent the asset being signed. * * @param format Format of the thumbnail * @param blob Blob of the thumbnail bytes */ setThumbnailFromBlob(format: string, blob: Blob): Promise; /** * Experimental. * Retains only the actions for which `keep` returns true. * * The inception action, `c2pa.created` or `c2pa.opened`, is always kept regardless of `keep`, * and is moved to index 0 if needed, so the manifest stays valid per the C2PA spec. Sets * `allActionsIncluded = false` when anything is removed. This does not touch ingredients. * Call {@link Builder.filterIngredients}, using `filterIngredients(() => false)` to drop all * orphans, afterwards if you also want to drop ingredients now orphaned by the removed * actions. * * Unlike the Node binding, Neon, which can invoke the JS predicate synchronously from Rust, * the WASM builder lives in a Web Worker. A predicate closure can't be called across the * worker boundary, so we evaluate it here on the main thread and send the resulting indices * to the worker, where WASM applies the equivalent index-based filter. The action/ingredient * ordering here must match what WASM iterates. See `filterActionsAt` and `filterIngredientsAt`. * * @param keep The action is retained when the predicate returns true. */ filterActions(keep: (action: Action) => boolean): Promise; /** * Experimental. * Retains ingredients, then rewrites positional ingredient references so linked actions * stay valid. * * An ingredient is kept if it is referenced by a current action, is a `parentOf` ingredient, * or `rescue` returns true for it. `rescue` therefore only ever rescues an otherwise-orphaned * ingredient. It can never drop a referenced or lineage ingredient. Call * {@link Builder.filterActions} first if you are also removing actions: the keep-set is * computed from whatever actions currently remain. * * @param rescue Can rescue an otherwise-orphaned ingredient by returning true. */ filterIngredients(rescue: (ingredient: Ingredient) => boolean): Promise; /** * Experimental. * Retains actions and ingredients together in one step. * * `rescueIngredient` is evaluated for every ingredient first; any action referencing an * ingredient it would rescue is force-kept regardless of `keepAction`. * * @param keepAction The action is retained when the predicate returns true. * @param rescueIngredient Can rescue an otherwise-orphaned ingredient (and the action * referencing it) by returning true. */ filterActionsAndIngredients(keepAction: (action: Action) => boolean, rescueIngredient: (ingredient: Ingredient) => boolean): Promise; /** * Replaces the actions in the `c2pa.actions`/`c2pa.actions.v2` assertions. * * A manifest can carry more than one actions assertion (the created-list and * gathered-list entries are distinct assertions). `transform` is therefore * invoked once per actions assertion, in positional order, with that * assertion's own actions. * * A no-op if there is no actions assertion. Use `addAction` for those. * * The returned list is written back as is. * `transform` can therefore produce an actions array that fails * validation at signing time, for example by removing the inception action * (`c2pa.created`/`c2pa.opened`) or moving it out of first position. * * @param transform Receives one assertion's actions and returns its full replacement list. */ updateActions(transform: (actions: Action[]) => Action[]): Promise; /** * Add an ingredient to the builder from a definition only. * * @param ingredientDefinition {@link Ingredient} definition. */ addIngredient(ingredientDefinition: Ingredient): Promise; /** * Add an ingredient to the builder from a definition, format, and blob. * Values specified in the ingredient definition will be merged with the ingredient, and these values take precendence. * * @param ingredientDefinition {@link Ingredient} definition. * @param format Format of the ingredient. * @param blob Blob of the ingredient's bytes. */ addIngredientFromBlob(ingredientDefinition: Ingredient, format: string, blob: Blob): Promise; /** * Add a resource to the builder's resource store with an ID and blob of the resource's bytes. * * @param resourceId ID associated with the resource being added. * @param blob Blob of the resource's bytes. */ addResourceFromBlob(resourceId: string, blob: Blob): Promise; /** * Gets the current manifest definition held by the builder. * * @returns The {@link ManifestDefinition} held by the builder. */ getDefinition(): Promise; /** * Save the builder into .c2pa format. * This "archive" can be added to as an ingredient with {@link addIngredientFromBlob} * * @returns A builder archive in application/c2pa format. */ toArchive(): Promise>; /** * Sign an asset. * * @param signer The signer to use for the manifest's claim signature. * @param format The format (MIME type) of the asset. * @param blob The asset bytes. * @param options Optional {@link SignOptions}. `identityAssertions` attaches * one or more CAWG identity assertions (`cawg.identity`) to the manifest. * * @todo Docs coming soon */ sign(signer: Signer, format: string, blob: Blob, options?: SignOptions): Promise>; /** * Sign an asset and get both the signed asset bytes and the manifest bytes. * * @param signer The signer to use for the manifest's claim signature. * @param format The format (MIME type) of the asset. * @param blob The asset bytes. * @param options Optional {@link SignOptions}. `identityAssertions` attaches * one or more CAWG identity assertions (`cawg.identity`) to the manifest. * * @todo Docs coming soon */ signAndGetManifestBytes(signer: Signer, format: string, blob: Blob, options?: SignOptions): Promise; /** * Dispose of this Builder, freeing the memory it occupied and preventing further use. Call this whenever the Builder is no longer needed. */ free(): Promise; } //# sourceMappingURL=builder.d.ts.map