openclaw-paygate-plugin 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -11
- package/dist/index.js.map +1 -1
- package/dist/src/core/config.d.ts +12 -0
- package/dist/src/core/config.d.ts.map +1 -0
- package/dist/src/core/config.js +14 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/index.d.ts +26 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +27 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/payment.d.ts +17 -0
- package/dist/src/core/payment.d.ts.map +1 -0
- package/dist/src/core/payment.js +95 -0
- package/dist/src/core/payment.js.map +1 -0
- package/dist/src/core/types.d.ts +95 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/verify.d.ts +29 -0
- package/dist/src/core/verify.d.ts.map +1 -0
- package/dist/src/core/verify.js +105 -0
- package/dist/src/core/verify.js.map +1 -0
- package/dist/src/core/wallet.d.ts +100 -0
- package/dist/src/core/wallet.d.ts.map +1 -0
- package/dist/src/core/wallet.js +225 -0
- package/dist/src/core/wallet.js.map +1 -0
- package/dist/src/server.d.ts +15 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +49 -0
- package/dist/src/server.js.map +1 -0
- package/index.ts +58 -11
- package/openclaw.plugin.json +10 -1
- package/package.json +9 -7
- package/src/core/config.d.ts +12 -0
- package/src/core/config.ts +21 -0
- package/src/core/index.ts +42 -0
- package/src/core/payment.d.ts +17 -0
- package/src/core/payment.ts +111 -0
- package/src/core/types.d.ts +95 -0
- package/src/core/types.ts +102 -0
- package/src/core/verify.d.ts +29 -0
- package/src/core/verify.ts +119 -0
- package/src/core/wallet.d.ts +100 -0
- package/src/core/wallet.ts +289 -0
- package/src/server.ts +58 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — BSVAgentWallet
|
|
3
|
+
*
|
|
4
|
+
* High-level wallet class for AI agent-to-agent BSV payments.
|
|
5
|
+
* Wraps @bsv/wallet-toolbox's Wallet + StorageKnex with a clean,
|
|
6
|
+
* minimal API surface designed for automated agent use.
|
|
7
|
+
*/
|
|
8
|
+
import type { SetupWallet } from '@bsv/wallet-toolbox';
|
|
9
|
+
import type { WalletConfig, PaymentParams, PaymentResult, VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* BSVAgentWallet — the primary class for agent-to-agent BSV payments.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Create a new wallet (generates keys)
|
|
16
|
+
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
17
|
+
*
|
|
18
|
+
* // Load an existing wallet
|
|
19
|
+
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
20
|
+
*
|
|
21
|
+
* // Make a payment
|
|
22
|
+
* const payment = await wallet.createPayment({ to: recipientPubKey, satoshis: 500 });
|
|
23
|
+
*
|
|
24
|
+
* // Verify and accept a payment
|
|
25
|
+
* const verification = wallet.verifyPayment({ beef: payment.beef });
|
|
26
|
+
* if (verification.valid) {
|
|
27
|
+
* await wallet.acceptPayment({ beef: payment.beef, ...derivationInfo });
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class BSVAgentWallet {
|
|
32
|
+
/** @internal — exposed for advanced operations (e.g. direct internalizeAction) */
|
|
33
|
+
readonly _setup: SetupWallet;
|
|
34
|
+
private constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Create a new agent wallet. Generates a fresh root key and persists it.
|
|
37
|
+
* The SQLite database and identity file are written to `config.storageDir`.
|
|
38
|
+
*/
|
|
39
|
+
private static create;
|
|
40
|
+
/**
|
|
41
|
+
* Load an existing agent wallet from its storage directory.
|
|
42
|
+
* Reads the persisted identity file and re-initializes the wallet.
|
|
43
|
+
*/
|
|
44
|
+
static load(config: WalletConfig): Promise<BSVAgentWallet>;
|
|
45
|
+
/**
|
|
46
|
+
* Get this wallet's public identity key (compressed hex, 33 bytes).
|
|
47
|
+
* This is the key other agents use to send payments to you.
|
|
48
|
+
*/
|
|
49
|
+
getIdentityKey(): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the wallet's current balance in satoshis.
|
|
52
|
+
*
|
|
53
|
+
* Uses the BRC-100 wallet's balance method which sums spendable outputs
|
|
54
|
+
* in the default basket.
|
|
55
|
+
*/
|
|
56
|
+
getBalance(): Promise<number>;
|
|
57
|
+
/**
|
|
58
|
+
* Cleanly shut down the wallet, releasing database connections and
|
|
59
|
+
* stopping the background monitor.
|
|
60
|
+
*/
|
|
61
|
+
destroy(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Build a BRC-29 payment to another agent.
|
|
64
|
+
*
|
|
65
|
+
* The transaction is created with `noSend: true` — the sender does NOT
|
|
66
|
+
* broadcast it. Instead, the Atomic BEEF and derivation metadata are
|
|
67
|
+
* returned so they can be transmitted to the recipient, who will
|
|
68
|
+
* verify and internalize (broadcast) the payment.
|
|
69
|
+
*
|
|
70
|
+
* @param params.to — Recipient's compressed public key (hex).
|
|
71
|
+
* @param params.satoshis — Amount in satoshis.
|
|
72
|
+
* @param params.description — Optional human-readable note.
|
|
73
|
+
*/
|
|
74
|
+
createPayment(params: PaymentParams): Promise<PaymentResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Verify an incoming Atomic BEEF payment.
|
|
77
|
+
*
|
|
78
|
+
* This performs structural validation and SPV verification via tx.verify().
|
|
79
|
+
*/
|
|
80
|
+
verifyPayment(params: VerifyParams): Promise<VerifyResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Accept (internalize) a verified payment into this wallet.
|
|
83
|
+
*
|
|
84
|
+
* Uses the BRC-29 wallet payment protocol to derive the correct key
|
|
85
|
+
* and claim the output. This triggers SPV verification and, if the
|
|
86
|
+
* transaction hasn't been broadcast yet, broadcasts it.
|
|
87
|
+
*/
|
|
88
|
+
acceptPayment(params: AcceptParams): Promise<AcceptResult>;
|
|
89
|
+
/** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
|
|
90
|
+
getSetup(): SetupWallet;
|
|
91
|
+
/**
|
|
92
|
+
* Internal: manually construct a BRC-100 wallet backed by SQLite.
|
|
93
|
+
*
|
|
94
|
+
* We build this by hand instead of using Setup.createWalletSQLite because
|
|
95
|
+
* the toolbox has a bug where its internal randomBytesHex is a stub.
|
|
96
|
+
* We use the same components but wire them up correctly.
|
|
97
|
+
*/
|
|
98
|
+
private static buildSetup;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/core/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD,OAAO,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAc;IACzB,kFAAkF;IAClF,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,OAAO;IAQP;;;OAGG;mBACkB,MAAM;IAwB3B;;;OAGG;WACU,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAoBhE;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAQlE;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhE;;;;;;OAMG;IACG,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAQhE,6EAA6E;IAC7E,QAAQ,IAAI,WAAW;IAQvB;;;;;;OAMG;mBACkB,UAAU;CAyEhC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — BSVAgentWallet
|
|
3
|
+
*
|
|
4
|
+
* High-level wallet class for AI agent-to-agent BSV payments.
|
|
5
|
+
* Wraps @bsv/wallet-toolbox's Wallet + StorageKnex with a clean,
|
|
6
|
+
* minimal API surface designed for automated agent use.
|
|
7
|
+
*/
|
|
8
|
+
import { PrivateKey, CachedKeyDeriver } from '@bsv/sdk';
|
|
9
|
+
import { Wallet, WalletStorageManager, Services, Monitor, StorageKnex, randomBytesHex, ChaintracksServiceClient, } from '@bsv/wallet-toolbox';
|
|
10
|
+
import knexLib from 'knex';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
|
|
14
|
+
import { buildPayment } from './payment.js';
|
|
15
|
+
import { verifyPayment, acceptPayment } from './verify.js';
|
|
16
|
+
/** Filename for the persisted wallet identity JSON. */
|
|
17
|
+
const IDENTITY_FILE = 'wallet-identity.json';
|
|
18
|
+
/**
|
|
19
|
+
* BSVAgentWallet — the primary class for agent-to-agent BSV payments.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Create a new wallet (generates keys)
|
|
24
|
+
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
25
|
+
*
|
|
26
|
+
* // Load an existing wallet
|
|
27
|
+
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
28
|
+
*
|
|
29
|
+
* // Make a payment
|
|
30
|
+
* const payment = await wallet.createPayment({ to: recipientPubKey, satoshis: 500 });
|
|
31
|
+
*
|
|
32
|
+
* // Verify and accept a payment
|
|
33
|
+
* const verification = wallet.verifyPayment({ beef: payment.beef });
|
|
34
|
+
* if (verification.valid) {
|
|
35
|
+
* await wallet.acceptPayment({ beef: payment.beef, ...derivationInfo });
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class BSVAgentWallet {
|
|
40
|
+
/** @internal — exposed for advanced operations (e.g. direct internalizeAction) */
|
|
41
|
+
_setup;
|
|
42
|
+
constructor(setup) {
|
|
43
|
+
this._setup = setup;
|
|
44
|
+
}
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Factory methods
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
/**
|
|
49
|
+
* Create a new agent wallet. Generates a fresh root key and persists it.
|
|
50
|
+
* The SQLite database and identity file are written to `config.storageDir`.
|
|
51
|
+
*/
|
|
52
|
+
static async create(config) {
|
|
53
|
+
// Generate a new root key (or use one provided in config)
|
|
54
|
+
const rootKeyHex = config.rootKeyHex ?? PrivateKey.fromRandom().toHex();
|
|
55
|
+
const rootKey = PrivateKey.fromHex(rootKeyHex);
|
|
56
|
+
const identityKey = rootKey.toPublicKey().toString();
|
|
57
|
+
// Ensure the storage directory exists
|
|
58
|
+
fs.mkdirSync(config.storageDir, { recursive: true });
|
|
59
|
+
// Persist identity for later loading
|
|
60
|
+
const identity = {
|
|
61
|
+
rootKeyHex,
|
|
62
|
+
identityKey,
|
|
63
|
+
network: config.network,
|
|
64
|
+
};
|
|
65
|
+
const identityPath = path.join(config.storageDir, IDENTITY_FILE);
|
|
66
|
+
fs.writeFileSync(identityPath, JSON.stringify(identity, null, 2), 'utf-8');
|
|
67
|
+
// Build the wallet
|
|
68
|
+
const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
|
|
69
|
+
return new BSVAgentWallet(setup);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load an existing agent wallet from its storage directory.
|
|
73
|
+
* Reads the persisted identity file and re-initializes the wallet.
|
|
74
|
+
*/
|
|
75
|
+
static async load(config) {
|
|
76
|
+
const identityPath = path.join(config.storageDir, IDENTITY_FILE);
|
|
77
|
+
if (!fs.existsSync(identityPath)) {
|
|
78
|
+
return this.create(config);
|
|
79
|
+
}
|
|
80
|
+
const identity = JSON.parse(fs.readFileSync(identityPath, 'utf-8'));
|
|
81
|
+
const rootKeyHex = config.rootKeyHex ?? identity.rootKeyHex;
|
|
82
|
+
const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
|
|
83
|
+
return new BSVAgentWallet(setup);
|
|
84
|
+
}
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Wallet lifecycle
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
/**
|
|
89
|
+
* Get this wallet's public identity key (compressed hex, 33 bytes).
|
|
90
|
+
* This is the key other agents use to send payments to you.
|
|
91
|
+
*/
|
|
92
|
+
async getIdentityKey() {
|
|
93
|
+
return this._setup.identityKey;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the wallet's current balance in satoshis.
|
|
97
|
+
*
|
|
98
|
+
* Uses the BRC-100 wallet's balance method which sums spendable outputs
|
|
99
|
+
* in the default basket.
|
|
100
|
+
*/
|
|
101
|
+
async getBalance() {
|
|
102
|
+
return await this._setup.wallet.balance();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Cleanly shut down the wallet, releasing database connections and
|
|
106
|
+
* stopping the background monitor.
|
|
107
|
+
*/
|
|
108
|
+
async destroy() {
|
|
109
|
+
await this._setup.wallet.destroy();
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// Payment creation (sender/payer side)
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Build a BRC-29 payment to another agent.
|
|
116
|
+
*
|
|
117
|
+
* The transaction is created with `noSend: true` — the sender does NOT
|
|
118
|
+
* broadcast it. Instead, the Atomic BEEF and derivation metadata are
|
|
119
|
+
* returned so they can be transmitted to the recipient, who will
|
|
120
|
+
* verify and internalize (broadcast) the payment.
|
|
121
|
+
*
|
|
122
|
+
* @param params.to — Recipient's compressed public key (hex).
|
|
123
|
+
* @param params.satoshis — Amount in satoshis.
|
|
124
|
+
* @param params.description — Optional human-readable note.
|
|
125
|
+
*/
|
|
126
|
+
async createPayment(params) {
|
|
127
|
+
return buildPayment(this._setup, params);
|
|
128
|
+
}
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// Payment verification & acceptance (receiver/merchant side)
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
/**
|
|
133
|
+
* Verify an incoming Atomic BEEF payment.
|
|
134
|
+
*
|
|
135
|
+
* This performs structural validation and SPV verification via tx.verify().
|
|
136
|
+
*/
|
|
137
|
+
async verifyPayment(params) {
|
|
138
|
+
return await verifyPayment(params);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Accept (internalize) a verified payment into this wallet.
|
|
142
|
+
*
|
|
143
|
+
* Uses the BRC-29 wallet payment protocol to derive the correct key
|
|
144
|
+
* and claim the output. This triggers SPV verification and, if the
|
|
145
|
+
* transaction hasn't been broadcast yet, broadcasts it.
|
|
146
|
+
*/
|
|
147
|
+
async acceptPayment(params) {
|
|
148
|
+
return acceptPayment(this._setup, params);
|
|
149
|
+
}
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
// Access to underlying toolbox objects (for advanced use)
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
/** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
|
|
154
|
+
getSetup() {
|
|
155
|
+
return this._setup;
|
|
156
|
+
}
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Private helpers
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
/**
|
|
161
|
+
* Internal: manually construct a BRC-100 wallet backed by SQLite.
|
|
162
|
+
*
|
|
163
|
+
* We build this by hand instead of using Setup.createWalletSQLite because
|
|
164
|
+
* the toolbox has a bug where its internal randomBytesHex is a stub.
|
|
165
|
+
* We use the same components but wire them up correctly.
|
|
166
|
+
*/
|
|
167
|
+
static async buildSetup(config, rootKeyHex) {
|
|
168
|
+
const chain = toChain(config.network);
|
|
169
|
+
const taalApiKey = config.taalApiKey ?? DEFAULT_TAAL_API_KEYS[chain];
|
|
170
|
+
const rootKey = PrivateKey.fromHex(rootKeyHex);
|
|
171
|
+
const identityKey = rootKey.toPublicKey().toString();
|
|
172
|
+
// 1. Key derivation
|
|
173
|
+
const keyDeriver = new CachedKeyDeriver(rootKey);
|
|
174
|
+
// 2. Storage manager (empty initially)
|
|
175
|
+
const storage = new WalletStorageManager(identityKey);
|
|
176
|
+
// 3. Network services (ARC broadcasting, chain tracking, etc.)
|
|
177
|
+
const serviceOptions = Services.createDefaultOptions(chain);
|
|
178
|
+
const chaintracksUrl = process.env.BSV_CHAINTRACKS_URL || 'https://chaintracks-us-1.bsvb.tech';
|
|
179
|
+
const arcUrl = process.env.BSV_ARC_URL;
|
|
180
|
+
serviceOptions.chaintracks = new ChaintracksServiceClient(chain, chaintracksUrl);
|
|
181
|
+
if (arcUrl) {
|
|
182
|
+
serviceOptions.arcUrl = arcUrl;
|
|
183
|
+
}
|
|
184
|
+
serviceOptions.taalApiKey = taalApiKey;
|
|
185
|
+
const services = new Services(serviceOptions);
|
|
186
|
+
// 4. Background monitor
|
|
187
|
+
const monopts = Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
|
|
188
|
+
const monitor = new Monitor(monopts);
|
|
189
|
+
monitor.addDefaultTasks();
|
|
190
|
+
// 5. The BRC-100 Wallet
|
|
191
|
+
const wallet = new Wallet({ chain, keyDeriver, storage, services, monitor });
|
|
192
|
+
// 6. SQLite storage via knex
|
|
193
|
+
const filePath = path.join(config.storageDir, `${DEFAULT_DB_NAME}.sqlite`);
|
|
194
|
+
const knex = knexLib({
|
|
195
|
+
client: 'sqlite3',
|
|
196
|
+
connection: { filename: filePath },
|
|
197
|
+
useNullAsDefault: true,
|
|
198
|
+
});
|
|
199
|
+
// Fee model: configurable via BSV_FEE_MODEL env var (default: 100 sat/KB)
|
|
200
|
+
const feeModelValue = config.feeModel ??
|
|
201
|
+
(process.env.BSV_FEE_MODEL ? parseInt(process.env.BSV_FEE_MODEL, 10) : 100);
|
|
202
|
+
const activeStorage = new StorageKnex({
|
|
203
|
+
chain,
|
|
204
|
+
knex,
|
|
205
|
+
commissionSatoshis: 0,
|
|
206
|
+
commissionPubKeyHex: undefined,
|
|
207
|
+
feeModel: { model: 'sat/kb', value: feeModelValue },
|
|
208
|
+
});
|
|
209
|
+
await activeStorage.migrate(DEFAULT_DB_NAME, randomBytesHex(33));
|
|
210
|
+
await activeStorage.makeAvailable();
|
|
211
|
+
await storage.addWalletStorageProvider(activeStorage);
|
|
212
|
+
await activeStorage.findOrInsertUser(identityKey);
|
|
213
|
+
return {
|
|
214
|
+
rootKey,
|
|
215
|
+
identityKey,
|
|
216
|
+
keyDeriver,
|
|
217
|
+
chain,
|
|
218
|
+
storage,
|
|
219
|
+
services,
|
|
220
|
+
monitor,
|
|
221
|
+
wallet,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,g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QAC1E,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ;YACnC,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE9E,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC;YACpC,KAAK;YACL,IAAI;YACJ,kBAAkB,EAAE,CAAC;YACrB,mBAAmB,EAAE,SAAS;YAC9B,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE;SACpD,CAAC,CAAC;QAEH,MAAM,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;QACjE,MAAM,aAAa,CAAC,aAAa,EAAE,CAAC;QACpC,MAAM,OAAO,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;QACtD,MAAM,aAAa,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAElD,OAAO;YACL,OAAO;YACP,WAAW;YACX,UAAU;YACV,KAAK;YACL,OAAO;YACP,QAAQ;YACR,OAAO;YACP,MAAM;SACP,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BSVAgentWallet } from './core/wallet.js';
|
|
2
|
+
export declare class PaygateServer {
|
|
3
|
+
private app;
|
|
4
|
+
private wallet;
|
|
5
|
+
private port;
|
|
6
|
+
private prices;
|
|
7
|
+
constructor(port: number, wallet: BSVAgentWallet);
|
|
8
|
+
setPrice(toolName: string, sats: number): void;
|
|
9
|
+
start(): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
10
|
+
getEarnings(): {
|
|
11
|
+
total: number;
|
|
12
|
+
note: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,MAAM,CAAkC;gBAEpC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAkChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAIvC,KAAK;IAIL,WAAW;;;;CAIZ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { createPaymentMiddleware } from '@bsv/payment-express-middleware';
|
|
3
|
+
export class PaygateServer {
|
|
4
|
+
app = express();
|
|
5
|
+
wallet;
|
|
6
|
+
port;
|
|
7
|
+
prices = new Map();
|
|
8
|
+
constructor(port, wallet) {
|
|
9
|
+
this.port = port;
|
|
10
|
+
this.wallet = wallet;
|
|
11
|
+
this.app.use(express.json());
|
|
12
|
+
// 402 Middleware
|
|
13
|
+
const paymentMiddleware = createPaymentMiddleware({
|
|
14
|
+
wallet: this.wallet._setup.wallet,
|
|
15
|
+
calculateRequestPrice: (req) => {
|
|
16
|
+
const toolName = req.params.toolName;
|
|
17
|
+
return this.prices.get(toolName) || 0;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
// Universal tool endpoint
|
|
21
|
+
this.app.post('/tool/:toolName', paymentMiddleware, async (req, res) => {
|
|
22
|
+
const { toolName } = req.params;
|
|
23
|
+
const params = req.body;
|
|
24
|
+
try {
|
|
25
|
+
// Here we would call the actual OpenClaw tool
|
|
26
|
+
// For now, we return a success placeholder
|
|
27
|
+
res.json({
|
|
28
|
+
success: true,
|
|
29
|
+
message: `Tool ${toolName} executed successfully after payment.`,
|
|
30
|
+
data: { result: "placeholder", params }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
res.status(500).json({ success: false, error: err.message });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
setPrice(toolName, sats) {
|
|
39
|
+
this.prices.set(toolName, sats);
|
|
40
|
+
}
|
|
41
|
+
start() {
|
|
42
|
+
return this.app.listen(this.port);
|
|
43
|
+
}
|
|
44
|
+
getEarnings() {
|
|
45
|
+
// This would ideally query the wallet's internalized payments
|
|
46
|
+
return { total: 0, note: "Earnings tracking pending wallet storage integration" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAI1E,MAAM,OAAO,aAAa;IAChB,GAAG,GAAG,OAAO,EAAE,CAAC;IAChB,MAAM,CAAiB;IACvB,IAAI,CAAS;IACb,MAAM,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEhD,YAAY,IAAY,EAAE,MAAsB;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAE7B,iBAAiB;QACjB,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;YAChD,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAoC;YAC/D,qBAAqB,EAAE,CAAC,GAAQ,EAAE,EAAE;gBAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACrC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;SACF,CAAC,CAAC;QAEH,0BAA0B;QAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;YACxF,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;YAChC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC;YAExB,IAAI,CAAC;gBACH,8CAA8C;gBAC9C,2CAA2C;gBAC3C,GAAG,CAAC,IAAI,CAAC;oBACP,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,QAAQ,QAAQ,uCAAuC;oBAChE,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE;iBACxC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,QAAgB,EAAE,IAAY;QACrC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,WAAW;QACT,8DAA8D;QAC9D,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,sDAAsD,EAAE,CAAC;IACpF,CAAC;CACF"}
|
package/index.ts
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
|
+
import { PaygateServer } from "./src/server.js";
|
|
4
|
+
import { BSVAgentWallet } from "./src/core/wallet.js";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* OpenClaw Paygate Plugin
|
|
6
8
|
* Monetize agent tools via 402 Payment Required.
|
|
7
9
|
*/
|
|
8
10
|
export default function register(api: any) {
|
|
9
|
-
const
|
|
11
|
+
const entries = api.getConfig?.()?.plugins?.entries || {};
|
|
12
|
+
const entry = entries['openclaw-paygate']
|
|
13
|
+
|| entries['openclaw-paygate-plugin']
|
|
14
|
+
|| entries['bsv-paygate']
|
|
15
|
+
|| {};
|
|
16
|
+
|
|
10
17
|
const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
|
|
11
18
|
const port = pluginConfig.port || 8080;
|
|
19
|
+
const network = pluginConfig.network || 'mainnet';
|
|
12
20
|
const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
let server: PaygateServer | null = null;
|
|
23
|
+
let wallet: BSVAgentWallet | null = null;
|
|
24
|
+
|
|
25
|
+
api.logger.info(`[paygate] Initializing Paygate Plugin (network: ${network}, port: ${port})`);
|
|
26
|
+
|
|
27
|
+
async function ensureInitialized() {
|
|
28
|
+
if (server) return server;
|
|
29
|
+
|
|
30
|
+
// Initialize shared wallet
|
|
31
|
+
wallet = await BSVAgentWallet.load({
|
|
32
|
+
network: network as any,
|
|
33
|
+
storageDir: walletDir
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
server = new PaygateServer(port, wallet);
|
|
37
|
+
return server;
|
|
38
|
+
}
|
|
15
39
|
|
|
16
40
|
// Register the paygate tool
|
|
17
41
|
api.registerTool({
|
|
@@ -38,13 +62,26 @@ export default function register(api: any) {
|
|
|
38
62
|
},
|
|
39
63
|
async execute(_id: string, params: any) {
|
|
40
64
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
const s = await ensureInitialized();
|
|
66
|
+
|
|
67
|
+
switch (params.action) {
|
|
68
|
+
case "monetize":
|
|
69
|
+
if (!params.toolName || params.priceSats === undefined) {
|
|
70
|
+
throw new Error("toolName and priceSats required");
|
|
71
|
+
}
|
|
72
|
+
s.setPrice(params.toolName, params.priceSats);
|
|
73
|
+
return { content: [{ type: "text", text: `✅ Tool '${params.toolName}' is now monetized at ${params.priceSats} sats.\nEndpoint: http://localhost:${port}/tool/${params.toolName}` }] };
|
|
74
|
+
|
|
75
|
+
case "earnings":
|
|
76
|
+
const earnings = s.getEarnings();
|
|
77
|
+
return { content: [{ type: "text", text: `💰 Total Earnings: ${earnings.total} sats\nNote: ${earnings.note}` }] };
|
|
78
|
+
|
|
79
|
+
case "status":
|
|
80
|
+
return { content: [{ type: "text", text: `Paygate Status:\nServer: http://localhost:${port}\nIdentity: ${await wallet?.getIdentityKey()}` }] };
|
|
81
|
+
|
|
82
|
+
default:
|
|
83
|
+
throw new Error(`Unknown action: ${params.action}`);
|
|
84
|
+
}
|
|
48
85
|
} catch (error: any) {
|
|
49
86
|
return {
|
|
50
87
|
content: [{
|
|
@@ -57,14 +94,24 @@ export default function register(api: any) {
|
|
|
57
94
|
});
|
|
58
95
|
|
|
59
96
|
// Register the background API server
|
|
97
|
+
let runningServer: any = null;
|
|
60
98
|
api.registerService({
|
|
61
99
|
id: "paygate-api-server",
|
|
62
100
|
start: async () => {
|
|
63
|
-
|
|
64
|
-
|
|
101
|
+
try {
|
|
102
|
+
const s = await ensureInitialized();
|
|
103
|
+
api.logger.info(`[paygate] Starting agent API server on port ${port}...`);
|
|
104
|
+
runningServer = s.start();
|
|
105
|
+
} catch (err: any) {
|
|
106
|
+
api.logger.error(`[paygate] API server failed: ${err.message}`);
|
|
107
|
+
}
|
|
65
108
|
},
|
|
66
109
|
stop: async () => {
|
|
67
110
|
api.logger.info("[paygate] Stopping agent API server...");
|
|
111
|
+
if (runningServer) {
|
|
112
|
+
runningServer.close();
|
|
113
|
+
runningServer = null;
|
|
114
|
+
}
|
|
68
115
|
}
|
|
69
116
|
});
|
|
70
117
|
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "openclaw-paygate",
|
|
2
|
+
"id": "openclaw-paygate-plugin",
|
|
3
3
|
"name": "BSV Paygate",
|
|
4
4
|
"description": "Monetize agent tools via 402 Payment Required",
|
|
5
5
|
"version": "0.1.0",
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
"default": 8080,
|
|
16
16
|
"description": "Port for the agent's API server"
|
|
17
17
|
},
|
|
18
|
+
"network": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"enum": ["mainnet", "testnet"],
|
|
21
|
+
"default": "mainnet",
|
|
22
|
+
"description": "BSV network to use"
|
|
23
|
+
},
|
|
18
24
|
"walletDir": {
|
|
19
25
|
"type": "string",
|
|
20
26
|
"description": "Path to BSV wallet storage (defaults to ~/.openclaw/bsv-wallet)"
|
|
@@ -25,6 +31,9 @@
|
|
|
25
31
|
"port": {
|
|
26
32
|
"label": "API Port",
|
|
27
33
|
"placeholder": "8080"
|
|
34
|
+
},
|
|
35
|
+
"network": {
|
|
36
|
+
"label": "BSV Network"
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-paygate-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "OpenClaw plugin for monetizing tools via 402 Payment Required flow",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,17 +19,19 @@
|
|
|
19
19
|
"test": "npx tsx src/**/*.test.ts"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@bsv/payment-express-middleware": "^2.0.1",
|
|
22
23
|
"@bsv/sdk": "^2.0.13",
|
|
23
|
-
"
|
|
24
|
+
"@bsv/wallet-toolbox": "^2.1.17",
|
|
24
25
|
"better-sqlite3": "^12.8.0",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
26
|
+
"dotenv": "^17.3.1",
|
|
27
|
+
"express": "^4.21.0",
|
|
28
|
+
"knex": "^3.2.8"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^22.10.0",
|
|
30
31
|
"@types/express": "^5.0.0",
|
|
31
|
-
"
|
|
32
|
-
"eslint": "^10.1.0"
|
|
32
|
+
"@types/node": "^22.10.0",
|
|
33
|
+
"eslint": "^10.1.0",
|
|
34
|
+
"typescript": "^6.0.2"
|
|
33
35
|
},
|
|
34
36
|
"openclaw": {
|
|
35
37
|
"extensions": [
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Configuration defaults and helpers.
|
|
3
|
+
*/
|
|
4
|
+
import type { WalletConfig } from './types.js';
|
|
5
|
+
/** Map our 'mainnet'/'testnet' to the wallet-toolbox's 'main'/'test' chain type. */
|
|
6
|
+
export type Chain = 'main' | 'test';
|
|
7
|
+
export declare function toChain(network: WalletConfig['network']): Chain;
|
|
8
|
+
/** Default TAAL API keys from the wallet-toolbox examples. */
|
|
9
|
+
export declare const DEFAULT_TAAL_API_KEYS: Record<Chain, string>;
|
|
10
|
+
/** Default SQLite database name. */
|
|
11
|
+
export declare const DEFAULT_DB_NAME = "a2a_agent_wallet";
|
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Configuration defaults and helpers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { WalletConfig } from './types.js';
|
|
6
|
+
|
|
7
|
+
/** Map our 'mainnet'/'testnet' to the wallet-toolbox's 'main'/'test' chain type. */
|
|
8
|
+
export type Chain = 'main' | 'test';
|
|
9
|
+
|
|
10
|
+
export function toChain(network: WalletConfig['network']): Chain {
|
|
11
|
+
return network === 'mainnet' ? 'main' : 'test';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Default TAAL API keys from the wallet-toolbox examples. */
|
|
15
|
+
export const DEFAULT_TAAL_API_KEYS: Record<Chain, string> = {
|
|
16
|
+
main: 'mainnet_9596de07e92300c6287e4393594ae39c',
|
|
17
|
+
test: 'testnet_0e6cf72133b43ea2d7861da2a38684e3',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Default SQLite database name. */
|
|
21
|
+
export const DEFAULT_DB_NAME = 'a2a_agent_wallet';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Agent-to-agent BSV payment library.
|
|
3
|
+
*
|
|
4
|
+
* Wraps @bsv/sdk and @bsv/wallet-toolbox to provide a clean, minimal API
|
|
5
|
+
* for AI agents to pay each other using BSV blockchain transactions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BSVAgentWallet } from '@a2a-bsv/core';
|
|
10
|
+
*
|
|
11
|
+
* const wallet = await BSVAgentWallet.load({
|
|
12
|
+
* network: 'testnet',
|
|
13
|
+
* storageDir: './my-agent-wallet',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const identityKey = await wallet.getIdentityKey();
|
|
17
|
+
* console.log('My identity:', identityKey);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Main wallet class
|
|
22
|
+
export { BSVAgentWallet } from './wallet.js';
|
|
23
|
+
|
|
24
|
+
// All types
|
|
25
|
+
export type {
|
|
26
|
+
WalletConfig,
|
|
27
|
+
WalletIdentity,
|
|
28
|
+
PaymentParams,
|
|
29
|
+
PaymentResult,
|
|
30
|
+
VerifyParams,
|
|
31
|
+
VerifyResult,
|
|
32
|
+
AcceptParams,
|
|
33
|
+
AcceptResult,
|
|
34
|
+
} from './types.js';
|
|
35
|
+
|
|
36
|
+
// Config helpers (for advanced use)
|
|
37
|
+
export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
|
|
38
|
+
export type { Chain } from './config.js';
|
|
39
|
+
|
|
40
|
+
// Lower-level helpers (for advanced use)
|
|
41
|
+
export { buildPayment } from './payment.js';
|
|
42
|
+
export { verifyPayment, acceptPayment } from './verify.js';
|