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.
Files changed (47) hide show
  1. package/README.md +39 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +51 -11
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/core/config.d.ts +12 -0
  6. package/dist/src/core/config.d.ts.map +1 -0
  7. package/dist/src/core/config.js +14 -0
  8. package/dist/src/core/config.js.map +1 -0
  9. package/dist/src/core/index.d.ts +26 -0
  10. package/dist/src/core/index.d.ts.map +1 -0
  11. package/dist/src/core/index.js +27 -0
  12. package/dist/src/core/index.js.map +1 -0
  13. package/dist/src/core/payment.d.ts +17 -0
  14. package/dist/src/core/payment.d.ts.map +1 -0
  15. package/dist/src/core/payment.js +95 -0
  16. package/dist/src/core/payment.js.map +1 -0
  17. package/dist/src/core/types.d.ts +95 -0
  18. package/dist/src/core/types.d.ts.map +1 -0
  19. package/dist/src/core/types.js +5 -0
  20. package/dist/src/core/types.js.map +1 -0
  21. package/dist/src/core/verify.d.ts +29 -0
  22. package/dist/src/core/verify.d.ts.map +1 -0
  23. package/dist/src/core/verify.js +105 -0
  24. package/dist/src/core/verify.js.map +1 -0
  25. package/dist/src/core/wallet.d.ts +100 -0
  26. package/dist/src/core/wallet.d.ts.map +1 -0
  27. package/dist/src/core/wallet.js +225 -0
  28. package/dist/src/core/wallet.js.map +1 -0
  29. package/dist/src/server.d.ts +15 -0
  30. package/dist/src/server.d.ts.map +1 -0
  31. package/dist/src/server.js +49 -0
  32. package/dist/src/server.js.map +1 -0
  33. package/index.ts +58 -11
  34. package/openclaw.plugin.json +10 -1
  35. package/package.json +9 -7
  36. package/src/core/config.d.ts +12 -0
  37. package/src/core/config.ts +21 -0
  38. package/src/core/index.ts +42 -0
  39. package/src/core/payment.d.ts +17 -0
  40. package/src/core/payment.ts +111 -0
  41. package/src/core/types.d.ts +95 -0
  42. package/src/core/types.ts +102 -0
  43. package/src/core/verify.d.ts +29 -0
  44. package/src/core/verify.ts +119 -0
  45. package/src/core/wallet.d.ts +100 -0
  46. package/src/core/wallet.ts +289 -0
  47. package/src/server.ts +58 -0
package/README.md CHANGED
@@ -7,10 +7,46 @@ A programmatic OpenClaw plugin that enables AI agents to monetize their capabili
7
7
  - **Auto-Handshake**: Automatically manages the payment request and verification flow.
8
8
  - **Unified Earnings**: All revenue is deposited directly into your agent's BSV wallet.
9
9
 
