@contentauth/c2pa-node 0.1.3 → 0.2.1

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.
@@ -1,42 +1,8 @@
1
- "use strict";
2
1
  // Copyright 2024 Adobe. All rights reserved.
3
2
  // This file is licensed to you under the Apache License,
4
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
4
  // or the MIT license (http://opensource.org/licenses/MIT),
6
5
  // at your option.
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
6
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
7
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
8
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,26 +12,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46
12
  step((generator = generator.apply(thisArg, _arguments || [])).next());
47
13
  });
48
14
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
15
  // Unless required by applicable law or agreed to in writing,
54
16
  // this software is distributed on an "AS IS" BASIS, WITHOUT
55
17
  // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
56
18
  // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
57
19
  // specific language governing permissions and limitations under
58
20
  // each license.
59
- const Trustmark_1 = require("./Trustmark");
60
- const path_1 = __importDefault(require("path"));
61
- const fs = __importStar(require("fs-extra"));
62
- const sharp_1 = __importDefault(require("sharp"));
63
- const tempDir = path_1.default.join(__dirname, "..", "tmp");
21
+ import { Trustmark } from "./Trustmark";
22
+ import path from "path";
23
+ import * as fs from "fs-extra";
24
+ import sharp from "sharp";
25
+ const tempDir = path.join(__dirname, "..", "tmp");
64
26
  // Helper function to convert raw RGB pixel data to JPEG format
