@contentauth/c2pa-node 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +2 -1
- package/README.md +11 -15
- package/dist/Builder.js +60 -80
- package/dist/Builder.spec.js +140 -155
- package/dist/IdentityAssertion.js +8 -18
- package/dist/IdentityAssertion.spec.js +28 -35
- package/dist/Reader.js +13 -29
- package/dist/Reader.spec.js +52 -63
- package/dist/Settings.js +16 -29
- package/dist/Settings.spec.js +47 -62
- package/dist/Signer.js +4 -13
- package/dist/Signer.spec.js +35 -43
- package/dist/Trustmark.js +8 -22
- package/dist/Trustmark.spec.js +50 -61
- package/dist/binary.js +1 -1
- package/dist/index.node +0 -0
- package/package.json +33 -30
- package/scripts/postinstall.cjs +18 -1
- package/Cargo.lock +0 -5079
- package/LICENSE +0 -21
package/Cargo.toml
CHANGED
|
@@ -3,6 +3,7 @@ name = "c2pa-node"
|
|
|
3
3
|
version = "0.1.0"
|
|
4
4
|
license = "MIT"
|
|
5
5
|
edition = "2021"
|
|
6
|
+
rust-version.workspace = true
|
|
6
7
|
exclude = ["index.node"]
|
|
7
8
|
|
|
8
9
|
[lib]
|
|
@@ -11,7 +12,7 @@ crate-type = ["cdylib"]
|
|
|
11
12
|
[dependencies]
|
|
12
13
|
async-trait = "0.1.77"
|
|
13
14
|
ciborium = "0.2.2"
|
|
14
|
-
c2pa = {
|
|
15
|
+
c2pa = { workspace = true, features = ["file_io", "add_thumbnails"] }
|
|
15
16
|
futures = "0.3"
|
|
16
17
|
image = "0.25.6"
|
|
17
18
|
neon = { version = "1.0.0", default-features = false, features = [
|
package/README.md
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
# C2PA Node.js library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@contentauth/c2pa-node` is a Node.js library in the [c2pa-js](https://github.com/contentauth/c2pa-js) monorepo that can:
|
|
4
4
|
- Read and validate C2PA data from media files in supported formats.
|
|
5
5
|
- Add signed manifests to media files in supported formats.
|
|
6
6
|
|
|
7
|
-
**WARNING**: This is an early version of this library, and there may be bugs and unimplemented features.
|
|
8
|
-
|
|
9
7
|
## Prerequisites
|
|
10
8
|
|
|
11
|
-
To use the C2PA Node library
|
|
12
|
-
- A [supported version of Node](https://github.com/neon-bindings/neon#platform-support).
|
|
13
|
-
- [Rust](https://www.rust-lang.org/tools/install).
|
|
9
|
+
To use the C2PA Node library you need Node.js **>=22**. If you need to manage multiple versions of Node on your machine, use a tool such as [nvm](https://github.com/nvm-sh/nvm).
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
To **build from source** you also need [Rust](https://www.rust-lang.org/tools/install). This is not required when installing the package normally — precompiled binaries are downloaded automatically during installation.
|
|
16
12
|
|
|
17
13
|
## Installation
|
|
18
14
|
|
|
@@ -47,15 +43,15 @@ This command will download precompiled binaries for the following systems:
|
|
|
47
43
|
|
|
48
44
|
## Documentation
|
|
49
45
|
|
|
50
|
-
Complete API documentation is generated from TypeScript source using [TypeDoc](https://typedoc.org/) and published to GitHub Pages at [https://contentauth.github.io/c2pa-
|
|
46
|
+
Complete API documentation is generated from TypeScript source using [TypeDoc](https://typedoc.org/) and published to GitHub Pages at [https://contentauth.github.io/c2pa-js/](https://contentauth.github.io/c2pa-js/).
|
|
51
47
|
|
|
52
|
-
To generate documentation locally:
|
|
48
|
+
To generate documentation locally, run the following from the monorepo root:
|
|
53
49
|
|
|
54
50
|
```bash
|
|
55
|
-
pnpm
|
|
51
|
+
pnpm ci:docs
|
|
56
52
|
```
|
|
57
53
|
|
|
58
|
-
This generates HTML documentation in the `docs/` directory
|
|
54
|
+
This generates HTML documentation in the `docs/` directory at the repo root. It is not checked into version control and is automatically published to GitHub Pages whenever a new release is published.
|
|
59
55
|
|
|
60
56
|
## Components
|
|
61
57
|
|
|
@@ -640,11 +636,11 @@ const builder = Builder.new(urlSettings);
|
|
|
640
636
|
|
|
641
637
|
|
|
642
638
|
### Build and use custom binary
|
|
643
|
-
**Build
|
|
644
|
-
```
|
|
645
|
-
|
|
639
|
+
**Build Rust binary:**
|
|
640
|
+
```bash
|
|
641
|
+
pnpm run build:rust
|
|
646
642
|
```
|
|
647
|
-
**Use custom
|
|
643
|
+
**Use custom Rust binary:**
|
|
648
644
|
```bash
|
|
649
645
|
export C2PA_LIBRARY_PATH=<path-to-binary-folder>/index.node
|
|
650
646
|
```
|
package/dist/Builder.js
CHANGED
|
@@ -3,18 +3,10 @@
|
|
|
3
3
|
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
4
4
|
// or the MIT license (http://opensource.org/licenses/MIT),
|
|
5
5
|
// at your option.
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
6
|
import { getNeonBinary } from "./binary.js";
|
|
16
7
|
import { IdentityAssertionSigner } from "./IdentityAssertion.js";
|
|
17
8
|
export class Builder {
|
|
9
|
+
builder;
|
|
18
10
|
constructor(builder) {
|
|
19
11
|
this.builder = builder;
|
|
20
12
|
}
|
|
@@ -63,40 +55,32 @@ export class Builder {
|
|
|
63
55
|
addAssertion(label, assertion, assertionKind) {
|
|
64
56
|
return getNeonBinary().builderAddAssertion.call(this.builder, label, assertion, assertionKind);
|
|
65
57
|
}
|
|
66
|
-
addResource(uri, resource) {
|
|
67
|
-
return
|
|
68
|
-
return getNeonBinary().builderAddResource.call(this.builder, uri, resource);
|
|
69
|
-
});
|
|
58
|
+
async addResource(uri, resource) {
|
|
59
|
+
return getNeonBinary().builderAddResource.call(this.builder, uri, resource);
|
|
70
60
|
}
|
|
71
|
-
addIngredient(ingredientJson, ingredient) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
});
|
|
61
|
+
async addIngredient(ingredientJson, ingredient) {
|
|
62
|
+
if (ingredient) {
|
|
63
|
+
return getNeonBinary().builderAddIngredientFromAsset.call(this.builder, ingredientJson, ingredient);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return getNeonBinary().builderAddIngredient.call(this.builder, ingredientJson);
|
|
67
|
+
}
|
|
80
68
|
}
|
|
81
69
|
addIngredientFromReader(reader) {
|
|
82
70
|
const readerHandle = reader.getHandle();
|
|
83
71
|
const result = getNeonBinary().builderAddIngredientFromReader.call(this.builder, readerHandle);
|
|
84
72
|
return JSON.parse(result);
|
|
85
73
|
}
|
|
86
|
-
toArchive(asset) {
|
|
87
|
-
return
|
|
88
|
-
return getNeonBinary().builderToArchive.call(this.builder, asset);
|
|
89
|
-
});
|
|
74
|
+
async toArchive(asset) {
|
|
75
|
+
return getNeonBinary().builderToArchive.call(this.builder, asset);
|
|
90
76
|
}
|
|
91
|
-
static fromArchive(asset, settings) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
?
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return new Builder(yield getNeonBinary().builderFromArchive(asset, settingsStr));
|
|
99
|
-
});
|
|
77
|
+
static async fromArchive(asset, settings) {
|
|
78
|
+
const settingsStr = settings
|
|
79
|
+
? typeof settings === "string"
|
|
80
|
+
? settings
|
|
81
|
+
: JSON.stringify(settings)
|
|
82
|
+
: undefined;
|
|
83
|
+
return new Builder(await getNeonBinary().builderFromArchive(asset, settingsStr));
|
|
100
84
|
}
|
|
101
85
|
sign(signer, input, output) {
|
|
102
86
|
return getNeonBinary().builderSign.call(this.builder, signer.getHandle(), input, output);
|
|
@@ -105,59 +89,55 @@ export class Builder {
|
|
|
105
89
|
const input = { path: filePath };
|
|
106
90
|
return getNeonBinary().builderSign.call(this.builder, signer.getHandle(), input, output);
|
|
107
91
|
}
|
|
108
|
-
signConfigAsync(callback, signerConfig, input, output) {
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if ("
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return result.manifest;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
throw new Error("Unexpected result for DestinationBuffer");
|
|
121
|
-
}
|
|
92
|
+
async signConfigAsync(callback, signerConfig, input, output) {
|
|
93
|
+
return getNeonBinary()
|
|
94
|
+
.builderSignConfigAsync.call(this.builder, callback, signerConfig, input, output)
|
|
95
|
+
.then((result) => {
|
|
96
|
+
// output is a buffer and result is the manifest and the signed asset.
|
|
97
|
+
if ("buffer" in output) {
|
|
98
|
+
if ("signedAsset" in result && "manifest" in result) {
|
|
99
|
+
output.buffer = result.signedAsset;
|
|
100
|
+
return result.manifest;
|
|
122
101
|
}
|
|
123
102
|
else {
|
|
124
|
-
|
|
125
|
-
return result;
|
|
103
|
+
throw new Error("Unexpected result for DestinationBuffer");
|
|
126
104
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// output is a file and result is the bytes of the manifest.
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.catch((error) => {
|
|
112
|
+
throw error;
|
|
131
113
|
});
|
|
132
114
|
}
|
|
133
|
-
signAsync(signer, input, output) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if ("
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return result.manifest;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new Error("Unexpected result for DestinationBuffer");
|
|
151
|
-
}
|
|
115
|
+
async signAsync(signer, input, output) {
|
|
116
|
+
const neonHandle = signer.getHandle();
|
|
117
|
+
const isIdentity = signer instanceof IdentityAssertionSigner;
|
|
118
|
+
const neonFn = isIdentity
|
|
119
|
+
? getNeonBinary().builderIdentitySignAsync
|
|
120
|
+
: getNeonBinary().builderSignAsync;
|
|
121
|
+
return neonFn
|
|
122
|
+
.call(this.builder, neonHandle, input, output)
|
|
123
|
+
.then((result) => {
|
|
124
|
+
// output is a buffer and result is the manifest and the signed asset.
|
|
125
|
+
if ("buffer" in output) {
|
|
126
|
+
if ("signedAsset" in result && "manifest" in result) {
|
|
127
|
+
output.buffer = result.signedAsset;
|
|
128
|
+
return result.manifest;
|
|
152
129
|
}
|
|
153
130
|
else {
|
|
154
|
-
|
|
155
|
-
return result;
|
|
131
|
+
throw new Error("Unexpected result for DestinationBuffer");
|
|
156
132
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// output is a file and result is the bytes of the manifest.
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
.catch((error) => {
|
|
140
|
+
throw error;
|
|
161
141
|
});
|
|
162
142
|
}
|
|
163
143
|
getManifestDefinition() {
|