10
+ ---
11
+
12
+ ## Configuration
13
+
14
+ You can configure the plugin in your `openclaw.json` file. The plugin supports both a flat structure and a nested `config` object under its ID.
15
+
16
+ ### Example Configuration
17
+ ```json
18
+ {
19
+ "plugins": {
20
+ "entries": {
21
+ "openclaw-paygate-plugin": {
22
+ "enabled": true,
23
+ "port": 8080,
24
+ "walletDir": "~/.openclaw/bsv-wallet",
25
+ "network": "mainnet"
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ ### Options
33
+
34
+ | Option | Default | Description |
35
+ | :--- | :--- | :--- |
36
+ | `port` | `8080` | Port for the agent's local API server. |
37
+ | `network` | `mainnet` | The BSV network to target (`mainnet` or `testnet`). |
38
+ | `walletDir` | `~/.openclaw/bsv-wallet` | Directory where `wallet-identity.json` is stored. |
39
+
40
+ ---
41
+
10
42
  ## AI Tool: `paygate`
11
- Agents can use the `paygate` tool to:
12
- - `monetize`: Wrap any tool with a price tag in satoshis.
13
- - `earnings`: Check the total BSV earned by the agent.
43
+ Agents can use the `paygate` tool to perform the following actions:
44
+
45
+ | Action | Description |
46
+ | :--- | :--- |
47
+ | `monetize` | Register an existing OpenClaw tool as a paid service with a price in satoshis. |
48
+ | `earnings` | Display the total BSV revenue earned by the agent through the paygate. |
49
+ | `status` | Show active paid endpoints, their prices, and the server URL. |
14
50
 
15
51
  ## Architecture
16
52
  Built with the **OpenClaw Plugin SDK**, this extension uses standard web middleware to enforce payments for API calls and tool executions.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QA8DxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QA2GxC"}
package/dist/index.js CHANGED
@@ -1,15 +1,35 @@
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
  * OpenClaw Paygate Plugin
5
7
  * Monetize agent tools via 402 Payment Required.
6
8
  */
7
9
  export default function register(api) {
8
- const entry = api.getConfig?.()?.plugins?.entries?.['openclaw-paygate'] || {};
10
+ const entries = api.getConfig?.()?.plugins?.entries || {};
11
+ const entry = entries['openclaw-paygate']
12
+ || entries['openclaw-paygate-plugin']
13
+ || entries['bsv-paygate']
14
+ || {};
9
15
  const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
10
16
  const port = pluginConfig.port || 8080;
17
+ const network = pluginConfig.network || 'mainnet';
11
18
  const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
12
- api.logger.info(`[paygate] Initializing Paygate Plugin (port: ${port})`);
19
+ let server = null;
20
+ let wallet = null;
21
+ api.logger.info(`[paygate] Initializing Paygate Plugin (network: ${network}, port: ${port})`);
22
+ async function ensureInitialized() {
23
+ if (server)
24
+ return server;
25
+ // Initialize shared wallet
26
+ wallet = await BSVAgentWallet.load({
27
+ network: network,
28
+ storageDir: walletDir
29
+ });
30
+ server = new PaygateServer(port, wallet);
31
+ return server;
32
+ }
13
33
  // Register the paygate tool
14
34
  api.registerTool({
15
35
  name: "paygate",
@@ -35,13 +55,22 @@ export default function register(api) {
35
55
  },
36
56
  async execute(_id, params) {
37
57
  try {
38
- // Implementation logic using payment-express-middleware will go here
39
- return {
40
- content: [{
41
- type: "text",
42
- text: `Paygate action '${params.action}' received. (Logic implementation pending)`
43
- }]
44
- };
58
+ const s = await ensureInitialized();
59
+ switch (params.action) {
60
+ case "monetize":
61
+ if (!params.toolName || params.priceSats === undefined) {
62
+ throw new Error("toolName and priceSats required");
63
+ }
64
+ s.setPrice(params.toolName, params.priceSats);
65
+ return { content: [{ type: "text", text: `✅ Tool '${params.toolName}' is now monetized at ${params.priceSats} sats.\nEndpoint: http://localhost:${port}/tool/${params.toolName}` }] };
66
+ case "earnings":
67
+ const earnings = s.getEarnings();
68
+ return { content: [{ type: "text", text: `💰 Total Earnings: ${earnings.total} sats\nNote: ${earnings.note}` }] };
69
+ case "status":
70
+ return { content: [{ type: "text", text: `Paygate Status:\nServer: http://localhost:${port}\nIdentity: ${await wallet?.getIdentityKey()}` }] };
71
+ default:
72
+ throw new Error(`Unknown action: ${params.action}`);
73
+ }
45
74
  }
46
75
  catch (error) {
47
76
  return {
@@ -54,14 +83,25 @@ export default function register(api) {
54
83
  }
55
84
  });
56
85
  // Register the background API server
86
+ let runningServer = null;
57
87
  api.registerService({
58
88
  id: "paygate-api-server",
59
89
  start: async () => {
60
- api.logger.info(`[paygate] Starting agent API server on port ${port}...`);
61
- // Express server logic with 402 middleware goes here
90
+ try {
91
+ const s = await ensureInitialized();
92
+ api.logger.info(`[paygate] Starting agent API server on port ${port}...`);
93
+ runningServer = s.start();
94
+ }
95
+ catch (err) {
96
+ api.logger.error(`[paygate] API server failed: ${err.message}`);
97
+ }
62
98
  },
63
99
  stop: async () => {
64
100
  api.logger.info("[paygate] Stopping agent API server...");
101
+ if (runningServer) {
102
+ runningServer.close();
103
+ runningServer = null;
104
+ }
65
105
  }
66
106
  });
