@1sat/client 0.0.2 → 0.0.4
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/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +3 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -16
- package/dist/index.js.map +1 -1
- package/dist/services/ArcadeClient.d.ts +46 -0
- package/dist/services/ArcadeClient.d.ts.map +1 -0
- package/dist/services/ArcadeClient.js +108 -0
- package/dist/services/ArcadeClient.js.map +1 -0
- package/dist/services/BaseClient.d.ts +33 -0
- package/dist/services/BaseClient.d.ts.map +1 -0
- package/dist/services/BaseClient.js +126 -0
- package/dist/services/BaseClient.js.map +1 -0
- package/dist/services/BeefClient.d.ts +27 -0
- package/dist/services/BeefClient.d.ts.map +1 -0
- package/dist/services/BeefClient.js +34 -0
- package/dist/services/BeefClient.js.map +1 -0
- package/dist/services/Bsv21Client.d.ts +110 -0
- package/dist/services/Bsv21Client.d.ts.map +1 -0
- package/dist/services/Bsv21Client.js +155 -0
- package/dist/services/Bsv21Client.js.map +1 -0
- package/dist/services/ChaintracksClient.d.ts +105 -0
- package/dist/services/ChaintracksClient.d.ts.map +1 -0
- package/dist/services/ChaintracksClient.js +227 -0
- package/dist/services/ChaintracksClient.js.map +1 -0
- package/dist/services/OneSatServices.d.ts +81 -0
- package/dist/services/OneSatServices.d.ts.map +1 -0
- package/dist/services/OneSatServices.js +401 -0
- package/dist/services/OneSatServices.js.map +1 -0
- package/dist/services/OrdfsClient.d.ts +48 -0
- package/dist/services/OrdfsClient.d.ts.map +1 -0
- package/dist/services/OrdfsClient.js +124 -0
- package/dist/services/OrdfsClient.js.map +1 -0
- package/dist/services/OverlayClient.d.ts +50 -0
- package/dist/services/OverlayClient.d.ts.map +1 -0
- package/dist/services/OverlayClient.js +48 -0
- package/dist/services/OverlayClient.js.map +1 -0
- package/dist/services/OwnerClient.d.ts +84 -0
- package/dist/services/OwnerClient.d.ts.map +1 -0
- package/dist/services/OwnerClient.js +241 -0
- package/dist/services/OwnerClient.js.map +1 -0
- package/dist/services/TxoClient.d.ts +42 -0
- package/dist/services/TxoClient.d.ts.map +1 -0
- package/dist/services/TxoClient.js +95 -0
- package/dist/services/TxoClient.js.map +1 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +11 -0
- package/dist/services/index.js.map +1 -0
- package/package.json +5 -6
- package/dist/broadcast/index.d.ts +0 -41
- package/dist/broadcast/index.d.ts.map +0 -1
- package/dist/broadcast/index.js +0 -78
- package/dist/broadcast/index.js.map +0 -1
- package/dist/http/index.d.ts +0 -32
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -63
- package/dist/http/index.js.map +0 -1
- package/dist/indexer/index.d.ts +0 -65
- package/dist/indexer/index.d.ts.map +0 -1
- package/dist/indexer/index.js +0 -202
- package/dist/indexer/index.js.map +0 -1
- package/dist/input.d.ts +0 -30
- package/dist/input.d.ts.map +0 -1
- package/dist/input.js +0 -46
- package/dist/input.js.map +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { BaseClient } from './BaseClient';
|
|
2
|
+
/**
|
|
3
|
+
* Client for /1sat/bsv21/* routes.
|
|
4
|
+
* Provides BSV21 token queries.
|
|
5
|
+
*
|
|
6
|
+
* Routes:
|
|
7
|
+
* - POST /lookup - Bulk lookup token details with funding status
|
|
8
|
+
* - GET /:tokenId - Get token details with funding status
|
|
9
|
+
* - GET /:tokenId/tx/:txid - Get token transaction data
|
|
10
|
+
* - GET /:tokenId/:lockType/:address/balance - Get token balance
|
|
11
|
+
* - GET /:tokenId/:lockType/:address/unspent - Get unspent token UTXOs
|
|
12
|
+
* - GET /:tokenId/:lockType/:address/history - Get token transaction history
|
|
13
|
+
* - POST /:tokenId/:lockType/balance - Multi-address token balance
|
|
14
|
+
* - POST /:tokenId/:lockType/unspent - Multi-address unspent token UTXOs
|
|
15
|
+
* - POST /:tokenId/:lockType/history - Multi-address token transaction history
|
|
16
|
+
*/
|
|
17
|
+
export class Bsv21Client extends BaseClient {
|
|
18
|
+
cache = new Map();
|
|
19
|
+
constructor(baseUrl, options = {}) {
|
|
20
|
+
super(`${baseUrl}/1sat/bsv21`, options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Bulk lookup token details with funding status.
|
|
24
|
+
* Returns details and active status for multiple tokens in one request.
|
|
25
|
+
* @param tokenIds - Array of token IDs (max 100)
|
|
26
|
+
*/
|
|
27
|
+
async lookupTokens(tokenIds) {
|
|
28
|
+
return this.request('/lookup', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
body: JSON.stringify(tokenIds),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get token details with funding status.
|
|
36
|
+
* Results are cached since token deploy data is immutable.
|
|
37
|
+
*/
|
|
38
|
+
async getTokenDetails(tokenId) {
|
|
39
|
+
const cached = this.cache.get(tokenId);
|
|
40
|
+
if (cached)
|
|
41
|
+
return cached;
|
|
42
|
+
const details = await this.request(`/${tokenId}`);
|
|
43
|
+
this.cache.set(tokenId, details);
|
|
44
|
+
return details;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get token transaction data for a specific txid
|
|
48
|
+
*/
|
|
49
|
+
async getTokenByTxid(tokenId, txid) {
|
|
50
|
+
return this.request(`/${tokenId}/tx/${txid}`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get token balance for an address
|
|
54
|
+
*/
|
|
55
|
+
async getBalance(tokenId, lockType, address) {
|
|
56
|
+
return this.request(`/${tokenId}/${lockType}/${address}/balance`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get unspent token UTXOs for an address
|
|
60
|
+
*/
|
|
61
|
+
async getUnspent(tokenId, lockType, address) {
|
|
62
|
+
return this.request(`/${tokenId}/${lockType}/${address}/unspent`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get token transaction history for an address
|
|
66
|
+
*/
|
|
67
|
+
async getHistory(tokenId, lockType, address) {
|
|
68
|
+
return this.request(`/${tokenId}/${lockType}/${address}/history`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get token balance for multiple addresses
|
|
72
|
+
* @param addresses - Array of addresses (max 100)
|
|
73
|
+
*/
|
|
74
|
+
async getBalanceMulti(tokenId, lockType, addresses) {
|
|
75
|
+
return this.request(`/${tokenId}/${lockType}/balance`, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: { 'Content-Type': 'application/json' },
|
|
78
|
+
body: JSON.stringify(addresses),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get unspent token UTXOs for multiple addresses
|
|
83
|
+
* @param addresses - Array of addresses (max 100)
|
|
84
|
+
*/
|
|
85
|
+
async getUnspentMulti(tokenId, lockType, addresses) {
|
|
86
|
+
return this.request(`/${tokenId}/${lockType}/unspent`, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: { 'Content-Type': 'application/json' },
|
|
89
|
+
body: JSON.stringify(addresses),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get token transaction history for multiple addresses
|
|
94
|
+
* @param addresses - Array of addresses (max 100)
|
|
95
|
+
*/
|
|
96
|
+
async getHistoryMulti(tokenId, lockType, addresses) {
|
|
97
|
+
return this.request(`/${tokenId}/${lockType}/history`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: { 'Content-Type': 'application/json' },
|
|
100
|
+
body: JSON.stringify(addresses),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validate specific outpoints against the token's overlay topic.
|
|
105
|
+
* Returns only those found in the overlay. By default returns minimal data
|
|
106
|
+
* (outpoint + score). Use opts to include additional fields.
|
|
107
|
+
* @param tokenId - Token ID (txid_vout format)
|
|
108
|
+
* @param outpoints - Array of outpoints to validate (max 1000)
|
|
109
|
+
* @param opts - Optional query flags for additional data
|
|
110
|
+
*/
|
|
111
|
+
async validateOutputs(tokenId, outpoints, opts) {
|
|
112
|
+
const params = this.buildOutputQuery(opts);
|
|
113
|
+
return this.request(`/${tokenId}/outputs${params}`, {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: { 'Content-Type': 'application/json' },
|
|
116
|
+
body: JSON.stringify(outpoints),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Validate a single outpoint against the token's overlay topic.
|
|
121
|
+
* Returns 404 if not found. By default returns minimal data (outpoint + score).
|
|
122
|
+
* @param tokenId - Token ID (txid_vout format)
|
|
123
|
+
* @param outpoint - Outpoint to validate (txid_vout or txid:vout)
|
|
124
|
+
* @param opts - Optional query flags for additional data
|
|
125
|
+
*/
|
|
126
|
+
async validateOutput(tokenId, outpoint, opts) {
|
|
127
|
+
const params = this.buildOutputQuery(opts);
|
|
128
|
+
return this.request(`/${tokenId}/outputs/${outpoint}${params}`);
|
|
129
|
+
}
|
|
130
|
+
buildOutputQuery(opts) {
|
|
131
|
+
if (!opts)
|
|
132
|
+
return '';
|
|
133
|
+
const parts = [];
|
|
134
|
+
if (opts.unspent)
|
|
135
|
+
parts.push('unspent=true');
|
|
136
|
+
if (opts.spend)
|
|
137
|
+
parts.push('spend=true');
|
|
138
|
+
if (opts.sats)
|
|
139
|
+
parts.push('sats=true');
|
|
140
|
+
if (opts.events)
|
|
141
|
+
parts.push('events=true');
|
|
142
|
+
if (opts.block)
|
|
143
|
+
parts.push('block=true');
|
|
144
|
+
if (opts.tags)
|
|
145
|
+
parts.push(`tags=${encodeURIComponent(opts.tags)}`);
|
|
146
|
+
return parts.length > 0 ? `?${parts.join('&')}` : '';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clear the token details cache
|
|
150
|
+
*/
|
|
151
|
+
clearCache() {
|
|
152
|
+
this.cache.clear();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=Bsv21Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bsv21Client.js","sourceRoot":"","sources":["../../src/services/Bsv21Client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAqBzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;IAClC,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAA;IAEtD,YAAY,OAAe,EAAE,UAAyB,EAAE;QACvD,KAAK,CAAC,GAAG,OAAO,aAAa,EAAE,OAAO,CAAC,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,QAAkB;QACpC,OAAO,IAAI,CAAC,OAAO,CAAwB,SAAS,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;SAC9B,CAAC,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,OAAe;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACtC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QAEzB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAsB,IAAI,OAAO,EAAE,CAAC,CAAA;QACtE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAChC,OAAO,OAAO,CAAA;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CACnB,OAAe,EACf,IAAY;QAEZ,OAAO,IAAI,CAAC,O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CAAC,WAAW,CAAC,CAAA;QACtC,IAAI,IAAI,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAC1C,IAAI,IAAI,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QACxC,IAAI,IAAI,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAClE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACrD,CAAC;IAED;;OAEG;IACH,UAAU;QACT,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;CACD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ClientOptions } from '@1sat/types';
|
|
2
|
+
import type { ChainTracker } from '@bsv/sdk';
|
|
3
|
+
import type { BaseBlockHeader, BlockHeader, Chain } from '@bsv/wallet-toolbox-mobile';
|
|
4
|
+
import { BaseClient } from './BaseClient';
|
|
5
|
+
/**
|
|
6
|
+
* Client for /1sat/chaintracks/* routes.
|
|
7
|
+
* Implements ChaintracksClientApi interface from @bsv/wallet-toolbox.
|
|
8
|
+
*
|
|
9
|
+
* Routes:
|
|
10
|
+
* - GET /tip - Get chain tip
|
|
11
|
+
* - GET /tip/stream - SSE stream of new blocks
|
|
12
|
+
* - GET /network - Get network type
|
|
13
|
+
* - GET /headers?height=N&count=M - Get raw header bytes
|
|
14
|
+
* - GET /header/height/:height - Get header by height
|
|
15
|
+
* - GET /header/hash/:hash - Get header by hash
|
|
16
|
+
*/
|
|
17
|
+
export declare class ChaintracksClient extends BaseClient implements ChainTracker {
|
|
18
|
+
private eventSource;
|
|
19
|
+
private subscribers;
|
|
20
|
+
private cachedTip;
|
|
21
|
+
private cachedTipTime;
|
|
22
|
+
private static readonly TIP_CACHE_TTL_MS;
|
|
23
|
+
constructor(baseUrl: string, options?: ClientOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Get current blockchain height (ChainTracker interface)
|
|
26
|
+
*/
|
|
27
|
+
currentHeight(): Promise<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Validate merkle root for a given height (ChainTracker interface)
|
|
30
|
+
*/
|
|
31
|
+
isValidRootForHeight(root: string, height: number): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the blockchain network (main or test)
|
|
34
|
+
*/
|
|
35
|
+
getChain(): Promise<Chain>;
|
|
36
|
+
/**
|
|
37
|
+
* Get service info - synthetic for remote client
|
|
38
|
+
*/
|
|
39
|
+
getInfo(): Promise<{
|
|
40
|
+
chain: Chain;
|
|
41
|
+
heightBulk: number;
|
|
42
|
+
heightLive: number;
|
|
43
|
+
storage: string;
|
|
44
|
+
bulkIngestors: string[];
|
|
45
|
+
liveIngestors: string[];
|
|
46
|
+
packages: {
|
|
47
|
+
name: string;
|
|
48
|
+
version: string;
|
|
49
|
+
}[];
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Get current chain height
|
|
53
|
+
*/
|
|
54
|
+
getPresentHeight(): Promise<number>;
|
|
55
|
+
/**
|
|
56
|
+
* Get headers as serialized 80-byte hex string
|
|
57
|
+
*/
|
|
58
|
+
getHeaders(height: number, count: number): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the current chain tip header (cached for 30 seconds)
|
|
61
|
+
*/
|
|
62
|
+
findChainTipHeader(): Promise<BlockHeader>;
|
|
63
|
+
/**
|
|
64
|
+
* Get the current chain tip hash
|
|
65
|
+
*/
|
|
66
|
+
findChainTipHash(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Get block header by height
|
|
69
|
+
*/
|
|
70
|
+
findHeaderForHeight(height: number): Promise<BlockHeader | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Get block header by hash
|
|
73
|
+
*/
|
|
74
|
+
findHeaderForBlockHash(hash: string): Promise<BlockHeader | undefined>;
|
|
75
|
+
/** No-op: Remote server tracks the chain */
|
|
76
|
+
addHeader(_header: BaseBlockHeader): Promise<void>;
|
|
77
|
+
/** No-op: Client is always ready */
|
|
78
|
+
startListening(): Promise<void>;
|
|
79
|
+
/** No-op: Resolves immediately */
|
|
80
|
+
listening(): Promise<void>;
|
|
81
|
+
/** Always true for remote client */
|
|
82
|
+
isListening(): Promise<boolean>;
|
|
83
|
+
/** Always true for remote client */
|
|
84
|
+
isSynchronized(): Promise<boolean>;
|
|
85
|
+
/** Not implemented for remote client */
|
|
86
|
+
subscribeReorgs(_listener: (depth: number, oldTip: BlockHeader, newTip: BlockHeader, deactivatedHeaders?: BlockHeader[]) => void): Promise<string>;
|
|
87
|
+
/** Unsubscribe from events */
|
|
88
|
+
unsubscribe(_subscriptionId: string): Promise<boolean>;
|
|
89
|
+
/** Subscribe to new header events */
|
|
90
|
+
subscribeHeaders(listener: (header: BlockHeader) => void): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Get raw header bytes for one or more headers
|
|
93
|
+
*/
|
|
94
|
+
getHeaderBytes(height: number, count?: number): Promise<number[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to new block notifications via SSE
|
|
97
|
+
* Returns unsubscribe function
|
|
98
|
+
*/
|
|
99
|
+
subscribe(callback: (header: BlockHeader) => void): () => void;
|
|
100
|
+
/**
|
|
101
|
+
* Close all connections
|
|
102
|
+
*/
|
|
103
|
+
close(): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ChaintracksClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChaintracksClient.d.ts","sourceRoot":"","sources":["../../src/services/ChaintracksClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,M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|
|
|
1
|
+
import { BaseClient } from './BaseClient';
|
|
2
|
+
/**
|
|
3
|
+
* Convert bytes to hex string (big-endian / natural order)
|
|
4
|
+
*/
|
|
5
|
+
function toHex(data) {
|
|
6
|
+
return Array.from(data)
|
|
7
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
8
|
+
.join('');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Client for /1sat/chaintracks/* routes.
|
|
12
|
+
* Implements ChaintracksClientApi interface from @bsv/wallet-toolbox.
|
|
13
|
+
*
|
|
14
|
+
* Routes:
|
|
15
|
+
* - GET /tip - Get chain tip
|
|
16
|
+
* - GET /tip/stream - SSE stream of new blocks
|
|
17
|
+
* - GET /network - Get network type
|
|
18
|
+
* - GET /headers?height=N&count=M - Get raw header bytes
|
|
19
|
+
* - GET /header/height/:height - Get header by height
|
|
20
|
+
* - GET /header/hash/:hash - Get header by hash
|
|
21
|
+
*/
|
|
22
|
+
export class ChaintracksClient extends BaseClient {
|
|
23
|
+
eventSource = null;
|
|
24
|
+
subscribers = new Set();
|
|
25
|
+
// Chain tip cache (30 second TTL)
|
|
26
|
+
cachedTip = null;
|
|
27
|
+
cachedTipTime = 0;
|
|
28
|
+
static TIP_CACHE_TTL_MS = 30_000;
|
|
29
|
+
constructor(baseUrl, options = {}) {
|
|
30
|
+
super(`${baseUrl}/1sat/chaintracks`, options);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get current blockchain height (ChainTracker interface)
|
|
34
|
+
*/
|
|
35
|
+
async currentHeight() {
|
|
36
|
+
const tip = await this.findChainTipHeader();
|
|
37
|
+
return tip.height;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate merkle root for a given height (ChainTracker interface)
|
|
41
|
+
*/
|
|
42
|
+
async isValidRootForHeight(root, height) {
|
|
43
|
+
try {
|
|
44
|
+
const header = await this.findHeaderForHeight(height);
|
|
45
|
+
return header?.merkleRoot === root;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error(`isValidRootForHeight(${height}) failed:`, e);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the blockchain network (main or test)
|
|
54
|
+
*/
|
|
55
|
+
async getChain() {
|
|
56
|
+
const data = await this.request('/network');
|
|
57
|
+
return data.network;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get service info - synthetic for remote client
|
|
61
|
+
*/
|
|
62
|
+
async getInfo() {
|
|
63
|
+
const tip = await this.findChainTipHeader();
|
|
64
|
+
const chain = await this.getChain();
|
|
65
|
+
return {
|
|
66
|
+
chain,
|
|
67
|
+
heightBulk: tip.height,
|
|
68
|
+
heightLive: tip.height,
|
|
69
|
+
storage: 'remote',
|
|
70
|
+
bulkIngestors: [],
|
|
71
|
+
liveIngestors: [],
|
|
72
|
+
packages: [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get current chain height
|
|
77
|
+
*/
|
|
78
|
+
async getPresentHeight() {
|
|
79
|
+
return this.currentHeight();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get headers as serialized 80-byte hex string
|
|
83
|
+
*/
|
|
84
|
+
async getHeaders(height, count) {
|
|
85
|
+
const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
|
|
86
|
+
return toHex(data);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the current chain tip header (cached for 30 seconds)
|
|
90
|
+
*/
|
|
91
|
+
async findChainTipHeader() {
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
if (this.cachedTip &&
|
|
94
|
+
now - this.cachedTipTime < ChaintracksClient.TIP_CACHE_TTL_MS) {
|
|
95
|
+
return this.cachedTip;
|
|
96
|
+
}
|
|
97
|
+
const header = await this.request('/tip');
|
|
98
|
+
console.log('[ChaintracksClient] findChainTipHeader:', header.height, header.hash);
|
|
99
|
+
this.cachedTip = header;
|
|
100
|
+
this.cachedTipTime = now;
|
|
101
|
+
return header;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the current chain tip hash
|
|
105
|
+
*/
|
|
106
|
+
async findChainTipHash() {
|
|
107
|
+
const tip = await this.findChainTipHeader();
|
|
108
|
+
return tip.hash;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get block header by height
|
|
112
|
+
*/
|
|
113
|
+
async findHeaderForHeight(height) {
|
|
114
|
+
try {
|
|
115
|
+
return await this.request(`/header/height/${height}`);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get block header by hash
|
|
123
|
+
*/
|
|
124
|
+
async findHeaderForBlockHash(hash) {
|
|
125
|
+
try {
|
|
126
|
+
return await this.request(`/header/hash/${hash}`);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** No-op: Remote server tracks the chain */
|
|
133
|
+
async addHeader(_header) { }
|
|
134
|
+
/** No-op: Client is always ready */
|
|
135
|
+
async startListening() { }
|
|
136
|
+
/** No-op: Resolves immediately */
|
|
137
|
+
async listening() { }
|
|
138
|
+
/** Always true for remote client */
|
|
139
|
+
async isListening() {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/** Always true for remote client */
|
|
143
|
+
async isSynchronized() {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
/** Not implemented for remote client */
|
|
147
|
+
async subscribeReorgs(_listener) {
|
|
148
|
+
throw new Error('Method not implemented.');
|
|
149
|
+
}
|
|
150
|
+
/** Unsubscribe from events */
|
|
151
|
+
async unsubscribe(_subscriptionId) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
/** Subscribe to new header events */
|
|
155
|
+
async subscribeHeaders(listener) {
|
|
156
|
+
this.subscribers.add(listener);
|
|
157
|
+
if (!this.eventSource) {
|
|
158
|
+
this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
|
|
159
|
+
this.eventSource.onmessage = (event) => {
|
|
160
|
+
try {
|
|
161
|
+
const header = JSON.parse(event.data);
|
|
162
|
+
for (const cb of this.subscribers) {
|
|
163
|
+
cb(header);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// Ignore parse errors
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
this.eventSource.onerror = () => {
|
|
171
|
+
this.eventSource?.close();
|
|
172
|
+
this.eventSource = null;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return 'subscription';
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get raw header bytes for one or more headers
|
|
179
|
+
*/
|
|
180
|
+
async getHeaderBytes(height, count = 1) {
|
|
181
|
+
const data = await this.requestBinary(`/headers?height=${height}&count=${count}`);
|
|
182
|
+
return Array.from(data);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Subscribe to new block notifications via SSE
|
|
186
|
+
* Returns unsubscribe function
|
|
187
|
+
*/
|
|
188
|
+
subscribe(callback) {
|
|
189
|
+
this.subscribers.add(callback);
|
|
190
|
+
if (!this.eventSource) {
|
|
191
|
+
this.eventSource = new EventSource(`${this.baseUrl}/tip/stream`);
|
|
192
|
+
this.eventSource.onmessage = (event) => {
|
|
193
|
+
try {
|
|
194
|
+
const header = JSON.parse(event.data);
|
|
195
|
+
for (const cb of this.subscribers) {
|
|
196
|
+
cb(header);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Ignore parse errors (e.g., keepalive messages)
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
this.eventSource.onerror = () => {
|
|
204
|
+
this.eventSource?.close();
|
|
205
|
+
this.eventSource = null;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return () => {
|
|
209
|
+
this.subscribers.delete(callback);
|
|
210
|
+
if (this.subscribers.size === 0 && this.eventSource) {
|
|
211
|
+
this.eventSource.close();
|
|
212
|
+
this.eventSource = null;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Close all connections
|
|
218
|
+
*/
|
|
219
|
+
close() {
|
|
220
|
+
if (this.eventSource) {
|
|
221
|
+
this.eventSource.close();
|
|
222
|
+
this.eventSource = null;
|
|
223
|
+
}
|
|
224
|
+
this.subscribers.clear();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=ChaintracksClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChaintracksClient.js","sourceRoot":"","sources":["../../src/services/ChaintracksClient.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;GAEG;AACH,SAAS,KAAK,CAAC,IAAgB;IAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAA;AACX,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IACxC,WAAW,GAAuB,IAAI,CAAA;IACtC,WAAW,GAAuC,IAAI,GAAG,EAAE,CAAA;IAEnE,kCAAkC;IAC1B,SAAS,GAAuB,IAAI,CAAA;IACpC,aAAa,GAAG,CAAC,CAAA;IACjB,MAAM,CAAU,gBAAgB,GAAG,MAAM,CAAA;IAEjD,YAAY,OAAe,EAAE,UAAyB,EAAE;QACvD,KAAK,CAAC,GAAG,OAAO,mBAAmB,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;IA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AAK,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;gBACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;YACxB,CAAC;QACF,CAAC,CAAA;IACF,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;YACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACxB,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Capability, SyncOutput } from '@1sat/types';
|
|
2
|
+
import { Beef, Transaction, type WalletLoggerInterface } from '@bsv/sdk';
|
|
3
|
+
import type { TableOutput, sdk as toolboxSdk } from '@bsv/wallet-toolbox-mobile';
|
|
4
|
+
import { ArcadeClient, BeefClient, Bsv21Client, ChaintracksClient, OrdfsClient, OverlayClient, OwnerClient, TxoClient } from './index';
|
|
5
|
+
type Chain = toolboxSdk.Chain;
|
|
6
|
+
type BlockHeader = toolboxSdk.BlockHeader;
|
|
7
|
+
type GetMerklePathResult = toolboxSdk.GetMerklePathResult;
|
|
8
|
+
type GetRawTxResult = toolboxSdk.GetRawTxResult;
|
|
9
|
+
type GetScriptHashHistoryResult = toolboxSdk.GetScriptHashHistoryResult;
|
|
10
|
+
type GetStatusForTxidsResult = toolboxSdk.GetStatusForTxidsResult;
|
|
11
|
+
type GetUtxoStatusOutputFormat = toolboxSdk.GetUtxoStatusOutputFormat;
|
|
12
|
+
type GetUtxoStatusResult = toolboxSdk.GetUtxoStatusResult;
|
|
13
|
+
type PostBeefResult = toolboxSdk.PostBeefResult;
|
|
14
|
+
type ServicesCallHistory = toolboxSdk.ServicesCallHistory;
|
|
15
|
+
type WalletServices = toolboxSdk.WalletServices;
|
|
16
|
+
export type { SyncOutput };
|
|
17
|
+
/**
|
|
18
|
+
* WalletServices implementation for 1Sat ecosystem.
|
|
19
|
+
*
|
|
20
|
+
* Provides access to 1Sat API clients and implements the WalletServices
|
|
21
|
+
* interface required by wallet-toolbox.
|
|
22
|
+
*
|
|
23
|
+
* API Routes:
|
|
24
|
+
* - /1sat/chaintracks/* - Block headers and chain tracking
|
|
25
|
+
* - /1sat/beef/* - Raw transactions and proofs
|
|
26
|
+
* - /1sat/arcade/* - Transaction broadcasting
|
|
27
|
+
* - /1sat/bsv21/* - BSV21 token data
|
|
28
|
+
* - /1sat/txo/* - Transaction outputs
|
|
29
|
+
* - /1sat/owner/* - Address queries and sync
|
|
30
|
+
* - /1sat/ordfs/* - Content/inscription serving
|
|
31
|
+
* - /overlay/* - Overlay services (topic managers, lookups)
|
|
32
|
+
*/
|
|
33
|
+
export declare class OneSatServices implements WalletServices {
|
|
34
|
+
chain: Chain;
|
|
35
|
+
readonly baseUrl: string;
|
|
36
|
+
readonly chaintracks: ChaintracksClient;
|
|
37
|
+
readonly beef: BeefClient;
|
|
38
|
+
readonly arcade: ArcadeClient;
|
|
39
|
+
readonly txo: TxoClient;
|
|
40
|
+
readonly owner: OwnerClient;
|
|
41
|
+
readonly ordfs: OrdfsClient;
|
|
42
|
+
readonly bsv21: Bsv21Client;
|
|
43
|
+
readonly overlay: OverlayClient;
|
|
44
|
+
private fallbackServices?;
|
|
45
|
+
/**
|
|
46
|
+
* URL for wallet storage sync endpoint (BRC-100 JSON-RPC).
|
|
47
|
+
* Used by StorageClient for remote wallet backup/sync.
|
|
48
|
+
*/
|
|
49
|
+
get storageUrl(): string;
|
|
50
|
+
constructor(chain: Chain, baseUrl?: string, fallbackServices?: WalletServices);
|
|
51
|
+
/**
|
|
52
|
+
* Get list of enabled capabilities from the server
|
|
53
|
+
*/
|
|
54
|
+
getCapabilities(): Promise<Capability[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Close all client connections
|
|
57
|
+
*/
|
|
58
|
+
close(): void;
|
|
59
|
+
getRawTx(txid: string, _useNext?: boolean): Promise<GetRawTxResult>;
|
|
60
|
+
getChainTracker(): Promise<ChaintracksClient>;
|
|
61
|
+
getHeaderForHeight(height: number): Promise<number[]>;
|
|
62
|
+
getHeight(): Promise<number>;
|
|
63
|
+
getMerklePath(txid: string, _useNext?: boolean): Promise<GetMerklePathResult>;
|
|
64
|
+
postBeef(beef: Beef, txids: string[], _logger?: WalletLoggerInterface): Promise<PostBeefResult[]>;
|
|
65
|
+
getBeefForTxid(txid: string): Promise<Beef>;
|
|
66
|
+
hashOutputScript(script: string): string;
|
|
67
|
+
getServicesCallHistory(_reset?: boolean): ServicesCallHistory;
|
|
68
|
+
getBsvExchangeRate(): Promise<number>;
|
|
69
|
+
getFiatExchangeRate(currency: 'USD' | 'GBP' | 'EUR', base?: 'USD' | 'GBP' | 'EUR'): Promise<number>;
|
|
70
|
+
getStatusForTxids(txids: string[], _useNext?: boolean): Promise<GetStatusForTxidsResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Helper to get tx status from Beef storage (fallback when Arcade doesn't know the tx)
|
|
73
|
+
*/
|
|
74
|
+
private getStatusFromBeef;
|
|
75
|
+
isUtxo(output: TableOutput): Promise<boolean>;
|
|
76
|
+
getUtxoStatus(_output: string, _outputFormat?: GetUtxoStatusOutputFormat, outpoint?: string, _useNext?: boolean): Promise<GetUtxoStatusResult>;
|
|
77
|
+
getScriptHashHistory(hash: string, useNext?: boolean, logger?: WalletLoggerInterface): Promise<GetScriptHashHistoryResult>;
|
|
78
|
+
hashToHeader(hash: string): Promise<BlockHeader>;
|
|
79
|
+
nLockTimeIsFinal(txOrLockTime: string | number[] | Transaction | number): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=OneSatServices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneSatServices.d.ts","sourceRoot":"","sources":["../../src/services/OneSatServices.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EA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