@totemsdk/proofgraph 0.1.0 → 0.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 +21 -0
- package/README.md +246 -0
- package/package.json +16 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Totem SDK Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# @totemsdk/proofgraph
|
|
2
|
+
|
|
3
|
+
Local deterministic proof relationship graph for Totem Edge — indexes proofs, identities, manifests, anchors, and subjects into a queryable, content-addressed DAG.
|
|
4
|
+
|
|
5
|
+
No network. No storage. Pure in-memory immutable graph with SHA3-256 content addressing.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @totemsdk/proofgraph
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`@totemsdk/proofgraph` takes `SignedProof` objects (from [`@totemsdk/proof`](https://www.npmjs.com/package/@totemsdk/proof)) and builds a local relationship graph you can query and verify. Every mutation returns a new graph with a recomputed `graphId` — the ID is a deterministic SHA3-256 over node and edge content, so the same logical graph always produces the same ID regardless of when it was built.
|
|
16
|
+
|
|
17
|
+
Key properties:
|
|
18
|
+
|
|
19
|
+
- **Immutable** — every add/mutation returns a new `ProofGraph`; originals are never modified
|
|
20
|
+
- **Idempotent** — adding the same node or edge twice has no effect (deduplication by content ID)
|
|
21
|
+
- **Content-deterministic** — `graphId` excludes `createdAt` timestamps so identical content always hashes identically
|
|
22
|
+
- **Interface-only storage** — `ProofGraphStoragePort` is an interface; no concrete adapter ships in this package
|
|
23
|
+
|
|
24
|
+
## All exports
|
|
25
|
+
|
|
26
|
+
### Graph construction
|
|
27
|
+
|
|
28
|
+
| Export | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `createProofGraph()` | Create an empty graph |
|
|
31
|
+
| `setGraphMetadata(graph, metadata)` | Attach mutable metadata; recomputes `graphId` |
|
|
32
|
+
| `addProof(graph, signed)` | Add a `SignedProof` with all its linked nodes and edges |
|
|
33
|
+
| `addIdentityDocument(graph, doc)` | Add a `TotemIdentityDocument` node |
|
|
34
|
+
| `addIdentityClaim(graph, signed)` | Add a `SignedIdentityClaim` with its edge type |
|
|
35
|
+
| `addManifest(graph, signed)` | Add a `SignedManifest` with `manifests_as` address edges |
|
|
36
|
+
| `addReceiptLike(graph, receipt)` | Add a receipt node; optionally link to a proof |
|
|
37
|
+
| `addAnchor(graph, anchor)` | Add a standalone anchor node; optionally link to a proof |
|
|
38
|
+
| `addNode(graph, node)` | Low-level: add a pre-built `ProofGraphNode` |
|
|
39
|
+
| `addEdge(graph, edge)` | Low-level: add a pre-built `ProofGraphEdge` |
|
|
40
|
+
| `buildEdge(type, from, to, contextId?)` | Construct an edge without adding it |
|
|
41
|
+
|
|
42
|
+
### Query
|
|
43
|
+
|
|
44
|
+
| Export | Description |
|
|
45
|
+
|--------|-------------|
|
|
46
|
+
| `findNode(graph, refId)` | Find a node by its `refId` |
|
|
47
|
+
| `getProofNodes(graph)` | All nodes of type `'proof'` |
|
|
48
|
+
| `findProofsBySubject(graph, subjectId)` | Proofs where the subject matches (via `about` or `proves` edges) |
|
|
49
|
+
| `findProofsByIssuer(graph, issuer)` | Proofs issued by a given address |
|
|
50
|
+
| `findAnchorsForProof(graph, proofId)` | Anchor nodes linked to a proof via `anchored_to` edges |
|
|
51
|
+
| `findRevocations(graph, proofId)` | Proofs that revoke a given proof |
|
|
52
|
+
| `findSupersessions(graph, proofId)` | Proofs that supersede a given proof |
|
|
53
|
+
| `findConflicts(graph)` | All subject nodes targeted by more than one proof |
|
|
54
|
+
| `getEvidenceTrail(graph, proofId)` | Evidence nodes linked to a proof, in insertion order |
|
|
55
|
+
| `getProofLineage(graph, proofId)` | Walk `derived_from` chain; returns ancestor nodes (cycle-safe) |
|
|
56
|
+
| `resolveCurrentProofSet(graph)` | Active proofs — revoked and superseded proofs are excluded |
|
|
57
|
+
| `getManifestsForAddress(graph, address)` | Manifest nodes linked to an address |
|
|
58
|
+
| `getEdgesFrom(graph, refId)` | All edges originating from a node |
|
|
59
|
+
| `getEdgesTo(graph, refId)` | All edges terminating at a node |
|
|
60
|
+
| `getEdgesByType(graph, type)` | All edges of a given type |
|
|
61
|
+
| `getEdgesBetween(graph, fromId, toId)` | All edges between two specific nodes |
|
|
62
|
+
| `reachableFrom(graph, startId, edgeTypes?)` | BFS reachability from a node, optionally filtered by edge type |
|
|
63
|
+
|
|
64
|
+
### Verification
|
|
65
|
+
|
|
66
|
+
| Export | Description |
|
|
67
|
+
|--------|-------------|
|
|
68
|
+
| `verifyProofGraph(graph)` | Verify all proof nodes; returns `ProofGraphVerifyResult` |
|
|
69
|
+
| `verifyGraphProofs(graph)` | Returns `string[]` — IDs of proofs that fail verification |
|
|
70
|
+
|
|
71
|
+
### Import / Export
|
|
72
|
+
|
|
73
|
+
| Export | Description |
|
|
74
|
+
|--------|-------------|
|
|
75
|
+
| `exportProofGraph(graph)` | Serialize to JSON string |
|
|
76
|
+
| `importProofGraph(json)` | Deserialize and verify `graphId` integrity — throws on tamper |
|
|
77
|
+
|
|
78
|
+
### Canonical helpers
|
|
79
|
+
|
|
80
|
+
| Export | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `computeNodeId(type, refId, data?)` | Deterministic SHA3-256 node ID |
|
|
83
|
+
| `computeEdgeId(type, from, to)` | Deterministic SHA3-256 edge ID |
|
|
84
|
+
| `computeProofGraphId(graph)` | SHA3-256 of all node and edge IDs (excludes `createdAt`, `metadata`) |
|
|
85
|
+
| `recomputeGraphId(graph)` | Return a new graph with a freshly computed `graphId` |
|
|
86
|
+
| `toHex(bytes)` | Uint8Array → lowercase hex (no 0x prefix) |
|
|
87
|
+
| `canonicalJson(value)` | Deterministic JSON — sorted keys, no `undefined` |
|
|
88
|
+
|
|
89
|
+
## Type reference
|
|
90
|
+
|
|
91
|
+
### `ProofGraph`
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface ProofGraph {
|
|
95
|
+
graphId: string; // SHA3-256 over all node/edge content IDs
|
|
96
|
+
nodes: ProofGraphNode[];
|
|
97
|
+
edges: ProofGraphEdge[];
|
|
98
|
+
createdAt: number; // Unix ms — excluded from graphId
|
|
99
|
+
metadata?: Record<string, unknown>; // Also excluded from graphId
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `ProofGraphNode`
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
interface ProofGraphNode {
|
|
107
|
+
id: string; // computeNodeId(type, refId, data)
|
|
108
|
+
type: ProofGraphNodeType;
|
|
109
|
+
refId: string; // External ID (proofId, address, evidenceId, …)
|
|
110
|
+
createdAt: number; // Unix ms — excluded from graphId hash
|
|
111
|
+
data?: Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type ProofGraphNodeType =
|
|
115
|
+
| 'proof' | 'subject' | 'issuer' | 'evidence'
|
|
116
|
+
| 'anchor' | 'manifest' | 'address' | 'identity'
|
|
117
|
+
| 'receipt';
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `ProofGraphEdge`
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
interface ProofGraphEdge {
|
|
124
|
+
id: string; // computeEdgeId(type, from, to)
|
|
125
|
+
type: ProofGraphEdgeType;
|
|
126
|
+
from: string; // source node refId
|
|
127
|
+
to: string; // target node refId
|
|
128
|
+
contextId?: string; // e.g. the proofId that caused this edge
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type ProofGraphEdgeType =
|
|
132
|
+
| 'issued_by' | 'about' | 'proves' | 'has_evidence'
|
|
133
|
+
| 'anchored_to' | 'revokes' | 'supersedes' | 'delegates_to'
|
|
134
|
+
| 'derived_from' | 'manifests_as' | 'controls' | 'supports';
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `ProofGraphVerifyResult`
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
interface ProofGraphVerifyResult {
|
|
141
|
+
valid: boolean;
|
|
142
|
+
invalidProofs: string[]; // proofIds that failed verification
|
|
143
|
+
checkedCount: number;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `ReceiptLikeInput` / `AnchorInput`
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
interface ReceiptLikeInput {
|
|
151
|
+
id: string;
|
|
152
|
+
data?: Record<string, unknown>;
|
|
153
|
+
proofId?: string; // If set, adds a 'supports' edge from receipt → proof
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface AnchorInput {
|
|
157
|
+
hash: string; // Used as the node's refId
|
|
158
|
+
proofId?: string; // If set, adds an 'anchored_to' edge from proof → anchor
|
|
159
|
+
[key: string]: unknown; // Additional fields stored as node data
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Usage
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import {
|
|
167
|
+
createProofGraph,
|
|
168
|
+
addProof,
|
|
169
|
+
addAnchor,
|
|
170
|
+
verifyProofGraph,
|
|
171
|
+
findProofsBySubject,
|
|
172
|
+
resolveCurrentProofSet,
|
|
173
|
+
exportProofGraph,
|
|
174
|
+
importProofGraph,
|
|
175
|
+
} from '@totemsdk/proofgraph';
|
|
176
|
+
import { createProof, signProof, createAnchorCommitment } from '@totemsdk/proof';
|
|
177
|
+
|
|
178
|
+
// 1. Build a signed proof
|
|
179
|
+
const unsigned = createProof({
|
|
180
|
+
kind: 'ownership',
|
|
181
|
+
subject: { id: 'totem:subject:asset:nft-001', kind: 'nft' },
|
|
182
|
+
issuer: 'MxROOT...',
|
|
183
|
+
});
|
|
184
|
+
const signed = signProof(unsigned, seed, keyIndex);
|
|
185
|
+
|
|
186
|
+
// 2. Build the graph
|
|
187
|
+
let graph = createProofGraph();
|
|
188
|
+
graph = addProof(graph, signed);
|
|
189
|
+
|
|
190
|
+
// 3. Add an on-chain anchor
|
|
191
|
+
graph = addAnchor(graph, {
|
|
192
|
+
hash: createAnchorCommitment(signed),
|
|
193
|
+
proofId: signed.proofId,
|
|
194
|
+
txId: '0xabc...',
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// 4. Query
|
|
198
|
+
const forAsset = findProofsBySubject(graph, 'totem:subject:asset:nft-001');
|
|
199
|
+
console.log('Proofs:', forAsset.length);
|
|
200
|
+
|
|
201
|
+
const active = resolveCurrentProofSet(graph);
|
|
202
|
+
console.log('Active proofs:', active.length);
|
|
203
|
+
|
|
204
|
+
// 5. Verify all signatures
|
|
205
|
+
const result = verifyProofGraph(graph);
|
|
206
|
+
console.assert(result.valid, result.invalidProofs);
|
|
207
|
+
|
|
208
|
+
// 6. Serialize / deserialize (graphId is verified on import)
|
|
209
|
+
const json = exportProofGraph(graph);
|
|
210
|
+
const restored = importProofGraph(json);
|
|
211
|
+
console.assert(restored.graphId === graph.graphId);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Design notes
|
|
215
|
+
|
|
216
|
+
### Content-deterministic `graphId`
|
|
217
|
+
|
|
218
|
+
`computeProofGraphId` excludes `node.createdAt` and `graph.metadata` from the hash. Two graphs built at different times from identical proofs will have the same `graphId`. This makes the ID suitable as a stable content address for caching and deduplication.
|
|
219
|
+
|
|
220
|
+
### Immutable + idempotent mutations
|
|
221
|
+
|
|
222
|
+
Every function that modifies a graph (`addProof`, `addEdge`, etc.) returns a new `ProofGraph` with a recomputed `graphId`. Calling the same add function twice with the same arguments returns a graph identical to calling it once — duplicate nodes and edges are silently ignored.
|
|
223
|
+
|
|
224
|
+
### `ProofGraphStoragePort`
|
|
225
|
+
|
|
226
|
+
This package exports a `ProofGraphStoragePort` interface only. If you need persistent storage, implement the interface in your own adapter:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import type { ProofGraphStoragePort, ProofGraph } from '@totemsdk/proofgraph';
|
|
230
|
+
|
|
231
|
+
class MyStorage implements ProofGraphStoragePort {
|
|
232
|
+
async save(graph: ProofGraph): Promise<void> { /* ... */ }
|
|
233
|
+
async load(graphId: string): Promise<ProofGraph | null> { /* ... */ }
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Related packages
|
|
238
|
+
|
|
239
|
+
- [`@totemsdk/proof`](https://www.npmjs.com/package/@totemsdk/proof) — signed proof creation and verification
|
|
240
|
+
- [`@totemsdk/proof-integritas`](https://www.npmjs.com/package/@totemsdk/proof-integritas) — Integritas v2 on-chain anchoring
|
|
241
|
+
- [`@totemsdk/identity`](https://www.npmjs.com/package/@totemsdk/identity) — identity documents and claims
|
|
242
|
+
- [`@totemsdk/core`](https://www.npmjs.com/package/@totemsdk/core) — WOTS signing primitives
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/proofgraph",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Local deterministic proof relationship graph for Totem Edge — indexes proofs, identities, manifests, and subjects into a queryable DAG",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Local deterministic proof relationship graph for Totem Edge — indexes proofs, identities, manifests, and subjects into a queryable content-addressed DAG",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@totemsdk/proof": "0.1.0",
|
|
21
20
|
"@totemsdk/core": "1.1.0",
|
|
21
|
+
"@totemsdk/proof": "0.1.1",
|
|
22
22
|
"@totemsdk/manifest": "0.1.2",
|
|
23
23
|
"@totemsdk/identity": "0.1.2"
|
|
24
24
|
},
|
|
@@ -47,14 +47,26 @@
|
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"author": "Totem SDK",
|
|
49
49
|
"homepage": "https://totemsdk.com",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/MrGheek/axia-totem/issues"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/MrGheek/axia-totem.git",
|
|
56
|
+
"directory": "packages/totem-sdk/packages/proofgraph"
|
|
57
|
+
},
|
|
50
58
|
"keywords": [
|
|
51
59
|
"totem",
|
|
52
60
|
"totemsdk",
|
|
53
61
|
"minima",
|
|
62
|
+
"blockchain",
|
|
54
63
|
"proof",
|
|
55
64
|
"graph",
|
|
56
65
|
"dag",
|
|
57
|
-
"identity"
|
|
66
|
+
"identity",
|
|
67
|
+
"attestation",
|
|
68
|
+
"verification",
|
|
69
|
+
"content-addressed"
|
|
58
70
|
],
|
|
59
71
|
"scripts": {
|
|
60
72
|
"build": "tsc",
|