@mnemopay/sdk 0.9.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +222 -158
- package/dist/anomaly.d.ts +242 -0
- package/dist/anomaly.d.ts.map +1 -0
- package/dist/anomaly.js +451 -0
- package/dist/anomaly.js.map +1 -0
- package/dist/behavioral.d.ts +253 -0
- package/dist/behavioral.d.ts.map +1 -0
- package/dist/behavioral.js +560 -0
- package/dist/behavioral.js.map +1 -0
- package/dist/fico.d.ts +136 -0
- package/dist/fico.d.ts.map +1 -0
- package/dist/fico.js +424 -0
- package/dist/fico.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/integrity.d.ts +167 -0
- package/dist/integrity.d.ts.map +1 -0
- package/dist/integrity.js +401 -0
- package/dist/integrity.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +154 -2
- package/dist/mcp/server.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Merkle Tree Memory Integrity — Tamper-Evident Agent Memory
|
|
4
|
+
*
|
|
5
|
+
* Protects against MemoryGraft attacks (injecting false memories into agent
|
|
6
|
+
* context) by maintaining a Merkle hash tree over all memory writes.
|
|
7
|
+
*
|
|
8
|
+
* How it works:
|
|
9
|
+
* 1. Every memory write produces a leaf hash: SHA-256(id + content + timestamp)
|
|
10
|
+
* 2. Leaf hashes build a binary Merkle tree
|
|
11
|
+
* 3. The root hash represents the entire memory state
|
|
12
|
+
* 4. Any modification to any memory changes the root
|
|
13
|
+
* 5. Merkle proofs verify individual memories without full tree traversal
|
|
14
|
+
*
|
|
15
|
+
* Attack vectors defended:
|
|
16
|
+
* - MemoryGraft: Injecting fabricated memories → root changes, detected
|
|
17
|
+
* - Memory tampering: Modifying existing memory content → leaf hash changes
|
|
18
|
+
* - Memory deletion: Removing memories silently → tree structure changes
|
|
19
|
+
* - Replay attacks: Re-inserting old memories → duplicate leaf detection
|
|
20
|
+
* - Reordering attacks: Changing memory chronology → position-dependent hashing
|
|
21
|
+
*
|
|
22
|
+
* References:
|
|
23
|
+
* - Merkle, R. (1987). "A Digital Signature Based on a Conventional Encryption Function"
|
|
24
|
+
* - OWASP Agentic AI Top 10 2026: A03 — Memory Poisoning
|
|
25
|
+
* - MnemoPay Master Strategy, Part 2.1 — Merkle tree memory integrity
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.MerkleTree = void 0;
|
|
29
|
+
// ─── SHA-256 Hashing ────────────────────────────────────────────────────────
|
|
30
|
+
let _crypto;
|
|
31
|
+
function getHash(data) {
|
|
32
|
+
if (!_crypto) {
|
|
33
|
+
try {
|
|
34
|
+
_crypto = require("crypto");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Browser fallback: use SubtleCrypto synchronously is not possible,
|
|
38
|
+
// so we use a simple non-cryptographic hash for environments without Node crypto.
|
|
39
|
+
// This should never happen in production (Node.js always has crypto).
|
|
40
|
+
throw new Error("MerkleTree requires Node.js crypto module");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return _crypto.createHash("sha256").update(data).digest("hex");
|
|
44
|
+
}
|
|
45
|
+
// ─── Merkle Tree ────────────────────────────────────────────────────────────
|
|
46
|
+
class MerkleTree {
|
|
47
|
+
leaves = [];
|
|
48
|
+
leafMap = new Map(); // memoryId → index
|
|
49
|
+
hashSet = new Set(); // duplicate detection
|
|
50
|
+
auditLog = [];
|
|
51
|
+
/** Max audit log entries to prevent unbounded growth */
|
|
52
|
+
static MAX_AUDIT_LOG = 1000;
|
|
53
|
+
/** Max leaves before requiring compaction */
|
|
54
|
+
static MAX_LEAVES = 100_000;
|
|
55
|
+
/**
|
|
56
|
+
* Add a memory entry to the tree.
|
|
57
|
+
* Returns the leaf hash.
|
|
58
|
+
*/
|
|
59
|
+
/** Max content size per leaf (100KB, matching memory limit) */
|
|
60
|
+
static MAX_CONTENT_SIZE = 102_400;
|
|
61
|
+
addLeaf(memoryId, content, timestamp) {
|
|
62
|
+
if (!memoryId || typeof memoryId !== "string")
|
|
63
|
+
throw new Error("memoryId is required");
|
|
64
|
+
if (!content || typeof content !== "string")
|
|
65
|
+
throw new Error("content is required");
|
|
66
|
+
if (memoryId.length > 256)
|
|
67
|
+
throw new Error("memoryId exceeds 256 characters");
|
|
68
|
+
if (content.length > MerkleTree.MAX_CONTENT_SIZE)
|
|
69
|
+
throw new Error(`Content exceeds ${MerkleTree.MAX_CONTENT_SIZE} bytes`);
|
|
70
|
+
if (this.leaves.length >= MerkleTree.MAX_LEAVES) {
|
|
71
|
+
throw new Error(`Merkle tree leaf limit reached (${MerkleTree.MAX_LEAVES}). Compact old memories first.`);
|
|
72
|
+
}
|
|
73
|
+
// Compute leaf hash: H(index || memoryId || content || timestamp)
|
|
74
|
+
// Including index prevents reordering attacks
|
|
75
|
+
const ts = timestamp ?? new Date().toISOString();
|
|
76
|
+
const index = this.leaves.length;
|
|
77
|
+
const leafData = `${index}:${memoryId}:${content}:${ts}`;
|
|
78
|
+
const hash = getHash(leafData);
|
|
79
|
+
// Duplicate detection: same hash means identical content at same position
|
|
80
|
+
if (this.hashSet.has(hash)) {
|
|
81
|
+
throw new Error(`Duplicate leaf detected for memory ${memoryId}`);
|
|
82
|
+
}
|
|
83
|
+
// If this memoryId was already added (memory update), remove the old leaf
|
|
84
|
+
if (this.leafMap.has(memoryId)) {
|
|
85
|
+
this._removeLeafByMemoryId(memoryId);
|
|
86
|
+
}
|
|
87
|
+
const leaf = { hash, memoryId, index };
|
|
88
|
+
this.leaves.push(leaf);
|
|
89
|
+
this.leafMap.set(memoryId, this.leaves.length - 1);
|
|
90
|
+
this.hashSet.add(hash);
|
|
91
|
+
this._audit("leaf_added", memoryId);
|
|
92
|
+
return hash;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Remove a memory from the tree (when memory is forgotten).
|
|
96
|
+
*/
|
|
97
|
+
removeLeaf(memoryId) {
|
|
98
|
+
if (!this.leafMap.has(memoryId))
|
|
99
|
+
return false;
|
|
100
|
+
this._removeLeafByMemoryId(memoryId);
|
|
101
|
+
this._audit("leaf_removed", memoryId);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
_removeLeafByMemoryId(memoryId) {
|
|
105
|
+
const idx = this.leafMap.get(memoryId);
|
|
106
|
+
if (idx === undefined)
|
|
107
|
+
return;
|
|
108
|
+
const leaf = this.leaves[idx];
|
|
109
|
+
if (leaf) {
|
|
110
|
+
this.hashSet.delete(leaf.hash);
|
|
111
|
+
}
|
|
112
|
+
// Mark as removed (null-ify) rather than splicing to preserve indices
|
|
113
|
+
// This avoids O(n) shifts and keeps proofs stable
|
|
114
|
+
this.leaves[idx] = null;
|
|
115
|
+
this.leafMap.delete(memoryId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Compute the Merkle root from all current leaves.
|
|
119
|
+
* Uses standard binary tree construction: H(left || right).
|
|
120
|
+
*/
|
|
121
|
+
getRoot() {
|
|
122
|
+
const activeLeaves = this.leaves.filter(l => l !== null);
|
|
123
|
+
if (activeLeaves.length === 0)
|
|
124
|
+
return getHash("empty");
|
|
125
|
+
let level = activeLeaves.map(l => l.hash);
|
|
126
|
+
// Build tree bottom-up
|
|
127
|
+
while (level.length > 1) {
|
|
128
|
+
const nextLevel = [];
|
|
129
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
130
|
+
const left = level[i];
|
|
131
|
+
const right = i + 1 < level.length ? level[i + 1] : left; // Duplicate last if odd
|
|
132
|
+
// Canonical ordering: always hash(smaller || larger) to prevent order-dependent roots
|
|
133
|
+
// when reconstructing from unordered sets. But for Merkle trees, positional ordering
|
|
134
|
+
// is correct (left child is always the lower index).
|
|
135
|
+
nextLevel.push(getHash(left + right));
|
|
136
|
+
}
|
|
137
|
+
level = nextLevel;
|
|
138
|
+
}
|
|
139
|
+
return level[0];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Generate a Merkle proof for a specific memory.
|
|
143
|
+
* The proof allows verifying this memory is in the tree without the full tree.
|
|
144
|
+
*/
|
|
145
|
+
getProof(memoryId) {
|
|
146
|
+
const idx = this.leafMap.get(memoryId);
|
|
147
|
+
if (idx === undefined)
|
|
148
|
+
throw new Error(`Memory ${memoryId} not in tree`);
|
|
149
|
+
const leaf = this.leaves[idx];
|
|
150
|
+
if (!leaf)
|
|
151
|
+
throw new Error(`Memory ${memoryId} has been removed`);
|
|
152
|
+
const activeLeaves = this.leaves.filter(l => l !== null);
|
|
153
|
+
const activeIndex = activeLeaves.findIndex(l => l.memoryId === memoryId);
|
|
154
|
+
if (activeIndex === -1)
|
|
155
|
+
throw new Error(`Memory ${memoryId} not found in active leaves`);
|
|
156
|
+
// Build proof path
|
|
157
|
+
let level = activeLeaves.map(l => l.hash);
|
|
158
|
+
const path = [];
|
|
159
|
+
let currentIdx = activeIndex;
|
|
160
|
+
while (level.length > 1) {
|
|
161
|
+
const nextLevel = [];
|
|
162
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
163
|
+
const left = level[i];
|
|
164
|
+
const right = i + 1 < level.length ? level[i + 1] : left;
|
|
165
|
+
if (i === currentIdx || i + 1 === currentIdx) {
|
|
166
|
+
// This pair contains our node
|
|
167
|
+
if (currentIdx % 2 === 0) {
|
|
168
|
+
// Our node is left child, sibling is right
|
|
169
|
+
const siblingHash = i + 1 < level.length ? level[i + 1] : level[i];
|
|
170
|
+
path.push({ hash: siblingHash, direction: "right" });
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Our node is right child, sibling is left
|
|
174
|
+
path.push({ hash: level[i], direction: "left" });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
nextLevel.push(getHash(left + right));
|
|
178
|
+
}
|
|
179
|
+
currentIdx = Math.floor(currentIdx / 2);
|
|
180
|
+
level = nextLevel;
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
leafHash: leaf.hash,
|
|
184
|
+
memoryId,
|
|
185
|
+
path,
|
|
186
|
+
rootHash: this.getRoot(),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Verify a Merkle proof is valid.
|
|
191
|
+
* Returns true if the proof correctly links the leaf to the root.
|
|
192
|
+
*/
|
|
193
|
+
static verifyProof(proof) {
|
|
194
|
+
if (!proof || !proof.leafHash || !proof.rootHash || !Array.isArray(proof.path)) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
let currentHash = proof.leafHash;
|
|
198
|
+
for (const step of proof.path) {
|
|
199
|
+
if (step.direction === "left") {
|
|
200
|
+
currentHash = getHash(step.hash + currentHash);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
currentHash = getHash(currentHash + step.hash);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return currentHash === proof.rootHash;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Verify a specific memory's content against the tree.
|
|
210
|
+
* Re-computes the leaf hash and checks it matches the stored hash.
|
|
211
|
+
*/
|
|
212
|
+
verifyMemory(memoryId, content, timestamp) {
|
|
213
|
+
const idx = this.leafMap.get(memoryId);
|
|
214
|
+
if (idx === undefined)
|
|
215
|
+
return false;
|
|
216
|
+
const leaf = this.leaves[idx];
|
|
217
|
+
if (!leaf)
|
|
218
|
+
return false;
|
|
219
|
+
// Recompute the hash
|
|
220
|
+
const leafData = `${leaf.index}:${memoryId}:${content}:${timestamp}`;
|
|
221
|
+
const expectedHash = getHash(leafData);
|
|
222
|
+
const match = expectedHash === leaf.hash;
|
|
223
|
+
this._audit(match ? "verification_pass" : "verification_fail", memoryId);
|
|
224
|
+
return match;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Take a snapshot of current tree state.
|
|
228
|
+
* Used for periodic checkpointing and tamper detection.
|
|
229
|
+
*/
|
|
230
|
+
snapshot() {
|
|
231
|
+
const rootHash = this.getRoot();
|
|
232
|
+
const leafCount = this.leaves.filter(l => l !== null).length;
|
|
233
|
+
const timestamp = new Date().toISOString();
|
|
234
|
+
const snapshotData = `${rootHash}:${leafCount}:${timestamp}`;
|
|
235
|
+
const snapshotHash = getHash(snapshotData);
|
|
236
|
+
this._audit("snapshot_created");
|
|
237
|
+
return { rootHash, leafCount, timestamp, snapshotHash };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Detect tampering by comparing current root to a previous snapshot.
|
|
241
|
+
* Also validates snapshot integrity (the snapshot itself wasn't tampered).
|
|
242
|
+
*/
|
|
243
|
+
detectTampering(previousSnapshot) {
|
|
244
|
+
// First, verify the snapshot itself wasn't tampered
|
|
245
|
+
const expectedSnapshotHash = getHash(`${previousSnapshot.rootHash}:${previousSnapshot.leafCount}:${previousSnapshot.timestamp}`);
|
|
246
|
+
if (expectedSnapshotHash !== previousSnapshot.snapshotHash) {
|
|
247
|
+
return {
|
|
248
|
+
tampered: true,
|
|
249
|
+
failedMemories: [],
|
|
250
|
+
currentRoot: this.getRoot(),
|
|
251
|
+
expectedRoot: previousSnapshot.rootHash,
|
|
252
|
+
summary: "CRITICAL: The snapshot itself has been tampered with. Cannot trust any comparison.",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const currentRoot = this.getRoot();
|
|
256
|
+
const currentLeafCount = this.leaves.filter(l => l !== null).length;
|
|
257
|
+
if (currentRoot === previousSnapshot.rootHash) {
|
|
258
|
+
return {
|
|
259
|
+
tampered: false,
|
|
260
|
+
failedMemories: [],
|
|
261
|
+
currentRoot,
|
|
262
|
+
expectedRoot: previousSnapshot.rootHash,
|
|
263
|
+
summary: `Integrity verified. ${currentLeafCount} memories, root matches snapshot.`,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// Root changed — determine what changed
|
|
267
|
+
const leafDiff = currentLeafCount - previousSnapshot.leafCount;
|
|
268
|
+
let summary = `Root hash mismatch. Leaves: ${previousSnapshot.leafCount} → ${currentLeafCount} (${leafDiff >= 0 ? "+" : ""}${leafDiff}).`;
|
|
269
|
+
if (leafDiff > 0) {
|
|
270
|
+
summary += ` ${leafDiff} new memories added since snapshot.`;
|
|
271
|
+
}
|
|
272
|
+
else if (leafDiff < 0) {
|
|
273
|
+
summary += ` ${Math.abs(leafDiff)} memories removed since snapshot.`;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
summary += " Same leaf count but content changed — possible memory modification.";
|
|
277
|
+
this._audit("tamper_detected");
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
tampered: true,
|
|
281
|
+
failedMemories: [], // Would need per-memory tracking to identify specific changes
|
|
282
|
+
currentRoot,
|
|
283
|
+
expectedRoot: previousSnapshot.rootHash,
|
|
284
|
+
summary,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Full tree verification: recompute root from all leaves and verify
|
|
289
|
+
* internal consistency (no corrupted nodes).
|
|
290
|
+
*/
|
|
291
|
+
verifyTreeIntegrity() {
|
|
292
|
+
const activeLeaves = this.leaves.filter(l => l !== null);
|
|
293
|
+
const computedRoot = this.getRoot();
|
|
294
|
+
// Verify no hash collisions in leaf set
|
|
295
|
+
const uniqueHashes = new Set(activeLeaves.map(l => l.hash));
|
|
296
|
+
if (uniqueHashes.size !== activeLeaves.length) {
|
|
297
|
+
return { valid: false, leafCount: activeLeaves.length, rootHash: computedRoot };
|
|
298
|
+
}
|
|
299
|
+
// Verify leaf map consistency
|
|
300
|
+
for (const [memId, idx] of this.leafMap) {
|
|
301
|
+
const leaf = this.leaves[idx];
|
|
302
|
+
if (!leaf || leaf.memoryId !== memId) {
|
|
303
|
+
return { valid: false, leafCount: activeLeaves.length, rootHash: computedRoot };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { valid: true, leafCount: activeLeaves.length, rootHash: computedRoot };
|
|
307
|
+
}
|
|
308
|
+
/** Number of active (non-removed) leaves */
|
|
309
|
+
get size() {
|
|
310
|
+
return this.leaves.filter(l => l !== null).length;
|
|
311
|
+
}
|
|
312
|
+
/** Get the audit log */
|
|
313
|
+
getAuditLog() {
|
|
314
|
+
return [...this.auditLog];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Compact the tree by removing null entries and re-indexing.
|
|
318
|
+
* This is a heavy operation — call during maintenance windows only.
|
|
319
|
+
* WARNING: This invalidates all existing proofs.
|
|
320
|
+
*/
|
|
321
|
+
compact() {
|
|
322
|
+
const before = this.leaves.length;
|
|
323
|
+
const activeLeaves = this.leaves.filter(l => l !== null);
|
|
324
|
+
// Re-index
|
|
325
|
+
this.leaves = [];
|
|
326
|
+
this.leafMap.clear();
|
|
327
|
+
this.hashSet.clear();
|
|
328
|
+
for (let i = 0; i < activeLeaves.length; i++) {
|
|
329
|
+
const leaf = { ...activeLeaves[i], index: i };
|
|
330
|
+
this.leaves.push(leaf);
|
|
331
|
+
this.leafMap.set(leaf.memoryId, i);
|
|
332
|
+
this.hashSet.add(leaf.hash);
|
|
333
|
+
}
|
|
334
|
+
return { removed: before - activeLeaves.length, remaining: activeLeaves.length };
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Serialize tree state for persistence.
|
|
338
|
+
*/
|
|
339
|
+
serialize() {
|
|
340
|
+
const activeLeaves = this.leaves.filter(l => l !== null);
|
|
341
|
+
return {
|
|
342
|
+
leaves: activeLeaves,
|
|
343
|
+
rootHash: this.getRoot(),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Deserialize from persisted state with validation.
|
|
348
|
+
*/
|
|
349
|
+
static deserialize(data) {
|
|
350
|
+
if (!data || !Array.isArray(data.leaves)) {
|
|
351
|
+
throw new Error("Invalid MerkleTree data");
|
|
352
|
+
}
|
|
353
|
+
const tree = new MerkleTree();
|
|
354
|
+
const seenIds = new Set();
|
|
355
|
+
const seenHashes = new Set();
|
|
356
|
+
for (const leaf of data.leaves) {
|
|
357
|
+
// Validate each leaf
|
|
358
|
+
if (!leaf.hash || typeof leaf.hash !== "string" || leaf.hash.length !== 64) {
|
|
359
|
+
throw new Error(`Invalid leaf hash for memory ${leaf.memoryId}`);
|
|
360
|
+
}
|
|
361
|
+
if (!leaf.memoryId || typeof leaf.memoryId !== "string") {
|
|
362
|
+
throw new Error("Invalid leaf memoryId");
|
|
363
|
+
}
|
|
364
|
+
if (seenIds.has(leaf.memoryId)) {
|
|
365
|
+
throw new Error(`Duplicate memoryId in tree: ${leaf.memoryId}`);
|
|
366
|
+
}
|
|
367
|
+
if (seenHashes.has(leaf.hash)) {
|
|
368
|
+
throw new Error(`Duplicate hash in tree: ${leaf.hash}`);
|
|
369
|
+
}
|
|
370
|
+
seenIds.add(leaf.memoryId);
|
|
371
|
+
seenHashes.add(leaf.hash);
|
|
372
|
+
tree.leaves.push({ ...leaf, index: tree.leaves.length });
|
|
373
|
+
tree.leafMap.set(leaf.memoryId, tree.leaves.length - 1);
|
|
374
|
+
tree.hashSet.add(leaf.hash);
|
|
375
|
+
}
|
|
376
|
+
// Verify root matches if provided
|
|
377
|
+
if (data.rootHash) {
|
|
378
|
+
const computedRoot = tree.getRoot();
|
|
379
|
+
if (computedRoot !== data.rootHash) {
|
|
380
|
+
throw new Error(`Root hash mismatch on deserialize: computed ${computedRoot}, expected ${data.rootHash}. Tree may be corrupted.`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return tree;
|
|
384
|
+
}
|
|
385
|
+
_audit(event, memoryId) {
|
|
386
|
+
// Root hash is computed lazily — only include it for verification/snapshot events
|
|
387
|
+
// to avoid O(n) cost on every leaf add/remove
|
|
388
|
+
const needsRoot = event === "verification_pass" || event === "verification_fail" || event === "tamper_detected" || event === "snapshot_created";
|
|
389
|
+
this.auditLog.push({
|
|
390
|
+
event,
|
|
391
|
+
memoryId,
|
|
392
|
+
rootHash: needsRoot ? this.getRoot() : "",
|
|
393
|
+
timestamp: new Date().toISOString(),
|
|
394
|
+
});
|
|
395
|
+
if (this.auditLog.length > MerkleTree.MAX_AUDIT_LOG) {
|
|
396
|
+
this.auditLog.splice(0, this.auditLog.length - (MerkleTree.MAX_AUDIT_LOG / 2));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
exports.MerkleTree = MerkleTree;
|
|
401
|
+
//# sourceMappingURL=integrity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrity.js","sourceRoot":"","sources":["../src/integrity.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AA0DH,+EAA+E;AAE/E,IAAI,OAAY,CAAC;AAEjB,SAAS,OAAO,CAAC,IAAY;IAC3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,CAAC;YACH,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,oEAAoE;YACpE,kFAAkF;YAClF,sEAAsE;YACtE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAED,+EAA+E;AAE/E,MAAa,UAAU;IACb,MAAM,GAAiB,EAAE,CAAC;IAC1B,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC,CAAC,mBAAmB;IAC7D,OAAO,GAAgB,IAAI,GAAG,EAAE,CAAC,CAAC,sBAAsB;IACxD,QAAQ,GAA0B,EAAE,CAAC;IAC7C,wDAAwD;IAChD,MAAM,CAAU,aAAa,GAAG,IAAI,CAAC;IAC7C,6CAA6C;IAC7C,MAAM,CAAU,UAAU,GAAG,OAAO,CAAC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AAQ,0BAA0B,CAAC,CAAC;YACpI,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,MAAM,CAAC,KAAmC,EAAE,QAAiB;QACnE,kFAAkF;QAClF,8CAA8C;QAC9C,MAAM,SAAS,GAAG,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK,iBAAiB,IAAI,KAAK,KAAK,kBAAkB,CAAC;QAChJ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,KAAK;YACL,QAAQ;YACR,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE;YACzC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;QACH,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;YACpD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;;AA7YH,gCA8YC"}
|
package/dist/mcp/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AA4sBnE,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAmfjD;AAID,MAAM,CAAC,OAAO,UAAU,mBAAmB,IAAI,MAAM,CAgBpD"}
|
package/dist/mcp/server.js
CHANGED
|
@@ -338,6 +338,80 @@ const TOOLS = [
|
|
|
338
338
|
},
|
|
339
339
|
},
|
|
340
340
|
},
|
|
341
|
+
// ── Agent FICO ─────────────────────────────────────────────────────────────
|
|
342
|
+
{
|
|
343
|
+
name: "agent_fico_score",
|
|
344
|
+
description: "Compute the agent's FICO credit score (300-850). Uses payment history, " +
|
|
345
|
+
"credit utilization, account age, behavior diversity, and fraud record. " +
|
|
346
|
+
"Returns score, rating, fee rate, trust level, and HITL requirement.",
|
|
347
|
+
inputSchema: {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: {
|
|
350
|
+
budgetCap: {
|
|
351
|
+
type: "number",
|
|
352
|
+
minimum: 1,
|
|
353
|
+
description: "Agent's budget cap for utilization calculation (default: 10000)",
|
|
354
|
+
},
|
|
355
|
+
fraudFlags: { type: "number", minimum: 0, description: "Number of fraud flags (default: 0)" },
|
|
356
|
+
disputeCount: { type: "number", minimum: 0, description: "Total disputes filed (default: 0)" },
|
|
357
|
+
disputesLost: { type: "number", minimum: 0, description: "Disputes lost (default: 0)" },
|
|
358
|
+
warnings: { type: "number", minimum: 0, description: "Fraud warnings (default: 0)" },
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
// ── Behavioral Finance ─────────────────────────────────────────────────────
|
|
363
|
+
{
|
|
364
|
+
name: "behavioral_analysis",
|
|
365
|
+
description: "Run behavioral finance analysis on a proposed spending amount. " +
|
|
366
|
+
"Returns prospect theory value, cooling-off recommendation, and loss framing. " +
|
|
367
|
+
"Based on Kahneman & Tversky (1992) and Thaler & Benartzi (2004).",
|
|
368
|
+
inputSchema: {
|
|
369
|
+
type: "object",
|
|
370
|
+
properties: {
|
|
371
|
+
amount: { type: "number", description: "The spending amount to analyze" },
|
|
372
|
+
monthlyIncome: {
|
|
373
|
+
type: "number",
|
|
374
|
+
minimum: 1,
|
|
375
|
+
description: "Agent's monthly income/budget for cooling-off calculation",
|
|
376
|
+
},
|
|
377
|
+
goalName: { type: "string", description: "Savings goal name for loss framing" },
|
|
378
|
+
goalTarget: { type: "number", description: "Savings goal target amount" },
|
|
379
|
+
goalCurrent: { type: "number", description: "Current savings toward goal" },
|
|
380
|
+
goalMonthlySavings: { type: "number", description: "Monthly savings rate" },
|
|
381
|
+
},
|
|
382
|
+
required: ["amount"],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
// ── Memory Integrity ───────────────────────────────────────────────────────
|
|
386
|
+
{
|
|
387
|
+
name: "memory_integrity_check",
|
|
388
|
+
description: "Check the integrity of the agent's memory store using SHA-256 Merkle trees. " +
|
|
389
|
+
"Detects tampering, injection, deletion, replay, and reordering attacks. " +
|
|
390
|
+
"Returns root hash, leaf count, and tampering status.",
|
|
391
|
+
inputSchema: {
|
|
392
|
+
type: "object",
|
|
393
|
+
properties: {
|
|
394
|
+
snapshotHash: {
|
|
395
|
+
type: "string",
|
|
396
|
+
description: "Previous snapshot hash to compare against (optional — omit for first check)",
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
// ── Anomaly Detection ──────────────────────────────────────────────────────
|
|
402
|
+
{
|
|
403
|
+
name: "anomaly_check",
|
|
404
|
+
description: "Check if a transaction amount is anomalous using EWMA streaming detection. " +
|
|
405
|
+
"Returns whether the value is normal, a warning, or a critical anomaly. " +
|
|
406
|
+
"Based on Roberts (1959) and Lucas & Saccucci (1990).",
|
|
407
|
+
inputSchema: {
|
|
408
|
+
type: "object",
|
|
409
|
+
properties: {
|
|
410
|
+
amount: { type: "number", description: "Transaction amount to check" },
|
|
411
|
+
},
|
|
412
|
+
required: ["amount"],
|
|
413
|
+
},
|
|
414
|
+
},
|
|
341
415
|
];
|
|
342
416
|
// ─── Tool execution ─────────────────────────────────────────────────────────
|
|
343
417
|
async function executeTool(agent, name, args) {
|
|
@@ -494,10 +568,88 @@ async function executeTool(agent, name, args) {
|
|
|
494
568
|
(o.trackingUrl ? ` Track: ${o.trackingUrl}` : "")).join("\n");
|
|
495
569
|
return `${list}\n\nSpent: $${summary.totalSpent.toFixed(2)} | Remaining: $${summary.remainingBudget.toFixed(2)} | Orders: ${summary.orderCount}`;
|
|
496
570
|
}
|
|
571
|
+
// ── Agent FICO ─────────────────────────────────────────────────────────
|
|
572
|
+
case "agent_fico_score": {
|
|
573
|
+
const fico = new index_js_2.AgentFICO();
|
|
574
|
+
const txHistory = await agent.history(1000);
|
|
575
|
+
const profile = await agent.profile();
|
|
576
|
+
const result = fico.compute({
|
|
577
|
+
transactions: txHistory.map((tx) => ({
|
|
578
|
+
id: tx.id,
|
|
579
|
+
amount: tx.amount,
|
|
580
|
+
status: tx.status,
|
|
581
|
+
reason: tx.reason || "",
|
|
582
|
+
createdAt: new Date(tx.createdAt),
|
|
583
|
+
settledAt: tx.settledAt ? new Date(tx.settledAt) : undefined,
|
|
584
|
+
counterparty: tx.counterparty,
|
|
585
|
+
})),
|
|
586
|
+
createdAt: new Date(Date.now() - 86400000 * 30),
|
|
587
|
+
fraudFlags: args.fraudFlags ?? 0,
|
|
588
|
+
disputeCount: args.disputeCount ?? 0,
|
|
589
|
+
disputesLost: args.disputesLost ?? 0,
|
|
590
|
+
warnings: args.warnings ?? 0,
|
|
591
|
+
budgetCap: args.budgetCap ?? 10000,
|
|
592
|
+
memoriesCount: profile.memoriesCount ?? 0,
|
|
593
|
+
});
|
|
594
|
+
return JSON.stringify(result, null, 2);
|
|
595
|
+
}
|
|
596
|
+
// ── Behavioral Finance ─────────────────────────────────────────────────
|
|
597
|
+
case "behavioral_analysis": {
|
|
598
|
+
const behavioral = new index_js_2.BehavioralEngine();
|
|
599
|
+
const prospect = behavioral.prospectValue(args.amount);
|
|
600
|
+
const analysis = { prospect };
|
|
601
|
+
if (args.monthlyIncome) {
|
|
602
|
+
analysis.coolingOff = behavioral.coolingOff(args.amount, args.monthlyIncome);
|
|
603
|
+
}
|
|
604
|
+
if (args.goalName && args.goalTarget && args.goalCurrent !== undefined && args.goalMonthlySavings) {
|
|
605
|
+
analysis.lossFrame = behavioral.lossFrame(args.amount, {
|
|
606
|
+
name: args.goalName,
|
|
607
|
+
target: args.goalTarget,
|
|
608
|
+
current: args.goalCurrent,
|
|
609
|
+
monthlySavings: args.goalMonthlySavings,
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return JSON.stringify(analysis, null, 2);
|
|
613
|
+
}
|
|
614
|
+
// ── Memory Integrity ─────────────────────────────────────────────────
|
|
615
|
+
case "memory_integrity_check": {
|
|
616
|
+
const tree = _merkleTree;
|
|
617
|
+
if (!tree || tree.size === 0) {
|
|
618
|
+
// Build tree from current memories
|
|
619
|
+
const memories = await agent.recall(50);
|
|
620
|
+
for (const m of memories) {
|
|
621
|
+
tree.addLeaf(m.id, m.content);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const snapshot = tree.snapshot();
|
|
625
|
+
const result = {
|
|
626
|
+
rootHash: snapshot.rootHash,
|
|
627
|
+
leafCount: snapshot.leafCount,
|
|
628
|
+
snapshotHash: snapshot.snapshotHash,
|
|
629
|
+
};
|
|
630
|
+
if (args.snapshotHash) {
|
|
631
|
+
const check = tree.detectTampering({
|
|
632
|
+
rootHash: args.snapshotHash,
|
|
633
|
+
leafCount: snapshot.leafCount,
|
|
634
|
+
snapshotHash: args.snapshotHash,
|
|
635
|
+
timestamp: new Date().toISOString(),
|
|
636
|
+
});
|
|
637
|
+
result.tampering = check;
|
|
638
|
+
}
|
|
639
|
+
return JSON.stringify(result, null, 2);
|
|
640
|
+
}
|
|
641
|
+
// ── Anomaly Detection ────────────────────────────────────────────────
|
|
642
|
+
case "anomaly_check": {
|
|
643
|
+
const result = _ewmaDetector.update(args.amount);
|
|
644
|
+
return JSON.stringify(result, null, 2);
|
|
645
|
+
}
|
|
497
646
|
default:
|
|
498
647
|
throw new Error(`Unknown tool: ${name}`);
|
|
499
648
|
}
|
|
500
649
|
}
|
|
650
|
+
// ── Module singletons ────────────────────────────────────────────────────────
|
|
651
|
+
const _merkleTree = new index_js_2.MerkleTree();
|
|
652
|
+
const _ewmaDetector = new index_js_2.EWMADetector(0.15, 2.5, 3.5, 10);
|
|
501
653
|
// ── Commerce singleton ──────────────────────────────────────────────────────
|
|
502
654
|
let _commerceEngine = null;
|
|
503
655
|
async function getCommerceEngine(agent) {
|
|
@@ -510,7 +662,7 @@ async function getCommerceEngine(agent) {
|
|
|
510
662
|
// ─── Server setup ───────────────────────────────────────────────────────────
|
|
511
663
|
async function startServer() {
|
|
512
664
|
const agent = createAgent();
|
|
513
|
-
const server = new index_js_1.Server({ name: "mnemopay", version: "0.
|
|
665
|
+
const server = new index_js_1.Server({ name: "mnemopay", version: "1.0.0-beta.1" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
|
|
514
666
|
// ── Tools ───────────────────────────────────────────────────────────────
|
|
515
667
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
516
668
|
tools: TOOLS,
|
|
@@ -967,7 +1119,7 @@ async function startServer() {
|
|
|
967
1119
|
// ─── Smithery sandbox — allows tool scanning without real credentials ──────
|
|
968
1120
|
function createSandboxServer() {
|
|
969
1121
|
const agent = index_js_2.MnemoPay.quick("smithery-sandbox");
|
|
970
|
-
const server = new index_js_1.Server({ name: "mnemopay", version: "0.
|
|
1122
|
+
const server = new index_js_1.Server({ name: "mnemopay", version: "1.0.0-beta.1" }, { capabilities: { tools: {}, resources: {}, prompts: {} } });
|
|
971
1123
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: TOOLS }));
|
|
972
1124
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
973
1125
|
const { name, arguments: args } = request.params;
|