@totemsdk/proofgraph 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -21
- package/NOTICE +60 -0
- package/README.md +31 -10
- package/dist/canonical.js +11 -19
- package/dist/cjs/canonical.d.ts +22 -0
- package/dist/cjs/canonical.js +51 -0
- package/dist/cjs/durable-store.d.ts +50 -0
- package/dist/cjs/durable-store.js +178 -0
- package/dist/cjs/evidence.d.ts +89 -0
- package/dist/cjs/evidence.js +130 -0
- package/dist/cjs/graph.d.ts +103 -0
- package/dist/cjs/graph.js +298 -0
- package/dist/cjs/index.d.ts +26 -0
- package/dist/cjs/index.js +84 -0
- package/dist/cjs/io.d.ts +26 -0
- package/dist/cjs/io.js +173 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/query.d.ts +85 -0
- package/dist/cjs/query.js +189 -0
- package/dist/cjs/replicated-evidence.d.ts +42 -0
- package/dist/cjs/replicated-evidence.js +98 -0
- package/dist/cjs/types.d.ts +62 -0
- package/dist/cjs/types.js +7 -0
- package/dist/cjs/verify.d.ts +23 -0
- package/dist/cjs/verify.js +77 -0
- package/dist/durable-store.js +9 -12
- package/dist/evidence.js +14 -19
- package/dist/graph.d.ts +11 -0
- package/dist/graph.js +47 -34
- package/dist/index.d.ts +3 -2
- package/dist/index.js +8 -52
- package/dist/io.js +4 -8
- package/dist/query.d.ts +4 -0
- package/dist/query.js +30 -38
- package/dist/replicated-evidence.d.ts +42 -0
- package/dist/replicated-evidence.js +95 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -2
- package/dist/verify.js +3 -40
- package/package.json +25 -15
- package/rust/pkg/package.json +2 -2
- package/rust/pkg/proofgraph_wasm_bg.wasm +0 -0
- package/rust/pkg-node/package.json +2 -2
- package/rust/pkg-node/proofgraph_wasm_bg.wasm +0 -0
package/dist/evidence.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Durable evidence-chain owner for @totemsdk/proofgraph (RFC-007 G8 / §4.3).
|
|
4
3
|
*
|
|
@@ -12,21 +11,17 @@
|
|
|
12
11
|
* `not-found` (bytes absent); `unavailable` (backend unreachable, or the
|
|
13
12
|
* backend deleted a blob the local index still references) is also surfaced.
|
|
14
13
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.assertEvidenceBinding = assertEvidenceBinding;
|
|
18
|
-
exports.createProofGraphEvidenceStore = createProofGraphEvidenceStore;
|
|
19
|
-
const errors_1 = require("@totemsdk/storage/errors");
|
|
20
|
-
const core_1 = require("@totemsdk/core");
|
|
14
|
+
import { StorageError } from '@totemsdk/storage/errors';
|
|
15
|
+
import { sha3_256, toHex } from '@totemsdk/core';
|
|
21
16
|
const DEFAULT_NS = 'totem-proofgraph-evidence';
|
|
22
17
|
const INDEX_PREFIX = 'totem_proofgraph_evidence:v1:';
|
|
23
|
-
function normalizeEvidenceHash(hash) {
|
|
18
|
+
export function normalizeEvidenceHash(hash) {
|
|
24
19
|
return hash.replace(/^0x/i, '').toLowerCase();
|
|
25
20
|
}
|
|
26
21
|
/** Throws `StorageError('corrupt')` unless `contentHash === artifact.digest`. */
|
|
27
|
-
function assertEvidenceBinding(binding) {
|
|
22
|
+
export function assertEvidenceBinding(binding) {
|
|
28
23
|
if (normalizeEvidenceHash(binding.contentHash) !== normalizeEvidenceHash(binding.artifact.digest)) {
|
|
29
|
-
throw new
|
|
24
|
+
throw new StorageError(`evidence binding mismatch for node "${binding.nodeId}": contentHash ${binding.contentHash} !== artifact.digest ${binding.artifact.digest}`, 'corrupt', { key: binding.nodeId });
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
function evidenceNodeIds(graph) {
|
|
@@ -37,7 +32,7 @@ function nodeContentHash(graph, nodeId) {
|
|
|
37
32
|
const value = graph.nodes.find((node) => node.id === nodeId)?.data?.contentHash;
|
|
38
33
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
39
34
|
}
|
|
40
|
-
function createProofGraphEvidenceStore(artifacts, index, options = {}) {
|
|
35
|
+
export function createProofGraphEvidenceStore(artifacts, index, options = {}) {
|
|
41
36
|
if (!artifacts.capabilities.writable) {
|
|
42
37
|
throw new Error('createProofGraphEvidenceStore requires a writable artifact store');
|
|
43
38
|
}
|
|
@@ -53,15 +48,15 @@ function createProofGraphEvidenceStore(artifacts, index, options = {}) {
|
|
|
53
48
|
continue;
|
|
54
49
|
const contentHash = options.contentHashFor?.(nodeId) ?? nodeContentHash(graph, nodeId);
|
|
55
50
|
if (!contentHash && options.requireContentHash) {
|
|
56
|
-
throw new
|
|
51
|
+
throw new StorageError(`evidence commitment missing for node "${nodeId}"`, 'corrupt', { key: indexKey(nodeId) });
|
|
57
52
|
}
|
|
58
53
|
// Byte-identity invariant: the stored bytes must hash to the commitment.
|
|
59
|
-
const digest =
|
|
54
|
+
const digest = toHex(sha3_256(bytes));
|
|
60
55
|
if (contentHash && normalizeEvidenceHash(contentHash) !== digest) {
|
|
61
|
-
throw new
|
|
56
|
+
throw new StorageError(`evidence commitment mismatch for node "${nodeId}": sha3(bytes) ${digest} !== contentHash ${contentHash}`, 'corrupt', { key: indexKey(nodeId) });
|
|
62
57
|
}
|
|
63
58
|
const receipt = await artifacts.put(namespace, bytes).catch((err) => {
|
|
64
|
-
throw new
|
|
59
|
+
throw new StorageError(`evidence put failed for node "${nodeId}": ${err.message}`, 'write-failed', { key: indexKey(nodeId), cause: err });
|
|
65
60
|
});
|
|
66
61
|
if (contentHash) {
|
|
67
62
|
// The artifact must address exactly the committed hash.
|
|
@@ -79,9 +74,9 @@ function createProofGraphEvidenceStore(artifacts, index, options = {}) {
|
|
|
79
74
|
async restoreEvidence(graph) {
|
|
80
75
|
const results = [];
|
|
81
76
|
const fail = (err) => {
|
|
82
|
-
if (err instanceof
|
|
77
|
+
if (err instanceof StorageError)
|
|
83
78
|
throw err;
|
|
84
|
-
throw new
|
|
79
|
+
throw new StorageError(`evidence read failed: ${err.message}`, 'unavailable', { cause: err });
|
|
85
80
|
};
|
|
86
81
|
for (const nodeId of evidenceNodeIds(graph)) {
|
|
87
82
|
const entry = await index.get(indexKey(nodeId));
|
|
@@ -101,13 +96,13 @@ function createProofGraphEvidenceStore(artifacts, index, options = {}) {
|
|
|
101
96
|
break;
|
|
102
97
|
case 'corrupt':
|
|
103
98
|
if (strict) {
|
|
104
|
-
throw new
|
|
99
|
+
throw new StorageError(`evidence artifact corrupt for node "${nodeId}": ${read.message ?? 'digest mismatch'}`, 'corrupt', { key: indexKey(nodeId) });
|
|
105
100
|
}
|
|
106
101
|
results.push({ nodeId, status: 'corrupt', ref, message: read.message ?? 'digest mismatch' });
|
|
107
102
|
break;
|
|
108
103
|
case 'unavailable':
|
|
109
104
|
if (strict) {
|
|
110
|
-
throw new
|
|
105
|
+
throw new StorageError(`evidence artifact unavailable for node "${nodeId}": ${read.message ?? 'backend unavailable'}`, 'unavailable', { key: indexKey(nodeId) });
|
|
111
106
|
}
|
|
112
107
|
results.push({ nodeId, status: 'unavailable', ref, message: read.message ?? 'backend unavailable' });
|
|
113
108
|
break;
|
package/dist/graph.d.ts
CHANGED
|
@@ -80,6 +80,17 @@ export declare function addIdentityClaim(graph: ProofGraph, signedClaim: SignedI
|
|
|
80
80
|
* manifests_as manifest → address
|
|
81
81
|
*/
|
|
82
82
|
export declare function addManifest(graph: ProofGraph, signedManifest: SignedManifest): ProofGraph;
|
|
83
|
+
/**
|
|
84
|
+
* Add a signed manifest **revision** without collapsing other revisions.
|
|
85
|
+
*
|
|
86
|
+
* Creates:
|
|
87
|
+
* manifest (logical) refId = manifestId
|
|
88
|
+
* manifest (revision) refId = manifestEnvelopeId, data = { manifestId, manifestEnvelopeId, signedManifest }
|
|
89
|
+
* address resolved author/operator address
|
|
90
|
+
* manifests_as manifestId → address
|
|
91
|
+
* revision_of manifestEnvelopeId → manifestId
|
|
92
|
+
*/
|
|
93
|
+
export declare function addManifestRevision(graph: ProofGraph, signedManifest: SignedManifest): ProofGraph;
|
|
83
94
|
/**
|
|
84
95
|
* Add a receipt-like node (payment, subscription, claim receipt) to the graph.
|
|
85
96
|
* If receipt.proofId is set, adds a 'supports' edge from the receipt to that proof.
|
package/dist/graph.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Proof graph mutation functions — all pure, all returning NEW graphs.
|
|
4
3
|
*
|
|
@@ -6,24 +5,12 @@
|
|
|
6
5
|
* recomputed graphId. Nodes and edges are deduplicated by ID so adding the
|
|
7
6
|
* same proof twice is idempotent.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.buildEdge = buildEdge;
|
|
13
|
-
exports.addNode = addNode;
|
|
14
|
-
exports.addEdge = addEdge;
|
|
15
|
-
exports.addIdentityDocument = addIdentityDocument;
|
|
16
|
-
exports.addProof = addProof;
|
|
17
|
-
exports.addIdentityClaim = addIdentityClaim;
|
|
18
|
-
exports.addManifest = addManifest;
|
|
19
|
-
exports.addReceiptLike = addReceiptLike;
|
|
20
|
-
exports.addAnchor = addAnchor;
|
|
21
|
-
const manifest_1 = require("@totemsdk/manifest");
|
|
22
|
-
const canonical_js_1 = require("./canonical.js");
|
|
23
|
-
const evidence_js_1 = require("./evidence.js");
|
|
8
|
+
import { computeManifestId, computeManifestEnvelopeId } from '@totemsdk/manifest';
|
|
9
|
+
import { computeNodeId, computeEdgeId, computeProofGraphId } from './canonical.js';
|
|
10
|
+
import { normalizeEvidenceHash } from './evidence.js';
|
|
24
11
|
function makeNode(type, refId, data) {
|
|
25
12
|
return {
|
|
26
|
-
id:
|
|
13
|
+
id: computeNodeId(type, refId),
|
|
27
14
|
type,
|
|
28
15
|
refId,
|
|
29
16
|
...(data !== undefined ? { data } : {}),
|
|
@@ -32,7 +19,7 @@ function makeNode(type, refId, data) {
|
|
|
32
19
|
}
|
|
33
20
|
function makeEdge(type, from, to, proofId, data) {
|
|
34
21
|
return {
|
|
35
|
-
id:
|
|
22
|
+
id: computeEdgeId(type, from, to, proofId, data),
|
|
36
23
|
type,
|
|
37
24
|
from,
|
|
38
25
|
to,
|
|
@@ -65,17 +52,17 @@ function rebuild(graph, newNodes, newEdges) {
|
|
|
65
52
|
...graph,
|
|
66
53
|
nodes,
|
|
67
54
|
edges,
|
|
68
|
-
graphId:
|
|
55
|
+
graphId: computeProofGraphId(nodes, edges),
|
|
69
56
|
};
|
|
70
57
|
}
|
|
71
58
|
/**
|
|
72
59
|
* Create an empty ProofGraph.
|
|
73
60
|
*/
|
|
74
|
-
function createProofGraph(metadata) {
|
|
61
|
+
export function createProofGraph(metadata) {
|
|
75
62
|
const nodes = [];
|
|
76
63
|
const edges = [];
|
|
77
64
|
return {
|
|
78
|
-
graphId:
|
|
65
|
+
graphId: computeProofGraphId(nodes, edges),
|
|
79
66
|
nodes,
|
|
80
67
|
edges,
|
|
81
68
|
createdAt: Date.now(),
|
|
@@ -85,39 +72,39 @@ function createProofGraph(metadata) {
|
|
|
85
72
|
/**
|
|
86
73
|
* Attach or replace mutable metadata. Does NOT affect graphId.
|
|
87
74
|
*/
|
|
88
|
-
function setGraphMetadata(graph, metadata) {
|
|
75
|
+
export function setGraphMetadata(graph, metadata) {
|
|
89
76
|
return { ...graph, metadata };
|
|
90
77
|
}
|
|
91
78
|
/**
|
|
92
79
|
* Build a ProofGraphEdge with a deterministic ID from its fields.
|
|
93
80
|
* Convenience helper so callers don't need to import computeEdgeId.
|
|
94
81
|
*/
|
|
95
|
-
function buildEdge(type, from, to, proofId, data) {
|
|
82
|
+
export function buildEdge(type, from, to, proofId, data) {
|
|
96
83
|
return makeEdge(type, from, to, proofId, data);
|
|
97
84
|
}
|
|
98
85
|
/**
|
|
99
86
|
* Add a node directly (type + refId pair). Idempotent — skipped if the node already exists.
|
|
100
87
|
*/
|
|
101
|
-
function addNode(graph, type, refId, data) {
|
|
88
|
+
export function addNode(graph, type, refId, data) {
|
|
102
89
|
return rebuild(graph, [makeNode(type, refId, data)], []);
|
|
103
90
|
}
|
|
104
91
|
/**
|
|
105
92
|
* Append a ProofGraphEdge and recompute graphId. Idempotent by edge ID.
|
|
106
93
|
* Spec API: addEdge(graph, edge). Use buildEdge() to construct the edge object.
|
|
107
94
|
*/
|
|
108
|
-
function addEdge(graph, edge) {
|
|
95
|
+
export function addEdge(graph, edge) {
|
|
109
96
|
const edges = mergeEdges(graph.edges, [edge]);
|
|
110
97
|
return {
|
|
111
98
|
...graph,
|
|
112
99
|
edges,
|
|
113
|
-
graphId:
|
|
100
|
+
graphId: computeProofGraphId(graph.nodes, edges),
|
|
114
101
|
};
|
|
115
102
|
}
|
|
116
103
|
/**
|
|
117
104
|
* Index a TotemIdentityDocument into the graph.
|
|
118
105
|
* Creates an 'identity' node with refId = doc.id.
|
|
119
106
|
*/
|
|
120
|
-
function addIdentityDocument(graph, doc) {
|
|
107
|
+
export function addIdentityDocument(graph, doc) {
|
|
121
108
|
return rebuild(graph, [makeNode('identity', doc.id, { ...doc })], []);
|
|
122
109
|
}
|
|
123
110
|
/**
|
|
@@ -137,7 +124,7 @@ function addIdentityDocument(graph, doc) {
|
|
|
137
124
|
* references proof → evidence (one per evidence ref, in array order)
|
|
138
125
|
* anchored_to proof → anchor (if present)
|
|
139
126
|
*/
|
|
140
|
-
function addProof(graph, signedProof) {
|
|
127
|
+
export function addProof(graph, signedProof) {
|
|
141
128
|
const proofNode = makeNode('proof', signedProof.proofId, {
|
|
142
129
|
...signedProof,
|
|
143
130
|
});
|
|
@@ -153,7 +140,7 @@ function addProof(graph, signedProof) {
|
|
|
153
140
|
for (const ev of signedProof.evidence) {
|
|
154
141
|
// RFC-007 Amendment A (A3): carry the claim commitment on the evidence
|
|
155
142
|
// node so the evidence store can enforce claim→contentHash→artifact.
|
|
156
|
-
newNodes.push(makeNode('evidence', ev.id, ev.hash ? { contentHash:
|
|
143
|
+
newNodes.push(makeNode('evidence', ev.id, ev.hash ? { contentHash: normalizeEvidenceHash(ev.hash) } : undefined));
|
|
157
144
|
newEdges.push(makeEdge('references', signedProof.proofId, ev.id, signedProof.proofId));
|
|
158
145
|
}
|
|
159
146
|
}
|
|
@@ -177,7 +164,7 @@ function addProof(graph, signedProof) {
|
|
|
177
164
|
* revokes → revokes edge (claim-node → subject identity)
|
|
178
165
|
* rotates_to → controls edge (claim-node → new address)
|
|
179
166
|
*/
|
|
180
|
-
function addIdentityClaim(graph, signedClaim) {
|
|
167
|
+
export function addIdentityClaim(graph, signedClaim) {
|
|
181
168
|
const { claim } = signedClaim;
|
|
182
169
|
const claimNode = makeNode('identity-claim', claim.id, {
|
|
183
170
|
...signedClaim,
|
|
@@ -231,8 +218,8 @@ function resolveManifestAddress(signedManifest) {
|
|
|
231
218
|
* Edge created:
|
|
232
219
|
* manifests_as manifest → address
|
|
233
220
|
*/
|
|
234
|
-
function addManifest(graph, signedManifest) {
|
|
235
|
-
const manifestId =
|
|
221
|
+
export function addManifest(graph, signedManifest) {
|
|
222
|
+
const manifestId = computeManifestId(signedManifest.manifest);
|
|
236
223
|
const address = resolveManifestAddress(signedManifest);
|
|
237
224
|
const manifestNode = makeNode('manifest', manifestId, {
|
|
238
225
|
...signedManifest,
|
|
@@ -242,11 +229,37 @@ function addManifest(graph, signedManifest) {
|
|
|
242
229
|
makeEdge('manifests_as', manifestId, address),
|
|
243
230
|
]);
|
|
244
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Add a signed manifest **revision** without collapsing other revisions.
|
|
234
|
+
*
|
|
235
|
+
* Creates:
|
|
236
|
+
* manifest (logical) refId = manifestId
|
|
237
|
+
* manifest (revision) refId = manifestEnvelopeId, data = { manifestId, manifestEnvelopeId, signedManifest }
|
|
238
|
+
* address resolved author/operator address
|
|
239
|
+
* manifests_as manifestId → address
|
|
240
|
+
* revision_of manifestEnvelopeId → manifestId
|
|
241
|
+
*/
|
|
242
|
+
export function addManifestRevision(graph, signedManifest) {
|
|
243
|
+
const manifestId = computeManifestId(signedManifest.manifest);
|
|
244
|
+
const manifestEnvelopeId = computeManifestEnvelopeId(signedManifest);
|
|
245
|
+
const address = resolveManifestAddress(signedManifest);
|
|
246
|
+
const logicalNode = makeNode('manifest', manifestId, { manifestId });
|
|
247
|
+
const revisionNode = makeNode('manifest', manifestEnvelopeId, {
|
|
248
|
+
manifestId,
|
|
249
|
+
manifestEnvelopeId,
|
|
250
|
+
signedManifest,
|
|
251
|
+
});
|
|
252
|
+
const addressNode = makeNode('address', address);
|
|
253
|
+
return rebuild(graph, [logicalNode, revisionNode, addressNode], [
|
|
254
|
+
makeEdge('manifests_as', manifestId, address),
|
|
255
|
+
makeEdge('revision_of', manifestEnvelopeId, manifestId),
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
245
258
|
/**
|
|
246
259
|
* Add a receipt-like node (payment, subscription, claim receipt) to the graph.
|
|
247
260
|
* If receipt.proofId is set, adds a 'supports' edge from the receipt to that proof.
|
|
248
261
|
*/
|
|
249
|
-
function addReceiptLike(graph, receipt) {
|
|
262
|
+
export function addReceiptLike(graph, receipt) {
|
|
250
263
|
const { id, data, proofId } = receipt;
|
|
251
264
|
const receiptNode = makeNode('receipt', id, data);
|
|
252
265
|
const newEdges = [];
|
|
@@ -259,7 +272,7 @@ function addReceiptLike(graph, receipt) {
|
|
|
259
272
|
* Add a standalone anchor node. If anchor.proofId is set, adds an 'anchored_to'
|
|
260
273
|
* edge from the proof to this anchor.
|
|
261
274
|
*/
|
|
262
|
-
function addAnchor(graph, anchor) {
|
|
275
|
+
export function addAnchor(graph, anchor) {
|
|
263
276
|
const { hash, proofId, ...rest } = anchor;
|
|
264
277
|
const nodeData = { ...rest };
|
|
265
278
|
const anchorNode = makeNode('anchor', hash, Object.keys(nodeData).length > 0 ? nodeData : undefined);
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export type { DurableProofGraphStore, DurableProofGraphStoreOptions, ProofGraphR
|
|
|
19
19
|
export { createProofGraphEvidenceStore, assertEvidenceBinding, normalizeEvidenceHash, } from './evidence.js';
|
|
20
20
|
export type { ProofGraphEvidenceStore, ProofGraphEvidenceStoreOptions, ProofGraphEvidenceResult, EvidenceArtifactBinding, PutEvidenceOptions, } from './evidence.js';
|
|
21
21
|
export { toHex, canonicalJson, computeNodeId, computeEdgeId, computeProofGraphId, recomputeGraphId, } from './canonical.js';
|
|
22
|
-
export { createProofGraph, setGraphMetadata, buildEdge, addNode, addEdge, addIdentityDocument, addProof, addIdentityClaim, addManifest, addReceiptLike, addAnchor, } from './graph.js';
|
|
23
|
-
export { findNode, getEdgesFrom, getEdgesTo, getEdgesByType, getProofNodes, findProofsBySubject, findProofsByIssuer, findAnchorsForProof, findRevocations, findSupersessions, findConflicts, getEvidenceTrail, getProofLineage, resolveCurrentProofSet, getManifestsForAddress, getEdgesBetween, reachableFrom, } from './query.js';
|
|
22
|
+
export { createProofGraph, setGraphMetadata, buildEdge, addNode, addEdge, addIdentityDocument, addProof, addIdentityClaim, addManifest, addManifestRevision, addReceiptLike, addAnchor, } from './graph.js';
|
|
23
|
+
export { findNode, getEdgesFrom, getEdgesTo, getEdgesByType, getProofNodes, findProofsBySubject, findProofsByIssuer, findAnchorsForProof, findRevocations, findSupersessions, findConflicts, getEvidenceTrail, getProofLineage, resolveCurrentProofSet, getManifestRevisions, getManifestsForAddress, getEdgesBetween, reachableFrom, } from './query.js';
|
|
24
24
|
export { verifyProofGraph, verifyGraphProofs, } from './verify.js';
|
|
25
25
|
export { exportProofGraph, importProofGraph, } from './io.js';
|
|
26
|
+
export * from './replicated-evidence.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module @totemsdk/proofgraph
|
|
4
3
|
*
|
|
@@ -14,54 +13,11 @@
|
|
|
14
13
|
* const g1 = addProof(g0, signedProof);
|
|
15
14
|
* const result = verifyProofGraph(g1);
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var canonical_js_1 = require("./canonical.js"); // canonicalJson / toHex re-exported from @totemsdk/proof
|
|
26
|
-
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return canonical_js_1.toHex; } });
|
|
27
|
-
Object.defineProperty(exports, "canonicalJson", { enumerable: true, get: function () { return canonical_js_1.canonicalJson; } });
|
|
28
|
-
Object.defineProperty(exports, "computeNodeId", { enumerable: true, get: function () { return canonical_js_1.computeNodeId; } });
|
|
29
|
-
Object.defineProperty(exports, "computeEdgeId", { enumerable: true, get: function () { return canonical_js_1.computeEdgeId; } });
|
|
30
|
-
Object.defineProperty(exports, "computeProofGraphId", { enumerable: true, get: function () { return canonical_js_1.computeProofGraphId; } });
|
|
31
|
-
Object.defineProperty(exports, "recomputeGraphId", { enumerable: true, get: function () { return canonical_js_1.recomputeGraphId; } });
|
|
32
|
-
var graph_js_1 = require("./graph.js");
|
|
33
|
-
Object.defineProperty(exports, "createProofGraph", { enumerable: true, get: function () { return graph_js_1.createProofGraph; } });
|
|
34
|
-
Object.defineProperty(exports, "setGraphMetadata", { enumerable: true, get: function () { return graph_js_1.setGraphMetadata; } });
|
|
35
|
-
Object.defineProperty(exports, "buildEdge", { enumerable: true, get: function () { return graph_js_1.buildEdge; } });
|
|
36
|
-
Object.defineProperty(exports, "addNode", { enumerable: true, get: function () { return graph_js_1.addNode; } });
|
|
37
|
-
Object.defineProperty(exports, "addEdge", { enumerable: true, get: function () { return graph_js_1.addEdge; } });
|
|
38
|
-
Object.defineProperty(exports, "addIdentityDocument", { enumerable: true, get: function () { return graph_js_1.addIdentityDocument; } });
|
|
39
|
-
Object.defineProperty(exports, "addProof", { enumerable: true, get: function () { return graph_js_1.addProof; } });
|
|
40
|
-
Object.defineProperty(exports, "addIdentityClaim", { enumerable: true, get: function () { return graph_js_1.addIdentityClaim; } });
|
|
41
|
-
Object.defineProperty(exports, "addManifest", { enumerable: true, get: function () { return graph_js_1.addManifest; } });
|
|
42
|
-
Object.defineProperty(exports, "addReceiptLike", { enumerable: true, get: function () { return graph_js_1.addReceiptLike; } });
|
|
43
|
-
Object.defineProperty(exports, "addAnchor", { enumerable: true, get: function () { return graph_js_1.addAnchor; } });
|
|
44
|
-
var query_js_1 = require("./query.js");
|
|
45
|
-
Object.defineProperty(exports, "findNode", { enumerable: true, get: function () { return query_js_1.findNode; } });
|
|
46
|
-
Object.defineProperty(exports, "getEdgesFrom", { enumerable: true, get: function () { return query_js_1.getEdgesFrom; } });
|
|
47
|
-
Object.defineProperty(exports, "getEdgesTo", { enumerable: true, get: function () { return query_js_1.getEdgesTo; } });
|
|
48
|
-
Object.defineProperty(exports, "getEdgesByType", { enumerable: true, get: function () { return query_js_1.getEdgesByType; } });
|
|
49
|
-
Object.defineProperty(exports, "getProofNodes", { enumerable: true, get: function () { return query_js_1.getProofNodes; } });
|
|
50
|
-
Object.defineProperty(exports, "findProofsBySubject", { enumerable: true, get: function () { return query_js_1.findProofsBySubject; } });
|
|
51
|
-
Object.defineProperty(exports, "findProofsByIssuer", { enumerable: true, get: function () { return query_js_1.findProofsByIssuer; } });
|
|
52
|
-
Object.defineProperty(exports, "findAnchorsForProof", { enumerable: true, get: function () { return query_js_1.findAnchorsForProof; } });
|
|
53
|
-
Object.defineProperty(exports, "findRevocations", { enumerable: true, get: function () { return query_js_1.findRevocations; } });
|
|
54
|
-
Object.defineProperty(exports, "findSupersessions", { enumerable: true, get: function () { return query_js_1.findSupersessions; } });
|
|
55
|
-
Object.defineProperty(exports, "findConflicts", { enumerable: true, get: function () { return query_js_1.findConflicts; } });
|
|
56
|
-
Object.defineProperty(exports, "getEvidenceTrail", { enumerable: true, get: function () { return query_js_1.getEvidenceTrail; } });
|
|
57
|
-
Object.defineProperty(exports, "getProofLineage", { enumerable: true, get: function () { return query_js_1.getProofLineage; } });
|
|
58
|
-
Object.defineProperty(exports, "resolveCurrentProofSet", { enumerable: true, get: function () { return query_js_1.resolveCurrentProofSet; } });
|
|
59
|
-
Object.defineProperty(exports, "getManifestsForAddress", { enumerable: true, get: function () { return query_js_1.getManifestsForAddress; } });
|
|
60
|
-
Object.defineProperty(exports, "getEdgesBetween", { enumerable: true, get: function () { return query_js_1.getEdgesBetween; } });
|
|
61
|
-
Object.defineProperty(exports, "reachableFrom", { enumerable: true, get: function () { return query_js_1.reachableFrom; } });
|
|
62
|
-
var verify_js_1 = require("./verify.js");
|
|
63
|
-
Object.defineProperty(exports, "verifyProofGraph", { enumerable: true, get: function () { return verify_js_1.verifyProofGraph; } });
|
|
64
|
-
Object.defineProperty(exports, "verifyGraphProofs", { enumerable: true, get: function () { return verify_js_1.verifyGraphProofs; } });
|
|
65
|
-
var io_js_1 = require("./io.js");
|
|
66
|
-
Object.defineProperty(exports, "exportProofGraph", { enumerable: true, get: function () { return io_js_1.exportProofGraph; } });
|
|
67
|
-
Object.defineProperty(exports, "importProofGraph", { enumerable: true, get: function () { return io_js_1.importProofGraph; } });
|
|
16
|
+
export { createDurableProofGraphStore, } from './durable-store.js';
|
|
17
|
+
export { createProofGraphEvidenceStore, assertEvidenceBinding, normalizeEvidenceHash, } from './evidence.js';
|
|
18
|
+
export { toHex, canonicalJson, computeNodeId, computeEdgeId, computeProofGraphId, recomputeGraphId, } from './canonical.js'; // canonicalJson / toHex re-exported from @totemsdk/proof
|
|
19
|
+
export { createProofGraph, setGraphMetadata, buildEdge, addNode, addEdge, addIdentityDocument, addProof, addIdentityClaim, addManifest, addManifestRevision, addReceiptLike, addAnchor, } from './graph.js';
|
|
20
|
+
export { findNode, getEdgesFrom, getEdgesTo, getEdgesByType, getProofNodes, findProofsBySubject, findProofsByIssuer, findAnchorsForProof, findRevocations, findSupersessions, findConflicts, getEvidenceTrail, getProofLineage, resolveCurrentProofSet, getManifestRevisions, getManifestsForAddress, getEdgesBetween, reachableFrom, } from './query.js';
|
|
21
|
+
export { verifyProofGraph, verifyGraphProofs, } from './verify.js';
|
|
22
|
+
export { exportProofGraph, importProofGraph, } from './io.js';
|
|
23
|
+
export * from './replicated-evidence.js';
|
package/dist/io.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Serialization helpers for ProofGraph.
|
|
4
3
|
*
|
|
@@ -9,10 +8,7 @@
|
|
|
9
8
|
* The graphId guards against silent corruption in transit. Node/edge
|
|
10
9
|
* validation prevents hostile or malformed input from entering the system.
|
|
11
10
|
*/
|
|
12
|
-
|
|
13
|
-
exports.exportProofGraph = exportProofGraph;
|
|
14
|
-
exports.importProofGraph = importProofGraph;
|
|
15
|
-
const canonical_js_1 = require("./canonical.js");
|
|
11
|
+
import { recomputeGraphId } from './canonical.js';
|
|
16
12
|
const VALID_NODE_TYPES = new Set([
|
|
17
13
|
'proof', 'identity', 'identity-claim', 'manifest', 'address',
|
|
18
14
|
'subject', 'evidence', 'anchor', 'receipt', 'payment', 'device',
|
|
@@ -121,7 +117,7 @@ function checkDepth(obj, depth, maxDepth, path) {
|
|
|
121
117
|
* Serialize a ProofGraph to a JSON string.
|
|
122
118
|
* The stored graphId was computed at mutation time and is included as-is.
|
|
123
119
|
*/
|
|
124
|
-
function exportProofGraph(graph) {
|
|
120
|
+
export function exportProofGraph(graph) {
|
|
125
121
|
return JSON.stringify(graph);
|
|
126
122
|
}
|
|
127
123
|
/**
|
|
@@ -133,7 +129,7 @@ function exportProofGraph(graph) {
|
|
|
133
129
|
*
|
|
134
130
|
* @throws Error if parsing, validation, or graphId verification fails.
|
|
135
131
|
*/
|
|
136
|
-
function importProofGraph(json) {
|
|
132
|
+
export function importProofGraph(json) {
|
|
137
133
|
let parsed;
|
|
138
134
|
try {
|
|
139
135
|
parsed = JSON.parse(json);
|
|
@@ -163,7 +159,7 @@ function importProofGraph(json) {
|
|
|
163
159
|
}
|
|
164
160
|
// Recompute and verify graphId
|
|
165
161
|
const originalId = typeof graph.graphId === 'string' ? graph.graphId : '';
|
|
166
|
-
const recomputed =
|
|
162
|
+
const recomputed = recomputeGraphId(graph);
|
|
167
163
|
// If a stored graphId exists, verify it matches
|
|
168
164
|
if (originalId !== '' && recomputed !== originalId) {
|
|
169
165
|
throw new Error(`importProofGraph: graphId mismatch — stored="${originalId}" recomputed="${recomputed}"`);
|
package/dist/query.d.ts
CHANGED
|
@@ -70,6 +70,10 @@ export declare function resolveCurrentProofSet(graph: ProofGraph): ProofGraphNod
|
|
|
70
70
|
* Return all manifest nodes linked to a given address via 'manifests_as' edges.
|
|
71
71
|
*/
|
|
72
72
|
export declare function getManifestsForAddress(graph: ProofGraph, address: string): ProofGraphNode[];
|
|
73
|
+
/**
|
|
74
|
+
* Return all content-addressed revisions of a logical manifest, ordered by envelope ID.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getManifestRevisions(graph: ProofGraph, manifestId: string): ProofGraphNode[];
|
|
73
77
|
/**
|
|
74
78
|
* Return all edges between two nodes (in either direction).
|
|
75
79
|
*/
|
package/dist/query.js
CHANGED
|
@@ -1,68 +1,49 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Query helpers for ProofGraph — pure read-only utilities.
|
|
4
3
|
*
|
|
5
4
|
* All functions receive a ProofGraph and return data without mutating the graph.
|
|
6
5
|
* Function names match the @totemsdk/proofgraph public API spec exactly.
|
|
7
6
|
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.findNode = findNode;
|
|
10
|
-
exports.getEdgesFrom = getEdgesFrom;
|
|
11
|
-
exports.getEdgesTo = getEdgesTo;
|
|
12
|
-
exports.getEdgesByType = getEdgesByType;
|
|
13
|
-
exports.getProofNodes = getProofNodes;
|
|
14
|
-
exports.findProofsBySubject = findProofsBySubject;
|
|
15
|
-
exports.findProofsByIssuer = findProofsByIssuer;
|
|
16
|
-
exports.findAnchorsForProof = findAnchorsForProof;
|
|
17
|
-
exports.findRevocations = findRevocations;
|
|
18
|
-
exports.findSupersessions = findSupersessions;
|
|
19
|
-
exports.findConflicts = findConflicts;
|
|
20
|
-
exports.getEvidenceTrail = getEvidenceTrail;
|
|
21
|
-
exports.getProofLineage = getProofLineage;
|
|
22
|
-
exports.resolveCurrentProofSet = resolveCurrentProofSet;
|
|
23
|
-
exports.getManifestsForAddress = getManifestsForAddress;
|
|
24
|
-
exports.getEdgesBetween = getEdgesBetween;
|
|
25
|
-
exports.reachableFrom = reachableFrom;
|
|
26
7
|
/**
|
|
27
8
|
* Find a node by its composed node ID (type:refId) or by refId alone.
|
|
28
9
|
*/
|
|
29
|
-
function findNode(graph, id) {
|
|
10
|
+
export function findNode(graph, id) {
|
|
30
11
|
return graph.nodes.find((n) => n.id === id || n.refId === id);
|
|
31
12
|
}
|
|
32
13
|
/**
|
|
33
14
|
* Return all outgoing edges from a node (identified by node ID or refId).
|
|
34
15
|
*/
|
|
35
|
-
function getEdgesFrom(graph, nodeIdOrRefId) {
|
|
16
|
+
export function getEdgesFrom(graph, nodeIdOrRefId) {
|
|
36
17
|
const node = findNode(graph, nodeIdOrRefId);
|
|
37
18
|
if (!node)
|
|
38
19
|
return [];
|
|
39
|
-
return graph.edges.filter((e) => e.from === node.refId);
|
|
20
|
+
return graph.edges.filter((e) => e.from === node.refId || e.from === node.id);
|
|
40
21
|
}
|
|
41
22
|
/**
|
|
42
23
|
* Return all incoming edges to a node (identified by node ID or refId).
|
|
43
24
|
*/
|
|
44
|
-
function getEdgesTo(graph, nodeIdOrRefId) {
|
|
25
|
+
export function getEdgesTo(graph, nodeIdOrRefId) {
|
|
45
26
|
const node = findNode(graph, nodeIdOrRefId);
|
|
46
27
|
if (!node)
|
|
47
28
|
return [];
|
|
48
|
-
return graph.edges.filter((e) => e.to === node.refId);
|
|
29
|
+
return graph.edges.filter((e) => e.to === node.refId || e.to === node.id);
|
|
49
30
|
}
|
|
50
31
|
/**
|
|
51
32
|
* Return all edges of a given type.
|
|
52
33
|
*/
|
|
53
|
-
function getEdgesByType(graph, type) {
|
|
34
|
+
export function getEdgesByType(graph, type) {
|
|
54
35
|
return graph.edges.filter((e) => e.type === type);
|
|
55
36
|
}
|
|
56
37
|
/**
|
|
57
38
|
* Return all proof nodes in the graph.
|
|
58
39
|
*/
|
|
59
|
-
function getProofNodes(graph) {
|
|
40
|
+
export function getProofNodes(graph) {
|
|
60
41
|
return graph.nodes.filter((n) => n.type === 'proof');
|
|
61
42
|
}
|
|
62
43
|
/**
|
|
63
44
|
* Find all 'proof' nodes connected to a subject via 'about' OR 'proves' edges.
|
|
64
45
|
*/
|
|
65
|
-
function findProofsBySubject(graph, subjectId) {
|
|
46
|
+
export function findProofsBySubject(graph, subjectId) {
|
|
66
47
|
const relevantEdges = graph.edges.filter((e) => (e.type === 'about' || e.type === 'proves') && e.to === subjectId);
|
|
67
48
|
const proofRefIds = new Set(relevantEdges.map((e) => e.from));
|
|
68
49
|
return graph.nodes.filter((n) => proofRefIds.has(n.refId) && n.type === 'proof');
|
|
@@ -70,7 +51,7 @@ function findProofsBySubject(graph, subjectId) {
|
|
|
70
51
|
/**
|
|
71
52
|
* Find all 'proof' nodes issued by a given address (via 'issued_by' edges).
|
|
72
53
|
*/
|
|
73
|
-
function findProofsByIssuer(graph, issuerId) {
|
|
54
|
+
export function findProofsByIssuer(graph, issuerId) {
|
|
74
55
|
const issuedEdges = graph.edges.filter((e) => e.type === 'issued_by' && e.to === issuerId);
|
|
75
56
|
const proofRefIds = new Set(issuedEdges.map((e) => e.from));
|
|
76
57
|
return graph.nodes.filter((n) => proofRefIds.has(n.refId) && n.type === 'proof');
|
|
@@ -78,7 +59,7 @@ function findProofsByIssuer(graph, issuerId) {
|
|
|
78
59
|
/**
|
|
79
60
|
* Find all 'anchor' nodes linked to a proof via 'anchored_to' edges.
|
|
80
61
|
*/
|
|
81
|
-
function findAnchorsForProof(graph, proofId) {
|
|
62
|
+
export function findAnchorsForProof(graph, proofId) {
|
|
82
63
|
const anchoredEdges = graph.edges.filter((e) => e.type === 'anchored_to' && e.from === proofId);
|
|
83
64
|
const anchorRefIds = new Set(anchoredEdges.map((e) => e.to));
|
|
84
65
|
return graph.nodes.filter((n) => anchorRefIds.has(n.refId) && n.type === 'anchor');
|
|
@@ -86,19 +67,19 @@ function findAnchorsForProof(graph, proofId) {
|
|
|
86
67
|
/**
|
|
87
68
|
* Find all 'revokes' edges whose target is the given proof node.
|
|
88
69
|
*/
|
|
89
|
-
function findRevocations(graph, proofId) {
|
|
70
|
+
export function findRevocations(graph, proofId) {
|
|
90
71
|
return graph.edges.filter((e) => e.type === 'revokes' && e.to === proofId);
|
|
91
72
|
}
|
|
92
73
|
/**
|
|
93
74
|
* Find all 'supersedes' edges whose target is the given proof node.
|
|
94
75
|
*/
|
|
95
|
-
function findSupersessions(graph, proofId) {
|
|
76
|
+
export function findSupersessions(graph, proofId) {
|
|
96
77
|
return graph.edges.filter((e) => e.type === 'supersedes' && e.to === proofId);
|
|
97
78
|
}
|
|
98
79
|
/**
|
|
99
80
|
* Find all 'conflicts_with' edges involving the given proof node (in either direction).
|
|
100
81
|
*/
|
|
101
|
-
function findConflicts(graph, proofId) {
|
|
82
|
+
export function findConflicts(graph, proofId) {
|
|
102
83
|
return graph.edges.filter((e) => e.type === 'conflicts_with' &&
|
|
103
84
|
(e.from === proofId || e.to === proofId));
|
|
104
85
|
}
|
|
@@ -107,7 +88,7 @@ function findConflicts(graph, proofId) {
|
|
|
107
88
|
* Returns nodes in insertion order (the order edges were added, which matches
|
|
108
89
|
* the original evidence array order from addProof).
|
|
109
90
|
*/
|
|
110
|
-
function getEvidenceTrail(graph, proofId) {
|
|
91
|
+
export function getEvidenceTrail(graph, proofId) {
|
|
111
92
|
const refEdges = graph.edges.filter((e) => e.type === 'references' && e.from === proofId);
|
|
112
93
|
return refEdges
|
|
113
94
|
.map((e) => graph.nodes.find((n) => n.refId === e.to && n.type === 'evidence'))
|
|
@@ -118,7 +99,7 @@ function getEvidenceTrail(graph, proofId) {
|
|
|
118
99
|
* Returns the ordered chain of ancestor proof nodes (closest ancestor first).
|
|
119
100
|
* Terminates on cycle detection.
|
|
120
101
|
*/
|
|
121
|
-
function getProofLineage(graph, proofId, _visited = new Set()) {
|
|
102
|
+
export function getProofLineage(graph, proofId, _visited = new Set()) {
|
|
122
103
|
if (_visited.has(proofId))
|
|
123
104
|
return [];
|
|
124
105
|
_visited.add(proofId);
|
|
@@ -137,7 +118,7 @@ function getProofLineage(graph, proofId, _visited = new Set()) {
|
|
|
137
118
|
* Return all proof nodes that are NOT the target of any 'revokes' or 'supersedes' edge.
|
|
138
119
|
* These are the current / active proofs in the graph.
|
|
139
120
|
*/
|
|
140
|
-
function resolveCurrentProofSet(graph) {
|
|
121
|
+
export function resolveCurrentProofSet(graph) {
|
|
141
122
|
const supersededOrRevoked = new Set();
|
|
142
123
|
for (const edge of graph.edges) {
|
|
143
124
|
if (edge.type === 'revokes' || edge.type === 'supersedes') {
|
|
@@ -149,15 +130,26 @@ function resolveCurrentProofSet(graph) {
|
|
|
149
130
|
/**
|
|
150
131
|
* Return all manifest nodes linked to a given address via 'manifests_as' edges.
|
|
151
132
|
*/
|
|
152
|
-
function getManifestsForAddress(graph, address) {
|
|
133
|
+
export function getManifestsForAddress(graph, address) {
|
|
153
134
|
const manifestEdges = graph.edges.filter((e) => e.type === 'manifests_as' && e.to === address);
|
|
154
135
|
const manifestRefIds = new Set(manifestEdges.map((e) => e.from));
|
|
155
136
|
return graph.nodes.filter((n) => manifestRefIds.has(n.refId) && n.type === 'manifest');
|
|
156
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Return all content-addressed revisions of a logical manifest, ordered by envelope ID.
|
|
140
|
+
*/
|
|
141
|
+
export function getManifestRevisions(graph, manifestId) {
|
|
142
|
+
const revisionRefs = new Set(graph.edges
|
|
143
|
+
.filter((edge) => edge.type === 'revision_of' && edge.to === manifestId)
|
|
144
|
+
.map((edge) => edge.from));
|
|
145
|
+
return graph.nodes
|
|
146
|
+
.filter((node) => node.type === 'manifest' && revisionRefs.has(node.refId))
|
|
147
|
+
.sort((a, b) => a.refId.localeCompare(b.refId));
|
|
148
|
+
}
|
|
157
149
|
/**
|
|
158
150
|
* Return all edges between two nodes (in either direction).
|
|
159
151
|
*/
|
|
160
|
-
function getEdgesBetween(graph, refIdA, refIdB) {
|
|
152
|
+
export function getEdgesBetween(graph, refIdA, refIdB) {
|
|
161
153
|
return graph.edges.filter((e) => (e.from === refIdA && e.to === refIdB) ||
|
|
162
154
|
(e.from === refIdB && e.to === refIdA));
|
|
163
155
|
}
|
|
@@ -165,7 +157,7 @@ function getEdgesBetween(graph, refIdA, refIdB) {
|
|
|
165
157
|
* Return the set of all node refIds reachable from a given node via directed edges.
|
|
166
158
|
* Includes the start node itself.
|
|
167
159
|
*/
|
|
168
|
-
function reachableFrom(graph, startRefId, _visited = new Set()) {
|
|
160
|
+
export function reachableFrom(graph, startRefId, _visited = new Set()) {
|
|
169
161
|
if (_visited.has(startRefId))
|
|
170
162
|
return _visited;
|
|
171
163
|
_visited.add(startRefId);
|