otx-btc-wallet-connectors 0.1.0

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 (142) hide show
  1. package/README.md +554 -0
  2. package/dist/base-IAFq7sd8.d.mts +53 -0
  3. package/dist/base-IAFq7sd8.d.ts +53 -0
  4. package/dist/binance/index.d.mts +81 -0
  5. package/dist/binance/index.d.ts +81 -0
  6. package/dist/binance/index.js +13 -0
  7. package/dist/binance/index.js.map +1 -0
  8. package/dist/binance/index.mjs +4 -0
  9. package/dist/binance/index.mjs.map +1 -0
  10. package/dist/bitget/index.d.mts +84 -0
  11. package/dist/bitget/index.d.ts +84 -0
  12. package/dist/bitget/index.js +13 -0
  13. package/dist/bitget/index.js.map +1 -0
  14. package/dist/bitget/index.mjs +4 -0
  15. package/dist/bitget/index.mjs.map +1 -0
  16. package/dist/chunk-5Z5Q2Y75.mjs +91 -0
  17. package/dist/chunk-5Z5Q2Y75.mjs.map +1 -0
  18. package/dist/chunk-7KK2LZLZ.mjs +208 -0
  19. package/dist/chunk-7KK2LZLZ.mjs.map +1 -0
  20. package/dist/chunk-AW2JZIHR.mjs +753 -0
  21. package/dist/chunk-AW2JZIHR.mjs.map +1 -0
  22. package/dist/chunk-EIJOSZXZ.js +331 -0
  23. package/dist/chunk-EIJOSZXZ.js.map +1 -0
  24. package/dist/chunk-EQHR7P7G.js +541 -0
  25. package/dist/chunk-EQHR7P7G.js.map +1 -0
  26. package/dist/chunk-EWRXLZO4.mjs +539 -0
  27. package/dist/chunk-EWRXLZO4.mjs.map +1 -0
  28. package/dist/chunk-FISNQZZ7.js +802 -0
  29. package/dist/chunk-FISNQZZ7.js.map +1 -0
  30. package/dist/chunk-HL4WDMGS.js +200 -0
  31. package/dist/chunk-HL4WDMGS.js.map +1 -0
  32. package/dist/chunk-IPYWR76I.js +314 -0
  33. package/dist/chunk-IPYWR76I.js.map +1 -0
  34. package/dist/chunk-JYYNWR5G.js +142 -0
  35. package/dist/chunk-JYYNWR5G.js.map +1 -0
  36. package/dist/chunk-LNKTYZJM.js +701 -0
  37. package/dist/chunk-LNKTYZJM.js.map +1 -0
  38. package/dist/chunk-LVZMONQL.mjs +699 -0
  39. package/dist/chunk-LVZMONQL.mjs.map +1 -0
  40. package/dist/chunk-MFXLQWOE.js +93 -0
  41. package/dist/chunk-MFXLQWOE.js.map +1 -0
  42. package/dist/chunk-NBIA4TTE.mjs +204 -0
  43. package/dist/chunk-NBIA4TTE.mjs.map +1 -0
  44. package/dist/chunk-O4DD2XJ2.js +206 -0
  45. package/dist/chunk-O4DD2XJ2.js.map +1 -0
  46. package/dist/chunk-P7HVBU2B.mjs +140 -0
  47. package/dist/chunk-P7HVBU2B.mjs.map +1 -0
  48. package/dist/chunk-Q7QVQYEB.js +210 -0
  49. package/dist/chunk-Q7QVQYEB.js.map +1 -0
  50. package/dist/chunk-RLZEG6KL.mjs +329 -0
  51. package/dist/chunk-RLZEG6KL.mjs.map +1 -0
  52. package/dist/chunk-SYLDBJ75.mjs +246 -0
  53. package/dist/chunk-SYLDBJ75.mjs.map +1 -0
  54. package/dist/chunk-TTEUU3CI.mjs +198 -0
  55. package/dist/chunk-TTEUU3CI.mjs.map +1 -0
  56. package/dist/chunk-V66BXDTR.mjs +292 -0
  57. package/dist/chunk-V66BXDTR.mjs.map +1 -0
  58. package/dist/chunk-X77ZT4OI.js +268 -0
  59. package/dist/chunk-X77ZT4OI.js.map +1 -0
  60. package/dist/imtoken/index.d.mts +116 -0
  61. package/dist/imtoken/index.d.ts +116 -0
  62. package/dist/imtoken/index.js +14 -0
  63. package/dist/imtoken/index.js.map +1 -0
  64. package/dist/imtoken/index.mjs +5 -0
  65. package/dist/imtoken/index.mjs.map +1 -0
  66. package/dist/index.d.mts +14 -0
  67. package/dist/index.d.ts +14 -0
  68. package/dist/index.js +170 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/index.mjs +13 -0
  71. package/dist/index.mjs.map +1 -0
  72. package/dist/ledger/index.d.mts +290 -0
  73. package/dist/ledger/index.d.ts +290 -0
  74. package/dist/ledger/index.js +14 -0
  75. package/dist/ledger/index.js.map +1 -0
  76. package/dist/ledger/index.mjs +5 -0
  77. package/dist/ledger/index.mjs.map +1 -0
  78. package/dist/okx/index.d.mts +88 -0
  79. package/dist/okx/index.d.ts +88 -0
  80. package/dist/okx/index.js +13 -0
  81. package/dist/okx/index.js.map +1 -0
  82. package/dist/okx/index.mjs +4 -0
  83. package/dist/okx/index.mjs.map +1 -0
  84. package/dist/phantom/index.d.mts +96 -0
  85. package/dist/phantom/index.d.ts +96 -0
  86. package/dist/phantom/index.js +14 -0
  87. package/dist/phantom/index.js.map +1 -0
  88. package/dist/phantom/index.mjs +5 -0
  89. package/dist/phantom/index.mjs.map +1 -0
  90. package/dist/psbt-builder-CFOs69Z5.d.mts +131 -0
  91. package/dist/psbt-builder-CFOs69Z5.d.ts +131 -0
  92. package/dist/trezor/index.d.mts +155 -0
  93. package/dist/trezor/index.d.ts +155 -0
  94. package/dist/trezor/index.js +14 -0
  95. package/dist/trezor/index.js.map +1 -0
  96. package/dist/trezor/index.mjs +5 -0
  97. package/dist/trezor/index.mjs.map +1 -0
  98. package/dist/unisat/index.d.mts +75 -0
  99. package/dist/unisat/index.d.ts +75 -0
  100. package/dist/unisat/index.js +13 -0
  101. package/dist/unisat/index.js.map +1 -0
  102. package/dist/unisat/index.mjs +4 -0
  103. package/dist/unisat/index.mjs.map +1 -0
  104. package/dist/utils/index.d.mts +398 -0
  105. package/dist/utils/index.d.ts +398 -0
  106. package/dist/utils/index.js +120 -0
  107. package/dist/utils/index.js.map +1 -0
  108. package/dist/utils/index.mjs +3 -0
  109. package/dist/utils/index.mjs.map +1 -0
  110. package/dist/xverse/index.d.mts +79 -0
  111. package/dist/xverse/index.d.ts +79 -0
  112. package/dist/xverse/index.js +13 -0
  113. package/dist/xverse/index.js.map +1 -0
  114. package/dist/xverse/index.mjs +4 -0
  115. package/dist/xverse/index.mjs.map +1 -0
  116. package/package.json +108 -0
  117. package/src/base.ts +132 -0
  118. package/src/binance/BinanceConnector.ts +307 -0
  119. package/src/binance/index.ts +1 -0
  120. package/src/bitget/BitgetConnector.ts +301 -0
  121. package/src/bitget/index.ts +1 -0
  122. package/src/imtoken/ImTokenConnector.ts +420 -0
  123. package/src/imtoken/index.ts +2 -0
  124. package/src/index.ts +78 -0
  125. package/src/ledger/LedgerConnector.ts +1019 -0
  126. package/src/ledger/index.ts +8 -0
  127. package/src/okx/OKXConnector.ts +230 -0
  128. package/src/okx/index.ts +1 -0
  129. package/src/phantom/PhantomConnector.ts +381 -0
  130. package/src/phantom/index.ts +2 -0
  131. package/src/trezor/TrezorConnector.ts +824 -0
  132. package/src/trezor/index.ts +6 -0
  133. package/src/unisat/UnisatConnector.ts +312 -0
  134. package/src/unisat/index.ts +1 -0
  135. package/src/utils/blockstream.ts +230 -0
  136. package/src/utils/btc-service.ts +364 -0
  137. package/src/utils/index.ts +56 -0
  138. package/src/utils/mempool.ts +232 -0
  139. package/src/utils/psbt-builder.ts +492 -0
  140. package/src/utils/types.ts +183 -0
  141. package/src/xverse/XverseConnector.ts +479 -0
  142. package/src/xverse/index.ts +1 -0
