@zanii/provenance 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 +159 -0
- package/README.md +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
- package/src/index.ts +125 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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 Derivative
|
|
95
|
+
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; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
137
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
138
|
+
or other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
142
|
+
defend, and hold each Contributor harmless for any liability
|
|
143
|
+
incurred by, or claims asserted against, such Contributor.
|
|
144
|
+
|
|
145
|
+
END OF TERMS AND CONDITIONS
|
|
146
|
+
|
|
147
|
+
Copyright 2026 Zanii
|
|
148
|
+
|
|
149
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
150
|
+
you may not use this file except in compliance with the License.
|
|
151
|
+
You may obtain a copy of the License at
|
|
152
|
+
|
|
153
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
154
|
+
|
|
155
|
+
Unless required by applicable law or agreed to in writing, software
|
|
156
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
157
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
158
|
+
See the License for the specific language governing permissions and
|
|
159
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @zanii/provenance
|
|
2
|
+
|
|
3
|
+
**AI-content provenance.** The infrastructure answer to deepfakes is not detection (an
|
|
4
|
+
arms race) but positive attribution: a **content credential** — the artifact's hash signed
|
|
5
|
+
by the creating agent's `did:key`, anchorable on the ledger (timestamped *before* it
|
|
6
|
+
mattered), and resolvable to the agent's public, **verified** track record. "Made by a
|
|
7
|
+
known, accountable agent" vs "appeared from nowhere."
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @zanii/provenance @zanii/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { buildContentCredential, verifyContentCredential, credentialReceipt, resolveCreator } from '@zanii/provenance';
|
|
15
|
+
|
|
16
|
+
// creator side — sign the artifact, anchor the credential:
|
|
17
|
+
const cred = buildContentCredential({ artifact: imageBytes, agentDid: agent.did, createdAt: ts,
|
|
18
|
+
meta: { model: 'img-gen-1' } }, agent.privateKey);
|
|
19
|
+
const r = credentialReceipt(cred);
|
|
20
|
+
await zanii.record({ target: r.target, payload: r.payload }); // content.created — anti-backdating
|
|
21
|
+
|
|
22
|
+
// verifier side — offline, zero trust:
|
|
23
|
+
verifyContentCredential(cred, imageBytes).ok; // signed by that DID, hash matches these bytes
|
|
24
|
+
const trust = await resolveCreator(cred); // the creator's verified ledger history
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Ship the credential as a sidecar/EXIF/XMP field — it's plain JSON; embedding is the
|
|
28
|
+
caller's concern.
|
|
29
|
+
|
|
30
|
+
## Honest limits (read these)
|
|
31
|
+
- Proves **who signed**, never who *authored* — a key signs whatever its holder feeds it.
|
|
32
|
+
Accountability comes from the DID's delegation chain + public history, not the signature.
|
|
33
|
+
- **Absence proves nothing** — unsigned content is not thereby fake. Opt-in infrastructure;
|
|
34
|
+
value grows with adoption (the HTTPS curve).
|
|
35
|
+
- The hash breaks on **re-encoding/crop** — perceptual hashing is out of scope for v1; link
|
|
36
|
+
derivatives explicitly via `meta.derivative_of`.
|
|
37
|
+
- Full **C2PA manifests are deliberately not v1** — this is the thin Zanii credential;
|
|
38
|
+
export adapters can come later.
|
|
39
|
+
|
|
40
|
+
## Changelog
|
|
41
|
+
- **0.1.0** — initial release: `buildContentCredential`, `verifyContentCredential`, `credentialReceipt`, `resolveCreator`.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type AgentTrust, type FetchLike } from '@zanii/a2a-directory';
|
|
2
|
+
export interface ContentCredential {
|
|
3
|
+
v: 1;
|
|
4
|
+
type: 'content_credential';
|
|
5
|
+
/** `sha256:<hex>` of the exact artifact bytes. */
|
|
6
|
+
artifact_hash: string;
|
|
7
|
+
/** The creating agent's `did:key`. */
|
|
8
|
+
agent: string;
|
|
9
|
+
/** Optional ledger receipt hash of the creating action (links credential → proof-of-action). */
|
|
10
|
+
receipt?: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
/** Free-form, signed metadata (e.g. `{ title, model, derivative_of }`). */
|
|
13
|
+
meta?: Record<string, unknown>;
|
|
14
|
+
sig: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CredentialInput {
|
|
17
|
+
/** The artifact bytes (or string) — hashed here. */
|
|
18
|
+
artifact?: Uint8Array | string;
|
|
19
|
+
/** Or a precomputed `sha256:<hex>` hash. */
|
|
20
|
+
artifactHash?: string;
|
|
21
|
+
agentDid: string;
|
|
22
|
+
receiptHash?: string;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
meta?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Sign a content credential with the creating agent's key. */
|
|
27
|
+
export declare function buildContentCredential(input: CredentialInput, agentPrivateKey: Uint8Array): ContentCredential;
|
|
28
|
+
export interface CredentialCheck {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
reasons: string[];
|
|
31
|
+
}
|
|
32
|
+
/** Verify a credential offline: signature by `agent`, and (when supplied) the artifact matches. */
|
|
33
|
+
export declare function verifyContentCredential(credential: ContentCredential | undefined, artifact?: Uint8Array | string): CredentialCheck;
|
|
34
|
+
/** Anchor the credential itself: a `content.created` receipt input (timestamped before it mattered). */
|
|
35
|
+
export declare function credentialReceipt(credential: ContentCredential): {
|
|
36
|
+
target: string;
|
|
37
|
+
payload: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
/** From a credential to the creator's **verified history** — "known, accountable agent". */
|
|
40
|
+
export declare function resolveCreator(credential: ContentCredential, opts?: {
|
|
41
|
+
server?: string;
|
|
42
|
+
fetchImpl?: FetchLike;
|
|
43
|
+
}): Promise<AgentTrust | null>;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGrF,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,oBAAoB,CAAC;IAC3B,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,sCAAs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UAAU,GAAG,IAAI,CAAC,CAE5B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/provenance — AI-content provenance: "made by a known, accountable agent."
|
|
3
|
+
*
|
|
4
|
+
* The infrastructure answer to deepfakes is not detection (an arms race) but positive
|
|
5
|
+
* attribution: a **content credential** — the artifact's hash signed by the creating
|
|
6
|
+
* agent's `did:key`, anchorable on the ledger (timestamped *before* it mattered), and
|
|
7
|
+
* resolvable to the agent's public, verified track record via `@zanii/a2a-directory`.
|
|
8
|
+
*
|
|
9
|
+
* Honest limits, stated up front: this proves **who signed**, never who *authored* — a
|
|
10
|
+
* key signs whatever its holder feeds it; accountability comes from the DID's delegation
|
|
11
|
+
* chain and history, not the signature alone. **Absence proves nothing** — unsigned
|
|
12
|
+
* content is not thereby fake; value grows with adoption (the HTTPS curve). The hash
|
|
13
|
+
* breaks on re-encoding/crop — perceptual hashing is out of scope for v1 (use
|
|
14
|
+
* `meta.derivative_of` to link derivatives). Full C2PA manifests are deliberately NOT
|
|
15
|
+
* v1; this is the thin Zanii credential (export adapters can come later).
|
|
16
|
+
*/
|
|
17
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
18
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
19
|
+
import { resolveAgent } from '@zanii/a2a-directory';
|
|
20
|
+
import { canonicalBytes, hashPayload, jcsHash, publicKeyFromDid } from '@zanii/core';
|
|
21
|
+
/** Sign a content credential with the creating agent's key. */
|
|
22
|
+
export function buildContentCredential(input, agentPrivateKey) {
|
|
23
|
+
if (Number.isNaN(Date.parse(input.createdAt)))
|
|
24
|
+
throw new Error('createdAt must be an ISO timestamp');
|
|
25
|
+
let artifactHash = input.artifactHash;
|
|
26
|
+
if (!artifactHash) {
|
|
27
|
+
if (input.artifact === undefined)
|
|
28
|
+
throw new Error('provide either artifact or artifactHash');
|
|
29
|
+
artifactHash = hashPayload(input.artifact);
|
|
30
|
+
}
|
|
31
|
+
if (!/^sha256:[0-9a-f]{64}$/.test(artifactHash))
|
|
32
|
+
throw new Error('artifactHash must be sha256:<hex>');
|
|
33
|
+
const unsigned = {
|
|
34
|
+
v: 1,
|
|
35
|
+
type: 'content_credential',
|
|
36
|
+
artifact_hash: artifactHash,
|
|
37
|
+
agent: input.agentDid,
|
|
38
|
+
...(input.receiptHash ? { receipt: input.receiptHash } : {}),
|
|
39
|
+
created_at: input.createdAt,
|
|
40
|
+
...(input.meta ? { meta: input.meta } : {}),
|
|
41
|
+
};
|
|
42
|
+
const sig = ed25519.sign(canonicalBytes(unsigned), agentPrivateKey);
|
|
43
|
+
return { ...unsigned, sig: `ed25519:${bytesToHex(sig)}` };
|
|
44
|
+
}
|
|
45
|
+
/** Verify a credential offline: signature by `agent`, and (when supplied) the artifact matches. */
|
|
46
|
+
export function verifyContentCredential(credential, artifact) {
|
|
47
|
+
const reasons = [];
|
|
48
|
+
const c = credential ?? {};
|
|
49
|
+
if (c.v !== 1 || c.type !== 'content_credential')
|
|
50
|
+
reasons.push('not a content credential (v1)');
|
|
51
|
+
if (typeof c.artifact_hash !== 'string' || !/^sha256:[0-9a-f]{64}$/.test(c.artifact_hash))
|
|
52
|
+
reasons.push('missing/invalid artifact_hash');
|
|
53
|
+
if (typeof c.created_at !== 'string' || Number.isNaN(Date.parse(c.created_at)))
|
|
54
|
+
reasons.push('missing/invalid created_at');
|
|
55
|
+
if (reasons.length === 0) {
|
|
56
|
+
const pub = publicKeyFromDid(c.agent);
|
|
57
|
+
const hex = typeof c.sig === 'string' && c.sig.startsWith('ed25519:') ? c.sig.slice('ed25519:'.length) : '';
|
|
58
|
+
if (!pub || !/^[0-9a-f]{128}$/.test(hex)) {
|
|
59
|
+
reasons.push('malformed agent key or signature');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const { sig: _omitted, ...unsigned } = c;
|
|
63
|
+
let ok = false;
|
|
64
|
+
try {
|
|
65
|
+
ok = ed25519.verify(hexToBytes(hex), canonicalBytes(unsigned), pub);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
ok = false;
|
|
69
|
+
}
|
|
70
|
+
if (!ok)
|
|
71
|
+
reasons.push('bad signature');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (reasons.length === 0 && artifact !== undefined && hashPayload(artifact) !== c.artifact_hash) {
|
|
75
|
+
reasons.push('artifact does not match artifact_hash');
|
|
76
|
+
}
|
|
77
|
+
return { ok: reasons.length === 0, reasons };
|
|
78
|
+
}
|
|
79
|
+
/** Anchor the credential itself: a `content.created` receipt input (timestamped before it mattered). */
|
|
80
|
+
export function credentialReceipt(credential) {
|
|
81
|
+
return {
|
|
82
|
+
target: 'content.created',
|
|
83
|
+
payload: {
|
|
84
|
+
_zr_kind: 'provenance',
|
|
85
|
+
v: 1,
|
|
86
|
+
artifact_hash: credential.artifact_hash,
|
|
87
|
+
credential_hash: jcsHash(credential),
|
|
88
|
+
agent: credential.agent,
|
|
89
|
+
created_at: credential.created_at,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** From a credential to the creator's **verified history** — "known, accountable agent". */
|
|
94
|
+
export async function resolveCreator(credential, opts = {}) {
|
|
95
|
+
return resolveAgent(credential.agent, opts);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAmC,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA4BrF,+DA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enance: sign an artifact's hash with the creating agent's did:key, anchor it on the ledger, and resolve the creator to their verified history — 'made by a known, accountable agent' vs 'appeared from nowhere'.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://ledger.zanii.agency",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.1.0",
|
|
30
|
+
"typescript": "^5.8.2",
|
|
31
|
+
"vitest": "^3.0.9"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@noble/curves": "^1.8.1",
|
|
35
|
+
"@noble/hashes": "^1.7.1",
|
|
36
|
+
"@zanii/core": "0.4.0",
|
|
37
|
+
"@zanii/a2a-directory": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.build.json",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/provenance — AI-content provenance: "made by a known, accountable agent."
|
|
3
|
+
*
|
|
4
|
+
* The infrastructure answer to deepfakes is not detection (an arms race) but positive
|
|
5
|
+
* attribution: a **content credential** — the artifact's hash signed by the creating
|
|
6
|
+
* agent's `did:key`, anchorable on the ledger (timestamped *before* it mattered), and
|
|
7
|
+
* resolvable to the agent's public, verified track record via `@zanii/a2a-directory`.
|
|
8
|
+
*
|
|
9
|
+
* Honest limits, stated up front: this proves **who signed**, never who *authored* — a
|
|
10
|
+
* key signs whatever its holder feeds it; accountability comes from the DID's delegation
|
|
11
|
+
* chain and history, not the signature alone. **Absence proves nothing** — unsigned
|
|
12
|
+
* content is not thereby fake; value grows with adoption (the HTTPS curve). The hash
|
|
13
|
+
* breaks on re-encoding/crop — perceptual hashing is out of scope for v1 (use
|
|
14
|
+
* `meta.derivative_of` to link derivatives). Full C2PA manifests are deliberately NOT
|
|
15
|
+
* v1; this is the thin Zanii credential (export adapters can come later).
|
|
16
|
+
*/
|
|
17
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
18
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
19
|
+
import { resolveAgent, type AgentTrust, type FetchLike } from '@zanii/a2a-directory';
|
|
20
|
+
import { canonicalBytes, hashPayload, jcsHash, publicKeyFromDid } from '@zanii/core';
|
|
21
|
+
|
|
22
|
+
export interface ContentCredential {
|
|
23
|
+
v: 1;
|
|
24
|
+
type: 'content_credential';
|
|
25
|
+
/** `sha256:<hex>` of the exact artifact bytes. */
|
|
26
|
+
artifact_hash: string;
|
|
27
|
+
/** The creating agent's `did:key`. */
|
|
28
|
+
agent: string;
|
|
29
|
+
/** Optional ledger receipt hash of the creating action (links credential → proof-of-action). */
|
|
30
|
+
receipt?: string;
|
|
31
|
+
created_at: string;
|
|
32
|
+
/** Free-form, signed metadata (e.g. `{ title, model, derivative_of }`). */
|
|
33
|
+
meta?: Record<string, unknown>;
|
|
34
|
+
sig: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CredentialInput {
|
|
38
|
+
/** The artifact bytes (or string) — hashed here. */
|
|
39
|
+
artifact?: Uint8Array | string;
|
|
40
|
+
/** Or a precomputed `sha256:<hex>` hash. */
|
|
41
|
+
artifactHash?: string;
|
|
42
|
+
agentDid: string;
|
|
43
|
+
receiptHash?: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
meta?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Sign a content credential with the creating agent's key. */
|
|
49
|
+
export function buildContentCredential(input: CredentialInput, agentPrivateKey: Uint8Array): ContentCredential {
|
|
50
|
+
if (Number.isNaN(Date.parse(input.createdAt))) throw new Error('createdAt must be an ISO timestamp');
|
|
51
|
+
let artifactHash = input.artifactHash;
|
|
52
|
+
if (!artifactHash) {
|
|
53
|
+
if (input.artifact === undefined) throw new Error('provide either artifact or artifactHash');
|
|
54
|
+
artifactHash = hashPayload(input.artifact);
|
|
55
|
+
}
|
|
56
|
+
if (!/^sha256:[0-9a-f]{64}$/.test(artifactHash)) throw new Error('artifactHash must be sha256:<hex>');
|
|
57
|
+
const unsigned = {
|
|
58
|
+
v: 1 as const,
|
|
59
|
+
type: 'content_credential' as const,
|
|
60
|
+
artifact_hash: artifactHash,
|
|
61
|
+
agent: input.agentDid,
|
|
62
|
+
...(input.receiptHash ? { receipt: input.receiptHash } : {}),
|
|
63
|
+
created_at: input.createdAt,
|
|
64
|
+
...(input.meta ? { meta: input.meta } : {}),
|
|
65
|
+
};
|
|
66
|
+
const sig = ed25519.sign(canonicalBytes(unsigned), agentPrivateKey);
|
|
67
|
+
return { ...unsigned, sig: `ed25519:${bytesToHex(sig)}` };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CredentialCheck {
|
|
71
|
+
ok: boolean;
|
|
72
|
+
reasons: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Verify a credential offline: signature by `agent`, and (when supplied) the artifact matches. */
|
|
76
|
+
export function verifyContentCredential(credential: ContentCredential | undefined, artifact?: Uint8Array | string): CredentialCheck {
|
|
77
|
+
const reasons: string[] = [];
|
|
78
|
+
const c = credential ?? ({} as ContentCredential);
|
|
79
|
+
if (c.v !== 1 || c.type !== 'content_credential') reasons.push('not a content credential (v1)');
|
|
80
|
+
if (typeof c.artifact_hash !== 'string' || !/^sha256:[0-9a-f]{64}$/.test(c.artifact_hash)) reasons.push('missing/invalid artifact_hash');
|
|
81
|
+
if (typeof c.created_at !== 'string' || Number.isNaN(Date.parse(c.created_at))) reasons.push('missing/invalid created_at');
|
|
82
|
+
if (reasons.length === 0) {
|
|
83
|
+
const pub = publicKeyFromDid(c.agent);
|
|
84
|
+
const hex = typeof c.sig === 'string' && c.sig.startsWith('ed25519:') ? c.sig.slice('ed25519:'.length) : '';
|
|
85
|
+
if (!pub || !/^[0-9a-f]{128}$/.test(hex)) {
|
|
86
|
+
reasons.push('malformed agent key or signature');
|
|
87
|
+
} else {
|
|
88
|
+
const { sig: _omitted, ...unsigned } = c;
|
|
89
|
+
let ok = false;
|
|
90
|
+
try {
|
|
91
|
+
ok = ed25519.verify(hexToBytes(hex), canonicalBytes(unsigned), pub);
|
|
92
|
+
} catch {
|
|
93
|
+
ok = false;
|
|
94
|
+
}
|
|
95
|
+
if (!ok) reasons.push('bad signature');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (reasons.length === 0 && artifact !== undefined && hashPayload(artifact) !== c.artifact_hash) {
|
|
99
|
+
reasons.push('artifact does not match artifact_hash');
|
|
100
|
+
}
|
|
101
|
+
return { ok: reasons.length === 0, reasons };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Anchor the credential itself: a `content.created` receipt input (timestamped before it mattered). */
|
|
105
|
+
export function credentialReceipt(credential: ContentCredential): { target: string; payload: Record<string, unknown> } {
|
|
106
|
+
return {
|
|
107
|
+
target: 'content.created',
|
|
108
|
+
payload: {
|
|
109
|
+
_zr_kind: 'provenance',
|
|
110
|
+
v: 1,
|
|
111
|
+
artifact_hash: credential.artifact_hash,
|
|
112
|
+
credential_hash: jcsHash(credential),
|
|
113
|
+
agent: credential.agent,
|
|
114
|
+
created_at: credential.created_at,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** From a credential to the creator's **verified history** — "known, accountable agent". */
|
|
120
|
+
export async function resolveCreator(
|
|
121
|
+
credential: ContentCredential,
|
|
122
|
+
opts: { server?: string; fetchImpl?: FetchLike } = {},
|
|
123
|
+
): Promise<AgentTrust | null> {
|
|
124
|
+
return resolveAgent(credential.agent, opts);
|
|
125
|
+
}
|