67
107
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI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,CAAC;oBAEjJ;wBACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;gBACxD,CAAC;YACH,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,UAAU,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;yBACjD,CAAC;iBACH,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,qCAAqC;IACrC,IAAI,aAAa,GAAQ,IAAI,CAAC;IAC9B,GAAG,CAAC,eAAe,CAAC;QAClB,EAAE,EAAE,oBAAoB;QACxB,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,MAAM,iBAAiB,EAAE,CAAC;gBACpC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,+CAA+C,IAAI,KAAK,CAAC,CAAC;gBAC1E,aAAa,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YAC5B,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QACD,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;YAC1D,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,CAAC,KAAK,EAAE,CAAC;gBACtB,aAAa,GAAG,IAAI,CAAC;YACvB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -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 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,oFAAoF;AACpF,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpC,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAE/D;AAED,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAGvD,CAAC;AAEF,oCAAoC;AACpC,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @a2a-bsv/core — Configuration defaults and helpers.
3
+ */
4
+ export function toChain(network) {
5
+ return network === 'mainnet' ? 'main' : 'test';
6
+ }
7
+ /** Default TAAL API keys from the wallet-toolbox examples. */
8
+ export const DEFAULT_TAAL_API_KEYS = {
9
+ main: 'mainnet_9596de07e92300c6287e4393594ae39c',
10
+ test: 'testnet_0e6cf72133b43ea2d7861da2a38684e3',
11
+ };
12
+ /** Default SQLite database name. */
13
+ export const DEFAULT_DB_NAME = 'a2a_agent_wallet';
14
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAA0B;IAC1D,IAAI,EAAE,0CAA0C;IAChD,IAAI,EAAE,0CAA0C;CACjD,CAAC;AAEF,oCAAoC;AACpC,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,26 @@
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
+ export { BSVAgentWallet } from './wallet.js';
21
+ export type { WalletConfig, WalletIdentity, PaymentParams, PaymentResult, VerifyParams, VerifyResult, AcceptParams, AcceptResult, } from './types.js';
22
+ export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
23
+ export type { Chain } from './config.js';
24
+ export { buildPayment } from './payment.js';
25
+ export { verifyPayment, acceptPayment } from './verify.js';
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,27 @@
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
+ // Main wallet class
21
+ export { BSVAgentWallet } from './wallet.js';
22
+ // Config helpers (for advanced use)
23
+ export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
24
+ // Lower-level helpers (for advanced use)
25
+ export { buildPayment } from './payment.js';
26
+ export { verifyPayment, acceptPayment } from './verify.js';
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oBAAoB;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAc7C,oCAAoC;AACpC,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9E,yCAAyC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment construction helpers.
3
+ *
4
+ * Uses BRC-29 key derivation so the recipient can internalize the payment
5
+ * without ever reusing an address.
6
+ */
7
+ import type { SetupWallet } from '@bsv/wallet-toolbox';
8
+ import type { PaymentParams, PaymentResult } from './types.js';
9
+ /**
10
+ * Build a BRC-29 payment transaction using the wallet's createAction API.
11
+ *
12
+ * The transaction is created with `acceptDelayedBroadcast: false` — the sender
13
+ * broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
14
+ * returned so the recipient can verify and internalize the payment on their side.
15
+ */
16
+ export declare function buildPayment(setup: SetupWallet, params: PaymentParams): Promise<PaymentResult>;
17
+ //# sourceMappingURL=payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/core/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CA8ExB"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment construction helpers.
3
+ *
4
+ * Uses BRC-29 key derivation so the recipient can internalize the payment
5
+ * without ever reusing an address.
6
+ */
7
+ import { Beef, Utils } from '@bsv/sdk';
8
+ import { randomBytesBase64, ScriptTemplateBRC29 } from '@bsv/wallet-toolbox';
9
+ /**
10
+ * Build a BRC-29 payment transaction using the wallet's createAction API.
11
+ *
12
+ * The transaction is created with `acceptDelayedBroadcast: false` — the sender
13
+ * broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
14
+ * returned so the recipient can verify and internalize the payment on their side.
15
+ */
16
+ export async function buildPayment(setup, params) {
17
+ const { to, satoshis, description } = params;
18
+ const desc = normalizeDescription(description ?? 'agent payment');
19
+ // Generate unique BRC-29 derivation prefixes and suffixes
20
+ const derivationPrefix = randomBytesBase64(8);
21
+ const derivationSuffix = randomBytesBase64(8);
22
+ // Build BRC-29 locking script
23
+ const keyDeriver = setup.keyDeriver;
24
+ const t = new ScriptTemplateBRC29({
25
+ derivationPrefix,
26
+ derivationSuffix,
27
+ keyDeriver,
28
+ });
29
+ // Determine the recipient identity key.
30
+ // If `to` is a compressed public key hex (66 chars, starts with 02/03), use directly.
31
+ // Otherwise treat as an address — for BRC-29 we need a public key.
32
+ let recipientPubKey;
33
+ if (/^0[23][0-9a-fA-F]{64}$/.test(to)) {
34
+ recipientPubKey = to;
35
+ }
36
+ else {
37
+ // If it's an address, we can't do BRC-29 (needs pubkey). Throw a clear error.
38
+ throw new Error('PaymentParams.to must be a compressed public key (hex) for BRC-29 payments. ' +
39
+ 'Raw BSV addresses are not supported — the recipient must share their identity key.');
40
+ }
41
+ const lockingScript = t.lock(setup.rootKey.toString(), recipientPubKey);
42
+ const label = 'a2a-payment';
43
+ const car = await setup.wallet.createAction({
44
+ outputs: [
45
+ {
46
+ lockingScript: lockingScript.toHex(),
47
+ satoshis,
48
+ outputDescription: desc,
49
+ tags: ['relinquish'],
50
+ customInstructions: JSON.stringify({
51
+ derivationPrefix,
52
+ derivationSuffix,
53
+ type: 'BRC29',
54
+ }),
55
+ },
56
+ ],
57
+ options: {
58
+ randomizeOutputs: false,
59
+ acceptDelayedBroadcast: false,
60
+ },
61
+ labels: [label],
62
+ description: desc,
63
+ });
64
+ // Extract the txid from the createAction result.
65
+ // The tx field is a number[] (AtomicBEEF binary). Parse it to get txid.
66
+ if (!car.tx) {
67
+ throw new Error('createAction did not return a transaction. Check wallet funding.');
68
+ }
69
+ const beef = Beef.fromBinary(car.tx);
70
+ // The last transaction in the beef is our new tx
71
+ const lastTx = beef.txs[beef.txs.length - 1];
72
+ const txid = lastTx.txid;
73
+ // Encode the atomic BEEF as base64
74
+ const atomicBinary = beef.toBinaryAtomic(txid);
75
+ const beefBase64 = Utils.toBase64(atomicBinary);
76
+ return {
77
+ beef: beefBase64,
78
+ txid,
79
+ satoshis,
80
+ derivationPrefix,
81
+ derivationSuffix,
82
+ senderIdentityKey: setup.identityKey,
83
+ };
84
+ }
85
+ /**
86
+ * Ensure description meets BRC-100's 5-50 character requirement.
87
+ */
88
+ function normalizeDescription(desc) {
89
+ if (desc.length < 5)
90
+ return desc.padEnd(5, ' ');
91
+ if (desc.length > 50)
92
+ return desc.slice(0, 50);
93
+ return desc;
94
+ }
95
+ //# sourceMappingURL=payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/core/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAkB,EAClB,MAAqB;IAErB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,IAAI,GAAG,oBAAoB,CAAC,WAAW,IAAI,eAAe,CAAC,CAAC;IAElE,0DAA0D;IAC1D,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAE9C,8BAA8B;IAC9B,MAAM,UAAU,GAAG,KAAK,CAAC,UAA8B,CAAC;IACxD,MAAM,CAAC,GAAG,IAAI,mBAAmB,CAAC;QAChC,gBAAgB;QAChB,gBAAgB;QAChB,UAAU;KACX,CAAC,CAAC;IAEH,wCAAwC;IACxC,sFAAsF;IACtF,mEAAmE;IACnE,IAA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,CAAC;IAEzB,mCAAmC;IACnC,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEhD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI;QACJ,QAAQ;QACR,gBAAgB;QAChB,gBAAgB;QAChB,iBAAiB,EAAE,KAAK,CAAC,WAAW;KACrC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAY;IACxC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
3
+ */
4
+ /** Wallet configuration for creating or loading an agent wallet. */
5
+ export interface WalletConfig {
6
+ /** BSV network to use. */
7
+ network: 'mainnet' | 'testnet';
8
+ /** Directory path for SQLite wallet persistence. */
9
+ storageDir: string;
10
+ /** Optional: pre-existing root private key hex. If omitted on create(), a new one is generated. */
11
+ rootKeyHex?: string;
12
+ /** Optional TAAL API key for ARC broadcasting. Falls back to public default. */
13
+ taalApiKey?: string;
14
+ /** Optional fee model in sat/KB. Falls back to BSV_FEE_MODEL env var or default 100 sat/KB. */
15
+ feeModel?: number;
16
+ }
17
+ /** Parameters for building a payment transaction. */
18
+ export interface PaymentParams {
19
+ /** Recipient's compressed public key (hex) or BSV address. */
20
+ to: string;
21
+ /** Amount to pay in satoshis. */
22
+ satoshis: number;
23
+ /** Human-readable description (5-50 chars per BRC-100). */
24
+ description?: string;
25
+ /** Optional metadata embedded as OP_RETURN (future use). */
26
+ metadata?: {
27
+ taskId?: string;
28
+ protocol?: string;
29
+ };
30
+ }
31
+ /** Result from building a payment. */
32
+ export interface PaymentResult {
33
+ /** Base64-encoded Atomic BEEF transaction data. */
34
+ beef: string;
35
+ /** Transaction ID (hex). */
36
+ txid: string;
37
+ /** Amount paid in satoshis. */
38
+ satoshis: number;
39
+ /** BRC-29 derivation prefix (base64). Needed by recipient to internalize. */
40
+ derivationPrefix: string;
41
+ /** BRC-29 derivation suffix (base64). Needed by recipient to internalize. */
42
+ derivationSuffix: string;
43
+ /** Sender's identity key (compressed hex). Needed by recipient to internalize. */
44
+ senderIdentityKey: string;
45
+ }
46
+ /** Parameters for verifying an incoming payment. */
47
+ export interface VerifyParams {
48
+ /** Base64-encoded Atomic BEEF data. */
49
+ beef: string;
50
+ /** Expected payment amount in satoshis. */
51
+ expectedAmount?: number;
52
+ /** Expected sender identity key (optional). */
53
+ expectedSender?: string;
54
+ }
55
+ /** Result from verifying a payment. */
56
+ export interface VerifyResult {
57
+ /** Whether the payment passes all checks. */
58
+ valid: boolean;
59
+ /** Transaction ID (hex). */
60
+ txid: string;
61
+ /** Number of outputs found in the transaction. */
62
+ outputCount: number;
63
+ /** Errors encountered during verification. */
64
+ errors: string[];
65
+ }
66
+ /** Parameters for accepting (internalizing) a verified payment. */
67
+ export interface AcceptParams {
68
+ /** Base64-encoded Atomic BEEF data. */
69
+ beef: string;
70
+ /** The output index to internalize (default: 0). */
71
+ vout?: number;
72
+ /** BRC-29 derivation prefix from the PaymentResult. */
73
+ derivationPrefix: string;
74
+ /** BRC-29 derivation suffix from the PaymentResult. */
75
+ derivationSuffix: string;
76
+ /** Sender's identity key from the PaymentResult. */
77
+ senderIdentityKey: string;
78
+ /** Human-readable description for wallet records (5-50 chars). */
79
+ description?: string;
80
+ }
81
+ /** Result from accepting a payment. */
82
+ export interface AcceptResult {
83
+ /** Whether the payment was accepted. */
84
+ accepted: boolean;
85
+ }
86
+ /** Serializable wallet identity info, persisted alongside the SQLite database. */
87
+ export interface WalletIdentity {
88
+ /** The root private key (hex). Guard this carefully. */
89
+ rootKeyHex: string;
90
+ /** The wallet's public identity key (compressed hex). */
91
+ identityKey: string;
92
+ /** Network this wallet targets. */
93
+ network: 'mainnet' | 'testnet';
94
+ }
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,gBAAgB,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,gBAAgB,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,KAAK,EAAE,OAAO,CAAC;IACf,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;CAChC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment verification and acceptance helpers.
3
+ *
4
+ * Verification: parse the Atomic BEEF, validate structure.
5
+ * Acceptance: internalize the payment into the recipient wallet via BRC-29
6
+ * wallet payment protocol.
7
+ */
8
+ import type { SetupWallet } from '@bsv/wallet-toolbox';
9
+ import type { VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
10
+ /**
11
+ * Verify an incoming Atomic BEEF payment.
12
+ *
13
+ * This performs structural validation:
14
+ * - Decodes the base64 BEEF
15
+ * - Checks the BEEF is parseable
16
+ * - Checks there is at least one transaction
17
+ * - Runs SPV verification via tx.verify()
18
+ * - Optionally checks the sender identity key
19
+ */
20
+ export declare function verifyPayment(params: VerifyParams): Promise<VerifyResult>;
21
+ /**
22
+ * Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
23
+ *
24
+ * This calls wallet.internalizeAction with the 'wallet payment' protocol,
25
+ * providing the BRC-29 derivation info so the wallet can derive the correct
26
+ * key and claim the output.
27
+ */
28
+ export declare function acceptPayment(setup: SetupWallet, params: AcceptParams): Promise<AcceptResult>;
29
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/core/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGzF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAkD/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,CAAC,CA2BvB"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment verification and acceptance helpers.
3
+ *
4
+ * Verification: parse the Atomic BEEF, validate structure.
5
+ * Acceptance: internalize the payment into the recipient wallet via BRC-29
6
+ * wallet payment protocol.
7
+ */
8
+ import { Beef, Utils } from '@bsv/sdk';
9
+ /**
10
+ * Verify an incoming Atomic BEEF payment.
11
+ *
12
+ * This performs structural validation:
13
+ * - Decodes the base64 BEEF
14
+ * - Checks the BEEF is parseable
15
+ * - Checks there is at least one transaction
16
+ * - Runs SPV verification via tx.verify()
17
+ * - Optionally checks the sender identity key
18
+ */
19
+ export async function verifyPayment(params) {
20
+ const errors = [];
21
+ let txid = '';
22
+ let outputCount = 0;
23
+ try {
24
+ const binary = Utils.toArray(params.beef, 'base64');
25
+ const beef = Beef.fromBinary(binary);
26
+ if (beef.txs.length === 0) {
27
+ errors.push('BEEF contains no transactions');
28
+ }
29
+ else {
30
+ const lastTx = beef.txs[beef.txs.length - 1];
31
+ txid = lastTx.txid;
32
+ // Parse the atomic transaction to count outputs
33
+ const tx = beef.findAtomicTransaction(txid);
34
+ if (tx) {
35
+ outputCount = tx.outputs.length;
36
+ // Run SPV verification
37
+ try {
38
+ await tx.verify();
39
+ }
40
+ catch (err) {
41
+ const message = err instanceof Error ? err.message : String(err);
42
+ errors.push(`SPV verification failed: ${message}`);
43
+ }
44
+ }
45
+ else {
46
+ errors.push('Could not find atomic transaction in BEEF');
47
+ }
48
+ }
49
+ }
50
+ catch (err) {
51
+ const message = err instanceof Error ? err.message : String(err);
52
+ errors.push(`BEEF parse error: ${message}`);
53
+ }
54
+ // Sender validation is independent of BEEF parsing
55
+ if (params.expectedSender) {
56
+ if (!/^0[23][0-9a-fA-F]{64}$/.test(params.expectedSender)) {
57
+ errors.push('expectedSender is not a valid compressed public key');
58
+ }
59
+ }
60
+ return {
61
+ valid: errors.length === 0,
62
+ txid,
63
+ outputCount,
64
+ errors,
65
+ };
66
+ }
67
+ /**
68
+ * Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
69
+ *
70
+ * This calls wallet.internalizeAction with the 'wallet payment' protocol,
71
+ * providing the BRC-29 derivation info so the wallet can derive the correct
72
+ * key and claim the output.
73
+ */
74
+ export async function acceptPayment(setup, params) {
75
+ const desc = normalizeDescription(params.description ?? 'received payment');
76
+ const vout = params.vout ?? 0;
77
+ const binary = Utils.toArray(params.beef, 'base64');
78
+ const args = {
79
+ tx: binary,
80
+ outputs: [
81
+ {
82
+ outputIndex: vout,
83
+ protocol: 'wallet payment',
84
+ paymentRemittance: {
85
+ derivationPrefix: params.derivationPrefix,
86
+ derivationSuffix: params.derivationSuffix,
87
+ senderIdentityKey: params.senderIdentityKey,
88
+ },
89
+ },
90
+ ],
91
+ description: desc,
92
+ };
93
+ const result = await setup.wallet.internalizeAction(args);
94
+ return {
95
+ accepted: result.accepted,
96
+ };
97
+ }
98
+ function normalizeDescription(desc) {
99
+ if (desc.length < 5)
100
+ return desc.padEnd(5, ' ');
101
+ if (desc.length > 50)
102
+ return desc.slice(0, 50);
103
+ return desc;
104
+ }
105
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/core/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKvC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAoB;IACtD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAErC,IAAI,IA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