@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/Cargo.lock
CHANGED
|
@@ -436,9 +436,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
|
|
436
436
|
|
|
437
437
|
[[package]]
|
|
438
438
|
name = "c2pa"
|
|
439
|
-
version = "0.
|
|
439
|
+
version = "0.68.0"
|
|
440
440
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
441
|
-
checksum = "
|
|
441
|
+
checksum = "46613af072ed8a145e9a726459074a0693aeb43c207efa0340b96967c2aced69"
|
|
442
442
|
dependencies = [
|
|
443
443
|
"asn1-rs",
|
|
444
444
|
"async-generic",
|
|
@@ -827,9 +827,9 @@ dependencies = [
|
|
|
827
827
|
|
|
828
828
|
[[package]]
|
|
829
829
|
name = "darling"
|
|
830
|
-
version = "0.
|
|
830
|
+
version = "0.21.3"
|
|
831
831
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
832
|
-
checksum = "
|
|
832
|
+
checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0"
|
|
833
833
|
dependencies = [
|
|
834
834
|
"darling_core",
|
|
835
835
|
"darling_macro",
|
|
@@ -837,9 +837,9 @@ dependencies = [
|
|
|
837
837
|
|
|
838
838
|
[[package]]
|
|
839
839
|
name = "darling_core"
|
|
840
|
-
version = "0.
|
|
840
|
+
version = "0.21.3"
|
|
841
841
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
842
|
-
checksum = "
|
|
842
|
+
checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4"
|
|
843
843
|
dependencies = [
|
|
844
844
|
"fnv",
|
|
845
845
|
"ident_case",
|
|
@@ -851,9 +851,9 @@ dependencies = [
|
|
|
851
851
|
|
|
852
852
|
[[package]]
|
|
853
853
|
name = "darling_macro"
|
|
854
|
-
version = "0.
|
|
854
|
+
version = "0.21.3"
|
|
855
855
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
856
|
-
checksum = "
|
|
856
|
+
checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
|
857
857
|
dependencies = [
|
|
858
858
|
"darling_core",
|
|
859
859
|
"quote",
|
|
@@ -2088,9 +2088,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
|
|
2088
2088
|
|
|
2089
2089
|
[[package]]
|
|
2090
2090
|
name = "memchr"
|
|
2091
|
-
version = "2.7.
|
|
2091
|
+
version = "2.7.6"
|
|
2092
2092
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2093
|
-
checksum = "
|
|
2093
|
+
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
|
2094
2094
|
|
|
2095
2095
|
[[package]]
|
|
2096
2096
|
name = "minimal-lexical"
|
|
@@ -2468,12 +2468,12 @@ dependencies = [
|
|
|
2468
2468
|
|
|
2469
2469
|
[[package]]
|
|
2470
2470
|
name = "pem"
|
|
2471
|
-
version = "3.0.
|
|
2471
|
+
version = "3.0.6"
|
|
2472
2472
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2473
|
-
checksum = "
|
|
2473
|
+
checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be"
|
|
2474
2474
|
dependencies = [
|
|
2475
2475
|
"base64 0.22.1",
|
|
2476
|
-
"
|
|
2476
|
+
"serde_core",
|
|
2477
2477
|
]
|
|
2478
2478
|
|
|
2479
2479
|
[[package]]
|
|
@@ -3402,10 +3402,11 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
|
|
|
3402
3402
|
|
|
3403
3403
|
[[package]]
|
|
3404
3404
|
name = "serde"
|
|
3405
|
-
version = "1.0.
|
|
3405
|
+
version = "1.0.228"
|
|
3406
3406
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3407
|
-
checksum = "
|
|
3407
|
+
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
|
3408
3408
|
dependencies = [
|
|
3409
|
+
"serde_core",
|
|
3409
3410
|
"serde_derive",
|
|
3410
3411
|
]
|
|
3411
3412
|
|
|
@@ -3448,11 +3449,20 @@ dependencies = [
|
|
|
3448
3449
|
"serde",
|
|
3449
3450
|
]
|
|
3450
3451
|
|
|
3452
|
+
[[package]]
|
|
3453
|
+
name = "serde_core"
|
|
3454
|
+
version = "1.0.228"
|
|
3455
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3456
|
+
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
3457
|
+
dependencies = [
|
|
3458
|
+
"serde_derive",
|
|
3459
|
+
]
|
|
3460
|
+
|
|
3451
3461
|
[[package]]
|
|
3452
3462
|
name = "serde_derive"
|
|
3453
|
-
version = "1.0.
|
|
3463
|
+
version = "1.0.228"
|
|
3454
3464
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3455
|
-
checksum = "
|
|
3465
|
+
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|
3456
3466
|
dependencies = [
|
|
3457
3467
|
"proc-macro2",
|
|
3458
3468
|
"quote",
|
|
@@ -3461,15 +3471,16 @@ dependencies = [
|
|
|
3461
3471
|
|
|
3462
3472
|
[[package]]
|
|
3463
3473
|
name = "serde_json"
|
|
3464
|
-
version = "1.0.
|
|
3474
|
+
version = "1.0.145"
|
|
3465
3475
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3466
|
-
checksum = "
|
|
3476
|
+
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
|
3467
3477
|
dependencies = [
|
|
3468
3478
|
"indexmap 2.10.0",
|
|
3469
3479
|
"itoa",
|
|
3470
3480
|
"memchr",
|
|
3471
3481
|
"ryu",
|
|
3472
3482
|
"serde",
|
|
3483
|
+
"serde_core",
|
|
3473
3484
|
]
|
|
3474
3485
|
|
|
3475
3486
|
[[package]]
|
|
@@ -3495,9 +3506,9 @@ dependencies = [
|
|
|
3495
3506
|
|
|
3496
3507
|
[[package]]
|
|
3497
3508
|
name = "serde_with"
|
|
3498
|
-
version = "3.
|
|
3509
|
+
version = "3.15.1"
|
|
3499
3510
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3500
|
-
checksum = "
|
|
3511
|
+
checksum = "aa66c845eee442168b2c8134fec70ac50dc20e760769c8ba0ad1319ca1959b04"
|
|
3501
3512
|
dependencies = [
|
|
3502
3513
|
"base64 0.22.1",
|
|
3503
3514
|
"chrono",
|
|
@@ -3506,8 +3517,7 @@ dependencies = [
|
|
|
3506
3517
|
"indexmap 2.10.0",
|
|
3507
3518
|
"schemars 0.9.0",
|
|
3508
3519
|
"schemars 1.0.4",
|
|
3509
|
-
"
|
|
3510
|
-
"serde_derive",
|
|
3520
|
+
"serde_core",
|
|
3511
3521
|
"serde_json",
|
|
3512
3522
|
"serde_with_macros",
|
|
3513
3523
|
"time",
|
|
@@ -3515,9 +3525,9 @@ dependencies = [
|
|
|
3515
3525
|
|
|
3516
3526
|
[[package]]
|
|
3517
3527
|
name = "serde_with_macros"
|
|
3518
|
-
version = "3.
|
|
3528
|
+
version = "3.15.1"
|
|
3519
3529
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3520
|
-
checksum = "
|
|
3530
|
+
checksum = "b91a903660542fced4e99881aa481bdbaec1634568ee02e0b8bd57c64cb38955"
|
|
3521
3531
|
dependencies = [
|
|
3522
3532
|
"darling",
|
|
3523
3533
|
"proc-macro2",
|
package/Cargo.toml
CHANGED
|
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
|
|
|
11
11
|
[dependencies]
|
|
12
12
|
async-trait = "0.1.77"
|
|
13
13
|
ciborium = "0.2.2"
|
|
14
|
-
c2pa = { version = "0.
|
|
14
|
+
c2pa = { version = "0.68", default-features = false, features = ["file_io", "pdf", "fetch_remote_manifests", "add_thumbnails", "rust_native_crypto"] }
|
|
15
15
|
futures = "0.3"
|
|
16
16
|
image = "0.25.6"
|
|
17
17
|
neon = { version = "1.0.0", default-features = false, features = [
|
|
@@ -29,7 +29,7 @@ reqwest = { version = "0.12.2", default-features = false, features = [
|
|
|
29
29
|
] }
|
|
30
30
|
serde = { version = "1.0.203", features = ["derive"] }
|
|
31
31
|
serde_bytes = "0.11.15"
|
|
32
|
-
serde_json = "1.0.
|
|
32
|
+
serde_json = "1.0.145"
|
|
33
33
|
toml = "0.8"
|
|
34
34
|
thiserror = "1.0.61"
|
|
35
35
|
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
|
package/dist/Builder.js
CHANGED
|
@@ -12,20 +12,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
18
|
-
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
19
|
-
// specific language governing permissions and limitations under
|
|
20
|
-
// each license.
|
|
21
|
-
const neon = require("./index.node");
|
|
22
|
-
import { IdentityAssertionSigner } from "./IdentityAssertion";
|
|
15
|
+
import { getNeonBinary } from "./binary.js";
|
|
16
|
+
import { IdentityAssertionSigner } from "./IdentityAssertion.js";
|
|
23
17
|
export class Builder {
|
|
24
18
|
constructor(builder) {
|
|
25
19
|
this.builder = builder;
|
|
26
20
|
}
|
|
27
21
|
static new() {
|
|
28
|
-
const builder =
|
|
22
|
+
const builder = getNeonBinary().builderNew();
|
|
29
23
|
return new Builder(builder);
|
|
30
24
|
}
|
|
31
25
|
static withJson(json) {
|
|
@@ -40,49 +34,53 @@ export class Builder {
|
|
|
40
34
|
}
|
|
41
35
|
throw new Error("Failed to stringify JSON Manifest Definition: Unknown error");
|
|
42
36
|
}
|
|
43
|
-
const builder =
|
|
37
|
+
const builder = getNeonBinary().builderWithJson(jsonString);
|
|
44
38
|
return new Builder(builder);
|
|
45
39
|
}
|
|
40
|
+
setIntent(intent) {
|
|
41
|
+
const intentString = JSON.stringify(intent);
|
|
42
|
+
getNeonBinary().builderSetIntent.call(this.builder, intentString);
|
|
43
|
+
}
|
|
46
44
|
setNoEmbed(noEmbed = true) {
|
|
47
|
-
|
|
45
|
+
getNeonBinary().builderSetNoEmbed.call(this.builder, noEmbed);
|
|
48
46
|
}
|
|
49
47
|
setRemoteUrl(remoteUrl) {
|
|
50
|
-
|
|
48
|
+
getNeonBinary().builderSetRemoteUrl.call(this.builder, remoteUrl);
|
|
51
49
|
}
|
|
52
50
|
addAssertion(label, assertion, assertionKind) {
|
|
53
|
-
return
|
|
51
|
+
return getNeonBinary().builderAddAssertion.call(this.builder, label, assertion, assertionKind);
|
|
54
52
|
}
|
|
55
53
|
addResource(uri, resource) {
|
|
56
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
return
|
|
55
|
+
return getNeonBinary().builderAddResource.call(this.builder, uri, resource);
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
addIngredient(ingredientJson, ingredient) {
|
|
61
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
return
|
|
60
|
+
return getNeonBinary().builderAddIngredient.call(this.builder, ingredientJson, ingredient);
|
|
63
61
|
});
|
|
64
62
|
}
|
|
65
63
|
toArchive(asset) {
|
|
66
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
return
|
|
65
|
+
return getNeonBinary().builderToArchive.call(this.builder, asset);
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
68
|
static fromArchive(asset) {
|
|
71
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
return new Builder(yield
|
|
70
|
+
return new Builder(yield getNeonBinary().builderFromArchive(asset));
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
sign(signer, input, output) {
|
|
76
|
-
return
|
|
74
|
+
return getNeonBinary().builderSign.call(this.builder, signer.signer(), input, output);
|
|
77
75
|
}
|
|
78
76
|
signFile(signer, filePath, output) {
|
|
79
77
|
const input = { path: filePath };
|
|
80
|
-
return
|
|
78
|
+
return getNeonBinary().builderSign.call(this.builder, signer.signer(), input, output);
|
|
81
79
|
}
|
|
82
80
|
signConfigAsync(callback, signerConfig, input, output) {
|
|
83
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
return
|
|
85
|
-
.call(this.builder, callback, signerConfig, input, output)
|
|
82
|
+
return getNeonBinary()
|
|
83
|
+
.builderSignConfigAsync.call(this.builder, callback, signerConfig, input, output)
|
|
86
84
|
.then((result) => {
|
|
87
85
|
// output is a buffer and result is the manifest and the signed asset.
|
|
88
86
|
if ("buffer" in output) {
|
|
@@ -109,8 +107,8 @@ export class Builder {
|
|
|
109
107
|
const neonHandle = signer.signer();
|
|
110
108
|
const isIdentity = signer instanceof IdentityAssertionSigner;
|
|
111
109
|
const neonFn = isIdentity
|
|
112
|
-
?
|
|
113
|
-
:
|
|
110
|
+
? getNeonBinary().builderIdentitySignAsync
|
|
111
|
+
: getNeonBinary().builderSignAsync;
|
|
114
112
|
return neonFn
|
|
115
113
|
.call(this.builder, neonHandle, input, output)
|
|
116
114
|
.then((result) => {
|
|
@@ -135,9 +133,9 @@ export class Builder {
|
|
|
135
133
|
});
|
|
136
134
|
}
|
|
137
135
|
getManifestDefinition() {
|
|
138
|
-
return JSON.parse(
|
|
136
|
+
return JSON.parse(getNeonBinary().builderManifestDefinition.call(this.builder));
|
|
139
137
|
}
|
|
140
138
|
updateManifestProperty(property, value) {
|
|
141
|
-
|
|
139
|
+
getNeonBinary().builderUpdateManifestProperty.call(this.builder, property, value);
|
|
142
140
|
}
|
|
143
141
|
}
|
package/dist/Builder.spec.js
CHANGED
|
@@ -12,13 +12,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
import { isActionsAssertion } from "./assertions";
|
|
16
|
-
import { CallbackSigner, LocalSigner } from "./Signer";
|
|
17
|
-
import { Reader } from "./Reader";
|
|
18
|
-
import { Builder } from "./Builder";
|
|
19
15
|
import * as fs from "fs-extra";
|
|
20
16
|
import path from "path";
|
|
21
17
|
import * as crypto from "crypto";
|
|
18
|
+
import { isActionsAssertion } from "./assertions.js";
|
|
19
|
+
import { CallbackSigner, LocalSigner } from "./Signer.js";
|
|
20
|
+
import { Reader } from "./Reader.js";
|
|
21
|
+
import { Builder } from "./Builder.js";
|
|
22
22
|
const tempDir = path.join(__dirname, "tmp");
|
|
23
23
|
class TestSigner {
|
|
24
24
|
constructor(privateKey) {
|
|
@@ -179,7 +179,7 @@ describe("Builder", () => {
|
|
|
179
179
|
const reader = yield Reader.fromAsset(dest);
|
|
180
180
|
const manifestStore = reader.json();
|
|
181
181
|
const activeManifest = reader.getActive();
|
|
182
|
-
expect(manifestStore.validation_status).
|
|
182
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
183
183
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
184
184
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
185
185
|
}));
|
|
@@ -227,7 +227,7 @@ describe("Builder", () => {
|
|
|
227
227
|
});
|
|
228
228
|
const manifestStore = reader.json();
|
|
229
229
|
const activeManifest = reader.getActive();
|
|
230
|
-
expect(manifestStore.validation_status).
|
|
230
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
231
231
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
232
232
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
233
233
|
}));
|
|
@@ -248,7 +248,7 @@ describe("Builder", () => {
|
|
|
248
248
|
const reader = yield Reader.fromAsset(dest);
|
|
249
249
|
const manifestStore = reader.json();
|
|
250
250
|
const activeManifest = reader.getActive();
|
|
251
|
-
expect(manifestStore.validation_status).
|
|
251
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
252
252
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
253
253
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
254
254
|
}));
|
|
@@ -272,7 +272,7 @@ describe("Builder", () => {
|
|
|
272
272
|
});
|
|
273
273
|
const manifestStore = reader.json();
|
|
274
274
|
const activeManifest = reader.getActive();
|
|
275
|
-
expect(manifestStore.validation_status).
|
|
275
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
276
276
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
277
277
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
278
278
|
}));
|
|
@@ -297,7 +297,7 @@ describe("Builder", () => {
|
|
|
297
297
|
});
|
|
298
298
|
const manifestStore = reader.json();
|
|
299
299
|
const activeManifest = reader.getActive();
|
|
300
|
-
expect(manifestStore.validation_status).
|
|
300
|
+
expect(manifestStore.validation_status[0].code).toBe("signingCredential.untrusted");
|
|
301
301
|
expect(manifestStore.active_manifest).not.toBeUndefined();
|
|
302
302
|
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
303
303
|
}));
|
|
@@ -389,5 +389,148 @@ describe("Builder", () => {
|
|
|
389
389
|
expect(JSON.stringify(manifestStore)).toContain("Test Ingredient");
|
|
390
390
|
expect(JSON.stringify(manifestStore)).toContain("thumbnail.ingredient");
|
|
391
391
|
}));
|
|
392
|
+
it("should perform redaction workflow like test_redaction_async", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
393
|
+
// This test mirrors the Rust test_redaction_async test
|
|
394
|
+
// Create a reader to get the parent manifest label from the existing source
|
|
395
|
+
const reader = yield Reader.fromAsset(source);
|
|
396
|
+
const parentManifestLabel = reader.activeLabel();
|
|
397
|
+
expect(parentManifestLabel).toBeDefined();
|
|
398
|
+
// Create a redacted URI for the assertion we are going to redact
|
|
399
|
+
// Using a common assertion label that might exist
|
|
400
|
+
const assertionLabel = "stds.schema-org.CreativeWork";
|
|
401
|
+
const redactedUri = `contentauth:urn:uuid:${parentManifestLabel}/c2pa.assertions/${assertionLabel}`;
|
|
402
|
+
// Create a builder with edit intent and redactions
|
|
403
|
+
const redactionManifestDefinition = {
|
|
404
|
+
claim_generator: "test-generator",
|
|
405
|
+
claim_generator_info: [
|
|
406
|
+
{
|
|
407
|
+
name: "c2pa_test",
|
|
408
|
+
version: "1.0.0",
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
title: "Test_Redaction_Manifest",
|
|
412
|
+
format: "image/jpeg",
|
|
413
|
+
instance_id: "1234",
|
|
414
|
+
intent: "edit",
|
|
415
|
+
redactions: [redactedUri],
|
|
416
|
+
assertions: [
|
|
417
|
+
{
|
|
418
|
+
label: "org.test.assertion",
|
|
419
|
+
data: {},
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
resources: { resources: {} },
|
|
423
|
+
};
|
|
424
|
+
const builder = Builder.withJson(redactionManifestDefinition);
|
|
425
|
+
// Add a redacted action
|
|
426
|
+
const redactedAction = {
|
|
427
|
+
actions: [
|
|
428
|
+
{
|
|
429
|
+
action: "c2pa.redacted",
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
};
|
|
433
|
+
builder.addAssertion("c2pa.actions", redactedAction, "Cbor");
|
|
434
|
+
// Use the callback signer like the other test
|
|
435
|
+
const signerConfig = {
|
|
436
|
+
alg: "es256",
|
|
437
|
+
certs: [publicKey],
|
|
438
|
+
reserveSize: 10000,
|
|
439
|
+
tsaUrl: undefined,
|
|
440
|
+
directCoseHandling: false,
|
|
441
|
+
};
|
|
442
|
+
const testSigner = new TestSigner(privateKey);
|
|
443
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
444
|
+
// Sign the manifest with the original image as input
|
|
445
|
+
const dest = { buffer: null };
|
|
446
|
+
const outputBuffer = yield builder.signAsync(signer, source, dest);
|
|
447
|
+
expect(outputBuffer.length).toBeGreaterThan(0);
|
|
448
|
+
// Verify the result by reading the signed manifest
|
|
449
|
+
const signedReader = yield Reader.fromAsset({
|
|
450
|
+
buffer: dest.buffer,
|
|
451
|
+
mimeType: "image/jpeg",
|
|
452
|
+
});
|
|
453
|
+
expect(signedReader).toBeDefined();
|
|
454
|
+
// Check that the manifest was created successfully
|
|
455
|
+
const activeManifest = signedReader.getActive();
|
|
456
|
+
expect(activeManifest).toBeDefined();
|
|
457
|
+
// Verify the redacted action was added
|
|
458
|
+
const assertions = activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.assertions;
|
|
459
|
+
const actionsAssertion = assertions === null || assertions === void 0 ? void 0 : assertions.find((a) => a.label === "c2pa.actions.v2");
|
|
460
|
+
expect(actionsAssertion).toBeDefined();
|
|
461
|
+
if (actionsAssertion && isActionsAssertion(actionsAssertion)) {
|
|
462
|
+
const actions = actionsAssertion.data.actions;
|
|
463
|
+
const redactedAction = actions.find((a) => a.action === "c2pa.redacted");
|
|
464
|
+
expect(redactedAction).toBeDefined();
|
|
465
|
+
expect(redactedAction === null || redactedAction === void 0 ? void 0 : redactedAction.action).toBe("c2pa.redacted");
|
|
466
|
+
}
|
|
467
|
+
}));
|
|
468
|
+
it("should test builder remote url", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
469
|
+
// This test mirrors the Rust test_builder_remote_url test
|
|
470
|
+
// Create a simple manifest definition similar to simple_manifest_json()
|
|
471
|
+
const simpleManifestDefinition = {
|
|
472
|
+
claim_generator_info: [
|
|
473
|
+
{
|
|
474
|
+
name: "c2pa_test",
|
|
475
|
+
version: "1.0.0",
|
|
476
|
+
},
|
|
477
|
+
],
|
|
478
|
+
title: "Test_Manifest",
|
|
479
|
+
assertions: [
|
|
480
|
+
{
|
|
481
|
+
label: "c2pa.actions",
|
|
482
|
+
data: {
|
|
483
|
+
actions: [
|
|
484
|
+
{
|
|
485
|
+
action: "c2pa.created",
|
|
486
|
+
digitalSourceType: "http://c2pa.org/digitalsourcetype/empty",
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
};
|
|
493
|
+
const builder = Builder.withJson(simpleManifestDefinition);
|
|
494
|
+
// Set remote URL and no embed flag like the Rust test
|
|
495
|
+
builder.setRemoteUrl("http://my_remote_url");
|
|
496
|
+
builder.setNoEmbed(true);
|
|
497
|
+
// Use the callback signer
|
|
498
|
+
const signerConfig = {
|
|
499
|
+
alg: "es256",
|
|
500
|
+
certs: [publicKey],
|
|
501
|
+
reserveSize: 10000,
|
|
502
|
+
tsaUrl: undefined,
|
|
503
|
+
directCoseHandling: false,
|
|
504
|
+
};
|
|
505
|
+
const testSigner = new TestSigner(privateKey);
|
|
506
|
+
const signer = CallbackSigner.newSigner(signerConfig, testSigner.sign);
|
|
507
|
+
// Sign the Builder and write it to the output stream
|
|
508
|
+
const dest = { buffer: null };
|
|
509
|
+
const manifestData = yield builder.signAsync(signer, source, dest);
|
|
510
|
+
// Check to make sure we have a remote url and no manifest data embedded
|
|
511
|
+
// Reading the image directly should fail since no_embed = true
|
|
512
|
+
// Note: This might fail due to remote URL fetch, which is expected behavior
|
|
513
|
+
try {
|
|
514
|
+
yield Reader.fromAsset({
|
|
515
|
+
buffer: dest.buffer,
|
|
516
|
+
mimeType: "image/jpeg",
|
|
517
|
+
});
|
|
518
|
+
// If we get here, the test should fail because we expect no embedded manifest
|
|
519
|
+
expect.fail("Expected Reader.fromAsset to fail when no_embed = true");
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
// This is expected - there should be no embedded manifest or remote fetch should fail
|
|
523
|
+
expect(error).toBeDefined();
|
|
524
|
+
}
|
|
525
|
+
// Now validate the manifest against the written asset using the separate manifest data
|
|
526
|
+
const reader = yield Reader.fromManifestDataAndAsset(manifestData, {
|
|
527
|
+
buffer: dest.buffer,
|
|
528
|
+
mimeType: "image/jpeg",
|
|
529
|
+
});
|
|
530
|
+
// Check if the manifest has the expected structure
|
|
531
|
+
const activeManifest = reader.getActive();
|
|
532
|
+
expect(activeManifest).toBeDefined();
|
|
533
|
+
expect(activeManifest === null || activeManifest === void 0 ? void 0 : activeManifest.title).toBe("Test_Manifest");
|
|
534
|
+
}));
|
|
392
535
|
});
|
|
393
536
|
});
|
|
@@ -18,22 +18,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
19
19
|
// specific language governing permissions and limitations under
|
|
20
20
|
// each license.
|
|
21
|
-
|
|
21
|
+
import { getNeonBinary } from "./binary.js";
|
|
22
22
|
export class IdentityAssertionBuilder {
|
|
23
23
|
constructor(_builder) {
|
|
24
24
|
this._builder = _builder;
|
|
25
25
|
}
|
|
26
26
|
static identityBuilderForCredentialHolder(credentialHolder) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const builder =
|
|
28
|
+
const builder = getNeonBinary().identityBuilderForCredentialHolder(credentialHolder.signer());
|
|
29
29
|
return new IdentityAssertionBuilder(builder);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
addReferencedAssertions(referencedAssertions) {
|
|
33
|
-
|
|
33
|
+
getNeonBinary().identityBuilderAddReferencedAssertions.call(this._builder, referencedAssertions);
|
|
34
34
|
}
|
|
35
35
|
addRoles(roles) {
|
|
36
|
-
|
|
36
|
+
getNeonBinary().identityBuilderAddRoles.call(this._builder, roles);
|
|
37
37
|
}
|
|
38
38
|
builder() {
|
|
39
39
|
return this._builder;
|
|
@@ -44,11 +44,11 @@ export class IdentityAssertionSigner {
|
|
|
44
44
|
this._signer = _signer;
|
|
45
45
|
}
|
|
46
46
|
static new(signer) {
|
|
47
|
-
const identitySigner =
|
|
47
|
+
const identitySigner = getNeonBinary().identitySignerNew(signer);
|
|
48
48
|
return new IdentityAssertionSigner(identitySigner);
|
|
49
49
|
}
|
|
50
50
|
addIdentityAssertion(identityAssertionBuilder) {
|
|
51
|
-
|
|
51
|
+
getNeonBinary().identitySignerAddIdentityAssertion.call(this._signer, identityAssertionBuilder.builder());
|
|
52
52
|
}
|
|
53
53
|
signer() {
|
|
54
54
|
return this._signer;
|
|
@@ -62,18 +62,18 @@ export class CallbackCredentialHolder {
|
|
|
62
62
|
return this.callbackCredentialHolder;
|
|
63
63
|
}
|
|
64
64
|
static newCallbackCredentialHolder(reserveSize, sigType, callback) {
|
|
65
|
-
const credentialHolder =
|
|
65
|
+
const credentialHolder = getNeonBinary().newCallbackCredentialHolder(reserveSize, sigType, callback);
|
|
66
66
|
return new CallbackCredentialHolder(credentialHolder);
|
|
67
67
|
}
|
|
68
68
|
sign(payload) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
return
|
|
70
|
+
return getNeonBinary().callbackSignerSignPayload.call(this.callbackCredentialHolder, payload);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
reserveSize() {
|
|
74
|
-
return
|
|
74
|
+
return getNeonBinary().callbackCredentialHolderReserveSize.call(this.callbackCredentialHolder);
|
|
75
75
|
}
|
|
76
76
|
sigType() {
|
|
77
|
-
return
|
|
77
|
+
return getNeonBinary().callbackCredentialHolderSigType.call(this.callbackCredentialHolder);
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/Reader.js
CHANGED
|
@@ -12,40 +12,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
// this software is distributed on an "AS IS" BASIS, WITHOUT
|
|
17
|
-
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
|
|
18
|
-
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
|
|
19
|
-
// specific language governing permissions and limitations under
|
|
20
|
-
// each license.
|
|
21
|
-
const neon = require("./index.node");
|
|
15
|
+
import { getNeonBinary } from "./binary.js";
|
|
22
16
|
export class Reader {
|
|
23
17
|
constructor(reader) {
|
|
24
18
|
this.reader = reader;
|
|
25
19
|
}
|
|
26
20
|
json() {
|
|
27
|
-
return JSON.parse(
|
|
21
|
+
return JSON.parse(getNeonBinary().readerJson.call(this.reader));
|
|
28
22
|
}
|
|
29
23
|
remoteUrl() {
|
|
30
|
-
return
|
|
24
|
+
return getNeonBinary().readerRemoteUrl.call(this.reader);
|
|
31
25
|
}
|
|
32
26
|
isEmbedded() {
|
|
33
|
-
return
|
|
27
|
+
return getNeonBinary().readerIsEmbedded.call(this.reader);
|
|
34
28
|
}
|
|
35
29
|
resourceToAsset(uri, asset) {
|
|
36
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return
|
|
31
|
+
return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
|
|
38
32
|
});
|
|
39
33
|
}
|
|
40
34
|
static fromAsset(asset) {
|
|
41
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const reader = yield
|
|
36
|
+
const reader = yield getNeonBinary().readerFromAsset(asset);
|
|
43
37
|
return new Reader(reader);
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
static fromManifestDataAndAsset(manifestData, asset) {
|
|
47
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const reader = yield
|
|
42
|
+
const reader = yield getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset);
|
|
49
43
|
return new Reader(reader);
|
|
50
44
|
});
|
|
51
45
|
}
|
|
@@ -65,7 +59,7 @@ export class Reader {
|
|
|
65
59
|
}
|
|
66
60
|
postValidateCawg() {
|
|
67
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return
|
|
62
|
+
return getNeonBinary().readerPostValidateCawg.call(this.reader);
|
|
69
63
|
});
|
|
70
64
|
}
|
|
71
65
|
}
|