openclaw-simplesv-plugin 0.1.4 → 0.1.6
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 +50 -10
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -12
- package/dist/index.js.map +1 -1
- package/dist/src/actions.d.ts +19 -0
- package/dist/src/actions.d.ts.map +1 -0
- package/dist/src/actions.js +46 -0
- package/dist/src/actions.js.map +1 -0
- 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/wallet.d.ts +12 -0
- package/dist/src/wallet.d.ts.map +1 -0
- package/dist/src/wallet.js +16 -0
- package/dist/src/wallet.js.map +1 -0
- package/index.ts +73 -12
- package/openclaw.plugin.json +12 -1
- package/package.json +1 -1
- package/src/actions.ts +54 -0
- 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/wallet.ts +20 -0
package/openclaw.plugin.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "openclaw-simplesv",
|
|
2
|
+
"id": "openclaw-simplesv-plugin",
|
|
3
3
|
"name": "BSV Simple Utility Belt",
|
|
4
4
|
"description": "High-level blockchain operations: DIDs, PushDrop tokens, and Inscriptions. Supports optional MCP integration.",
|
|
5
5
|
"version": "0.1.2",
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
"default": "https://chaintracks-us-1.bsvb.tech",
|
|
21
21
|
"description": "Custom Chaintracks server URL for SPV header verification"
|
|
22
22
|
},
|
|
23
|
+
"arcUrl": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"default": "https://arc.gorillapool.io",
|
|
26
|
+
"description": "Custom ARC/Arcade server URL for transaction broadcasting"
|
|
27
|
+
},
|
|
23
28
|
"walletDir": {
|
|
24
29
|
"type": "string",
|
|
25
30
|
"description": "Path to BSV wallet storage (defaults to ~/.openclaw/bsv-wallet)"
|
|
@@ -41,6 +46,12 @@
|
|
|
41
46
|
"help": "Custom server for SPV block header verification",
|
|
42
47
|
"advanced": true
|
|
43
48
|
},
|
|
49
|
+
"arcUrl": {
|
|
50
|
+
"label": "ARC/Arcade Server URL",
|
|
51
|
+
"placeholder": "https://arc.gorillapool.io",
|
|
52
|
+
"help": "Custom server for transaction broadcasting",
|
|
53
|
+
"advanced": true
|
|
54
|
+
},
|
|
44
55
|
"enableMcp": {
|
|
45
56
|
"label": "Enable Advanced MCP Tools",
|
|
46
57
|
"help": "Requires @bsv/simple-mcp to be installed"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-simplesv-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "OpenClaw plugin for advanced BSV operations (DIDs, Tokens, Inscriptions) via @bsv/simple and optional MCP integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
package/src/actions.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ClawWalletCore } from './wallet.js';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { createDIDMethods } from '@bsv/simple/dist/modules/did.js';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { createInscriptionMethods } from '@bsv/simple/dist/modules/inscriptions.js';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { createTokenMethods } from '@bsv/simple/dist/modules/tokens.js';
|
|
8
|
+
|
|
9
|
+
export class SimpleSVManager {
|
|
10
|
+
private didMethods: any;
|
|
11
|
+
private inscriptionMethods: any;
|
|
12
|
+
private tokenMethods: any;
|
|
13
|
+
private core: ClawWalletCore;
|
|
14
|
+
|
|
15
|
+
constructor(core: ClawWalletCore) {
|
|
16
|
+
this.core = core;
|
|
17
|
+
// Initialize high-level modules
|
|
18
|
+
this.didMethods = createDIDMethods(core);
|
|
19
|
+
this.inscriptionMethods = createInscriptionMethods(core);
|
|
20
|
+
this.tokenMethods = createTokenMethods(core);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async resolveDid(did: string) {
|
|
24
|
+
return await this.didMethods.resolveDID(did);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getMyDid() {
|
|
28
|
+
return await this.didMethods.getDID();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async inscribe(data: any, text?: string) {
|
|
32
|
+
if (text) {
|
|
33
|
+
return await this.inscriptionMethods.createInscription({ text });
|
|
34
|
+
}
|
|
35
|
+
return await this.inscriptionMethods.createInscription({ data });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async issueToken(basket: string, data: any) {
|
|
39
|
+
return await this.tokenMethods.issueToken({ basket, data });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async transferToken(tokenId: string, recipientKey: string) {
|
|
43
|
+
return await this.tokenMethods.transferToken({ tokenId, recipientKey });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getStatus() {
|
|
47
|
+
return {
|
|
48
|
+
identityKey: this.core.identityKey,
|
|
49
|
+
address: this.core.getAddress(),
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
status: this.core.getStatus()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -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';
|
|
@@ -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,111 @@
|
|
|
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
|
+
|
|
8
|
+
import { Beef, Utils } from '@bsv/sdk';
|
|
9
|
+
import { randomBytesBase64, ScriptTemplateBRC29 } from '@bsv/wallet-toolbox';
|
|
10
|
+
import type { SetupWallet } from '@bsv/wallet-toolbox';
|
|
11
|
+
import type { PaymentParams, PaymentResult } from './types.js';
|
|
12
|
+
import type { CachedKeyDeriver } from '@bsv/sdk';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build a BRC-29 payment transaction using the wallet's createAction API.
|
|
16
|
+
*
|
|
17
|
+
* The transaction is created with `acceptDelayedBroadcast: false` — the sender
|
|
18
|
+
* broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
|
|
19
|
+
* returned so the recipient can verify and internalize the payment on their side.
|
|
20
|
+
*/
|
|
21
|
+
export async function buildPayment(
|
|
22
|
+
setup: SetupWallet,
|
|
23
|
+
params: PaymentParams,
|
|
24
|
+
): Promise<PaymentResult> {
|
|
25
|
+
const { to, satoshis, description } = params;
|
|
26
|
+
const desc = normalizeDescription(description ?? 'agent payment');
|
|
27
|
+
|
|
28
|
+
// Generate unique BRC-29 derivation prefixes and suffixes
|
|
29
|
+
const derivationPrefix = randomBytesBase64(8);
|
|
30
|
+
const derivationSuffix = randomBytesBase64(8);
|
|
31
|
+
|
|
32
|
+
// Build BRC-29 locking script
|
|
33
|
+
const keyDeriver = setup.keyDeriver as CachedKeyDeriver;
|
|
34
|
+
const t = new ScriptTemplateBRC29({
|
|
35
|
+
derivationPrefix,
|
|
36
|
+
derivationSuffix,
|
|
37
|
+
keyDeriver,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Determine the recipient identity key.
|
|
41
|
+
// If `to` is a compressed public key hex (66 chars, starts with 02/03), use directly.
|
|
42
|
+
// Otherwise treat as an address — for BRC-29 we need a public key.
|
|
43
|
+
let recipientPubKey: string;
|
|
44
|
+
if (/^0[23][0-9a-fA-F]{64}$/.test(to)) {
|
|
45
|
+
recipientPubKey = to;
|
|
46
|
+
} else {
|
|
47
|
+
// If it's an address, we can't do BRC-29 (needs pubkey). Throw a clear error.
|
|
48
|
+
throw new Error(
|
|
49
|
+
'PaymentParams.to must be a compressed public key (hex) for BRC-29 payments. ' +
|
|
50
|
+
'Raw BSV addresses are not supported — the recipient must share their identity key.'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const lockingScript = t.lock(setup.rootKey.toString(), recipientPubKey);
|
|
55
|
+
|
|
56
|
+
const label = 'a2a-payment';
|
|
57
|
+
const car = await setup.wallet.createAction({
|
|
58
|
+
outputs: [
|
|
59
|
+
{
|
|
60
|
+
lockingScript: lockingScript.toHex(),
|
|
61
|
+
satoshis,
|
|
62
|
+
outputDescription: desc,
|
|
63
|
+
tags: ['relinquish'],
|
|
64
|
+
customInstructions: JSON.stringify({
|
|
65
|
+
derivationPrefix,
|
|
66
|
+
derivationSuffix,
|
|
67
|
+
type: 'BRC29',
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
options: {
|
|
72
|
+
randomizeOutputs: false,
|
|
73
|
+
acceptDelayedBroadcast: false,
|
|
74
|
+
},
|
|
75
|
+
labels: [label],
|
|
76
|
+
description: desc,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Extract the txid from the createAction result.
|
|
80
|
+
// The tx field is a number[] (AtomicBEEF binary). Parse it to get txid.
|
|
81
|
+
if (!car.tx) {
|
|
82
|
+
throw new Error('createAction did not return a transaction. Check wallet funding.');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const beef = Beef.fromBinary(car.tx);
|
|
86
|
+
// The last transaction in the beef is our new tx
|
|
87
|
+
const lastTx = beef.txs[beef.txs.length - 1];
|
|
88
|
+
const txid = lastTx.txid;
|
|
89
|
+
|
|
90
|
+
// Encode the atomic BEEF as base64
|
|
91
|
+
const atomicBinary = beef.toBinaryAtomic(txid);
|
|
92
|
+
const beefBase64 = Utils.toBase64(atomicBinary);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
beef: beefBase64,
|
|
96
|
+
txid,
|
|
97
|
+
satoshis,
|
|
98
|
+
derivationPrefix,
|
|
99
|
+
derivationSuffix,
|
|
100
|
+
senderIdentityKey: setup.identityKey,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Ensure description meets BRC-100's 5-50 character requirement.
|
|
106
|
+
*/
|
|
107
|
+
function normalizeDescription(desc: string): string {
|
|
108
|
+
if (desc.length < 5) return desc.padEnd(5, ' ');
|
|
109
|
+
if (desc.length > 50) return desc.slice(0, 50);
|
|
110
|
+
return desc;
|
|
111
|
+
}
|
|
@@ -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,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Wallet configuration for creating or loading an agent wallet. */
|
|
6
|
+
export interface WalletConfig {
|
|
7
|
+
/** BSV network to use. */
|
|
8
|
+
network: 'mainnet' | 'testnet';
|
|
9
|
+
/** Directory path for SQLite wallet persistence. */
|
|
10
|
+
storageDir: string;
|
|
11
|
+
/** Optional: pre-existing root private key hex. If omitted on create(), a new one is generated. */
|
|
12
|
+
rootKeyHex?: string;
|
|
13
|
+
/** Optional TAAL API key for ARC broadcasting. Falls back to public default. */
|
|
14
|
+
taalApiKey?: string;
|
|
15
|
+
/** Optional fee model in sat/KB. Falls back to BSV_FEE_MODEL env var or default 100 sat/KB. */
|
|
16
|
+
feeModel?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Parameters for building a payment transaction. */
|
|
20
|
+
export interface PaymentParams {
|
|
21
|
+
/** Recipient's compressed public key (hex) or BSV address. */
|
|
22
|
+
to: string;
|
|
23
|
+
/** Amount to pay in satoshis. */
|
|
24
|
+
satoshis: number;
|
|
25
|
+
/** Human-readable description (5-50 chars per BRC-100). */
|
|
26
|
+
description?: string;
|
|
27
|
+
/** Optional metadata embedded as OP_RETURN (future use). */
|
|
28
|
+
metadata?: {
|
|
29
|
+
taskId?: string;
|
|
30
|
+
protocol?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Result from building a payment. */
|
|
35
|
+
export interface PaymentResult {
|
|
36
|
+
/** Base64-encoded Atomic BEEF transaction data. */
|
|
37
|
+
beef: string;
|
|
38
|
+
/** Transaction ID (hex). */
|
|
39
|
+
txid: string;
|
|
40
|
+
/** Amount paid in satoshis. */
|
|
41
|
+
satoshis: number;
|
|
42
|
+
/** BRC-29 derivation prefix (base64). Needed by recipient to internalize. */
|
|
43
|
+
derivationPrefix: string;
|
|
44
|
+
/** BRC-29 derivation suffix (base64). Needed by recipient to internalize. */
|
|
45
|
+
derivationSuffix: string;
|
|
46
|
+
/** Sender's identity key (compressed hex). Needed by recipient to internalize. */
|
|
47
|
+
senderIdentityKey: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Parameters for verifying an incoming payment. */
|
|
51
|
+
export interface VerifyParams {
|
|
52
|
+
/** Base64-encoded Atomic BEEF data. */
|
|
53
|
+
beef: string;
|
|
54
|
+
/** Expected payment amount in satoshis. */
|
|
55
|
+
expectedAmount?: number;
|
|
56
|
+
/** Expected sender identity key (optional). */
|
|
57
|
+
expectedSender?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Result from verifying a payment. */
|
|
61
|
+
export interface VerifyResult {
|
|
62
|
+
/** Whether the payment passes all checks. */
|
|
63
|
+
valid: boolean;
|
|
64
|
+
/** Transaction ID (hex). */
|
|
65
|
+
txid: string;
|
|
66
|
+
/** Number of outputs found in the transaction. */
|
|
67
|
+
outputCount: number;
|
|
68
|
+
/** Errors encountered during verification. */
|
|
69
|
+
errors: string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Parameters for accepting (internalizing) a verified payment. */
|
|
73
|
+
export interface AcceptParams {
|
|
74
|
+
/** Base64-encoded Atomic BEEF data. */
|
|
75
|
+
beef: string;
|
|
76
|
+
/** The output index to internalize (default: 0). */
|
|
77
|
+
vout?: number;
|
|
78
|
+
/** BRC-29 derivation prefix from the PaymentResult. */
|
|
79
|
+
derivationPrefix: string;
|
|
80
|
+
/** BRC-29 derivation suffix from the PaymentResult. */
|
|
81
|
+
derivationSuffix: string;
|
|
82
|
+
/** Sender's identity key from the PaymentResult. */
|
|
83
|
+
senderIdentityKey: string;
|
|
84
|
+
/** Human-readable description for wallet records (5-50 chars). */
|
|
85
|
+
description?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Result from accepting a payment. */
|
|
89
|
+
export interface AcceptResult {
|
|
90
|
+
/** Whether the payment was accepted. */
|
|
91
|
+
accepted: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Serializable wallet identity info, persisted alongside the SQLite database. */
|
|
95
|
+
export interface WalletIdentity {
|
|
96
|
+
/** The root private key (hex). Guard this carefully. */
|
|
97
|
+
rootKeyHex: string;
|
|
98
|
+
/** The wallet's public identity key (compressed hex). */
|
|
99
|
+
identityKey: string;
|
|
100
|
+
/** Network this wallet targets. */
|
|
101
|
+
network: 'mainnet' | 'testnet';
|
|
102
|
+
}
|
|
@@ -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,119 @@
|
|
|
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
|
+
|
|
9
|
+
import { Beef, Utils } from '@bsv/sdk';
|
|
10
|
+
import type { SetupWallet } from '@bsv/wallet-toolbox';
|
|
11
|
+
import type { VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
|
|
12
|
+
import type { InternalizeActionArgs } from '@bsv/sdk';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Verify an incoming Atomic BEEF payment.
|
|
16
|
+
*
|
|
17
|
+
* This performs structural validation:
|
|
18
|
+
* - Decodes the base64 BEEF
|
|
19
|
+
* - Checks the BEEF is parseable
|
|
20
|
+
* - Checks there is at least one transaction
|
|
21
|
+
* - Runs SPV verification via tx.verify()
|
|
22
|
+
* - Optionally checks the sender identity key
|
|
23
|
+
*/
|
|
24
|
+
export async function verifyPayment(params: VerifyParams): Promise<VerifyResult> {
|
|
25
|
+
const errors: string[] = [];
|
|
26
|
+
let txid = '';
|
|
27
|
+
let outputCount = 0;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const binary = Utils.toArray(params.beef, 'base64');
|
|
31
|
+
const beef = Beef.fromBinary(binary);
|
|
32
|
+
|
|
33
|
+
if (beef.txs.length === 0) {
|
|
34
|
+
errors.push('BEEF contains no transactions');
|
|
35
|
+
} else {
|
|
36
|
+
const lastTx = beef.txs[beef.txs.length - 1];
|
|
37
|
+
txid = lastTx.txid;
|
|
38
|
+
|
|
39
|
+
// Parse the atomic transaction to count outputs
|
|
40
|
+
const tx = beef.findAtomicTransaction(txid);
|
|
41
|
+
if (tx) {
|
|
42
|
+
outputCount = tx.outputs.length;
|
|
43
|
+
|
|
44
|
+
// Run SPV verification
|
|
45
|
+
try {
|
|
46
|
+
await tx.verify();
|
|
47
|
+
} catch (err: unknown) {
|
|
48
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
49
|
+
errors.push(`SPV verification failed: ${message}`);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
errors.push('Could not find atomic transaction in BEEF');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} catch (err: unknown) {
|
|
57
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
58
|
+
errors.push(`BEEF parse error: ${message}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Sender validation is independent of BEEF parsing
|
|
62
|
+
if (params.expectedSender) {
|
|
63
|
+
if (!/^0[23][0-9a-fA-F]{64}$/.test(params.expectedSender)) {
|
|
64
|
+
errors.push('expectedSender is not a valid compressed public key');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
valid: errors.length === 0,
|
|
70
|
+
txid,
|
|
71
|
+
outputCount,
|
|
72
|
+
errors,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
|
|
78
|
+
*
|
|
79
|
+
* This calls wallet.internalizeAction with the 'wallet payment' protocol,
|
|
80
|
+
* providing the BRC-29 derivation info so the wallet can derive the correct
|
|
81
|
+
* key and claim the output.
|
|
82
|
+
*/
|
|
83
|
+
export async function acceptPayment(
|
|
84
|
+
setup: SetupWallet,
|
|
85
|
+
params: AcceptParams,
|
|
86
|
+
): Promise<AcceptResult> {
|
|
87
|
+
const desc = normalizeDescription(params.description ?? 'received payment');
|
|
88
|
+
const vout = params.vout ?? 0;
|
|
89
|
+
|
|
90
|
+
const binary = Utils.toArray(params.beef, 'base64');
|
|
91
|
+
|
|
92
|
+
const args: InternalizeActionArgs = {
|
|
93
|
+
tx: binary,
|
|
94
|
+
outputs: [
|
|
95
|
+
{
|
|
96
|
+
outputIndex: vout,
|
|
97
|
+
protocol: 'wallet payment',
|
|
98
|
+
paymentRemittance: {
|
|
99
|
+
derivationPrefix: params.derivationPrefix,
|
|
100
|
+
derivationSuffix: params.derivationSuffix,
|
|
101
|
+
senderIdentityKey: params.senderIdentityKey,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
description: desc,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const result = await setup.wallet.internalizeAction(args);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
accepted: result.accepted,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function normalizeDescription(desc: string): string {
|
|
116
|
+
if (desc.length < 5) return desc.padEnd(5, ' ');
|
|
117
|
+
if (desc.length > 50) return desc.slice(0, 50);
|
|
118
|
+
return desc;
|
|
119
|
+
}
|