@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.
Files changed (64) hide show
  1. package/dist/api/balance/index.d.ts +50 -0
  2. package/dist/api/balance/index.js +135 -0
  3. package/dist/api/broadcast/index.d.ts +24 -0
  4. package/dist/api/broadcast/index.js +73 -0
  5. package/dist/api/constants.d.ts +21 -0
  6. package/dist/api/constants.js +29 -0
  7. package/dist/api/index.d.ts +36 -0
  8. package/dist/api/index.js +59 -0
  9. package/dist/api/inscriptions/index.d.ts +25 -0
  10. package/dist/api/inscriptions/index.js +98 -0
  11. package/dist/api/locks/index.d.ts +47 -0
  12. package/dist/api/locks/index.js +291 -0
  13. package/dist/api/ordinals/index.d.ts +102 -0
  14. package/dist/api/ordinals/index.js +566 -0
  15. package/dist/api/payments/index.d.ts +48 -0
  16. package/dist/api/payments/index.js +185 -0
  17. package/dist/api/signing/index.d.ts +35 -0
  18. package/dist/api/signing/index.js +78 -0
  19. package/dist/api/skills/registry.d.ts +61 -0
  20. package/dist/api/skills/registry.js +74 -0
  21. package/dist/api/skills/types.d.ts +71 -0
  22. package/dist/api/skills/types.js +14 -0
  23. package/dist/api/tokens/index.d.ts +87 -0
  24. package/dist/api/tokens/index.js +457 -0
  25. package/dist/cwi/chrome.d.ts +11 -0
  26. package/dist/cwi/chrome.js +39 -0
  27. package/dist/cwi/event.d.ts +11 -0
  28. package/dist/cwi/event.js +38 -0
  29. package/dist/cwi/factory.d.ts +14 -0
  30. package/dist/cwi/factory.js +44 -0
  31. package/dist/cwi/index.d.ts +11 -0
  32. package/dist/cwi/index.js +11 -0
  33. package/dist/cwi/types.d.ts +39 -0
  34. package/dist/cwi/types.js +39 -0
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.js +7 -1
  37. package/dist/indexers/CosignIndexer.js +1 -0
  38. package/dist/indexers/InscriptionIndexer.js +3 -4
  39. package/dist/indexers/LockIndexer.js +1 -0
  40. package/dist/indexers/OrdLockIndexer.js +1 -0
  41. package/dist/indexers/OriginIndexer.js +1 -1
  42. package/dist/indexers/index.d.ts +1 -1
  43. package/dist/indexers/types.d.ts +18 -0
  44. package/dist/services/OneSatServices.d.ts +19 -10
  45. package/dist/services/OneSatServices.js +201 -39
  46. package/dist/services/client/ChaintracksClient.d.ts +55 -13
  47. package/dist/services/client/ChaintracksClient.js +123 -28
  48. package/dist/services/client/OrdfsClient.d.ts +2 -2
  49. package/dist/services/client/OrdfsClient.js +4 -3
  50. package/dist/services/client/TxoClient.js +9 -0
  51. package/dist/sync/AddressManager.d.ts +85 -0
  52. package/dist/sync/AddressManager.js +107 -0
  53. package/dist/sync/SyncManager.d.ts +207 -0
  54. package/dist/sync/SyncManager.js +507 -0
  55. package/dist/sync/index.d.ts +4 -0
  56. package/dist/sync/index.js +2 -0
  57. package/dist/wallet/factory.d.ts +64 -0
  58. package/dist/wallet/factory.js +129 -0
  59. package/dist/wallet/index.d.ts +1 -0
  60. package/dist/wallet/index.js +1 -0
  61. package/package.json +14 -4
  62. package/dist/OneSatWallet.d.ts +0 -316
  63. package/dist/OneSatWallet.js +0 -956
  64. package/dist/indexers/TransactionParser.d.ts +0 -53
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Balance Module
3
+ *
4
+ * Skills for querying wallet balance and payment UTXOs.
5
+ */
6
+ import type { Skill } from "../skills/types";
7
+ export interface Balance {
8
+ /** Balance in satoshis */
9
+ satoshis: number;
10
+ /** Balance in BSV */
11
+ bsv: number;
12
+ /** Balance in USD cents */
13
+ usdInCents: number;
14
+ }
15
+ export interface PaymentUtxo {
16
+ txid: string;
17
+ vout: number;
18
+ satoshis: number;
19
+ script: string;
20
+ }
21
+ /** Input for getBalance skill (no required params) */
22
+ export type GetBalanceInput = Record<string, never>;
23
+ /**
24
+ * Get wallet balance with USD conversion.
25
+ */
26
+ export declare const getBalance: Skill<GetBalanceInput, Balance>;
27
+ /** Input for getPaymentUtxos skill (no required params) */
28
+ export type GetPaymentUtxosInput = Record<string, never>;
29
+ /**
30
+ * Get payment UTXOs for external use.
31
+ */
32
+ export declare const getPaymentUtxos: Skill<GetPaymentUtxosInput, PaymentUtxo[]>;
33
+ /** Input for getExchangeRate skill (no required params) */
34
+ export type GetExchangeRateInput = Record<string, never>;
35
+ /**
36
+ * Get current BSV/USD exchange rate.
37
+ */
38
+ export declare const getExchangeRate: Skill<GetExchangeRateInput, number>;
39
+ /** Input for getChainInfo skill (no required params) */
40
+ export type GetChainInfoInput = Record<string, never>;
41
+ /** Output for getChainInfo skill */
42
+ export interface ChainInfo {
43
+ blocks: number;
44
+ }
45
+ /**
46
+ * Get chain info from WhatsOnChain.
47
+ */
48
+ export declare const getChainInfo: Skill<GetChainInfoInput, ChainInfo | null>;
49
+ /** All balance skills for registry */
50
+ export declare const balanceSkills: (Skill<GetBalanceInput, Balance> | Skill<GetPaymentUtxosInput, PaymentUtxo[]> | Skill<GetExchangeRateInput, number> | Skill<GetChainInfoInput, ChainInfo | null>)[];
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Balance Module
3
+ *
4
+ * Skills for querying wallet balance and payment UTXOs.
5
+ */
6
+ import { FUNDING_BASKET, WOC_MAINNET_URL, WOC_TESTNET_URL, EXCHANGE_RATE_CACHE_TTL } from "../constants";
7
+ // Module-level cache for exchange rate
8
+ let exchangeRateCache = null;
9
+ // ============================================================================
10
+ // Internal helpers
11
+ // ============================================================================
12
+ async function fetchExchangeRate(chain, wocApiKey) {
13
+ if (exchangeRateCache && Date.now() - exchangeRateCache.timestamp < EXCHANGE_RATE_CACHE_TTL) {
14
+ return exchangeRateCache.rate;
15
+ }
16
+ const baseUrl = chain === "main" ? WOC_MAINNET_URL : WOC_TESTNET_URL;
17
+ const headers = {};
18
+ if (wocApiKey)
19
+ headers["woc-api-key"] = wocApiKey;
20
+ try {
21
+ const response = await fetch(`${baseUrl}/exchangerate`, { headers });
22
+ if (!response.ok)
23
+ throw new Error(`Failed to fetch: ${response.statusText}`);
24
+ const data = await response.json();
25
+ const rate = Number(data.rate.toFixed(2));
26
+ exchangeRateCache = { rate, timestamp: Date.now() };
27
+ return rate;
28
+ }
29
+ catch {
30
+ return exchangeRateCache?.rate ?? 0;
31
+ }
32
+ }
33
+ /**
34
+ * Get wallet balance with USD conversion.
35
+ */
36
+ export const getBalance = {
37
+ meta: {
38
+ name: "getBalance",
39
+ description: "Get wallet balance in satoshis, BSV, and USD cents",
40
+ category: "balance",
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {},
44
+ },
45
+ },
46
+ async execute(ctx) {
47
+ const exchangeRate = await fetchExchangeRate(ctx.chain, ctx.wocApiKey);
48
+ const result = await ctx.wallet.listOutputs({ basket: FUNDING_BASKET, limit: 10000 });
49
+ const satoshis = result.outputs.reduce((sum, o) => sum + o.satoshis, 0);
50
+ const bsv = satoshis / 100_000_000;
51
+ const usdInCents = Math.round(bsv * exchangeRate * 100);
52
+ return { satoshis, bsv, usdInCents };
53
+ },
54
+ };
55
+ /**
56
+ * Get payment UTXOs for external use.
57
+ */
58
+ export const getPaymentUtxos = {
59
+ meta: {
60
+ name: "getPaymentUtxos",
61
+ description: "Get payment UTXOs from the wallet for external use",
62
+ category: "balance",
63
+ inputSchema: {
64
+ type: "object",
65
+ properties: {},
66
+ },
67
+ },
68
+ async execute(ctx) {
69
+ const result = await ctx.wallet.listOutputs({
70
+ basket: FUNDING_BASKET,
71
+ include: "locking scripts",
72
+ limit: 10000,
73
+ });
74
+ return result.outputs.map((o) => {
75
+ const [txid, voutStr] = o.outpoint.split(".");
76
+ return {
77
+ txid,
78
+ vout: Number.parseInt(voutStr, 10),
79
+ satoshis: o.satoshis,
80
+ script: o.lockingScript || "",
81
+ };
82
+ });
83
+ },
84
+ };
85
+ /**
86
+ * Get current BSV/USD exchange rate.
87
+ */
88
+ export const getExchangeRate = {
89
+ meta: {
90
+ name: "getExchangeRate",
91
+ description: "Get current BSV/USD exchange rate from WhatsOnChain",
92
+ category: "balance",
93
+ inputSchema: {
94
+ type: "object",
95
+ properties: {},
96
+ },
97
+ },
98
+ async execute(ctx) {
99
+ return fetchExchangeRate(ctx.chain, ctx.wocApiKey);
100
+ },
101
+ };
102
+ /**
103
+ * Get chain info from WhatsOnChain.
104
+ */
105
+ export const getChainInfo = {
106
+ meta: {
107
+ name: "getChainInfo",
108
+ description: "Get current chain info (block height) from WhatsOnChain",
109
+ category: "balance",
110
+ inputSchema: {
111
+ type: "object",
112
+ properties: {},
113
+ },
114
+ },
115
+ async execute(ctx) {
116
+ const baseUrl = ctx.chain === "main" ? WOC_MAINNET_URL : WOC_TESTNET_URL;
117
+ const headers = {};
118
+ if (ctx.wocApiKey)
119
+ headers["woc-api-key"] = ctx.wocApiKey;
120
+ try {
121
+ const response = await fetch(`${baseUrl}/chain/info`, { headers });
122
+ if (!response.ok)
123
+ return null;
124
+ return await response.json();
125
+ }
126
+ catch {
127
+ return null;
128
+ }
129
+ },
130
+ };
131
+ // ============================================================================
132
+ // Module exports
133
+ // ============================================================================
134
+ /** All balance skills for registry */
135
+ export const balanceSkills = [getBalance, getPaymentUtxos, getExchangeRate, getChainInfo];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Broadcast Module
3
+ *
4
+ * Skills for broadcasting transactions.
5
+ */
6
+ import type { Skill } from "../skills/types";
7
+ export interface BroadcastRequest {
8
+ /** Raw transaction hex */
9
+ rawtx: string;
10
+ /** Transaction format */
11
+ format?: "tx" | "beef" | "ef";
12
+ /** Description for wallet records */
13
+ description?: string;
14
+ }
15
+ export interface BroadcastResponse {
16
+ txid?: string;
17
+ error?: string;
18
+ }
19
+ /**
20
+ * Broadcast a transaction and internalize it into the wallet.
21
+ */
22
+ export declare const broadcast: Skill<BroadcastRequest, BroadcastResponse>;
23
+ /** All broadcast skills for registry */
24
+ export declare const broadcastSkills: Skill<BroadcastRequest, BroadcastResponse>[];
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Broadcast Module
3
+ *
4
+ * Skills for broadcasting transactions.
5
+ */
6
+ import { Beef, Transaction } from "@bsv/sdk";
7
+ // ============================================================================
8
+ // Skills
9
+ // ============================================================================
10
+ /**
11
+ * Broadcast a transaction and internalize it into the wallet.
12
+ */
13
+ export const broadcast = {
14
+ meta: {
15
+ name: "broadcast",
16
+ description: "Broadcast a transaction and internalize it into the wallet",
17
+ category: "broadcast",
18
+ inputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ rawtx: { type: "string", description: "Raw transaction hex" },
22
+ format: {
23
+ type: "string",
24
+ description: "Transaction format (tx, beef, ef)",
25
+ enum: ["tx", "beef", "ef"],
26
+ },
27
+ description: { type: "string", description: "Description for wallet records" },
28
+ },
29
+ required: ["rawtx"],
30
+ },
31
+ },
32
+ async execute(ctx, input) {
33
+ try {
34
+ let tx;
35
+ switch (input.format) {
36
+ case "beef":
37
+ tx = Transaction.fromHexBEEF(input.rawtx);
38
+ break;
39
+ case "ef":
40
+ tx = Transaction.fromHexEF(input.rawtx);
41
+ break;
42
+ default:
43
+ tx = Transaction.fromHex(input.rawtx);
44
+ }
45
+ const txid = tx.id("hex");
46
+ const beef = new Beef();
47
+ beef.mergeTransaction(tx);
48
+ const outputs = tx.outputs.map((_, index) => ({
49
+ outputIndex: index,
50
+ protocol: "wallet payment",
51
+ paymentRemittance: {
52
+ derivationPrefix: "default",
53
+ derivationSuffix: `${txid}.${index}`,
54
+ senderIdentityKey: "",
55
+ },
56
+ }));
57
+ await ctx.wallet.internalizeAction({
58
+ tx: Array.from(beef.toBinary()),
59
+ outputs,
60
+ description: input.description || "Broadcast transaction",
61
+ });
62
+ return { txid };
63
+ }
64
+ catch (error) {
65
+ return { error: error instanceof Error ? error.message : "Unknown error" };
66
+ }
67
+ },
68
+ };
69
+ // ============================================================================
70
+ // Module exports
71
+ // ============================================================================
72
+ /** All broadcast skills for registry */
73
+ export const broadcastSkills = [broadcast];
@@ -0,0 +1,21 @@
1
+ /**
2
+ * API Constants
3
+ */
4
+ export declare const FUNDING_BASKET = "default";
5
+ export declare const ORDINALS_BASKET = "1sat";
6
+ export declare const BSV21_BASKET = "bsv21";
7
+ export declare const LOCK_BASKET = "lock";
8
+ export declare const WOC_MAINNET_URL = "https://api.whatsonchain.com/v1/bsv/main";
9
+ export declare const WOC_TESTNET_URL = "https://api.whatsonchain.com/v1/bsv/test";
10
+ export declare const ONESAT_MAINNET_URL = "https://1sat.shruggr.cloud";
11
+ export declare const ONESAT_TESTNET_URL = "https://testnet.api.1sat.app";
12
+ export declare const ONESAT_MAINNET_CONTENT_URL = "https://1sat.shruggr.cloud/content";
13
+ export declare const ONESAT_TESTNET_CONTENT_URL = "https://testnet.api.1sat.app/content";
14
+ export declare const ORDLOCK_PREFIX = "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000";
15
+ export declare const ORDLOCK_SUFFIX = "615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868";
16
+ export declare const LOCK_PREFIX = "20d37f4de0d1c735b4d51a5572df0f3d9104d1d9e99db8694fdd1b1a92e1f0dce1757601687f76a9";
17
+ export declare const LOCK_SUFFIX = "88ac7e7601207f75a9011488";
18
+ export declare const MESSAGE_SIGNING_PROTOCOL: [0 | 1 | 2, string];
19
+ export declare const MAX_INSCRIPTION_BYTES = 100000;
20
+ export declare const MIN_UNLOCK_SATS = 1500;
21
+ export declare const EXCHANGE_RATE_CACHE_TTL: number;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * API Constants
3
+ */
4
+ // Basket names
5
+ export const FUNDING_BASKET = "default";
6
+ export const ORDINALS_BASKET = "1sat";
7
+ export const BSV21_BASKET = "bsv21";
8
+ export const LOCK_BASKET = "lock";
9
+ // WhatsOnChain API URLs
10
+ export const WOC_MAINNET_URL = "https://api.whatsonchain.com/v1/bsv/main";
11
+ export const WOC_TESTNET_URL = "https://api.whatsonchain.com/v1/bsv/test";
12
+ // 1Sat API base URLs
13
+ export const ONESAT_MAINNET_URL = "https://1sat.shruggr.cloud";
14
+ export const ONESAT_TESTNET_URL = "https://testnet.api.1sat.app";
15
+ // 1Sat API content URLs (at root, not under /1sat/)
16
+ export const ONESAT_MAINNET_CONTENT_URL = "https://1sat.shruggr.cloud/content";
17
+ export const ONESAT_TESTNET_CONTENT_URL = "https://testnet.api.1sat.app/content";
18
+ // OrdLock contract constants
19
+ export const ORDLOCK_PREFIX = "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000";
20
+ export const ORDLOCK_SUFFIX = "615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868";
21
+ // Lock template constants
22
+ export const LOCK_PREFIX = "20d37f4de0d1c735b4d51a5572df0f3d9104d1d9e99db8694fdd1b1a92e1f0dce1757601687f76a9";
23
+ export const LOCK_SUFFIX = "88ac7e7601207f75a9011488";
24
+ // Message signing protocol
25
+ export const MESSAGE_SIGNING_PROTOCOL = [1, "message signing"];
26
+ // Constants
27
+ export const MAX_INSCRIPTION_BYTES = 100_000;
28
+ export const MIN_UNLOCK_SATS = 1500;
29
+ export const EXCHANGE_RATE_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 1Sat Wallet Toolbox API Layer
3
+ *
4
+ * This module provides skills (self-describing actions) for interacting with the 1Sat ecosystem.
5
+ * All skills work with any BRC-100 compatible wallet interface via OneSatContext.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { createContext, transferOrdinal, skillRegistry } from '@1sat/wallet-toolbox/api';
10
+ *
11
+ * // Create context with a BRC-100 compatible wallet
12
+ * const ctx = createContext(wallet, { services, chain: 'main' });
13
+ *
14
+ * // Execute skills directly
15
+ * const result = await transferOrdinal.execute(ctx, { outpoint: '...', address: '...' });
16
+ *
17
+ * // Or via registry (useful for AI agents)
18
+ * const skill = skillRegistry.get('transferOrdinal');
19
+ * const result = await skill.execute(ctx, { outpoint: '...', address: '...' });
20
+ *
21
+ * // Get MCP-compatible tool list
22
+ * const tools = skillRegistry.toMcpTools();
23
+ * ```
24
+ */
25
+ export { type OneSatContext, type Skill, type SkillMetadata, type SkillCategory, type JsonSchemaProperty, createContext, } from "./skills/types";
26
+ export { SkillRegistry, skillRegistry, type McpTool } from "./skills/registry";
27
+ export * from "./constants";
28
+ export * from "./balance";
29
+ export * from "./payments";
30
+ export * from "./ordinals";
31
+ export * from "./tokens";
32
+ export * from "./inscriptions";
33
+ export * from "./locks";
34
+ export * from "./signing";
35
+ export * from "./broadcast";
36
+ export type { WalletInterface, WalletOutput, CreateActionArgs, CreateActionResult, CreateActionOutput, CreateActionInput, ListOutputsResult, ListOutputsArgs, } from "@bsv/sdk";
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 1Sat Wallet Toolbox API Layer
3
+ *
4
+ * This module provides skills (self-describing actions) for interacting with the 1Sat ecosystem.
5
+ * All skills work with any BRC-100 compatible wallet interface via OneSatContext.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { createContext, transferOrdinal, skillRegistry } from '@1sat/wallet-toolbox/api';
10
+ *
11
+ * // Create context with a BRC-100 compatible wallet
12
+ * const ctx = createContext(wallet, { services, chain: 'main' });
13
+ *
14
+ * // Execute skills directly
15
+ * const result = await transferOrdinal.execute(ctx, { outpoint: '...', address: '...' });
16
+ *
17
+ * // Or via registry (useful for AI agents)
18
+ * const skill = skillRegistry.get('transferOrdinal');
19
+ * const result = await skill.execute(ctx, { outpoint: '...', address: '...' });
20
+ *
21
+ * // Get MCP-compatible tool list
22
+ * const tools = skillRegistry.toMcpTools();
23
+ * ```
24
+ */
25
+ // Export skill types and helpers
26
+ export { createContext, } from "./skills/types";
27
+ // Export skill registry
28
+ export { SkillRegistry, skillRegistry } from "./skills/registry";
29
+ // Export constants
30
+ export * from "./constants";
31
+ // Export module skills and types
32
+ export * from "./balance";
33
+ export * from "./payments";
34
+ export * from "./ordinals";
35
+ export * from "./tokens";
36
+ export * from "./inscriptions";
37
+ export * from "./locks";
38
+ export * from "./signing";
39
+ export * from "./broadcast";
40
+ // Register all skills with the global registry
41
+ import { skillRegistry } from "./skills/registry";
42
+ import { balanceSkills } from "./balance";
43
+ import { paymentsSkills } from "./payments";
44
+ import { ordinalsSkills } from "./ordinals";
45
+ import { tokensSkills } from "./tokens";
46
+ import { inscriptionsSkills } from "./inscriptions";
47
+ import { locksSkills } from "./locks";
48
+ import { signingSkills } from "./signing";
49
+ import { broadcastSkills } from "./broadcast";
50
+ skillRegistry.registerAll([
51
+ ...balanceSkills,
52
+ ...paymentsSkills,
53
+ ...ordinalsSkills,
54
+ ...tokensSkills,
55
+ ...inscriptionsSkills,
56
+ ...locksSkills,
57
+ ...signingSkills,
58
+ ...broadcastSkills,
59
+ ]);
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Inscriptions Module
3
+ *
4
+ * Skills for creating inscriptions.
5
+ */
6
+ import type { Skill } from "../skills/types";
7
+ export interface InscribeRequest {
8
+ /** Base64 encoded content */
9
+ base64Content: string;
10
+ /** Content type (MIME type) */
11
+ contentType: string;
12
+ /** Optional MAP metadata */
13
+ map?: Record<string, string>;
14
+ }
15
+ export interface InscribeResponse {
16
+ txid?: string;
17
+ rawtx?: string;
18
+ error?: string;
19
+ }
20
+ /**
21
+ * Create an inscription.
22
+ */
23
+ export declare const inscribe: Skill<InscribeRequest, InscribeResponse>;
24
+ /** All inscription skills for registry */
25
+ export declare const inscriptionsSkills: Skill<InscribeRequest, InscribeResponse>[];
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Inscriptions Module
3
+ *
4
+ * Skills for creating inscriptions.
5
+ */
6
+ import { P2PKH, PublicKey, Script, Utils } from "@bsv/sdk";
7
+ import { Inscription } from "@bopen-io/templates";
8
+ import { MAX_INSCRIPTION_BYTES, ORDINALS_BASKET } from "../constants";
9
+ // ============================================================================
10
+ // Constants
11
+ // ============================================================================
12
+ const ORDINAL_PROTOCOL = [1, "ordinal"];
13
+ // ============================================================================
14
+ // Internal helpers
15
+ // ============================================================================
16
+ function buildInscriptionScript(address, base64Content, contentType) {
17
+ const content = Utils.toArray(base64Content, "base64");
18
+ const inscription = Inscription.create(new Uint8Array(content), contentType);
19
+ const inscriptionScript = inscription.lock();
20
+ const p2pkhScript = new P2PKH().lock(address);
21
+ const combined = new Script();
22
+ for (const chunk of inscriptionScript.chunks)
23
+ combined.chunks.push(chunk);
24
+ for (const chunk of p2pkhScript.chunks)
25
+ combined.chunks.push(chunk);
26
+ return combined;
27
+ }
28
+ // ============================================================================
29
+ // Skills
30
+ // ============================================================================
31
+ /**
32
+ * Create an inscription.
33
+ */
34
+ export const inscribe = {
35
+ meta: {
36
+ name: "inscribe",
37
+ description: "Create a new inscription with the given content and type",
38
+ category: "inscriptions",
39
+ inputSchema: {
40
+ type: "object",
41
+ properties: {
42
+ base64Content: { type: "string", description: "Base64 encoded content" },
43
+ contentType: { type: "string", description: "Content type (MIME type)" },
44
+ map: {
45
+ type: "object",
46
+ description: "Optional MAP metadata",
47
+ properties: {},
48
+ },
49
+ },
50
+ required: ["base64Content", "contentType"],
51
+ },
52
+ },
53
+ async execute(ctx, input) {
54
+ try {
55
+ const decoded = Utils.toArray(input.base64Content, "base64");
56
+ if (decoded.length > MAX_INSCRIPTION_BYTES) {
57
+ return { error: `Inscription data too large: ${decoded.length} bytes (max ${MAX_INSCRIPTION_BYTES})` };
58
+ }
59
+ const keyID = Date.now().toString();
60
+ const { publicKey } = await ctx.wallet.getPublicKey({
61
+ protocolID: ORDINAL_PROTOCOL,
62
+ keyID,
63
+ counterparty: "self",
64
+ forSelf: true,
65
+ });
66
+ const address = PublicKey.fromString(publicKey).toAddress();
67
+ const lockingScript = buildInscriptionScript(address, input.base64Content, input.contentType);
68
+ const result = await ctx.wallet.createAction({
69
+ description: "Create inscription",
70
+ outputs: [
71
+ {
72
+ lockingScript: lockingScript.toHex(),
73
+ satoshis: 1,
74
+ outputDescription: "Inscription",
75
+ basket: ORDINALS_BASKET,
76
+ tags: [`type:${input.contentType}`],
77
+ customInstructions: JSON.stringify({
78
+ protocolID: ORDINAL_PROTOCOL,
79
+ keyID,
80
+ }),
81
+ },
82
+ ],
83
+ });
84
+ if (!result.txid) {
85
+ return { error: "no-txid-returned" };
86
+ }
87
+ return { txid: result.txid, rawtx: result.tx ? Utils.toHex(result.tx) : undefined };
88
+ }
89
+ catch (error) {
90
+ return { error: error instanceof Error ? error.message : "unknown-error" };
91
+ }
92
+ },
93
+ };
94
+ // ============================================================================
95
+ // Module exports
96
+ // ============================================================================
97
+ /** All inscription skills for registry */
98
+ export const inscriptionsSkills = [inscribe];
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Locks Module
3
+ *
4
+ * Skills for time-locking BSV.
5
+ */
6
+ import type { Skill } from "../skills/types";
7
+ export interface LockBsvRequest {
8
+ /** Amount in satoshis to lock */
9
+ satoshis: number;
10
+ /** Block height until which to lock */
11
+ until: number;
12
+ }
13
+ export interface LockData {
14
+ /** Total locked satoshis */
15
+ totalLocked: number;
16
+ /** Unlockable satoshis (matured locks) */
17
+ unlockable: number;
18
+ /** Next unlock block height */
19
+ nextUnlock: number;
20
+ }
21
+ export interface LockOperationResponse {
22
+ txid?: string;
23
+ rawtx?: string;
24
+ error?: string;
25
+ }
26
+ /** Input for getLockData skill (no required params) */
27
+ export type GetLockDataInput = Record<string, never>;
28
+ /**
29
+ * Get lock data summary.
30
+ */
31
+ export declare const getLockData: Skill<GetLockDataInput, LockData>;
32
+ /** Input for lockBsv skill */
33
+ export interface LockBsvInput {
34
+ requests: LockBsvRequest[];
35
+ }
36
+ /**
37
+ * Lock BSV until a block height.
38
+ */
39
+ export declare const lockBsv: Skill<LockBsvInput, LockOperationResponse>;
40
+ /** Input for unlockBsv skill (no required params) */
41
+ export type UnlockBsvInput = Record<string, never>;
42
+ /**
43
+ * Unlock matured BSV locks.
44
+ */
45
+ export declare const unlockBsv: Skill<UnlockBsvInput, LockOperationResponse>;
46
+ /** All lock skills for registry */
47
+ export declare const locksSkills: (Skill<GetLockDataInput, LockData> | Skill<LockBsvInput, LockOperationResponse> | Skill<UnlockBsvInput, LockOperationResponse>)[];