@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.
Files changed (69) hide show
  1. package/dist/errors.d.ts +8 -0
  2. package/dist/errors.d.ts.map +1 -0
  3. package/dist/errors.js +12 -0
  4. package/dist/errors.js.map +1 -0
  5. package/dist/index.d.ts +3 -12
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -16
  8. package/dist/index.js.map +1 -1
  9. package/dist/services/ArcadeClient.d.ts +46 -0
  10. package/dist/services/ArcadeClient.d.ts.map +1 -0
  11. package/dist/services/ArcadeClient.js +108 -0
  12. package/dist/services/ArcadeClient.js.map +1 -0
  13. package/dist/services/BaseClient.d.ts +33 -0
  14. package/dist/services/BaseClient.d.ts.map +1 -0
  15. package/dist/services/BaseClient.js +126 -0
  16. package/dist/services/BaseClient.js.map +1 -0
  17. package/dist/services/BeefClient.d.ts +27 -0
  18. package/dist/services/BeefClient.d.ts.map +1 -0
  19. package/dist/services/BeefClient.js +34 -0
  20. package/dist/services/BeefClient.js.map +1 -0
  21. package/dist/services/Bsv21Client.d.ts +110 -0
  22. package/dist/services/Bsv21Client.d.ts.map +1 -0
  23. package/dist/services/Bsv21Client.js +155 -0
  24. package/dist/services/Bsv21Client.js.map +1 -0
  25. package/dist/services/ChaintracksClient.d.ts +105 -0
  26. package/dist/services/ChaintracksClient.d.ts.map +1 -0
  27. package/dist/services/ChaintracksClient.js +227 -0
  28. package/dist/services/ChaintracksClient.js.map +1 -0
  29. package/dist/services/OneSatServices.d.ts +81 -0
  30. package/dist/services/OneSatServices.d.ts.map +1 -0
  31. package/dist/services/OneSatServices.js +401 -0
  32. package/dist/services/OneSatServices.js.map +1 -0
  33. package/dist/services/OrdfsClient.d.ts +48 -0
  34. package/dist/services/OrdfsClient.d.ts.map +1 -0
  35. package/dist/services/OrdfsClient.js +124 -0
  36. package/dist/services/OrdfsClient.js.map +1 -0
  37. package/dist/services/OverlayClient.d.ts +50 -0
  38. package/dist/services/OverlayClient.d.ts.map +1 -0
  39. package/dist/services/OverlayClient.js +48 -0
  40. package/dist/services/OverlayClient.js.map +1 -0
  41. package/dist/services/OwnerClient.d.ts +84 -0
  42. package/dist/services/OwnerClient.d.ts.map +1 -0
  43. package/dist/services/OwnerClient.js +241 -0
  44. package/dist/services/OwnerClient.js.map +1 -0
  45. package/dist/services/TxoClient.d.ts +42 -0
  46. package/dist/services/TxoClient.d.ts.map +1 -0
  47. package/dist/services/TxoClient.js +95 -0
  48. package/dist/services/TxoClient.js.map +1 -0
  49. package/dist/services/index.d.ts +11 -0
  50. package/dist/services/index.d.ts.map +1 -0
  51. package/dist/services/index.js +11 -0
  52. package/dist/services/index.js.map +1 -0
  53. package/package.json +5 -6
  54. package/dist/broadcast/index.d.ts +0 -41
  55. package/dist/broadcast/index.d.ts.map +0 -1
  56. package/dist/broadcast/index.js +0 -78
  57. package/dist/broadcast/index.js.map +0 -1
  58. package/dist/http/index.d.ts +0 -32
  59. package/dist/http/index.d.ts.map +0 -1
  60. package/dist/http/index.js +0 -63
  61. package/dist/http/index.js.map +0 -1
  62. package/dist/indexer/index.d.ts +0 -65
  63. package/dist/indexer/index.d.ts.map +0 -1
  64. package/dist/indexer/index.js +0 -202
  65. package/dist/indexer/index.js.map +0 -1
  66. package/dist/input.d.ts +0 -30
  67. package/dist/input.d.ts.map +0 -1
  68. package/dist/input.js +0 -46
  69. package/dist/input.js.map +0 -1
