Skip to content

Commit f21c81d

Browse files
authored
Add c2pa-types + typed activeManifest and manifestStore APIs (#11)
* feat: add c2pa-types package with automatic type generation * feat: add typed manifestStore and activeManifest APIs * chore: changeset * chore: add copyright header
1 parent cd68747 commit f21c81d

File tree

19 files changed

+331
-43
lines changed

19 files changed

+331
-43
lines changed

.changeset/five-rice-raise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@contentauth/c2pa-types': minor
3+
'@contentauth/c2pa-wasm': minor
4+
'@contentauth/c2pa-web': minor
5+
---
6+
7+
Added reader.manifestStore() and reader.activeManifest() APIs

Cargo.lock

Lines changed: 49 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
resolver = '2'
44
members = [
55
'packages/c2pa-wasm',
6+
'packages/c2pa-types',
67
]
78

89
[profile.release]

packages/c2pa-types/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schemas
2+
types

packages/c2pa-types/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "c2pa-types"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
c2pa = { version = "0.62.0", features = ["pdf", "rust_native_crypto", "json_schema"], default-features = false }
8+
schemars = "0.8.21"
9+
serde_json = "1.0.143"

packages/c2pa-types/index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2025 Adobe
3+
* All Rights Reserved.
4+
*
5+
* NOTICE: Adobe permits you to use, modify, and distribute this file in
6+
* accordance with the terms of the Adobe license agreement accompanying
7+
* it.
8+
*/
9+
10+
import type { Reader } from './types/ManifestStore.js';
11+
12+
// Renames the auto-generated "Reader" type to the more appropriate "ManifestStore"
13+
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type
14+
export interface ManifestStore extends Reader {}
15+
16+
export type { Manifest } from './types/ManifestStore.js';

packages/c2pa-types/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@contentauth/c2pa-types",
3+
"description": "Typescript types generated from c2pa-rs",
4+
"type": "module",
5+
"version": "0.1.1",
6+
"types": "index.d.ts",
7+
"scripts": {
8+
"test": "echo \"No tests to run\" && exit 0",
9+
"build": "pnpm clean && json2ts -i schemas/ -o types/",
10+
"clean": "rimraf types"
11+
},
12+
"files": ["index.d.ts", "types/**/*"],
13+
"dependencies": {
14+
"json-schema-to-typescript": "^15.0.4",
15+
"rimraf": "^6.0.1"
16+
}
17+
}

packages/c2pa-types/project.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "c2pa-types",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"tags": ["lib"],
5+
"projectType": "library",
6+
"sourceRoot": "packages/c2pa-types/src",
7+
"targets": {
8+
"build": {
9+
"cache": true,
10+
"inputs": [
11+
"{projectRoot}/**/*",
12+
"!{projectRoot}/schemas/**/*",
13+
"!{projectRoot}/types/**/*"
14+
],
15+
"executor": "nx:run-commands",
16+
"options": {
17+
"commands": [
18+
"cargo run",
19+
"pnpm build"
20+
],
21+
"parallel": false,
22+
"cwd": "{projectRoot}"
23+
}
24+
}
25+
}
26+
}

packages/c2pa-types/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 Adobe
2+
// All Rights Reserved.
3+
//
4+
// NOTICE: Adobe permits you to use, modify, and distribute this file in
5+
// accordance with the terms of the Adobe license agreement accompanying
6+
// it.
7+
8+
use std::{fs, path::Path};
9+
10+
use c2pa::Reader;
11+
use schemars::{schema::RootSchema, schema_for};
12+
13+
fn main() {
14+
let output_dir = Path::new("./schemas");
15+
16+
if fs::exists(output_dir).unwrap() {
17+
fs::remove_dir_all(output_dir).expect("Could not clear existing schema directory");
18+
}
19+
20+
fs::create_dir_all(output_dir).expect("Could not create schema directory");
21+
22+
write_schema(&schema_for!(Reader), &"ManifestStore", output_dir);
23+
}
24+
25+
fn write_schema(schema: &RootSchema, name: &str, output_dir: &Path) {
26+
println!("Exporting JSON schema for {name}");
27+
let output_path = output_dir.join(format!("{name}.json"));
28+
let output = serde_json::to_string_pretty(schema).expect("Failed to serialize schema");
29+
fs::write(&output_path, output).expect("Unable to write schema");
30+
println!("Wrote schema to {}", output_path.display());
31+
}

packages/c2pa-wasm/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ wasm-bindgen-futures = "0.4.50"
2525
c2pa = { version = "0.62.0", features = ["pdf", "rust_native_crypto", "fetch_remote_manifests"], default-features = false }
2626
async-trait = "0.1.88"
2727
thiserror = "2.0.12"
28+
serde-wasm-bindgen = "0.6.5"
29+
serde = "1.0.219"
2830

2931
[dependencies.web-sys]
3032
version = "0.3.77"

0 commit comments

Comments
 (0)