@@ -0,0 +1,290 @@
1
+ import { BitcoinNetwork, WalletAccount, SignPsbtOptions } from 'otx-btc-wallet-core';
2
+ import { B as BaseConnector } from '../base-IAFq7sd8.mjs';
3
+
4
+ /**
5
+ * Ledger address type configuration
6
+ */
7
+ type LedgerAddressType = 'legacy' | 'nested-segwit' | 'segwit' | 'taproot';
8
+ /**
9
+ * Ledger connector options
10
+ */
11
+ interface LedgerConnectorOptions {
12
+ /** Address type for derivation (default: 'segwit') */
13
+ addressType?: LedgerAddressType;
14
+ /** Account index (default: 0) */
15
+ accountIndex?: number;
16
+ /** Address index (default: 0) */
17
+ addressIndex?: number;
18
+ }
19
+ interface LedgerBtcApp {
20
+ getWalletPublicKey(path: string, opts?: {
21
+ verify?: boolean;
22
+ format?: 'legacy' | 'p2sh' | 'bech32' | 'bech32m';
23
+ }): Promise<{
24
+ publicKey: string;
25
+ bitcoinAddress: string;
26
+ chainCode: string;
27
+ }>;
28
+ getWalletXpub(arg: {
29
+ path: string;
30
+ xpubVersion: number;
31
+ }): Promise<string>;
32
+ signMessage(path: string, messageHex: string): Promise<{
33
+ v: number;
34
+ r: string;
35
+ s: string;
36
+ }>;
37
+ splitTransaction(transactionHex: string, isSegwitSupported?: boolean | null, hasExtraData?: boolean, additionals?: string[]): LedgerTransaction;
38
+ createPaymentTransaction(arg: {
39
+ inputs: Array<[LedgerTransaction, number, string | null | undefined, number?]>;
40
+ associatedKeysets: string[];
41
+ changePath?: string;
42
+ outputScriptHex: string;
43
+ lockTime?: number;
44
+ sigHashType?: number;
45
+ segwit?: boolean;
46
+ additionals?: string[];
47
+ expiryHeight?: Buffer;
48
+ useTrustedInputForSegwit?: boolean;
49
+ }): Promise<string>;
50
+ serializeTransactionOutputs(tx: LedgerTransaction): Buffer;
51
+ }
52
+ /**
53
+ * Ledger Transaction type (returned by splitTransaction)
54
+ */
55
+ interface LedgerTransaction {
56
+ version: Buffer;
57
+ inputs: Array<{
58
+ prevout: Buffer;
59
+ script: Buffer;
60
+ sequence: Buffer;
61
+ }>;
62
+ outputs?: Array<{
63
+ amount: Buffer;
64
+ script: Buffer;
65
+ }>;
66
+ locktime?: Buffer;
67
+ witness?: Buffer;
68
+ }
69
+ /**
70
+ * UTXO input for createPaymentTransaction
71
+ */
72
+ interface LedgerUtxoInput {
73
+ /** Raw transaction hex that created this UTXO */
74
+ txHex: string;
75
+ /** Output index in the transaction */
76
+ outputIndex: number;
77
+ /** BIP32 derivation path for signing (e.g., "84'/0'/0'/0/0") */
78
+ derivationPath: string;
79
+ /** Optional redeem script for P2SH inputs */
80
+ redeemScript?: string;
81
+ /** Optional sequence number (default: 0xffffffff) */
82
+ sequence?: number;
83
+ }
84
+ /**
85
+ * Output for createPaymentTransaction
86
+ */
87
+ interface LedgerTxOutput {
88
+ /** Recipient address */
89
+ address: string;
90
+ /** Amount in satoshis */
91
+ satoshis: number;
92
+ }
93
+ /**
94
+ * Options for sendBitcoin method
95
+ */
96
+ interface SendBitcoinOptions {
97
+ /** Fee rate in sat/vB (optional, defaults to "hour" priority) */
98
+ feeRate?: number;
99
+ }
100
+ /**
101
+ * Ledger Hardware Wallet Connector
102
+ *
103
+ * @see https://developers.ledger.com/docs/transport/overview
104
+ * @see https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-app-btc
105
+ */
106
+ declare class LedgerConnector extends BaseConnector {
107
+ readonly id = "ledger";
108
+ readonly name = "Ledger";
109
+ readonly icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgdmlld0JveD0iMCAwIDIwMCAyMDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF83MDM1XzUxMTApIj4KPHJlY3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHJ4PSIzMiIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTE0Mi4yMzkgMzcuNUg4NS4wOTY0VjExNC41ODJIMTYyLjIzOVY1Ny40MzkzQzE2Mi4yMzggNTQuODE2IDE2MS43MiA1Mi4yMTg2IDE2MC43MTQgNDkuNzk1OUMxNTkuNzA4IDQ3LjM3MzIgMTU4LjIzMyA0NS4xNzI4IDE1Ni4zNzYgNDMuMzIwN0MxNTQuNTE4IDQxLjQ2ODUgMTUyLjMxMyA0MC4wMDExIDE0OS44ODcgMzkuMDAyM0MxNDcuNDYyIDM4LjAwMzUgMTQ0Ljg2MyAzNy40OTMgMTQyLjIzOSAzNy41WiIgZmlsbD0iYmxhY2siLz4KPHBhdGggZD0iTTY3LjI5MjkgMzcuNUg1Ny40NDY0QzUyLjE1NjMgMzcuNSA0Ny4wODI5IDM5LjYwMTUgNDMuMzQyMiA0My4z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wMzVfNTExMCI+CjxyZWN0IHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo=";
110
+ private _transport;
111
+ private _btcApp;
112
+ private _account;
113
+ private _network;
114
+ private _options;
115
+ private _derivationPath;
116
+ private static readonly CONNECTION_TIMEOUT;
117
+ constructor(options?: LedgerConnectorOptions);
118
+ /**
119
+ * Override checkReady - Ledger is always "ready" since it doesn't require browser extension
120
+ * The actual device connection happens when connect() is called
121
+ */
122
+ protected checkReady(): void;
123
+ /**
124
+ * Get the provider - for Ledger this is the Bitcoin app instance
125
+ */
126
+ protected getProvider(): LedgerBtcApp | null;
127
+ /**
128
+ * Get current address type
129
+ */
130
+ getAddressType(): LedgerAddressType;
131
+ /**
132
+ * Set address type options before connecting
133
+ * Call this before connect() to change the address derivation path
134
+ */
135
+ setOptions(options: LedgerConnectorOptions): void;
136
+ /**
137
+ * Get available address types for UI selection
138
+ */
139
+ static getAvailableAddressTypes(): Array<{
140
+ type: LedgerAddressType;
141
+ label: string;
142
+ description: string;
143
+ }>;
144
+ /**
145
+ * Check if WebUSB is supported in the current browser
146
+ */
147
+ isSupported(): Promise<boolean>;
148
+ /**
149
+ * Initialize transport with timeout
150
+ * Uses request() instead of create() to always show device selection popup
151
+ */
152
+ private initTransport;
153
+ /**
154
+ * Get BTC app instance, initializing if needed
155
+ */
156
+ private getBtcAppInstance;
157
+ /**
158
+ * Connect to Ledger device
159
+ * IMPORTANT: This must be called within a user gesture (click event)
160
+ */
161
+ connect(network?: BitcoinNetwork): Promise<WalletAccount>;
162
+ /**
163
+ * Get address with verification on device
164
+ */
165
+ getAddressWithVerification(): Promise<WalletAccount>;
166
+ private setupDisconnectListener;
167
+ private closeTransport;
168
+ disconnect(): Promise<void>;
169
+ getAccounts(): Promise<WalletAccount[]>;
170
+ signMessage(message: string): Promise<string>;
171
+ /**
172
+ * Sign a PSBT with Ledger
173
+ *
174
+ * Note: Ledger hardware wallets don't support direct PSBT signing through the standard API.
175
+ * Use the createTransaction method or sendTransaction instead.
176
+ */
177
+ signPsbt(_psbtHex: string, _options?: SignPsbtOptions): Promise<string>;
178
+ /**
179
+ * Sign multiple PSBTs
180
+ */
181
+ signPsbts(psbtHexs: string[], options?: SignPsbtOptions): Promise<string[]>;
182
+ /**
183
+ * Send a Bitcoin transaction
184
+ *
185
+ * @param to - Recipient address
186
+ * @param satoshis - Amount to send in satoshis
187
+ * @param options - Send options (feeRate, etc.)
188
+ * @returns Transaction ID after broadcast
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const txid = await ledger.sendTransaction('bc1q...', 50000);
193
+ * // With custom fee rate
194
+ * const txid = await ledger.sendTransaction('bc1q...', 50000, { feeRate: 10 });
195
+ * ```
196
+ */
197
+ sendTransaction(to: string, satoshis: number, options?: SendBitcoinOptions): Promise<string>;
198
+ /**
199
+ * Create and sign a Bitcoin transaction using Ledger
200
+ *
201
+ * This method requires you to provide UTXOs (unspent transaction outputs) which
202
+ * must be fetched from a blockchain API (e.g., Blockstream, Mempool.space, etc.)
203
+ *
204
+ * @param inputs - Array of UTXO inputs to spend
205
+ * @param outputs - Array of outputs (recipients)
206
+ * @param changePath - Optional BIP32 path for change output
207
+ * @returns Signed transaction hex ready for broadcast
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const signedTx = await ledger.createTransaction(
212
+ * [{
213
+ * txHex: '0100000001...', // Raw tx hex that created the UTXO
214
+ * outputIndex: 0,
215
+ * derivationPath: "84'/0'/0'/0/0",
216
+ * }],
217
+ * [{
218
+ * address: 'bc1q...',
219
+ * satoshis: 50000,
220
+ * }],
221
+ * "84'/0'/0'/1/0" // Change address path
222
+ * );
223
+ * ```
224
+ */
225
+ createTransaction(inputs: LedgerUtxoInput[], outputs: LedgerTxOutput[], changePath?: string): Promise<string>;
226
+ /**
227
+ * Build output script hex from outputs array
228
+ * Format: varint(output_count) + [amount(8 bytes LE) + varint(script_len) + script]...
229
+ */
230
+ private buildOutputScript;
231
+ /**
232
+ * Convert address to scriptPubKey hex
233
+ */
234
+ private addressToScriptPubKey;
235
+ /**
236
+ * Decode bech32/bech32m address to hex
237
+ */
238
+ private decodeBech32;
239
+ /**
240
+ * Decode base58check address to hex (without version byte)
241
+ */
242
+ private decodeBase58Check;
243
+ /**
244
+ * Encode number as varint hex
245
+ */
246
+ private encodeVarint;
247
+ /**
248
+ * Convert uint16 to little-endian hex
249
+ */
250
+ private uint16ToLittleEndian;
251
+ /**
252
+ * Convert uint32 to little-endian hex
253
+ */
254
+ private uint32ToLittleEndian;
255
+ /**
256
+ * Convert uint64 to little-endian hex
257
+ */
258
+ private uint64ToLittleEndian;
259
+ /**
260
+ * Get additionals array based on address type
261
+ */
262
+ private getAdditionals;
263
+ getNetwork(): Promise<BitcoinNetwork>;
264
+ /**
265
+ * Get extended public key (xpub/ypub/zpub) for account
266
+ */
267
+ getExtendedPublicKey(): Promise<string>;
268
+ /**
269
+ * Get multiple addresses for the account
270
+ */
271
+ getAddresses(startIndex: number, count: number): Promise<WalletAccount[]>;
272
+ /**
273
+ * Get current derivation path
274
+ */
275
+ getDerivationPath(): string;
276
+ /**
277
+ * Check if device is connected
278
+ */
279
+ isConnected(): boolean;
280
+ /**
281
+ * Get the Ledger Bitcoin app instance for advanced operations
282
+ * This allows users to call createPaymentTransaction directly
283
+ */
284
+ getBtcApp(): LedgerBtcApp | null;
285
+ private mapLedgerAddressType;
286
+ private getXpubVersion;
287
+ private handleLedgerError;
288
+ }
289
+
290
+ export { type LedgerAddressType, LedgerConnector, type LedgerConnectorOptions, type LedgerTxOutput, type LedgerUtxoInput, type SendBitcoinOptions };
@@ -0,0 +1,290 @@
1
+ import { BitcoinNetwork, WalletAccount, SignPsbtOptions } from 'otx-btc-wallet-core';
2
+ import { B as BaseConnector } from '../base-IAFq7sd8.js';
3
+
4
+ /**
5
+ * Ledger address type configuration
6
+ */
7
+ type LedgerAddressType = 'legacy' | 'nested-segwit' | 'segwit' | 'taproot';
8
+ /**
9
+ * Ledger connector options
10
+ */
11
+ interface LedgerConnectorOptions {
12
+ /** Address type for derivation (default: 'segwit') */
13
+ addressType?: LedgerAddressType;
14
+ /** Account index (default: 0) */
15
+ accountIndex?: number;
16
+ /** Address index (default: 0) */
17
+ addressIndex?: number;
18
+ }
19
+ interface LedgerBtcApp {
20
+ getWalletPublicKey(path: string, opts?: {
21
+ verify?: boolean;
22
+ format?: 'legacy' | 'p2sh' | 'bech32' | 'bech32m';
23
+ }): Promise<{
24
+ publicKey: string;
25
+ bitcoinAddress: string;
26
+ chainCode: string;
27
+ }>;
28
+ getWalletXpub(arg: {
29
+ path: string;
30
+ xpubVersion: number;
31
+ }): Promise<string>;
32
+ signMessage(path: string, messageHex: string): Promise<{
33
+ v: number;
34
+ r: string;
35
+ s: string;
36
+ }>;
37
+ splitTransaction(transactionHex: string, isSegwitSupported?: boolean | null, hasExtraData?: boolean, additionals?: string[]): LedgerTransaction;
38
+ createPaymentTransaction(arg: {
39
+ inputs: Array<[LedgerTransaction, number, string | null | undefined, number?]>;
40
+ associatedKeysets: string[];
41
+ changePath?: string;
42
+ outputScriptHex: string;
43
+ lockTime?: number;
44
+ sigHashType?: number;
45
+ segwit?: boolean;
46
+ additionals?: string[];
47
+ expiryHeight?: Buffer;
48
+ useTrustedInputForSegwit?: boolean;
49
+ }): Promise<string>;
50
+ serializeTransactionOutputs(tx: LedgerTransaction): Buffer;
51
+ }
52
+ /**
53
+ * Ledger Transaction type (returned by splitTransaction)
54
+ */
55
+ interface LedgerTransaction {
56
+ version: Buffer;
57
+ inputs: Array<{
58
+ prevout: Buffer;
59
+ script: Buffer;
60
+ sequence: Buffer;
61
+ }>;
62
+ outputs?: Array<{
63
+ amount: Buffer;
64
+ script: Buffer;
65
+ }>;
66
+ locktime?: Buffer;
67
+ witness?: Buffer;
68
+ }
69
+ /**
70
+ * UTXO input for createPaymentTransaction
71
+ */
72
+ interface LedgerUtxoInput {
73
+ /** Raw transaction hex that created this UTXO */
74
+ txHex: string;
75
+ /** Output index in the transaction */
76
+ outputIndex: number;
77
+ /** BIP32 derivation path for signing (e.g., "84'/0'/0'/0/0") */
78
+ derivationPath: string;
79
+ /** Optional redeem script for P2SH inputs */
80
+ redeemScript?: string;
81
+ /** Optional sequence number (default: 0xffffffff) */
82
+ sequence?: number;
83
+ }
84
+ /**
85
+ * Output for createPaymentTransaction
86
+ */
87
+ interface LedgerTxOutput {
88
+ /** Recipient address */
89
+ address: string;
90
+ /** Amount in satoshis */
91
+ satoshis: number;
92
+ }
93
+ /**
94
+ * Options for sendBitcoin method
95
+ */
96
+ interface SendBitcoinOptions {
97
+ /** Fee rate in sat/vB (optional, defaults to "hour" priority) */
98
+ feeRate?: number;
99
+ }
100
+ /**
101
+ * Ledger Hardware Wallet Connector
102
+ *
103
+ * @see https://developers.ledger.com/docs/transport/overview
104
+ * @see https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-app-btc
105
+ */
106
+ declare class LedgerConnector extends BaseConnector {
107
+ readonly id = "ledger";
108
+ readonly name = "Ledger";
109
+ readonly icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgdmlld0JveD0iMCAwIDIwMCAyMDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF83MDM1XzUxMTApIj4KPHJlY3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHJ4PSIzMiIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTE0Mi4yMzkgMzcuNUg4NS4wOTY0VjExNC41ODJIMTYyLjIzOVY1Ny40MzkzQzE2Mi4yMzggNTQuODE2IDE2MS43MiA1Mi4yMTg2IDE2MC43MTQgNDkuNzk1OUMxNTkuNzA4IDQ3LjM3MzIgMTU4LjIzMyA0NS4xNzI4IDE1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i42MDcgNDEuNDkgMTU0LjgwNiA0My4zNDIyIDE1Ni42NThDNDUuMTk0NCAxNTguNTEgNDcuMzkzMiAxNTkuOTc5IDQ5LjgxMzMgMTYwLjk4MkM1Mi4yMzMzIDE2MS45ODQgNTQuODI3IDE2Mi41IDU3LjQ0NjQgMTYyLjVINjcuMjkyOVYxMzIuNzA3SDM3LjVaIiBmaWxsPSJibGFjayIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzcwMzVfNTExMCI+CjxyZWN0IHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo=";
110
+ private _transport;
111
+ private _btcApp;
112
+ private _account;
113
+ private _network;
114
+ private _options;
115
+ private _derivationPath;
116
+ private static readonly CONNECTION_TIMEOUT;
117
+ constructor(options?: LedgerConnectorOptions);
118
+ /**
119
+ * Override checkReady - Ledger is always "ready" since it doesn't require browser extension
120
+ * The actual device connection happens when connect() is called
121
+ */
122
+ protected checkReady(): void;
123
+ /**
124
+ * Get the provider - for Ledger this is the Bitcoin app instance
125
+ */
126
+ protected getProvider(): LedgerBtcApp | null;
127
+ /**
128
+ * Get current address type
129
+ */
130
+ getAddressType(): LedgerAddressType;
131
+ /**
132
+ * Set address type options before connecting
133
+ * Call this before connect() to change the address derivation path
134
+ */
135
+ setOptions(options: LedgerConnectorOptions): void;
136
+ /**
137
+ * Get available address types for UI selection
138
+ */
139
+ static getAvailableAddressTypes(): Array<{
140
+ type: LedgerAddressType;
141
+ label: string;
142
+ description: string;
143
+ }>;
144
+ /**
145
+ * Check if WebUSB is supported in the current browser
146
+ */
147
+ isSupported(): Promise<boolean>;
148
+ /**
149
+ * Initialize transport with timeout
150
+ * Uses request() instead of create() to always show device selection popup
151
+ */
152
+ private initTransport;
153
+ /**
154
+ * Get BTC app instance, initializing if needed
155
+ */
156
+ private getBtcAppInstance;
157
+ /**
158
+ * Connect to Ledger device
159
+ * IMPORTANT: This must be called within a user gesture (click event)
160
+ */
161
+ connect(network?: BitcoinNetwork): Promise<WalletAccount>;
162
+ /**
163
+ * Get address with verification on device
164
+ */
165
+ getAddressWithVerification(): Promise<WalletAccount>;
166
+ private setupDisconnectListener;
167
+ private closeTransport;
168
+ disconnect(): Promise<void>;
169
+ getAccounts(): Promise<WalletAccount[]>;
170
+ signMessage(message: string): Promise<string>;
171
+ /**
172
+ * Sign a PSBT with Ledger
173
+ *
174
+ * Note: Ledger hardware wallets don't support direct PSBT signing through the standard API.
175
+ * Use the createTransaction method or sendTransaction instead.
176
+ */
177
+ signPsbt(_psbtHex: string, _options?: SignPsbtOptions): Promise<string>;
178
+ /**
179
+ * Sign multiple PSBTs
180
+ */
181
+ signPsbts(psbtHexs: string[], options?: SignPsbtOptions): Promise<string[]>;
182
+ /**
183
+ * Send a Bitcoin transaction
184
+ *
185
+ * @param to - Recipient address
186
+ * @param satoshis - Amount to send in satoshis
187
+ * @param options - Send options (feeRate, etc.)
188
+ * @returns Transaction ID after broadcast
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const txid = await ledger.sendTransaction('bc1q...', 50000);
193
+ * // With custom fee rate
194
+ * const txid = await ledger.sendTransaction('bc1q...', 50000, { feeRate: 10 });
195
+ * ```
196
+ */
197
+ sendTransaction(to: string, satoshis: number, options?: SendBitcoinOptions): Promise<string>;
198
+ /**
199
+ * Create and sign a Bitcoin transaction using Ledger
200
+ *
201
+ * This method requires you to provide UTXOs (unspent transaction outputs) which
202
+ * must be fetched from a blockchain API (e.g., Blockstream, Mempool.space, etc.)
203
+ *
204
+ * @param inputs - Array of UTXO inputs to spend
205
+ * @param outputs - Array of outputs (recipients)
206
+ * @param changePath - Optional BIP32 path for change output
207
+ * @returns Signed transaction hex ready for broadcast
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const signedTx = await ledger.createTransaction(
212
+ * [{
213
+ * txHex: '0100000001...', // Raw tx hex that created the UTXO
214
+ * outputIndex: 0,
215
+ * derivationPath: "84'/0'/0'/0/0",
216
+ * }],
217
+ * [{
218
+ * address: 'bc1q...',
219
+ * satoshis: 50000,
220
+ * }],
221
+ * "84'/0'/0'/1/0" // Change address path
222
+ * );
223
+ * ```
224
+ */
225
+ createTransaction(inputs: LedgerUtxoInput[], outputs: LedgerTxOutput[], changePath?: string): Promise<string>;
226
+ /**
227
+ * Build output script hex from outputs array
228
+ * Format: varint(output_count) + [amount(8 bytes LE) + varint(script_len) + script]...
229
+ */
230
+ private buildOutputScript;
231
+ /**
232
+ * Convert address to scriptPubKey hex
233
+ */
234
+ private addressToScriptPubKey;
235
+ /**
236
+ * Decode bech32/bech32m address to hex
237
+ */
238
+ private decodeBech32;
239
+ /**
240
+ * Decode base58check address to hex (without version byte)
241
+ */
242
+ private decodeBase58Check;
243
+ /**
244
+ * Encode number as varint hex
245
+ */
246
+ private encodeVarint;
247
+ /**
248
+ * Convert uint16 to little-endian hex
249
+ */
250
+ private uint16ToLittleEndian;
251
+ /**
252
+ * Convert uint32 to little-endian hex
253
+ */
254
+ private uint32ToLittleEndian;
255
+ /**
256
+ * Convert uint64 to little-endian hex
257
+ */
258
+ private uint64ToLittleEndian;
259
+ /**
260
+ * Get additionals array based on address type
261
+ */
262
+ private getAdditionals;
263
+ getNetwork(): Promise<BitcoinNetwork>;
264
+ /**
265
+ * Get extended public key (xpub/ypub/zpub) for account
266
+ */
267
+ getExtendedPublicKey(): Promise<string>;
268
+ /**
269
+ * Get multiple addresses for the account
270
+ */
271
+ getAddresses(startIndex: number, count: number): Promise<WalletAccount[]>;
272
+ /**
273
+ * Get current derivation path
274
+ */
275
+ getDerivationPath(): string;
276
+ /**
277
+ * Check if device is connected
278
+ */
279
+ isConnected(): boolean;
280
+ /**
281
+ * Get the Ledger Bitcoin app instance for advanced operations
282
+ * This allows users to call createPaymentTransaction directly
283
+ */
284
+ getBtcApp(): LedgerBtcApp | null;
285
+ private mapLedgerAddressType;
286
+ private getXpubVersion;
287
+ private handleLedgerError;
288
+ }
289
+
290
+ export { type LedgerAddressType, LedgerConnector, type LedgerConnectorOptions, type LedgerTxOutput, type LedgerUtxoInput, type SendBitcoinOptions };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkLNKTYZJM_js = require('../chunk-LNKTYZJM.js');
4
+ require('../chunk-FISNQZZ7.js');
5
+ require('../chunk-MFXLQWOE.js');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "LedgerConnector", {
10
+ enumerable: true,
11
+ get: function () { return chunkLNKTYZJM_js.LedgerConnector; }
12
+ });
13
+ //# sourceMappingURL=out.js.map
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export { LedgerConnector } from '../chunk-LVZMONQL.mjs';
2
+ import '../chunk-AW2JZIHR.mjs';
3
+ import '../chunk-5Z5Q2Y75.mjs';
4
+ //# sourceMappingURL=out.js.map
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}