Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 43 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,100 @@
# c2pa-js

> [!NOTE]
> Looking for the old `c2pa-js` repo? It's available [here](https://github.com/contentauth/c2pa-js-legacy) as `c2pa-js-legacy`. Those packages are now deprecated and implementors wishing to interact with C2PA metadata on the web should use the libraries in this repo instead.
> The old `c2pa-js` repository is now in [c2pa-js-legacy](https://github.com/contentauth/c2pa-js-legacy) and is deprecated. If you need to work with C2PA metadata in the browser, use the libraries in this repository instead.

A collection of libraries and tools that enable interaction with [C2PA metadata](https://c2pa.org/) in JavaScript. Part of the [Content Authenticity Initiative](https://contentauthenticity.org/).
JavaScript libraries and tools for working with [C2PA metadata](https://c2pa.org/). This repository is part of the [Content Authenticity Initiative](https://contentauthenticity.org/).

## Using This Monorepo
## Using this monorepo

This monorepo is managed by [NX](https://nx.dev/getting-started/intro) and [pnpm](https://pnpm.io/).
This monorepo uses [Nx](https://nx.dev/getting-started/intro) and [pnpm](https://pnpm.io/).

### Prerequisites

The following must be installed before working with this monorepo:
Install the following before you work in this repository.

#### Node.js

Node.js **v22 or later** is required (earlier versions may fail with build errors related to unknown file extensions).
Node.js **v22 or later** is required. Older versions may fail to build because of unrecognized file extensions.

If you use [nvm](https://github.com/nvm-sh/nvm), you can install the required version with:
If you use [nvm](https://github.com/nvm-sh/nvm), install a supported v22 release (for example, `nvm install 22` or `nvm install 22.22.0`).

```sh
nvm install <version>
nvm install 22.22.0
```

#### pnpm and NX
#### pnpm and Nx

Install pnpm and NX.
Install `pnpm` and the Nx CLI globally:

```sh
npm install -g pnpm
npm install -g nx
```

#### Rust Toolchain (for building `c2pa-wasm`)
#### Rust toolchain for building `c2pa-wasm`

If you plan to build from source (rather than only consuming published packages), the Rust toolchain and additional prerequisites are required. See [`c2pa-wasm`'s prerequisites](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm#prerequisites) for full details.
To build from source instead of using published packages only, you need the Rust toolchain and other prerequisites. See [Prerequisites in `packages/c2pa-wasm/README.md`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm#prerequisites).

### Recommended Setup Order
### Recommended setup order

1. Install Node.js, pnpm, and NX (see above).
2. Install the Rust toolchain and `c2pa-wasm` prerequisites (see [`packages/c2pa-wasm/README.md`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm#prerequisites)).
3. Run `pnpm install` from the repo root to install the project's dependencies.
1. Install Node.js, `pnpm`, and the Nx CLI (see the previous sections).
2. Install the Rust toolchain and `c2pa-wasm` prerequisites ([`packages/c2pa-wasm/README.md`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm#prerequisites)).
3. From the repository root, run `pnpm install` to install dependencies.

### Running Commands with Nx
### Running commands with Nx

Commands are run in the following format: `nx [target] [project]`, e.g.:
Run tasks as `nx <target> <project>`. For example:

```sh
nx build c2pa-web # This will build c2pa-web and all of its dependencies
nx test c2pa-web # This will build and run the tests defined in the c2pa-web package
nx lint c2pa-web # This will run ESLint on the c2pa-web package
nx lint c2pa-web --fix # This will run ESLint on the c2pa-web package and fix any errors
nx build c2pa-web # Builds c2pa-web and its dependencies
nx test c2pa-web # Builds and runs tests for c2pa-web
nx lint c2pa-web # Runs ESLint on c2pa-web
nx lint c2pa-web --fix # Runs ESLint and applies fixes
```

### Committing Changes for Release
### Committing changes for a release

If your changes should be part of a release, you will need to create and commit a changeset.
Include a changeset when your change should ship in a release.

To create a new changeset, from the root repo directory, run:
From the repository root:

```sh
pnpm changeset
```

Follow the prompts to bump the version numbers of affected packages as appropriate. This will generate a new changeset markdown file in the `.changeset` directory, which should then be committed as part of your PR.
Follow the prompts to bump affected packages. The command adds a Markdown file under `.changeset/`; commit that file with your pull request.

Once the PR is merge into `main`, the changeset bot will create a release PR, which will then be reviewed, merged, and result in a new release being published.
After the pull request merges to `main`, the changeset bot opens a release pull request. When that pull request merges, a new release is published.

## Packages
## Directory layout

Please see the individual package directories for more detailed information.
See each package directory for full details.

### `packages/`
### packages

Published libraries intended for production use.
The `/packages` directory contains libraries published for production use.

#### [c2pa-web](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-web)
#### c2pa-web

The SDK for interacting with [C2PA metadata](https://c2pa.org/) on the web.
SDK for [C2PA](https://c2pa.org/) metadata in the browser. Source: [`packages/c2pa-web`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-web).

#### [c2pa-wasm](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm)
#### c2pa-wasm

The WebAssembly wrapper for [c2pa-rs](https://github.com/contentauth/c2pa-rs) that powers c2pa-web, built with [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen). While these bindings can be used directly, most users will prefer the convenience of c2pa-web.
WebAssembly bindings for [`c2pa-rs`](https://github.com/contentauth/c2pa-rs), built with [`wasm-bindgen`](https://github.com/wasm-bindgen/wasm-bindgen). They power `c2pa-web`; most applications should use `c2pa-web` instead of calling the bindings directly. Source: [`packages/c2pa-wasm`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm).

#### [c2pa-types](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-types)
#### c2pa-types

Exports TypeScript types autogenerated from [c2pa-rs](https://github.com/contentauth/c2pa-rs) structs, used by c2pa-web.
TypeScript types generated from `c2pa-rs` structs for use by `c2pa-web`. Source: [`packages/c2pa-types`](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-types).

### `tools/`
### tools

Other tools that provide utilities for local development.
The `/tools` directory contains utilities for local development.

#### [testbed](https://github.com/contentauth/c2pa-js/tree/main/tools/testbed)
#### testbed

A minimal website that can be used to view c2pa-web output and as a sandbox for local development.
Minimal site for inspecting `c2pa-web` output and experimenting locally. Source: [`tools/testbed`](https://github.com/contentauth/c2pa-js/tree/main/tools/testbed).

#### [nx-wasm-bindgen](https://github.com/contentauth/c2pa-js/tree/main/tools/nx-wasm-bindgen)
#### nx-wasm-bindgen

A custom [NX executor](https://nx.dev/concepts/executors-and-configurations) that contains the logic for building c2pa-wasm using [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen).
Custom [Nx executor](https://nx.dev/concepts/executors-and-configurations) that builds `c2pa-wasm` with `wasm-bindgen`. Source: [`tools/nx-wasm-bindgen`](https://github.com/contentauth/c2pa-js/tree/main/tools/nx-wasm-bindgen).

## License

This project is licensed under the terms of the [MIT license](https://github.com/contentauth/c2pa-js-v2/blob/main/LICENSE).
This project is licensed under the [MIT license](https://github.com/contentauth/c2pa-js/blob/main/LICENSE).
20 changes: 14 additions & 6 deletions packages/c2pa-types/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# c2pa-types

Exports TypeScript types autogenerated from [c2pa-rs](https://github.com/contentauth/c2pa-rs) structs, used by c2pa-web.
Exports TypeScript types used by c2pa-web that are auto-generated from [c2pa-rs](https://github.com/contentauth/c2pa-rs) structs.

### Building
## Prerequisites

Ensure the repo-wide prerequisites ([Node.js](https://nodejs.org/) v22+, [NX](https://nx.dev/getting-started/intro), and [pnpm](https://pnpm.io/)) are installed. See the [top-level README](https://github.com/contentauth/c2pa-js#prerequisites) for details.
Ensure the repo-wide prerequisites are installed:

- [Node.js](https://nodejs.org/) v22+
- [NX](https://nx.dev/getting-started/intro)
- [pnpm](https://pnpm.io/)

See the [c2pa-js README](../../README.md#prerequisites) for details.

## Building

To build the types:

Expand All @@ -15,6 +23,6 @@ nx build c2pa-types
The types are built as follows:

1. Specific structs ([example](https://github.com/contentauth/c2pa-rs/blob/main/sdk/src/manifest.rs#L55)) from c2pa-rs are annotated with the `schemars::JsonSchema` attribute.
2. JSON schema files are generated by calling `schemars::schema_for` and saved to the `schemas/` directory
3. Schema files are read by `json-schema-to-typescript` and used to generate TypeScript types, saved to the `types/` directory
4. Types are "gathered" and exported from the `index.d.ts` file
2. JSON schema files are generated by calling `schemars::schema_for` and saved to the `schemas/` directory.
3. Schema files are read by `json-schema-to-typescript` and used to generate TypeScript types, saved to the `types/` directory.
4. Types are "gathered" and exported from the `index.d.ts` file.
35 changes: 25 additions & 10 deletions packages/c2pa-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,61 @@ npm install @contentauth/c2pa-wasm

### Prerequisites

Ensure the repo-wide prerequisites ([Node.js](https://nodejs.org/) v22+, [NX](https://nx.dev/getting-started/intro), and [pnpm](https://pnpm.io/)) are installed. See the [top-level README](https://github.com/contentauth/c2pa-js#prerequisites) for details.
Ensure the repo-wide prerequisites are installed.:

Then, all of the following prerequisites must be installed before `c2pa-wasm` can be built:
- ([Node.js](https://nodejs.org/) v22+
- [NX](https://nx.dev/getting-started/intro)
- [pnpm](https://pnpm.io/))

#### Rust
See the [c2pa-js README](../../README.md#prerequisites) for details.

Then, install all of the following prerequisites:

[Installation instructions](https://www.rust-lang.org/tools/install)
- [Rust](#rust)
- [wasm-bindgen-cli](#wasm-bindgen-cli)
- [wasm-pack](#wasm-pack)

#### Rust

Minimum supported Rust version: **1.88.0**.
The minimum supported Rust version is **1.88.0**.

To install Rust via [rustup](https://rustup.rs/):

```sh
curl https://sh.rustup.rs -sSf | sh
```

Additionally, the `wasm32-unknown-unknown` target must be installed:
For more information, see [Install Rust](https://www.rust-lang.org/tools/install).

Additionally, you must install the `wasm32-unknown-unknown` target:

```sh
rustup target add wasm32-unknown-unknown
```

#### wasm-bindgen-cli

[Documentation](https://wasm-bindgen.github.io/wasm-bindgen/reference/cli)
The `wasm-bindgen-cli` provides options to tweak JavaScript generated by `wasm-bingen`.

For more information, see the [wasm-bindgen-cli documentation](https://wasm-bindgen.github.io/wasm-bindgen/reference/cli).

```sh
cargo install wasm-bindgen-cli@0.2.114
cargo install wasm-bindgen-cli@0.2.120
```

> **Important:** The version of `wasm-bindgen-cli` **must** match the version of the `wasm-bindgen` dependency in [`Cargo.toml`](./Cargo.toml). A version mismatch will cause build failures with errors like _"rust Wasm file schema version: X.X.X, this binary schema version: Y.Y.Y"_. If you encounter this, check `Cargo.toml` for the correct version and reinstall the CLI accordingly.
> [!IMPORTANT]
> The version of `wasm-bindgen-cli` **must** match the version of the `wasm-bindgen` dependency in [`Cargo.toml`](https://github.com/contentauth/c2pa-js/blob/main/packages/c2pa-wasm/Cargo.toml). A version mismatch will cause build failures with errors like _"rust Wasm file schema version: X.X.X, this binary schema version: Y.Y.Y"_. If you encounter this, check `Cargo.toml` for the correct version and reinstall the CLI accordingly.

#### wasm-pack

[Documentation](https://rustwasm.github.io/docs/wasm-pack/)
Wasm-pack is a tool for building and working with Rust-generated WebAssembly that interoperates with JavaScript.

```sh
cargo install wasm-pack@0.13.1
```

For more information, see the [wasm-pack documentation](https://rustwasm.github.io/docs/wasm-pack/).

### Building

To build the library:
Expand Down
16 changes: 11 additions & 5 deletions packages/c2pa-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ npm install @contentauth/c2pa-web

## Importing the library

There are two ways to import the library, due to [specific requirements](https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Loading_and_running) for handling Wasm modules:
Due to [specific requirements](https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Loading_and_running) for handling Wasm modules, there are two ways to import the library:

- Using a separate Wasm binary, which provides better performance.
- Using an inline Wasm binary, which is more convenient.
Expand All @@ -22,7 +22,7 @@ There are two ways to import the library, due to [specific requirements](https:/
The recommended way to import the library is to fetch the Wasm binary over the network at runtime.
This requires that the Wasm binary be hosted separately.

With Vite:
Use a solution appropriate to your tooling; for example, using Vite:

```typescript
import { createC2pa } from '@contentauth/c2pa-web';
Expand All @@ -32,7 +32,7 @@ import wasmSrc from '@contentauth/c2pa-web/resources/c2pa.wasm?url';
const c2pa = createC2pa({ wasmSrc });
```

Use a solution appropriate to your tooling. Alternatively, you can request the binary from a CDN:
Alternatively, you can request the binary from a CDN:

```typescript
import { createC2pa } from '@contentauth/c2pa-web';
Expand Down Expand Up @@ -288,9 +288,15 @@ For the full list, see the [API reference](https://contentauth.github.io/c2pa-js

### Prerequisites

Ensure the repo-wide prerequisites ([Node.js](https://nodejs.org/) v22+, [NX](https://nx.dev/getting-started/intro), and [pnpm](https://pnpm.io/)) are installed. See the [top-level README](https://github.com/contentauth/c2pa-js#prerequisites) for details.
Ensure the repo-wide prerequisites are installed:

[`c2pa-wasm`'s prerequisites](https://github.com/contentauth/c2pa-js/tree/main/packages/c2pa-wasm#prerequisites) must also be installed.
- [Node.js](https://nodejs.org/) v22+
- [NX](https://nx.dev/getting-started/intro)
- [pnpm](https://pnpm.io/)

See the [c2pa-js README](../../README.md#prerequisites) for details.

Then, install [the additional prerequisites for `c2pa-wasm`](../c2pa-wasm/README.md#prerequisites).

### Building

Expand Down
Loading