@1sat/wallet-toolbox 0.0.9 → 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.
@@ -1,100 +0,0 @@
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
- }
@@ -1,156 +0,0 @@
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
- }
@@ -1,53 +0,0 @@
1
- import { Transaction } from "@bsv/sdk";
2
- import type { OneSatServices } from "../services/OneSatServices";
3
- import type { Indexer } from "./types";
4
- /**
5
- * Represents the result of parsing a single output
6
- */
7
- export interface ParsedOutput {
8
- vout: number;
9
- basket: string;
10
- tags: string[];
11
- customInstructions?: unknown;
12
- }
13
- /**
14
- * Represents the result of parsing an entire transaction
15
- */
16
- export interface ParseResult {
17
- outputs: ParsedOutput[];
18
- summary?: unknown;
19
- }
20
- /**
21
- * TransactionParser runs indexers over a transaction to extract
22
- * basket, tags, and custom instructions for wallet-toolbox.
23
- *
24
- * This is a stripped-down version of TxoStore.ingest() that only
25
- * handles parsing without SPV verification or storage.
26
- */
27
- export declare class TransactionParser {
28
- indexers: Indexer[];
29
- owners: Set<string>;
30
- private services;
31
- constructor(indexers: Indexer[], owners: Set<string>, services: OneSatServices);
32
- /**
33
- * Parse a transaction and extract wallet-toolbox metadata
34
- */
35
- parse(tx: Transaction, isBroadcasted: boolean): Promise<ParseResult>;
36
- /**
37
- * Parse all inputs - run indexers on source outputs to populate ctx.spends
38
- */
39
- private parseInputs;
40
- /**
41
- * Load source transactions for all inputs and set them on tx.inputs[].sourceTransaction
42
- */
43
- private loadSourceTransactions;
44
- /**
45
- * Build minimal parse context from transaction
46
- */
47
- private buildContext;
48
- /**
49
- * Convert parsed context to wallet-toolbox format with baskets and tags
50
- * Filters outputs to only return those owned by addresses in the owners set
51
- */
52
- private convertToWalletToolboxFormat;
53
- }