@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.
@@ -0,0 +1,58 @@
1
+ import type { BalanceResponse, ClientOptions, IndexedOutput, SyncOutput, TxoQueryOptions } from "../types";
2
+ import { BaseClient } from "./BaseClient";
3
+ /**
4
+ * Client for /api/owner/* routes.
5
+ * Provides owner (address) queries and sync.
6
+ *
7
+ * Routes:
8
+ * - GET /:owner/txos - Get TXOs for owner
9
+ * - GET /:owner/balance - Get balance
10
+ * - GET /:owner/sync - SSE stream of outputs for sync
11
+ */
12
+ export declare class OwnerClient extends BaseClient {
13
+ constructor(baseUrl: string, options?: ClientOptions);
14
+ /**
15
+ * Get TXOs owned by an address/owner
16
+ */
17
+ getTxos(owner: string, opts?: TxoQueryOptions & {
18
+ refresh?: boolean;
19
+ }): Promise<IndexedOutput[]>;
20
+ /**
21
+ * Get balance for an address/owner
22
+ */
23
+ getBalance(owner: string): Promise<BalanceResponse>;
24
+ /**
25
+ * Sync outputs for an owner via SSE stream.
26
+ * Returns an EventSource that emits SyncOutput events.
27
+ *
28
+ * @param owner - Address/owner to sync
29
+ * @param onOutput - Callback for each output
30
+ * @param from - Starting score (for pagination/resumption)
31
+ * @param onDone - Callback when sync completes (client should retry after delay)
32
+ * @param onError - Callback for errors
33
+ * @returns Unsubscribe function
34
+ */
35
+ sync(owner: string, onOutput: (output: SyncOutput) => void, from?: number, onDone?: () => void, onError?: (error: Error) => void): () => void;
36
+ /**
37
+ * Sync outputs for multiple owners via SSE stream.
38
+ * The server merges results from all owners in score order.
39
+ *
40
+ * @param owners - Array of addresses/owners to sync
41
+ * @param onOutput - Callback for each output
42
+ * @param from - Starting score (for pagination/resumption)
43
+ * @param onDone - Callback when sync completes (client should retry after delay)
44
+ * @param onError - Callback for errors
45
+ * @returns Unsubscribe function
46
+ */
47
+ syncMulti(owners: string[], onOutput: (output: SyncOutput) => void, from?: number, onDone?: () => void, onError?: (error: Error) => void): () => void;
48
+ /**
49
+ * Sync outputs as an async iterator.
50
+ * Yields SyncOutput objects until the stream is done.
51
+ */
52
+ syncIterator(owner: string, from?: number): AsyncGenerator<SyncOutput, void, unknown>;
53
+ /**
54
+ * Sync outputs for multiple owners as an async iterator.
55
+ * Yields SyncOutput objects until the stream is done.
56
+ */
57
+ syncMultiIterator(owners: string[], from?: number): AsyncGenerator<SyncOutput, void, unknown>;
58
+ }
@@ -0,0 +1,46 @@
1
+ import type { ClientOptions, IndexedOutput, SearchRequest, TxoQueryOptions } from "../types";
2
+ import { BaseClient } from "./BaseClient";
3
+ /**
4
+ * Client for /api/txo/* routes.
5
+ * Provides TXO (transaction output) lookup and search.
6
+ *
7
+ * Routes:
8
+ * - GET /outpoint/:outpoint - Get single TXO
9
+ * - GET /outpoint/:outpoint/spend - Get spend info
10
+ * - POST /outpoints - Get multiple TXOs
11
+ * - POST /outpoints/spends - Get multiple spends
12
+ * - GET /tx/:txid - Get all TXOs for a transaction
13
+ * - GET /search/:key - Search by single key
14
+ * - POST /search - Search by multiple keys
15
+ */
16
+ export declare class TxoClient extends BaseClient {
17
+ constructor(baseUrl: string, options?: ClientOptions);
18
+ /**
19
+ * Get a single TXO by outpoint
20
+ */
21
+ get(outpoint: string, opts?: TxoQueryOptions): Promise<IndexedOutput>;
22
+ /**
23
+ * Get multiple TXOs by outpoints
24
+ */
25
+ getBatch(outpoints: string[], opts?: TxoQueryOptions): Promise<(IndexedOutput | null)[]>;
26
+ /**
27
+ * Get spend info for an outpoint
28
+ */
29
+ getSpend(outpoint: string): Promise<string | null>;
30
+ /**
31
+ * Get spend info for multiple outpoints
32
+ */
33
+ getSpends(outpoints: string[]): Promise<(string | null)[]>;
34
+ /**
35
+ * Get all TXOs for a transaction
36
+ */
37
+ getByTxid(txid: string, opts?: TxoQueryOptions): Promise<IndexedOutput[]>;
38
+ /**
39
+ * Search TXOs by a single key
40
+ */
41
+ search(key: string, opts?: TxoQueryOptions): Promise<IndexedOutput[]>;
42
+ /**
43
+ * Search TXOs by multiple keys
44
+ */
45
+ searchMultiple(req: SearchRequest): Promise<IndexedOutput[]>;
46
+ }
@@ -0,0 +1,8 @@
1
+ export { BaseClient } from "./BaseClient";
2
+ export { ChaintracksClient } from "./ChaintracksClient";
3
+ export { BeefClient } from "./BeefClient";
4
+ export { ArcadeClient } from "./ArcadeClient";
5
+ export { TxoClient } from "./TxoClient";
6
+ export { OwnerClient } from "./OwnerClient";
7
+ export { OrdfsClient } from "./OrdfsClient";
8
+ export { Bsv21Client } from "./Bsv21Client";
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Consolidated type definitions for 1sat-stack API clients.
3
+ * These types mirror the structures returned by the 1sat-stack server.
4
+ */
5
+ /**
6
+ * Options for configuring API clients
7
+ */
8
+ export interface ClientOptions {
9
+ /** Request timeout in milliseconds (default: 30000) */
10
+ timeout?: number;
11
+ /** Custom fetch implementation */
12
+ fetch?: typeof fetch;
13
+ }
14
+ /**
15
+ * Server capabilities returned by /api/capabilities endpoint.
16
+ * These match the actual capability names from 1sat-stack.
17
+ */
18
+ export type Capability = "beef" | "pubsub" | "txo" | "owner" | "indexer" | "bsv21" | "ordfs" | "chaintracks" | "arcade" | "overlay";
19
+ /**
20
+ * Block header data returned by chaintracks endpoints
21
+ */
22
+ export interface BlockHeader {
23
+ height: number;
24
+ hash: string;
25
+ version: number;
26
+ prevHash: string;
27
+ merkleRoot: string;
28
+ time: number;
29
+ bits: number;
30
+ nonce: number;
31
+ }
32
+ /**
33
+ * Transaction status values from arcade
34
+ */
35
+ export type TxStatus = "UNKNOWN" | "RECEIVED" | "SENT_TO_NETWORK" | "ACCEPTED_BY_NETWORK" | "SEEN_ON_NETWORK" | "DOUBLE_SPEND_ATTEMPTED" | "REJECTED" | "MINED" | "IMMUTABLE";
36
+ /**
37
+ * Transaction status response from arcade
38
+ */
39
+ export interface TransactionStatus {
40
+ txid: string;
41
+ txStatus: TxStatus;
42
+ timestamp: string;
43
+ blockHash?: string;
44
+ blockHeight?: number;
45
+ merklePath?: string;
46
+ extraInfo?: string;
47
+ competingTxs?: string[];
48
+ }
49
+ /**
50
+ * Options for submitting transactions to arcade
51
+ */
52
+ export interface SubmitOptions {
53
+ /** URL for status callbacks */
54
+ callbackUrl?: string;
55
+ /** Token for authenticating callbacks */
56
+ callbackToken?: string;
57
+ /** Receive all status updates, not just final */
58
+ fullStatusUpdates?: boolean;
59
+ /** Skip fee validation */
60
+ skipFeeValidation?: boolean;
61
+ /** Skip script validation */
62
+ skipScriptValidation?: boolean;
63
+ }
64
+ /**
65
+ * Mining policy from arcade
66
+ */
67
+ export interface Policy {
68
+ maxscriptsizepolicy: number;
69
+ maxtxsigopscountspolicy: number;
70
+ maxtxsizepolicy: number;
71
+ miningFee: {
72
+ satoshis: number;
73
+ bytes: number;
74
+ };
75
+ }
76
+ /**
77
+ * Indexed transaction output
78
+ */
79
+ export interface IndexedOutput {
80
+ outpoint: string;
81
+ satoshis: number;
82
+ script?: string;
83
+ height?: number;
84
+ idx?: number;
85
+ owners?: string[];
86
+ events?: string[];
87
+ data?: Record<string, unknown>;
88
+ spend?: string;
89
+ score: number;
90
+ }
91
+ /**
92
+ * Spend information response
93
+ */
94
+ export interface SpendResponse {
95
+ spendTxid: string | null;
96
+ }
97
+ /**
98
+ * Options for querying TXOs
99
+ */
100
+ export interface TxoQueryOptions {
101
+ /** Tags to include in response data */
102
+ tags?: string[];
103
+ /** Include script in response */
104
+ script?: boolean;
105
+ /** Starting score for pagination */
106
+ from?: number;
107
+ /** Maximum results to return */
108
+ limit?: number;
109
+ /** Reverse order */
110
+ rev?: boolean;
111
+ /** Filter for unspent only */
112
+ unspent?: boolean;
113
+ }
114
+ /**
115
+ * Search request for multiple keys
116
+ */
117
+ export interface SearchRequest {
118
+ keys: string[];
119
+ limit?: number;
120
+ from?: number;
121
+ reverse?: boolean;
122
+ unspent?: boolean;
123
+ tags?: string[];
124
+ }
125
+ /**
126
+ * Balance response from owner endpoint
127
+ */
128
+ export interface BalanceResponse {
129
+ balance: number;
130
+ count: number;
131
+ }
132
+ /**
133
+ * Sync output streamed via SSE
134
+ */
135
+ export interface SyncOutput {
136
+ outpoint: string;
137
+ score: number;
138
+ spendTxid?: string;
139
+ }
140
+ /**
141
+ * Indexed output from parse/ingest operations
142
+ */
143
+ export interface IndexedTxo {
144
+ outpoint: string;
145
+ satoshis: number;
146
+ script?: string;
147
+ owners?: string[];
148
+ events?: string[];
149
+ data?: Record<string, unknown>;
150
+ }
151
+ /**
152
+ * Index context returned by parse/ingest
153
+ */
154
+ export interface IndexContext {
155
+ txid: string;
156
+ score: number;
157
+ outputs: IndexedTxo[];
158
+ }
159
+ /**
160
+ * OrdFS metadata for an inscription
161
+ */
162
+ export interface OrdfsMetadata {
163
+ outpoint: string;
164
+ origin?: string;
165
+ sequence: number;
166
+ contentType: string;
167
+ contentLength: number;
168
+ parent?: string;
169
+ map?: Record<string, unknown>;
170
+ }
171
+ /**
172
+ * BSV21 token details (deploy data)
173
+ */
174
+ export interface Bsv21TokenDetails {
175
+ id: string;
176
+ txid: string;
177
+ vout: number;
178
+ op: string;
179
+ amt: string;
180
+ sym?: string;
181
+ dec: number;
182
+ icon?: string;
183
+ }
184
+ /**
185
+ * BSV21 token data structure from overlay API
186
+ */
187
+ export interface Bsv21TokenData {
188
+ id: string;
189
+ op: string;
190
+ amt: string;
191
+ sym?: string;
192
+ dec?: number;
193
+ icon?: string;
194
+ address?: string;
195
+ }
196
+ /**
197
+ * BSV21 output data from overlay API
198
+ */
199
+ export interface Bsv21OutputData {
200
+ txid: string;
201
+ vout: number;
202
+ data: {
203
+ bsv21: Bsv21TokenData;
204
+ };
205
+ script: string;
206
+ satoshis: number;
207
+ spend: string | null;
208
+ score: number;
209
+ }
210
+ /**
211
+ * BSV21 transaction data from overlay API
212
+ */
213
+ export interface Bsv21TransactionData {
214
+ txid: string;
215
+ inputs: Bsv21OutputData[];
216
+ outputs: Bsv21OutputData[];
217
+ beef?: string;
218
+ }
219
+ /**
220
+ * Event from SSE subscription
221
+ */
222
+ export interface SseEvent {
223
+ topic: string;
224
+ data: string;
225
+ score?: number;
226
+ }
@@ -1,4 +1,4 @@
1
- import { type KeyDeriverApi, type PrivateKey, type WalletProtocol, type Counterparty } from "@bsv/sdk";
1
+ import { type Counterparty, type KeyDeriverApi, type PrivateKey, type WalletProtocol } from "@bsv/sdk";
2
2
  /**
3
3
  * A read-only KeyDeriver that exposes an identity key but throws on any signing/derivation operation.
4
4
  * Used when the wallet is instantiated with only a public key.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/wallet-toolbox",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",
@@ -32,10 +32,13 @@
32
32
  "dev": "tsc --watch",
33
33
  "lint": "biome check src",
34
34
  "lint:fix": "biome check --write src",
35
- "test": "bun test"
35
+ "test": "bun test",
36
+ "tester:build": "bun build ./tester/src/entry.ts --outdir ./tester/dist --target browser --splitting --define 'process.env={}' --define 'global=globalThis' --sourcemap=inline",
37
+ "tester": "bun run build && bun run tester:build && bun ./tester/server.ts"
36
38
  },
37
39
  "dependencies": {
38
- "@bsv/sdk": "^1.9.24",
40
+ "@bopen-io/ts-templates": "^1.1.0",
41
+ "@bsv/sdk": "1.9.24",
39
42
  "@bsv/wallet-toolbox": "^1.7.14",
40
43
  "buffer": "^6.0.3"
41
44
  },
@@ -1,53 +0,0 @@
1
- import { Transaction } from "@bsv/sdk";
2
- import type { Indexer } from "./types";
3
- import type { OneSatServices } from "../services/OneSatServices";
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
- }