@1sat/wallet-toolbox 0.0.8 → 0.0.9

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 (55) hide show
  1. package/dist/api/OneSatApi.d.ts +100 -0
  2. package/dist/api/OneSatApi.js +156 -0
  3. package/dist/api/balance/index.d.ts +38 -0
  4. package/dist/api/balance/index.js +82 -0
  5. package/dist/api/broadcast/index.d.ts +22 -0
  6. package/dist/api/broadcast/index.js +45 -0
  7. package/dist/api/constants.d.ts +21 -0
  8. package/dist/api/constants.js +29 -0
  9. package/dist/api/index.d.ts +36 -0
  10. package/dist/api/index.js +38 -0
  11. package/dist/api/inscriptions/index.d.ts +25 -0
  12. package/dist/api/inscriptions/index.js +50 -0
  13. package/dist/api/locks/index.d.ts +44 -0
  14. package/dist/api/locks/index.js +233 -0
  15. package/dist/api/ordinals/index.d.ts +87 -0
  16. package/dist/api/ordinals/index.js +446 -0
  17. package/dist/api/payments/index.d.ts +37 -0
  18. package/dist/api/payments/index.js +130 -0
  19. package/dist/api/signing/index.d.ts +32 -0
  20. package/dist/api/signing/index.js +41 -0
  21. package/dist/api/tokens/index.d.ts +88 -0
  22. package/dist/api/tokens/index.js +400 -0
  23. package/dist/cwi/chrome.d.ts +11 -0
  24. package/dist/cwi/chrome.js +39 -0
  25. package/dist/cwi/event.d.ts +11 -0
  26. package/dist/cwi/event.js +38 -0
  27. package/dist/cwi/factory.d.ts +14 -0
  28. package/dist/cwi/factory.js +44 -0
  29. package/dist/cwi/index.d.ts +11 -0
  30. package/dist/cwi/index.js +11 -0
  31. package/dist/cwi/types.d.ts +39 -0
  32. package/dist/cwi/types.js +39 -0
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +5 -1
  35. package/dist/indexers/CosignIndexer.js +1 -0
  36. package/dist/indexers/InscriptionIndexer.js +3 -4
  37. package/dist/indexers/LockIndexer.js +1 -0
  38. package/dist/indexers/OrdLockIndexer.js +1 -0
  39. package/dist/indexers/OriginIndexer.js +1 -1
  40. package/dist/indexers/index.d.ts +1 -1
  41. package/dist/indexers/types.d.ts +18 -0
  42. package/dist/services/OneSatServices.d.ts +19 -10
  43. package/dist/services/OneSatServices.js +201 -39
  44. package/dist/services/client/ChaintracksClient.d.ts +55 -13
  45. package/dist/services/client/ChaintracksClient.js +123 -28
  46. package/dist/services/client/OrdfsClient.d.ts +2 -2
  47. package/dist/services/client/OrdfsClient.js +4 -3
  48. package/dist/services/client/TxoClient.js +9 -0
  49. package/dist/sync/AddressManager.d.ts +85 -0
  50. package/dist/sync/AddressManager.js +107 -0
  51. package/dist/sync/SyncManager.d.ts +207 -0
  52. package/dist/sync/SyncManager.js +507 -0
  53. package/dist/sync/index.d.ts +4 -0
  54. package/dist/sync/index.js +2 -0
  55. package/package.json +5 -4
