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

    Exposes methods for building C2PA manifests and signing assets.

    interface Builder {
        addAction: (action: Action) => Promise<void>;
        addAssertion: (label: string, data: unknown) => Promise<void>;
        addIngredient: (ingredientDefinition: Ingredient) => Promise<void>;
        addIngredientFromBlob: (
            ingredientDefinition: Ingredient,
            format: string,
            blob: Blob,
        ) => Promise<void>;
        addRedaction: (uri: string, reason: string) => Promise<void>;
        addResourceFromBlob: (resourceId: string, blob: Blob) => Promise<void>;
        filterActions: (keep: (action: Action) => boolean) => Promise<void>;
        filterActionsAndIngredients: (
            keepAction: (action: Action) => boolean,
            rescueIngredient: (ingredient: Ingredient) => boolean,
        ) => Promise<void>;
        filterIngredients: (
            rescue: (ingredient: Ingredient) => boolean,
        ) => Promise<void>;
        free: () => Promise<void>;
        getDefinition: () => Promise<ManifestDefinition>;
        setIntent: (intent: BuilderIntent) => Promise<void>;
        setNoEmbed: (noEmbed: boolean) => Promise<void>;
        setRemoteUrl: (url: string) => Promise<void>;
        setThumbnailFromBlob: (format: string, blob: Blob) => Promise<void>;
        sign: (
            signer: Signer,
            format: string,
            blob: Blob,
        ) => Promise<Uint8Array<ArrayBuffer>>;
        signAndGetManifestBytes: (
            signer: Signer,
            format: string,
            blob: Blob,
        ) => Promise<ManifestAndAssetBytes>;
        toArchive: () => Promise<Uint8Array<ArrayBuffer>>;
        updateActions: (
            transform: (actions: Action[]) => Action[],
        ) => Promise<void>;
    }
    Index

    Properties

    addAction: (action: Action) => Promise<void>

    Add an action to the manifest's actions assertion.

    Type Declaration

      • (action: Action): Promise<void>
      • Parameters

        • action: Action

          Object representing the action to be added.

        Returns Promise<void>

    addAssertion: (label: string, data: unknown) => Promise<void>

    Add an assertion to the manifest under the given label.

    Type Declaration

      • (label: string, data: unknown): Promise<void>
      • Parameters

        • label: string

          The assertion label (reverse-domain format).

        • data: unknown

          The assertion data (any JSON-serializable value).

        Returns Promise<void>

    addIngredient: (ingredientDefinition: Ingredient) => Promise<void>

    Add an ingredient to the builder from a definition only.

    Type Declaration

    addIngredientFromBlob: (
        ingredientDefinition: Ingredient,
        format: string,
        blob: Blob,
    ) => 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.

    Type Declaration

      • (ingredientDefinition: Ingredient, format: string, blob: Blob): Promise<void>
      • Parameters

        • ingredientDefinition: Ingredient

          Ingredient definition.

        • format: string

          Format of the ingredient.

        • blob: Blob

          Blob of the ingredient's bytes.

        Returns Promise<void>

    addRedaction: (uri: string, reason: string) => 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.

    Type Declaration

      • (uri: string, reason: string): Promise<void>
      • Parameters

        • uri: string

          JUMBF URI of the assertion to redact.

        • reason: string

          The C2paReason for the redaction.

        Returns Promise<void>

    addResourceFromBlob: (resourceId: string, blob: Blob) => Promise<void>

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

    Type Declaration

      • (resourceId: string, blob: Blob): Promise<void>
      • Parameters

        • resourceId: string

          ID associated with the resource being added.

        • blob: Blob

          Blob of the resource's bytes.

        Returns Promise<void>

    filterActions: (keep: (action: Action) => boolean) => 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.

    Type Declaration

      • (keep: (action: Action) => boolean): Promise<void>
      • Parameters

        • keep: (action: Action) => boolean

          The action is retained when the predicate returns true.

        Returns Promise<void>

    filterActionsAndIngredients: (
        keepAction: (action: Action) => boolean,
        rescueIngredient: (ingredient: Ingredient) => boolean,
    ) => 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.

    Type Declaration

      • (
            keepAction: (action: Action) => boolean,
            rescueIngredient: (ingredient: Ingredient) => boolean,
        ): Promise<void>
      • 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>

    filterIngredients: (
        rescue: (ingredient: Ingredient) => boolean,
    ) => 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.

    Type Declaration

      • (rescue: (ingredient: Ingredient) => boolean): Promise<void>
      • Parameters

        • rescue: (ingredient: Ingredient) => boolean

          Can rescue an otherwise-orphaned ingredient by returning true.

        Returns Promise<void>

    free: () => Promise<void>

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

    getDefinition: () => Promise<ManifestDefinition>

    Gets the current manifest definition held by the builder.

    Type Declaration

    setIntent: (intent: BuilderIntent) => Promise<void>

    Sets the builder "intent."

    Additional documentation coming soon.

    setNoEmbed: (noEmbed: boolean) => 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.

    Type Declaration

      • (noEmbed: boolean): Promise<void>
      • Parameters

        • noEmbed: boolean

          Value to set the no_embed flag.

        Returns Promise<void>

    setRemoteUrl: (url: string) => Promise<void>

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

    Type Declaration

      • (url: string): Promise<void>
      • Parameters

        • url: string

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

        Returns Promise<void>

    setThumbnailFromBlob: (format: string, blob: Blob) => Promise<void>

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

    Type Declaration

      • (format: string, blob: Blob): Promise<void>
      • Parameters

        • format: string

          Format of the thumbnail

        • blob: Blob

          Blob of the thumbnail bytes

        Returns Promise<void>

    sign: (
        signer: Signer,
        format: string,
        blob: Blob,
    ) => Promise<Uint8Array<ArrayBuffer>>

    Sign an asset.

    Docs coming soon

    signAndGetManifestBytes: (
        signer: Signer,
        format: string,
        blob: Blob,
    ) => Promise<ManifestAndAssetBytes>

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

    Docs coming soon

    toArchive: () => Promise<Uint8Array<ArrayBuffer>>

    Save the builder into .c2pa format. This "archive" can be added to as an ingredient with addIngredientFromBlob

    Type Declaration

      • (): Promise<Uint8Array<ArrayBuffer>>
      • Returns Promise<Uint8Array<ArrayBuffer>>

        A builder archive in application/c2pa format.

    updateActions: (transform: (actions: Action[]) => Action[]) => Promise<void>

    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.

    Type Declaration

      • (transform: (actions: Action[]) => Action[]): Promise<void>
      • Parameters

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

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

        Returns Promise<void>