@@ -1,78 +0,0 @@
1
- /**
2
- * Transaction broadcaster for 1Sat API
3
- *
4
- * Broadcasts transactions to the BSV network via the 1Sat API
5
- */
6
- import { API_HOST } from '@1sat/constants';
7
- import { Utils } from '@bsv/sdk';
8
- import { createHttpClient } from '../http';
9
- const { toBase64 } = Utils;
10
- /**
11
- * 1Sat API transaction broadcaster
12
- *
13
- * Implements the @bsv/sdk Broadcaster interface for compatibility
14
- * with the Transaction class's broadcast() method.
15
- */
16
- export class OneSatBroadcaster {
17
- url;
18
- httpClient;
19
- constructor(config = {}) {
20
- const { apiHost = API_HOST, httpClient } = config;
21
- this.url = `${apiHost}/tx`;
22
- this.httpClient = httpClient ?? createHttpClient();
23
- }
24
- /**
25
- * Broadcast a transaction to the network
26
- *
27
- * @param tx - Transaction to broadcast
28
- * @returns Broadcast result with txid on success
29
- */
30
- async broadcast(tx) {
31
- const rawtx = toBase64(tx.toBinary());
32
- try {
33
- const response = await this.httpClient.request(this.url, {
34
- method: 'POST',
35
- headers: {
36
- 'Content-Type': 'application/json',
37
- Accept: 'application/json',
38
- },
39
- data: { rawtx },
40
- });
41
- if (response.ok) {
42
- const txid = typeof response.data === 'string'
43
- ? response.data
44
- : tx.id('hex');
45
- return {
46
- status: 'success',
47
- txid,
48
- message: 'broadcast successful',
49
- };
50
- }
51
- const errorMsg = typeof response.data === 'object' && response.data?.message
52
- ? response.data.message
53
- : 'Unknown error';
54
- return {
55
- status: 'error',
56
- code: response.status.toString(),
57
- description: errorMsg,
58
- };
59
- }
60
- catch (error) {
61
- return {
62
- status: 'error',
63
- code: '500',
64
- description: error instanceof Error ? error.message : 'Internal Server Error',
65
- };
66
- }
67
- }
68
- }
69
- /**
70
- * Create a 1Sat broadcaster instance
71
- *
72
- * @param config - Optional configuration
73
- * @returns Broadcaster instance
74
- */
75
- export function createBroadcaster(config) {
76
- return new OneSatBroadcaster(config);
77
- }
78
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/broadcast/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAQ1C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;AAY1B;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACZ,GA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E;gBAChC,WAAW,EAAE,QAAQ;aACrB,CAAA;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO;gBACN,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,KAAK;gBACX,WAAW,EACV,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;aACjE,CAAA;QACF,CAAC;IACF,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA0B;IAC3D,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC"}
@@ -1,32 +0,0 @@
1
- /**
2
- * HTTP client abstraction for 1Sat API
3
- *
4
- * Provides a universal HTTP client that works in both browser and Node.js
5
- */
6
- import type { HttpClient, HttpClientRequestOptions, HttpClientResponse } from '@bsv/sdk';
7
- /**
8
- * Fetch function interface
9
- */
10
- export type FetchFn = (url: string, options: FetchOptions) => Promise<Response>;
11
- /**
12
- * Fetch options limited to what we need
13
- */
14
- export interface FetchOptions {
15
- method?: string;
16
- headers?: Record<string, string>;
17
- body?: string | null;
18
- }
19
- /**
20
- * HTTP client using fetch API (browser/modern Node.js)
21
- */
22
- export declare class FetchHttpClient implements HttpClient {
23
- private readonly fetch;
24
- constructor(fetch: FetchFn);
25
- request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>;
26
- }
27
- /**
28
- * Create a default HTTP client for the current environment
29
- */
30
- export declare function createHttpClient(): HttpClient;
31
- export type { HttpClient, HttpClientRequestOptions, HttpClientResponse };
32
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACX,UAAU,EACV,wBAAwB,EACxB,kBAAkB,EAClB,MAAM,UAAU,CAAA;AAGjB;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE/E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,UAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,OAAO;IAErC,OAAO,CAAC,CAAC,EACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAoBjC;AAWD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CAkB7C;AAGD,YAAY,EAAE,UAAU,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,CAAA"}
@@ -1,63 +0,0 @@
1
- /**
2
- * HTTP client abstraction for 1Sat API
3
- *
4
- * Provides a universal HTTP client that works in both browser and Node.js
5
- */
6
- import { NodejsHttpClient } from '@bsv/sdk';
7
- /**
8
- * HTTP client using fetch API (browser/modern Node.js)
9
- */
10
- export class FetchHttpClient {
11
- fetch;
12
- constructor(fetch) {
13
- this.fetch = fetch;
14
- }
15
- async request(url, options) {
16
- const fetchOptions = {
17
- method: options.method,
18
- headers: options.headers,
19
- body: options.data ? JSON.stringify(options.data) : null,
20
- };
21
- const res = await this.fetch(url, fetchOptions);
22
- const mediaType = res.headers.get('Content-Type');
23
- const data = mediaType?.startsWith('application/json')
24
- ? await res.json()
25
- : await res.text();
26
- return {
27
- ok: res.ok,
28
- status: res.status,
29
- statusText: res.statusText,
30
- data: data,
31
- };
32
- }
33
- }
34
- /**
35
- * No-op HTTP client that throws (for unsupported environments)
36
- */
37
- const noHttpClient = {
38
- async request() {
39
- throw new Error('No method available to perform HTTP request');
40
- },
41
- };
42
- /**
43
- * Create a default HTTP client for the current environment
44
- */
45
- export function createHttpClient() {
46
- // Browser environment
47
- if (typeof globalThis.fetch === 'function') {
48
- return new FetchHttpClient(globalThis.fetch.bind(globalThis));
49
- }
50
- // Node.js environment
51
- if (typeof require !== 'undefined') {
52
- try {
53
- // biome-ignore lint/security/noGlobalEval: Need dynamic require for Node.js
54
- const https = eval('require')('node:https');
55
- return new NodejsHttpClient(https);
56
- }
57
- catch {
58
- return noHttpClient;
59
- }
60
- }
61
- return noHttpClient;
62
- }
63
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAgB3C;;GAEG;AACH,MAAM,OAAO,eAAe;IACE;IAA7B,YAA6B,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAE/C,KAAK,CAAC,OAAO,CACZ,GAAW,EACX,OAAiC;QAEjC,MAAM,YAAY,GAAiB;YAClC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;SACxD,CAAA;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAA;QAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QACjD,MAAM,IAAI,GAAG,SAAS,EAAE,UAAU,CAAC,kBAAkB,CAAC;YACrD,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE;YAClB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAEnB,OAAO;YACN,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,IAAI,EAAE,IAAS;SACf,CAAA;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,YAAY,GAAe;IAChC,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAC/D,CAAC;CACD,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC/B,sBAAsB;IACtB,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QAC5C,OAAO,IAAI,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,sBAAsB;IACtB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACpC,IAAI,CAAC;YACJ,4EAA4E;YAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAA;YAC3C,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAA;QACnC,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,YAAY,CAAA;QACpB,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAA;AACpB,CAAC"}
@@ -1,65 +0,0 @@
1
- /**
2
- * 1Sat Indexer API client
3
- *
4
- * Provides methods for fetching UTXOs from the 1Sat API
5
- */
6
- import type { NftUtxo, TokenSelectionOptions, TokenSelectionResult, TokenUtxo, Utxo } from '@1sat/types';
7
- import { TokenType } from '@1sat/types';
8
- export type ScriptEncoding = 'hex' | 'base64' | 'asm';
9
- export interface FetchOptions {
10
- /** API host URL (defaults to mainnet) */
11
- apiHost?: string;
12
- /** Script encoding format */
13
- scriptEncoding?: ScriptEncoding;
14
- }
15
- export interface FetchNftOptions extends FetchOptions {
16
- /** Filter by collection ID */
17
- collectionId?: string;
18
- /** Number of UTXOs to fetch */
19
- limit?: number;
20
- /** Offset for pagination */
21
- offset?: number;
22
- }
23
- export interface FetchTokenOptions extends FetchOptions {
24
- /** Number of UTXOs to fetch */
25
- limit?: number;
26
- /** Offset for pagination */
27
- offset?: number;
28
- }
29
- /**
30
- * Fetch payment UTXOs for an address
31
- *
32
- * @param address - Address to fetch UTXOs for
33
- * @param options - Fetch options
34
- * @returns Array of payment UTXOs (excludes 1-sat and locked outputs)
35
- */
36
- export declare function fetchPayUtxos(address: string, options?: FetchOptions): Promise<Utxo[]>;
37
- /**
38
- * Fetch NFT UTXOs for an address
39
- *
40
- * @param address - Address to fetch UTXOs for
41
- * @param options - Fetch options including optional collection filter
42
- * @returns Array of NFT UTXOs
43
- */
44
- export declare function fetchNftUtxos(address: string, options?: FetchNftOptions): Promise<NftUtxo[]>;
45
- /**
46
- * Fetch token UTXOs for an address
47
- *
48
- * @param protocol - Token protocol (BSV20 or BSV21)
49
- * @param tokenId - Token ID (tick for BSV20, origin for BSV21)
50
- * @param address - Address to fetch UTXOs for
51
- * @param options - Fetch options
52
- * @returns Array of token UTXOs
53
- */
54
- export declare function fetchTokenUtxos(protocol: TokenType, tokenId: string, address: string, options?: FetchTokenOptions): Promise<TokenUtxo[]>;
55
- /**
56
- * Select token UTXOs to satisfy a required amount
57
- *
58
- * @param tokenUtxos - Available token UTXOs
59
- * @param requiredTokens - Required amount in display format
60
- * @param decimals - Token decimal places
61
- * @param options - Selection strategy options
62
- * @returns Selected UTXOs and total selected amount
63
- */
64
- export declare function selectTokenUtxos(tokenUtxos: TokenUtxo[], requiredTokens: number, decimals: number, options?: TokenSelectionOptions): TokenSelectionResult;
65
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/indexer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACX,OAAO,EAC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AChB,OAAO,GAAE,qBAA0B,GACjC,oBAAoB,CA4DtB"}
@@ -1,202 +0,0 @@
1
- /**
2
- * 1Sat Indexer API client
3
- *
4
- * Provides methods for fetching UTXOs from the 1Sat API
5
- */
6
- import { API_HOST } from '@1sat/constants';
7
- import { TokenSelectionStrategy, TokenType } from '@1sat/types';
8
- import { P2PKH, Script, Utils } from '@bsv/sdk';
9
- import { toToken } from 'satoshi-token';
10
- const { toBase64, toHex, fromBase58Check, toArray } = Utils;
11
- /**
12
- * Check if a UTXO has a lock (time-locked output)
13
- */
14
- function isLocked(utxo) {
15
- const data = utxo.data;
16
- return !!data?.lock;
17
- }
18
- /**
19
- * Convert script bytes to specified encoding
20
- */
21
- function encodeScript(scriptBytes, encoding) {
22
- switch (encoding) {
23
- case 'hex':
24
- return toHex(scriptBytes);
25
- case 'base64':
26
- return toBase64(scriptBytes);
27
- case 'asm':
28
- return Script.fromBinary(scriptBytes).toASM();
29
- }
30
- }
31
- /**
32
- * Fetch payment UTXOs for an address
33
- *
34
- * @param address - Address to fetch UTXOs for
35
- * @param options - Fetch options
36
- * @returns Array of payment UTXOs (excludes 1-sat and locked outputs)
37
- */
38
- export async function fetchPayUtxos(address, options = {}) {
39
- const { apiHost = API_HOST, scriptEncoding = 'base64' } = options;
40
- const url = `${apiHost}/txos/address/${address}/unspent?bsv20=false`;
41
- const res = await fetch(url);
42
- if (!res.ok) {
43
- throw new Error(`Error fetching pay UTXOs: ${res.statusText}`);
44
- }
45
- const rawUtxos = (await res.json());
46
- // Filter out 1-sat outputs and locked outputs
47
- const filtered = rawUtxos.filter((u) => u.satoshis !== 1 && !isLocked(u));
48
- // Get pubkey hash from address and create P2PKH script
49
- const { data: pubKeyHash } = fromBase58Check(address);
50
- const p2pkhScript = new P2PKH().lock(pubKeyHash);
51
- const scriptBytes = p2pkhScript.toBinary();
52
- return filtered.map((utxo) => ({
53
- txid: utxo.txid,
54
- vout: utxo.vout,
55
- satoshis: utxo.satoshis,
56
- script: encodeScript(scriptBytes, scriptEncoding),
57
- }));
58
- }
59
- /**
60
- * Fetch NFT UTXOs for an address
61
- *
62
- * @param address - Address to fetch UTXOs for
63
- * @param options - Fetch options including optional collection filter
64
- * @returns Array of NFT UTXOs
65
- */
66
- export async function fetchNftUtxos(address, options = {}) {
67
- const { apiHost = API_HOST, scriptEncoding = 'base64', collectionId, limit = 10, offset = 0, } = options;
68
- let url = `${apiHost}/txos/address/${address}/unspent?limit=${limit}&offset=${offset}&`;
69
- // Add collection filter if specified
70
- if (collectionId) {
71
- const query = { map: { subTypeData: { collectionId } } };
72
- const queryJson = JSON.stringify(query);
73
- const queryBytes = toArray(queryJson, 'utf8');
74
- url += `q=${toBase64(queryBytes)}`;
75
- }
76
- const res = await fetch(url);
77
- if (!res.ok) {
78
- throw new Error(`Error fetching NFT UTXOs: ${res.statusText}`);
79
- }
80
- const rawUtxos = (await res.json());
81
- // Filter to 1-sat non-listed outputs
82
- const filtered = rawUtxos.filter((u) => u.satoshis === 1 && !u.data?.list);
83
- if (filtered.length === 0) {
84
- return [];
85
- }
86
- // Fetch scripts for these outpoints
87
- const outpoints = filtered.map((u) => `${u.txid}_${u.vout}`);
88
- const scriptRes = await fetch(`${apiHost}/txos/outpoints?script=true`, {
89
- method: 'POST',
90
- headers: { 'Content-Type': 'application/json' },
91
- body: JSON.stringify(outpoints),
92
- });
93
- if (!scriptRes.ok) {
94
- throw new Error(`Error fetching NFT scripts: ${scriptRes.statusText}`);
95
- }
96
- const nftsWithScripts = (await scriptRes.json());
97
- return nftsWithScripts.map((utxo) => {
98
- // Script from API is base64, convert if needed
99
- const scriptBytes = toArray(utxo.script, 'base64');
100
- const script = encodeScript(scriptBytes, scriptEncoding);
101
- const nftUtxo = {
102
- txid: utxo.txid,
103
- vout: utxo.vout,
104
- satoshis: 1,
105
- script,
106
- origin: utxo.origin.outpoint,
107
- contentType: '', // Would need additional API call for content type
108
- };
109
- if (collectionId) {
110
- nftUtxo.collectionId = collectionId;
111
- }
112
- return nftUtxo;
113
- });
114
- }
115
- /**
116
- * Fetch token UTXOs for an address
117
- *
118
- * @param protocol - Token protocol (BSV20 or BSV21)
119
- * @param tokenId - Token ID (tick for BSV20, origin for BSV21)
120
- * @param address - Address to fetch UTXOs for
121
- * @param options - Fetch options
122
- * @returns Array of token UTXOs
123
- */
124
- export async function fetchTokenUtxos(protocol, tokenId, address, options = {}) {
125
- const { apiHost = API_HOST, limit = 10, offset = 0 } = options;
126
- const idParam = protocol === TokenType.BSV20 ? 'tick' : 'id';
127
- const url = `${apiHost}/bsv20/${address}/${idParam}/${tokenId}?bsv20=true&listing=false&limit=${limit}&offset=${offset}`;
128
- const res = await fetch(url);
129
- if (!res.ok) {
130
- throw new Error(`Error fetching ${protocol} UTXOs: ${res.statusText}`);
131
- }
132
- const rawUtxos = (await res.json());
133
- return rawUtxos.map((utxo) => ({
134
- txid: utxo.txid,
135
- vout: utxo.vout,
136
- satoshis: 1,
137
- script: utxo.script,
138
- amt: utxo.amt,
139
- id: tokenId,
140
- }));
141
- }
142
- /**
143
- * Select token UTXOs to satisfy a required amount
144
- *
145
- * @param tokenUtxos - Available token UTXOs
146
- * @param requiredTokens - Required amount in display format
147
- * @param decimals - Token decimal places
148
- * @param options - Selection strategy options
149
- * @returns Selected UTXOs and total selected amount
150
- */
151
- export function selectTokenUtxos(tokenUtxos, requiredTokens, decimals, options = {}) {
152
- const { inputStrategy = TokenSelectionStrategy.RetainOrder, outputStrategy = TokenSelectionStrategy.RetainOrder, } = options;
153
- // Sort UTXOs based on input strategy
154
- const sortedUtxos = [...tokenUtxos].sort((a, b) => {
155
- if (inputStrategy === TokenSelectionStrategy.RetainOrder)
156
- return 0;
157
- const amtA = BigInt(a.amt);
158
- const amtB = BigInt(b.amt);
159
- switch (inputStrategy) {
160
- case TokenSelectionStrategy.SmallestFirst:
161
- return Number(amtA - amtB);
162
- case TokenSelectionStrategy.LargestFirst:
163
- return Number(amtB - amtA);
164
- case TokenSelectionStrategy.Random:
165
- return Math.random() - 0.5;
166
- default:
167
- return 0;
168
- }
169
- });
170
- let totalSelected = 0;
171
- const selectedUtxos = [];
172
- for (const utxo of sortedUtxos) {
173
- selectedUtxos.push(utxo);
174
- totalSelected += toToken(utxo.amt, decimals);
175
- if (totalSelected >= requiredTokens && requiredTokens > 0) {
176
- break;
177
- }
178
- }
179
- // Sort selected UTXOs based on output strategy
180
- if (outputStrategy !== TokenSelectionStrategy.RetainOrder) {
181
- selectedUtxos.sort((a, b) => {
182
- const amtA = BigInt(a.amt);
183
- const amtB = BigInt(b.amt);
184
- switch (outputStrategy) {
185
- case TokenSelectionStrategy.SmallestFirst:
186
- return Number(amtA - amtB);
187
- case TokenSelectionStrategy.LargestFirst:
188
- return Number(amtB - amtA);
189
- case TokenSelectionStrategy.Random:
190
- return Math.random() - 0.5;
191
- default:
192
- return 0;
193
- }
194
- });
195
- }
196
- return {
197
- selectedUtxos,
198
- totalSelected,
199
- isEnough: totalSelected >= requiredTokens,
200
- };
201
- }
202
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAQ1C,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;AA2B3D;;GAEG;AACH,SAAS,QAAQ,CAAC,IAAU;IAC3B,MAAM,IAAI,GAAI,IAAiD,CAAC,IAAI,CAAA;IACpE,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAA;AACpB,CAAC;AAED;;GAEG;AACH,SAA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AI,cAAc,KAAK,sBAAsB,CAAC,WAAW,EAAE,CAAC;QAC3D,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;YAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;YAE1B,QAAQ,cAAc,EAAE,CAAC;gBACxB,KAAK,sBAAsB,CAAC,aAAa;oBACxC,OAAO,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;gBAC3B,KAAK,sBAAsB,CAAC,YAAY;oBACvC,OAAO,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;gBAC3B,KAAK,sBAAsB,CAAC,MAAM;oBACjC,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAA;gBAC3B;oBACC,OAAO,CAAC,CAAA;YACV,CAAC;QACF,CAAC,CAAC,CAAA;IACH,CAAC;IAED,OAAO;QACN,aAAa;QACb,aAAa;QACb,QAAQ,EAAE,aAAa,IAAI,cAAc;KACzC,CAAA;AACF,CAAC"}
package/dist/input.d.ts DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * UTXO to TransactionInput conversion utilities
3
- */
4
- import type { Utxo } from '@1sat/types';
5
- import { type Transaction, type TransactionInput, type UnlockingScript } from '@bsv/sdk';
6
- /**
7
- * Unlocking script template interface
8
- */
9
- export interface UnlockTemplate {
10
- sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
11
- estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
12
- }
13
- /**
14
- * Convert a UTXO with base64-encoded script to a TransactionInput
15
- *
16
- * @param utxo - UTXO with base64-encoded script
17
- * @param unlockTemplate - Optional unlocking script template. When omitted,
18
- * creates an input for external signing (signInputs: false mode)
19
- * @returns TransactionInput ready to add to a transaction
20
- */
21
- export declare function inputFromUtxo(utxo: Utxo, unlockTemplate?: UnlockTemplate): TransactionInput;
22
- /**
23
- * Convert multiple UTXOs to TransactionInputs
24
- *
25
- * @param utxos - Array of UTXOs with base64-encoded scripts
26
- * @param unlockTemplate - Optional unlocking script template
27
- * @returns Array of TransactionInputs
28
- */
29
- export declare function inputsFromUtxos(utxos: Utxo[], unlockTemplate?: UnlockTemplate): TransactionInput[];
30
- //# sourceMappingURL=input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAGpB,MAAM,UAAU,CAAA;AAOjB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;IACvE,cAAc,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACxE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,IAAI,EACV,cAAc,CAAC,EAAE,cAAc,GAC7B,gBAAgB,CAuBlB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,CAAC,EAAE,cAAc,GAC7B,gBAAgB,EAAE,CAEpB"}
package/dist/input.js DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * UTXO to TransactionInput conversion utilities
3
- */
4
- import { Utils, fromUtxo, } from '@bsv/sdk';
5
- const { toHex, toArray } = Utils;
6
- /** Standard P2PKH unlocking script size in bytes */
7
- const P2PKH_UNLOCK_SIZE = 107;
8
- /**
9
- * Convert a UTXO with base64-encoded script to a TransactionInput
10
- *
11
- * @param utxo - UTXO with base64-encoded script
12
- * @param unlockTemplate - Optional unlocking script template. When omitted,
13
- * creates an input for external signing (signInputs: false mode)
14
- * @returns TransactionInput ready to add to a transaction
15
- */
16
- export function inputFromUtxo(utxo, unlockTemplate) {
17
- // Convert script from base64 to hex for fromUtxo
18
- const scriptBytes = toArray(utxo.script, 'base64');
19
- const utxoHex = {
20
- ...utxo,
21
- script: toHex(scriptBytes),
22
- };
23
- if (unlockTemplate) {
24
- return fromUtxo(utxoHex, unlockTemplate);
25
- }
26
- // For signInputs: false mode - create input that supports fee estimation
27
- // but must be signed externally (e.g., by wallet)
28
- return fromUtxo(utxoHex, {
29
- estimateLength: async () => P2PKH_UNLOCK_SIZE,
30
- sign: async () => {
31
- throw new Error('Cannot sign input: transaction was built with signInputs: false. ' +
32
- 'This input must be signed externally (e.g., by a wallet).');
33
- },
34
- });
35
- }
36
- /**
37
- * Convert multiple UTXOs to TransactionInputs
38
- *
39
- * @param utxos - Array of UTXOs with base64-encoded scripts
40
- * @param unlockTemplate - Optional unlocking script template
41
- * @returns Array of TransactionInputs
42
- */
43
- export function inputsFromUtxos(utxos, unlockTemplate) {
44
- return utxos.map((utxo) => inputFromUtxo(utxo, unlockTemplate));
45
- }
46
- //# sourceMappingURL=input.js.map
package/dist/input.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAIN,KAAK,EACL,QAAQ,GACR,MAAM,UAAU,CAAA;AAEjB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;AAEhC,oDAAoD;AACpD,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAU7B;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC5B,IAAU,EACV,cAA+B;IAE/B,iDAAiD;IACjD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAClD,MAAM,OAAO,GAAG;QACf,GAAG,IAAI;QACP,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC;KAC1B,CAAA;IAED,IAAI,cAAc,EAAE,CAAC;QACpB,OAAO,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;IACzC,CAAC;IAED,yEAAyE;IACzE,kDAAkD;IAClD,OAAO,QAAQ,CAAC,OAAO,EAAE;QACxB,cAAc,EAAE,KAAK,IAAI,EAAE,CAAC,iBAAiB;QAC7C,IAAI,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,KAAK,CACd,mEAAmE;gBAClE,2DAA2D,CAC5D,CAAA;QACF,CAAC;KACD,CAAC,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC9B,KAAa,EACb,cAA+B;IAE/B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;AAChE,CAAC"}