@contentauth/c2pa-js
    Preparing search index...

    The Builder class supports building C2PA manifests and signing assets.

    Index

    Methods

    • Add an assertion to the manifest under the given label.

      Parameters

      • label: string

        The assertion label (reverse-domain format).

      • data: unknown

        The assertion data (any JSON-serializable value).

      Returns Promise<void>

    • 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.

      Parameters

      • ingredientDefinition: Ingredient

        Ingredient definition.

      • format: string

        Format of the ingredient.

      • blob: Blob

        Blob of the ingredient's bytes.

      Returns Promise<void>

    • 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.

      Parameters

      • uri: string

        JUMBF URI of the assertion to redact.

      • reason: string

        The C2paReason for the redaction.

      Returns Promise<void>

    • Add a resource to the builder's resource store with an ID and blob of the resource's bytes.

      Parameters

      • resourceId: string

        ID associated with the resource being added.

      • blob: Blob

        Blob of the resource's bytes.

      Returns Promise<void>

    • 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 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.

      Parameters

      • keep: (action: Action) => boolean

        The action is retained when the predicate returns true.

      Returns Promise<void>

    • 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.

      Parameters

      • keepAction: (action: Action) => boolean

        The action is retained when the predicate returns true.

      • rescueIngredient: (ingredient: Ingredient) => boolean

        Can rescue an otherwise-orphaned ingredient (and the action referencing it) by returning true.

      Returns Promise<void>

    • 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 Builder.filterActions first if you are also removing actions: the keep-set is computed from whatever actions currently remain.

      Parameters

      • rescue: (ingredient: Ingredient) => boolean

        Can rescue an otherwise-orphaned ingredient by returning true.

      Returns Promise<void>

    • Dispose of this Builder, freeing the memory it occupied and preventing further use. Call this whenever the Builder is no longer needed.

      Returns Promise<void>

    • Sets the state of the no_embed flag. To skip embedding a manifest (e.g. for the remote-only case), set this to true.

      Parameters

      • noEmbed: boolean

        Value to set the no_embed flag.

      Returns Promise<void>

    • Sets the remote URL for a remote manifest. The manifest is expected to be available at this location.

      Parameters

      • url: string

        URL pointing to the location the remote manifest will be stored.

      Returns Promise<void>

    • Set a thumbnail from a blob to be included in the manifest. The blob should represent the asset being signed.

      Parameters

      • format: string

        Format of the thumbnail

      • blob: Blob

        Blob of the thumbnail bytes

      Returns Promise<void>

    • Sign an asset.

      Parameters

      • signer: Signer

        The signer to use for the manifest's claim signature.

      • format: string

        The format (MIME type) of the asset.

      • blob: Blob

        The asset bytes.

      • Optionaloptions: SignOptions

        Optional SignOptions. identityAssertions attaches one or more CAWG identity assertions (cawg.identity) to the manifest.

      Returns Promise<Uint8Array<ArrayBuffer>>

      Docs coming soon

    • Sign an asset and get both the signed asset bytes and the manifest bytes.

      Parameters

      • signer: Signer

        The signer to use for the manifest's claim signature.

      • format: string

        The format (MIME type) of the asset.

      • blob: Blob

        The asset bytes.

      • Optionaloptions: SignOptions

        Optional SignOptions. identityAssertions attaches one or more CAWG identity assertions (cawg.identity) to the manifest.

      Returns Promise<ManifestAndAssetBytes>

      Docs coming soon

    • 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.

      Parameters

      • transform: (actions: Action[]) => Action[]

        Receives one assertion's actions and returns its full replacement list.

      Returns Promise<void>