@contentauth/c2pa-node 0.2.2 → 0.3.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.lock +35 -25
- package/Cargo.toml +2 -2
- package/dist/Builder.js +23 -25
- package/dist/Builder.spec.js +152 -9
- package/dist/IdentityAssertion.js +10 -10
- package/dist/Reader.js +8 -14
- package/dist/Reader.spec.js +64 -64
- package/dist/Settings.js +10 -10
- package/dist/Settings.spec.js +2 -2
- package/dist/Signer.js +17 -14
- package/dist/Signer.spec.js +64 -1
- package/dist/Trustmark.js +4 -4
- package/dist/Trustmark.spec.js +1 -1
- package/dist/binary.js +24 -0
- package/dist/index.js +7 -7
- package/dist/index.node +0 -0
- package/dist/types/Builder.d.ts +3 -2
- package/dist/types/IdentityAssertion.d.ts +1 -1
- package/dist/types/Reader.d.ts +1 -1
- package/dist/types/Settings.d.ts +1 -1
- package/dist/types/Signer.d.ts +2 -1
- package/dist/types/Trustmark.d.ts +1 -1
- package/dist/types/binary.d.ts +1 -0
- package/dist/types/index.d.ts +8 -8
- package/dist/types/types.d.ts +9 -5
- package/package.json +7 -4
- package/scripts/{postinstall.js → postinstall.cjs} +12 -14
- package/src/lib.rs +6 -1
- package/src/neon_builder.rs +12 -1
- package/src/neon_signer.rs +9 -4
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from "./types";
|
|
2
|
-
export { Builder } from "./Builder";
|
|
3
|
-
export { Reader } from "./Reader";
|
|
4
|
-
export { LocalSigner, CallbackSigner } from "./Signer";
|
|
5
|
-
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion";
|
|
6
|
-
export { Trustmark } from "./Trustmark";
|
|
7
|
-
export { isActionsAssertion } from "./assertions";
|
|
8
|
-
export * from "./Settings";
|
|
1
|
+
export type * from "./types.d.ts";
|
|
2
|
+
export { Builder } from "./Builder.js";
|
|
3
|
+
export { Reader } from "./Reader.js";
|
|
4
|
+
export { LocalSigner, CallbackSigner } from "./Signer.js";
|
|
5
|
+
export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion.js";
|
|
6
|
+
export { Trustmark } from "./Trustmark.js";
|
|
7
|
+
export { isActionsAssertion } from "./assertions.js";
|
|
8
|
+
export * from "./Settings.js";
|
package/dist/types/types.d.ts
CHANGED
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
|
|
14
14
|
// This file contains types not included in @contentauth/c2pa-types and not directly applicable to the neon generated code (index.node.d.ts)
|
|
15
15
|
import { Buffer } from "buffer";
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
BuilderIntent,
|
|
18
|
+
Manifest,
|
|
19
|
+
ManifestStore,
|
|
20
|
+
} from "@contentauth/c2pa-types";
|
|
17
21
|
/**
|
|
18
22
|
* Describes the digital signature algorithms allowed by the C2PA spec
|
|
19
23
|
*
|
|
@@ -118,6 +122,7 @@ export interface CallbackSignerInterface {
|
|
|
118
122
|
certs(): Array<Buffer>;
|
|
119
123
|
reserveSize(): number;
|
|
120
124
|
timeAuthorityUrl(): string | undefined;
|
|
125
|
+
directCoseHandling(): boolean;
|
|
121
126
|
signer(): NeonCallbackSignerHandle;
|
|
122
127
|
}
|
|
123
128
|
|
|
@@ -153,10 +158,8 @@ export interface JsCallbackSignerConfig {
|
|
|
153
158
|
tsaUrl?: string;
|
|
154
159
|
tsaHeaders?: Array<[string, string]>;
|
|
155
160
|
tsaBody?: Buffer;
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
// differentiate between directCoseHandling: true/false - both cases pass the
|
|
159
|
-
// same data to the JavaScript callback regardless of this setting.
|
|
161
|
+
// When true, the callback function should return fully-formed COSE data.
|
|
162
|
+
// When false, the callback function should return raw signature data and the c2pa SDK will handle COSE wrapping.
|
|
160
163
|
directCoseHandling: boolean;
|
|
161
164
|
}
|
|
162
165
|
|
|
@@ -173,6 +176,7 @@ export interface HashedUri {
|
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
export interface BuilderInterface {
|
|
179
|
+
setIntent(intent: BuilderIntent): void;
|
|
176
180
|
/**
|
|
177
181
|
* Set the no embed flag of the manifest
|
|
178
182
|
* @param noEmbed The no embed flag of the manifest
|
package/package.json
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "git+https://github.com/contentauth/c2pa-node-v2.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.3.0",
|
|
8
8
|
"description": "Node.js bindings for C2PA",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
|
+
"type": "module",
|
|
10
11
|
"types": "dist/types/index.d.ts",
|
|
11
12
|
"files": [
|
|
12
13
|
"dist",
|
|
@@ -22,13 +23,15 @@
|
|
|
22
23
|
"license": "MIT",
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@changesets/cli": "^2.29.6",
|
|
25
|
-
"@contentauth/c2pa-types": "^0.
|
|
26
|
+
"@contentauth/c2pa-types": "^0.3.1",
|
|
26
27
|
"@eslint/js": "^9.33.0",
|
|
27
28
|
"@neon-rs/cli": "0.1.82",
|
|
29
|
+
"@types/cli-progress": "^3.11.6",
|
|
28
30
|
"@types/debug": "^4.1.12",
|
|
29
31
|
"@types/fs-extra": "^11.0.4",
|
|
30
32
|
"@types/jest": "^29.5.14",
|
|
31
33
|
"@types/node": "^22.17.1",
|
|
34
|
+
"@types/unzipper": "^0.10.11",
|
|
32
35
|
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
33
36
|
"@typescript-eslint/parser": "^8.39.1",
|
|
34
37
|
"@vitest/ui": "^3.2.4",
|
|
@@ -72,14 +75,14 @@
|
|
|
72
75
|
"changeset:publish": "changeset publish",
|
|
73
76
|
"ci": "run-s build:rust-debug build:ts test",
|
|
74
77
|
"ci:release": "pnpm run build && changeset tag && pnpm publish --access=public --no-git-checks",
|
|
75
|
-
"clean": "rimraf dist
|
|
78
|
+
"clean": "rimraf dist target",
|
|
76
79
|
"cross": "pnpm run cross-build --release",
|
|
77
80
|
"cross-build": "cross build --message-format=json-render-diagnostics > cross.log",
|
|
78
81
|
"debug": "pnpm run cargo-build --",
|
|
79
82
|
"lint": "cargo clippy && pnpm eslint",
|
|
80
83
|
"postbuild:rust-debug": "neon dist < cargo.log",
|
|
81
84
|
"postcross-build": "neon dist -m /target < cross.log",
|
|
82
|
-
"postinstall": "node scripts/postinstall.
|
|
85
|
+
"postinstall": "node scripts/postinstall.cjs",
|
|
83
86
|
"release": "run-s build changeset:publish",
|
|
84
87
|
"test": "pnpm build:debug && vitest run",
|
|
85
88
|
"test:watch": "pnpm build:debug && vitest",
|
|
@@ -17,6 +17,9 @@ const { mkdirp } = require('mkdirp');
|
|
|
17
17
|
const { resolve } = require('node:path');
|
|
18
18
|
const { exec } = require('node:child_process');
|
|
19
19
|
const { promisify } = require('node:util');
|
|
20
|
+
// node-fetch v3 is ES module only, so we'll import it dynamically
|
|
21
|
+
// pretty-bytes is ES module only, so we'll import it dynamically
|
|
22
|
+
// pkg-dir is ES module only, so we'll import it dynamically
|
|
20
23
|
|
|
21
24
|
const pExec = promisify(exec);
|
|
22
25
|
|
|
@@ -69,19 +72,16 @@ function getPlatform() {
|
|
|
69
72
|
|
|
70
73
|
async function downloadFromUrl(appRoot, url) {
|
|
71
74
|
console.log(`Checking for a release at: ${url}`);
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const fetch = fetchModule.default;
|
|
75
|
+
const { default: fetch } = await import('node-fetch');
|
|
76
|
+
const { default: prettyBytes } = await import('pretty-bytes');
|
|
75
77
|
const res = await fetch(url);
|
|
76
78
|
|
|
77
79
|
if (res.ok) {
|
|
78
|
-
// Dynamic import for ES module
|
|
79
|
-
const { default: prettyBytes } = await import('pretty-bytes');
|
|
80
80
|
|
|
81
|
-
const destDir = resolve(appRoot, 'dist'
|
|
81
|
+
const destDir = resolve(appRoot, 'dist');
|
|
82
82
|
const totalSize = parseInt(res.headers.get('Content-Length'), 10);
|
|
83
83
|
await mkdirp(destDir);
|
|
84
|
-
const destPath = resolve(destDir, '
|
|
84
|
+
const destPath = resolve(destDir, 'index.node');
|
|
85
85
|
const destStream = createWriteStream(destPath);
|
|
86
86
|
const progress = new PassThrough();
|
|
87
87
|
const bar = new cliProgress.SingleBar(
|
|
@@ -157,10 +157,10 @@ async function rustExists() {
|
|
|
157
157
|
|
|
158
158
|
async function buildRust(root) {
|
|
159
159
|
console.log('🦀 Building Rust...');
|
|
160
|
-
const
|
|
161
|
-
const bindingsPath = resolve(
|
|
160
|
+
const distDir = resolve(root, 'dist');
|
|
161
|
+
const bindingsPath = resolve(distDir, 'index.node');
|
|
162
162
|
const cargoPath = resolve(root, 'Cargo.toml');
|
|
163
|
-
await mkdirp(
|
|
163
|
+
await mkdirp(distDir);
|
|
164
164
|
return new Promise((resolve, reject) => {
|
|
165
165
|
const result = exec(
|
|
166
166
|
`npx cargo-cp-artifact -nc "${bindingsPath}" -- cargo build --message-format=json-render-diagnostics --release --manifest-path="${cargoPath}"`,
|
|
@@ -173,10 +173,8 @@ async function buildRust(root) {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
async function main() {
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
const pkgDir = pkgDirModule.packageDirectory;
|
|
179
|
-
const appRoot = await pkgDir(__dirname);
|
|
176
|
+
const { packageDirectory } = await import('pkg-dir');
|
|
177
|
+
const appRoot = await packageDirectory(__filename);
|
|
180
178
|
const distRoot = resolve(appRoot, 'dist');
|
|
181
179
|
const cargoDistPath = resolve(distRoot, 'Cargo.toml');
|
|
182
180
|
const libraryOverridePath = process.env.C2PA_LIBRARY_PATH;
|
package/src/lib.rs
CHANGED
|
@@ -32,9 +32,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
|
32
32
|
// Builder
|
|
33
33
|
cx.export_function("builderNew", neon_builder::NeonBuilder::new)?;
|
|
34
34
|
cx.export_function("builderWithJson", neon_builder::NeonBuilder::with_json)?;
|
|
35
|
+
cx.export_function("builderSetIntent", neon_builder::NeonBuilder::set_intent)?;
|
|
35
36
|
cx.export_function("builderSetNoEmbed", neon_builder::NeonBuilder::set_no_embed)?;
|
|
36
37
|
cx.export_function(
|
|
37
|
-
"
|
|
38
|
+
"builderSetRemoteUrl",
|
|
38
39
|
neon_builder::NeonBuilder::set_remote_url,
|
|
39
40
|
)?;
|
|
40
41
|
cx.export_function(
|
|
@@ -131,6 +132,10 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
|
131
132
|
"callbackSignerTimeAuthorityUrl",
|
|
132
133
|
neon_signer::NeonCallbackSigner::time_authority_url,
|
|
133
134
|
)?;
|
|
135
|
+
cx.export_function(
|
|
136
|
+
"callbackSignerDirectCoseHandling",
|
|
137
|
+
neon_signer::NeonCallbackSigner::direct_cose_handling,
|
|
138
|
+
)?;
|
|
134
139
|
|
|
135
140
|
// Identity Assertions
|
|
136
141
|
cx.export_function(
|
package/src/neon_builder.rs
CHANGED
|
@@ -16,7 +16,7 @@ use crate::error::{as_js_error, Error};
|
|
|
16
16
|
use crate::neon_identity_assertion_signer::NeonIdentityAssertionSigner;
|
|
17
17
|
use crate::neon_signer::{CallbackSignerConfig, NeonCallbackSigner, NeonLocalSigner};
|
|
18
18
|
use crate::runtime::runtime;
|
|
19
|
-
use c2pa::Builder;
|
|
19
|
+
use c2pa::{Builder, BuilderIntent};
|
|
20
20
|
use neon::prelude::*;
|
|
21
21
|
use neon_serde4;
|
|
22
22
|
use serde::{Deserialize, Serialize};
|
|
@@ -59,6 +59,17 @@ impl NeonBuilder {
|
|
|
59
59
|
}))
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
pub fn set_intent(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
63
|
+
let rt = runtime();
|
|
64
|
+
let this = cx.this::<JsBox<Self>>()?;
|
|
65
|
+
let intent_str = cx.argument::<JsString>(0)?.value(&mut cx);
|
|
66
|
+
let intent: BuilderIntent = serde_json::from_str(&intent_str)
|
|
67
|
+
.or_else(|_| cx.throw_error(format!("Invalid intent: {}", intent_str)))?;
|
|
68
|
+
let mut builder = rt.block_on(async { this.builder.lock().await });
|
|
69
|
+
builder.set_intent(intent);
|
|
70
|
+
Ok(cx.undefined())
|
|
71
|
+
}
|
|
72
|
+
|
|
62
73
|
pub fn set_no_embed(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
63
74
|
let rt = runtime();
|
|
64
75
|
let this = cx.this::<JsBox<Self>>()?;
|
package/src/neon_signer.rs
CHANGED
|
@@ -201,6 +201,11 @@ impl NeonCallbackSigner {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
pub fn direct_cose_handling(mut cx: FunctionContext) -> JsResult<JsBoolean> {
|
|
205
|
+
let this = cx.this::<JsBox<Self>>()?;
|
|
206
|
+
Ok(cx.boolean(this.config.direct_cose_handling))
|
|
207
|
+
}
|
|
208
|
+
|
|
204
209
|
pub fn sign(mut cx: FunctionContext) -> JsResult<JsPromise> {
|
|
205
210
|
let rt = runtime();
|
|
206
211
|
let this = cx.this::<JsBox<Self>>()?;
|
|
@@ -321,12 +326,12 @@ impl AsyncSigner for NeonCallbackSigner {
|
|
|
321
326
|
}
|
|
322
327
|
|
|
323
328
|
fn direct_cose_handling(&self) -> bool {
|
|
324
|
-
// TODO: The direct_cose_handling field is currently not used in the signing logic.
|
|
325
|
-
// The field is read from config and exposed via this getter, but the actual signing
|
|
326
|
-
// implementation does not differentiate between directCoseHandling: true/false.
|
|
327
|
-
// Both cases pass the same data to the JavaScript callback regardless of this setting.
|
|
328
329
|
self.config.direct_cose_handling
|
|
329
330
|
}
|
|
331
|
+
|
|
332
|
+
fn async_raw_signer(&self) -> Option<Box<&dyn AsyncRawSigner>> {
|
|
333
|
+
Some(Box::new(self))
|
|
334
|
+
}
|
|
330
335
|
}
|
|
331
336
|
|
|
332
337
|
impl TimeStampProvider for NeonCallbackSigner {
|