@1sat/wallet-toolbox 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -186,6 +186,26 @@ const services = new OneSatServices("main", "https://ordfs.network");
186
186
  | `getBsv21TokenByTxid(tokenId, txid)` | Get BSV21 token data |
187
187
  | `getBsv21TokenDetails(tokenId)` | Get BSV21 token metadata (cached) |
188
188
 
189
+ #### Available Clients
190
+
191
+ OneSatServices exposes specialized API clients as public properties:
192
+
193
+ | Client | Property | Purpose |
194
+ |--------|----------|---------|
195
+ | Chaintracks | `.chaintracks` | Block headers and chain tracking |
196
+ | BEEF | `.beef` | Raw transactions and BEEF proofs |
197
+ | Arcade | `.arcade` | Transaction broadcasting |
198
+ | TXO | `.txo` | Transaction output queries |
199
+ | Owner | `.owner` | Address queries and SSE sync |
200
+ | OrdFS | `.ordfs` | Content and inscription metadata |
201
+ | BSV21 | `.bsv21` | BSV21 token data |
202
+
203
+ ```typescript
204
+ const services = new OneSatServices("main");
205
+ const rawTx = await services.beef.getRawTx(txid);
206
+ const metadata = await services.ordfs.getMetadata(outpoint);
207
+ ```
208
+
189
209
  ---
190
210
 
191
211
  ### ReadOnlySigner
@@ -242,25 +262,6 @@ Tags enable filtered queries via `listOutputs({ tags })`. Tags are only added fo
242
262
 
243
263
  ---
244
264
 
245
- ### TransactionParser
246
-
247
- Runs indexers over transactions to extract basket/tags for wallet-toolbox storage.
248
-
249
- ```typescript
250
- import { TransactionParser, FundIndexer, OriginIndexer } from "@1sat/wallet-toolbox";
251
-
252
- const parser = new TransactionParser(
253
- [new FundIndexer(owners, "mainnet"), new OriginIndexer(owners, "mainnet", services)],
254
- owners,
255
- services
256
- );
257
-
258
- const result = await parser.parse(transaction, true);
259
- // result.outputs: ParsedOutput[] with vout, basket, tags, customInstructions
260
- ```
261
-
262
- ---
263
-
264
265
  ## Project Status
265
266
 
266
267
  ### Completed
@@ -269,12 +270,12 @@ const result = await parser.parse(transaction, true);
269
270
  - [x] Read-only mode via public key
270
271
  - [x] OneSatServices (WalletServices implementation)
271
272
  - [x] All indexers migrated from yours-wallet
272
- - [x] TransactionParser for indexed ingestion
273
273
  - [x] `ingestTransaction()` method
274
274
  - [x] `syncAddress()` / `syncAll()` synchronization
275
275
  - [x] Event system for sync progress
276
276
  - [x] `broadcast()` method
277
277
  - [x] `getChainTracker()` implementation
278
+ - [x] Modular API client architecture
278
279
 
279
280
  ### TODO
280
281
 
@@ -287,7 +288,6 @@ const result = await parser.parse(transaction, true);
287
288
  - [ ] `getScriptHashHistory()`
288
289
  - [ ] `hashToHeader()`
289
290
  - [ ] `nLockTimeIsFinal()`
290
- - [ ] Improve basket/tag extraction in TransactionParser
291
291
  - [ ] Tests
292
292
  - [ ] Integration with yours-wallet
293
293
 
@@ -1,37 +1,68 @@
1
- import { Wallet, WalletStorageManager } from "@bsv/wallet-toolbox/mobile";
1
+ import { type PrivateKey, Transaction } from "@bsv/sdk";
2
+ import { Wallet, type WalletStorageManager } from "@bsv/wallet-toolbox/mobile";
2
3
  import type { Chain } from "@bsv/wallet-toolbox/mobile/out/src/sdk/types";
