@1sat/wallet-toolbox 0.0.8 → 0.0.10
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/dist/api/balance/index.d.ts +50 -0
- package/dist/api/balance/index.js +135 -0
- package/dist/api/broadcast/index.d.ts +24 -0
- package/dist/api/broadcast/index.js +73 -0
- package/dist/api/constants.d.ts +21 -0
- package/dist/api/constants.js +29 -0
- package/dist/api/index.d.ts +36 -0
- package/dist/api/index.js +59 -0
- package/dist/api/inscriptions/index.d.ts +25 -0
- package/dist/api/inscriptions/index.js +98 -0
- package/dist/api/locks/index.d.ts +47 -0
- package/dist/api/locks/index.js +291 -0
- package/dist/api/ordinals/index.d.ts +102 -0
- package/dist/api/ordinals/index.js +566 -0
- package/dist/api/payments/index.d.ts +48 -0
- package/dist/api/payments/index.js +185 -0
- package/dist/api/signing/index.d.ts +35 -0
- package/dist/api/signing/index.js +78 -0
- package/dist/api/skills/registry.d.ts +61 -0
- package/dist/api/skills/registry.js +74 -0
- package/dist/api/skills/types.d.ts +71 -0
- package/dist/api/skills/types.js +14 -0
- package/dist/api/tokens/index.d.ts +87 -0
- package/dist/api/tokens/index.js +457 -0
- package/dist/cwi/chrome.d.ts +11 -0
- package/dist/cwi/chrome.js +39 -0
- package/dist/cwi/event.d.ts +11 -0
- package/dist/cwi/event.js +38 -0
- package/dist/cwi/factory.d.ts +14 -0
- package/dist/cwi/factory.js +44 -0
- package/dist/cwi/index.d.ts +11 -0
- package/dist/cwi/index.js +11 -0
- package/dist/cwi/types.d.ts +39 -0
- package/dist/cwi/types.js +39 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -1
- package/dist/indexers/CosignIndexer.js +1 -0
- package/dist/indexers/InscriptionIndexer.js +3 -4
- package/dist/indexers/LockIndexer.js +1 -0
- package/dist/indexers/OrdLockIndexer.js +1 -0
- package/dist/indexers/OriginIndexer.js +1 -1
- package/dist/indexers/index.d.ts +1 -1
- package/dist/indexers/types.d.ts +18 -0
- package/dist/services/OneSatServices.d.ts +19 -10
- package/dist/services/OneSatServices.js +201 -39
- package/dist/services/client/ChaintracksClient.d.ts +55 -13
- package/dist/services/client/ChaintracksClient.js +123 -28
- package/dist/services/client/OrdfsClient.d.ts +2 -2
- package/dist/services/client/OrdfsClient.js +4 -3
- package/dist/services/client/TxoClient.js +9 -0
- package/dist/sync/AddressManager.d.ts +85 -0
- package/dist/sync/AddressManager.js +107 -0
- package/dist/sync/SyncManager.d.ts +207 -0
- package/dist/sync/SyncManager.js +507 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.js +2 -0
- package/dist/wallet/factory.d.ts +64 -0
- package/dist/wallet/factory.js +129 -0
- package/dist/wallet/index.d.ts +1 -0
- package/dist/wallet/index.js +1 -0
- package/package.json +14 -4
- package/dist/OneSatWallet.d.ts +0 -316
- package/dist/OneSatWallet.js +0 -956
- package/dist/indexers/TransactionParser.d.ts +0 -53
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payments Module
|
|
3
|
+
*
|
|
4
|
+
* Skills for sending BSV payments.
|
|
5
|
+
*/
|
|
6
|
+
import { P2PKH, Script, Utils } from "@bsv/sdk";
|
|
7
|
+
import { Inscription } from "@bopen-io/templates";
|
|
8
|
+
import { FUNDING_BASKET } from "../constants";
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Internal helpers
|
|
11
|
+
// ============================================================================
|
|
12
|
+
function isPaymail(address) {
|
|
13
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address);
|
|
14
|
+
}
|
|
15
|
+
function buildInscriptionScript(address, base64Data, mimeType) {
|
|
16
|
+
const content = Utils.toArray(base64Data, "base64");
|
|
17
|
+
const inscription = Inscription.create(new Uint8Array(content), mimeType);
|
|
18
|
+
const inscriptionScript = inscription.lock();
|
|
19
|
+
const p2pkhScript = new P2PKH().lock(address);
|
|
20
|
+
const combined = new Script();
|
|
21
|
+
for (const chunk of inscriptionScript.chunks)
|
|
22
|
+
combined.chunks.push(chunk);
|
|
23
|
+
for (const chunk of p2pkhScript.chunks)
|
|
24
|
+
combined.chunks.push(chunk);
|
|
25
|
+
return combined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Send BSV to one or more destinations.
|
|
29
|
+
*/
|
|
30
|
+
export const sendBsv = {
|
|
31
|
+
meta: {
|
|
32
|
+
name: "sendBsv",
|
|
33
|
+
description: "Send BSV to one or more destinations (addresses, scripts, or OP_RETURN)",
|
|
34
|
+
category: "payments",
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
requests: {
|
|
39
|
+
type: "array",
|
|
40
|
+
description: "Array of payment requests",
|
|
41
|
+
items: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
address: { type: "string", description: "Destination P2PKH address" },
|
|
45
|
+
paymail: { type: "string", description: "Destination paymail address" },
|
|
46
|
+
satoshis: { type: "integer", description: "Amount in satoshis" },
|
|
47
|
+
script: { type: "string", description: "Custom locking script (hex)" },
|
|
48
|
+
data: {
|
|
49
|
+
type: "array",
|
|
50
|
+
description: "OP_RETURN data elements",
|
|
51
|
+
items: { type: "string" },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
required: ["satoshis"],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["requests"],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
async execute(ctx, input) {
|
|
62
|
+
try {
|
|
63
|
+
const { requests } = input;
|
|
64
|
+
if (!requests || requests.length === 0) {
|
|
65
|
+
return { error: "no-requests" };
|
|
66
|
+
}
|
|
67
|
+
const outputs = [];
|
|
68
|
+
for (const req of requests) {
|
|
69
|
+
let lockingScript;
|
|
70
|
+
if (req.script) {
|
|
71
|
+
lockingScript = Script.fromHex(req.script);
|
|
72
|
+
}
|
|
73
|
+
else if (req.address) {
|
|
74
|
+
if (req.inscription) {
|
|
75
|
+
lockingScript = buildInscriptionScript(req.address, req.inscription.base64Data, req.inscription.mimeType);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
lockingScript = new P2PKH().lock(req.address);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (req.data && req.data.length > 0) {
|
|
82
|
+
try {
|
|
83
|
+
lockingScript = Script.fromASM(`OP_0 OP_RETURN ${req.data.join(" ")}`);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return { error: "invalid-data" };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (req.paymail) {
|
|
90
|
+
return { error: "paymail-not-yet-implemented" };
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return { error: "invalid-request" };
|
|
94
|
+
}
|
|
95
|
+
outputs.push({
|
|
96
|
+
lockingScript: lockingScript.toHex(),
|
|
97
|
+
satoshis: req.satoshis,
|
|
98
|
+
outputDescription: `Payment of ${req.satoshis} sats`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const result = await ctx.wallet.createAction({
|
|
102
|
+
description: `Send ${requests.length} payment(s)`,
|
|
103
|
+
outputs,
|
|
104
|
+
options: { signAndProcess: true },
|
|
105
|
+
});
|
|
106
|
+
if (!result.txid) {
|
|
107
|
+
return { error: "no-txid-returned" };
|
|
108
|
+
}
|
|
109
|
+
return { txid: result.txid, rawtx: result.tx ? Utils.toHex(result.tx) : undefined };
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return { error: error instanceof Error ? error.message : "unknown-error" };
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Send all BSV to a destination address.
|
|
118
|
+
*/
|
|
119
|
+
export const sendAllBsv = {
|
|
120
|
+
meta: {
|
|
121
|
+
name: "sendAllBsv",
|
|
122
|
+
description: "Send all BSV from wallet to a single destination address",
|
|
123
|
+
category: "payments",
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
destination: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "Destination P2PKH address to send all funds to",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
required: ["destination"],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
async execute(ctx, input) {
|
|
136
|
+
try {
|
|
137
|
+
const { destination } = input;
|
|
138
|
+
if (isPaymail(destination)) {
|
|
139
|
+
return { error: "paymail-not-yet-implemented" };
|
|
140
|
+
}
|
|
141
|
+
const listResult = await ctx.wallet.listOutputs({
|
|
142
|
+
basket: FUNDING_BASKET,
|
|
143
|
+
include: "locking scripts",
|
|
144
|
+
limit: 10000,
|
|
145
|
+
});
|
|
146
|
+
if (!listResult.outputs || listResult.outputs.length === 0) {
|
|
147
|
+
return { error: "no-funds" };
|
|
148
|
+
}
|
|
149
|
+
const totalSats = listResult.outputs.reduce((sum, o) => sum + o.satoshis, 0);
|
|
150
|
+
const estimatedFee = Math.ceil((listResult.outputs.length * 150 + 44) * 1);
|
|
151
|
+
const sendAmount = totalSats - estimatedFee;
|
|
152
|
+
if (sendAmount <= 0) {
|
|
153
|
+
return { error: "insufficient-funds-for-fee" };
|
|
154
|
+
}
|
|
155
|
+
const inputs = listResult.outputs.map((o) => ({
|
|
156
|
+
outpoint: o.outpoint,
|
|
157
|
+
inputDescription: "Sweep funds",
|
|
158
|
+
}));
|
|
159
|
+
const result = await ctx.wallet.createAction({
|
|
160
|
+
description: "Send all BSV",
|
|
161
|
+
inputs,
|
|
162
|
+
outputs: [
|
|
163
|
+
{
|
|
164
|
+
lockingScript: new P2PKH().lock(destination).toHex(),
|
|
165
|
+
satoshis: sendAmount,
|
|
166
|
+
outputDescription: "Sweep all funds",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
options: { signAndProcess: true },
|
|
170
|
+
});
|
|
171
|
+
if (!result.txid) {
|
|
172
|
+
return { error: "no-txid-returned" };
|
|
173
|
+
}
|
|
174
|
+
return { txid: result.txid, rawtx: result.tx ? Utils.toHex(result.tx) : undefined };
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return { error: error instanceof Error ? error.message : "unknown-error" };
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
// ============================================================================
|
|
182
|
+
// Module exports
|
|
183
|
+
// ============================================================================
|
|
184
|
+
/** All payment skills for registry */
|
|
185
|
+
export const paymentsSkills = [sendBsv, sendAllBsv];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing Module
|
|
3
|
+
*
|
|
4
|
+
* Skills for message signing.
|
|
5
|
+
*/
|
|
6
|
+
import type { Skill } from "../skills/types";
|
|
7
|
+
export interface SignMessageRequest {
|
|
8
|
+
/** Message to sign */
|
|
9
|
+
message: string;
|
|
10
|
+
/** Message encoding */
|
|
11
|
+
encoding?: "utf8" | "hex" | "base64";
|
|
12
|
+
/** Derivation tag for key selection */
|
|
13
|
+
tag?: {
|
|
14
|
+
label: string;
|
|
15
|
+
id: string;
|
|
16
|
+
domain: string;
|
|
17
|
+
meta: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface SignedMessage {
|
|
21
|
+
address: string;
|
|
22
|
+
pubKey: string;
|
|
23
|
+
message: string;
|
|
24
|
+
sig: string;
|
|
25
|
+
derivationTag?: SignMessageRequest["tag"];
|
|
26
|
+
}
|
|
27
|
+
export interface SignMessageResponse extends Partial<SignedMessage> {
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sign a message using BSM (Bitcoin Signed Message) format.
|
|
32
|
+
*/
|
|
33
|
+
export declare const signMessage: Skill<SignMessageRequest, SignMessageResponse>;
|
|
34
|
+
/** All signing skills for registry */
|
|
35
|
+
export declare const signingSkills: Skill<SignMessageRequest, SignMessageResponse>[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing Module
|
|
3
|
+
*
|
|
4
|
+
* Skills for message signing.
|
|
5
|
+
*/
|
|
6
|
+
import { BigNumber, BSM, PublicKey, Signature, Utils } from "@bsv/sdk";
|
|
7
|
+
import { MESSAGE_SIGNING_PROTOCOL } from "../constants";
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Skills
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Sign a message using BSM (Bitcoin Signed Message) format.
|
|
13
|
+
*/
|
|
14
|
+
export const signMessage = {
|
|
15
|
+
meta: {
|
|
16
|
+
name: "signMessage",
|
|
17
|
+
description: "Sign a message using BSM (Bitcoin Signed Message) format",
|
|
18
|
+
category: "signing",
|
|
19
|
+
inputSchema: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
message: { type: "string", description: "Message to sign" },
|
|
23
|
+
encoding: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Message encoding (utf8, hex, base64)",
|
|
26
|
+
enum: ["utf8", "hex", "base64"],
|
|
27
|
+
},
|
|
28
|
+
tag: {
|
|
29
|
+
type: "object",
|
|
30
|
+
description: "Derivation tag for key selection",
|
|
31
|
+
properties: {
|
|
32
|
+
label: { type: "string" },
|
|
33
|
+
id: { type: "string" },
|
|
34
|
+
domain: { type: "string" },
|
|
35
|
+
meta: { type: "object" },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ["message"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
async execute(ctx, input) {
|
|
43
|
+
try {
|
|
44
|
+
const { message, encoding = "utf8", tag } = input;
|
|
45
|
+
const messageBytes = Utils.toArray(message, encoding);
|
|
46
|
+
const msgHash = BSM.magicHash(messageBytes);
|
|
47
|
+
const keyID = tag ? `${tag.label}:${tag.id}:${tag.domain}` : "identity";
|
|
48
|
+
const result = await ctx.wallet.createSignature({
|
|
49
|
+
protocolID: MESSAGE_SIGNING_PROTOCOL,
|
|
50
|
+
keyID,
|
|
51
|
+
hashToDirectlySign: Array.from(msgHash),
|
|
52
|
+
});
|
|
53
|
+
const pubKeyResult = await ctx.wallet.getPublicKey({
|
|
54
|
+
protocolID: MESSAGE_SIGNING_PROTOCOL,
|
|
55
|
+
keyID,
|
|
56
|
+
forSelf: true,
|
|
57
|
+
});
|
|
58
|
+
const publicKey = PublicKey.fromString(pubKeyResult.publicKey);
|
|
59
|
+
const signature = Signature.fromDER(result.signature);
|
|
60
|
+
const recovery = signature.CalculateRecoveryFactor(publicKey, new BigNumber(msgHash));
|
|
61
|
+
return {
|
|
62
|
+
address: publicKey.toAddress(),
|
|
63
|
+
pubKey: publicKey.toString(),
|
|
64
|
+
message,
|
|
65
|
+
sig: signature.toCompact(recovery, true, "base64"),
|
|
66
|
+
derivationTag: tag,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return { error: error instanceof Error ? error.message : "unknown-error" };
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Module exports
|
|
76
|
+
// ============================================================================
|
|
77
|
+
/** All signing skills for registry */
|
|
78
|
+
export const signingSkills = [signMessage];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill registry for runtime discovery and MCP integration.
|
|
3
|
+
*/
|
|
4
|
+
import type { Skill, SkillCategory } from "./types";
|
|
5
|
+
type AnySkill = Skill<any, any>;
|
|
6
|
+
/**
|
|
7
|
+
* MCP-compatible tool definition.
|
|
8
|
+
*/
|
|
9
|
+
export interface McpTool {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
inputSchema: object;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Registry for collecting and discovering skills at runtime.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SkillRegistry {
|
|
18
|
+
private skills;
|
|
19
|
+
/**
|
|
20
|
+
* Register a skill.
|
|
21
|
+
*/
|
|
22
|
+
register(skill: AnySkill): void;
|
|
23
|
+
/**
|
|
24
|
+
* Register multiple skills.
|
|
25
|
+
*/
|
|
26
|
+
registerAll(skills: AnySkill[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get a skill by name.
|
|
29
|
+
*/
|
|
30
|
+
get(name: string): AnySkill | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a skill exists.
|
|
33
|
+
*/
|
|
34
|
+
has(name: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* List all registered skills.
|
|
37
|
+
*/
|
|
38
|
+
list(): Skill[];
|
|
39
|
+
/**
|
|
40
|
+
* List skills by category.
|
|
41
|
+
*/
|
|
42
|
+
listByCategory(category: SkillCategory): Skill[];
|
|
43
|
+
/**
|
|
44
|
+
* Get skill names.
|
|
45
|
+
*/
|
|
46
|
+
names(): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Convert to MCP-compatible tool list.
|
|
49
|
+
* Prefixes names with "1sat__" for namespace isolation.
|
|
50
|
+
*/
|
|
51
|
+
toMcpTools(): McpTool[];
|
|
52
|
+
/**
|
|
53
|
+
* Number of registered skills.
|
|
54
|
+
*/
|
|
55
|
+
get size(): number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Global skill registry singleton.
|
|
59
|
+
*/
|
|
60
|
+
export declare const skillRegistry: SkillRegistry;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill registry for runtime discovery and MCP integration.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Registry for collecting and discovering skills at runtime.
|
|
6
|
+
*/
|
|
7
|
+
export class SkillRegistry {
|
|
8
|
+
skills = new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Register a skill.
|
|
11
|
+
*/
|
|
12
|
+
register(skill) {
|
|
13
|
+
this.skills.set(skill.meta.name, skill);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Register multiple skills.
|
|
17
|
+
*/
|
|
18
|
+
registerAll(skills) {
|
|
19
|
+
for (const skill of skills) {
|
|
20
|
+
this.register(skill);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a skill by name.
|
|
25
|
+
*/
|
|
26
|
+
get(name) {
|
|
27
|
+
return this.skills.get(name);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a skill exists.
|
|
31
|
+
*/
|
|
32
|
+
has(name) {
|
|
33
|
+
return this.skills.has(name);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* List all registered skills.
|
|
37
|
+
*/
|
|
38
|
+
list() {
|
|
39
|
+
return Array.from(this.skills.values());
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* List skills by category.
|
|
43
|
+
*/
|
|
44
|
+
listByCategory(category) {
|
|
45
|
+
return this.list().filter((s) => s.meta.category === category);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get skill names.
|
|
49
|
+
*/
|
|
50
|
+
names() {
|
|
51
|
+
return Array.from(this.skills.keys());
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convert to MCP-compatible tool list.
|
|
55
|
+
* Prefixes names with "1sat__" for namespace isolation.
|
|
56
|
+
*/
|
|
57
|
+
toMcpTools() {
|
|
58
|
+
return this.list().map((skill) => ({
|
|
59
|
+
name: `1sat__${skill.meta.name}`,
|
|
60
|
+
description: skill.meta.description,
|
|
61
|
+
inputSchema: skill.meta.inputSchema,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Number of registered skills.
|
|
66
|
+
*/
|
|
67
|
+
get size() {
|
|
68
|
+
return this.skills.size;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Global skill registry singleton.
|
|
73
|
+
*/
|
|
74
|
+
export const skillRegistry = new SkillRegistry();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the skill/action pattern.
|
|
3
|
+
*/
|
|
4
|
+
import type { WalletInterface } from "@bsv/sdk";
|
|
5
|
+
import type { OneSatServices } from "../../services/OneSatServices";
|
|
6
|
+
/**
|
|
7
|
+
* Context passed to all skills.
|
|
8
|
+
* Contains the wallet and optional services for backend operations.
|
|
9
|
+
*/
|
|
10
|
+
export interface OneSatContext {
|
|
11
|
+
/** BRC-100 compatible wallet interface */
|
|
12
|
+
wallet: WalletInterface;
|
|
13
|
+
/** Optional services for operations requiring backend (purchases, lookups) */
|
|
14
|
+
services?: OneSatServices;
|
|
15
|
+
/** Network chain */
|
|
16
|
+
chain: "main" | "test";
|
|
17
|
+
/** Optional WhatsOnChain API key */
|
|
18
|
+
wocApiKey?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* JSON Schema property definition for skill input schemas.
|
|
22
|
+
*/
|
|
23
|
+
export interface JsonSchemaProperty {
|
|
24
|
+
type: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
25
|
+
description?: string;
|
|
26
|
+
enum?: string[];
|
|
27
|
+
default?: unknown;
|
|
28
|
+
items?: JsonSchemaProperty;
|
|
29
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Skill category for grouping related operations.
|
|
34
|
+
*/
|
|
35
|
+
export type SkillCategory = "balance" | "payments" | "ordinals" | "tokens" | "inscriptions" | "locks" | "signing" | "broadcast";
|
|
36
|
+
/**
|
|
37
|
+
* Metadata describing a skill for AI agents and tooling.
|
|
38
|
+
*/
|
|
39
|
+
export interface SkillMetadata<TInput = unknown> {
|
|
40
|
+
/** Unique skill name */
|
|
41
|
+
name: string;
|
|
42
|
+
/** Human-readable description of what the skill does */
|
|
43
|
+
description: string;
|
|
44
|
+
/** Category for grouping */
|
|
45
|
+
category: SkillCategory;
|
|
46
|
+
/** JSON Schema for the input parameters (MCP-compatible) */
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object";
|
|
49
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
50
|
+
required?: string[];
|
|
51
|
+
};
|
|
52
|
+
/** Whether this skill requires OneSatServices to be provided in context */
|
|
53
|
+
requiresServices?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A skill is a self-describing action that can be executed with a context.
|
|
57
|
+
*/
|
|
58
|
+
export interface Skill<TInput = unknown, TOutput = unknown> {
|
|
59
|
+
/** Metadata describing the skill */
|
|
60
|
+
meta: SkillMetadata<TInput>;
|
|
61
|
+
/** Execute the skill with context and input */
|
|
62
|
+
execute: (ctx: OneSatContext, input: TInput) => Promise<TOutput>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Helper to create a context object from a wallet and options.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createContext(wallet: WalletInterface, options?: {
|
|
68
|
+
services?: OneSatServices;
|
|
69
|
+
chain?: "main" | "test";
|
|
70
|
+
wocApiKey?: string;
|
|
71
|
+
}): OneSatContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the skill/action pattern.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Helper to create a context object from a wallet and options.
|
|
6
|
+
*/
|
|
7
|
+
export function createContext(wallet, options) {
|
|
8
|
+
return {
|
|
9
|
+
wallet,
|
|
10
|
+
services: options?.services,
|
|
11
|
+
chain: options?.chain ?? "main",
|
|
12
|
+
wocApiKey: options?.wocApiKey,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokens Module
|
|
3
|
+
*
|
|
4
|
+
* Skills for managing BSV21 tokens.
|
|
5
|
+
*/
|
|
6
|
+
import { type WalletOutput } from "@bsv/sdk";
|
|
7
|
+
import type { Skill } from "../skills/types";
|
|
8
|
+
type PubKeyHex = string;
|
|
9
|
+
export interface Bsv21Balance {
|
|
10
|
+
/** Token protocol (bsv-20) */
|
|
11
|
+
p: string;
|
|
12
|
+
/** Token ID (outpoint for BSV21, tick for BSV20) */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Token symbol */
|
|
15
|
+
sym?: string;
|
|
16
|
+
/** Token icon URL */
|
|
17
|
+
icon?: string;
|
|
18
|
+
/** Decimal places */
|
|
19
|
+
dec: number;
|
|
20
|
+
/** Total amount (confirmed + pending) */
|
|
21
|
+
amt: string;
|
|
22
|
+
/** Breakdown of confirmed vs pending */
|
|
23
|
+
all: {
|
|
24
|
+
confirmed: bigint;
|
|
25
|
+
pending: bigint;
|
|
26
|
+
};
|
|
27
|
+
/** Listed amounts (if applicable) */
|
|
28
|
+
listed: {
|
|
29
|
+
confirmed: bigint;
|
|
30
|
+
pending: bigint;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface SendBsv21Request {
|
|
34
|
+
/** Token ID (txid_vout format) */
|
|
35
|
+
tokenId: string;
|
|
36
|
+
/** Amount to send (as bigint or string) */
|
|
37
|
+
amount: bigint | string;
|
|
38
|
+
/** Recipient's identity public key (preferred) */
|
|
39
|
+
counterparty?: PubKeyHex;
|
|
40
|
+
/** Legacy: raw P2PKH address */
|
|
41
|
+
address?: string;
|
|
42
|
+
/** Paymail address */
|
|
43
|
+
paymail?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface PurchaseBsv21Request {
|
|
46
|
+
/** Token ID (txid_vout format of the deploy transaction) */
|
|
47
|
+
tokenId: string;
|
|
48
|
+
/** Outpoint of listed token UTXO (OrdLock containing BSV21) */
|
|
49
|
+
outpoint: string;
|
|
50
|
+
/** Amount of tokens in the listing */
|
|
51
|
+
amount: bigint | string;
|
|
52
|
+
/** Optional marketplace fee address */
|
|
53
|
+
marketplaceAddress?: string;
|
|
54
|
+
/** Optional marketplace fee rate (0-1) */
|
|
55
|
+
marketplaceRate?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface TokenOperationResponse {
|
|
58
|
+
txid?: string;
|
|
59
|
+
rawtx?: string;
|
|
60
|
+
error?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Input for listTokens skill */
|
|
63
|
+
export interface ListTokensInput {
|
|
64
|
+
/** Max number of tokens to return */
|
|
65
|
+
limit?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* List BSV21 token outputs from the wallet.
|
|
69
|
+
*/
|
|
70
|
+
export declare const listTokens: Skill<ListTokensInput, WalletOutput[]>;
|
|
71
|
+
/** Input for getBsv21Balances skill (no required params) */
|
|
72
|
+
export type GetBsv21BalancesInput = Record<string, never>;
|
|
73
|
+
/**
|
|
74
|
+
* Get aggregated BSV21 token balances.
|
|
75
|
+
*/
|
|
76
|
+
export declare const getBsv21Balances: Skill<GetBsv21BalancesInput, Bsv21Balance[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Send BSV21 tokens to an address.
|
|
79
|
+
*/
|
|
80
|
+
export declare const sendBsv21: Skill<SendBsv21Request, TokenOperationResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Purchase BSV21 tokens from marketplace.
|
|
83
|
+
*/
|
|
84
|
+
export declare const purchaseBsv21: Skill<PurchaseBsv21Request, TokenOperationResponse>;
|
|
85
|
+
/** All token skills for registry */
|
|
86
|
+
export declare const tokensSkills: (Skill<ListTokensInput, WalletOutput[]> | Skill<GetBsv21BalancesInput, Bsv21Balance[]> | Skill<SendBsv21Request, TokenOperationResponse> | Skill<PurchaseBsv21Request, TokenOperationResponse>)[];
|
|
87
|
+
export {};
|