bsv-mcp 0.2.9 → 0.2.11
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/CHANGELOG.md +19 -0
- package/README.md +26 -2
- package/dist/index.js +6777 -126216
- package/index.ts +287 -265
- package/package.json +4 -3
- package/tools/bap/generate.test.ts +17 -16
- package/tools/index.ts +8 -3
- package/tools/ordinals/getInscription.ts +15 -65
- package/tools/ordinals/getTokenByIdOrTicker.ts +14 -80
- package/tools/ordinals/index.ts +8 -7
- package/tools/ordinals/marketListings.ts +21 -188
- package/tools/ordinals/marketSales.ts +21 -127
- package/tools/ordinals/searchInscriptions.ts +21 -108
- package/tools/wallet/brc100.ts +572 -0
- package/tools/wallet/cancelListing.ts +80 -0
- package/tools/wallet/createOrdinals.ts +62 -143
- package/tools/wallet/getAddress.ts +19 -13
- package/tools/wallet/getBalance.ts +29 -25
- package/tools/wallet/getBsv21Balances.ts +28 -0
- package/tools/wallet/getLockData.ts +25 -0
- package/tools/wallet/getOrdinals.ts +35 -0
- package/tools/wallet/listOrdinal.ts +86 -0
- package/tools/wallet/listTokens.ts +28 -0
- package/tools/wallet/lockBsv.ts +69 -0
- package/tools/wallet/opnsDeregister.ts +80 -0
- package/tools/wallet/opnsRegister.ts +80 -0
- package/tools/wallet/purchaseListing.ts +89 -290
- package/tools/wallet/refreshUtxos.ts +21 -32
- package/tools/wallet/schemas.ts +7 -11
- package/tools/wallet/sendAllBsv.ts +64 -0
- package/tools/wallet/sendToAddress.ts +46 -47
- package/tools/wallet/signBsm.ts +29 -0
- package/tools/wallet/sweepBsv.ts +70 -0
- package/tools/wallet/sweepBsv21.ts +71 -0
- package/tools/wallet/sweepOrdinals.ts +69 -0
- package/tools/wallet/tools.ts +50 -88
- package/tools/wallet/transferOrdToken.ts +137 -129
- package/tools/wallet/unlockBsv.ts +57 -0
- package/tools/wallet/a2bPublishAgent.ts +0 -307
- package/tools/wallet/sendOrdinals.ts +0 -160
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OneSatContext } from '@1sat/actions'
|
|
2
|
+
import { sendAllBsv } from '@1sat/actions'
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
|
|
6
|
+
const sendAllBsvArgsSchema = z.object({
|
|
7
|
+
destination: z
|
|
8
|
+
.string()
|
|
9
|
+
.describe('Destination P2PKH address to send all funds to'),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export function registerSendAllBsvTool(
|
|
13
|
+
server: McpServer,
|
|
14
|
+
ctx: OneSatContext | undefined,
|
|
15
|
+
) {
|
|
16
|
+
server.tool(
|
|
17
|
+
'wallet_sendAllBsv',
|
|
18
|
+
'Send all BSV in the wallet to a single recipient',
|
|
19
|
+
{ ...sendAllBsvArgsSchema.shape },
|
|
20
|
+
async ({ destination }) => {
|
|
21
|
+
if (!ctx) {
|
|
22
|
+
return {
|
|
23
|
+
content: [
|
|
24
|
+
{
|
|
25
|
+
type: 'text',
|
|
26
|
+
text: 'Wallet not initialized. Please configure a wallet before sending.',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
isError: true,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const result = await sendAllBsv.execute(ctx, { destination })
|
|
35
|
+
|
|
36
|
+
if (result.error) {
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: 'text', text: result.error }],
|
|
39
|
+
isError: true,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: JSON.stringify(result, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
} catch (err: unknown) {
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
text: err instanceof Error ? err.message : String(err),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
isError: true,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -1,75 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
1
|
+
import type { OneSatContext } from '@1sat/actions'
|
|
2
|
+
import { sendBsv } from '@1sat/actions'
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { toSatoshi } from 'satoshi-token'
|
|
5
|
+
import { getBsvPriceWithCache } from '../bsv/getPrice'
|
|
6
|
+
import { sendToAddressArgsSchema } from './schemas'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export function registerSendToAddressTool(
|
|
9
|
+
server: McpServer,
|
|
10
|
+
ctx: OneSatContext | undefined,
|
|
11
|
+
) {
|
|
12
12
|
server.tool(
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
'wallet_sendToAddress',
|
|
14
|
+
'Sends Bitcoin SV (BSV) to a specified address. This tool supports payments in both BSV and USD amounts (with automatic conversion using current exchange rates). Transaction fees are automatically calculated and a confirmation with transaction ID is returned upon success.',
|
|
15
15
|
{ ...sendToAddressArgsSchema.shape },
|
|
16
|
-
async ({ address, amount, currency =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
async ({ address, amount, currency = 'BSV', description = 'Send to address' }) => {
|
|
17
|
+
if (!ctx) {
|
|
18
|
+
return {
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
type: 'text',
|
|
22
|
+
text: 'Wallet not initialized. Please configure a wallet before sending.',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
isError: true,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
let satoshis: number
|
|
31
|
+
if (currency === 'USD') {
|
|
32
|
+
const bsvPriceUsd = await getBsvPriceWithCache()
|
|
33
|
+
satoshis = toSatoshi(amount / bsvPriceUsd)
|
|
30
34
|
} else {
|
|
31
|
-
|
|
32
|
-
satoshis = toSatoshi(amount);
|
|
35
|
+
satoshis = toSatoshi(amount)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
const result = await sendBsv.execute(ctx, {
|
|
39
|
+
requests: [{ address, satoshis }],
|
|
40
|
+
})
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
satoshis,
|
|
45
|
-
outputDescription: `Payment to ${address}`,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
});
|
|
42
|
+
if (result.error) {
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: 'text', text: result.error }],
|
|
45
|
+
isError: true,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
49
48
|
|
|
50
49
|
return {
|
|
51
50
|
content: [
|
|
52
51
|
{
|
|
53
|
-
type:
|
|
52
|
+
type: 'text',
|
|
54
53
|
text: JSON.stringify({
|
|
55
|
-
status:
|
|
56
|
-
txid:
|
|
54
|
+
status: 'success',
|
|
55
|
+
txid: result.txid,
|
|
57
56
|
satoshis,
|
|
58
57
|
}),
|
|
59
58
|
},
|
|
60
59
|
],
|
|
61
|
-
}
|
|
60
|
+
}
|
|
62
61
|
} catch (error) {
|
|
63
62
|
return {
|
|
64
63
|
content: [
|
|
65
64
|
{
|
|
66
|
-
type:
|
|
65
|
+
type: 'text',
|
|
67
66
|
text: error instanceof Error ? error.message : String(error),
|
|
68
67
|
},
|
|
69
68
|
],
|
|
70
69
|
isError: true,
|
|
71
|
-
}
|
|
70
|
+
}
|
|
72
71
|
}
|
|
73
72
|
},
|
|
74
|
-
)
|
|
73
|
+
)
|
|
75
74
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { signBsm, type OneSatContext } from '@1sat/actions'
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
export function registerSignBsmTool(
|
|
6
|
+
server: McpServer,
|
|
7
|
+
ctx?: OneSatContext,
|
|
8
|
+
) {
|
|
9
|
+
server.tool(
|
|
10
|
+
'wallet_signBsm',
|
|
11
|
+
'Sign a message using BSM (Bitcoin Signed Message) format',
|
|
12
|
+
{
|
|
13
|
+
message: z.string().describe('The message to sign'),
|
|
14
|
+
encoding: z.enum(['utf8', 'hex', 'base64']).optional().describe('Message encoding format'),
|
|
15
|
+
},
|
|
16
|
+
async (params) => {
|
|
17
|
+
try {
|
|
18
|
+
if (!ctx) throw new Error('BRC-100 wallet context not available')
|
|
19
|
+
const result = await signBsm.execute(ctx, params)
|
|
20
|
+
return {
|
|
21
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
22
|
+
}
|
|
23
|
+
} catch (err: unknown) {
|
|
24
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
25
|
+
return { content: [{ type: 'text', text: msg }], isError: true }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { OneSatContext } from '@1sat/actions'
|
|
2
|
+
import { sweepBsv } from '@1sat/actions'
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
|
|
6
|
+
const sweepInputSchema = z.object({
|
|
7
|
+
outpoint: z.string().describe('Outpoint (txid_vout)'),
|
|
8
|
+
satoshis: z.number().int().describe('Satoshis in output'),
|
|
9
|
+
lockingScript: z.string().describe('Locking script hex'),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const sweepBsvSchema = z.object({
|
|
13
|
+
inputs: z.array(sweepInputSchema).describe('UTXOs to sweep (use prepareSweepInputs to build these)'),
|
|
14
|
+
wif: z.string().describe('WIF private key controlling the inputs'),
|
|
15
|
+
amount: z.number().int().optional().describe('Amount to sweep (satoshis). If omitted, sweeps all input value.'),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export function registerSweepBsvTool(
|
|
19
|
+
server: McpServer,
|
|
20
|
+
ctx: OneSatContext | undefined,
|
|
21
|
+
) {
|
|
22
|
+
server.tool(
|
|
23
|
+
'wallet_sweepBsv',
|
|
24
|
+
'Sweep BSV from an external WIF private key into the wallet',
|
|
25
|
+
{ ...sweepBsvSchema.shape },
|
|
26
|
+
async ({ inputs, wif, amount }) => {
|
|
27
|
+
if (!ctx) {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text' as const,
|
|
32
|
+
text: 'BRC-100 wallet context not available',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
isError: true,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const result = await sweepBsv.execute(ctx, { inputs, wif, amount })
|
|
41
|
+
|
|
42
|
+
if (result.error) {
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: 'text' as const, text: result.error }],
|
|
45
|
+
isError: true,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: 'text' as const,
|
|
53
|
+
text: JSON.stringify(result, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2),
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text' as const,
|
|
62
|
+
text: error instanceof Error ? error.message : String(error),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
isError: true,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { OneSatContext } from '@1sat/actions'
|
|
2
|
+
import { sweepBsv21 } from '@1sat/actions'
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
|
|
6
|
+
const sweepBsv21InputSchema = z.object({
|
|
7
|
+
outpoint: z.string().describe('Outpoint (txid_vout)'),
|
|
8
|
+
satoshis: z.number().int().describe('Satoshis (should be 1)'),
|
|
9
|
+
lockingScript: z.string().describe('Locking script hex'),
|
|
10
|
+
tokenId: z.string().describe('Token ID (txid_vout format)'),
|
|
11
|
+
amount: z.string().describe('Token amount as string'),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const sweepBsv21Schema = z.object({
|
|
15
|
+
inputs: z.array(sweepBsv21InputSchema).describe('Token UTXOs to sweep (must all be same tokenId)'),
|
|
16
|
+
wif: z.string().describe('WIF private key controlling the inputs'),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export function registerSweepBsv21Tool(
|
|
20
|
+
server: McpServer,
|
|
21
|
+
ctx: OneSatContext | undefined,
|
|
22
|
+
) {
|
|
23
|
+
server.tool(
|
|
24
|
+
'wallet_sweepBsv21',
|
|
25
|
+
'Sweep BSV21 tokens from an external WIF private key into the wallet',
|
|
26
|
+
{ ...sweepBsv21Schema.shape },
|
|
27
|
+
async ({ inputs, wif }) => {
|
|
28
|
+
if (!ctx) {
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: 'text' as const,
|
|
33
|
+
text: 'BRC-100 wallet context not available',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
isError: true,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const result = await sweepBsv21.execute(ctx, { inputs, wif })
|
|
42
|
+
|
|
43
|
+
if (result.error) {
|
|
44
|
+
return {
|
|
45
|
+
content: [{ type: 'text' as const, text: result.error }],
|
|
46
|
+
isError: true,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text' as const,
|
|
54
|
+
text: JSON.stringify(result, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: 'text' as const,
|
|
63
|
+
text: error instanceof Error ? error.message : String(error),
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
isError: true,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { OneSatContext } from '@1sat/actions'
|
|
2
|
+
import { sweepOrdinals } from '@1sat/actions'
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
|
|
6
|
+
const sweepInputSchema = z.object({
|
|
7
|
+
outpoint: z.string().describe('Outpoint (txid_vout)'),
|
|
8
|
+
satoshis: z.number().int().describe('Satoshis (should be 1)'),
|
|
9
|
+
lockingScript: z.string().describe('Locking script hex'),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const sweepOrdinalsSchema = z.object({
|
|
13
|
+
inputs: z.array(sweepInputSchema).describe('Ordinal UTXOs to sweep'),
|
|
14
|
+
wif: z.string().describe('WIF private key controlling the inputs'),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export function registerSweepOrdinalsTool(
|
|
18
|
+
server: McpServer,
|
|
19
|
+
ctx: OneSatContext | undefined,
|
|
20
|
+
) {
|
|
21
|
+
server.tool(
|
|
22
|
+
'wallet_sweepOrdinals',
|
|
23
|
+
'Sweep ordinals from an external WIF private key into the wallet',
|
|
24
|
+
{ ...sweepOrdinalsSchema.shape },
|
|
25
|
+
async ({ inputs, wif }) => {
|
|
26
|
+
if (!ctx) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text' as const,
|
|
31
|
+
text: 'BRC-100 wallet context not available',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const result = await sweepOrdinals.execute(ctx, { inputs, wif })
|
|
40
|
+
|
|
41
|
+
if (result.error) {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: 'text' as const, text: result.error }],
|
|
44
|
+
isError: true,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: 'text' as const,
|
|
52
|
+
text: JSON.stringify(result, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2),
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text' as const,
|
|
61
|
+
text: error instanceof Error ? error.message : String(error),
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
isError: true,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
)
|
|
69
|
+
}
|
package/tools/wallet/tools.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { OneSatContext } from "@1sat/actions";
|
|
2
|
+
import type { PrivateKey } from "@bsv/sdk";
|
|
2
3
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
import { registerA2bPublishMcpTool } from "./a2bPublishMcp";
|
|
5
|
+
import { registerBrc100Tools } from "./brc100";
|
|
4
6
|
import { registerCreateOrdinalsTool } from "./createOrdinals";
|
|
5
7
|
import { registerGatherCollectionInfoTool } from "./gatherCollectionInfo";
|
|
6
8
|
import { registerGetAddressTool } from "./getAddress";
|
|
7
9
|
import { registerWalletGetBalanceTool } from "./getBalance";
|
|
8
|
-
import {
|
|
10
|
+
import { registerGetBsv21BalancesTool } from "./getBsv21Balances";
|
|
11
|
+
import { registerGetLockDataTool } from "./getLockData";
|
|
12
|
+
import { registerGetOrdinalsTool } from "./getOrdinals";
|
|
13
|
+
import { registerListTokensTool } from "./listTokens";
|
|
9
14
|
import { registerMintCollectionTool } from "./mintCollection";
|
|
10
15
|
import { registerPurchaseListingTool } from "./purchaseListing";
|
|
11
16
|
import { registerRefreshUtxosTool } from "./refreshUtxos";
|
|
12
|
-
import { walletEncryptionArgsSchema } from "./schemas";
|
|
13
17
|
import { registerSendToAddressTool } from "./sendToAddress";
|
|
18
|
+
import { registerSignBsmTool } from "./signBsm";
|
|
14
19
|
import { registerTransferOrdTokenTool } from "./transferOrdToken";
|
|
20
|
+
import { registerListOrdinalTool } from "./listOrdinal";
|
|
21
|
+
import { registerCancelListingTool } from "./cancelListing";
|
|
22
|
+
import { registerSendAllBsvTool } from "./sendAllBsv";
|
|
23
|
+
import { registerLockBsvTool } from "./lockBsv";
|
|
24
|
+
import { registerUnlockBsvTool } from "./unlockBsv";
|
|
25
|
+
import { registerOpnsRegisterTool } from "./opnsRegister";
|
|
26
|
+
import { registerOpnsDeregisterTool } from "./opnsDeregister";
|
|
27
|
+
import { registerSweepBsvTool } from "./sweepBsv";
|
|
28
|
+
import { registerSweepOrdinalsTool } from "./sweepOrdinals";
|
|
29
|
+
import { registerSweepBsv21Tool } from "./sweepBsv21";
|
|
15
30
|
import type { Wallet } from "./wallet";
|
|
16
31
|
|
|
17
32
|
export function registerWalletTools(
|
|
@@ -21,28 +36,29 @@ export function registerWalletTools(
|
|
|
21
36
|
disableBroadcasting: boolean;
|
|
22
37
|
enableA2bTools: boolean;
|
|
23
38
|
identityPk?: PrivateKey;
|
|
39
|
+
ctx?: OneSatContext;
|
|
24
40
|
},
|
|
25
41
|
): void {
|
|
26
42
|
// Register the wallet_sendToAddress tool
|
|
27
|
-
registerSendToAddressTool(server,
|
|
43
|
+
registerSendToAddressTool(server, config.ctx);
|
|
28
44
|
|
|
29
45
|
// Register the wallet_getAddress tool
|
|
30
|
-
registerGetAddressTool(server,
|
|
31
|
-
|
|
32
|
-
// Register the wallet_getPublicKey tool
|
|
33
|
-
registerGetPublicKeyTool(server, wallet);
|
|
46
|
+
registerGetAddressTool(server, config.ctx);
|
|
34
47
|
|
|
35
48
|
// Register the wallet_purchaseListing tool
|
|
36
|
-
registerPurchaseListingTool(server,
|
|
49
|
+
registerPurchaseListingTool(server, config.ctx);
|
|
37
50
|
|
|
38
51
|
// Register the wallet_transferOrdToken tool
|
|
39
|
-
registerTransferOrdTokenTool(server,
|
|
52
|
+
registerTransferOrdTokenTool(server, config.ctx);
|
|
40
53
|
|
|
41
54
|
// Register the wallet_refreshUtxos tool
|
|
42
|
-
registerRefreshUtxosTool(server,
|
|
55
|
+
registerRefreshUtxosTool(server, config.ctx);
|
|
43
56
|
|
|
44
57
|
// Register the wallet_getBalance tool
|
|
45
|
-
registerWalletGetBalanceTool(server,
|
|
58
|
+
registerWalletGetBalanceTool(server, config.ctx);
|
|
59
|
+
|
|
60
|
+
// Register full BRC-100 wallet interface
|
|
61
|
+
registerBrc100Tools(server, config.ctx);
|
|
46
62
|
|
|
47
63
|
// A2B tools have to be explicitly enabled
|
|
48
64
|
if (config.enableA2bTools) {
|
|
@@ -52,86 +68,32 @@ export function registerWalletTools(
|
|
|
52
68
|
});
|
|
53
69
|
}
|
|
54
70
|
|
|
55
|
-
// Register combined wallet_encryption tool
|
|
56
|
-
server.tool(
|
|
57
|
-
"wallet_encryption",
|
|
58
|
-
"Combined tool for encrypting and decrypting data using the wallet's cryptographic keys.\n\n" +
|
|
59
|
-
"PARAMETERS:\n" +
|
|
60
|
-
'- mode: (required) Either "encrypt" to encrypt plaintext or "decrypt" to decrypt ciphertext\n' +
|
|
61
|
-
"- data: (required) Text string or array of numbers to process\n" +
|
|
62
|
-
"- encoding: (optional) For text input, the encoding format (utf8, hex, base64) - default is utf8\n" +
|
|
63
|
-
"- recipientPublicKeyHex: (optional) Hexadecimal representation of the recipient's public key (required for encrypt mode)\n\n" +
|
|
64
|
-
"EXAMPLES:\n" +
|
|
65
|
-
"1. Encrypt text data:\n" +
|
|
66
|
-
" {\n" +
|
|
67
|
-
' "mode": "encrypt",\n' +
|
|
68
|
-
' "data": "Hello World",\n' +
|
|
69
|
-
' "encoding": "utf8",\n' +
|
|
70
|
-
' "recipientPublicKeyHex": "020202020202020202020202020202020202020202020202020202020202020202"\n' +
|
|
71
|
-
" }\n\n" +
|
|
72
|
-
"2. Decrypt previously encrypted data:\n" +
|
|
73
|
-
" {\n" +
|
|
74
|
-
' "mode": "decrypt",\n' +
|
|
75
|
-
' "data": [encrypted bytes from previous response]\n' +
|
|
76
|
-
" }",
|
|
77
|
-
{ ...walletEncryptionArgsSchema.shape },
|
|
78
|
-
async ({ mode, data, encoding, recipientPublicKeyHex }) => {
|
|
79
|
-
try {
|
|
80
|
-
|
|
81
|
-
let inputData: number[];
|
|
82
|
-
if (typeof data === "string") {
|
|
83
|
-
inputData = Utils.toArray(data, encoding || "utf8");
|
|
84
|
-
} else {
|
|
85
|
-
inputData = Array.from(data);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// let resultBuffer: Buffer;
|
|
89
|
-
// let resultOutput: string | number[];
|
|
90
|
-
|
|
91
|
-
if (mode === "encrypt") {
|
|
92
|
-
// recipientPublicKeyHex is validated by Zod schema to be present for encrypt mode
|
|
93
|
-
// The schema ensures recipientPublicKeyHex is defined here.
|
|
94
|
-
// resultBuffer = await wallet.encrypt({
|
|
95
|
-
// data: inputBuffer,
|
|
96
|
-
// recipientPublicKeyHex: recipientPublicKeyHex as string, // Still needs type assertion if Zod optional isn't fully narrowed
|
|
97
|
-
// });
|
|
98
|
-
throw new Error("Encrypt method not yet implemented in wallet");
|
|
99
|
-
// if (encoding === "utf8") {
|
|
100
|
-
// resultOutput = Array.from(resultBuffer);
|
|
101
|
-
// } else {
|
|
102
|
-
// resultOutput = resultBuffer.toString(encoding || "base64");
|
|
103
|
-
// }
|
|
104
|
-
}
|
|
105
|
-
// mode === "decrypt"
|
|
106
|
-
// resultBuffer = await wallet.decrypt({ data: inputBuffer });
|
|
107
|
-
throw new Error("Decrypt method not yet implemented in wallet");
|
|
108
|
-
|
|
109
|
-
// return {
|
|
110
|
-
// content: [
|
|
111
|
-
// { type: "text", text: JSON.stringify({ data: resultOutput }) },
|
|
112
|
-
// ],
|
|
113
|
-
// };
|
|
114
|
-
} catch (error) {
|
|
115
|
-
const errorMessage =
|
|
116
|
-
error instanceof Error ? error.message : String(error);
|
|
117
|
-
return {
|
|
118
|
-
content: [
|
|
119
|
-
{
|
|
120
|
-
type: "text",
|
|
121
|
-
text: `Error during ${mode}: ${errorMessage}`,
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
isError: true,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
);
|
|
129
|
-
|
|
130
71
|
// Register createOrdinals tool
|
|
131
|
-
registerCreateOrdinalsTool(server,
|
|
72
|
+
registerCreateOrdinalsTool(server, config.ctx);
|
|
132
73
|
|
|
133
74
|
// Register collection tools
|
|
134
75
|
registerGatherCollectionInfoTool(server, wallet);
|
|
135
76
|
registerMintCollectionTool(server, wallet);
|
|
136
77
|
|
|
78
|
+
// Register read-only wallet tools
|
|
79
|
+
registerGetOrdinalsTool(server, config.ctx);
|
|
80
|
+
registerListTokensTool(server, config.ctx);
|
|
81
|
+
registerGetBsv21BalancesTool(server, config.ctx);
|
|
82
|
+
registerGetLockDataTool(server, config.ctx);
|
|
83
|
+
registerSignBsmTool(server, config.ctx);
|
|
84
|
+
|
|
85
|
+
// Register state-changing action tools
|
|
86
|
+
registerListOrdinalTool(server, config.ctx);
|
|
87
|
+
registerCancelListingTool(server, config.ctx);
|
|
88
|
+
registerSendAllBsvTool(server, config.ctx);
|
|
89
|
+
registerLockBsvTool(server, config.ctx);
|
|
90
|
+
registerUnlockBsvTool(server, config.ctx);
|
|
91
|
+
registerOpnsRegisterTool(server, config.ctx);
|
|
92
|
+
registerOpnsDeregisterTool(server, config.ctx);
|
|
93
|
+
|
|
94
|
+
// Register sweep tools
|
|
95
|
+
registerSweepBsvTool(server, config.ctx);
|
|
96
|
+
registerSweepOrdinalsTool(server, config.ctx);
|
|
97
|
+
registerSweepBsv21Tool(server, config.ctx);
|
|
98
|
+
|
|
137
99
|
}
|