@@ -0,0 +1,100 @@
1
+ /**
2
+ * OneSatApi - 1Sat ecosystem application logic built on BRC-100/CWI
3
+ *
4
+ * This class provides convenient, app-specific methods for the 1Sat ecosystem
5
+ * that internally use the standard CWI (WalletInterface) primitives.
6
+ *
7
+ * The class is a thin facade over the modular functions in the subfolders.
8
+ * You can use the class for convenience, or import functions directly:
9
+ *
10
+ * ```typescript
11
+ * // Class-based usage
12
+ * const api = new OneSatApi(cwi);
13
+ * const ordinals = await api.listOrdinals();
14
+ *
15
+ * // Function-based usage
16
+ * import { listOrdinals } from '@1sat/wallet-toolbox/api/ordinals';
17
+ * const ordinals = await listOrdinals(cwi);
18
+ * ```
19
+ */
20
+ import type { WalletInterface, WalletOutput, ListOutputsArgs } from "@bsv/sdk";
21
+ import type { OneSatServices } from "../services/OneSatServices";
22
+ import * as balance from "./balance";
23
+ import * as payments from "./payments";
24
+ import * as ordinals from "./ordinals";
25
+ import * as tokens from "./tokens";
26
+ import * as inscriptions from "./inscriptions";
27
+ import * as locks from "./locks";
28
+ import * as signing from "./signing";
29
+ import * as broadcast from "./broadcast";
30
+ export type { Balance, PaymentUtxo } from "./balance";
31
+ export type { SendBsvRequest, SendBsvResponse } from "./payments";
32
+ export type { TransferOrdinalRequest, ListOrdinalRequest, PurchaseOrdinalRequest, OrdinalOperationResponse, } from "./ordinals";
33
+ export type { Bsv21Balance, SendBsv21Request, PurchaseBsv21Request, TokenOperationResponse } from "./tokens";
34
+ export type { InscribeRequest, InscribeResponse } from "./inscriptions";
35
+ export type { LockBsvRequest, LockData, LockOperationResponse } from "./locks";
36
+ export type { SignMessageRequest, SignedMessage, } from "./signing";
37
+ export type { BroadcastRequest, BroadcastResponse } from "./broadcast";
38
+ export declare class OneSatApi {
39
+ private cwi;
40
+ private services?;
41
+ private chain;
42
+ private wocApiKey?;
43
+ constructor(cwi: WalletInterface, services?: OneSatServices | undefined, chain?: "main" | "test", wocApiKey?: string | undefined);
44
+ getBalance(): Promise<balance.Balance>;
45
+ getPaymentUtxos(): Promise<balance.PaymentUtxo[]>;
46
+ getExchangeRate(): Promise<number>;
47
+ sendBsv(requests: payments.SendBsvRequest[]): Promise<payments.SendBsvResponse>;
48
+ sendAllBsv(destination: string): Promise<payments.SendBsvResponse>;
49
+ /**
50
+ * List ordinals from the 1sat basket.
51
+ * Returns WalletOutput[] directly - use tags for metadata.
52
+ */
53
+ listOrdinals(options?: Partial<ListOutputsArgs>): Promise<WalletOutput[]>;
54
+ buildTransferOrdinal(request: ordinals.TransferOrdinalRequest): Promise<import("@bsv/sdk").CreateActionArgs | {
55
+ error: string;
56
+ }>;
57
+ buildListOrdinal(request: ordinals.ListOrdinalRequest): Promise<import("@bsv/sdk").CreateActionArgs | {
58
+ error: string;
59
+ }>;
60
+ transferOrdinal(request: ordinals.TransferOrdinalRequest): Promise<ordinals.OrdinalOperationResponse>;
61
+ listOrdinal(request: ordinals.ListOrdinalRequest): Promise<ordinals.OrdinalOperationResponse>;
62
+ cancelListing(outpoint: string): Promise<ordinals.OrdinalOperationResponse>;
63
+ purchaseOrdinal(request: ordinals.PurchaseOrdinalRequest): Promise<ordinals.OrdinalOperationResponse>;
64
+ /**
65
+ * Derive a cancel address for an ordinal listing.
66
+ * Uses the outpoint as keyID with security level 1 (self-only).
67
+ */
68
+ deriveCancelAddress(outpoint: string): Promise<string>;
69
+ /**
70
+ * List BSV21 token outputs.
71
+ * Returns WalletOutput[] directly - use tags for metadata.
72
+ */
73
+ listTokens(limit?: number): Promise<WalletOutput[]>;
74
+ getBsv21Balances(): Promise<tokens.Bsv21Balance[]>;
75
+ sendBsv21(request: tokens.SendBsv21Request): Promise<tokens.TokenOperationResponse>;
76
+ purchaseBsv21(request: tokens.PurchaseBsv21Request): Promise<tokens.TokenOperationResponse>;
77
+ inscribe(request: inscriptions.InscribeRequest): Promise<inscriptions.InscribeResponse>;
78
+ /**
79
+ * List locked outputs.
80
+ * Returns WalletOutput[] directly - use tags for metadata.
81
+ */
82
+ listLocks(limit?: number): Promise<WalletOutput[]>;
83
+ getLockData(): Promise<locks.LockData>;
84
+ lockBsv(requests: locks.LockBsvRequest[]): Promise<locks.LockOperationResponse>;
85
+ unlockBsv(): Promise<locks.LockOperationResponse>;
86
+ signMessage(request: signing.SignMessageRequest): Promise<signing.SignedMessage | {
87
+ error: string;
88
+ }>;
89
+ broadcast(request: broadcast.BroadcastRequest): Promise<broadcast.BroadcastResponse>;
90
+ /**
91
+ * Get the content URL for an inscription/ordinal.
92
+ * Useful for displaying in img/video tags.
93
+ * @param outpoint - Outpoint in format "txid_vout" (e.g., "abc123_0")
94
+ */
95
+ getContentUrl(outpoint: string): string;
96
+ /**
97
+ * Get the current block height from the CWI wallet.
98
+ */
99
+ getBlockHeight(): Promise<number>;
100
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * OneSatApi - 1Sat ecosystem application logic built on BRC-100/CWI
3
+ *
4
+ * This class provides convenient, app-specific methods for the 1Sat ecosystem
5
+ * that internally use the standard CWI (WalletInterface) primitives.
6
+ *
7
+ * The class is a thin facade over the modular functions in the subfolders.
8
+ * You can use the class for convenience, or import functions directly:
9
+ *
10
+ * ```typescript
11
+ * // Class-based usage
12
+ * const api = new OneSatApi(cwi);
13
+ * const ordinals = await api.listOrdinals();
14
+ *
15
+ * // Function-based usage
16
+ * import { listOrdinals } from '@1sat/wallet-toolbox/api/ordinals';
17
+ * const ordinals = await listOrdinals(cwi);
18
+ * ```
19
+ */
20
+ // Import from modules
21
+ import * as balance from "./balance";
22
+ import * as payments from "./payments";
23
+ import * as ordinals from "./ordinals";
24
+ import * as tokens from "./tokens";
25
+ import * as inscriptions from "./inscriptions";
26
+ import * as locks from "./locks";
27
+ import * as signing from "./signing";
28
+ import * as broadcast from "./broadcast";
29
+ import { ONESAT_MAINNET_CONTENT_URL, ONESAT_TESTNET_CONTENT_URL, } from "./constants";
30
+ export class OneSatApi {
31
+ cwi;
32
+ services;
33
+ chain;
34
+ wocApiKey;
35
+ constructor(cwi, services, chain = "main", wocApiKey) {
36
+ this.cwi = cwi;
37
+ this.services = services;
38
+ this.chain = chain;
39
+ this.wocApiKey = wocApiKey;
40
+ }
41
+ // ============ Balance ============
42
+ getBalance() {
43
+ return balance.getBalance(this.cwi, this.chain, this.wocApiKey);
44
+ }
45
+ getPaymentUtxos() {
46
+ return balance.getPaymentUtxos(this.cwi);
47
+ }
48
+ getExchangeRate() {
49
+ return balance.getExchangeRate(this.chain, this.wocApiKey);
50
+ }
51
+ // ============ Payments ============
52
+ sendBsv(requests) {
53
+ return payments.sendBsv(this.cwi, requests);
54
+ }
55
+ sendAllBsv(destination) {
56
+ return payments.sendAllBsv(this.cwi, destination);
57
+ }
58
+ // ============ Ordinals ============
59
+ /**
60
+ * List ordinals from the 1sat basket.
61
+ * Returns WalletOutput[] directly - use tags for metadata.
62
+ */
63
+ listOrdinals(options) {
64
+ return ordinals.listOrdinals(this.cwi, options);
65
+ }
66
+ buildTransferOrdinal(request) {
67
+ return ordinals.buildTransferOrdinal(this.cwi, request);
68
+ }
69
+ buildListOrdinal(request) {
70
+ return ordinals.buildListOrdinal(this.cwi, request);
71
+ }
72
+ transferOrdinal(request) {
73
+ return ordinals.transferOrdinal(this.cwi, request);
74
+ }
75
+ listOrdinal(request) {
76
+ return ordinals.listOrdinal(this.cwi, request);
77
+ }
78
+ cancelListing(outpoint) {
79
+ return ordinals.cancelListing(this.cwi, outpoint);
80
+ }
81
+ purchaseOrdinal(request) {
82
+ return ordinals.purchaseOrdinal(this.cwi, request, this.services);
83
+ }
84
+ /**
85
+ * Derive a cancel address for an ordinal listing.
86
+ * Uses the outpoint as keyID with security level 1 (self-only).
87
+ */
88
+ deriveCancelAddress(outpoint) {
89
+ return ordinals.deriveCancelAddress(this.cwi, outpoint);
90
+ }
91
+ // ============ Tokens ============
92
+ /**
93
+ * List BSV21 token outputs.
94
+ * Returns WalletOutput[] directly - use tags for metadata.
95
+ */
96
+ listTokens(limit) {
97
+ return tokens.listTokens(this.cwi, limit);
98
+ }
99
+ getBsv21Balances() {
100
+ return tokens.getBsv21Balances(this.cwi);
101
+ }
102
+ sendBsv21(request) {
103
+ return tokens.sendBsv21(this.cwi, request, this.services);
104
+ }
105
+ purchaseBsv21(request) {
106
+ return tokens.purchaseBsv21(this.cwi, request, this.services);
107
+ }
108
+ // ============ Inscriptions ============
109
+ inscribe(request) {
110
+ return inscriptions.inscribe(this.cwi, request);
111
+ }
112
+ // ============ Locks ============
113
+ /**
114
+ * List locked outputs.
115
+ * Returns WalletOutput[] directly - use tags for metadata.
116
+ */
117
+ listLocks(limit) {
118
+ return locks.listLocks(this.cwi, limit);
119
+ }
120
+ getLockData() {
121
+ return locks.getLockData(this.cwi, this.chain, this.wocApiKey);
122
+ }
123
+ lockBsv(requests) {
124
+ return locks.lockBsv(this.cwi, requests);
125
+ }
126
+ unlockBsv() {
127
+ return locks.unlockBsv(this.cwi, this.chain, this.wocApiKey);
128
+ }
129
+ // ============ Signing ============
130
+ signMessage(request) {
131
+ return signing.signMessage(this.cwi, request);
132
+ }
133
+ // ============ Broadcast ============
134
+ broadcast(request) {
135
+ return broadcast.broadcast(this.cwi, request);
136
+ }
137
+ // ============ Utilities ============
138
+ /**
139
+ * Get the content URL for an inscription/ordinal.
140
+ * Useful for displaying in img/video tags.
141
+ * @param outpoint - Outpoint in format "txid_vout" (e.g., "abc123_0")
142
+ */
143
+ getContentUrl(outpoint) {
144
+ const contentBaseUrl = this.chain === "main"
145
+ ? ONESAT_MAINNET_CONTENT_URL
146
+ : ONESAT_TESTNET_CONTENT_URL;
147
+ return `${contentBaseUrl}/${outpoint}`;
148
+ }
149
+ /**
150
+ * Get the current block height from the CWI wallet.
151
+ */
152
+ async getBlockHeight() {
153
+ const result = await this.cwi.getHeight({});
154
+ return result.height;
155
+ }
156
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Balance Module
3
+ *
4
+ * Functions for querying wallet balance and payment UTXOs.
5
+ */
6
+ import type { WalletInterface } from "@bsv/sdk";
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
+ /**
22
+ * Get wallet balance with USD conversion.
23
+ */
24
+ export declare function getBalance(cwi: WalletInterface, chain?: "main" | "test", wocApiKey?: string): Promise<Balance>;
25
+ /**
26
+ * Get payment UTXOs for external use.
27
+ */
28
+ export declare function getPaymentUtxos(cwi: WalletInterface): Promise<PaymentUtxo[]>;
29
+ /**
30
+ * Get current BSV/USD exchange rate.
31
+ */
32
+ export declare function getExchangeRate(chain?: "main" | "test", wocApiKey?: string): Promise<number>;
33
+ /**
34
+ * Get chain info from WhatsOnChain.
35
+ */
36
+ export declare function getChainInfo(chain?: "main" | "test", wocApiKey?: string): Promise<{
37
+ blocks: number;
38
+ } | null>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Balance Module
3
+ *
4
+ * Functions 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
+ * Get wallet balance with USD conversion.
11
+ */
12
+ export async function getBalance(cwi, chain = "main", wocApiKey) {
13
+ const exchangeRate = await getExchangeRate(chain, wocApiKey);
14
+ const result = await cwi.listOutputs({ basket: FUNDING_BASKET, limit: 10000 });
15
+ console.log(`[getBalance] Found ${result.outputs.length} outputs in "${FUNDING_BASKET}" basket, total: ${result.totalOutputs}`);
16
+ const satoshis = result.outputs.reduce((sum, o) => sum + o.satoshis, 0);
17
+ console.log(`[getBalance] Total satoshis: ${satoshis}`);
18
+ const bsv = satoshis / 100_000_000;
19
+ const usdInCents = Math.round(bsv * exchangeRate * 100);
20
+ return { satoshis, bsv, usdInCents };
21
+ }
22
+ /**
23
+ * Get payment UTXOs for external use.
24
+ */
25
+ export async function getPaymentUtxos(cwi) {
26
+ const result = await cwi.listOutputs({
27
+ basket: FUNDING_BASKET,
28
+ include: "locking scripts",
29
+ limit: 10000,
30
+ });
31
+ return result.outputs.map((o) => {
32
+ const [txid, voutStr] = o.outpoint.split(".");
33
+ return {
34
+ txid,
35
+ vout: parseInt(voutStr, 10),
36
+ satoshis: o.satoshis,
37
+ script: o.lockingScript || "",
38
+ };
39
+ });
40
+ }
41
+ /**
42
+ * Get current BSV/USD exchange rate.
43
+ */
44
+ export async function getExchangeRate(chain = "main", wocApiKey) {
45
+ if (exchangeRateCache && Date.now() - exchangeRateCache.timestamp < EXCHANGE_RATE_CACHE_TTL) {
46
+ return exchangeRateCache.rate;
47
+ }
48
+ const baseUrl = chain === "main" ? WOC_MAINNET_URL : WOC_TESTNET_URL;
49
+ const headers = {};
50
+ if (wocApiKey)
51
+ headers["woc-api-key"] = wocApiKey;
52
+ try {
53
+ const response = await fetch(`${baseUrl}/exchangerate`, { headers });
54
+ if (!response.ok)
55
+ throw new Error(`Failed to fetch: ${response.statusText}`);
56
+ const data = await response.json();
57
+ const rate = Number(data.rate.toFixed(2));
58
+ exchangeRateCache = { rate, timestamp: Date.now() };
59
+ return rate;
60
+ }
61
+ catch {
62
+ return exchangeRateCache?.rate ?? 0;
63
+ }
64
+ }
65
+ /**
66
+ * Get chain info from WhatsOnChain.
67
+ */
68
+ export async function getChainInfo(chain = "main", wocApiKey) {
69
+ const baseUrl = chain === "main" ? WOC_MAINNET_URL : WOC_TESTNET_URL;
70
+ const headers = {};
71
+ if (wocApiKey)
72
+ headers["woc-api-key"] = wocApiKey;
73
+ try {
74
+ const response = await fetch(`${baseUrl}/chain/info`, { headers });
75
+ if (!response.ok)
76
+ return null;
77
+ return await response.json();
78
+ }
79
+ catch {
80
+ return null;
81
+ }
82
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Broadcast Module
3
+ *
4
+ * Functions for broadcasting transactions.
5
+ */
6
+ import { type WalletInterface } from "@bsv/sdk";
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 function broadcast(cwi: WalletInterface, request: BroadcastRequest): Promise<BroadcastResponse>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Broadcast Module
3
+ *
4
+ * Functions for broadcasting transactions.
5
+ */
6
+ import { Beef, Transaction, } from "@bsv/sdk";
7
+ /**
8
+ * Broadcast a transaction and internalize it into the wallet.
9
+ */
10
+ export async function broadcast(cwi, request) {
11
+ try {
12
+ let tx;
13
+ switch (request.format) {
14
+ case "beef":
15
+ tx = Transaction.fromHexBEEF(request.rawtx);
16
+ break;
17
+ case "ef":
18
+ tx = Transaction.fromHexEF(request.rawtx);
19
+ break;
20
+ default:
21
+ tx = Transaction.fromHex(request.rawtx);
22
+ }
23
+ const txid = tx.id("hex");
24
+ const beef = new Beef();
25
+ beef.mergeTransaction(tx);
26
+ const outputs = tx.outputs.map((_, index) => ({
27
+ outputIndex: index,
28
+ protocol: "wallet payment",
29
+ paymentRemittance: {
30
+ derivationPrefix: "default",
31
+ derivationSuffix: `${txid}.${index}`,
32
+ senderIdentityKey: "",
33
+ },
34
+ }));
35
+ await cwi.internalizeAction({
36
+ tx: Array.from(beef.toBinary()),
37
+ outputs,
38
+ description: request.description || "Broadcast transaction",
39
+ });
40
+ return { txid };
41
+ }
42
+ catch (error) {
43
+ return { error: error instanceof Error ? error.message : "Unknown error" };
44
+ }
45
+ }
@@ -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 the OneSatApi class for interacting with the 1Sat ecosystem.
5
+ * All methods work with any BRC-100 compatible wallet interface (CWI).
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { OneSatApi } from '@1sat/wallet-toolbox';
10
+ *
11
+ * // Create API instance with a CWI-compatible wallet
12
+ * const api = new OneSatApi(cwi);
13
+ *
14
+ * // Use the API
15
+ * const balance = await api.getBalance();
16
+ * const ordinals = await api.listOrdinals();
17
+ * const result = await api.sendBsv([{ address: '...', satoshis: 1000 }]);
18
+ * ```
19
+ *
20
+ * You can also import functions directly from modules:
21
+ * ```typescript
22
+ * import { listOrdinals } from '@1sat/wallet-toolbox/api/ordinals';
23
+ * import { sendBsv } from '@1sat/wallet-toolbox/api/payments';
24
+ * ```
25
+ */
26
+ export { OneSatApi } from "./OneSatApi";
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,38 @@
1
+ /**
2
+ * 1Sat Wallet Toolbox API Layer
3
+ *
4
+ * This module provides the OneSatApi class for interacting with the 1Sat ecosystem.
5
+ * All methods work with any BRC-100 compatible wallet interface (CWI).
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { OneSatApi } from '@1sat/wallet-toolbox';
10
+ *
11
+ * // Create API instance with a CWI-compatible wallet
12
+ * const api = new OneSatApi(cwi);
13
+ *
14
+ * // Use the API
15
+ * const balance = await api.getBalance();
16
+ * const ordinals = await api.listOrdinals();
17
+ * const result = await api.sendBsv([{ address: '...', satoshis: 1000 }]);
18
+ * ```
19
+ *
20
+ * You can also import functions directly from modules:
21
+ * ```typescript
22
+ * import { listOrdinals } from '@1sat/wallet-toolbox/api/ordinals';
23
+ * import { sendBsv } from '@1sat/wallet-toolbox/api/payments';
24
+ * ```
25
+ */
26
+ // Export the main API class
27
+ export { OneSatApi } from "./OneSatApi";
28
+ // Export constants
29
+ export * from "./constants";
30
+ // Export module functions and types
31
+ export * from "./balance";
32
+ export * from "./payments";
33
+ export * from "./ordinals";
34
+ export * from "./tokens";
35
+ export * from "./inscriptions";
36
+ export * from "./locks";
37
+ export * from "./signing";
38
+ export * from "./broadcast";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Inscriptions Module
3
+ *
4
+ * Functions for creating inscriptions.
5
+ */
6
+ import { type WalletInterface } from "@bsv/sdk";
7
+ export interface InscribeRequest {
8
+ /** Base64 encoded data */
9
+ base64Data: string;
10
+ /** MIME type of the content */
11
+ mimeType: string;
12
+ /** Optional MAP metadata */
13
+ map?: Record<string, string>;
14
+ /** Destination address for the inscription (required - use a derived address) */
15
+ destination: string;
16
+ }
17
+ export interface InscribeResponse {
18
+ txid?: string;
19
+ rawtx?: string;
20
+ error?: string;
21
+ }
22
+ /**
23
+ * Create an inscription.
24
+ */
25
+ export declare function inscribe(cwi: WalletInterface, request: InscribeRequest): Promise<InscribeResponse>;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Inscriptions Module
3
+ *
4
+ * Functions for creating inscriptions.
5
+ */
6
+ import { P2PKH, Script, Utils, } from "@bsv/sdk";
7
+ import { Inscription } from "@bopen-io/templates";
8
+ import { MAX_INSCRIPTION_BYTES } from "../constants";
9
+ /**
10
+ * Build an inscription locking script.
11
+ */
12
+ function buildInscriptionScript(address, base64Data, mimeType) {
13
+ const content = Utils.toArray(base64Data, "base64");
14
+ const inscription = Inscription.create(new Uint8Array(content), mimeType);
15
+ const inscriptionScript = inscription.lock();
16
+ const p2pkhScript = new P2PKH().lock(address);
17
+ const combined = new Script();
18
+ for (const chunk of inscriptionScript.chunks)
19
+ combined.chunks.push(chunk);
20
+ for (const chunk of p2pkhScript.chunks)
21
+ combined.chunks.push(chunk);
22
+ return combined;
23
+ }
24
+ /**
25
+ * Create an inscription.
26
+ */
27
+ export async function inscribe(cwi, request) {
28
+ try {
29
+ const decoded = Buffer.from(request.base64Data, "base64");
30
+ if (decoded.length > MAX_INSCRIPTION_BYTES) {
31
+ return { error: `Inscription data too large: ${decoded.length} bytes (max ${MAX_INSCRIPTION_BYTES})` };
32
+ }
33
+ const lockingScript = buildInscriptionScript(request.destination, request.base64Data, request.mimeType);
34
+ const result = await cwi.createAction({
35
+ description: "Create inscription",
36
+ outputs: [{
37
+ lockingScript: lockingScript.toHex(),
38
+ satoshis: 1,
39
+ outputDescription: "Inscription",
40
+ }],
41
+ });
42
+ if (!result.txid) {
43
+ return { error: "no-txid-returned" };
44
+ }
45
+ return { txid: result.txid, rawtx: result.tx ? Utils.toHex(result.tx) : undefined };
46
+ }
47
+ catch (error) {
48
+ return { error: error instanceof Error ? error.message : "unknown-error" };
49
+ }
50
+ }