3
- import { PrivateKey, Transaction, type InternalizeActionResult } from "@bsv/sdk";
4
- export interface SyncStartEvent {
5
- address: string;
6
- fromScore: number;
7
- }
8
- export interface SyncProgressEvent {
9
- address: string;
10
- processed: number;
11
- remaining: number;
12
- currentScore: number;
13
- done: boolean;
14
- }
15
- export interface SyncTxEvent {
16
- address: string;
17
- txid: string;
18
- type: "output" | "spend";
19
- }
20
- export interface SyncErrorEvent {
21
- address: string;
22
- error: Error;
23
- }
24
- export interface SyncCompleteEvent {
25
- address: string;
26
- processed: number;
27
- finalScore: number;
4
+ import { Outpoint } from "./indexers/Outpoint";
5
+ import type { Indexer, ParseContext, Txo } from "./indexers/types";
6
+ import { OneSatServices, type SyncOutput } from "./services/OneSatServices";
7
+ /**
8
+ * Result of ingestTransaction including parse context for debugging
9
+ */
10
+ export interface IngestResult {
11
+ parseContext: ParseContext;
12
+ internalizedCount: number;
28
13
  }
14
+ /**
15
+ * Events emitted by OneSatWallet during sync operations
16
+ */
29
17
  export interface OneSatWalletEvents {
30
- "sync:start": SyncStartEvent;
31
- "sync:progress": SyncProgressEvent;
32
- "sync:tx": SyncTxEvent;
33
- "sync:error": SyncErrorEvent;
34
- "sync:complete": SyncCompleteEvent;
18
+ "sync:start": {
19
+ address: string;
20
+ fromScore: number;
21
+ };
22
+ "sync:output": {
23
+ address: string;
24
+ output: SyncOutput;
25
+ };
26
+ "sync:skipped": {
27
+ address: string;
28
+ outpoint: string;
29
+ reason: string;
30
+ };
31
+ "sync:parsed": {
32
+ address: string;
33
+ txid: string;
34
+ parseContext: ParseContext;
35
+ internalizedCount: number;
36
+ };
37
+ "sync:error": {
38
+ address: string;
39
+ error: Error;
40
+ };
41
+ "sync:complete": {
42
+ address: string;
43
+ };
44
+ "syncAll:start": {
45
+ addresses: string[];
46
+ fromScore: number;
47
+ };
48
+ "syncAll:output": {
49
+ output: SyncOutput;
50
+ };
51
+ "syncAll:skipped": {
52
+ outpoint: string;
53
+ reason: string;
54
+ };
55
+ "syncAll:parsed": {
56
+ txid: string;
57
+ parseContext: ParseContext;
58
+ internalizedCount: number;
59
+ };
60
+ "syncAll:error": {
61
+ error: Error;
62
+ };
63
+ "syncAll:complete": {
64
+ addresses: string[];
65
+ };
35
66
  }
36
67
  type EventCallback<T> = (event: T) => void;
37
68
  export interface OneSatWalletArgs {
@@ -52,13 +83,18 @@ export interface OneSatWalletArgs {
52
83
  */
53
84
  owners?: Set<string>;
54
85
  /**
55
- * Custom OrdFS server URL (default: https://ordfs.network)
86
+ * Indexers to use for parsing transactions.
87
+ * If not provided, default indexers will be used.
56
88
  */
57
- ordfsUrl?: string;
89
+ indexers?: Indexer[];
58
90
  /**
59
- * Custom 1Sat indexer URL (default: based on chain - mainnet or testnet)
91
+ * Custom 1Sat API URL (default: based on chain - mainnet or testnet)
60
92
  */
61
93
  onesatUrl?: string;
94
+ /**
95
+ * Automatically start syncing all owner addresses on construction.
96
+ */
97
+ autoSync?: boolean;
62
98
  }
63
99
  /**
64
100
  * OneSatWallet extends the BRC-100 Wallet with 1Sat-specific indexing and services.
@@ -69,64 +105,156 @@ export interface OneSatWalletArgs {
69
105
  */
70
106
  export declare class OneSatWallet extends Wallet {
71
107
  private readonly isReadOnly;
72
- private readonly parser;
73
- private readonly oneSatServices;
108
+ private readonly indexers;
109
+ readonly services: OneSatServices;
74
110
  private owners;
75
111
  private listeners;
112
+ private activeSyncs;
113
+ private activeMultiSync;
76
114
  constructor(args: OneSatWalletArgs);
77
115
  /**
78
116
  * Returns true if this wallet was created with only a public key.
79
117
  * Read-only wallets can query but not sign transactions.
80
118
  */
81
119
  get readOnly(): boolean;
120
+ /**
121
+ * Subscribe to wallet events
122
+ */
123
+ on<K extends keyof OneSatWalletEvents>(event: K, callback: EventCallback<OneSatWalletEvents[K]>): void;
124
+ /**
125
+ * Unsubscribe from wallet events
126
+ */
127
+ off<K extends keyof OneSatWalletEvents>(event: K, callback: EventCallback<OneSatWalletEvents[K]>): void;
128
+ /**
129
+ * Emit a wallet event
130
+ */
131
+ private emit;
82
132
  /**
83
133
  * Add an address to the set of owned addresses.
84
134
  * Outputs to these addresses will be indexed.
85
135
  */
86
136
  addOwner(address: string): void;
87
137
  /**
88
- * Subscribe to wallet events.
138
+ * Parse a transaction through indexers without internalizing.
139
+ *
140
+ * This is useful for debugging/testing to see what the indexers produce
141
+ * without actually storing the transaction in the wallet.
142
+ *
143
+ * @param tx - Transaction or txid to parse
144
+ * @param isBroadcasted - Whether this transaction has been broadcast
145
+ * @returns ParseContext with all indexer data
89
146
  */
90
- on<K extends keyof OneSatWalletEvents>(event: K, callback: EventCallback<OneSatWalletEvents[K]>): void;
147
+ parseTransaction(txOrTxid: Transaction | string, isBroadcasted?: boolean): Promise<ParseContext>;
91
148
  /**
92
- * Unsubscribe from wallet events.
149
+ * Parse a single output without full transaction context.
150
+ * Runs all indexers' parse() methods but NOT summarize().
151
+ *
152
+ * @param output - The TransactionOutput to parse
153
+ * @param outpoint - The outpoint identifying this output
154
+ * @returns Txo with all indexer data populated
93
155
  */
94
- off<K extends keyof OneSatWalletEvents>(event: K, callback: EventCallback<OneSatWalletEvents[K]>): void;
95
- private emit;
156
+ parseOutput(output: Transaction["outputs"][0], outpoint: Outpoint): Promise<Txo>;
96
157
  /**
97
- * Ingest a transaction by running it through indexers and then internalizing.
158
+ * Load and parse a single output by outpoint.
159
+ * Loads the transaction, extracts the output, and runs indexers on it.
160
+ *
161
+ * @param outpoint - Outpoint string (txid_vout)
162
+ * @returns Txo with all indexer data populated
163
+ */
164
+ loadTxo(outpoint: string): Promise<Txo>;
165
+ /**
166
+ * Run all indexers on a single Txo and populate its data/owner/basket
167
+ */
168
+ runIndexersOnTxo(txo: Txo): Promise<void>;
169
+ /**
170
+ * Parse all inputs - run indexers on source outputs to populate ctx.spends
171
+ */
172
+ private parseInputs;
173
+ /**
174
+ * Load a transaction by txid.
175
+ * Checks storage first, falls back to beef service.
176
+ *
177
+ * @param txid - Transaction ID to load
178
+ * @returns Transaction (without source transactions hydrated)
179
+ */
180
+ loadTransaction(txid: string): Promise<Transaction>;
181
+ /**
182
+ * Load and attach source transactions for all inputs (1 level deep).
183
+ * Modifies the transaction in place.
184
+ */
185
+ hydrateSourceTransactions(tx: Transaction): Promise<void>;
186
+ /**
187
+ * Build minimal parse context from transaction
188
+ */
189
+ buildParseContext(tx: Transaction): ParseContext;
190
+ /**
191
+ * Ingest a transaction by running it through indexers and writing directly to storage.
98
192
  *
99
193
  * This is the main entry point for adding external transactions to the wallet.
100
194
  * The indexers extract basket, tags, and custom instructions which are then
101
- * passed to the underlying wallet's internalizeAction.
195
+ * written directly to the wallet's storage.
196
+ *
197
+ * Unlike internalizeAction, this method also marks any wallet outputs that are
198
+ * consumed as inputs in the transaction as spent (spentBy, spendable: false).
102
199
  *
103
- * @param tx - Transaction or BEEF to ingest
200
+ * @param tx - Transaction to ingest
104
201
  * @param description - Human-readable description
105
202
  * @param labels - Optional labels for the transaction
106
203
  * @param isBroadcasted - Whether this transaction has been broadcast (affects validation)
204
+ * @returns Result including parse details for all outputs
107
205
  */
108
- ingestTransaction(tx: Transaction, description: string, labels?: string[], isBroadcasted?: boolean): Promise<InternalizeActionResult>;
206
+ ingestTransaction(tx: Transaction, description: string, labels?: string[], isBroadcasted?: boolean): Promise<IngestResult>;
109
207
  /**
110
208
  * Broadcast a transaction and ingest it into the wallet if successful.
111
209
  *
112
210
  * @param tx - Transaction to broadcast
113
211
  * @param description - Human-readable description for the transaction
114
212
  * @param labels - Optional labels for the transaction
115
- * @returns The internalize result if successful
213
+ * @returns The ingest result if successful
116
214
  * @throws Error if broadcast fails
117
215
  */
118
- broadcast(tx: Transaction, description: string, labels?: string[]): Promise<InternalizeActionResult>;
216
+ broadcast(tx: Transaction, description: string, labels?: string[]): Promise<IngestResult>;
119
217
  /**
120
- * Sync a single address from the 1Sat indexer.
121
- * Fetches new outputs and spends, ingesting transactions as needed.
218
+ * Sync a single address from the 1Sat indexer using Server-Sent Events.
219
+ * Runs in the background - use stopSync() or close() to stop.
122
220
  *
123
221
  * @param address - The address to sync
124
- * @param limit - Max outputs per page (default 100)
125
222
  */
126
- syncAddress(address: string, limit?: number): Promise<void>;
223
+ syncAddress(address: string, fromScore?: number): void;
224
+ /**
225
+ * Process a spend transaction during sync.
226
+ * Only marks our output as spent - doesn't ingest the spend tx.
227
+ * If the spend tx has outputs we own, they'll come through sync separately.
228
+ */
229
+ private processSpendTx;
230
+ /**
231
+ * Stop syncing a specific address.
232
+ */
233
+ stopSync(address: string): void;
234
+ /**
235
+ * Close the wallet and cleanup all active sync connections.
236
+ */
237
+ close(): void;
238
+ /**
239
+ * Start syncing all owner addresses using a single multi-owner SSE connection.
240
+ * This is more efficient than syncing each address individually.
241
+ *
242
+ * @param fromScore - Starting score (for pagination/resumption)
243
+ */
244
+ syncAll(fromScore?: number): void;
245
+ /**
246
+ * Process a spend transaction during multi-owner sync.
247
+ * Only marks our output as spent - doesn't ingest the spend tx.
248
+ */
249
+ private processSpendTxMulti;
250
+ /**
251
+ * Stop the multi-owner sync.
252
+ */
253
+ stopSyncAll(): void;
127
254
  /**
128
- * Sync all owner addresses in parallel.
255
+ * Start syncing each owner address individually.
256
+ * For most cases, use syncAll() instead which uses a single connection.
129
257
  */
130
- syncAll(): Promise<void>;
258
+ syncEach(): void;
131
259
  }
132
260
  export {};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- export { OneSatWallet, type OneSatWalletArgs, type OneSatWalletEvents, type SyncStartEvent, type SyncProgressEvent, type SyncTxEvent, type SyncErrorEvent, type SyncCompleteEvent, } from "./OneSatWallet";
2
- export { OneSatServices, type OrdfsMetadata } from "./services/OneSatServices";
1
+ export { OneSatWallet, type OneSatWalletArgs, type OneSatWalletEvents, type IngestResult, } from "./OneSatWallet";
2
+ export { OneSatServices, type SyncOutput } from "./services/OneSatServices";
3
+ export type { OrdfsMetadata, Capability } from "./services/types";
4
+ export * from "./services/client";
3
5
  export { ReadOnlySigner } from "./signers/ReadOnlySigner";
4
6
  export * from "./indexers";
5
- export { WalletStorageManager } from "@bsv/wallet-toolbox/mobile";
6
- export { StorageIdb } from "@bsv/wallet-toolbox/mobile/out/src/storage/StorageIdb";
7
- export type { Chain } from "@bsv/wallet-toolbox/mobile/out/src/sdk/types";