@totemsdk/proofgraph 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.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Canonical JSON and ID rules for @totemsdk/proofgraph.
3
+ *
4
+ * canonicalJson is implemented fresh — @totemsdk/identity and @totemsdk/proof
5
+ * each have their own copy; none of them export it publicly.
6
+ *
7
+ * ID rules:
8
+ * Node: type + ":" + refId (e.g. "proof:totem:proof:abc123")
9
+ * Edge: sha3_256("totem-proofgraph-edge" + type + from + to + (proofId||'') + dataHash)
10
+ * Graph: sha3_256("totem-proofgraph" + canonicalJson(nodeHashes) + canonicalJson(sortedEdges))
11
+ * — node.createdAt and graph.metadata excluded from graphId (time-variant / mutable)
12
+ */
13
+ import type { ProofGraphNode, ProofGraphEdge } from './types.js';
14
+ export declare function toHex(bytes: Uint8Array): string;
15
+ export declare function canonicalJson(value: unknown): string;
16
+ export declare function computeNodeId(type: string, refId: string): string;
17
+ export declare function computeEdgeId(type: string, from: string, to: string, proofId: string | undefined, data: Record<string, unknown> | undefined): string;
18
+ export declare function computeProofGraphId(nodes: ProofGraphNode[], edges: ProofGraphEdge[]): string;
19
+ export declare function recomputeGraphId(graph: {
20
+ nodes: ProofGraphNode[];
21
+ edges: ProofGraphEdge[];
22
+ }): string;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * Canonical JSON and ID rules for @totemsdk/proofgraph.
4
+ *
5
+ * canonicalJson is implemented fresh — @totemsdk/identity and @totemsdk/proof
6
+ * each have their own copy; none of them export it publicly.
7
+ *
8
+ * ID rules:
9
+ * Node: type + ":" + refId (e.g. "proof:totem:proof:abc123")
10
+ * Edge: sha3_256("totem-proofgraph-edge" + type + from + to + (proofId||'') + dataHash)
11
+ * Graph: sha3_256("totem-proofgraph" + canonicalJson(nodeHashes) + canonicalJson(sortedEdges))
12
+ * — node.createdAt and graph.metadata excluded from graphId (time-variant / mutable)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.toHex = toHex;
16
+ exports.canonicalJson = canonicalJson;
17
+ exports.computeNodeId = computeNodeId;
18
+ exports.computeEdgeId = computeEdgeId;
19
+ exports.computeProofGraphId = computeProofGraphId;
20
+ exports.recomputeGraphId = recomputeGraphId;
21
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
22
+ function toHex(bytes) {
23
+ return Array.from(bytes)
24
+ .map((b) => b.toString(16).padStart(2, '0'))
25
+ .join('');
26
+ }
27
+ function canonicalJson(value) {
28
+ if (value === null || typeof value !== 'object') {
29
+ return JSON.stringify(value);
30
+ }
31
+ if (Array.isArray(value)) {
32
+ return '[' + value.map(canonicalJson).join(',') + ']';
33
+ }
34
+ const obj = value;
35
+ const keys = Object.keys(obj).sort();
36
+ const pairs = keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`);
37
+ return '{' + pairs.join(',') + '}';
38
+ }
39
+ function computeNodeId(type, refId) {
40
+ return `${type}:${refId}`;
41
+ }
42
+ function computeEdgeId(type, from, to, proofId, data) {
43
+ const canonicalDataHash = toHex((0, sha3_js_1.sha3_256)(new TextEncoder().encode(canonicalJson(data ?? {}))));
44
+ const input = 'totem-proofgraph-edge' + type + from + to + (proofId ?? '') + canonicalDataHash;
45
+ return toHex((0, sha3_js_1.sha3_256)(new TextEncoder().encode(input)));
46
+ }
47
+ /**
48
+ * Content-stable projection of a node for graphId computation.
49
+ * Strips createdAt (time-variant) so equivalent logical content always
50
+ * produces the same graphId regardless of when nodes were created.
51
+ */
52
+ function nodeForHashing(node) {
53
+ const { createdAt: _createdAt, ...rest } = node;
54
+ return rest;
55
+ }
56
+ function computeProofGraphId(nodes, edges) {
57
+ const sortedNodes = [...nodes]
58
+ .sort((a, b) => a.id.localeCompare(b.id))
59
+ .map(nodeForHashing);
60
+ const sortedEdges = [...edges].sort((a, b) => a.id.localeCompare(b.id));
61
+ const input = 'totem-proofgraph' + canonicalJson(sortedNodes) + canonicalJson(sortedEdges);
62
+ return toHex((0, sha3_js_1.sha3_256)(new TextEncoder().encode(input)));
63
+ }
64
+ function recomputeGraphId(graph) {
65
+ return computeProofGraphId(graph.nodes, graph.edges);
66
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Proof graph mutation functions — all pure, all returning NEW graphs.
3
+ *
4
+ * Immutable pattern: every mutation returns a brand-new ProofGraph with a
5
+ * recomputed graphId. Nodes and edges are deduplicated by ID so adding the
6
+ * same proof twice is idempotent.
7
+ */
8
+ import type { SignedProof } from '@totemsdk/proof';
9
+ import type { SignedIdentityClaim, TotemIdentityDocument } from '@totemsdk/identity';
10
+ import type { SignedManifest } from '@totemsdk/manifest';
11
+ import type { ProofGraph, ProofGraphEdge, ProofGraphEdgeType, ProofGraphNodeType, ReceiptLikeInput, AnchorInput } from './types.js';
12
+ /**
13
+ * Create an empty ProofGraph.
14
+ */
15
+ export declare function createProofGraph(metadata?: Record<string, unknown>): ProofGraph;
16
+ /**
17
+ * Attach or replace mutable metadata. Does NOT affect graphId.
18
+ */
19
+ export declare function setGraphMetadata(graph: ProofGraph, metadata: Record<string, unknown>): ProofGraph;
20
+ /**
21
+ * Build a ProofGraphEdge with a deterministic ID from its fields.
22
+ * Convenience helper so callers don't need to import computeEdgeId.
23
+ */
24
+ export declare function buildEdge(type: ProofGraphEdgeType, from: string, to: string, proofId?: string, data?: Record<string, unknown>): ProofGraphEdge;
25
+ /**
26
+ * Add a node directly (type + refId pair). Idempotent — skipped if the node already exists.
27
+ */
28
+ export declare function addNode(graph: ProofGraph, type: ProofGraphNodeType, refId: string, data?: Record<string, unknown>): ProofGraph;
29
+ /**
30
+ * Append a ProofGraphEdge and recompute graphId. Idempotent by edge ID.
31
+ * Spec API: addEdge(graph, edge). Use buildEdge() to construct the edge object.
32
+ */
33
+ export declare function addEdge(graph: ProofGraph, edge: ProofGraphEdge): ProofGraph;
34
+ /**
35
+ * Index a TotemIdentityDocument into the graph.
36
+ * Creates an 'identity' node with refId = doc.id.
37
+ */
38
+ export declare function addIdentityDocument(graph: ProofGraph, doc: TotemIdentityDocument): ProofGraph;
39
+ /**
40
+ * Index a SignedProof into the graph.
41
+ *
42
+ * Nodes created:
43
+ * proof — proofId (stores the full SignedProof in .data)
44
+ * identity — signature.address (issuer key address)
45
+ * subject — proof.subject.id
46
+ * evidence — ev.id (one per evidence ref)
47
+ * anchor — anchor.hash (if present)
48
+ *
49
+ * Edges created (all referencing the proofId):
50
+ * proves proof → subject
51
+ * issued_by proof → identity (signer)
52
+ * about proof → subject
53
+ * references proof → evidence (one per evidence ref, in array order)
54
+ * anchored_to proof → anchor (if present)
55
+ */
56
+ export declare function addProof(graph: ProofGraph, signedProof: SignedProof): ProofGraph;
57
+ /**
58
+ * Index a SignedIdentityClaim into the graph.
59
+ *
60
+ * Nodes created:
61
+ * identity-claim — claim.id (stores the full signed claim in .data)
62
+ * address — issuer address
63
+ * address/identity — target address (for delegates_to / rotates_to / revokes)
64
+ *
65
+ * Edges created based on claim.type:
66
+ * all types → issued_by (claim-node → issuer address)
67
+ * delegates_to → delegates_to edge (claim-node → delegated address)
68
+ * revokes → revokes edge (claim-node → subject identity)
69
+ * rotates_to → controls edge (claim-node → new address)
70
+ */
71
+ export declare function addIdentityClaim(graph: ProofGraph, signedClaim: SignedIdentityClaim): ProofGraph;
72
+ /**
73
+ * Index a SignedManifest into the graph.
74
+ *
75
+ * Nodes created:
76
+ * manifest — computed manifest ID (stores manifest content in .data)
77
+ * address — resolved author/agent/operator address
78
+ *
79
+ * Edge created:
80
+ * manifests_as manifest → address
81
+ */
82
+ export declare function addManifest(graph: ProofGraph, signedManifest: SignedManifest): ProofGraph;
83
+ /**
84
+ * Add a receipt-like node (payment, subscription, claim receipt) to the graph.
85
+ * If receipt.proofId is set, adds a 'supports' edge from the receipt to that proof.
86
+ */
87
+ export declare function addReceiptLike(graph: ProofGraph, receipt: ReceiptLikeInput): ProofGraph;
88
+ /**
89
+ * Add a standalone anchor node. If anchor.proofId is set, adds an 'anchored_to'
90
+ * edge from the proof to this anchor.
91
+ */
92
+ export declare function addAnchor(graph: ProofGraph, anchor: AnchorInput): ProofGraph;
package/dist/graph.js ADDED
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ /**
3
+ * Proof graph mutation functions — all pure, all returning NEW graphs.
4
+ *
5
+ * Immutable pattern: every mutation returns a brand-new ProofGraph with a
6
+ * recomputed graphId. Nodes and edges are deduplicated by ID so adding the
7
+ * same proof twice is idempotent.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.createProofGraph = createProofGraph;
11
+ exports.setGraphMetadata = setGraphMetadata;
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
+ function makeNode(type, refId, data) {
24
+ return {
25
+ id: (0, canonical_js_1.computeNodeId)(type, refId),
26
+ type,
27
+ refId,
28
+ ...(data !== undefined ? { data } : {}),
29
+ createdAt: Date.now(),
30
+ };
31
+ }
32
+ function makeEdge(type, from, to, proofId, data) {
33
+ return {
34
+ id: (0, canonical_js_1.computeEdgeId)(type, from, to, proofId, data),
35
+ type,
36
+ from,
37
+ to,
38
+ ...(proofId !== undefined ? { proofId } : {}),
39
+ ...(data !== undefined ? { data } : {}),
40
+ };
41
+ }
42
+ function mergeNodes(existing, incoming) {
43
+ const byId = new Map(existing.map((n) => [n.id, n]));
44
+ for (const node of incoming) {
45
+ if (!byId.has(node.id)) {
46
+ byId.set(node.id, node);
47
+ }
48
+ }
49
+ return Array.from(byId.values());
50
+ }
51
+ function mergeEdges(existing, incoming) {
52
+ const byId = new Map(existing.map((e) => [e.id, e]));
53
+ for (const edge of incoming) {
54
+ if (!byId.has(edge.id)) {
55
+ byId.set(edge.id, edge);
56
+ }
57
+ }
58
+ return Array.from(byId.values());
59
+ }
60
+ function rebuild(graph, newNodes, newEdges) {
61
+ const nodes = mergeNodes(graph.nodes, newNodes);
62
+ const edges = mergeEdges(graph.edges, newEdges);
63
+ return {
64
+ ...graph,
65
+ nodes,
66
+ edges,
67
+ graphId: (0, canonical_js_1.computeProofGraphId)(nodes, edges),
68
+ };
69
+ }
70
+ /**
71
+ * Create an empty ProofGraph.
72
+ */
73
+ function createProofGraph(metadata) {
74
+ const nodes = [];
75
+ const edges = [];
76
+ return {
77
+ graphId: (0, canonical_js_1.computeProofGraphId)(nodes, edges),
78
+ nodes,
79
+ edges,
80
+ createdAt: Date.now(),
81
+ ...(metadata !== undefined ? { metadata } : {}),
82
+ };
83
+ }
84
+ /**
85
+ * Attach or replace mutable metadata. Does NOT affect graphId.
86
+ */
87
+ function setGraphMetadata(graph, metadata) {
88
+ return { ...graph, metadata };
89
+ }
90
+ /**
91
+ * Build a ProofGraphEdge with a deterministic ID from its fields.
92
+ * Convenience helper so callers don't need to import computeEdgeId.
93
+ */
94
+ function buildEdge(type, from, to, proofId, data) {
95
+ return makeEdge(type, from, to, proofId, data);
96
+ }
97
+ /**
98
+ * Add a node directly (type + refId pair). Idempotent — skipped if the node already exists.
99
+ */
100
+ function addNode(graph, type, refId, data) {
101
+ return rebuild(graph, [makeNode(type, refId, data)], []);
102
+ }
103
+ /**
104
+ * Append a ProofGraphEdge and recompute graphId. Idempotent by edge ID.
105
+ * Spec API: addEdge(graph, edge). Use buildEdge() to construct the edge object.
106
+ */
107
+ function addEdge(graph, edge) {
108
+ const edges = mergeEdges(graph.edges, [edge]);
109
+ return {
110
+ ...graph,
111
+ edges,
112
+ graphId: (0, canonical_js_1.computeProofGraphId)(graph.nodes, edges),
113
+ };
114
+ }
115
+ /**
116
+ * Index a TotemIdentityDocument into the graph.
117
+ * Creates an 'identity' node with refId = doc.id.
118
+ */
119
+ function addIdentityDocument(graph, doc) {
120
+ return rebuild(graph, [makeNode('identity', doc.id, { ...doc })], []);
121
+ }
122
+ /**
123
+ * Index a SignedProof into the graph.
124
+ *
125
+ * Nodes created:
126
+ * proof — proofId (stores the full SignedProof in .data)
127
+ * identity — signature.address (issuer key address)
128
+ * subject — proof.subject.id
129
+ * evidence — ev.id (one per evidence ref)
130
+ * anchor — anchor.hash (if present)
131
+ *
132
+ * Edges created (all referencing the proofId):
133
+ * proves proof → subject
134
+ * issued_by proof → identity (signer)
135
+ * about proof → subject
136
+ * references proof → evidence (one per evidence ref, in array order)
137
+ * anchored_to proof → anchor (if present)
138
+ */
139
+ function addProof(graph, signedProof) {
140
+ const proofNode = makeNode('proof', signedProof.proofId, {
141
+ ...signedProof,
142
+ });
143
+ const identityNode = makeNode('identity', signedProof.signature.address);
144
+ const subjectNode = makeNode('subject', signedProof.subject.id);
145
+ const newNodes = [proofNode, identityNode, subjectNode];
146
+ const newEdges = [
147
+ makeEdge('proves', signedProof.proofId, signedProof.subject.id, signedProof.proofId),
148
+ makeEdge('issued_by', signedProof.proofId, signedProof.signature.address, signedProof.proofId),
149
+ makeEdge('about', signedProof.proofId, signedProof.subject.id, signedProof.proofId),
150
+ ];
151
+ if (signedProof.evidence) {
152
+ for (const ev of signedProof.evidence) {
153
+ newNodes.push(makeNode('evidence', ev.id));
154
+ newEdges.push(makeEdge('references', signedProof.proofId, ev.id, signedProof.proofId));
155
+ }
156
+ }
157
+ if (signedProof.anchor) {
158
+ newNodes.push(makeNode('anchor', signedProof.anchor.hash));
159
+ newEdges.push(makeEdge('anchored_to', signedProof.proofId, signedProof.anchor.hash, signedProof.proofId));
160
+ }
161
+ return rebuild(graph, newNodes, newEdges);
162
+ }
163
+ /**
164
+ * Index a SignedIdentityClaim into the graph.
165
+ *
166
+ * Nodes created:
167
+ * identity-claim — claim.id (stores the full signed claim in .data)
168
+ * address — issuer address
169
+ * address/identity — target address (for delegates_to / rotates_to / revokes)
170
+ *
171
+ * Edges created based on claim.type:
172
+ * all types → issued_by (claim-node → issuer address)
173
+ * delegates_to → delegates_to edge (claim-node → delegated address)
174
+ * revokes → revokes edge (claim-node → subject identity)
175
+ * rotates_to → controls edge (claim-node → new address)
176
+ */
177
+ function addIdentityClaim(graph, signedClaim) {
178
+ const { claim } = signedClaim;
179
+ const claimNode = makeNode('identity-claim', claim.id, {
180
+ ...signedClaim,
181
+ });
182
+ const issuerNode = makeNode('address', claim.issuer);
183
+ const newNodes = [claimNode, issuerNode];
184
+ const newEdges = [
185
+ makeEdge('issued_by', claim.id, claim.issuer),
186
+ ];
187
+ if (claim.type === 'delegates_to') {
188
+ newNodes.push(makeNode('address', claim.object));
189
+ newEdges.push(makeEdge('delegates_to', claim.id, claim.object));
190
+ }
191
+ else if (claim.type === 'revokes') {
192
+ newNodes.push(makeNode('identity', claim.subject));
193
+ newEdges.push(makeEdge('revokes', claim.id, claim.subject));
194
+ }
195
+ else if (claim.type === 'rotates_to') {
196
+ newNodes.push(makeNode('address', claim.object));
197
+ newEdges.push(makeEdge('controls', claim.id, claim.object));
198
+ }
199
+ return rebuild(graph, newNodes, newEdges);
200
+ }
201
+ /**
202
+ * Resolve the author address from a manifest based on its type.
203
+ * AppManifest / DAppManifest → authorAddress
204
+ * CapabilityManifest → agentAddress
205
+ * EdgeServiceManifest → operatorAddress
206
+ * Falls back to signedManifest.authorAddress if the manifest type is unknown.
207
+ */
208
+ function resolveManifestAddress(signedManifest) {
209
+ const m = signedManifest.manifest;
210
+ if (m['type'] === 'capability' && typeof m['agentAddress'] === 'string') {
211
+ return m['agentAddress'];
212
+ }
213
+ if (m['type'] === 'edge-service' && typeof m['operatorAddress'] === 'string') {
214
+ return m['operatorAddress'];
215
+ }
216
+ if (typeof m['authorAddress'] === 'string') {
217
+ return m['authorAddress'];
218
+ }
219
+ return signedManifest.authorAddress;
220
+ }
221
+ /**
222
+ * Index a SignedManifest into the graph.
223
+ *
224
+ * Nodes created:
225
+ * manifest — computed manifest ID (stores manifest content in .data)
226
+ * address — resolved author/agent/operator address
227
+ *
228
+ * Edge created:
229
+ * manifests_as manifest → address
230
+ */
231
+ function addManifest(graph, signedManifest) {
232
+ const manifestId = (0, manifest_1.computeManifestId)(signedManifest.manifest);
233
+ const address = resolveManifestAddress(signedManifest);
234
+ const manifestNode = makeNode('manifest', manifestId, {
235
+ ...signedManifest,
236
+ });
237
+ const addressNode = makeNode('address', address);
238
+ return rebuild(graph, [manifestNode, addressNode], [
239
+ makeEdge('manifests_as', manifestId, address),
240
+ ]);
241
+ }
242
+ /**
243
+ * Add a receipt-like node (payment, subscription, claim receipt) to the graph.
244
+ * If receipt.proofId is set, adds a 'supports' edge from the receipt to that proof.
245
+ */
246
+ function addReceiptLike(graph, receipt) {
247
+ const { id, data, proofId } = receipt;
248
+ const receiptNode = makeNode('receipt', id, data);
249
+ const newEdges = [];
250
+ if (proofId !== undefined) {
251
+ newEdges.push(makeEdge('supports', id, proofId, proofId));
252
+ }
253
+ return rebuild(graph, [receiptNode], newEdges);
254
+ }
255
+ /**
256
+ * Add a standalone anchor node. If anchor.proofId is set, adds an 'anchored_to'
257
+ * edge from the proof to this anchor.
258
+ */
259
+ function addAnchor(graph, anchor) {
260
+ const { hash, proofId, ...rest } = anchor;
261
+ const nodeData = { ...rest };
262
+ const anchorNode = makeNode('anchor', hash, Object.keys(nodeData).length > 0 ? nodeData : undefined);
263
+ const newEdges = [];
264
+ if (proofId !== undefined) {
265
+ newEdges.push(makeEdge('anchored_to', proofId, hash, proofId));
266
+ }
267
+ return rebuild(graph, [anchorNode], newEdges);
268
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module @totemsdk/proofgraph
3
+ *
4
+ * Local deterministic proof relationship graph for Totem Edge.
5
+ *
6
+ * Indexes SignedProofs, SignedIdentityClaims, SignedManifests, identity
7
+ * documents, and custom evidence nodes into an immutable, queryable DAG
8
+ * keyed by a content-derived graphId. Pure package — no network, no DHT,
9
+ * no blockchain submission, no crypto reimplementation.
10
+ *
11
+ * Usage:
12
+ * const g0 = createProofGraph();
13
+ * const g1 = addProof(g0, signedProof);
14
+ * const result = verifyProofGraph(g1);
15
+ */
16
+ export type { ProofGraphNodeType, ProofGraphEdgeType, ProofGraphNode, ProofGraphEdge, ProofGraph, ProofGraphVerifyResult, ProofGraphStoragePort, ReceiptLikeInput, AnchorInput, } from './types.js';
17
+ export { toHex, canonicalJson, computeNodeId, computeEdgeId, computeProofGraphId, recomputeGraphId, } from './canonical.js';
18
+ export { createProofGraph, setGraphMetadata, buildEdge, addNode, addEdge, addIdentityDocument, addProof, addIdentityClaim, addManifest, addReceiptLike, addAnchor, } from './graph.js';
19
+ export { findNode, getEdgesFrom, getEdgesTo, getEdgesByType, getProofNodes, findProofsBySubject, findProofsByIssuer, findAnchorsForProof, findRevocations, findSupersessions, findConflicts, getEvidenceTrail, getProofLineage, resolveCurrentProofSet, getManifestsForAddress, getEdgesBetween, reachableFrom, } from './query.js';
20
+ export { verifyProofGraph, verifyGraphProofs, } from './verify.js';
21
+ export { exportProofGraph, importProofGraph, } from './io.js';
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * @module @totemsdk/proofgraph
4
+ *
5
+ * Local deterministic proof relationship graph for Totem Edge.
6
+ *
7
+ * Indexes SignedProofs, SignedIdentityClaims, SignedManifests, identity
8
+ * documents, and custom evidence nodes into an immutable, queryable DAG
9
+ * keyed by a content-derived graphId. Pure package — no network, no DHT,
10
+ * no blockchain submission, no crypto reimplementation.
11
+ *
12
+ * Usage:
13
+ * const g0 = createProofGraph();
14
+ * const g1 = addProof(g0, signedProof);
15
+ * const result = verifyProofGraph(g1);
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.importProofGraph = exports.exportProofGraph = exports.verifyGraphProofs = exports.verifyProofGraph = exports.reachableFrom = exports.getEdgesBetween = exports.getManifestsForAddress = exports.resolveCurrentProofSet = exports.getProofLineage = exports.getEvidenceTrail = exports.findConflicts = exports.findSupersessions = exports.findRevocations = exports.findAnchorsForProof = exports.findProofsByIssuer = exports.findProofsBySubject = exports.getProofNodes = exports.getEdgesByType = exports.getEdgesTo = exports.getEdgesFrom = exports.findNode = exports.addAnchor = exports.addReceiptLike = exports.addManifest = exports.addIdentityClaim = exports.addProof = exports.addIdentityDocument = exports.addEdge = exports.addNode = exports.buildEdge = exports.setGraphMetadata = exports.createProofGraph = exports.recomputeGraphId = exports.computeProofGraphId = exports.computeEdgeId = exports.computeNodeId = exports.canonicalJson = exports.toHex = void 0;
19
+ var canonical_js_1 = require("./canonical.js");
20
+ Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return canonical_js_1.toHex; } });
21
+ Object.defineProperty(exports, "canonicalJson", { enumerable: true, get: function () { return canonical_js_1.canonicalJson; } });
22
+ Object.defineProperty(exports, "computeNodeId", { enumerable: true, get: function () { return canonical_js_1.computeNodeId; } });
23
+ Object.defineProperty(exports, "computeEdgeId", { enumerable: true, get: function () { return canonical_js_1.computeEdgeId; } });
24
+ Object.defineProperty(exports, "computeProofGraphId", { enumerable: true, get: function () { return canonical_js_1.computeProofGraphId; } });
25
+ Object.defineProperty(exports, "recomputeGraphId", { enumerable: true, get: function () { return canonical_js_1.recomputeGraphId; } });
26
+ var graph_js_1 = require("./graph.js");
27
+ Object.defineProperty(exports, "createProofGraph", { enumerable: true, get: function () { return graph_js_1.createProofGraph; } });
28
+ Object.defineProperty(exports, "setGraphMetadata", { enumerable: true, get: function () { return graph_js_1.setGraphMetadata; } });
29
+ Object.defineProperty(exports, "buildEdge", { enumerable: true, get: function () { return graph_js_1.buildEdge; } });
30
+ Object.defineProperty(exports, "addNode", { enumerable: true, get: function () { return graph_js_1.addNode; } });
31
+ Object.defineProperty(exports, "addEdge", { enumerable: true, get: function () { return graph_js_1.addEdge; } });
32
+ Object.defineProperty(exports, "addIdentityDocument", { enumerable: true, get: function () { return graph_js_1.addIdentityDocument; } });
33
+ Object.defineProperty(exports, "addProof", { enumerable: true, get: function () { return graph_js_1.addProof; } });
34
+ Object.defineProperty(exports, "addIdentityClaim", { enumerable: true, get: function () { return graph_js_1.addIdentityClaim; } });
35
+ Object.defineProperty(exports, "addManifest", { enumerable: true, get: function () { return graph_js_1.addManifest; } });
36
+ Object.defineProperty(exports, "addReceiptLike", { enumerable: true, get: function () { return graph_js_1.addReceiptLike; } });
37
+ Object.defineProperty(exports, "addAnchor", { enumerable: true, get: function () { return graph_js_1.addAnchor; } });
38
+ var query_js_1 = require("./query.js");
39
+ Object.defineProperty(exports, "findNode", { enumerable: true, get: function () { return query_js_1.findNode; } });
40
+ Object.defineProperty(exports, "getEdgesFrom", { enumerable: true, get: function () { return query_js_1.getEdgesFrom; } });
41
+ Object.defineProperty(exports, "getEdgesTo", { enumerable: true, get: function () { return query_js_1.getEdgesTo; } });
42
+ Object.defineProperty(exports, "getEdgesByType", { enumerable: true, get: function () { return query_js_1.getEdgesByType; } });
43
+ Object.defineProperty(exports, "getProofNodes", { enumerable: true, get: function () { return query_js_1.getProofNodes; } });
44
+ Object.defineProperty(exports, "findProofsBySubject", { enumerable: true, get: function () { return query_js_1.findProofsBySubject; } });
45
+ Object.defineProperty(exports, "findProofsByIssuer", { enumerable: true, get: function () { return query_js_1.findProofsByIssuer; } });
46
+ Object.defineProperty(exports, "findAnchorsForProof", { enumerable: true, get: function () { return query_js_1.findAnchorsForProof; } });
47
+ Object.defineProperty(exports, "findRevocations", { enumerable: true, get: function () { return query_js_1.findRevocations; } });
48
+ Object.defineProperty(exports, "findSupersessions", { enumerable: true, get: function () { return query_js_1.findSupersessions; } });
49
+ Object.defineProperty(exports, "findConflicts", { enumerable: true, get: function () { return query_js_1.findConflicts; } });
50
+ Object.defineProperty(exports, "getEvidenceTrail", { enumerable: true, get: function () { return query_js_1.getEvidenceTrail; } });
51
+ Object.defineProperty(exports, "getProofLineage", { enumerable: true, get: function () { return query_js_1.getProofLineage; } });
52
+ Object.defineProperty(exports, "resolveCurrentProofSet", { enumerable: true, get: function () { return query_js_1.resolveCurrentProofSet; } });
53
+ Object.defineProperty(exports, "getManifestsForAddress", { enumerable: true, get: function () { return query_js_1.getManifestsForAddress; } });
54
+ Object.defineProperty(exports, "getEdgesBetween", { enumerable: true, get: function () { return query_js_1.getEdgesBetween; } });
55
+ Object.defineProperty(exports, "reachableFrom", { enumerable: true, get: function () { return query_js_1.reachableFrom; } });
56
+ var verify_js_1 = require("./verify.js");
57
+ Object.defineProperty(exports, "verifyProofGraph", { enumerable: true, get: function () { return verify_js_1.verifyProofGraph; } });
58
+ Object.defineProperty(exports, "verifyGraphProofs", { enumerable: true, get: function () { return verify_js_1.verifyGraphProofs; } });
59
+ var io_js_1 = require("./io.js");
60
+ Object.defineProperty(exports, "exportProofGraph", { enumerable: true, get: function () { return io_js_1.exportProofGraph; } });
61
+ Object.defineProperty(exports, "importProofGraph", { enumerable: true, get: function () { return io_js_1.importProofGraph; } });
package/dist/io.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Serialization helpers for ProofGraph.
3
+ *
4
+ * exportProofGraph: JSON-stringify the graph for storage or transport.
5
+ * importProofGraph: parse JSON, recompute graphId, throw if it doesn't match.
6
+ *
7
+ * The graphId guards against silent corruption in transit.
8
+ */
9
+ import type { ProofGraph } from './types.js';
10
+ /**
11
+ * Serialize a ProofGraph to a JSON string.
12
+ * The stored graphId was computed at mutation time and is included as-is.
13
+ */
14
+ export declare function exportProofGraph(graph: ProofGraph): string;
15
+ /**
16
+ * Deserialize a ProofGraph from a JSON string.
17
+ *
18
+ * Recomputes the graphId from nodes + edges. Throws if the recomputed value
19
+ * does not match the stored graphId — indicates tampering or data corruption.
20
+ *
21
+ * @throws Error if graphId verification fails.
22
+ */
23
+ export declare function importProofGraph(json: string): ProofGraph;
package/dist/io.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * Serialization helpers for ProofGraph.
4
+ *
5
+ * exportProofGraph: JSON-stringify the graph for storage or transport.
6
+ * importProofGraph: parse JSON, recompute graphId, throw if it doesn't match.
7
+ *
8
+ * The graphId guards against silent corruption in transit.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.exportProofGraph = exportProofGraph;
12
+ exports.importProofGraph = importProofGraph;
13
+ const canonical_js_1 = require("./canonical.js");
14
+ /**
15
+ * Serialize a ProofGraph to a JSON string.
16
+ * The stored graphId was computed at mutation time and is included as-is.
17
+ */
18
+ function exportProofGraph(graph) {
19
+ return JSON.stringify(graph);
20
+ }
21
+ /**
22
+ * Deserialize a ProofGraph from a JSON string.
23
+ *
24
+ * Recomputes the graphId from nodes + edges. Throws if the recomputed value
25
+ * does not match the stored graphId — indicates tampering or data corruption.
26
+ *
27
+ * @throws Error if graphId verification fails.
28
+ */
29
+ function importProofGraph(json) {
30
+ let parsed;
31
+ try {
32
+ parsed = JSON.parse(json);
33
+ }
34
+ catch (err) {
35
+ throw new Error(`importProofGraph: invalid JSON — ${err.message}`);
36
+ }
37
+ const graph = parsed;
38
+ if (!graph || typeof graph !== 'object') {
39
+ throw new Error('importProofGraph: parsed value is not an object');
40
+ }
41
+ if (!Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
42
+ throw new Error('importProofGraph: missing nodes or edges arrays');
43
+ }
44
+ const recomputed = (0, canonical_js_1.recomputeGraphId)(graph);
45
+ if (recomputed !== graph.graphId) {
46
+ throw new Error(`importProofGraph: graphId mismatch — stored="${graph.graphId}" recomputed="${recomputed}"`);
47
+ }
48
+ return graph;
49
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Query helpers for ProofGraph — pure read-only utilities.
3
+ *
4
+ * All functions receive a ProofGraph and return data without mutating the graph.
5
+ * Function names match the @totemsdk/proofgraph public API spec exactly.
6
+ */
7
+ import type { ProofGraph, ProofGraphNode, ProofGraphEdge, ProofGraphEdgeType } from './types.js';
8
+ /**
9
+ * Find a node by its composed node ID (type:refId) or by refId alone.
10
+ */
11
+ export declare function findNode(graph: ProofGraph, id: string): ProofGraphNode | undefined;
12
+ /**
13
+ * Return all outgoing edges from a node (identified by node ID or refId).
14
+ */
15
+ export declare function getEdgesFrom(graph: ProofGraph, nodeIdOrRefId: string): ProofGraphEdge[];
16
+ /**
17
+ * Return all incoming edges to a node (identified by node ID or refId).
18
+ */
19
+ export declare function getEdgesTo(graph: ProofGraph, nodeIdOrRefId: string): ProofGraphEdge[];
20
+ /**
21
+ * Return all edges of a given type.
22
+ */
23
+ export declare function getEdgesByType(graph: ProofGraph, type: ProofGraphEdgeType): ProofGraphEdge[];
24
+ /**
25
+ * Return all proof nodes in the graph.
26
+ */
27
+ export declare function getProofNodes(graph: ProofGraph): ProofGraphNode[];
28
+ /**
29
+ * Find all 'proof' nodes connected to a subject via 'about' OR 'proves' edges.
30
+ */
31
+ export declare function findProofsBySubject(graph: ProofGraph, subjectId: string): ProofGraphNode[];
32
+ /**
33
+ * Find all 'proof' nodes issued by a given address (via 'issued_by' edges).
34
+ */
35
+ export declare function findProofsByIssuer(graph: ProofGraph, issuerId: string): ProofGraphNode[];
36
+ /**
37
+ * Find all 'anchor' nodes linked to a proof via 'anchored_to' edges.
38
+ */
39
+ export declare function findAnchorsForProof(graph: ProofGraph, proofId: string): ProofGraphNode[];
40
+ /**
41
+ * Find all 'revokes' edges whose target is the given proof node.
42
+ */
43
+ export declare function findRevocations(graph: ProofGraph, proofId: string): ProofGraphEdge[];
44
+ /**
45
+ * Find all 'supersedes' edges whose target is the given proof node.
46
+ */
47
+ export declare function findSupersessions(graph: ProofGraph, proofId: string): ProofGraphEdge[];
48
+ /**
49
+ * Find all 'conflicts_with' edges involving the given proof node (in either direction).
50
+ */
51
+ export declare function findConflicts(graph: ProofGraph, proofId: string): ProofGraphEdge[];
52
+ /**
53
+ * Traverse 'references' edges from a proof to its evidence nodes.
54
+ * Returns nodes in insertion order (the order edges were added, which matches
55
+ * the original evidence array order from addProof).
56
+ */
57
+ export declare function getEvidenceTrail(graph: ProofGraph, proofId: string): ProofGraphNode[];
58
+ /**
59
+ * Recursively traverse 'derived_from' edges from a proof node.
60
+ * Returns the ordered chain of ancestor proof nodes (closest ancestor first).
61
+ * Terminates on cycle detection.
62
+ */
63
+ export declare function getProofLineage(graph: ProofGraph, proofId: string, _visited?: Set<string>): ProofGraphNode[];
64
+ /**
65
+ * Return all proof nodes that are NOT the target of any 'revokes' or 'supersedes' edge.
66
+ * These are the current / active proofs in the graph.
67
+ */
68
+ export declare function resolveCurrentProofSet(graph: ProofGraph): ProofGraphNode[];
69
+ /**
70
+ * Return all manifest nodes linked to a given address via 'manifests_as' edges.
71
+ */
72
+ export declare function getManifestsForAddress(graph: ProofGraph, address: string): ProofGraphNode[];
73
+ /**
74
+ * Return all edges between two nodes (in either direction).
75
+ */
76
+ export declare function getEdgesBetween(graph: ProofGraph, refIdA: string, refIdB: string): ProofGraphEdge[];
77
+ /**
78
+ * Return the set of all node refIds reachable from a given node via directed edges.
79
+ * Includes the start node itself.
80
+ */
81
+ export declare function reachableFrom(graph: ProofGraph, startRefId: string, _visited?: Set<string>): Set<string>;
package/dist/query.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ /**
3
+ * Query helpers for ProofGraph — pure read-only utilities.
4
+ *
5
+ * All functions receive a ProofGraph and return data without mutating the graph.
6
+ * Function names match the @totemsdk/proofgraph public API spec exactly.
7
+ */
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
+ /**
27
+ * Find a node by its composed node ID (type:refId) or by refId alone.
28
+ */
29
+ function findNode(graph, id) {
30
+ return graph.nodes.find((n) => n.id === id || n.refId === id);
31
+ }
32
+ /**
33
+ * Return all outgoing edges from a node (identified by node ID or refId).
34
+ */
35
+ function getEdgesFrom(graph, nodeIdOrRefId) {
36
+ const node = findNode(graph, nodeIdOrRefId);
37
+ if (!node)
38
+ return [];
39
+ return graph.edges.filter((e) => e.from === node.refId);
40
+ }
41
+ /**
42
+ * Return all incoming edges to a node (identified by node ID or refId).
43
+ */
44
+ function getEdgesTo(graph, nodeIdOrRefId) {
45
+ const node = findNode(graph, nodeIdOrRefId);
46
+ if (!node)
47
+ return [];
48
+ return graph.edges.filter((e) => e.to === node.refId);
49
+ }
50
+ /**
51
+ * Return all edges of a given type.
52
+ */
53
+ function getEdgesByType(graph, type) {
54
+ return graph.edges.filter((e) => e.type === type);
55
+ }
56
+ /**
57
+ * Return all proof nodes in the graph.
58
+ */
59
+ function getProofNodes(graph) {
60
+ return graph.nodes.filter((n) => n.type === 'proof');
61
+ }
62
+ /**
63
+ * Find all 'proof' nodes connected to a subject via 'about' OR 'proves' edges.
64
+ */
65
+ function findProofsBySubject(graph, subjectId) {
66
+ const relevantEdges = graph.edges.filter((e) => (e.type === 'about' || e.type === 'proves') && e.to === subjectId);
67
+ const proofRefIds = new Set(relevantEdges.map((e) => e.from));
68
+ return graph.nodes.filter((n) => proofRefIds.has(n.refId) && n.type === 'proof');
69
+ }
70
+ /**
71
+ * Find all 'proof' nodes issued by a given address (via 'issued_by' edges).
72
+ */
73
+ function findProofsByIssuer(graph, issuerId) {
74
+ const issuedEdges = graph.edges.filter((e) => e.type === 'issued_by' && e.to === issuerId);
75
+ const proofRefIds = new Set(issuedEdges.map((e) => e.from));
76
+ return graph.nodes.filter((n) => proofRefIds.has(n.refId) && n.type === 'proof');
77
+ }
78
+ /**
79
+ * Find all 'anchor' nodes linked to a proof via 'anchored_to' edges.
80
+ */
81
+ function findAnchorsForProof(graph, proofId) {
82
+ const anchoredEdges = graph.edges.filter((e) => e.type === 'anchored_to' && e.from === proofId);
83
+ const anchorRefIds = new Set(anchoredEdges.map((e) => e.to));
84
+ return graph.nodes.filter((n) => anchorRefIds.has(n.refId) && n.type === 'anchor');
85
+ }
86
+ /**
87
+ * Find all 'revokes' edges whose target is the given proof node.
88
+ */
89
+ function findRevocations(graph, proofId) {
90
+ return graph.edges.filter((e) => e.type === 'revokes' && e.to === proofId);
91
+ }
92
+ /**
93
+ * Find all 'supersedes' edges whose target is the given proof node.
94
+ */
95
+ function findSupersessions(graph, proofId) {
96
+ return graph.edges.filter((e) => e.type === 'supersedes' && e.to === proofId);
97
+ }
98
+ /**
99
+ * Find all 'conflicts_with' edges involving the given proof node (in either direction).
100
+ */
101
+ function findConflicts(graph, proofId) {
102
+ return graph.edges.filter((e) => e.type === 'conflicts_with' &&
103
+ (e.from === proofId || e.to === proofId));
104
+ }
105
+ /**
106
+ * Traverse 'references' edges from a proof to its evidence nodes.
107
+ * Returns nodes in insertion order (the order edges were added, which matches
108
+ * the original evidence array order from addProof).
109
+ */
110
+ function getEvidenceTrail(graph, proofId) {
111
+ const refEdges = graph.edges.filter((e) => e.type === 'references' && e.from === proofId);
112
+ return refEdges
113
+ .map((e) => graph.nodes.find((n) => n.refId === e.to && n.type === 'evidence'))
114
+ .filter((n) => n !== undefined);
115
+ }
116
+ /**
117
+ * Recursively traverse 'derived_from' edges from a proof node.
118
+ * Returns the ordered chain of ancestor proof nodes (closest ancestor first).
119
+ * Terminates on cycle detection.
120
+ */
121
+ function getProofLineage(graph, proofId, _visited = new Set()) {
122
+ if (_visited.has(proofId))
123
+ return [];
124
+ _visited.add(proofId);
125
+ const derivedEdges = graph.edges.filter((e) => e.type === 'derived_from' && e.from === proofId);
126
+ const result = [];
127
+ for (const edge of derivedEdges) {
128
+ const node = graph.nodes.find((n) => n.refId === edge.to);
129
+ if (node) {
130
+ result.push(node);
131
+ result.push(...getProofLineage(graph, edge.to, _visited));
132
+ }
133
+ }
134
+ return result;
135
+ }
136
+ /**
137
+ * Return all proof nodes that are NOT the target of any 'revokes' or 'supersedes' edge.
138
+ * These are the current / active proofs in the graph.
139
+ */
140
+ function resolveCurrentProofSet(graph) {
141
+ const supersededOrRevoked = new Set();
142
+ for (const edge of graph.edges) {
143
+ if (edge.type === 'revokes' || edge.type === 'supersedes') {
144
+ supersededOrRevoked.add(edge.to);
145
+ }
146
+ }
147
+ return graph.nodes.filter((n) => n.type === 'proof' && !supersededOrRevoked.has(n.refId));
148
+ }
149
+ /**
150
+ * Return all manifest nodes linked to a given address via 'manifests_as' edges.
151
+ */
152
+ function getManifestsForAddress(graph, address) {
153
+ const manifestEdges = graph.edges.filter((e) => e.type === 'manifests_as' && e.to === address);
154
+ const manifestRefIds = new Set(manifestEdges.map((e) => e.from));
155
+ return graph.nodes.filter((n) => manifestRefIds.has(n.refId) && n.type === 'manifest');
156
+ }
157
+ /**
158
+ * Return all edges between two nodes (in either direction).
159
+ */
160
+ function getEdgesBetween(graph, refIdA, refIdB) {
161
+ return graph.edges.filter((e) => (e.from === refIdA && e.to === refIdB) ||
162
+ (e.from === refIdB && e.to === refIdA));
163
+ }
164
+ /**
165
+ * Return the set of all node refIds reachable from a given node via directed edges.
166
+ * Includes the start node itself.
167
+ */
168
+ function reachableFrom(graph, startRefId, _visited = new Set()) {
169
+ if (_visited.has(startRefId))
170
+ return _visited;
171
+ _visited.add(startRefId);
172
+ const outgoing = graph.edges.filter((e) => e.from === startRefId);
173
+ for (const edge of outgoing) {
174
+ reachableFrom(graph, edge.to, _visited);
175
+ }
176
+ return _visited;
177
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @totemsdk/proofgraph — Type definitions
3
+ *
4
+ * Pure schema — no network, no DHT, no blockchain submission, no crypto.
5
+ */
6
+ export type ProofGraphNodeType = 'proof' | 'identity' | 'identity-claim' | 'manifest' | 'address' | 'subject' | 'evidence' | 'anchor' | 'receipt' | 'payment' | 'device' | 'service' | 'policy' | 'custom';
7
+ export type ProofGraphEdgeType = 'proves' | 'issued_by' | 'signed_by' | 'about' | 'references' | 'derived_from' | 'supports' | 'contradicts' | 'supersedes' | 'revokes' | 'anchored_to' | 'delegates_to' | 'controls' | 'depends_on' | 'manifests_as' | 'conflicts_with';
8
+ export interface ProofGraphNode {
9
+ id: string;
10
+ type: ProofGraphNodeType;
11
+ refId: string;
12
+ data?: Record<string, unknown>;
13
+ createdAt: number;
14
+ }
15
+ export interface ProofGraphEdge {
16
+ id: string;
17
+ type: ProofGraphEdgeType;
18
+ from: string;
19
+ to: string;
20
+ proofId?: string;
21
+ data?: Record<string, unknown>;
22
+ }
23
+ export interface ProofGraph {
24
+ graphId: string;
25
+ nodes: ProofGraphNode[];
26
+ edges: ProofGraphEdge[];
27
+ createdAt: number;
28
+ metadata?: Record<string, unknown>;
29
+ }
30
+ export interface ProofGraphVerifyResult {
31
+ valid: boolean;
32
+ invalidProofs: string[];
33
+ reason?: string;
34
+ }
35
+ /**
36
+ * Input object for addReceiptLike.
37
+ */
38
+ export interface ReceiptLikeInput {
39
+ id: string;
40
+ data?: Record<string, unknown>;
41
+ proofId?: string;
42
+ }
43
+ /**
44
+ * Input object for addAnchor.
45
+ */
46
+ export interface AnchorInput {
47
+ hash: string;
48
+ provider?: string;
49
+ txId?: string;
50
+ confirmedAt?: number;
51
+ metadata?: Record<string, unknown>;
52
+ proofId?: string;
53
+ }
54
+ /**
55
+ * Storage port — interface only, no concrete implementation in this package.
56
+ * Adapters (SQLite, LevelDB, in-memory) live in consumer packages.
57
+ */
58
+ export interface ProofGraphStoragePort {
59
+ save(graph: ProofGraph): Promise<void>;
60
+ load(graphId: string): Promise<ProofGraph | null>;
61
+ findByNodeId(id: string): Promise<ProofGraph | null>;
62
+ }
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @totemsdk/proofgraph — Type definitions
4
+ *
5
+ * Pure schema — no network, no DHT, no blockchain submission, no crypto.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Graph-level verification.
3
+ *
4
+ * verifyProofGraph: iterates proof nodes, recovers SignedProof from node.data,
5
+ * and delegates to @totemsdk/proof's verifyProof for each one.
6
+ * Never reimplements cryptography.
7
+ *
8
+ * verifyGraphProofs: same logic, returns the list of invalid proof IDs (string[]).
9
+ */
10
+ import type { ProofGraph, ProofGraphVerifyResult } from './types.js';
11
+ /**
12
+ * Verify every proof node stored in the graph.
13
+ *
14
+ * Iterates nodes of type 'proof', casts node.data back to SignedProof,
15
+ * and calls proofModule.verifyProof() from @totemsdk/proof.
16
+ * Returns { valid: true } if ALL proofs pass; otherwise lists the failing proofIds.
17
+ */
18
+ export declare function verifyProofGraph(graph: ProofGraph, _options?: Record<string, unknown>): ProofGraphVerifyResult;
19
+ /**
20
+ * Returns the list of invalid proof IDs in the graph.
21
+ * Equivalent to verifyProofGraph(graph).invalidProofs.
22
+ */
23
+ export declare function verifyGraphProofs(graph: ProofGraph): string[];
package/dist/verify.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Graph-level verification.
4
+ *
5
+ * verifyProofGraph: iterates proof nodes, recovers SignedProof from node.data,
6
+ * and delegates to @totemsdk/proof's verifyProof for each one.
7
+ * Never reimplements cryptography.
8
+ *
9
+ * verifyGraphProofs: same logic, returns the list of invalid proof IDs (string[]).
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.verifyProofGraph = verifyProofGraph;
46
+ exports.verifyGraphProofs = verifyGraphProofs;
47
+ const proofModule = __importStar(require("@totemsdk/proof"));
48
+ /**
49
+ * Verify every proof node stored in the graph.
50
+ *
51
+ * Iterates nodes of type 'proof', casts node.data back to SignedProof,
52
+ * and calls proofModule.verifyProof() from @totemsdk/proof.
53
+ * Returns { valid: true } if ALL proofs pass; otherwise lists the failing proofIds.
54
+ */
55
+ function verifyProofGraph(graph, _options) {
56
+ const invalidProofs = [];
57
+ for (const node of graph.nodes) {
58
+ if (node.type !== 'proof' || !node.data)
59
+ continue;
60
+ const signedProof = node.data;
61
+ const result = proofModule.verifyProof(signedProof);
62
+ if (!result.valid) {
63
+ invalidProofs.push(node.refId);
64
+ }
65
+ }
66
+ return {
67
+ valid: invalidProofs.length === 0,
68
+ invalidProofs,
69
+ };
70
+ }
71
+ /**
72
+ * Returns the list of invalid proof IDs in the graph.
73
+ * Equivalent to verifyProofGraph(graph).invalidProofs.
74
+ */
75
+ function verifyGraphProofs(graph) {
76
+ return verifyProofGraph(graph).invalidProofs;
77
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@totemsdk/proofgraph",
3
+ "version": "0.1.0",
4
+ "description": "Local deterministic proof relationship graph for Totem Edge — indexes proofs, identities, manifests, and subjects into a queryable DAG",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "dependencies": {
20
+ "@totemsdk/proof": "0.1.0",
21
+ "@totemsdk/core": "1.1.0",
22
+ "@totemsdk/manifest": "0.1.2",
23
+ "@totemsdk/identity": "0.1.2"
24
+ },
25
+ "peerDependencies": {
26
+ "@noble/hashes": "^2.0.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "@noble/hashes": {
30
+ "optional": false
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@noble/hashes": "^2.2.0",
35
+ "@types/jest": "^29.0.0",
36
+ "@types/node": "^20.0.0",
37
+ "jest": "^29.0.0",
38
+ "ts-jest": "^29.0.0",
39
+ "typescript": "^5.0.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "license": "MIT",
48
+ "author": "Totem SDK",
49
+ "homepage": "https://totemsdk.com",
50
+ "keywords": [
51
+ "totem",
52
+ "totemsdk",
53
+ "minima",
54
+ "proof",
55
+ "graph",
56
+ "dag",
57
+ "identity"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsc",
61
+ "clean": "rm -rf dist",
62
+ "test": "jest --passWithNoTests"
63
+ }
64
+ }