65
27
  function rawRgbToJpeg(rawRgbData, width, height) {
66
28
  return __awaiter(this, void 0, void 0, function* () {
67
29
  // Create a sharp image from raw RGB data
68
- const image = (0, sharp_1.default)(rawRgbData, {
30
+ const image = sharp(rawRgbData, {
69
31
  raw: {
70
32
  width,
71
33
  height,
@@ -84,14 +46,14 @@ describe("Trustmark", () => {
84
46
  const trustmarkConfig = {
85
47
  variant: "B", // Original Trustmark model
86
48
  version: "BCH_3", // Tolerates 3 bit flips
87
- modelPath: path_1.default.join(tempDir, "trustmark_models"), // Use temporary directory for model path
49
+ modelPath: path.join(tempDir, "trustmark_models"), // Use temporary directory for model path
88
50
  };
89
51
  beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
90
52
  yield fs.ensureDir(tempDir);
91
53
  // Use an actual test image from fixtures directory
92
54
  testImage = yield fs.readFile("./tests/fixtures/A.jpg");
93
55
  // Get image dimensions for converting raw pixel data
94
- const imageInfo = yield (0, sharp_1.default)(testImage).metadata();
56
+ const imageInfo = yield sharp(testImage).metadata();
95
57
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
58
  testImageWidth = imageInfo.width;
97
59
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -100,7 +62,7 @@ describe("Trustmark", () => {
100
62
  beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
101
63
  // Note: In a real test environment, you would need a valid model file
102
64
  // For now, we'll mock the trustmark creation or handle the case where model doesn't exist
103
- trustmark = yield Trustmark_1.Trustmark.newTrustmark(trustmarkConfig);
65
+ trustmark = yield Trustmark.newTrustmark(trustmarkConfig);
104
66
  }));
105
67
  describe("newTrustmark", () => {
106
68
  it("should create a new trustmark instance with valid config", () => __awaiter(void 0, void 0, void 0, function* () {
@@ -114,7 +76,7 @@ describe("Trustmark", () => {
114
76
  variant: "X", // Invalid variant
115
77
  version: "BCH_3", // Valid version
116
78
  };
117
- yield expect(Trustmark_1.Trustmark.newTrustmark(invalidConfig)).rejects.toThrow("Watermark configuration error: invalid variant");
79
+ yield expect(Trustmark.newTrustmark(invalidConfig)).rejects.toThrow("Watermark configuration error: invalid variant");
118
80
  }));
119
81
  });
120
82
  describe("encode", () => {
@@ -0,0 +1,23 @@
1
+ // Copyright 2025 Adobe. All rights reserved.
2
+ // This file is licensed to you under the Apache License,
3
+ // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4
+ // or the MIT license (http://opensource.org/licenses/MIT),
5
+ // at your option.
6
+ // Unless required by applicable law or agreed to in writing,
7
+ // this software is distributed on an "AS IS" BASIS, WITHOUT
8
+ // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
9
+ // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
10
+ // specific language governing permissions and limitations under
11
+ // each license.
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+ export function isActionsAssertion(obj) {
14
+ return (typeof obj === "object" &&
15
+ obj !== null &&
16
+ "label" in obj &&
17
+ "data" in obj &&
18
+ typeof obj.label === "string" &&
19
+ (obj.label === "c2pa.actions" || obj.label === "c2pa.actions.v2") &&
20
+ typeof obj.data === "object" &&
21
+ obj.data !== null &&
22
+ Array.isArray(obj.data.actions));
23
+ }
package/dist/index.js CHANGED
@@ -1,20 +1,12 @@
1
- "use strict";
2
1
  // Copyright 2025 Adobe. All rights reserved.
3
2
  // This file is licensed to you under the Apache License,
4
3
  // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
5
4
  // or the MIT license (http://opensource.org/licenses/MIT),
6
5
  // at your option.
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.Trustmark = exports.IdentityAssertionSigner = exports.IdentityAssertionBuilder = exports.CallbackSigner = exports.LocalSigner = exports.Reader = exports.Builder = void 0;
9
- var Builder_1 = require("./Builder");
10
- Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return Builder_1.Builder; } });
11
- var Reader_1 = require("./Reader");
12
- Object.defineProperty(exports, "Reader", { enumerable: true, get: function () { return Reader_1.Reader; } });
13
- var Signer_1 = require("./Signer");
14
- Object.defineProperty(exports, "LocalSigner", { enumerable: true, get: function () { return Signer_1.LocalSigner; } });
15
- Object.defineProperty(exports, "CallbackSigner", { enumerable: true, get: function () { return Signer_1.CallbackSigner; } });
16
- var IdentityAssertion_1 = require("./IdentityAssertion");
17
- Object.defineProperty(exports, "IdentityAssertionBuilder", { enumerable: true, get: function () { return IdentityAssertion_1.IdentityAssertionBuilder; } });
18
- Object.defineProperty(exports, "IdentityAssertionSigner", { enumerable: true, get: function () { return IdentityAssertion_1.IdentityAssertionSigner; } });
19
- var Trustmark_1 = require("./Trustmark");
20
- Object.defineProperty(exports, "Trustmark", { enumerable: true, get: function () { return Trustmark_1.Trustmark; } });
6
+ export { Builder } from "./Builder";
7
+ export { Reader } from "./Reader";
8
+ export { LocalSigner, CallbackSigner } from "./Signer";
9
+ export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion";
10
+ export { Trustmark } from "./Trustmark";
11
+ export { isActionsAssertion } from "./assertions";
12
+ export * from "./Settings";
package/dist/index.node CHANGED
Binary file
@@ -1,13 +1,13 @@
1
- import { IdentityAssertionSigner } from "./IdentityAssertion";
2
- import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, ManifestDefinition, SourceAsset } from "./types";
1
+ import type { BuilderInterface, CallbackSignerInterface, ClaimVersion, DestinationAsset, IdentityAssertionSignerInterface, JsCallbackSignerConfig, LocalSignerInterface, ManifestAssertionKind, SourceAsset } from "./types";
2
+ import type { Manifest } from "@contentauth/c2pa-types";
3
3
  export declare class Builder implements BuilderInterface {
4
4
  private builder;
5
5
  private constructor();
6
6
  static new(): Builder;
7
- static withJson(json: ManifestDefinition): Builder;
7
+ static withJson(json: Manifest): Builder;
8
8
  setNoEmbed(noEmbed?: boolean): void;
9
9
  setRemoteUrl(remoteUrl: string): void;
10
- addAssertion(label: string, assertion: string, assertionKind?: ManifestAssertionKind): void;
10
+ addAssertion(label: string, assertion: unknown, assertionKind?: ManifestAssertionKind): void;
11
11
  addResource(uri: string, resource: SourceAsset): Promise<void>;
12
12
  addIngredient(ingredientJson: string, ingredient: SourceAsset): Promise<void>;
13
13
  toArchive(asset: DestinationAsset): Promise<void>;
@@ -15,8 +15,7 @@ export declare class Builder implements BuilderInterface {
15
15
  sign(signer: LocalSignerInterface, input: SourceAsset, output: DestinationAsset): Buffer;
16
16
  signFile(signer: LocalSignerInterface, filePath: string, output: DestinationAsset): Buffer;
17
17
  signConfigAsync(callback: (data: Buffer) => Promise<Buffer>, signerConfig: JsCallbackSignerConfig, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
18
- signAsync(signer: CallbackSignerInterface, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
19
- identitySignAsync(signer: IdentityAssertionSigner, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
20
- getManifestDefinition(): ManifestDefinition;
18
+ signAsync(signer: CallbackSignerInterface | IdentityAssertionSignerInterface, input: SourceAsset, output: DestinationAsset): Promise<Buffer>;
19
+ getManifestDefinition(): Manifest;
21
20
  updateManifestProperty(property: string, value: ClaimVersion): void;
22
21
  }
@@ -1,16 +1,25 @@
1
- import type { CallbackSignerInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface } from "./types";
1
+ import type { CallbackCredentialHolderInterface, IdentityAssertionBuilderInterface, IdentityAssertionSignerInterface, NeonCallbackCredentialHolderHandle, NeonIdentityAssertionSignerHandle, NeonIdentityAssertionBuilderHandle, SignerPayload, NeonCallbackSignerHandle } from "./types";
2
2
  export declare class IdentityAssertionBuilder implements IdentityAssertionBuilderInterface {
3
3
  private _builder;
4
- private constructor();
5
- static identityBuilderForCredentialHolder(credentialHolder: CallbackSignerInterface): Promise<IdentityAssertionBuilder>;
4
+ constructor(_builder: NeonIdentityAssertionBuilderHandle);
5
+ static identityBuilderForCredentialHolder(credentialHolder: CallbackCredentialHolderInterface): Promise<IdentityAssertionBuilder>;
6
6
  addReferencedAssertions(referencedAssertions: string[]): void;
7
7
  addRoles(roles: string[]): void;
8
- builder(): IdentityAssertionBuilderInterface;
8
+ builder(): NeonIdentityAssertionBuilderHandle;
9
9
  }
10
10
  export declare class IdentityAssertionSigner implements IdentityAssertionSignerInterface {
11
11
  private _signer;
12
- private constructor();
13
- static new(signer: CallbackSignerInterface): IdentityAssertionSigner;
12
+ constructor(_signer: NeonIdentityAssertionSignerHandle);
13
+ static new(signer: NeonCallbackSignerHandle): IdentityAssertionSigner;
14
14
  addIdentityAssertion(identityAssertionBuilder: IdentityAssertionBuilder): void;
15
- signer(): IdentityAssertionSignerInterface;
15
+ signer(): NeonIdentityAssertionSignerHandle;
16
+ }
17
+ export declare class CallbackCredentialHolder implements CallbackCredentialHolderInterface {
18
+ private callbackCredentialHolder;
19
+ constructor(callbackCredentialHolder: NeonCallbackCredentialHolderHandle);
20
+ signer(): NeonCallbackCredentialHolderHandle;
21
+ static newCallbackCredentialHolder(reserveSize: number, sigType: string, callback: (signerPayload: SignerPayload) => Promise<Buffer>): CallbackCredentialHolder;
22
+ sign(payload: SignerPayload): Promise<Buffer>;
23
+ reserveSize(): number;
24
+ sigType(): string;
16
25
  }
@@ -1,7 +1,8 @@
1
- import type { DestinationAsset, Manifest, ManifestStore, ReaderInterface, SourceAsset } from "./types";
1
+ import type { DestinationAsset, ReaderInterface, SourceAsset, NeonReaderHandle } from "./types";
2
+ import type { Manifest, ManifestStore } from "@contentauth/c2pa-types";
2
3
  export declare class Reader implements ReaderInterface {
3
4
  private reader;
4
- private constructor();
5
+ constructor(reader: NeonReaderHandle);
5
6
  json(): ManifestStore;
6
7
  remoteUrl(): string;
7
8
  isEmbedded(): boolean;
@@ -0,0 +1,63 @@
1
+ import type { TrustConfig, VerifyConfig } from "./types";
2
+ /**
3
+ * Load settings from a JSON string and apply them globally.
4
+ * @param json The JSON string containing the settings configuration
5
+ */
6
+ export declare function loadC2paSettings(json: string): void;
7
+ /**
8
+ * Load settings from a TOML string and apply them globally.
9
+ * @param toml The TOML string containing the settings configuration
10
+ */
11
+ export declare function loadC2paSettingsToml(toml: string): void;
12
+ /**
13
+ * Load settings from a TOML or JSON file path and apply them globally.
14
+ * The file format is determined by the file extension (.toml for TOML, otherwise JSON).
15
+ * @param filePath The path to the settings file
16
+ */
17
+ export declare function loadSettingsFromFile(filePath: string): Promise<void>;
18
+ /**
19
+ * Load settings from a URL and apply them globally.
20
+ * The format is determined by the content-type header or file extension (.toml for TOML, otherwise JSON).
21
+ * @param url The URL to fetch the settings from
22
+ */
23
+ export declare function loadSettingsFromUrl(url: string): Promise<void>;
24
+ /**
25
+ * Get the current settings as a JSON string.
26
+ * @returns The JSON representation of the current settings
27
+ */
28
+ export declare function getSettingsJson(): string;
29
+ /**
30
+ * Load trust configuration into the main trust settings.
31
+ * @param trustConfig The trust configuration object
32
+ */
33
+ export declare function loadTrustConfig(trustConfig: TrustConfig): void;
34
+ /**
35
+ * Load trust configuration into the CAWG trust settings.
36
+ * @param trustConfig The trust configuration object
37
+ */
38
+ export declare function loadCawgTrustConfig(trustConfig: TrustConfig): void;
39
+ /**
40
+ * Get the current trust configuration.
41
+ * @returns The current trust configuration object
42
+ */
43
+ export declare function getTrustConfig(): TrustConfig;
44
+ /**
45
+ * Get the current CAWG trust configuration.
46
+ * @returns The current CAWG trust configuration object
47
+ */
48
+ export declare function getCawgTrustConfig(): TrustConfig;
49
+ /**
50
+ * Load verify configuration into the verify settings.
51
+ * @param verifyConfig The verify configuration object
52
+ */
53
+ export declare function loadVerifyConfig(verifyConfig: VerifyConfig): void;
54
+ /**
55
+ * Patch the verify configuration with any subset of fields.
56
+ * @param patch Partial verify config fields to update
57
+ */
58
+ export declare function patchVerifyConfig(patch: Partial<VerifyConfig>): void;
59
+ /**
60
+ * Get the current verify configuration.
61
+ * @returns The current verify configuration object
62
+ */
63
+ export declare function getVerifyConfig(): VerifyConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,19 @@
1
- import type { LocalSignerInterface, CallbackSignerInterface, SigningAlg, JsCallbackSignerConfig } from "./types";
1
+ import type { CallbackSignerInterface, JsCallbackSignerConfig, NeonCallbackSignerHandle, NeonLocalSignerHandle, LocalSignerInterface, SigningAlg } from "./types";
2
2
  export declare class LocalSigner implements LocalSignerInterface {
3
3
  private localSigner;
4
- private constructor();
4
+ constructor(localSigner: NeonLocalSignerHandle);
5
5
  static newSigner(certificate: Buffer, privateKey: Buffer, algorithm: SigningAlg, tsaUrl?: string): LocalSigner;
6
6
  sign(data: Buffer): Buffer;
7
7
  alg(): SigningAlg;
8
8
  certs(): Array<Buffer>;
9
9
  reserveSize(): number;
10
10
  timeAuthorityUrl(): string | undefined;
11
- signer(): LocalSignerInterface;
11
+ signer(): NeonLocalSignerHandle;
12
12
  }
13
13
  export declare class CallbackSigner implements CallbackSignerInterface {
14
14
  private callbackSigner;
15
- private constructor();
16
- signer(): CallbackSignerInterface;
15
+ constructor(callbackSigner: NeonCallbackSignerHandle);
16
+ signer(): NeonCallbackSignerHandle;
17
17
  static newSigner(config: JsCallbackSignerConfig, callback: (data: Buffer) => Promise<Buffer>): CallbackSigner;
18
18
  sign(data: Buffer): Promise<Buffer>;
19
19
  alg(): SigningAlg;
@@ -1,7 +1,7 @@
1
- import type { TrustmarkInterface as TrustmarkInterface, TrustmarkConfig } from "./types";
1
+ import type { TrustmarkInterface, TrustmarkConfig, NeonTrustmarkHandle } from "./types";
2
2
  export declare class Trustmark implements TrustmarkInterface {
3
3
  private trustmark;
4
- private constructor();
4
+ constructor(trustmark: NeonTrustmarkHandle);
5
5
  static newTrustmark(config: TrustmarkConfig): Promise<Trustmark>;
6
6
  encode(image: Buffer, strength: number, watermark?: string): Promise<Buffer>;
7
7
  decode(image: Buffer): Promise<string>;
@@ -0,0 +1,8 @@
1
+ export declare function isActionsAssertion(obj: unknown): obj is {
2
+ label: string;
3
+ data: {
4
+ actions: Array<{
5
+ action: string;
6
+ }>;
7
+ };
8
+ };
@@ -2,5 +2,7 @@ export type * from "./types";
2
2
  export { Builder } from "./Builder";
3
3
  export { Reader } from "./Reader";
4
4
  export { LocalSigner, CallbackSigner } from "./Signer";
5
- export { IdentityAssertionBuilder, IdentityAssertionSigner, } from "./IdentityAssertion";
5
+ export { IdentityAssertionBuilder, IdentityAssertionSigner, CallbackCredentialHolder, } from "./IdentityAssertion";
6
6
  export { Trustmark } from "./Trustmark";
7
+ export { isActionsAssertion } from "./assertions";
8
+ export * from "./Settings";