@mnemopay/sdk 0.7.5 → 0.8.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 +182 -211
- package/dist/fraud.d.ts +75 -1
- package/dist/fraud.d.ts.map +1 -1
- package/dist/fraud.js +247 -26
- package/dist/fraud.js.map +1 -1
- package/dist/identity.d.ts +154 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +277 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +29 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -7
- package/dist/index.js.map +1 -1
- package/dist/ledger.d.ts +137 -0
- package/dist/ledger.d.ts.map +1 -0
- package/dist/ledger.js +250 -0
- package/dist/ledger.js.map +1 -0
- package/dist/network.d.ts +155 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +263 -0
- package/dist/network.js.map +1 -0
- package/dist/rails/index.d.ts +2 -0
- package/dist/rails/index.d.ts.map +1 -1
- package/dist/rails/index.js +5 -1
- package/dist/rails/index.js.map +1 -1
- package/dist/rails/paystack.d.ts +157 -0
- package/dist/rails/paystack.d.ts.map +1 -0
- package/dist/rails/paystack.js +366 -0
- package/dist/rails/paystack.js.map +1 -0
- package/package.json +18 -16
package/dist/identity.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Identity System for MnemoPay
|
|
4
|
+
*
|
|
5
|
+
* Inspired by the elephant's olfactory signature system — each elephant has
|
|
6
|
+
* a unique chemical identity recognizable by kin after 12+ years of separation.
|
|
7
|
+
* Similarly, each MnemoPay agent gets a unique cryptographic identity that
|
|
8
|
+
* persists across sessions and enables trust verification.
|
|
9
|
+
*
|
|
10
|
+
* Components:
|
|
11
|
+
* - AgentIdentity: Cryptographic keypair + metadata for each agent
|
|
12
|
+
* - CapabilityToken: Scoped, time-limited permissions for agent actions
|
|
13
|
+
* - IdentityRegistry: Discovery and verification of agent identities
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.IdentityRegistry = void 0;
|
|
17
|
+
// ─── Crypto Utilities ───────────────────────────────────────────────────────
|
|
18
|
+
function generateKeyPair() {
|
|
19
|
+
// Use Web Crypto API for browser compatibility
|
|
20
|
+
// For production: use ECDSA P-256 or Ed25519
|
|
21
|
+
// For now: generate deterministic-length hex keys using crypto.randomUUID
|
|
22
|
+
const privateBytes = new Uint8Array(32);
|
|
23
|
+
crypto.getRandomValues(privateBytes);
|
|
24
|
+
const privateKey = Array.from(privateBytes).map(b => b.toString(16).padStart(2, "0")).join("");
|
|
25
|
+
// Derive "public key" — in production this would be ECDSA point derivation
|
|
26
|
+
const publicBytes = new Uint8Array(32);
|
|
27
|
+
crypto.getRandomValues(publicBytes);
|
|
28
|
+
const publicKey = Array.from(publicBytes).map(b => b.toString(16).padStart(2, "0")).join("");
|
|
29
|
+
return { publicKey, privateKey };
|
|
30
|
+
}
|
|
31
|
+
function signMessage(message, _privateKey) {
|
|
32
|
+
// Simplified HMAC-like signature for now
|
|
33
|
+
// Production: use actual ECDSA signing
|
|
34
|
+
const encoder = new TextEncoder();
|
|
35
|
+
const data = encoder.encode(message + _privateKey);
|
|
36
|
+
let hash = 0x811c9dc5;
|
|
37
|
+
for (const byte of data) {
|
|
38
|
+
hash ^= byte;
|
|
39
|
+
hash = Math.imul(hash, 0x01000193);
|
|
40
|
+
}
|
|
41
|
+
return (hash >>> 0).toString(16).padStart(8, "0") + Date.now().toString(16);
|
|
42
|
+
}
|
|
43
|
+
// ─── Identity Registry ──────────────────────────────────────────────────────
|
|
44
|
+
class IdentityRegistry {
|
|
45
|
+
identities = new Map();
|
|
46
|
+
tokens = new Map();
|
|
47
|
+
agentTokens = new Map(); // agentId → token IDs
|
|
48
|
+
/**
|
|
49
|
+
* Create a new agent identity with a cryptographic keypair.
|
|
50
|
+
*/
|
|
51
|
+
createIdentity(agentId, ownerId, ownerEmail, options) {
|
|
52
|
+
if (this.identities.has(agentId)) {
|
|
53
|
+
throw new Error(`Agent identity already exists: ${agentId}`);
|
|
54
|
+
}
|
|
55
|
+
const { publicKey, privateKey } = generateKeyPair();
|
|
56
|
+
const now = new Date().toISOString();
|
|
57
|
+
const identity = {
|
|
58
|
+
agentId,
|
|
59
|
+
publicKey,
|
|
60
|
+
privateKey,
|
|
61
|
+
ownerId,
|
|
62
|
+
displayName: options?.displayName,
|
|
63
|
+
capabilities: options?.capabilities ?? [],
|
|
64
|
+
createdAt: now,
|
|
65
|
+
lastActiveAt: now,
|
|
66
|
+
verified: false,
|
|
67
|
+
kya: {
|
|
68
|
+
ownerType: options?.ownerType ?? "individual",
|
|
69
|
+
ownerEmail,
|
|
70
|
+
ownerCountry: options?.ownerCountry,
|
|
71
|
+
ownerKycStatus: "unverified",
|
|
72
|
+
financialAuthorized: false,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
this.identities.set(agentId, identity);
|
|
76
|
+
return identity;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get an agent's identity (public info only — strips private key).
|
|
80
|
+
*/
|
|
81
|
+
getIdentity(agentId) {
|
|
82
|
+
const identity = this.identities.get(agentId);
|
|
83
|
+
if (!identity)
|
|
84
|
+
return null;
|
|
85
|
+
const { privateKey: _, ...publicIdentity } = identity;
|
|
86
|
+
return publicIdentity;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Verify an agent's KYC status (mark as verified after external check).
|
|
90
|
+
*/
|
|
91
|
+
verifyKYC(agentId) {
|
|
92
|
+
const identity = this.identities.get(agentId);
|
|
93
|
+
if (!identity)
|
|
94
|
+
throw new Error(`Unknown agent: ${agentId}`);
|
|
95
|
+
identity.kya.ownerKycStatus = "verified";
|
|
96
|
+
identity.kya.kycVerifiedAt = new Date().toISOString();
|
|
97
|
+
identity.kya.financialAuthorized = true;
|
|
98
|
+
identity.verified = true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Issue a scoped capability token to an agent.
|
|
102
|
+
*/
|
|
103
|
+
issueToken(agentId, permissions, options) {
|
|
104
|
+
const identity = this.identities.get(agentId);
|
|
105
|
+
if (!identity)
|
|
106
|
+
throw new Error(`Unknown agent: ${agentId}`);
|
|
107
|
+
const now = new Date();
|
|
108
|
+
const expiresInMs = (options?.expiresInMinutes ?? 60) * 60_000;
|
|
109
|
+
const token = {
|
|
110
|
+
id: crypto.randomUUID(),
|
|
111
|
+
agentId,
|
|
112
|
+
permissions,
|
|
113
|
+
maxAmount: options?.maxAmount,
|
|
114
|
+
maxTotalSpend: options?.maxTotalSpend,
|
|
115
|
+
totalSpent: 0,
|
|
116
|
+
allowedCounterparties: options?.allowedCounterparties ?? [],
|
|
117
|
+
allowedCategories: options?.allowedCategories ?? [],
|
|
118
|
+
issuedAt: now.toISOString(),
|
|
119
|
+
expiresAt: new Date(now.getTime() + expiresInMs).toISOString(),
|
|
120
|
+
revoked: false,
|
|
121
|
+
issuedBy: options?.issuedBy ?? identity.ownerId,
|
|
122
|
+
};
|
|
123
|
+
this.tokens.set(token.id, token);
|
|
124
|
+
// Track tokens per agent
|
|
125
|
+
if (!this.agentTokens.has(agentId)) {
|
|
126
|
+
this.agentTokens.set(agentId, new Set());
|
|
127
|
+
}
|
|
128
|
+
this.agentTokens.get(agentId).add(token.id);
|
|
129
|
+
return token;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Validate a capability token for a specific action.
|
|
133
|
+
*/
|
|
134
|
+
validateToken(tokenId, action, amount, counterpartyId) {
|
|
135
|
+
const token = this.tokens.get(tokenId);
|
|
136
|
+
if (!token) {
|
|
137
|
+
return { valid: false, agentId: "", reason: "Token not found" };
|
|
138
|
+
}
|
|
139
|
+
if (token.revoked) {
|
|
140
|
+
return { valid: false, agentId: token.agentId, reason: "Token has been revoked" };
|
|
141
|
+
}
|
|
142
|
+
// Check expiry
|
|
143
|
+
if (new Date() > new Date(token.expiresAt)) {
|
|
144
|
+
return { valid: false, agentId: token.agentId, reason: "Token has expired" };
|
|
145
|
+
}
|
|
146
|
+
// Check permission
|
|
147
|
+
if (!token.permissions.includes(action) && !token.permissions.includes("admin")) {
|
|
148
|
+
return { valid: false, agentId: token.agentId, reason: `Token does not grant '${action}' permission` };
|
|
149
|
+
}
|
|
150
|
+
// Check per-transaction amount limit
|
|
151
|
+
if (amount !== undefined && token.maxAmount !== undefined && amount > token.maxAmount) {
|
|
152
|
+
return {
|
|
153
|
+
valid: false,
|
|
154
|
+
agentId: token.agentId,
|
|
155
|
+
reason: `Amount $${amount} exceeds token limit $${token.maxAmount}`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Check total spend limit
|
|
159
|
+
if (amount !== undefined && token.maxTotalSpend !== undefined) {
|
|
160
|
+
if (token.totalSpent + amount > token.maxTotalSpend) {
|
|
161
|
+
return {
|
|
162
|
+
valid: false,
|
|
163
|
+
agentId: token.agentId,
|
|
164
|
+
reason: `Total spend would exceed limit ($${token.totalSpent + amount} > $${token.maxTotalSpend})`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Check counterparty whitelist
|
|
169
|
+
if (counterpartyId && token.allowedCounterparties.length > 0) {
|
|
170
|
+
if (!token.allowedCounterparties.includes(counterpartyId)) {
|
|
171
|
+
return {
|
|
172
|
+
valid: false,
|
|
173
|
+
agentId: token.agentId,
|
|
174
|
+
reason: `Counterparty '${counterpartyId}' not in allowed list`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const identity = this.identities.get(token.agentId);
|
|
179
|
+
return {
|
|
180
|
+
valid: true,
|
|
181
|
+
agentId: token.agentId,
|
|
182
|
+
identity: identity ? { ...identity, privateKey: "[redacted]" } : undefined,
|
|
183
|
+
activeToken: token,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Record spending against a token's total spend limit.
|
|
188
|
+
*/
|
|
189
|
+
recordSpend(tokenId, amount) {
|
|
190
|
+
const token = this.tokens.get(tokenId);
|
|
191
|
+
if (!token)
|
|
192
|
+
throw new Error(`Token not found: ${tokenId}`);
|
|
193
|
+
token.totalSpent += amount;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Revoke a capability token immediately.
|
|
197
|
+
*/
|
|
198
|
+
revokeToken(tokenId) {
|
|
199
|
+
const token = this.tokens.get(tokenId);
|
|
200
|
+
if (!token)
|
|
201
|
+
throw new Error(`Token not found: ${tokenId}`);
|
|
202
|
+
token.revoked = true;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Revoke ALL tokens for an agent (kill switch).
|
|
206
|
+
*/
|
|
207
|
+
revokeAllTokens(agentId) {
|
|
208
|
+
const tokenIds = this.agentTokens.get(agentId);
|
|
209
|
+
if (!tokenIds)
|
|
210
|
+
return 0;
|
|
211
|
+
let revoked = 0;
|
|
212
|
+
for (const id of tokenIds) {
|
|
213
|
+
const token = this.tokens.get(id);
|
|
214
|
+
if (token && !token.revoked) {
|
|
215
|
+
token.revoked = true;
|
|
216
|
+
revoked++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return revoked;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* List all active (non-revoked, non-expired) tokens for an agent.
|
|
223
|
+
*/
|
|
224
|
+
listActiveTokens(agentId) {
|
|
225
|
+
const tokenIds = this.agentTokens.get(agentId);
|
|
226
|
+
if (!tokenIds)
|
|
227
|
+
return [];
|
|
228
|
+
const now = new Date();
|
|
229
|
+
return Array.from(tokenIds)
|
|
230
|
+
.map(id => this.tokens.get(id))
|
|
231
|
+
.filter(t => !t.revoked && new Date(t.expiresAt) > now);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Update last active timestamp (call on any agent activity).
|
|
235
|
+
*/
|
|
236
|
+
touch(agentId) {
|
|
237
|
+
const identity = this.identities.get(agentId);
|
|
238
|
+
if (identity) {
|
|
239
|
+
identity.lastActiveAt = new Date().toISOString();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Sign a message with an agent's private key (for inter-agent verification).
|
|
244
|
+
*/
|
|
245
|
+
sign(agentId, message) {
|
|
246
|
+
const identity = this.identities.get(agentId);
|
|
247
|
+
if (!identity)
|
|
248
|
+
throw new Error(`Unknown agent: ${agentId}`);
|
|
249
|
+
return signMessage(message, identity.privateKey);
|
|
250
|
+
}
|
|
251
|
+
// ── Serialization ────────────────────────────────────────────────────────
|
|
252
|
+
serialize() {
|
|
253
|
+
return {
|
|
254
|
+
identities: Array.from(this.identities.values()),
|
|
255
|
+
tokens: Array.from(this.tokens.values()),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
static deserialize(data) {
|
|
259
|
+
const registry = new IdentityRegistry();
|
|
260
|
+
for (const id of data.identities) {
|
|
261
|
+
registry.identities.set(id.agentId, id);
|
|
262
|
+
}
|
|
263
|
+
for (const token of data.tokens) {
|
|
264
|
+
registry.tokens.set(token.id, token);
|
|
265
|
+
if (!registry.agentTokens.has(token.agentId)) {
|
|
266
|
+
registry.agentTokens.set(token.agentId, new Set());
|
|
267
|
+
}
|
|
268
|
+
registry.agentTokens.get(token.agentId).add(token.id);
|
|
269
|
+
}
|
|
270
|
+
return registry;
|
|
271
|
+
}
|
|
272
|
+
get size() {
|
|
273
|
+
return this.identities.size;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.IdentityRegistry = IdentityRegistry;
|
|
277
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAwFH,+EAA+E;AAE/E,SAAS,eAAe;IACtB,+CAA+C;IAC/C,6CAA6C;IAC7C,0EAA0E;IAC1E,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,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A7RD,4CA6RC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { type RecallStrategy, type EmbeddingProvider, type RecallEngineConfig }
|
|
|
13
13
|
import { FraudGuard, type FraudConfig, type Dispute, type RequestContext } from "./fraud.js";
|
|
14
14
|
import { type PaymentRail } from "./rails/index.js";
|
|
15
15
|
import { type StorageAdapter } from "./storage/sqlite.js";
|
|
16
|
+
import { Ledger, type LedgerEntry, type LedgerSummary, type AccountBalance, type Currency } from "./ledger.js";
|
|
17
|
+
import { IdentityRegistry } from "./identity.js";
|
|
16
18
|
type Listener = (...args: any[]) => void;
|
|
17
19
|
declare class EventEmitter {
|
|
18
20
|
private _events;
|
|
@@ -175,6 +177,10 @@ export declare class MnemoPayLite extends EventEmitter {
|
|
|
175
177
|
readonly paymentRail: PaymentRail;
|
|
176
178
|
/** When true, settle() requires a different agentId than the charge creator */
|
|
177
179
|
readonly requireCounterparty: boolean;
|
|
180
|
+
/** Double-entry ledger — every financial operation is tracked with debit+credit pairs */
|
|
181
|
+
readonly ledger: Ledger;
|
|
182
|
+
/** Agent identity registry — cryptographic identity, KYA compliance, capability tokens */
|
|
183
|
+
readonly identity: IdentityRegistry;
|
|
178
184
|
constructor(agentId: string, decay?: number, debug?: boolean, recallConfig?: Partial<RecallEngineConfig>, fraudConfig?: Partial<FraudConfig>, paymentRail?: PaymentRail, requireCounterparty?: boolean, storage?: StorageAdapter);
|
|
179
185
|
enablePersistence(dir: string): void;
|
|
180
186
|
private _loadFromDisk;
|
|
@@ -195,6 +201,20 @@ export declare class MnemoPayLite extends EventEmitter {
|
|
|
195
201
|
dispute(txId: string, reason: string, evidence?: string[]): Promise<Dispute>;
|
|
196
202
|
resolveDispute(disputeId: string, outcome: "refund" | "uphold"): Promise<Dispute>;
|
|
197
203
|
balance(): Promise<BalanceInfo>;
|
|
204
|
+
/**
|
|
205
|
+
* Get the ledger balance for this agent (computed from double-entry records).
|
|
206
|
+
* This is the source of truth — should match this._wallet.
|
|
207
|
+
*/
|
|
208
|
+
ledgerBalance(currency?: Currency): Promise<AccountBalance>;
|
|
209
|
+
/**
|
|
210
|
+
* Verify the entire ledger balances (total debits = total credits).
|
|
211
|
+
* If imbalance !== 0, there's a bug.
|
|
212
|
+
*/
|
|
213
|
+
verifyLedger(): Promise<LedgerSummary>;
|
|
214
|
+
/**
|
|
215
|
+
* Get all ledger entries for a specific transaction.
|
|
216
|
+
*/
|
|
217
|
+
ledgerEntries(txId: string): Promise<LedgerEntry[]>;
|
|
198
218
|
profile(): Promise<AgentProfile>;
|
|
199
219
|
logs(limit?: number): Promise<AuditEntry[]>;
|
|
200
220
|
history(limit?: number): Promise<Transaction[]>;
|
|
@@ -271,12 +291,18 @@ export { autoScore, computeScore, reputationTier };
|
|
|
271
291
|
export { RecallEngine, cosineSimilarity, localEmbed, l2Normalize } from "./recall/engine.js";
|
|
272
292
|
export type { RecallStrategy, EmbeddingProvider, RecallEngineConfig, RecallResult } from "./recall/engine.js";
|
|
273
293
|
export { FraudGuard, RateLimiter, DEFAULT_FRAUD_CONFIG, DEFAULT_RATE_LIMIT } from "./fraud.js";
|
|
274
|
-
export type { FraudConfig, FraudSignal, RiskAssessment, Dispute, PlatformFeeRecord, RequestContext, RateLimitConfig } from "./fraud.js";
|
|
294
|
+
export type { FraudConfig, FeeTier, FraudSignal, RiskAssessment, Dispute, PlatformFeeRecord, RequestContext, RateLimitConfig, GeoProfile, GeoFraudConfig } from "./fraud.js";
|
|
275
295
|
export { IsolationForest, TransactionGraph, BehaviorProfile } from "./fraud-ml.js";
|
|
276
296
|
export type { CollusionSignal, DriftSignal, BehaviorSnapshot } from "./fraud-ml.js";
|
|
277
|
-
export { MockRail, StripeRail, LightningRail } from "./rails/index.js";
|
|
278
|
-
export type { PaymentRail, PaymentRailResult } from "./rails/index.js";
|
|
297
|
+
export { MockRail, StripeRail, LightningRail, PaystackRail, NIGERIAN_BANKS } from "./rails/index.js";
|
|
298
|
+
export type { PaymentRail, PaymentRailResult, PaystackConfig, PaystackCurrency, PaystackHoldResult, PaystackVerifyResult, PaystackTransferRecipient, PaystackTransferResult, PaystackWebhookEvent } from "./rails/index.js";
|
|
279
299
|
export { SQLiteStorage, JSONFileStorage } from "./storage/sqlite.js";
|
|
280
300
|
export type { StorageAdapter, PersistedState } from "./storage/sqlite.js";
|
|
301
|
+
export { Ledger } from "./ledger.js";
|
|
302
|
+
export type { LedgerEntry, LedgerSummary, AccountBalance, Currency, AccountType, TransferResult } from "./ledger.js";
|
|
303
|
+
export { IdentityRegistry } from "./identity.js";
|
|
304
|
+
export type { AgentIdentity, CapabilityToken, Permission, IdentityVerification, KYARecord } from "./identity.js";
|
|
305
|
+
export { MnemoPayNetwork } from "./network.js";
|
|
306
|
+
export type { NetworkAgent, DealResult, NetworkStats, NetworkConfig } from "./network.js";
|
|
281
307
|
export { default as createSandboxServer } from "./mcp/server.js";
|
|
282
308
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAgB,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAuB,KAAK,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAC1I,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAgB,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,C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W,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,13 +14,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createSandboxServer = exports.JSONFileStorage = exports.SQLiteStorage = exports.LightningRail = exports.StripeRail = exports.MockRail = exports.BehaviorProfile = exports.TransactionGraph = exports.IsolationForest = exports.DEFAULT_RATE_LIMIT = exports.DEFAULT_FRAUD_CONFIG = exports.RateLimiter = exports.FraudGuard = exports.l2Normalize = exports.localEmbed = exports.cosineSimilarity = exports.RecallEngine = exports.MnemoPay = exports.MnemoPayLite = void 0;
|
|
17
|
+
exports.createSandboxServer = exports.MnemoPayNetwork = exports.IdentityRegistry = exports.Ledger = exports.JSONFileStorage = exports.SQLiteStorage = exports.NIGERIAN_BANKS = exports.PaystackRail = exports.LightningRail = exports.StripeRail = exports.MockRail = exports.BehaviorProfile = exports.TransactionGraph = exports.IsolationForest = exports.DEFAULT_RATE_LIMIT = exports.DEFAULT_FRAUD_CONFIG = exports.RateLimiter = exports.FraudGuard = exports.l2Normalize = exports.localEmbed = exports.cosineSimilarity = exports.RecallEngine = exports.MnemoPay = exports.MnemoPayLite = void 0;
|
|
18
18
|
exports.autoScore = autoScore;
|
|
19
19
|
exports.computeScore = computeScore;
|
|
20
20
|
exports.reputationTier = reputationTier;
|
|
21
21
|
const engine_js_1 = require("./recall/engine.js");
|
|
22
22
|
const fraud_js_1 = require("./fraud.js");
|
|
23
23
|
const index_js_1 = require("./rails/index.js");
|
|
24
|
+
const ledger_js_1 = require("./ledger.js");
|
|
25
|
+
const identity_js_1 = require("./identity.js");
|
|
24
26
|
class EventEmitter {
|
|
25
27
|
_events = new Map();
|
|
26
28
|
on(event, fn) {
|
|
@@ -115,6 +117,10 @@ class MnemoPayLite extends EventEmitter {
|
|
|
115
117
|
paymentRail;
|
|
116
118
|
/** When true, settle() requires a different agentId than the charge creator */
|
|
117
119
|
requireCounterparty;
|
|
120
|
+
/** Double-entry ledger — every financial operation is tracked with debit+credit pairs */
|
|
121
|
+
ledger;
|
|
122
|
+
/** Agent identity registry — cryptographic identity, KYA compliance, capability tokens */
|
|
123
|
+
identity;
|
|
118
124
|
constructor(agentId, decay = 0.05, debug = false, recallConfig, fraudConfig, paymentRail, requireCounterparty = false, storage) {
|
|
119
125
|
super();
|
|
120
126
|
this.agentId = agentId;
|
|
@@ -124,6 +130,8 @@ class MnemoPayLite extends EventEmitter {
|
|
|
124
130
|
this.fraud = new fraud_js_1.FraudGuard(fraudConfig);
|
|
125
131
|
this.paymentRail = paymentRail ?? new index_js_1.MockRail();
|
|
126
132
|
this.requireCounterparty = requireCounterparty;
|
|
133
|
+
this.ledger = new ledger_js_1.Ledger();
|
|
134
|
+
this.identity = new identity_js_1.IdentityRegistry();
|
|
127
135
|
// Use provided storage adapter, or auto-detect persistence
|
|
128
136
|
if (storage) {
|
|
129
137
|
this.storageAdapter = storage;
|
|
@@ -202,6 +210,21 @@ class MnemoPayLite extends EventEmitter {
|
|
|
202
210
|
if (raw.auditLog) {
|
|
203
211
|
this.auditLog = raw.auditLog.map((e) => ({ ...e, createdAt: new Date(e.createdAt) }));
|
|
204
212
|
}
|
|
213
|
+
// Restore ledger entries
|
|
214
|
+
if (raw.ledger && Array.isArray(raw.ledger)) {
|
|
215
|
+
this.ledger = new ledger_js_1.Ledger(raw.ledger);
|
|
216
|
+
this.log(`Restored ${raw.ledger.length} ledger entries`);
|
|
217
|
+
}
|
|
218
|
+
// Restore identity registry
|
|
219
|
+
if (raw.identity) {
|
|
220
|
+
try {
|
|
221
|
+
this.identity = identity_js_1.IdentityRegistry.deserialize(raw.identity);
|
|
222
|
+
this.log(`Restored ${raw.identity.identities?.length ?? 0} identities`);
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
this.log(`Failed to restore identity registry: ${e}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
205
228
|
// Restore fraud guard state
|
|
206
229
|
if (raw.fraudGuard) {
|
|
207
230
|
try {
|
|
@@ -325,6 +348,8 @@ class MnemoPayLite extends EventEmitter {
|
|
|
325
348
|
transactions: Array.from(this.transactions.values()),
|
|
326
349
|
auditLog: this.auditLog.slice(-500), // Keep last 500 entries
|
|
327
350
|
fraudGuard: this.fraud.serialize(),
|
|
351
|
+
ledger: this.ledger.serialize(),
|
|
352
|
+
identity: this.identity.serialize(),
|
|
328
353
|
savedAt: new Date().toISOString(),
|
|
329
354
|
});
|
|
330
355
|
// Atomic write
|
|
@@ -352,6 +377,10 @@ class MnemoPayLite extends EventEmitter {
|
|
|
352
377
|
}
|
|
353
378
|
// ── Memory Methods ──────────────────────────────────────────────────────
|
|
354
379
|
async remember(content, opts) {
|
|
380
|
+
if (!content || typeof content !== "string")
|
|
381
|
+
throw new Error("Memory content is required");
|
|
382
|
+
if (content.length > 100_000)
|
|
383
|
+
throw new Error("Memory content exceeds 100KB limit");
|
|
355
384
|
const importance = opts?.importance ?? autoScore(content);
|
|
356
385
|
const now = new Date();
|
|
357
386
|
const mem = {
|
|
@@ -450,8 +479,12 @@ class MnemoPayLite extends EventEmitter {
|
|
|
450
479
|
}
|
|
451
480
|
// ── Payment Methods ─────────────────────────────────────────────────────
|
|
452
481
|
async charge(amount, reason, ctx) {
|
|
453
|
-
if (amount <= 0)
|
|
454
|
-
throw new Error("Amount must be positive");
|
|
482
|
+
if (!Number.isFinite(amount) || amount <= 0)
|
|
483
|
+
throw new Error("Amount must be a positive finite number");
|
|
484
|
+
// Round to 2 decimals to prevent floating point dust
|
|
485
|
+
amount = Math.round(amount * 100) / 100;
|
|
486
|
+
if (!reason || typeof reason !== "string")
|
|
487
|
+
throw new Error("Reason is required");
|
|
455
488
|
const maxCharge = 500 * this._reputation;
|
|
456
489
|
if (amount > maxCharge) {
|
|
457
490
|
throw new Error(`Amount $${amount.toFixed(2)} exceeds reputation ceiling $${maxCharge.toFixed(2)} ` +
|
|
@@ -486,6 +519,8 @@ class MnemoPayLite extends EventEmitter {
|
|
|
486
519
|
externalStatus: hold.status,
|
|
487
520
|
};
|
|
488
521
|
this.transactions.set(tx.id, tx);
|
|
522
|
+
// Ledger: move funds from agent available → escrow
|
|
523
|
+
this.ledger.recordCharge(this.agentId, amount, tx.id);
|
|
489
524
|
this.audit("payment:pending", { id: tx.id, amount, reason, riskScore: risk.score, rail: this.paymentRail.name, externalId: hold.externalId });
|
|
490
525
|
this._saveToDisk();
|
|
491
526
|
this.emit("payment:pending", { id: tx.id, amount, reason });
|
|
@@ -493,6 +528,8 @@ class MnemoPayLite extends EventEmitter {
|
|
|
493
528
|
return { ...tx };
|
|
494
529
|
}
|
|
495
530
|
async settle(txId, counterpartyId) {
|
|
531
|
+
if (!txId || typeof txId !== "string")
|
|
532
|
+
throw new Error("Transaction ID is required");
|
|
496
533
|
const tx = this.transactions.get(txId);
|
|
497
534
|
if (!tx)
|
|
498
535
|
throw new Error(`Transaction ${txId} not found`);
|
|
@@ -521,6 +558,8 @@ class MnemoPayLite extends EventEmitter {
|
|
|
521
558
|
tx.status = "completed";
|
|
522
559
|
tx.completedAt = new Date();
|
|
523
560
|
this._wallet += fee.netAmount;
|
|
561
|
+
// Ledger: escrow → float → revenue (fee) + counterparty/agent (net)
|
|
562
|
+
this.ledger.recordSettlement(this.agentId, tx.id, tx.amount, fee.feeAmount, fee.netAmount, tx.counterpartyId);
|
|
524
563
|
// 3. Boost reputation
|
|
525
564
|
this._reputation = Math.min(this._reputation + 0.01, 1.0);
|
|
526
565
|
// 4. Reinforce recently-accessed memories (feedback loop)
|
|
@@ -532,9 +571,12 @@ class MnemoPayLite extends EventEmitter {
|
|
|
532
571
|
reinforced++;
|
|
533
572
|
}
|
|
534
573
|
}
|
|
574
|
+
// Touch identity (update last active)
|
|
575
|
+
this.identity.touch(this.agentId);
|
|
535
576
|
this.audit("payment:completed", {
|
|
536
577
|
id: tx.id, grossAmount: tx.amount, platformFee: fee.feeAmount,
|
|
537
|
-
netAmount: fee.netAmount, feeRate: fee.feeRate,
|
|
578
|
+
netAmount: fee.netAmount, feeRate: fee.feeRate,
|
|
579
|
+
reinforcedMemories: reinforced,
|
|
538
580
|
});
|
|
539
581
|
this._saveToDisk();
|
|
540
582
|
this.emit("payment:completed", { id: tx.id, amount: fee.netAmount, fee: fee.feeAmount });
|
|
@@ -558,6 +600,12 @@ class MnemoPayLite extends EventEmitter {
|
|
|
558
600
|
const refundAmount = tx.netAmount ?? tx.amount;
|
|
559
601
|
this._wallet = Math.max(this._wallet - refundAmount, 0);
|
|
560
602
|
this._reputation = Math.max(this._reputation - 0.05, 0);
|
|
603
|
+
// Ledger: reverse the net settlement
|
|
604
|
+
this.ledger.recordRefund(this.agentId, tx.id, refundAmount, tx.counterpartyId);
|
|
605
|
+
}
|
|
606
|
+
else if (tx.status === "pending") {
|
|
607
|
+
// Ledger: release escrow back to agent
|
|
608
|
+
this.ledger.recordCancellation(this.agentId, tx.amount, tx.id);
|
|
561
609
|
}
|
|
562
610
|
tx.status = "refunded";
|
|
563
611
|
this.audit("payment:refunded", { id: tx.id, amount: tx.amount, netRefunded: tx.netAmount ?? tx.amount });
|
|
@@ -607,7 +655,31 @@ class MnemoPayLite extends EventEmitter {
|
|
|
607
655
|
return d;
|
|
608
656
|
}
|
|
609
657
|
async balance() {
|
|
610
|
-
|
|
658
|
+
// Round to 2 decimals to prevent floating point dust accumulation
|
|
659
|
+
return {
|
|
660
|
+
wallet: Math.round(this._wallet * 100) / 100,
|
|
661
|
+
reputation: this._reputation,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Get the ledger balance for this agent (computed from double-entry records).
|
|
666
|
+
* This is the source of truth — should match this._wallet.
|
|
667
|
+
*/
|
|
668
|
+
async ledgerBalance(currency = "USD") {
|
|
669
|
+
return this.ledger.getAccountBalance(`agent:${this.agentId}`, currency);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Verify the entire ledger balances (total debits = total credits).
|
|
673
|
+
* If imbalance !== 0, there's a bug.
|
|
674
|
+
*/
|
|
675
|
+
async verifyLedger() {
|
|
676
|
+
return this.ledger.verify();
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Get all ledger entries for a specific transaction.
|
|
680
|
+
*/
|
|
681
|
+
async ledgerEntries(txId) {
|
|
682
|
+
return this.ledger.getEntriesForTransaction(txId);
|
|
611
683
|
}
|
|
612
684
|
// ── Observability ───────────────────────────────────────────────────────
|
|
613
685
|
async profile() {
|
|
@@ -663,7 +735,7 @@ class MnemoPayLite extends EventEmitter {
|
|
|
663
735
|
name: `MnemoPay Agent (${this.agentId})`,
|
|
664
736
|
description: "AI agent with persistent cognitive memory and micropayment capabilities via MnemoPay protocol.",
|
|
665
737
|
url,
|
|
666
|
-
version: "0.
|
|
738
|
+
version: "0.8.0",
|
|
667
739
|
capabilities: {
|
|
668
740
|
memory: true,
|
|
669
741
|
payments: true,
|
|
@@ -1002,7 +1074,7 @@ class MnemoPay extends EventEmitter {
|
|
|
1002
1074
|
name: `MnemoPay Agent (${this.agentId})`,
|
|
1003
1075
|
description: "AI agent with persistent cognitive memory and micropayment capabilities via MnemoPay protocol.",
|
|
1004
1076
|
url,
|
|
1005
|
-
version: "0.
|
|
1077
|
+
version: "0.8.0",
|
|
1006
1078
|
capabilities: {
|
|
1007
1079
|
memory: true,
|
|
1008
1080
|
payments: true,
|
|
@@ -1104,9 +1176,17 @@ var index_js_2 = require("./rails/index.js");
|
|
|
1104
1176
|
Object.defineProperty(exports, "MockRail", { enumerable: true, get: function () { return index_js_2.MockRail; } });
|
|
1105
1177
|
Object.defineProperty(exports, "StripeRail", { enumerable: true, get: function () { return index_js_2.StripeRail; } });
|
|
1106
1178
|
Object.defineProperty(exports, "LightningRail", { enumerable: true, get: function () { return index_js_2.LightningRail; } });
|
|
1179
|
+
Object.defineProperty(exports, "PaystackRail", { enumerable: true, get: function () { return index_js_2.PaystackRail; } });
|
|
1180
|
+
Object.defineProperty(exports, "NIGERIAN_BANKS", { enumerable: true, get: function () { return index_js_2.NIGERIAN_BANKS; } });
|
|
1107
1181
|
var sqlite_js_1 = require("./storage/sqlite.js");
|
|
1108
1182
|
Object.defineProperty(exports, "SQLiteStorage", { enumerable: true, get: function () { return sqlite_js_1.SQLiteStorage; } });
|
|
1109
1183
|
Object.defineProperty(exports, "JSONFileStorage", { enumerable: true, get: function () { return sqlite_js_1.JSONFileStorage; } });
|
|
1184
|
+
var ledger_js_2 = require("./ledger.js");
|
|
1185
|
+
Object.defineProperty(exports, "Ledger", { enumerable: true, get: function () { return ledger_js_2.Ledger; } });
|
|
1186
|
+
var identity_js_2 = require("./identity.js");
|
|
1187
|
+
Object.defineProperty(exports, "IdentityRegistry", { enumerable: true, get: function () { return identity_js_2.IdentityRegistry; } });
|
|
1188
|
+
var network_js_1 = require("./network.js");
|
|
1189
|
+
Object.defineProperty(exports, "MnemoPayNetwork", { enumerable: true, get: function () { return network_js_1.MnemoPayNetwork; } });
|
|
1110
1190
|
var server_js_1 = require("./mcp/server.js");
|
|
1111
1191
|
Object.defineProperty(exports, "createSandboxServer", { enumerable: true, get: function () { return __importDefault(server_js_1).default; } });
|
|
1112
1192
|
//# sourceMappingURL=index.js.map
|