@totemsdk/proofgraph 1.0.1 → 1.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.
Files changed (44) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +60 -0
  3. package/README.md +1 -1
  4. package/dist/canonical.js +11 -19
  5. package/dist/cjs/canonical.d.ts +22 -0
  6. package/dist/cjs/canonical.js +51 -0
  7. package/dist/cjs/durable-store.d.ts +50 -0
  8. package/dist/cjs/durable-store.js +178 -0
  9. package/dist/cjs/evidence.d.ts +89 -0
  10. package/dist/cjs/evidence.js +130 -0
  11. package/dist/cjs/graph.d.ts +103 -0
  12. package/dist/cjs/graph.js +298 -0
  13. package/dist/cjs/index.d.ts +26 -0
  14. package/dist/cjs/index.js +84 -0
  15. package/dist/cjs/io.d.ts +26 -0
  16. package/dist/cjs/io.js +173 -0
  17. package/dist/cjs/package.json +1 -0
  18. package/dist/cjs/query.d.ts +85 -0
  19. package/dist/cjs/query.js +189 -0
  20. package/dist/cjs/replicated-evidence.d.ts +42 -0
  21. package/dist/cjs/replicated-evidence.js +98 -0
  22. package/dist/cjs/types.d.ts +62 -0
  23. package/dist/cjs/types.js +7 -0
  24. package/dist/cjs/verify.d.ts +23 -0
  25. package/dist/cjs/verify.js +77 -0
  26. package/dist/durable-store.js +9 -12
  27. package/dist/evidence.js +14 -19
  28. package/dist/graph.d.ts +11 -0
  29. package/dist/graph.js +47 -34
  30. package/dist/index.d.ts +3 -2
  31. package/dist/index.js +8 -52
  32. package/dist/io.js +4 -8
  33. package/dist/query.d.ts +4 -0
  34. package/dist/query.js +28 -36
  35. package/dist/replicated-evidence.d.ts +42 -0
  36. package/dist/replicated-evidence.js +95 -0
  37. package/dist/types.d.ts +1 -1
  38. package/dist/types.js +1 -2
  39. package/dist/verify.js +3 -40
  40. package/package.json +21 -14
  41. package/rust/pkg/package.json +2 -2
  42. package/rust/pkg/proofgraph_wasm_bg.wasm +0 -0
  43. package/rust/pkg-node/package.json +2 -2
  44. package/rust/pkg-node/proofgraph_wasm_bg.wasm +0 -0
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
- 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 = exports.normalizeEvidenceHash = exports.assertEvidenceBinding = exports.createProofGraphEvidenceStore = exports.createDurableProofGraphStore = void 0;
19
- var durable_store_js_1 = require("./durable-store.js");
20
- Object.defineProperty(exports, "createDurableProofGraphStore", { enumerable: true, get: function () { return durable_store_js_1.createDurableProofGraphStore; } });
21
- var evidence_js_1 = require("./evidence.js");
22
- Object.defineProperty(exports, "createProofGraphEvidenceStore", { enumerable: true, get: function () { return evidence_js_1.createProofGraphEvidenceStore; } });
23
- Object.defineProperty(exports, "assertEvidenceBinding", { enumerable: true, get: function () { return evidence_js_1.assertEvidenceBinding; } });
24
- Object.defineProperty(exports, "normalizeEvidenceHash", { enumerable: true, get: function () { return evidence_js_1.normalizeEvidenceHash; } });
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
- Object.defineProperty(exports, "__esModule", { value: true });
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 = (0, canonical_js_1.recomputeGraphId)(graph);
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,38 +1,19 @@
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 [];
@@ -41,7 +22,7 @@ function getEdgesFrom(graph, nodeIdOrRefId) {
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 [];
@@ -50,19 +31,19 @@ function getEdgesTo(graph, nodeIdOrRefId) {
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);
@@ -0,0 +1,42 @@
1
+ /**
2
+ * RFC-057 Phase 4 — replicated proofgraph evidence adapter.
3
+ *
4
+ * Keeps the authoritative proofgraph evidence store local while allowing a
5
+ * replicated index to locate the same digest-verified artifacts on other
6
+ * peers. The replicated index is never trusted for bytes: every read
7
+ * re-verifies the artifact digest.
8
+ */
9
+ import type { ArtifactRef, ArtifactStore } from '@totemsdk/storage/artifacts';
10
+ import type { ProofGraph } from './types.js';
11
+ export interface ReplicatedEvidenceIndexEntry {
12
+ readonly nodeId: string;
13
+ readonly ref: ArtifactRef;
14
+ readonly contentHash: string;
15
+ readonly storedAt: number;
16
+ }
17
+ export interface ReplicatedEvidenceIndexPort {
18
+ get(key: string): Promise<unknown | null>;
19
+ put(key: string, value: unknown): Promise<void>;
20
+ list?(prefix?: string): AsyncIterable<{
21
+ key: string;
22
+ value: unknown;
23
+ }>;
24
+ }
25
+ export interface ReplicatedEvidenceRead {
26
+ readonly nodeId: string;
27
+ readonly status: 'ok' | 'not-found' | 'corrupt' | 'unavailable';
28
+ readonly ref?: ArtifactRef;
29
+ readonly bytes?: Uint8Array;
30
+ readonly message?: string;
31
+ }
32
+ export interface ReplicatedProofGraphEvidenceStore {
33
+ putEvidence(graph: ProofGraph, bytesFor: (nodeId: string) => Uint8Array | undefined): Promise<ArtifactRef[]>;
34
+ getEvidence(nodeId: string): Promise<ReplicatedEvidenceRead>;
35
+ verifyEvidence(nodeId: string): Promise<boolean>;
36
+ listEvidence(): AsyncIterable<ReplicatedEvidenceIndexEntry>;
37
+ }
38
+ export declare function createReplicatedProofGraphEvidenceStore(options: {
39
+ artifacts: ArtifactStore;
40
+ index: ReplicatedEvidenceIndexPort;
41
+ namespace?: string;
42
+ }): ReplicatedProofGraphEvidenceStore;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * RFC-057 Phase 4 — replicated proofgraph evidence adapter.
3
+ *
4
+ * Keeps the authoritative proofgraph evidence store local while allowing a
5
+ * replicated index to locate the same digest-verified artifacts on other
6
+ * peers. The replicated index is never trusted for bytes: every read
7
+ * re-verifies the artifact digest.
8
+ */
9
+ import { sha3_256, toHex } from '@totemsdk/core';
10
+ import { StorageError } from '@totemsdk/storage/errors';
11
+ const KEY_PREFIX = 'proofgraph:evidence:';
12
+ const DEFAULT_NAMESPACE = 'totem-proofgraph-evidence';
13
+ function normalizeHash(value) {
14
+ return value.replace(/^0x/i, '').toLowerCase();
15
+ }
16
+ function evidenceNodes(graph) {
17
+ return graph.nodes.filter((node) => node.type === 'evidence');
18
+ }
19
+ function contentHashOf(node) {
20
+ const value = node.data?.contentHash;
21
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
22
+ }
23
+ export function createReplicatedProofGraphEvidenceStore(options) {
24
+ if (!options.artifacts.capabilities.writable) {
25
+ throw new Error('replicated evidence store requires a writable artifact store');
26
+ }
27
+ const namespace = options.namespace ?? DEFAULT_NAMESPACE;
28
+ const key = (nodeId) => `${KEY_PREFIX}${nodeId}`;
29
+ return {
30
+ async putEvidence(graph, bytesFor) {
31
+ const refs = [];
32
+ for (const node of evidenceNodes(graph)) {
33
+ const bytes = bytesFor(node.id);
34
+ if (!bytes)
35
+ continue;
36
+ const digest = toHex(sha3_256(bytes));
37
+ const contentHash = contentHashOf(node);
38
+ if (contentHash && normalizeHash(contentHash) !== digest) {
39
+ throw new StorageError(`evidence commitment mismatch for node "${node.id}"`, 'corrupt', {
40
+ key: key(node.id),
41
+ });
42
+ }
43
+ const receipt = await options.artifacts.put(namespace, bytes);
44
+ if (contentHash && normalizeHash(contentHash) !== receipt.ref.digest) {
45
+ throw new StorageError(`artifact digest mismatch for node "${node.id}"`, 'corrupt', {
46
+ key: key(node.id),
47
+ });
48
+ }
49
+ await options.index.put(key(node.id), {
50
+ nodeId: node.id,
51
+ ref: receipt.ref,
52
+ contentHash: contentHash ?? receipt.ref.digest,
53
+ storedAt: Date.now(),
54
+ });
55
+ refs.push(receipt.ref);
56
+ }
57
+ return refs;
58
+ },
59
+ async getEvidence(nodeId) {
60
+ const raw = await options.index.get(key(nodeId));
61
+ if (!raw)
62
+ return { nodeId, status: 'not-found' };
63
+ const entry = raw;
64
+ const read = await options.artifacts.get(entry.ref);
65
+ if (read.status !== 'ok' || !read.bytes) {
66
+ return {
67
+ nodeId,
68
+ status: read.status,
69
+ ref: entry.ref,
70
+ ...(read.message ? { message: read.message } : {}),
71
+ };
72
+ }
73
+ const digest = toHex(sha3_256(read.bytes));
74
+ if (normalizeHash(entry.contentHash) !== digest) {
75
+ return {
76
+ nodeId,
77
+ status: 'corrupt',
78
+ ref: entry.ref,
79
+ message: `evidence digest mismatch: ${digest} !== ${entry.contentHash}`,
80
+ };
81
+ }
82
+ return { nodeId, status: 'ok', ref: entry.ref, bytes: read.bytes };
83
+ },
84
+ async verifyEvidence(nodeId) {
85
+ return (await this.getEvidence(nodeId)).status === 'ok';
86
+ },
87
+ async *listEvidence() {
88
+ if (!options.index.list)
89
+ return;
90
+ for await (const entry of options.index.list(KEY_PREFIX)) {
91
+ yield entry.value;
92
+ }
93
+ },
94
+ };
95
+ }
package/dist/types.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Pure schema — no network, no DHT, no blockchain submission, no crypto.
5
5
  */
6
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';
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' | 'revision_of' | 'conflicts_with';
8
8
  export interface ProofGraphNode {
9
9
  id: string;
10
10
  type: ProofGraphNodeType;
package/dist/types.js CHANGED
@@ -1,7 +1,6 @@
1
- "use strict";
2
1
  /**
3
2
  * @totemsdk/proofgraph — Type definitions
4
3
  *
5
4
  * Pure schema — no network, no DHT, no blockchain submission, no crypto.
6
5
  */
7
- Object.defineProperty(exports, "__esModule", { value: true });
6
+ export {};
package/dist/verify.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Graph-level verification.
4
3
  *
@@ -8,43 +7,7 @@
8
7
  *
9
8
  * verifyGraphProofs: same logic, returns the list of invalid proof IDs (string[]).
10
9
  */
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"));
10
+ import * as proofModule from '@totemsdk/proof';
48
11
  /**
49
12
  * Verify every proof node stored in the graph.
50
13
  *
@@ -52,7 +15,7 @@ const proofModule = __importStar(require("@totemsdk/proof"));
52
15
  * and calls proofModule.verifyProof() from @totemsdk/proof.
53
16
  * Returns { valid: true } if ALL proofs pass; otherwise lists the failing proofIds.
54
17
  */
55
- function verifyProofGraph(graph, _options) {
18
+ export function verifyProofGraph(graph, _options) {
56
19
  const invalidProofs = [];
57
20
  for (const node of graph.nodes) {
58
21
  if (node.type !== 'proof' || !node.data)
@@ -72,6 +35,6 @@ function verifyProofGraph(graph, _options) {
72
35
  * Returns the list of invalid proof IDs in the graph.
73
36
  * Equivalent to verifyProofGraph(graph).invalidProofs.
74
37
  */
75
- function verifyGraphProofs(graph) {
38
+ export function verifyGraphProofs(graph) {
76
39
  return verifyProofGraph(graph).invalidProofs;
77
40
  }
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@totemsdk/proofgraph",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Local deterministic proof relationship graph for Totem Edge — indexes proofs, identities, manifests, and subjects into a queryable content-addressed DAG",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "dist/cjs/index.js",
6
+ "types": "dist/cjs/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/index.d.ts",
10
- "require": "./dist/index.js",
11
- "import": "./dist/index.js"
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/cjs/index.d.ts",
15
+ "default": "./dist/cjs/index.js"
16
+ }
12
17
  }
13
18
  },
14
19
  "files": [
@@ -16,14 +21,15 @@
16
21
  "rust/pkg/",
17
22
  "rust/pkg-node/",
18
23
  "README.md",
19
- "LICENSE"
24
+ "LICENSE",
25
+ "NOTICE"
20
26
  ],
21
27
  "dependencies": {
22
- "@totemsdk/core": "^1.2.11",
23
- "@totemsdk/proof": "^1.0.0",
24
- "@totemsdk/storage": "^0.1.0",
25
- "@totemsdk/manifest": "^1.0.0",
26
- "@totemsdk/identity": "^1.0.1"
28
+ "@totemsdk/core": "^1.4.2",
29
+ "@totemsdk/proof": "^1.0.2",
30
+ "@totemsdk/storage": "^0.2.2",
31
+ "@totemsdk/identity": "^1.1.0",
32
+ "@totemsdk/manifest": "^2.1.0"
27
33
  },
28
34
  "devDependencies": {
29
35
  "@types/jest": "^30.0.0",
@@ -38,7 +44,7 @@
38
44
  "publishConfig": {
39
45
  "access": "public"
40
46
  },
41
- "license": "MIT",
47
+ "license": "Apache-2.0",
42
48
  "author": "Totem SDK",
43
49
  "homepage": "https://docs.totem.ing",
44
50
  "bugs": {
@@ -65,8 +71,9 @@
65
71
  "verification",
66
72
  "content-addressed"
67
73
  ],
74
+ "type": "module",
68
75
  "scripts": {
69
- "build": "npm run build:wasm && tsc && node ../../scripts/clean-wasm-output-ignores.mjs",
76
+ "build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
70
77
  "build:wasm": "cd rust && wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node",
71
78
  "clean": "rm -rf dist rust/pkg rust/pkg-node rust/target",
72
79
  "test": "jest"
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "description": "Local deterministic proof relationship graph — content-addressed DAG, node/edge ID computation, graph ID hashing, import/export validation (Rust/WASM)",
8
8
  "version": "0.1.0",
9
- "license": "MIT",
9
+ "license": "Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/Totem-Edge/totem-sdk"
@@ -24,4 +24,4 @@
24
24
  "./proofgraph_wasm.js",
25
25
  "./snippets/*"
26
26
  ]
27
- }
27
+ }
Binary file
@@ -5,7 +5,7 @@
5
5
  ],
6
6
  "description": "Local deterministic proof relationship graph — content-addressed DAG, node/edge ID computation, graph ID hashing, import/export validation (Rust/WASM)",
7
7
  "version": "0.1.0",
8
- "license": "MIT",
8
+ "license": "Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/Totem-Edge/totem-sdk"
@@ -18,4 +18,4 @@
18
18
  "main": "proofgraph_wasm.js",
19
19
  "homepage": "https://totem.ing",
20
20
  "types": "proofgraph_wasm.d.ts"
21
- }
21
+ }