@gsengai/c2pa 0.1.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/LICENSE +201 -0
- package/dev-certs/README.md +21 -0
- package/dev-certs/dev-cert-chain.pem +29 -0
- package/dev-certs/dev-private-key.pem +5 -0
- package/dist/index.cjs +224 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Development certificates — NOT TRUSTED, integration testing only
|
|
2
|
+
|
|
3
|
+
> **⚠️ These are self-signed development certificates.** Anything signed with
|
|
4
|
+
> them **fails public trust validation by design** (validators report
|
|
5
|
+
> `signingCredential.untrusted`). They exist so the quickstart and the test
|
|
6
|
+
> suite work with zero setup. **Never use them in production.** For the
|
|
7
|
+
> production certificate path (CA-issued certificate meeting the C2PA trust
|
|
8
|
+
> requirements, keys in a KMS/HSM), see [`docs/CERTIFICATES.md`](../../../docs/CERTIFICATES.md).
|
|
9
|
+
|
|
10
|
+
Files:
|
|
11
|
+
|
|
12
|
+
- `dev-cert-chain.pem` — ES256 (P-256) leaf signing certificate + self-signed dev root, leaf first. The leaf carries the C2PA claim-signing profile (critical `digitalSignature` key usage, `emailProtection` EKU, `CA:FALSE`).
|
|
13
|
+
- `dev-private-key.pem` — the leaf's PKCS#8 private key. It is deliberately public: it protects nothing and must protect nothing.
|
|
14
|
+
|
|
15
|
+
Regenerate with `scripts/gen-dev-certs.sh` from the repo root (requires `openssl`).
|
|
16
|
+
|
|
17
|
+
`createImageSigner` falls back to these files when no `certPath`/`keyPath` is
|
|
18
|
+
given and prints a one-time warning to stderr saying so.
|
|
19
|
+
|
|
20
|
+
This library supports compliance with EU AI Act Article 50 and California
|
|
21
|
+
SB 942; it does not make you compliant and is not legal advice.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIICSDCCAe2gAwIBAgIULw16OkPhobTbRqVlT2sndaX86uYwCgYIKoZIzj0EAwIw
|
|
3
|
+
ZzELMAkGA1UEBhMCVVMxFDASBgNVBAoMC2dzZW5nYWkgZGV2MUIwQAYDVQQDDDln
|
|
4
|
+
c2VuZ2FpIERFViBST09UIC0gTk9UIFRSVVNURUQgLSBpbnRlZ3JhdGlvbiB0ZXN0
|
|
5
|
+
aW5nIG9ubHkwHhcNMjYwNzA5MTQ0OTUxWhcNMzYwNzA2MTQ0OTUxWjBpMQswCQYD
|
|
6
|
+
VQQGEwJVUzEUMBIGA1UECgwLZ3NlbmdhaSBkZXYxRDBCBgNVBAMMO2dzZW5nYWkg
|
|
7
|
+
REVWIFNJR05FUiAtIE5PVCBUUlVTVEVEIC0gaW50ZWdyYXRpb24gdGVzdGluZyBv
|
|
8
|
+
bmx5MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGZq/Fp22KZHjyaTOlRWQ1qpf
|
|
9
|
+
9gr5O0dHkiVY34ag7X8jqN5/yQHBWv61TMrPpAxxk9pWAgm/aMd5QIiyKVE2q6N1
|
|
10
|
+
MHMwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYB
|
|
11
|
+
BQUHAwQwHQYDVR0OBBYEFBjTK8/AY9ZVsO8Hz0ovyQXl4dtXMB8GA1UdIwQYMBaA
|
|
12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qgWw==
|
|
29
|
+
-----END CERTIFICATE-----
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
GENERATOR_ASSERTION_LABEL: () => GENERATOR_ASSERTION_LABEL,
|
|
24
|
+
TRAINED_ALGORITHMIC_MEDIA: () => TRAINED_ALGORITHMIC_MEDIA,
|
|
25
|
+
createImageSigner: () => createImageSigner,
|
|
26
|
+
detectImageMime: () => detectImageMime,
|
|
27
|
+
readManifest: () => readManifest
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_tsx@4.23.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
32
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
33
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
34
|
+
|
|
35
|
+
// src/mime.ts
|
|
36
|
+
var PNG_MAGIC = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
37
|
+
function detectImageMime(bytes, what) {
|
|
38
|
+
const head = Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.byteLength, 8));
|
|
39
|
+
if (head.length >= 8 && head.equals(PNG_MAGIC)) {
|
|
40
|
+
return "image/png";
|
|
41
|
+
}
|
|
42
|
+
if (head.length >= 3 && head[0] === 255 && head[1] === 216 && head[2] === 255) {
|
|
43
|
+
return "image/jpeg";
|
|
44
|
+
}
|
|
45
|
+
throw new TypeError(
|
|
46
|
+
`gsengai: ${what} is not a PNG or JPEG image (unrecognized magic bytes). Only PNG and JPEG are supported in the MVP.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/read.ts
|
|
51
|
+
var import_promises = require("fs/promises");
|
|
52
|
+
var import_c2pa_node = require("@contentauth/c2pa-node");
|
|
53
|
+
|
|
54
|
+
// src/settings.ts
|
|
55
|
+
var OFFLINE_NO_VERIFY_SETTINGS = {
|
|
56
|
+
verify: {
|
|
57
|
+
verify_after_reading: false,
|
|
58
|
+
verify_after_sign: false,
|
|
59
|
+
verify_trust: false,
|
|
60
|
+
ocsp_fetch: false,
|
|
61
|
+
remote_manifest_fetch: false
|
|
62
|
+
},
|
|
63
|
+
trust: { verify_trust_list: false }
|
|
64
|
+
};
|
|
65
|
+
var OFFLINE_VALIDATE_SETTINGS = {
|
|
66
|
+
verify: {
|
|
67
|
+
verify_after_reading: true,
|
|
68
|
+
verify_trust: true,
|
|
69
|
+
ocsp_fetch: false,
|
|
70
|
+
remote_manifest_fetch: false
|
|
71
|
+
},
|
|
72
|
+
trust: { verify_trust_list: true }
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/read.ts
|
|
76
|
+
async function readManifest(input) {
|
|
77
|
+
const bytes = typeof input === "string" ? await (0, import_promises.readFile)(input) : Buffer.from(input);
|
|
78
|
+
const mimeType = detectImageMime(bytes, "input");
|
|
79
|
+
const reader = await import_c2pa_node.Reader.fromAsset({ buffer: bytes, mimeType }, OFFLINE_VALIDATE_SETTINGS);
|
|
80
|
+
if (!reader) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const activeLabel = reader.activeLabel();
|
|
84
|
+
if (!activeLabel) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const store = reader.json();
|
|
88
|
+
const active = reader.getActive();
|
|
89
|
+
const results = store.validation_results?.activeManifest;
|
|
90
|
+
return {
|
|
91
|
+
activeLabel,
|
|
92
|
+
ingredientCount: active?.ingredients?.length ?? 0,
|
|
93
|
+
validationState: store.validation_state ?? null,
|
|
94
|
+
validationStatusCodes: {
|
|
95
|
+
success: (results?.success ?? []).map((s) => s.code),
|
|
96
|
+
informational: (results?.informational ?? []).map((s) => s.code),
|
|
97
|
+
failure: (results?.failure ?? []).map((s) => s.code)
|
|
98
|
+
},
|
|
99
|
+
manifestLabels: Object.keys(store.manifests ?? {})
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/signer.ts
|
|
104
|
+
var import_node_fs = require("fs");
|
|
105
|
+
var import_promises2 = require("fs/promises");
|
|
106
|
+
var import_node_path = require("path");
|
|
107
|
+
var import_node_url = require("url");
|
|
108
|
+
var import_c2pa_node2 = require("@contentauth/c2pa-node");
|
|
109
|
+
var import_core = require("@gsengai/core");
|
|
110
|
+
var VERSION = "0.1.0";
|
|
111
|
+
var GENERATOR_NAME = "gsengai-c2pa";
|
|
112
|
+
var GENERATOR_ASSERTION_LABEL = "org.gsengai.generator";
|
|
113
|
+
var TRAINED_ALGORITHMIC_MEDIA = "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia";
|
|
114
|
+
var DEV_CERT_PATH = (0, import_node_url.fileURLToPath)(new URL("../dev-certs/dev-cert-chain.pem", importMetaUrl));
|
|
115
|
+
var DEV_KEY_PATH = (0, import_node_url.fileURLToPath)(new URL("../dev-certs/dev-private-key.pem", importMetaUrl));
|
|
116
|
+
var devCertWarningShown = false;
|
|
117
|
+
function warnIfDevCerts(certPath, keyPath) {
|
|
118
|
+
if (certPath && keyPath || devCertWarningShown) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
devCertWarningShown = true;
|
|
122
|
+
console.warn(
|
|
123
|
+
"[gsengai] Using the bundled DEVELOPMENT certificates: signed manifests are UNTRUSTED by public validators and are for integration testing only. Provide certPath/keyPath with your own signing certificate for production \u2014 see docs/CERTIFICATES.md."
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function createImageSigner(options) {
|
|
127
|
+
const { store, systemId, failMode } = options;
|
|
128
|
+
if (typeof systemId !== "string" || systemId.length === 0) {
|
|
129
|
+
throw new TypeError("gsengai: systemId must be a non-empty string");
|
|
130
|
+
}
|
|
131
|
+
warnIfDevCerts(options.certPath, options.keyPath);
|
|
132
|
+
const cert = (0, import_node_fs.readFileSync)(options.certPath ?? DEV_CERT_PATH);
|
|
133
|
+
const key = (0, import_node_fs.readFileSync)(options.keyPath ?? DEV_KEY_PATH);
|
|
134
|
+
const signer = import_c2pa_node2.LocalSigner.newSigner(cert, key, "es256");
|
|
135
|
+
return {
|
|
136
|
+
async signImage(sign) {
|
|
137
|
+
if (typeof sign.model !== "string" || sign.model.length === 0) {
|
|
138
|
+
throw new TypeError("gsengai: model must be a non-empty string");
|
|
139
|
+
}
|
|
140
|
+
const inputBytes = typeof sign.input === "string" ? await (0, import_promises2.readFile)(sign.input) : Buffer.from(sign.input);
|
|
141
|
+
const mimeType = detectImageMime(inputBytes, "signImage input");
|
|
142
|
+
const existing = await import_c2pa_node2.Reader.fromAsset(
|
|
143
|
+
{ buffer: inputBytes, mimeType },
|
|
144
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
145
|
+
);
|
|
146
|
+
const title = sign.output !== void 0 ? (0, import_node_path.basename)(sign.output) : typeof sign.input === "string" ? (0, import_node_path.basename)(sign.input) : mimeType === "image/png" ? "image.png" : "image.jpg";
|
|
147
|
+
const builder = import_c2pa_node2.Builder.withJson(
|
|
148
|
+
{
|
|
149
|
+
// The backend allows exactly one claim_generator_info entry (ADR-0019);
|
|
150
|
+
// model info lives in the created action and the org.gsengai.generator assertion.
|
|
151
|
+
claim_generator_info: [{ name: GENERATOR_NAME, version: VERSION }],
|
|
152
|
+
title
|
|
153
|
+
},
|
|
154
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
155
|
+
);
|
|
156
|
+
const when = (/* @__PURE__ */ new Date()).toISOString();
|
|
157
|
+
if (existing) {
|
|
158
|
+
builder.setIntent("edit");
|
|
159
|
+
} else {
|
|
160
|
+
builder.setIntent({ create: TRAINED_ALGORITHMIC_MEDIA });
|
|
161
|
+
builder.addAction(
|
|
162
|
+
JSON.stringify({
|
|
163
|
+
action: "c2pa.created",
|
|
164
|
+
digitalSourceType: TRAINED_ALGORITHMIC_MEDIA,
|
|
165
|
+
softwareAgent: { name: sign.model },
|
|
166
|
+
when
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
builder.addAssertion(GENERATOR_ASSERTION_LABEL, {
|
|
171
|
+
generator: { name: GENERATOR_NAME, version: VERSION },
|
|
172
|
+
model: sign.model,
|
|
173
|
+
when
|
|
174
|
+
});
|
|
175
|
+
let signedBytes;
|
|
176
|
+
let output;
|
|
177
|
+
if (sign.output !== void 0) {
|
|
178
|
+
builder.sign(signer, { buffer: inputBytes, mimeType }, { path: sign.output });
|
|
179
|
+
signedBytes = await (0, import_promises2.readFile)(sign.output);
|
|
180
|
+
output = sign.output;
|
|
181
|
+
} else {
|
|
182
|
+
const dest = { buffer: null };
|
|
183
|
+
builder.sign(signer, { buffer: inputBytes, mimeType }, dest);
|
|
184
|
+
if (!dest.buffer) {
|
|
185
|
+
throw new Error("gsengai: signing produced no output buffer");
|
|
186
|
+
}
|
|
187
|
+
signedBytes = dest.buffer;
|
|
188
|
+
output = signedBytes;
|
|
189
|
+
}
|
|
190
|
+
const readBack = await import_c2pa_node2.Reader.fromAsset(
|
|
191
|
+
{ buffer: signedBytes, mimeType },
|
|
192
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
193
|
+
);
|
|
194
|
+
const manifestLabel = readBack?.activeLabel();
|
|
195
|
+
if (!manifestLabel) {
|
|
196
|
+
throw new Error("gsengai: signed output has no readable active manifest");
|
|
197
|
+
}
|
|
198
|
+
const record = (0, import_core.safeAppend)(
|
|
199
|
+
store,
|
|
200
|
+
{
|
|
201
|
+
modality: "image",
|
|
202
|
+
model: sign.model,
|
|
203
|
+
systemId,
|
|
204
|
+
outputBytes: signedBytes,
|
|
205
|
+
manifestRef: manifestLabel,
|
|
206
|
+
markingMethods: ["c2pa"],
|
|
207
|
+
promptHash: sign.promptHash ?? null,
|
|
208
|
+
disclosureContext: sign.disclosureContext ?? null
|
|
209
|
+
},
|
|
210
|
+
failMode
|
|
211
|
+
);
|
|
212
|
+
return { output, record, manifestLabel };
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
GENERATOR_ASSERTION_LABEL,
|
|
219
|
+
TRAINED_ALGORITHMIC_MEDIA,
|
|
220
|
+
createImageSigner,
|
|
221
|
+
detectImageMime,
|
|
222
|
+
readManifest
|
|
223
|
+
});
|
|
224
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_tsx@4.23.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","../src/mime.ts","../src/read.ts","../src/settings.ts","../src/signer.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nexport type { ImageMime } from \"./mime\";\nexport { detectImageMime } from \"./mime\";\nexport type { ManifestSummary, ValidationStatusCodes } from \"./read\";\nexport { readManifest } from \"./read\";\nexport type {\n CreateImageSignerOptions,\n ImageSigner,\n SignImageOptions,\n SignImageResult,\n} from \"./signer\";\nexport {\n createImageSigner,\n GENERATOR_ASSERTION_LABEL,\n TRAINED_ALGORITHMIC_MEDIA,\n} from \"./signer\";\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","// SPDX-License-Identifier: Apache-2.0\n\nexport type ImageMime = \"image/png\" | \"image/jpeg\";\n\nconst PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n\n/**\n * Detect the image format from magic bytes. Only PNG and JPEG are supported in\n * the MVP (PRD B1); anything else — including corrupt or truncated data — throws.\n */\nexport function detectImageMime(bytes: Uint8Array, what: string): ImageMime {\n const head = Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.byteLength, 8));\n if (head.length >= 8 && head.equals(PNG_MAGIC)) {\n return \"image/png\";\n }\n if (head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff) {\n return \"image/jpeg\";\n }\n throw new TypeError(\n `gsengai: ${what} is not a PNG or JPEG image (unrecognized magic bytes). ` +\n \"Only PNG and JPEG are supported in the MVP.\",\n );\n}\n","// SPDX-License-Identifier: Apache-2.0\nimport { readFile } from \"node:fs/promises\";\nimport { Reader } from \"@contentauth/c2pa-node\";\nimport { detectImageMime } from \"./mime\";\nimport { OFFLINE_VALIDATE_SETTINGS } from \"./settings\";\n\n/** Validation status codes as reported by the C2PA validator, grouped by outcome. */\nexport interface ValidationStatusCodes {\n success: string[];\n informational: string[];\n failure: string[];\n}\n\n/** Summary of the C2PA manifest store embedded in an asset. */\nexport interface ManifestSummary {\n /** Label of the active (most recent) manifest. */\n activeLabel: string;\n /** Number of ingredients on the active manifest (parents + components). */\n ingredientCount: number;\n /**\n * Overall validation state as reported by the validator. Dev-cert-signed\n * assets report a valid signature but an untrusted credential — see\n * docs/CERTIFICATES.md; this library never claims trust it does not have.\n */\n validationState: string | null;\n /** Exact validator status codes for the active manifest. */\n validationStatusCodes: ValidationStatusCodes;\n /** All manifest labels in the store — the provenance chain, active first is not guaranteed. */\n manifestLabels: string[];\n}\n\ninterface ValidationResultsShape {\n activeManifest?: {\n success?: { code: string }[];\n informational?: { code: string }[];\n failure?: { code: string }[];\n };\n}\n\n/**\n * Read and locally validate the C2PA manifest store of a PNG/JPEG asset.\n * Returns null when the asset carries no manifest. Never fetches anything\n * remote (no OCSP, no remote manifests); trust is evaluated against local\n * configuration only.\n */\nexport async function readManifest(input: string | Uint8Array): Promise<ManifestSummary | null> {\n const bytes = typeof input === \"string\" ? await readFile(input) : Buffer.from(input);\n const mimeType = detectImageMime(bytes, \"input\");\n const reader = await Reader.fromAsset({ buffer: bytes, mimeType }, OFFLINE_VALIDATE_SETTINGS);\n if (!reader) {\n return null;\n }\n const activeLabel = reader.activeLabel();\n if (!activeLabel) {\n return null;\n }\n const store = reader.json() as {\n manifests?: Record<string, unknown>;\n validation_state?: string;\n validation_results?: ValidationResultsShape;\n };\n const active = reader.getActive();\n const results = store.validation_results?.activeManifest;\n return {\n activeLabel,\n ingredientCount: active?.ingredients?.length ?? 0,\n validationState: store.validation_state ?? null,\n validationStatusCodes: {\n success: (results?.success ?? []).map((s) => s.code),\n informational: (results?.informational ?? []).map((s) => s.code),\n failure: (results?.failure ?? []).map((s) => s.code),\n },\n manifestLabels: Object.keys(store.manifests ?? {}),\n };\n}\n","// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Offline discipline: every Reader/Builder gets explicit\n * settings so no OCSP or remote-manifest fetch can occur at sign or read time,\n * and no TSA URL is ever configured. Trust evaluation stays local: it runs\n * against configured anchors only (none by default), which is what makes the\n * dev-cert `signingCredential.untrusted` status honest and reproducible.\n */\n\n/** Settings for signing and for existence-check reads: no verification, no fetches. */\nexport const OFFLINE_NO_VERIFY_SETTINGS = {\n verify: {\n verify_after_reading: false,\n verify_after_sign: false,\n verify_trust: false,\n ocsp_fetch: false,\n remote_manifest_fetch: false,\n },\n trust: { verify_trust_list: false },\n} as const;\n\n/** Settings for `readManifest`: full local validation including trust, still no fetches. */\nexport const OFFLINE_VALIDATE_SETTINGS = {\n verify: {\n verify_after_reading: true,\n verify_trust: true,\n ocsp_fetch: false,\n remote_manifest_fetch: false,\n },\n trust: { verify_trust_list: true },\n} as const;\n","// SPDX-License-Identifier: Apache-2.0\nimport { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Builder, LocalSigner, Reader } from \"@contentauth/c2pa-node\";\nimport { type EvidenceRecord, type EvidenceStore, type FailMode, safeAppend } from \"@gsengai/core\";\nimport { detectImageMime } from \"./mime\";\nimport { OFFLINE_NO_VERIFY_SETTINGS } from \"./settings\";\n\nconst VERSION = \"0.1.0\";\nconst GENERATOR_NAME = \"gsengai-c2pa\";\n/** Label of the custom assertion carrying generator/model info on every signing (ADR-0019). */\nexport const GENERATOR_ASSERTION_LABEL = \"org.gsengai.generator\";\nexport const TRAINED_ALGORITHMIC_MEDIA =\n \"http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia\";\n\nconst DEV_CERT_PATH = fileURLToPath(new URL(\"../dev-certs/dev-cert-chain.pem\", import.meta.url));\nconst DEV_KEY_PATH = fileURLToPath(new URL(\"../dev-certs/dev-private-key.pem\", import.meta.url));\n\nlet devCertWarningShown = false;\n\nexport interface CreateImageSignerOptions {\n store: EvidenceStore;\n /** Integrator's system/feature identifier — persisted as `system_id` (PRD §4). */\n systemId: string;\n /** PEM certificate chain (leaf first). Defaults to the bundled DEV certificates. */\n certPath?: string;\n /** PKCS#8 PEM private key for the leaf certificate. Defaults to the bundled DEV key. */\n keyPath?: string;\n /**\n * Applies to evidence-store failures only (ADR-0017): `open` (default) warns,\n * counts the lost record, and still returns the signed asset; `strict` throws.\n * Signing failures always throw regardless of this setting.\n */\n failMode?: FailMode;\n}\n\nexport interface SignImageOptions {\n /** Source image: file path or bytes. PNG and JPEG only (MVP). */\n input: string | Uint8Array;\n /** Destination file path. Omit to receive the signed asset as a Buffer. */\n output?: string;\n /** Model identifier that generated the image — recorded in the manifest and the evidence record. */\n model: string;\n /** Optional prompt hash (compute with `hashPrompt` from @gsengai/core). */\n promptHash?: string | null;\n disclosureContext?: string | null;\n}\n\nexport interface SignImageResult {\n /** The signed asset: the `output` path when one was given, otherwise a Buffer. */\n output: string | Buffer;\n /** The appended evidence record; null only in fail-open mode when the store failed (the loss is counted). */\n record: EvidenceRecord | null;\n /** Active manifest label of the signed output, as reported by the C2PA reader (ADR-0018). */\n manifestLabel: string;\n}\n\nexport interface ImageSigner {\n /**\n * Sign a PNG/JPEG with a C2PA manifest declaring AI generation and append one\n * evidence record (PRD B6). If the input already carries a manifest it is\n * preserved as the parent ingredient — never overwritten (PRD B3, ADR-0015).\n */\n signImage(options: SignImageOptions): Promise<SignImageResult>;\n}\n\nfunction warnIfDevCerts(certPath: string | undefined, keyPath: string | undefined): void {\n if ((certPath && keyPath) || devCertWarningShown) {\n return;\n }\n devCertWarningShown = true;\n console.warn(\n \"[gsengai] Using the bundled DEVELOPMENT certificates: signed manifests are UNTRUSTED \" +\n \"by public validators and are for integration testing only. Provide certPath/keyPath \" +\n \"with your own signing certificate for production — see docs/CERTIFICATES.md.\",\n );\n}\n\nexport function createImageSigner(options: CreateImageSignerOptions): ImageSigner {\n const { store, systemId, failMode } = options;\n if (typeof systemId !== \"string\" || systemId.length === 0) {\n throw new TypeError(\"gsengai: systemId must be a non-empty string\");\n }\n warnIfDevCerts(options.certPath, options.keyPath);\n // Read eagerly so a bad path fails at construction, not at first sign.\n const cert = readFileSync(options.certPath ?? DEV_CERT_PATH);\n const key = readFileSync(options.keyPath ?? DEV_KEY_PATH);\n const signer = LocalSigner.newSigner(cert, key, \"es256\"); // no TSA URL — offline by design\n\n return {\n async signImage(sign: SignImageOptions): Promise<SignImageResult> {\n if (typeof sign.model !== \"string\" || sign.model.length === 0) {\n throw new TypeError(\"gsengai: model must be a non-empty string\");\n }\n const inputBytes =\n typeof sign.input === \"string\" ? await readFile(sign.input) : Buffer.from(sign.input);\n const mimeType = detectImageMime(inputBytes, \"signImage input\");\n\n // ADR-0015 intent mapping: existing manifest → edit + parent ingredient\n // (chained, never overwritten); none → create + trainedAlgorithmicMedia.\n const existing = await Reader.fromAsset(\n { buffer: inputBytes, mimeType },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const title =\n sign.output !== undefined\n ? basename(sign.output)\n : typeof sign.input === \"string\"\n ? basename(sign.input)\n : mimeType === \"image/png\"\n ? \"image.png\"\n : \"image.jpg\";\n const builder = Builder.withJson(\n {\n // The backend allows exactly one claim_generator_info entry (ADR-0019);\n // model info lives in the created action and the org.gsengai.generator assertion.\n claim_generator_info: [{ name: GENERATOR_NAME, version: VERSION }],\n title,\n },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const when = new Date().toISOString();\n if (existing) {\n // Edit path: the builder generates the parent ingredient and its\n // c2pa.opened action itself — adding our own opened action would drop\n // the ingredient reference and fail validation (ADR-0019).\n builder.setIntent(\"edit\");\n } else {\n builder.setIntent({ create: TRAINED_ALGORITHMIC_MEDIA });\n builder.addAction(\n JSON.stringify({\n action: \"c2pa.created\",\n digitalSourceType: TRAINED_ALGORITHMIC_MEDIA,\n softwareAgent: { name: sign.model },\n when,\n }),\n );\n }\n // Generator/model info + timestamp on both paths (PRD B2, ADR-0019).\n builder.addAssertion(GENERATOR_ASSERTION_LABEL, {\n generator: { name: GENERATOR_NAME, version: VERSION },\n model: sign.model,\n when,\n });\n\n // Signing failures always throw (ADR-0017) — nothing to fail open with.\n let signedBytes: Buffer;\n let output: string | Buffer;\n if (sign.output !== undefined) {\n builder.sign(signer, { buffer: inputBytes, mimeType }, { path: sign.output });\n signedBytes = await readFile(sign.output);\n output = sign.output;\n } else {\n const dest: { buffer: Buffer | null } = { buffer: null };\n builder.sign(signer, { buffer: inputBytes, mimeType }, dest);\n if (!dest.buffer) {\n throw new Error(\"gsengai: signing produced no output buffer\");\n }\n signedBytes = dest.buffer;\n output = signedBytes;\n }\n\n const readBack = await Reader.fromAsset(\n { buffer: signedBytes, mimeType },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const manifestLabel = readBack?.activeLabel();\n if (!manifestLabel) {\n throw new Error(\"gsengai: signed output has no readable active manifest\");\n }\n\n // Evidence-store failures follow failMode (ADR-0017); output_hash is the\n // sha256 of the signed output bytes, hashed centrally in core (ADR-0018).\n const record = safeAppend(\n store,\n {\n modality: \"image\",\n model: sign.model,\n systemId,\n outputBytes: signedBytes,\n manifestRef: manifestLabel,\n markingMethods: [\"c2pa\"],\n promptHash: sign.promptHash ?? null,\n disclosureContext: sign.disclosureContext ?? null,\n },\n failMode,\n );\n\n return { output, record, manifestLabel };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gB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GD,UAAI;AACJ,UAAI;AACJ,UAAI,KAAK,WAAW,QAAW;AAC7B,gBAAQ,KAAK,QAAQ,EAAE,QAAQ,YAAY,SAAS,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAC5E,sBAAc,UAAM,2BAAS,KAAK,MAAM;AACxC,iBAAS,KAAK;AAAA,MAChB,OAAO;AACL,cAAM,OAAkC,EAAE,QAAQ,KAAK;AACvD,gBAAQ,KAAK,QAAQ,EAAE,QAAQ,YAAY,SAAS,GAAG,IAAI;AAC3D,YAAI,CAAC,KAAK,QAAQ;AAChB,gBAAM,IAAI,MAAM,4CAA4C;AAAA,QAC9D;AACA,sBAAc,KAAK;AACnB,iBAAS;AAAA,MACX;AAEA,YAAM,WAAW,MAAM,yBAAO;AAAA,QAC5B,EAAE,QAAQ,aAAa,SAAS;AAAA,QAChC;AAAA,MACF;AACA,YAAM,gBAAgB,UAAU,YAAY;AAC5C,UAAI,CAAC,eAAe;AAClB,cAAM,IAAI,MAAM,wDAAwD;AAAA,MAC1E;AAIA,YAAM,aAAS;AAAA,QACb;AAAA,QACA;AAAA,UACE,UAAU;AAAA,UACV,OAAO,KAAK;AAAA,UACZ;AAAA,UACA,aAAa;AAAA,UACb,aAAa;AAAA,UACb,gBAAgB,CAAC,MAAM;AAAA,UACvB,YAAY,KAAK,cAAc;AAAA,UAC/B,mBAAmB,KAAK,qBAAqB;AAAA,QAC/C;AAAA,QACA;AAAA,MACF;AAEA,aAAO,EAAE,QAAQ,QAAQ,cAAc;AAAA,IACzC;AAAA,EACF;AACF;","names":["import_promises","import_c2pa_node"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EvidenceStore, FailMode, EvidenceRecord } from '@gsengai/core';
|
|
2
|
+
|
|
3
|
+
type ImageMime = "image/png" | "image/jpeg";
|
|
4
|
+
/**
|
|
5
|
+
* Detect the image format from magic bytes. Only PNG and JPEG are supported in
|
|
6
|
+
* the MVP (PRD B1); anything else — including corrupt or truncated data — throws.
|
|
7
|
+
*/
|
|
8
|
+
declare function detectImageMime(bytes: Uint8Array, what: string): ImageMime;
|
|
9
|
+
|
|
10
|
+
/** Validation status codes as reported by the C2PA validator, grouped by outcome. */
|
|
11
|
+
interface ValidationStatusCodes {
|
|
12
|
+
success: string[];
|
|
13
|
+
informational: string[];
|
|
14
|
+
failure: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Summary of the C2PA manifest store embedded in an asset. */
|
|
17
|
+
interface ManifestSummary {
|
|
18
|
+
/** Label of the active (most recent) manifest. */
|
|
19
|
+
activeLabel: string;
|
|
20
|
+
/** Number of ingredients on the active manifest (parents + components). */
|
|
21
|
+
ingredientCount: number;
|
|
22
|
+
/**
|
|
23
|
+
* Overall validation state as reported by the validator. Dev-cert-signed
|
|
24
|
+
* assets report a valid signature but an untrusted credential — see
|
|
25
|
+
* docs/CERTIFICATES.md; this library never claims trust it does not have.
|
|
26
|
+
*/
|
|
27
|
+
validationState: string | null;
|
|
28
|
+
/** Exact validator status codes for the active manifest. */
|
|
29
|
+
validationStatusCodes: ValidationStatusCodes;
|
|
30
|
+
/** All manifest labels in the store — the provenance chain, active first is not guaranteed. */
|
|
31
|
+
manifestLabels: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read and locally validate the C2PA manifest store of a PNG/JPEG asset.
|
|
35
|
+
* Returns null when the asset carries no manifest. Never fetches anything
|
|
36
|
+
* remote (no OCSP, no remote manifests); trust is evaluated against local
|
|
37
|
+
* configuration only.
|
|
38
|
+
*/
|
|
39
|
+
declare function readManifest(input: string | Uint8Array): Promise<ManifestSummary | null>;
|
|
40
|
+
|
|
41
|
+
/** Label of the custom assertion carrying generator/model info on every signing (ADR-0019). */
|
|
42
|
+
declare const GENERATOR_ASSERTION_LABEL = "org.gsengai.generator";
|
|
43
|
+
declare const TRAINED_ALGORITHMIC_MEDIA = "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia";
|
|
44
|
+
interface CreateImageSignerOptions {
|
|
45
|
+
store: EvidenceStore;
|
|
46
|
+
/** Integrator's system/feature identifier — persisted as `system_id` (PRD §4). */
|
|
47
|
+
systemId: string;
|
|
48
|
+
/** PEM certificate chain (leaf first). Defaults to the bundled DEV certificates. */
|
|
49
|
+
certPath?: string;
|
|
50
|
+
/** PKCS#8 PEM private key for the leaf certificate. Defaults to the bundled DEV key. */
|
|
51
|
+
keyPath?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Applies to evidence-store failures only (ADR-0017): `open` (default) warns,
|
|
54
|
+
* counts the lost record, and still returns the signed asset; `strict` throws.
|
|
55
|
+
* Signing failures always throw regardless of this setting.
|
|
56
|
+
*/
|
|
57
|
+
failMode?: FailMode;
|
|
58
|
+
}
|
|
59
|
+
interface SignImageOptions {
|
|
60
|
+
/** Source image: file path or bytes. PNG and JPEG only (MVP). */
|
|
61
|
+
input: string | Uint8Array;
|
|
62
|
+
/** Destination file path. Omit to receive the signed asset as a Buffer. */
|
|
63
|
+
output?: string;
|
|
64
|
+
/** Model identifier that generated the image — recorded in the manifest and the evidence record. */
|
|
65
|
+
model: string;
|
|
66
|
+
/** Optional prompt hash (compute with `hashPrompt` from @gsengai/core). */
|
|
67
|
+
promptHash?: string | null;
|
|
68
|
+
disclosureContext?: string | null;
|
|
69
|
+
}
|
|
70
|
+
interface SignImageResult {
|
|
71
|
+
/** The signed asset: the `output` path when one was given, otherwise a Buffer. */
|
|
72
|
+
output: string | Buffer;
|
|
73
|
+
/** The appended evidence record; null only in fail-open mode when the store failed (the loss is counted). */
|
|
74
|
+
record: EvidenceRecord | null;
|
|
75
|
+
/** Active manifest label of the signed output, as reported by the C2PA reader (ADR-0018). */
|
|
76
|
+
manifestLabel: string;
|
|
77
|
+
}
|
|
78
|
+
interface ImageSigner {
|
|
79
|
+
/**
|
|
80
|
+
* Sign a PNG/JPEG with a C2PA manifest declaring AI generation and append one
|
|
81
|
+
* evidence record (PRD B6). If the input already carries a manifest it is
|
|
82
|
+
* preserved as the parent ingredient — never overwritten (PRD B3, ADR-0015).
|
|
83
|
+
*/
|
|
84
|
+
signImage(options: SignImageOptions): Promise<SignImageResult>;
|
|
85
|
+
}
|
|
86
|
+
declare function createImageSigner(options: CreateImageSignerOptions): ImageSigner;
|
|
87
|
+
|
|
88
|
+
export { type CreateImageSignerOptions, GENERATOR_ASSERTION_LABEL, type ImageMime, type ImageSigner, type ManifestSummary, type SignImageOptions, type SignImageResult, TRAINED_ALGORITHMIC_MEDIA, type ValidationStatusCodes, createImageSigner, detectImageMime, readManifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EvidenceStore, FailMode, EvidenceRecord } from '@gsengai/core';
|
|
2
|
+
|
|
3
|
+
type ImageMime = "image/png" | "image/jpeg";
|
|
4
|
+
/**
|
|
5
|
+
* Detect the image format from magic bytes. Only PNG and JPEG are supported in
|
|
6
|
+
* the MVP (PRD B1); anything else — including corrupt or truncated data — throws.
|
|
7
|
+
*/
|
|
8
|
+
declare function detectImageMime(bytes: Uint8Array, what: string): ImageMime;
|
|
9
|
+
|
|
10
|
+
/** Validation status codes as reported by the C2PA validator, grouped by outcome. */
|
|
11
|
+
interface ValidationStatusCodes {
|
|
12
|
+
success: string[];
|
|
13
|
+
informational: string[];
|
|
14
|
+
failure: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Summary of the C2PA manifest store embedded in an asset. */
|
|
17
|
+
interface ManifestSummary {
|
|
18
|
+
/** Label of the active (most recent) manifest. */
|
|
19
|
+
activeLabel: string;
|
|
20
|
+
/** Number of ingredients on the active manifest (parents + components). */
|
|
21
|
+
ingredientCount: number;
|
|
22
|
+
/**
|
|
23
|
+
* Overall validation state as reported by the validator. Dev-cert-signed
|
|
24
|
+
* assets report a valid signature but an untrusted credential — see
|
|
25
|
+
* docs/CERTIFICATES.md; this library never claims trust it does not have.
|
|
26
|
+
*/
|
|
27
|
+
validationState: string | null;
|
|
28
|
+
/** Exact validator status codes for the active manifest. */
|
|
29
|
+
validationStatusCodes: ValidationStatusCodes;
|
|
30
|
+
/** All manifest labels in the store — the provenance chain, active first is not guaranteed. */
|
|
31
|
+
manifestLabels: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read and locally validate the C2PA manifest store of a PNG/JPEG asset.
|
|
35
|
+
* Returns null when the asset carries no manifest. Never fetches anything
|
|
36
|
+
* remote (no OCSP, no remote manifests); trust is evaluated against local
|
|
37
|
+
* configuration only.
|
|
38
|
+
*/
|
|
39
|
+
declare function readManifest(input: string | Uint8Array): Promise<ManifestSummary | null>;
|
|
40
|
+
|
|
41
|
+
/** Label of the custom assertion carrying generator/model info on every signing (ADR-0019). */
|
|
42
|
+
declare const GENERATOR_ASSERTION_LABEL = "org.gsengai.generator";
|
|
43
|
+
declare const TRAINED_ALGORITHMIC_MEDIA = "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia";
|
|
44
|
+
interface CreateImageSignerOptions {
|
|
45
|
+
store: EvidenceStore;
|
|
46
|
+
/** Integrator's system/feature identifier — persisted as `system_id` (PRD §4). */
|
|
47
|
+
systemId: string;
|
|
48
|
+
/** PEM certificate chain (leaf first). Defaults to the bundled DEV certificates. */
|
|
49
|
+
certPath?: string;
|
|
50
|
+
/** PKCS#8 PEM private key for the leaf certificate. Defaults to the bundled DEV key. */
|
|
51
|
+
keyPath?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Applies to evidence-store failures only (ADR-0017): `open` (default) warns,
|
|
54
|
+
* counts the lost record, and still returns the signed asset; `strict` throws.
|
|
55
|
+
* Signing failures always throw regardless of this setting.
|
|
56
|
+
*/
|
|
57
|
+
failMode?: FailMode;
|
|
58
|
+
}
|
|
59
|
+
interface SignImageOptions {
|
|
60
|
+
/** Source image: file path or bytes. PNG and JPEG only (MVP). */
|
|
61
|
+
input: string | Uint8Array;
|
|
62
|
+
/** Destination file path. Omit to receive the signed asset as a Buffer. */
|
|
63
|
+
output?: string;
|
|
64
|
+
/** Model identifier that generated the image — recorded in the manifest and the evidence record. */
|
|
65
|
+
model: string;
|
|
66
|
+
/** Optional prompt hash (compute with `hashPrompt` from @gsengai/core). */
|
|
67
|
+
promptHash?: string | null;
|
|
68
|
+
disclosureContext?: string | null;
|
|
69
|
+
}
|
|
70
|
+
interface SignImageResult {
|
|
71
|
+
/** The signed asset: the `output` path when one was given, otherwise a Buffer. */
|
|
72
|
+
output: string | Buffer;
|
|
73
|
+
/** The appended evidence record; null only in fail-open mode when the store failed (the loss is counted). */
|
|
74
|
+
record: EvidenceRecord | null;
|
|
75
|
+
/** Active manifest label of the signed output, as reported by the C2PA reader (ADR-0018). */
|
|
76
|
+
manifestLabel: string;
|
|
77
|
+
}
|
|
78
|
+
interface ImageSigner {
|
|
79
|
+
/**
|
|
80
|
+
* Sign a PNG/JPEG with a C2PA manifest declaring AI generation and append one
|
|
81
|
+
* evidence record (PRD B6). If the input already carries a manifest it is
|
|
82
|
+
* preserved as the parent ingredient — never overwritten (PRD B3, ADR-0015).
|
|
83
|
+
*/
|
|
84
|
+
signImage(options: SignImageOptions): Promise<SignImageResult>;
|
|
85
|
+
}
|
|
86
|
+
declare function createImageSigner(options: CreateImageSignerOptions): ImageSigner;
|
|
87
|
+
|
|
88
|
+
export { type CreateImageSignerOptions, GENERATOR_ASSERTION_LABEL, type ImageMime, type ImageSigner, type ManifestSummary, type SignImageOptions, type SignImageResult, TRAINED_ALGORITHMIC_MEDIA, type ValidationStatusCodes, createImageSigner, detectImageMime, readManifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// src/mime.ts
|
|
2
|
+
var PNG_MAGIC = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
3
|
+
function detectImageMime(bytes, what) {
|
|
4
|
+
const head = Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.byteLength, 8));
|
|
5
|
+
if (head.length >= 8 && head.equals(PNG_MAGIC)) {
|
|
6
|
+
return "image/png";
|
|
7
|
+
}
|
|
8
|
+
if (head.length >= 3 && head[0] === 255 && head[1] === 216 && head[2] === 255) {
|
|
9
|
+
return "image/jpeg";
|
|
10
|
+
}
|
|
11
|
+
throw new TypeError(
|
|
12
|
+
`gsengai: ${what} is not a PNG or JPEG image (unrecognized magic bytes). Only PNG and JPEG are supported in the MVP.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/read.ts
|
|
17
|
+
import { readFile } from "fs/promises";
|
|
18
|
+
import { Reader } from "@contentauth/c2pa-node";
|
|
19
|
+
|
|
20
|
+
// src/settings.ts
|
|
21
|
+
var OFFLINE_NO_VERIFY_SETTINGS = {
|
|
22
|
+
verify: {
|
|
23
|
+
verify_after_reading: false,
|
|
24
|
+
verify_after_sign: false,
|
|
25
|
+
verify_trust: false,
|
|
26
|
+
ocsp_fetch: false,
|
|
27
|
+
remote_manifest_fetch: false
|
|
28
|
+
},
|
|
29
|
+
trust: { verify_trust_list: false }
|
|
30
|
+
};
|
|
31
|
+
var OFFLINE_VALIDATE_SETTINGS = {
|
|
32
|
+
verify: {
|
|
33
|
+
verify_after_reading: true,
|
|
34
|
+
verify_trust: true,
|
|
35
|
+
ocsp_fetch: false,
|
|
36
|
+
remote_manifest_fetch: false
|
|
37
|
+
},
|
|
38
|
+
trust: { verify_trust_list: true }
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/read.ts
|
|
42
|
+
async function readManifest(input) {
|
|
43
|
+
const bytes = typeof input === "string" ? await readFile(input) : Buffer.from(input);
|
|
44
|
+
const mimeType = detectImageMime(bytes, "input");
|
|
45
|
+
const reader = await Reader.fromAsset({ buffer: bytes, mimeType }, OFFLINE_VALIDATE_SETTINGS);
|
|
46
|
+
if (!reader) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const activeLabel = reader.activeLabel();
|
|
50
|
+
if (!activeLabel) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const store = reader.json();
|
|
54
|
+
const active = reader.getActive();
|
|
55
|
+
const results = store.validation_results?.activeManifest;
|
|
56
|
+
return {
|
|
57
|
+
activeLabel,
|
|
58
|
+
ingredientCount: active?.ingredients?.length ?? 0,
|
|
59
|
+
validationState: store.validation_state ?? null,
|
|
60
|
+
validationStatusCodes: {
|
|
61
|
+
success: (results?.success ?? []).map((s) => s.code),
|
|
62
|
+
informational: (results?.informational ?? []).map((s) => s.code),
|
|
63
|
+
failure: (results?.failure ?? []).map((s) => s.code)
|
|
64
|
+
},
|
|
65
|
+
manifestLabels: Object.keys(store.manifests ?? {})
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/signer.ts
|
|
70
|
+
import { readFileSync } from "fs";
|
|
71
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
72
|
+
import { basename } from "path";
|
|
73
|
+
import { fileURLToPath } from "url";
|
|
74
|
+
import { Builder, LocalSigner, Reader as Reader2 } from "@contentauth/c2pa-node";
|
|
75
|
+
import { safeAppend } from "@gsengai/core";
|
|
76
|
+
var VERSION = "0.1.0";
|
|
77
|
+
var GENERATOR_NAME = "gsengai-c2pa";
|
|
78
|
+
var GENERATOR_ASSERTION_LABEL = "org.gsengai.generator";
|
|
79
|
+
var TRAINED_ALGORITHMIC_MEDIA = "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia";
|
|
80
|
+
var DEV_CERT_PATH = fileURLToPath(new URL("../dev-certs/dev-cert-chain.pem", import.meta.url));
|
|
81
|
+
var DEV_KEY_PATH = fileURLToPath(new URL("../dev-certs/dev-private-key.pem", import.meta.url));
|
|
82
|
+
var devCertWarningShown = false;
|
|
83
|
+
function warnIfDevCerts(certPath, keyPath) {
|
|
84
|
+
if (certPath && keyPath || devCertWarningShown) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
devCertWarningShown = true;
|
|
88
|
+
console.warn(
|
|
89
|
+
"[gsengai] Using the bundled DEVELOPMENT certificates: signed manifests are UNTRUSTED by public validators and are for integration testing only. Provide certPath/keyPath with your own signing certificate for production \u2014 see docs/CERTIFICATES.md."
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function createImageSigner(options) {
|
|
93
|
+
const { store, systemId, failMode } = options;
|
|
94
|
+
if (typeof systemId !== "string" || systemId.length === 0) {
|
|
95
|
+
throw new TypeError("gsengai: systemId must be a non-empty string");
|
|
96
|
+
}
|
|
97
|
+
warnIfDevCerts(options.certPath, options.keyPath);
|
|
98
|
+
const cert = readFileSync(options.certPath ?? DEV_CERT_PATH);
|
|
99
|
+
const key = readFileSync(options.keyPath ?? DEV_KEY_PATH);
|
|
100
|
+
const signer = LocalSigner.newSigner(cert, key, "es256");
|
|
101
|
+
return {
|
|
102
|
+
async signImage(sign) {
|
|
103
|
+
if (typeof sign.model !== "string" || sign.model.length === 0) {
|
|
104
|
+
throw new TypeError("gsengai: model must be a non-empty string");
|
|
105
|
+
}
|
|
106
|
+
const inputBytes = typeof sign.input === "string" ? await readFile2(sign.input) : Buffer.from(sign.input);
|
|
107
|
+
const mimeType = detectImageMime(inputBytes, "signImage input");
|
|
108
|
+
const existing = await Reader2.fromAsset(
|
|
109
|
+
{ buffer: inputBytes, mimeType },
|
|
110
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
111
|
+
);
|
|
112
|
+
const title = sign.output !== void 0 ? basename(sign.output) : typeof sign.input === "string" ? basename(sign.input) : mimeType === "image/png" ? "image.png" : "image.jpg";
|
|
113
|
+
const builder = Builder.withJson(
|
|
114
|
+
{
|
|
115
|
+
// The backend allows exactly one claim_generator_info entry (ADR-0019);
|
|
116
|
+
// model info lives in the created action and the org.gsengai.generator assertion.
|
|
117
|
+
claim_generator_info: [{ name: GENERATOR_NAME, version: VERSION }],
|
|
118
|
+
title
|
|
119
|
+
},
|
|
120
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
121
|
+
);
|
|
122
|
+
const when = (/* @__PURE__ */ new Date()).toISOString();
|
|
123
|
+
if (existing) {
|
|
124
|
+
builder.setIntent("edit");
|
|
125
|
+
} else {
|
|
126
|
+
builder.setIntent({ create: TRAINED_ALGORITHMIC_MEDIA });
|
|
127
|
+
builder.addAction(
|
|
128
|
+
JSON.stringify({
|
|
129
|
+
action: "c2pa.created",
|
|
130
|
+
digitalSourceType: TRAINED_ALGORITHMIC_MEDIA,
|
|
131
|
+
softwareAgent: { name: sign.model },
|
|
132
|
+
when
|
|
133
|
+
})
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
builder.addAssertion(GENERATOR_ASSERTION_LABEL, {
|
|
137
|
+
generator: { name: GENERATOR_NAME, version: VERSION },
|
|
138
|
+
model: sign.model,
|
|
139
|
+
when
|
|
140
|
+
});
|
|
141
|
+
let signedBytes;
|
|
142
|
+
let output;
|
|
143
|
+
if (sign.output !== void 0) {
|
|
144
|
+
builder.sign(signer, { buffer: inputBytes, mimeType }, { path: sign.output });
|
|
145
|
+
signedBytes = await readFile2(sign.output);
|
|
146
|
+
output = sign.output;
|
|
147
|
+
} else {
|
|
148
|
+
const dest = { buffer: null };
|
|
149
|
+
builder.sign(signer, { buffer: inputBytes, mimeType }, dest);
|
|
150
|
+
if (!dest.buffer) {
|
|
151
|
+
throw new Error("gsengai: signing produced no output buffer");
|
|
152
|
+
}
|
|
153
|
+
signedBytes = dest.buffer;
|
|
154
|
+
output = signedBytes;
|
|
155
|
+
}
|
|
156
|
+
const readBack = await Reader2.fromAsset(
|
|
157
|
+
{ buffer: signedBytes, mimeType },
|
|
158
|
+
OFFLINE_NO_VERIFY_SETTINGS
|
|
159
|
+
);
|
|
160
|
+
const manifestLabel = readBack?.activeLabel();
|
|
161
|
+
if (!manifestLabel) {
|
|
162
|
+
throw new Error("gsengai: signed output has no readable active manifest");
|
|
163
|
+
}
|
|
164
|
+
const record = safeAppend(
|
|
165
|
+
store,
|
|
166
|
+
{
|
|
167
|
+
modality: "image",
|
|
168
|
+
model: sign.model,
|
|
169
|
+
systemId,
|
|
170
|
+
outputBytes: signedBytes,
|
|
171
|
+
manifestRef: manifestLabel,
|
|
172
|
+
markingMethods: ["c2pa"],
|
|
173
|
+
promptHash: sign.promptHash ?? null,
|
|
174
|
+
disclosureContext: sign.disclosureContext ?? null
|
|
175
|
+
},
|
|
176
|
+
failMode
|
|
177
|
+
);
|
|
178
|
+
return { output, record, manifestLabel };
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
GENERATOR_ASSERTION_LABEL,
|
|
184
|
+
TRAINED_ALGORITHMIC_MEDIA,
|
|
185
|
+
createImageSigner,
|
|
186
|
+
detectImageMime,
|
|
187
|
+
readManifest
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mime.ts","../src/read.ts","../src/settings.ts","../src/signer.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nexport type ImageMime = \"image/png\" | \"image/jpeg\";\n\nconst PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n\n/**\n * Detect the image format from magic bytes. Only PNG and JPEG are supported in\n * the MVP (PRD B1); anything else — including corrupt or truncated data — throws.\n */\nexport function detectImageMime(bytes: Uint8Array, what: string): ImageMime {\n const head = Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.byteLength, 8));\n if (head.length >= 8 && head.equals(PNG_MAGIC)) {\n return \"image/png\";\n }\n if (head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff) {\n return \"image/jpeg\";\n }\n throw new TypeError(\n `gsengai: ${what} is not a PNG or JPEG image (unrecognized magic bytes). ` +\n \"Only PNG and JPEG are supported in the MVP.\",\n );\n}\n","// SPDX-License-Identifier: Apache-2.0\nimport { readFile } from \"node:fs/promises\";\nimport { Reader } from \"@contentauth/c2pa-node\";\nimport { detectImageMime } from \"./mime\";\nimport { OFFLINE_VALIDATE_SETTINGS } from \"./settings\";\n\n/** Validation status codes as reported by the C2PA validator, grouped by outcome. */\nexport interface ValidationStatusCodes {\n success: string[];\n informational: string[];\n failure: string[];\n}\n\n/** Summary of the C2PA manifest store embedded in an asset. */\nexport interface ManifestSummary {\n /** Label of the active (most recent) manifest. */\n activeLabel: string;\n /** Number of ingredients on the active manifest (parents + components). */\n ingredientCount: number;\n /**\n * Overall validation state as reported by the validator. Dev-cert-signed\n * assets report a valid signature but an untrusted credential — see\n * docs/CERTIFICATES.md; this library never claims trust it does not have.\n */\n validationState: string | null;\n /** Exact validator status codes for the active manifest. */\n validationStatusCodes: ValidationStatusCodes;\n /** All manifest labels in the store — the provenance chain, active first is not guaranteed. */\n manifestLabels: string[];\n}\n\ninterface ValidationResultsShape {\n activeManifest?: {\n success?: { code: string }[];\n informational?: { code: string }[];\n failure?: { code: string }[];\n };\n}\n\n/**\n * Read and locally validate the C2PA manifest store of a PNG/JPEG asset.\n * Returns null when the asset carries no manifest. Never fetches anything\n * remote (no OCSP, no remote manifests); trust is evaluated against local\n * configuration only.\n */\nexport async function readManifest(input: string | Uint8Array): Promise<ManifestSummary | null> {\n const bytes = typeof input === \"string\" ? await readFile(input) : Buffer.from(input);\n const mimeType = detectImageMime(bytes, \"input\");\n const reader = await Reader.fromAsset({ buffer: bytes, mimeType }, OFFLINE_VALIDATE_SETTINGS);\n if (!reader) {\n return null;\n }\n const activeLabel = reader.activeLabel();\n if (!activeLabel) {\n return null;\n }\n const store = reader.json() as {\n manifests?: Record<string, unknown>;\n validation_state?: string;\n validation_results?: ValidationResultsShape;\n };\n const active = reader.getActive();\n const results = store.validation_results?.activeManifest;\n return {\n activeLabel,\n ingredientCount: active?.ingredients?.length ?? 0,\n validationState: store.validation_state ?? null,\n validationStatusCodes: {\n success: (results?.success ?? []).map((s) => s.code),\n informational: (results?.informational ?? []).map((s) => s.code),\n failure: (results?.failure ?? []).map((s) => s.code),\n },\n manifestLabels: Object.keys(store.manifests ?? {}),\n };\n}\n","// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Offline discipline: every Reader/Builder gets explicit\n * settings so no OCSP or remote-manifest fetch can occur at sign or read time,\n * and no TSA URL is ever configured. Trust evaluation stays local: it runs\n * against configured anchors only (none by default), which is what makes the\n * dev-cert `signingCredential.untrusted` status honest and reproducible.\n */\n\n/** Settings for signing and for existence-check reads: no verification, no fetches. */\nexport const OFFLINE_NO_VERIFY_SETTINGS = {\n verify: {\n verify_after_reading: false,\n verify_after_sign: false,\n verify_trust: false,\n ocsp_fetch: false,\n remote_manifest_fetch: false,\n },\n trust: { verify_trust_list: false },\n} as const;\n\n/** Settings for `readManifest`: full local validation including trust, still no fetches. */\nexport const OFFLINE_VALIDATE_SETTINGS = {\n verify: {\n verify_after_reading: true,\n verify_trust: true,\n ocsp_fetch: false,\n remote_manifest_fetch: false,\n },\n trust: { verify_trust_list: true },\n} as const;\n","// SPDX-License-Identifier: Apache-2.0\nimport { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Builder, LocalSigner, Reader } from \"@contentauth/c2pa-node\";\nimport { type EvidenceRecord, type EvidenceStore, type FailMode, safeAppend } from \"@gsengai/core\";\nimport { detectImageMime } from \"./mime\";\nimport { OFFLINE_NO_VERIFY_SETTINGS } from \"./settings\";\n\nconst VERSION = \"0.1.0\";\nconst GENERATOR_NAME = \"gsengai-c2pa\";\n/** Label of the custom assertion carrying generator/model info on every signing (ADR-0019). */\nexport const GENERATOR_ASSERTION_LABEL = \"org.gsengai.generator\";\nexport const TRAINED_ALGORITHMIC_MEDIA =\n \"http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia\";\n\nconst DEV_CERT_PATH = fileURLToPath(new URL(\"../dev-certs/dev-cert-chain.pem\", import.meta.url));\nconst DEV_KEY_PATH = fileURLToPath(new URL(\"../dev-certs/dev-private-key.pem\", import.meta.url));\n\nlet devCertWarningShown = false;\n\nexport interface CreateImageSignerOptions {\n store: EvidenceStore;\n /** Integrator's system/feature identifier — persisted as `system_id` (PRD §4). */\n systemId: string;\n /** PEM certificate chain (leaf first). Defaults to the bundled DEV certificates. */\n certPath?: string;\n /** PKCS#8 PEM private key for the leaf certificate. Defaults to the bundled DEV key. */\n keyPath?: string;\n /**\n * Applies to evidence-store failures only (ADR-0017): `open` (default) warns,\n * counts the lost record, and still returns the signed asset; `strict` throws.\n * Signing failures always throw regardless of this setting.\n */\n failMode?: FailMode;\n}\n\nexport interface SignImageOptions {\n /** Source image: file path or bytes. PNG and JPEG only (MVP). */\n input: string | Uint8Array;\n /** Destination file path. Omit to receive the signed asset as a Buffer. */\n output?: string;\n /** Model identifier that generated the image — recorded in the manifest and the evidence record. */\n model: string;\n /** Optional prompt hash (compute with `hashPrompt` from @gsengai/core). */\n promptHash?: string | null;\n disclosureContext?: string | null;\n}\n\nexport interface SignImageResult {\n /** The signed asset: the `output` path when one was given, otherwise a Buffer. */\n output: string | Buffer;\n /** The appended evidence record; null only in fail-open mode when the store failed (the loss is counted). */\n record: EvidenceRecord | null;\n /** Active manifest label of the signed output, as reported by the C2PA reader (ADR-0018). */\n manifestLabel: string;\n}\n\nexport interface ImageSigner {\n /**\n * Sign a PNG/JPEG with a C2PA manifest declaring AI generation and append one\n * evidence record (PRD B6). If the input already carries a manifest it is\n * preserved as the parent ingredient — never overwritten (PRD B3, ADR-0015).\n */\n signImage(options: SignImageOptions): Promise<SignImageResult>;\n}\n\nfunction warnIfDevCerts(certPath: string | undefined, keyPath: string | undefined): void {\n if ((certPath && keyPath) || devCertWarningShown) {\n return;\n }\n devCertWarningShown = true;\n console.warn(\n \"[gsengai] Using the bundled DEVELOPMENT certificates: signed manifests are UNTRUSTED \" +\n \"by public validators and are for integration testing only. Provide certPath/keyPath \" +\n \"with your own signing certificate for production — see docs/CERTIFICATES.md.\",\n );\n}\n\nexport function createImageSigner(options: CreateImageSignerOptions): ImageSigner {\n const { store, systemId, failMode } = options;\n if (typeof systemId !== \"string\" || systemId.length === 0) {\n throw new TypeError(\"gsengai: systemId must be a non-empty string\");\n }\n warnIfDevCerts(options.certPath, options.keyPath);\n // Read eagerly so a bad path fails at construction, not at first sign.\n const cert = readFileSync(options.certPath ?? DEV_CERT_PATH);\n const key = readFileSync(options.keyPath ?? DEV_KEY_PATH);\n const signer = LocalSigner.newSigner(cert, key, \"es256\"); // no TSA URL — offline by design\n\n return {\n async signImage(sign: SignImageOptions): Promise<SignImageResult> {\n if (typeof sign.model !== \"string\" || sign.model.length === 0) {\n throw new TypeError(\"gsengai: model must be a non-empty string\");\n }\n const inputBytes =\n typeof sign.input === \"string\" ? await readFile(sign.input) : Buffer.from(sign.input);\n const mimeType = detectImageMime(inputBytes, \"signImage input\");\n\n // ADR-0015 intent mapping: existing manifest → edit + parent ingredient\n // (chained, never overwritten); none → create + trainedAlgorithmicMedia.\n const existing = await Reader.fromAsset(\n { buffer: inputBytes, mimeType },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const title =\n sign.output !== undefined\n ? basename(sign.output)\n : typeof sign.input === \"string\"\n ? basename(sign.input)\n : mimeType === \"image/png\"\n ? \"image.png\"\n : \"image.jpg\";\n const builder = Builder.withJson(\n {\n // The backend allows exactly one claim_generator_info entry (ADR-0019);\n // model info lives in the created action and the org.gsengai.generator assertion.\n claim_generator_info: [{ name: GENERATOR_NAME, version: VERSION }],\n title,\n },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const when = new Date().toISOString();\n if (existing) {\n // Edit path: the builder generates the parent ingredient and its\n // c2pa.opened action itself — adding our own opened action would drop\n // the ingredient reference and fail validation (ADR-0019).\n builder.setIntent(\"edit\");\n } else {\n builder.setIntent({ create: TRAINED_ALGORITHMIC_MEDIA });\n builder.addAction(\n JSON.stringify({\n action: \"c2pa.created\",\n digitalSourceType: TRAINED_ALGORITHMIC_MEDIA,\n softwareAgent: { name: sign.model },\n when,\n }),\n );\n }\n // Generator/model info + timestamp on both paths (PRD B2, ADR-0019).\n builder.addAssertion(GENERATOR_ASSERTION_LABEL, {\n generator: { name: GENERATOR_NAME, version: VERSION },\n model: sign.model,\n when,\n });\n\n // Signing failures always throw (ADR-0017) — nothing to fail open with.\n let signedBytes: Buffer;\n let output: string | Buffer;\n if (sign.output !== undefined) {\n builder.sign(signer, { buffer: inputBytes, mimeType }, { path: sign.output });\n signedBytes = await readFile(sign.output);\n output = sign.output;\n } else {\n const dest: { buffer: Buffer | null } = { buffer: null };\n builder.sign(signer, { buffer: inputBytes, mimeType }, dest);\n if (!dest.buffer) {\n throw new Error(\"gsengai: signing produced no output buffer\");\n }\n signedBytes = dest.buffer;\n output = signedBytes;\n }\n\n const readBack = await Reader.fromAsset(\n { buffer: signedBytes, mimeType },\n OFFLINE_NO_VERIFY_SETTINGS,\n );\n const manifestLabel = readBack?.activeLabel();\n if (!manifestLabel) {\n throw new Error(\"gsengai: signed output has no readable active manifest\");\n }\n\n // Evidence-store failures follow failMode (ADR-0017); output_hash is the\n // sha256 of the signed output bytes, hashed centrally in core (ADR-0018).\n const record = safeAppend(\n store,\n {\n modality: \"image\",\n model: sign.model,\n systemId,\n outputBytes: signedBytes,\n manifestRef: manifestLabel,\n markingMethods: [\"c2pa\"],\n promptHash: sign.promptHash ?? null,\n disclosureContext: sign.disclosureContext ?? null,\n },\n failMode,\n );\n\n return { output, record, manifestLabel };\n },\n };\n}\n"],"mappings":";AAIA,IAAM,YAAY,OAAO,KAAK,CAAC,KAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IAAM,EAAI,CAAC;AAMvE,SAAS,gBAAgB,OAAmB,MAAyB;AAC1E,QAAM,OAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,KAAK,IAAI,MAAM,YAAY,CAAC,CAAC;AACtF,MAAI,KAAK,UAAU,KAAK,KAAK,OAAO,SAAS,GAAG;AAC9C,WAAO;AAAA,EACT;AACA,MAAI,KAAK,UAAU,KAAK,KAAK,CAAC,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Y,SAAS,GAAG,IAAI;AAC3D,YAAI,CAAC,KAAK,QAAQ;AAChB,gBAAM,IAAI,MAAM,4CAA4C;AAAA,QAC9D;AACA,sBAAc,KAAK;AACnB,iBAAS;AAAA,MACX;AAEA,YAAM,WAAW,MAAMC,QAAO;AAAA,QAC5B,EAAE,QAAQ,aAAa,SAAS;AAAA,QAChC;AAAA,MACF;AACA,YAAM,gBAAgB,UAAU,YAAY;AAC5C,UAAI,CAAC,eAAe;AAClB,cAAM,IAAI,MAAM,wDAAwD;AAAA,MAC1E;AAIA,YAAM,SAAS;AAAA,QACb;AAAA,QACA;AAAA,UACE,UAAU;AAAA,UACV,OAAO,KAAK;AAAA,UACZ;AAAA,UACA,aAAa;AAAA,UACb,aAAa;AAAA,UACb,gBAAgB,CAAC,MAAM;AAAA,UACvB,YAAY,KAAK,cAAc;AAAA,UAC/B,mBAAmB,KAAK,qBAAqB;AAAA,QAC/C;AAAA,QACA;AAAA,MACF;AAEA,aAAO,EAAE,QAAQ,QAAQ,cAAc;AAAA,IACzC;AAAA,EACF;AACF;","names":["readFile","Reader","readFile","Reader"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gsengai/c2pa",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "C2PA image signing for AI-generated media: signed manifests with AI-generation assertions, ingredient preservation, evidence record per signing. Supports compliance with EU AI Act Article 50 and California SB 942. Not legal advice.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"default": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"dev-certs"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@contentauth/c2pa-node": "0.6.0",
|
|
32
|
+
"@gsengai/core": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@contentauth/c2pa-types": "^0.7.0",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.6.0"
|
|
38
|
+
},
|
|
39
|
+
"author": "Dominik Ertl",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"eu-ai-act",
|
|
42
|
+
"ai-act",
|
|
43
|
+
"article-50",
|
|
44
|
+
"sb-942",
|
|
45
|
+
"ai-transparency",
|
|
46
|
+
"ai-disclosure",
|
|
47
|
+
"ai-compliance",
|
|
48
|
+
"content-provenance",
|
|
49
|
+
"c2pa",
|
|
50
|
+
"content-credentials",
|
|
51
|
+
"provenance",
|
|
52
|
+
"image-signing"
|
|
53
|
+
],
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/gsengai/gsengai.git",
|
|
57
|
+
"directory": "packages/c2pa"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/gsengai/gsengai/tree/main/packages/c2pa#readme",
|
|
60
|
+
"bugs": "https://github.com/gsengai/gsengai/issues",
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup"
|
|
66
|
+
}
|
|
67
|
+
}
|