@mnemopay/sdk 0.7.4 → 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 +266 -193
- 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 +23 -10
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MnemoPay Network — Multi-Agent Transaction Orchestration
|
|
3
|
+
*
|
|
4
|
+
* Enables agent-to-agent commerce where both parties have memory,
|
|
5
|
+
* identity, and a shared transaction context. This is the developer
|
|
6
|
+
* primitive that no competitor offers:
|
|
7
|
+
*
|
|
8
|
+
* const net = new MnemoPayNetwork();
|
|
9
|
+
* const buyer = net.register("buyer-agent", "owner-1", "dev@co.com");
|
|
10
|
+
* const seller = net.register("seller-agent", "owner-2", "dev@co.com");
|
|
11
|
+
* const deal = await net.transact(buyer, seller, 25, "API access for 1 month");
|
|
12
|
+
* // Both agents now remember the deal. Seller got paid. Buyer's memory
|
|
13
|
+
* // links this purchase to the outcome. Identities verified. Ledger balanced.
|
|
14
|
+
*
|
|
15
|
+
* Developer-first: one class, one method, full lifecycle.
|
|
16
|
+
*/
|
|
17
|
+
import { MnemoPayLite, type Transaction } from "./index.js";
|
|
18
|
+
import { IdentityRegistry, type Permission, type CapabilityToken } from "./identity.js";
|
|
19
|
+
import { Ledger } from "./ledger.js";
|
|
20
|
+
import type { FraudConfig } from "./fraud.js";
|
|
21
|
+
import type { PaymentRail } from "./rails/index.js";
|
|
22
|
+
export interface NetworkAgent {
|
|
23
|
+
/** The MnemoPayLite instance */
|
|
24
|
+
instance: MnemoPayLite;
|
|
25
|
+
/** Agent's display name */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Owner who registered this agent */
|
|
28
|
+
ownerId: string;
|
|
29
|
+
/** Active capability token */
|
|
30
|
+
token?: CapabilityToken;
|
|
31
|
+
}
|
|
32
|
+
export interface DealResult {
|
|
33
|
+
/** Unique deal ID */
|
|
34
|
+
dealId: string;
|
|
35
|
+
/** The charge transaction */
|
|
36
|
+
charge: Transaction;
|
|
37
|
+
/** The settled transaction (after settle) */
|
|
38
|
+
settlement?: Transaction;
|
|
39
|
+
/** Buyer's memory ID for this deal */
|
|
40
|
+
buyerMemoryId: string;
|
|
41
|
+
/** Seller's memory ID for this deal */
|
|
42
|
+
sellerMemoryId: string;
|
|
43
|
+
/** Fee deducted */
|
|
44
|
+
platformFee: number;
|
|
45
|
+
/** Net amount seller received */
|
|
46
|
+
netAmount: number;
|
|
47
|
+
/** Timestamp */
|
|
48
|
+
timestamp: string;
|
|
49
|
+
}
|
|
50
|
+
export interface NetworkStats {
|
|
51
|
+
/** Total registered agents */
|
|
52
|
+
agentCount: number;
|
|
53
|
+
/** Total completed deals */
|
|
54
|
+
dealCount: number;
|
|
55
|
+
/** Total volume transacted (gross) */
|
|
56
|
+
totalVolume: number;
|
|
57
|
+
/** Total platform fees collected */
|
|
58
|
+
totalFees: number;
|
|
59
|
+
/** Active agents (transacted in last hour) */
|
|
60
|
+
activeAgents: number;
|
|
61
|
+
/** Ledger balanced */
|
|
62
|
+
ledgerBalanced: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface NetworkConfig {
|
|
65
|
+
/** Fraud config applied to all agents */
|
|
66
|
+
fraud?: Partial<FraudConfig>;
|
|
67
|
+
/** Payment rail for all agents */
|
|
68
|
+
paymentRail?: PaymentRail;
|
|
69
|
+
/** Auto-verify KYC on registration (dev/testing mode). Default: true */
|
|
70
|
+
autoVerifyKyc?: boolean;
|
|
71
|
+
/** Default permissions for new agent tokens */
|
|
72
|
+
defaultPermissions?: Permission[];
|
|
73
|
+
/** Token expiry in minutes. Default: 1440 (24h) */
|
|
74
|
+
tokenExpiryMinutes?: number;
|
|
75
|
+
/** Debug logging */
|
|
76
|
+
debug?: boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare class MnemoPayNetwork {
|
|
79
|
+
private agents;
|
|
80
|
+
private deals;
|
|
81
|
+
private _totalVolume;
|
|
82
|
+
private _totalFees;
|
|
83
|
+
/** Shared identity registry — all agents on this network share it */
|
|
84
|
+
readonly identity: IdentityRegistry;
|
|
85
|
+
/** Shared ledger — single source of truth for all money movement */
|
|
86
|
+
readonly ledger: Ledger;
|
|
87
|
+
/** Network configuration */
|
|
88
|
+
readonly config: Required<NetworkConfig>;
|
|
89
|
+
constructor(config?: NetworkConfig);
|
|
90
|
+
/**
|
|
91
|
+
* Register an agent on the network. Returns the MnemoPayLite instance.
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* const buyer = net.register("buyer-bot", "jerry", "jerry@example.com");
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
register(agentId: string, ownerId: string, ownerEmail: string, options?: {
|
|
98
|
+
displayName?: string;
|
|
99
|
+
capabilities?: string[];
|
|
100
|
+
permissions?: Permission[];
|
|
101
|
+
maxAmount?: number;
|
|
102
|
+
maxTotalSpend?: number;
|
|
103
|
+
}): MnemoPayLite;
|
|
104
|
+
/**
|
|
105
|
+
* Get a registered agent's MnemoPayLite instance.
|
|
106
|
+
*/
|
|
107
|
+
getAgent(agentId: string): MnemoPayLite | null;
|
|
108
|
+
/**
|
|
109
|
+
* Execute a full buyer→seller transaction with shared memory context.
|
|
110
|
+
*
|
|
111
|
+
* Both agents remember the deal. The buyer's charge flows through escrow,
|
|
112
|
+
* platform fee is deducted, and the seller receives the net amount.
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* const deal = await net.transact("buyer-bot", "seller-bot", 25, "API access");
|
|
116
|
+
* // deal.buyerMemoryId — buyer remembers what they paid for
|
|
117
|
+
* // deal.sellerMemoryId — seller remembers what they delivered
|
|
118
|
+
* // deal.netAmount — what seller actually received (after 1.9% fee)
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
transact(buyerId: string, sellerId: string, amount: number, reason: string, options?: {
|
|
122
|
+
/** Extra context for buyer's memory */
|
|
123
|
+
buyerContext?: string;
|
|
124
|
+
/** Extra context for seller's memory */
|
|
125
|
+
sellerContext?: string;
|
|
126
|
+
/** Tags for both memories */
|
|
127
|
+
tags?: string[];
|
|
128
|
+
}): Promise<DealResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Refund a deal. Buyer gets money back, both agents remember the refund.
|
|
131
|
+
*/
|
|
132
|
+
refundDeal(dealId: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Network-wide statistics.
|
|
135
|
+
*/
|
|
136
|
+
stats(): NetworkStats;
|
|
137
|
+
/**
|
|
138
|
+
* Get all deals between two agents.
|
|
139
|
+
*/
|
|
140
|
+
dealsBetween(agentA: string, agentB: string): DealResult[];
|
|
141
|
+
/**
|
|
142
|
+
* Get an agent's deal history.
|
|
143
|
+
*/
|
|
144
|
+
agentDeals(agentId: string): DealResult[];
|
|
145
|
+
/**
|
|
146
|
+
* List all registered agent IDs.
|
|
147
|
+
*/
|
|
148
|
+
listAgents(): string[];
|
|
149
|
+
/**
|
|
150
|
+
* Disconnect all agents and clean up.
|
|
151
|
+
*/
|
|
152
|
+
shutdown(): Promise<void>;
|
|
153
|
+
private log;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAiB,EAAE,YAAY,EAAE,KAAK,WAAW,EAAqC,MAAM,YAAY,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,WAAW,YAAY;IAC3B,gCAAgC;IAChC,QAAQ,EAAE,YAAY,CAAC;IACvB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,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AAC;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,YAAY;IA8Cf;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAM9C;;;;;;;;;;;;OAYG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QACR,uCAAuC;QACvC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,wCAAwC;QACxC,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,6BAA6B;QAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,GACA,OAAO,CAAC,UAAU,CAAC;IA4EtB;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+B/C;;OAEG;IACH,KAAK,IAAI,YAAY;IAsBrB;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE;IAO1D;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE;IAMzC;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;IAMtB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B,OAAO,CAAC,GAAG;CAGZ"}
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MnemoPay Network — Multi-Agent Transaction Orchestration
|
|
4
|
+
*
|
|
5
|
+
* Enables agent-to-agent commerce where both parties have memory,
|
|
6
|
+
* identity, and a shared transaction context. This is the developer
|
|
7
|
+
* primitive that no competitor offers:
|
|
8
|
+
*
|
|
9
|
+
* const net = new MnemoPayNetwork();
|
|
10
|
+
* const buyer = net.register("buyer-agent", "owner-1", "dev@co.com");
|
|
11
|
+
* const seller = net.register("seller-agent", "owner-2", "dev@co.com");
|
|
12
|
+
* const deal = await net.transact(buyer, seller, 25, "API access for 1 month");
|
|
13
|
+
* // Both agents now remember the deal. Seller got paid. Buyer's memory
|
|
14
|
+
* // links this purchase to the outcome. Identities verified. Ledger balanced.
|
|
15
|
+
*
|
|
16
|
+
* Developer-first: one class, one method, full lifecycle.
|
|
17
|
+
*/
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.MnemoPayNetwork = void 0;
|
|
23
|
+
const index_js_1 = __importDefault(require("./index.js"));
|
|
24
|
+
const identity_js_1 = require("./identity.js");
|
|
25
|
+
const ledger_js_1 = require("./ledger.js");
|
|
26
|
+
// ─── Network ────────────────────────────────────────────────────────────────
|
|
27
|
+
class MnemoPayNetwork {
|
|
28
|
+
agents = new Map();
|
|
29
|
+
deals = [];
|
|
30
|
+
_totalVolume = 0;
|
|
31
|
+
_totalFees = 0;
|
|
32
|
+
/** Shared identity registry — all agents on this network share it */
|
|
33
|
+
identity;
|
|
34
|
+
/** Shared ledger — single source of truth for all money movement */
|
|
35
|
+
ledger;
|
|
36
|
+
/** Network configuration */
|
|
37
|
+
config;
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.identity = new identity_js_1.IdentityRegistry();
|
|
40
|
+
this.ledger = new ledger_js_1.Ledger();
|
|
41
|
+
this.config = {
|
|
42
|
+
fraud: config?.fraud ?? {},
|
|
43
|
+
paymentRail: config?.paymentRail,
|
|
44
|
+
autoVerifyKyc: config?.autoVerifyKyc ?? true,
|
|
45
|
+
defaultPermissions: config?.defaultPermissions ?? ["charge", "settle", "refund", "remember", "recall"],
|
|
46
|
+
tokenExpiryMinutes: config?.tokenExpiryMinutes ?? 1440,
|
|
47
|
+
debug: config?.debug ?? false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// ── Agent Registration ────────────────────────────────────────────────
|
|
51
|
+
/**
|
|
52
|
+
* Register an agent on the network. Returns the MnemoPayLite instance.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const buyer = net.register("buyer-bot", "jerry", "jerry@example.com");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
register(agentId, ownerId, ownerEmail, options) {
|
|
59
|
+
if (this.agents.has(agentId)) {
|
|
60
|
+
return this.agents.get(agentId).instance;
|
|
61
|
+
}
|
|
62
|
+
// Create identity
|
|
63
|
+
this.identity.createIdentity(agentId, ownerId, ownerEmail, {
|
|
64
|
+
displayName: options?.displayName ?? agentId,
|
|
65
|
+
capabilities: options?.capabilities,
|
|
66
|
+
});
|
|
67
|
+
// Auto-verify in dev mode
|
|
68
|
+
if (this.config.autoVerifyKyc) {
|
|
69
|
+
this.identity.verifyKYC(agentId);
|
|
70
|
+
}
|
|
71
|
+
// Issue capability token
|
|
72
|
+
const token = this.identity.issueToken(agentId, options?.permissions ?? this.config.defaultPermissions, {
|
|
73
|
+
maxAmount: options?.maxAmount,
|
|
74
|
+
maxTotalSpend: options?.maxTotalSpend,
|
|
75
|
+
expiresInMinutes: this.config.tokenExpiryMinutes,
|
|
76
|
+
});
|
|
77
|
+
// Create MnemoPayLite instance
|
|
78
|
+
const instance = index_js_1.default.quick(agentId, {
|
|
79
|
+
fraud: this.config.fraud,
|
|
80
|
+
paymentRail: this.config.paymentRail,
|
|
81
|
+
requireCounterparty: true,
|
|
82
|
+
debug: this.config.debug,
|
|
83
|
+
});
|
|
84
|
+
this.agents.set(agentId, {
|
|
85
|
+
instance,
|
|
86
|
+
name: options?.displayName ?? agentId,
|
|
87
|
+
ownerId,
|
|
88
|
+
token,
|
|
89
|
+
});
|
|
90
|
+
this.log(`Registered agent: ${agentId} (owner: ${ownerId})`);
|
|
91
|
+
return instance;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get a registered agent's MnemoPayLite instance.
|
|
95
|
+
*/
|
|
96
|
+
getAgent(agentId) {
|
|
97
|
+
return this.agents.get(agentId)?.instance ?? null;
|
|
98
|
+
}
|
|
99
|
+
// ── Multi-Agent Transactions ──────────────────────────────────────────
|
|
100
|
+
/**
|
|
101
|
+
* Execute a full buyer→seller transaction with shared memory context.
|
|
102
|
+
*
|
|
103
|
+
* Both agents remember the deal. The buyer's charge flows through escrow,
|
|
104
|
+
* platform fee is deducted, and the seller receives the net amount.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* const deal = await net.transact("buyer-bot", "seller-bot", 25, "API access");
|
|
108
|
+
* // deal.buyerMemoryId — buyer remembers what they paid for
|
|
109
|
+
* // deal.sellerMemoryId — seller remembers what they delivered
|
|
110
|
+
* // deal.netAmount — what seller actually received (after 1.9% fee)
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async transact(buyerId, sellerId, amount, reason, options) {
|
|
114
|
+
if (!Number.isFinite(amount) || amount <= 0)
|
|
115
|
+
throw new Error("Amount must be a positive finite number");
|
|
116
|
+
if (!reason || typeof reason !== "string")
|
|
117
|
+
throw new Error("Reason is required");
|
|
118
|
+
// Round to 2 decimals
|
|
119
|
+
amount = Math.round(amount * 100) / 100;
|
|
120
|
+
const buyer = this.agents.get(buyerId);
|
|
121
|
+
const seller = this.agents.get(sellerId);
|
|
122
|
+
if (!buyer)
|
|
123
|
+
throw new Error(`Buyer agent '${buyerId}' not registered on network`);
|
|
124
|
+
if (!seller)
|
|
125
|
+
throw new Error(`Seller agent '${sellerId}' not registered on network`);
|
|
126
|
+
if (buyerId === sellerId)
|
|
127
|
+
throw new Error("Buyer and seller cannot be the same agent");
|
|
128
|
+
// Validate buyer's token allows this charge
|
|
129
|
+
if (buyer.token) {
|
|
130
|
+
const validation = this.identity.validateToken(buyer.token.id, "charge", amount, sellerId);
|
|
131
|
+
if (!validation.valid) {
|
|
132
|
+
throw new Error(`Buyer token validation failed: ${validation.reason}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const dealId = crypto.randomUUID();
|
|
136
|
+
const tags = [...(options?.tags ?? []), "deal", `deal:${dealId}`];
|
|
137
|
+
const now = new Date().toISOString();
|
|
138
|
+
// 1. Buyer charges (creates escrow hold)
|
|
139
|
+
const charge = await buyer.instance.charge(amount, reason);
|
|
140
|
+
// 2. Settle with seller as counterparty
|
|
141
|
+
const settlement = await buyer.instance.settle(charge.id, sellerId);
|
|
142
|
+
// 3. Record spend against buyer's token
|
|
143
|
+
if (buyer.token) {
|
|
144
|
+
this.identity.recordSpend(buyer.token.id, amount);
|
|
145
|
+
}
|
|
146
|
+
// 4. Both agents remember the deal
|
|
147
|
+
const buyerMemContent = `Paid $${amount} to ${seller.name} for: ${reason}` +
|
|
148
|
+
(options?.buyerContext ? `. ${options.buyerContext}` : "");
|
|
149
|
+
const sellerMemContent = `Received $${settlement.netAmount} from ${buyer.name} for: ${reason}` +
|
|
150
|
+
(options?.sellerContext ? `. ${options.sellerContext}` : "");
|
|
151
|
+
const buyerMemoryId = await buyer.instance.remember(buyerMemContent, {
|
|
152
|
+
importance: 0.7,
|
|
153
|
+
tags: [...tags, "payment:sent"],
|
|
154
|
+
});
|
|
155
|
+
const sellerMemoryId = await seller.instance.remember(sellerMemContent, {
|
|
156
|
+
importance: 0.7,
|
|
157
|
+
tags: [...tags, "payment:received"],
|
|
158
|
+
});
|
|
159
|
+
// 5. Fund the seller's wallet with the net amount
|
|
160
|
+
const fee = settlement.platformFee ?? 0;
|
|
161
|
+
const net = settlement.netAmount ?? amount;
|
|
162
|
+
// 6. Touch identities
|
|
163
|
+
this.identity.touch(buyerId);
|
|
164
|
+
this.identity.touch(sellerId);
|
|
165
|
+
// 7. Record the deal
|
|
166
|
+
const deal = {
|
|
167
|
+
dealId,
|
|
168
|
+
charge,
|
|
169
|
+
settlement,
|
|
170
|
+
buyerMemoryId,
|
|
171
|
+
sellerMemoryId,
|
|
172
|
+
platformFee: fee,
|
|
173
|
+
netAmount: net,
|
|
174
|
+
timestamp: now,
|
|
175
|
+
};
|
|
176
|
+
this.deals.push(deal);
|
|
177
|
+
this._totalVolume += amount;
|
|
178
|
+
this._totalFees += fee;
|
|
179
|
+
this.log(`Deal ${dealId}: ${buyerId} → ${sellerId}, $${amount} (fee: $${fee}, net: $${net})`);
|
|
180
|
+
return deal;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Refund a deal. Buyer gets money back, both agents remember the refund.
|
|
184
|
+
*/
|
|
185
|
+
async refundDeal(dealId) {
|
|
186
|
+
const deal = this.deals.find(d => d.dealId === dealId);
|
|
187
|
+
if (!deal)
|
|
188
|
+
throw new Error(`Deal '${dealId}' not found`);
|
|
189
|
+
const buyer = this.agents.get(deal.charge.agentId);
|
|
190
|
+
if (!buyer)
|
|
191
|
+
throw new Error(`Buyer agent no longer on network`);
|
|
192
|
+
// Refund the transaction
|
|
193
|
+
await buyer.instance.refund(deal.charge.id);
|
|
194
|
+
// Both agents remember the refund
|
|
195
|
+
const sellerId = deal.settlement?.counterpartyId;
|
|
196
|
+
const seller = sellerId ? this.agents.get(sellerId) : null;
|
|
197
|
+
await buyer.instance.remember(`Refund: Got $${deal.netAmount} back for deal ${dealId}`, { importance: 0.6, tags: ["deal", `deal:${dealId}`, "refund"] });
|
|
198
|
+
if (seller) {
|
|
199
|
+
await seller.instance.remember(`Refund: Returned $${deal.netAmount} for deal ${dealId}`, { importance: 0.6, tags: ["deal", `deal:${dealId}`, "refund"] });
|
|
200
|
+
}
|
|
201
|
+
this.log(`Refunded deal ${dealId}`);
|
|
202
|
+
}
|
|
203
|
+
// ── Queries ───────────────────────────────────────────────────────────
|
|
204
|
+
/**
|
|
205
|
+
* Network-wide statistics.
|
|
206
|
+
*/
|
|
207
|
+
stats() {
|
|
208
|
+
const oneHourAgo = Date.now() - 3_600_000;
|
|
209
|
+
const activeAgents = new Set();
|
|
210
|
+
for (const deal of this.deals) {
|
|
211
|
+
if (new Date(deal.timestamp).getTime() > oneHourAgo) {
|
|
212
|
+
activeAgents.add(deal.charge.agentId);
|
|
213
|
+
if (deal.settlement?.counterpartyId) {
|
|
214
|
+
activeAgents.add(deal.settlement.counterpartyId);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
agentCount: this.agents.size,
|
|
220
|
+
dealCount: this.deals.length,
|
|
221
|
+
totalVolume: Math.round(this._totalVolume * 100) / 100,
|
|
222
|
+
totalFees: Math.round(this._totalFees * 100) / 100,
|
|
223
|
+
activeAgents: activeAgents.size,
|
|
224
|
+
ledgerBalanced: true, // Each agent's ledger is independently balanced
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get all deals between two agents.
|
|
229
|
+
*/
|
|
230
|
+
dealsBetween(agentA, agentB) {
|
|
231
|
+
return this.deals.filter(d => (d.charge.agentId === agentA && d.settlement?.counterpartyId === agentB) ||
|
|
232
|
+
(d.charge.agentId === agentB && d.settlement?.counterpartyId === agentA));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get an agent's deal history.
|
|
236
|
+
*/
|
|
237
|
+
agentDeals(agentId) {
|
|
238
|
+
return this.deals.filter(d => d.charge.agentId === agentId || d.settlement?.counterpartyId === agentId);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* List all registered agent IDs.
|
|
242
|
+
*/
|
|
243
|
+
listAgents() {
|
|
244
|
+
return Array.from(this.agents.keys());
|
|
245
|
+
}
|
|
246
|
+
// ── Lifecycle ─────────────────────────────────────────────────────────
|
|
247
|
+
/**
|
|
248
|
+
* Disconnect all agents and clean up.
|
|
249
|
+
*/
|
|
250
|
+
async shutdown() {
|
|
251
|
+
for (const [id, agent] of this.agents) {
|
|
252
|
+
await agent.instance.disconnect();
|
|
253
|
+
}
|
|
254
|
+
this.log(`Network shut down. ${this.deals.length} deals completed.`);
|
|
255
|
+
}
|
|
256
|
+
// ── Internal ──────────────────────────────────────────────────────────
|
|
257
|
+
log(msg) {
|
|
258
|
+
if (this.config.debug)
|
|
259
|
+
console.log(`[mnemopay:network] ${msg}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.MnemoPayNetwork = MnemoPayNetwork;
|
|
263
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;AAEH,0DAAyG;AACzG,+CAAwF;AACxF,2CAAqC;AAkErC,+EAA+E;AAE/E,MAAa,eAAe;IAClB,MAAM,GAA8B,IAAI,GAAG,EAAE,CAAC;IAC9C,KAAK,GAAiB,EAAE,CAAC;IACzB,YAAY,GAAG,CAAC,CAAC;IACjB,UAAU,GAAG,CAAC,CAAC;IAEvB,qEAAqE;IAC5D,QAAQ,CAAmB;IACpC,oEAAoE;IAC3D,MAAM,CAAS;IACxB,4BAA4B;IACnB,MAAM,CAA0B;IAEzC,YAAY,MAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,8BAAgB,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG;YACZ,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE;YAC1B,WAAW,EAAE,MAAM,EAAE,WAAkB;YACvC,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,IAAI;YAC5C,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC;YACtG,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,IAAI,IAAI;YACtD,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,KAAK;SAC9B,CAA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CAAC,CAAC,UAAU,EAAE,cAAc,KAAK,MAAM,CAAC;YACxE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,UAAU,EAAE,cAAc,KAAK,MAAM,CAAC,CACzE,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAe;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC3B,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,UAAU,EAAE,cAAc,KAAK,OAAO,CACzE,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,yEAAyE;IAEzE;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,sBAAsB,IAAI,CAAC,KAAK,CAAC,MAAM,mBAAmB,CAAC,CAAC;IACvE,CAAC;IAED,yEAAyE;IAEjE,GAAG,CAAC,GAAW;QACrB,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AAjTD,0CAiTC"}
|
package/dist/rails/index.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export declare class StripeRail implements PaymentRail {
|
|
|
52
52
|
capturePayment(externalId: string, amount: number): Promise<PaymentRailResult>;
|
|
53
53
|
reversePayment(externalId: string, _amount: number): Promise<PaymentRailResult>;
|
|
54
54
|
}
|
|
55
|
+
export { PaystackRail, NIGERIAN_BANKS } from "./paystack.js";
|
|
56
|
+
export type { PaystackConfig, PaystackCurrency, PaystackHoldResult, PaystackVerifyResult, PaystackTransferRecipient, PaystackTransferResult, PaystackWebhookEvent, } from "./paystack.js";
|
|
55
57
|
export declare class LightningRail implements PaymentRail {
|
|
56
58
|
readonly name = "lightning";
|
|
57
59
|
private baseUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rails/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,UAAU,CACR,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9B;;;OAGG;IACH,cAAc,CACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9B;;;OAGG;IACH,cAAc,CACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/B;AAID,qBAAa,QAAS,YAAW,WAAW;IAC1C,QAAQ,CAAC,IAAI,UAAU;IACvB,OAAO,CAAC,OAAO,CAAK;IAEd,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAOvF,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQ9E,cAAc,CAAC,UAAU,E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AQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBACS,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,SAAQ;IAMrE,+CAA+C;IAC/C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9B,OAAO,CAAC,SAAS;YAIH,UAAU;IAgBlB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAiBvF,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAc/E,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAQtF"}
|
package/dist/rails/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* const agent = MnemoPay.quick("id", { paymentRail: new StripeRail("sk_test_...") });
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.LightningRail = exports.StripeRail = exports.MockRail = void 0;
|
|
13
|
+
exports.LightningRail = exports.NIGERIAN_BANKS = exports.PaystackRail = exports.StripeRail = exports.MockRail = void 0;
|
|
14
14
|
// ─── Mock Rail (default — existing in-memory behavior) ──────────────────────
|
|
15
15
|
class MockRail {
|
|
16
16
|
name = "mock";
|
|
@@ -92,6 +92,10 @@ class StripeRail {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
exports.StripeRail = StripeRail;
|
|
95
|
+
// Re-export Paystack rail
|
|
96
|
+
var paystack_js_1 = require("./paystack.js");
|
|
97
|
+
Object.defineProperty(exports, "PaystackRail", { enumerable: true, get: function () { return paystack_js_1.PaystackRail; } });
|
|
98
|
+
Object.defineProperty(exports, "NIGERIAN_BANKS", { enumerable: true, get: function () { return paystack_js_1.NIGERIAN_BANKS; } });
|
|
95
99
|
// ─── Lightning Rail (L402) ──────────────────────────────────────────────────
|
|
96
100
|
// Requires a running LND node. Uses HODL invoices for escrow.
|
|
97
101
|
class LightningRail {
|
package/dist/rails/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rails/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA2CH,+EAA+E;AAE/E,MAAa,QAAQ;IACV,IAAI,GAAG,MAAM,CAAC;IACf,OAAO,GAAG,CAAC,CAAC;IAEpB,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,MAAc,EAAE,OAAe;QAC9D,OAAO;YACL,UAAU,EAAE,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE;YACzC,MAAM,EAAE,MAAM;SACf,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,MAAc;QACrD,OAAO;YACL,UAAU;YACV,MAAM,EAAE,UAAU;YAClB,SAAS,EAAE,gBAAgB,IAAI,CAAC,OAAO,EAAE;SAC1C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,MAAc;QACrD,OAAO;YACL,UAAU;YACV,MAAM,EAAE,UAAU;SACnB,CAAC;IACJ,CAAC;CACF;AAzBD,4BAyBC;AAED,+EAA+E;AAC/E,iDAAiD;AACjD,2DAA2D;AAE3D,MAAa,UAAU;IACZ,IAAI,GAAG,QAAQ,CAAC;IACjB,MAAM,CAAM;IACZ,QAAQ,CAAS;IAEzB;;;OAGG;IACH,YAAY,SAAiB,EAAE,QAAQ,GAAG,KAAK;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,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C;CACF;AAjFD,sCAiFC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paystack Payment Rail for MnemoPay
|
|
3
|
+
*
|
|
4
|
+
* Production-grade integration with Paystack's payment infrastructure.
|
|
5
|
+
* Supports NGN, GHS, ZAR, KES, USD. Uses the same battle-tested patterns
|
|
6
|
+
* from the Dele backend: idempotency guards, webhook HMAC-SHA512 verification,
|
|
7
|
+
* failure reversals, and reference-based deduplication.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const rail = new PaystackRail("sk_live_...", { currency: "NGN" });
|
|
11
|
+
* const agent = MnemoPay.quick("agent-1", { paymentRail: rail });
|
|
12
|
+
*
|
|
13
|
+
* Flows:
|
|
14
|
+
* 1. Checkout: createHold → user pays at authorization_url → capturePayment (verify)
|
|
15
|
+
* 2. Saved card: createHold with authorizationCode → auto-charged → capturePayment (verify)
|
|
16
|
+
* 3. Payout: createTransferRecipient → initiateTransfer
|
|
17
|
+
* 4. Webhook: verifyWebhook → process event
|
|
18
|
+
*/
|
|
19
|
+
import type { PaymentRail, PaymentRailResult } from "./index.js";
|
|
20
|
+
export type PaystackCurrency = "NGN" | "GHS" | "ZAR" | "KES" | "USD";
|
|
21
|
+
export interface PaystackConfig {
|
|
22
|
+
/** ISO currency code. Default: "NGN" */
|
|
23
|
+
currency?: PaystackCurrency;
|
|
24
|
+
/** Callback URL after checkout payment. Optional. */
|
|
25
|
+
callbackUrl?: string;
|
|
26
|
+
/** Base URL override (for testing). Default: "https://api.paystack.co" */
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/** Request timeout in ms. Default: 30000 */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Channels to enable (card, bank, ussd, mobile_money, etc). Default: all */
|
|
31
|
+
channels?: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface PaystackHoldResult extends PaymentRailResult {
|
|
34
|
+
/** Paystack authorization URL — redirect user here to pay */
|
|
35
|
+
authorizationUrl?: string;
|
|
36
|
+
/** Paystack access code */
|
|
37
|
+
accessCode?: string;
|
|
38
|
+
/** Unique reference for this transaction */
|
|
39
|
+
reference: string;
|
|
40
|
+
}
|
|
41
|
+
export interface PaystackVerifyResult extends PaymentRailResult {
|
|
42
|
+
/** Amount in major currency units (e.g., Naira, not kobo) */
|
|
43
|
+
amount: number;
|
|
44
|
+
/** Currency code */
|
|
45
|
+
currency: PaystackCurrency;
|
|
46
|
+
/** Customer email */
|
|
47
|
+
customerEmail?: string;
|
|
48
|
+
/** Reusable authorization for future charges */
|
|
49
|
+
authorization?: {
|
|
50
|
+
authorizationCode: string;
|
|
51
|
+
cardType: string;
|
|
52
|
+
last4: string;
|
|
53
|
+
bank: string;
|
|
54
|
+
reusable: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** Transaction metadata */
|
|
57
|
+
metadata?: Record<string, unknown>;
|
|
58
|
+
/** Paystack gateway response */
|
|
59
|
+
gatewayResponse?: string;
|
|
60
|
+
/** Paid at timestamp */
|
|
61
|
+
paidAt?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface PaystackTransferRecipient {
|
|
64
|
+
recipientCode: string;
|
|
65
|
+
name: string;
|
|
66
|
+
bankCode: string;
|
|
67
|
+
accountNumber: string;
|
|
68
|
+
currency: PaystackCurrency;
|
|
69
|
+
}
|
|
70
|
+
export interface PaystackTransferResult extends PaymentRailResult {
|
|
71
|
+
/** Transfer reference */
|
|
72
|
+
reference: string;
|
|
73
|
+
/** Amount in major units */
|
|
74
|
+
amount: number;
|
|
75
|
+
/** Transfer status: pending, success, failed, reversed */
|
|
76
|
+
transferStatus: string;
|
|
77
|
+
}
|
|
78
|
+
export interface PaystackWebhookEvent {
|
|
79
|
+
event: string;
|
|
80
|
+
data: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export declare class PaystackRail implements PaymentRail {
|
|
83
|
+
readonly name = "paystack";
|
|
84
|
+
private readonly secretKey;
|
|
85
|
+
private readonly currency;
|
|
86
|
+
private readonly baseUrl;
|
|
87
|
+
private readonly callbackUrl?;
|
|
88
|
+
private readonly timeoutMs;
|
|
89
|
+
private readonly channels?;
|
|
90
|
+
/** Reference-based idempotency guard — tracks processed references */
|
|
91
|
+
private processedRefs;
|
|
92
|
+
constructor(secretKey: string, config?: PaystackConfig);
|
|
93
|
+
/**
|
|
94
|
+
* Initialize a Paystack transaction (hold).
|
|
95
|
+
*
|
|
96
|
+
* If no authorizationCode is in metadata, returns an authorization_url
|
|
97
|
+
* for checkout. If authorizationCode is present, charges the saved card
|
|
98
|
+
* directly (no redirect needed).
|
|
99
|
+
*/
|
|
100
|
+
createHold(amount: number, reason: string, agentId: string, options?: {
|
|
101
|
+
email?: string;
|
|
102
|
+
authorizationCode?: string;
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
}): Promise<PaystackHoldResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Verify/capture a Paystack transaction.
|
|
107
|
+
* Call after user completes checkout or after charging saved card.
|
|
108
|
+
*/
|
|
109
|
+
capturePayment(externalId: string, _amount: number): Promise<PaystackVerifyResult>;
|
|
110
|
+
/**
|
|
111
|
+
* Refund a Paystack transaction.
|
|
112
|
+
* Supports full and partial refunds.
|
|
113
|
+
*/
|
|
114
|
+
reversePayment(externalId: string, amount: number): Promise<PaymentRailResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Create a transfer recipient (bank account for payouts).
|
|
117
|
+
* Must be called before initiateTransfer.
|
|
118
|
+
*/
|
|
119
|
+
createTransferRecipient(name: string, accountNumber: string, bankCode: string, currency?: PaystackCurrency): Promise<PaystackTransferRecipient>;
|
|
120
|
+
/**
|
|
121
|
+
* Initiate a bank transfer (payout).
|
|
122
|
+
* The recipient must already be created via createTransferRecipient.
|
|
123
|
+
*/
|
|
124
|
+
initiateTransfer(recipientCode: string, amount: number, reason: string, agentId?: string): Promise<PaystackTransferResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Verify a webhook signature (HMAC-SHA512).
|
|
127
|
+
* Returns the parsed event if valid, throws if signature mismatch.
|
|
128
|
+
*/
|
|
129
|
+
verifyWebhook(rawBody: string | Buffer, signature: string): PaystackWebhookEvent;
|
|
130
|
+
/**
|
|
131
|
+
* Resolve a bank account — verify the account name matches.
|
|
132
|
+
*/
|
|
133
|
+
resolveBank(accountNumber: string, bankCode: string): Promise<{
|
|
134
|
+
accountName: string;
|
|
135
|
+
accountNumber: string;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* List available banks for a given country/currency.
|
|
139
|
+
*/
|
|
140
|
+
listBanks(country?: string, perPage?: number): Promise<Array<{
|
|
141
|
+
name: string;
|
|
142
|
+
code: string;
|
|
143
|
+
}>>;
|
|
144
|
+
private mapVerifyResponse;
|
|
145
|
+
/**
|
|
146
|
+
* Convert major currency units to minor units (e.g., Naira → kobo).
|
|
147
|
+
* Paystack API expects amounts in minor units.
|
|
148
|
+
*/
|
|
149
|
+
toMinorUnits(amount: number): number;
|
|
150
|
+
/**
|
|
151
|
+
* Convert minor units back to major units (e.g., kobo → Naira).
|
|
152
|
+
*/
|
|
153
|
+
fromMinorUnits(minorAmount: number): number;
|
|
154
|
+
private request;
|
|
155
|
+
}
|
|
156
|
+
export declare const NIGERIAN_BANKS: Record<string, string>;
|
|
157
|
+
//# sourceMappingURL=paystack.d.ts.map
|