@sequence0/sdk 1.0.3 → 1.1.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.
Files changed (49) hide show
  1. package/README.md +137 -10
  2. package/dist/chains/bitcoin-taproot.d.ts +371 -0
  3. package/dist/chains/bitcoin-taproot.d.ts.map +1 -0
  4. package/dist/chains/bitcoin-taproot.js +1241 -0
  5. package/dist/chains/bitcoin-taproot.js.map +1 -0
  6. package/dist/chains/bitcoin.d.ts +12 -7
  7. package/dist/chains/bitcoin.d.ts.map +1 -1
  8. package/dist/chains/bitcoin.js +14 -9
  9. package/dist/chains/bitcoin.js.map +1 -1
  10. package/dist/core/client.d.ts +4 -5
  11. package/dist/core/client.d.ts.map +1 -1
  12. package/dist/core/client.js +54 -29
  13. package/dist/core/client.js.map +1 -1
  14. package/dist/erc4337/account.d.ts +241 -0
  15. package/dist/erc4337/account.d.ts.map +1 -0
  16. package/dist/erc4337/account.js +810 -0
  17. package/dist/erc4337/account.js.map +1 -0
  18. package/dist/erc4337/index.d.ts +9 -0
  19. package/dist/erc4337/index.d.ts.map +1 -0
  20. package/dist/erc4337/index.js +16 -0
  21. package/dist/erc4337/index.js.map +1 -0
  22. package/dist/erc4337/types.d.ts +173 -0
  23. package/dist/erc4337/types.d.ts.map +1 -0
  24. package/dist/erc4337/types.js +52 -0
  25. package/dist/erc4337/types.js.map +1 -0
  26. package/dist/index.d.ts +29 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +43 -2
  29. package/dist/index.js.map +1 -1
  30. package/dist/utils/discovery.d.ts.map +1 -1
  31. package/dist/utils/discovery.js +56 -1
  32. package/dist/utils/discovery.js.map +1 -1
  33. package/dist/utils/eip712.d.ts +36 -0
  34. package/dist/utils/eip712.d.ts.map +1 -0
  35. package/dist/utils/eip712.js +80 -0
  36. package/dist/utils/eip712.js.map +1 -0
  37. package/dist/utils/fee.d.ts +2 -2
  38. package/dist/utils/fee.js +2 -2
  39. package/dist/utils/validation.d.ts +8 -0
  40. package/dist/utils/validation.d.ts.map +1 -1
  41. package/dist/utils/validation.js +18 -0
  42. package/dist/utils/validation.js.map +1 -1
  43. package/dist/utils/websocket.js +1 -1
  44. package/dist/utils/websocket.js.map +1 -1
  45. package/dist/wallet/wallet.d.ts +23 -2
  46. package/dist/wallet/wallet.d.ts.map +1 -1
  47. package/dist/wallet/wallet.js +91 -31
  48. package/dist/wallet/wallet.js.map +1 -1
  49. package/package.json +8 -2
package/README.md CHANGED
@@ -30,6 +30,74 @@ const txHash = await wallet.sendTransaction({
30
30
  console.log('TX Hash:', txHash);
31
31
  ```
32
32
 
33
+ ## What's New in v1.1.0
34
+
35
+ ### Bitcoin Taproot (P2TR) Support
36
+
37
+ Full Bitcoin Taproot transaction lifecycle: address derivation, UTXO management, transaction building, FROST Schnorr signing, and broadcast. FROST-secp256k1 produces BIP-340 compatible Schnorr signatures that are native to Taproot key-path spends.
38
+
39
+ ```typescript
40
+ import { BitcoinTaprootAdapter } from '@sequence0/sdk';
41
+
42
+ const btc = new BitcoinTaprootAdapter({ network: 'mainnet' });
43
+
44
+ // Derive a Taproot address from a FROST group public key
45
+ const addr = btc.deriveAddress('02abcdef...');
46
+ console.log(addr.address); // bc1p...
47
+
48
+ // Get balance and UTXOs
49
+ const balance = await btc.getBalance('bc1p...');
50
+ const utxos = await btc.getUTXOs('bc1p...');
51
+
52
+ // Build a transaction
53
+ const unsignedTx = await btc.buildTransaction(
54
+ { to: 'bc1p...recipient', amount: 50000, feeRate: 15 },
55
+ 'bc1p...sender'
56
+ );
57
+
58
+ // Or use via the Wallet class for automatic signing
59
+ const wallet = await s0.createWallet({ chain: 'bitcoin' });
60
+ const txHash = await wallet.sendTransaction({
61
+ to: 'bc1p...recipient',
62
+ amount: 50000,
63
+ feeRate: 15,
64
+ });
65
+ ```
66
+
67
+ ### ERC-4337 Account Abstraction
68
+
69
+ Smart accounts backed by FROST threshold signing. Enables gas-sponsored transactions, batch calls, and programmable transaction validation.
70
+
71
+ ```typescript
72
+ import { Sequence0Account } from '@sequence0/sdk';
73
+
74
+ // Create a new AA wallet backed by FROST
75
+ const account = await Sequence0Account.create({
76
+ threshold: 16,
77
+ committeeSize: 24,
78
+ chain: 'ethereum',
79
+ ownerPrivateKey: '0x...',
80
+ bundlerUrl: 'https://api.pimlico.io/v2/1/rpc?apikey=YOUR_KEY',
81
+ });
82
+
83
+ console.log('Smart Account:', account.getAddress());
84
+
85
+ // Send a single transaction
86
+ const txHash = await account.sendTransaction({
87
+ to: '0xRecipient',
88
+ value: BigInt('1000000000000000000'),
89
+ });
90
+
91
+ // Batch multiple calls
92
+ const txHash2 = await account.sendBatchTransaction([
93
+ { to: '0xTokenA', data: '0xa9059cbb...' },
94
+ { to: '0xTokenB', data: '0xa9059cbb...' },
95
+ ]);
96
+
97
+ // Sign messages
98
+ const sig = await account.signMessage('Hello from Sequence0 AA!');
99
+ ```
100
+
33
101
  ## Features
34
102
 
35
103
  | Feature | Description |
@@ -37,22 +105,27 @@ console.log('TX Hash:', txHash);
37
105
  | **Multi-Chain** | Ethereum, Bitcoin, Solana, Polygon, Arbitrum, Base, and 60+ more (67 total) |
38
106
  | **Threshold Signing** | FROST (t-of-n) — no single point of failure |
39
107
  | **No Private Keys** | Keys are sharded across the agent network |
108
+ | **Bitcoin Taproot** | Native P2TR support with BIP-340 Schnorr signatures |
109
+ | **Account Abstraction** | ERC-4337 smart accounts with batched transactions |
40
110
  | **Real-Time Events** | WebSocket subscriptions for signing progress |
41
111
  | **Chain Adapters** | Auto-builds chain-native transactions |
42
112
 
43
113
  ## Supported Chains
44
114
 
45
115
  ### EVM (secp256k1)
46
- Ethereum, Polygon, Arbitrum, Optimism, Base, BSC, Avalanche
116
+ Ethereum, Polygon, Arbitrum, Optimism, Base, BSC, Avalanche, and 40+ more
47
117
 
48
- ### Non-EVM
49
- Bitcoin (Schnorr/Taproot), Solana (Ed25519)
118
+ ### Bitcoin (Taproot/Schnorr)
119
+ Full P2TR lifecycle: address derivation, UTXO selection, transaction building, Schnorr signing, and broadcast via the `BitcoinTaprootAdapter`.
50
120
 
51
- > **Note:** Bitcoin, Dogecoin, and Litecoin support wallet creation and raw message signing via `sign()`. However, `sendTransaction()` is not yet supported for UTXO chains — full transaction serialization requires `bitcoinjs-lib`. Use `sign()` to get the Schnorr signature and construct the raw transaction externally.
121
+ ### Solana (Ed25519)
122
+ Native SOL transfers with versioned transactions.
123
+
124
+ > **Note:** Dogecoin and Litecoin support wallet creation and raw message signing via `sign()`. Full `sendTransaction()` support for these UTXO chains is coming soon.
52
125
 
53
126
  ## API Reference
54
127
 
55
- ### `Sequence0` Main Client
128
+ ### `Sequence0` -- Main Client
56
129
 
57
130
  ```typescript
58
131
  const s0 = new Sequence0({
@@ -105,7 +178,7 @@ const wallet = await s0.createWallet({
105
178
  | `subscribe(walletId?)` | `Promise<WsClient>` | Subscribe to real-time events |
106
179
  | `refreshKeys(walletId)` | `Promise<void>` | Proactive key rotation |
107
180
 
108
- ### `Wallet` Threshold Wallet
181
+ ### `Wallet` -- Threshold Wallet
109
182
 
110
183
  ```typescript
111
184
  const wallet = await s0.createWallet({
@@ -127,15 +200,69 @@ const wallet = await s0.createWallet({
127
200
  | `getBalance()` | `Promise<string>` | Get native token balance |
128
201
  | `info()` | `Record<string, unknown>` | Get wallet summary |
129
202
 
203
+ ### `BitcoinTaprootAdapter` -- Bitcoin P2TR
204
+
205
+ ```typescript
206
+ import { BitcoinTaprootAdapter } from '@sequence0/sdk';
207
+
208
+ const btc = new BitcoinTaprootAdapter({ network: 'mainnet' });
209
+ ```
210
+
211
+ | Method | Returns | Description |
212
+ |--------|---------|-------------|
213
+ | `deriveAddress(pubkeyHex)` | `TaprootAddressInfo` | Derive bc1p... address from FROST public key |
214
+ | `getBalance(address)` | `Promise<string>` | Get balance in satoshis |
215
+ | `getUTXOs(address)` | `Promise<TaprootUtxo[]>` | Fetch unspent outputs |
216
+ | `getFeeRates()` | `Promise<FeeRateEstimate>` | Get recommended fee rates |
217
+ | `buildTransaction(tx, from)` | `Promise<string>` | Build unsigned transaction |
218
+ | `buildUnsignedTx(inputs, outputs, feeRate)` | `UnsignedTaprootTx` | Build with explicit inputs/outputs |
219
+ | `attachSignature(unsignedTx, sig)` | `Promise<string>` | Attach FROST Schnorr signature |
220
+ | `broadcast(signedTx)` | `Promise<string>` | Broadcast to Bitcoin network |
221
+ | `getTransaction(txid)` | `Promise<any>` | Get transaction details |
222
+ | `getBlockHeight()` | `Promise<number>` | Get current block height |
223
+
224
+ ### `Sequence0Account` -- ERC-4337 Smart Account
225
+
226
+ ```typescript
227
+ import { Sequence0Account } from '@sequence0/sdk';
228
+
229
+ const account = await Sequence0Account.create({
230
+ threshold: 16,
231
+ committeeSize: 24,
232
+ chain: 'ethereum',
233
+ ownerPrivateKey: '0x...',
234
+ bundlerUrl: 'https://bundler.example.com',
235
+ });
236
+ ```
237
+
238
+ | Method | Returns | Description |
239
+ |--------|---------|-------------|
240
+ | `Sequence0Account.create(options)` | `Promise<Sequence0Account>` | Create new AA wallet via DKG |
241
+ | `Sequence0Account.fromExisting(walletId, pubkey, options)` | `Promise<Sequence0Account>` | Reconnect to existing wallet |
242
+ | `getAddress()` | `string` | Get smart account address |
243
+ | `sendTransaction(tx)` | `Promise<string>` | Build, sign, submit UserOperation |
244
+ | `sendBatchTransaction(txs)` | `Promise<string>` | Batch multiple calls |
245
+ | `signMessage(message)` | `Promise<string>` | Sign with EIP-191 prefix |
246
+ | `buildUserOp(callData)` | `Promise<PackedUserOperation>` | Build unsigned UserOp |
247
+ | `submitUserOp(userOp, bundlerUrl?)` | `Promise<string>` | Submit to bundler |
248
+ | `estimateUserOpGas(userOp)` | `Promise<UserOperationGasEstimate>` | Estimate gas |
249
+ | `waitForUserOp(hash, timeout?)` | `Promise<UserOperationReceipt>` | Wait for inclusion |
250
+ | `getBalance()` | `Promise<string>` | Get native token balance |
251
+ | `isDeployed()` | `boolean` | Check if deployed on-chain |
252
+
130
253
  ### Chain Adapters
131
254
 
132
255
  Use chain adapters directly for advanced control:
133
256
 
134
257
  ```typescript
135
- import { EthereumAdapter, BitcoinAdapter, SolanaAdapter } from '@sequence0/sdk';
258
+ import {
259
+ EthereumAdapter,
260
+ BitcoinTaprootAdapter,
261
+ SolanaAdapter,
262
+ } from '@sequence0/sdk';
136
263
 
137
264
  const eth = new EthereumAdapter('ethereum', 'https://eth.llamarpc.com');
138
- const btc = new BitcoinAdapter('mainnet');
265
+ const btc = new BitcoinTaprootAdapter({ network: 'mainnet' });
139
266
  const sol = new SolanaAdapter('mainnet');
140
267
  ```
141
268
 
@@ -169,7 +296,7 @@ try {
169
296
 
170
297
  ## Any Language (REST API)
171
298
 
172
- This SDK wraps a plain **HTTP + JSON** REST API exposed by every agent node. You can integrate from **any language** Python, Go, Rust, Java, etc. by calling the API directly:
299
+ This SDK wraps a plain **HTTP + JSON** REST API exposed by every agent node. You can integrate from **any language** -- Python, Go, Rust, Java, etc. -- by calling the API directly:
173
300
 
174
301
  ```bash
175
302
  # Health check
@@ -208,4 +335,4 @@ Signing fees are always paid in **ETH on the Sequence0 chain** (chain 800801). F
208
335
 
209
336
  ## License
210
337
 
211
- MIT © Sequence0 Network
338
+ MIT (c) Sequence0 Network
@@ -0,0 +1,371 @@
1
+ /**
2
+ * Bitcoin Taproot (P2TR) Chain Adapter
3
+ *
4
+ * Full Taproot transaction lifecycle: address derivation, UTXO management,
5
+ * transaction building, FROST Schnorr signing, and broadcast.
6
+ *
7
+ * FROST-secp256k1 produces BIP-340 compatible Schnorr signatures that are
8
+ * NATIVE to Taproot key-path spends -- no signature format conversion needed.
9
+ *
10
+ * Key features:
11
+ * - **Real secp256k1 EC point arithmetic** for BIP-341 key tweaking
12
+ * (lift_x, point_add, scalar_mul -- no external crypto dependencies)
13
+ * - **Per-input sighash computation** for multi-input transactions
14
+ * (each input gets its own BIP-341 sighash for independent FROST signing)
15
+ * - **Full transaction serialization** with proper segwit witness structure
16
+ * - **Broadcast via Mempool.space API** (mainnet, testnet, signet, regtest)
17
+ *
18
+ * No external dependencies beyond Node.js crypto (SHA-256).
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { BitcoinTaprootAdapter } from '@sequence0/sdk';
23
+ *
24
+ * const btc = new BitcoinTaprootAdapter({ network: 'mainnet' });
25
+ *
26
+ * // Derive a Taproot address from a FROST group public key
27
+ * const addr = btc.deriveAddress('02abcdef...');
28
+ * console.log(addr.address); // bc1p...
29
+ *
30
+ * // Get balance and UTXOs
31
+ * const balance = await btc.getBalance('bc1p...');
32
+ * const utxos = await btc.getUTXOs('bc1p...');
33
+ *
34
+ * // Build, sign, and broadcast
35
+ * const unsignedTx = await btc.buildTransaction(
36
+ * { to: 'bc1p...recipient', amount: 50000, feeRate: 15 },
37
+ * 'bc1p...sender'
38
+ * );
39
+ * // ... sign via FROST ...
40
+ * const txid = await btc.broadcast(signedTxHex);
41
+ * ```
42
+ */
43
+ import { ChainAdapter, BtcTransaction } from '../core/types';
44
+ /** Bitcoin network type */
45
+ export type BitcoinNetwork = 'mainnet' | 'testnet' | 'signet' | 'regtest';
46
+ /** UTXO from the indexer API */
47
+ export interface TaprootUtxo {
48
+ /** Transaction hash (big-endian hex, 64 chars) */
49
+ txid: string;
50
+ /** Output index */
51
+ vout: number;
52
+ /** Value in satoshis */
53
+ value: number;
54
+ /** ScriptPubKey (hex-encoded) */
55
+ scriptPubkey: string;
56
+ /** Confirmation status */
57
+ status: {
58
+ confirmed: boolean;
59
+ blockHeight?: number;
60
+ blockHash?: string;
61
+ blockTime?: number;
62
+ };
63
+ }
64
+ /** Taproot address metadata returned by deriveAddress */
65
+ export interface TaprootAddressInfo {
66
+ /** Bech32m-encoded Taproot address (bc1p... / tb1p...) */
67
+ address: string;
68
+ /** X-only internal public key (64-char hex) */
69
+ xOnlyPubkey: string;
70
+ /** X-only output key after tweak (64-char hex) */
71
+ outputKey: string;
72
+ /** ScriptPubKey (hex-encoded, OP_1 <32-byte output key>) */
73
+ scriptPubkey: string;
74
+ /**
75
+ * Taproot tweak scalar (64-char hex).
76
+ * This must be applied to the FROST group private key during signing:
77
+ * tweaked_privkey = privkey + tweak (mod n)
78
+ * The FROST signing request should include this tweak so agents can
79
+ * adjust their secret shares before producing partial signatures.
80
+ */
81
+ tapTweak: string;
82
+ /** Network */
83
+ network: BitcoinNetwork;
84
+ }
85
+ /** Unsigned Taproot transaction ready for FROST signing */
86
+ export interface UnsignedTaprootTx {
87
+ /**
88
+ * Sighash for the first input (32 bytes, hex-encoded).
89
+ * For single-input transactions this is all you need.
90
+ * For multi-input transactions, use `sighashes` instead.
91
+ */
92
+ sighash: string;
93
+ /**
94
+ * Per-input sighashes (32 bytes each, hex-encoded).
95
+ * Each input has its own BIP-341 sighash that must be independently
96
+ * signed via FROST. The same key signs all inputs, but each sighash
97
+ * includes the input index and produces a different message.
98
+ */
99
+ sighashes: string[];
100
+ /** Serialized unsigned transaction (hex-encoded) */
101
+ rawUnsigned: string;
102
+ /** Transaction inputs */
103
+ inputs: TaprootTxInput[];
104
+ /** Transaction outputs */
105
+ outputs: TaprootTxOutput[];
106
+ /** Estimated virtual size in vbytes */
107
+ estimatedVsize: number;
108
+ /** Estimated fee in satoshis */
109
+ estimatedFee: number;
110
+ }
111
+ /** Signed Taproot transaction */
112
+ export interface SignedTaprootTx {
113
+ /** Serialized signed transaction (hex-encoded), ready for broadcast */
114
+ rawSigned: string;
115
+ /** Transaction ID */
116
+ txid: string;
117
+ /** Virtual size in vbytes */
118
+ vsize: number;
119
+ }
120
+ /** Transaction input (a UTXO being spent) */
121
+ export interface TaprootTxInput {
122
+ txid: string;
123
+ vout: number;
124
+ value: number;
125
+ scriptPubkey: string;
126
+ }
127
+ /** Transaction output */
128
+ export interface TaprootTxOutput {
129
+ address: string;
130
+ value: number;
131
+ }
132
+ /** Options for creating the adapter */
133
+ export interface BitcoinTaprootOptions {
134
+ /** Bitcoin network (default: 'mainnet') */
135
+ network?: BitcoinNetwork;
136
+ /** Custom Mempool/Blockstream API URL for UTXO queries and broadcast */
137
+ apiUrl?: string;
138
+ /** Custom Electrum RPC URL (alternative to HTTP API) */
139
+ electrumUrl?: string;
140
+ }
141
+ /** Fee rate estimates from the mempool */
142
+ export interface FeeRateEstimate {
143
+ /** Fee rate for next block confirmation (sat/vB) */
144
+ fastest: number;
145
+ /** Fee rate for confirmation within 30 minutes (sat/vB) */
146
+ halfHour: number;
147
+ /** Fee rate for confirmation within 1 hour (sat/vB) */
148
+ hour: number;
149
+ /** Fee rate for economy confirmation (sat/vB) */
150
+ economy: number;
151
+ /** Minimum relay fee (sat/vB) */
152
+ minimum: number;
153
+ }
154
+ export declare class BitcoinTaprootAdapter implements ChainAdapter {
155
+ private network;
156
+ private apiUrl;
157
+ constructor(options?: BitcoinTaprootOptions);
158
+ getRpcUrl(): string;
159
+ /**
160
+ * Derive a Taproot (P2TR) address from a FROST group public key.
161
+ *
162
+ * The FROST group verifying key is a secp256k1 point. For Taproot:
163
+ * 1. Extract the x-only public key (32 bytes)
164
+ * 2. Compute the Taproot tweak: t = hash_TapTweak(x_only_pubkey)
165
+ * 3. Compute the output key: Q = P + t*G
166
+ * 4. Encode as Bech32m with witness version 1
167
+ *
168
+ * @param groupPubkeyHex - Hex-encoded FROST group verifying key (33 bytes compressed or 32 bytes x-only)
169
+ * @returns TaprootAddressInfo with address, keys, and scriptPubkey
170
+ */
171
+ deriveAddress(groupPubkeyHex: string): TaprootAddressInfo;
172
+ /**
173
+ * Compute the Taproot tweak for a FROST group public key.
174
+ *
175
+ * The FROST signing protocol must apply this tweak to the group private key
176
+ * before signing. This ensures the Schnorr signature verifies against the
177
+ * tweaked output key (which is what the scriptPubKey commits to).
178
+ *
179
+ * The tweak scalar t = hash_TapTweak(internal_key) is returned as hex.
180
+ * During FROST signing, the group's secret share is tweaked:
181
+ * tweaked_share = share + t (mod n)
182
+ *
183
+ * @param groupPubkeyHex - Hex-encoded FROST group verifying key (33 or 32 bytes)
184
+ * @returns Hex-encoded 32-byte tweak scalar
185
+ */
186
+ getTapTweak(groupPubkeyHex: string): string;
187
+ /**
188
+ * Fetch unspent transaction outputs (UTXOs) for a Taproot address.
189
+ *
190
+ * @param address - Bech32m Taproot address (bc1p... / tb1p...)
191
+ * @returns Array of UTXOs sorted by value (largest first)
192
+ */
193
+ getUTXOs(address: string): Promise<TaprootUtxo[]>;
194
+ /**
195
+ * Get the balance of a Bitcoin address in satoshis.
196
+ * Includes both confirmed and unconfirmed (mempool) balances.
197
+ *
198
+ * @param address - Taproot address
199
+ * @returns Balance in satoshis as a string
200
+ */
201
+ getBalance(address: string): Promise<string>;
202
+ /**
203
+ * Get the confirmed balance only (excluding mempool transactions).
204
+ *
205
+ * @param address - Taproot address
206
+ * @returns Confirmed balance in satoshis as a string
207
+ */
208
+ getConfirmedBalance(address: string): Promise<string>;
209
+ /**
210
+ * Get recommended fee rates from the mempool.
211
+ *
212
+ * @returns Fee rate estimates in sat/vB
213
+ */
214
+ getFeeRates(): Promise<FeeRateEstimate>;
215
+ /**
216
+ * Estimate the fee for a transaction with the given number of inputs and outputs.
217
+ *
218
+ * @param inputCount - Number of Taproot inputs
219
+ * @param outputCount - Number of outputs (including change)
220
+ * @param feeRate - Fee rate in sat/vB
221
+ * @returns Estimated fee in satoshis
222
+ */
223
+ estimateFee(inputCount: number, outputCount: number, feeRate: number): number;
224
+ /**
225
+ * Build an unsigned Bitcoin Taproot transaction.
226
+ *
227
+ * Fetches UTXOs, selects inputs using a largest-first strategy,
228
+ * constructs outputs (recipient + change), computes the BIP-341
229
+ * sighash, and returns the serialized unsigned transaction.
230
+ *
231
+ * The returned sighash is what gets passed to the FROST signing
232
+ * protocol. The resulting 64-byte Schnorr signature is directly
233
+ * usable as the Taproot witness.
234
+ *
235
+ * @param tx - Transaction parameters (to, amount, feeRate)
236
+ * @param fromAddress - Sender's Taproot address
237
+ * @returns Hex-encoded unsigned transaction data (JSON-encoded internally)
238
+ */
239
+ buildTransaction(tx: BtcTransaction, fromAddress: string): Promise<string>;
240
+ /**
241
+ * Build an unsigned Taproot transaction with explicit control over inputs and outputs.
242
+ *
243
+ * For advanced usage when you want to manually select UTXOs and construct
244
+ * the transaction outputs.
245
+ *
246
+ * @param inputs - UTXOs to spend
247
+ * @param outputs - Transaction outputs
248
+ * @param xOnlyInternalKey - 32-byte x-only internal key (hex-encoded)
249
+ * @param feeRate - Fee rate in sat/vB
250
+ * @returns UnsignedTaprootTx ready for FROST signing
251
+ */
252
+ buildUnsignedTx(inputs: TaprootTxInput[], outputs: TaprootTxOutput[], feeRate: number): UnsignedTaprootTx;
253
+ /**
254
+ * Attach FROST Schnorr signature(s) to an unsigned Taproot transaction.
255
+ *
256
+ * The FROST signing protocol produces 64-byte BIP-340 Schnorr signatures
257
+ * (R_x || s) that are directly used as Taproot witness for key-path spends.
258
+ *
259
+ * For single-input transactions: pass a single 128-char hex signature.
260
+ * For multi-input transactions: pass signatures separated by commas, or
261
+ * a single signature that will be applied to all inputs (if all inputs
262
+ * share the same signing key and the caller signs each sighash separately).
263
+ *
264
+ * @param unsignedTxHex - Hex-encoded unsigned transaction (from buildTransaction)
265
+ * @param signatureHex - 64-byte FROST Schnorr signature(s). For multi-input
266
+ * transactions, separate per-input signatures with commas.
267
+ * @returns Hex-encoded signed transaction ready for broadcast
268
+ */
269
+ attachSignature(unsignedTxHex: string, signatureHex: string): Promise<string>;
270
+ /**
271
+ * Attach FROST Schnorr signature(s) with full output (returns structured data).
272
+ *
273
+ * @param unsignedTx - The UnsignedTaprootTx from buildUnsignedTx
274
+ * @param signatureHex - 64-byte FROST Schnorr signature(s) (hex). For multi-input
275
+ * transactions, pass an array of per-input signatures or a comma-separated string.
276
+ * @returns SignedTaprootTx with raw_signed, txid, and vsize
277
+ */
278
+ attachSignatureToTx(unsignedTx: UnsignedTaprootTx, signatureHex: string | string[]): SignedTaprootTx;
279
+ /**
280
+ * Parse signature hex into per-input signatures.
281
+ * Supports: single sig (applied to all inputs), comma-separated, or concatenated.
282
+ */
283
+ private parseSignatures;
284
+ /**
285
+ * Broadcast a signed Taproot transaction to the Bitcoin network.
286
+ *
287
+ * Accepts either a raw Bitcoin transaction hex or the hex-encoded JSON
288
+ * format from attachSignature().
289
+ *
290
+ * @param signedTx - Hex-encoded signed transaction
291
+ * @returns Transaction ID (txid)
292
+ */
293
+ broadcast(signedTx: string): Promise<string>;
294
+ /**
295
+ * Get transaction details by txid.
296
+ *
297
+ * @param txid - Transaction ID
298
+ * @returns Transaction data or null if not found
299
+ */
300
+ getTransaction(txid: string): Promise<any | null>;
301
+ /**
302
+ * Get the current block height.
303
+ */
304
+ getBlockHeight(): Promise<number>;
305
+ /**
306
+ * Check if an address is a valid Taproot (P2TR) address.
307
+ */
308
+ isTaprootAddress(address: string): boolean;
309
+ /**
310
+ * Convert a Taproot address to its scriptPubKey.
311
+ * P2TR scriptPubKey: OP_1 (0x51) + PUSH32 (0x20) + <32-byte witness program>
312
+ */
313
+ addressToScriptPubkey(address: string): string;
314
+ private selectUTXOs;
315
+ /**
316
+ * Serialize an unsigned Taproot transaction.
317
+ *
318
+ * Bitcoin transaction format (segwit):
319
+ * - Version (4 bytes LE)
320
+ * - Marker + Flag (00 01 for segwit)
321
+ * - Input count (varint)
322
+ * - Inputs (outpoint + empty scriptSig + sequence)
323
+ * - Output count (varint)
324
+ * - Outputs (value + scriptPubkey)
325
+ * - Witness (placeholder for signing)
326
+ * - Locktime (4 bytes LE)
327
+ */
328
+ private serializeUnsignedTx;
329
+ /**
330
+ * Serialize a signed Taproot transaction with per-input signatures.
331
+ *
332
+ * @param unsignedTx - The unsigned transaction data
333
+ * @param signatures - Array of per-input signature hex strings (128 chars each)
334
+ */
335
+ private serializeSignedTx;
336
+ /**
337
+ * Compute the BIP-341 Taproot sighash for key-path spend.
338
+ *
339
+ * The sighash message for SIGHASH_DEFAULT (0x00) includes:
340
+ * - Epoch (0x00)
341
+ * - Sighash type (0x00)
342
+ * - Transaction version (4 bytes LE)
343
+ * - Locktime (4 bytes LE)
344
+ * - SHA-256 of prevouts
345
+ * - SHA-256 of amounts
346
+ * - SHA-256 of scriptPubKeys
347
+ * - SHA-256 of sequences
348
+ * - SHA-256 of outputs
349
+ * - Spend type (0x00 for key-path, no annex)
350
+ * - Input index (4 bytes LE)
351
+ */
352
+ /**
353
+ * Compute all per-input BIP-341 sighashes for the transaction.
354
+ *
355
+ * Each input has its own sighash because the input_index field differs.
356
+ * The common transaction-level hashes (prevouts, amounts, scripts, sequences,
357
+ * outputs) are precomputed once and reused across all inputs.
358
+ *
359
+ * @returns Array of hex-encoded sighashes, one per input
360
+ */
361
+ private computeAllSighashes;
362
+ }
363
+ /**
364
+ * Create a Bitcoin Taproot adapter for mainnet.
365
+ */
366
+ export declare function createBitcoinTaprootAdapter(options?: Omit<BitcoinTaprootOptions, 'network'>): BitcoinTaprootAdapter;
367
+ /**
368
+ * Create a Bitcoin Taproot adapter for testnet.
369
+ */
370
+ export declare function createBitcoinTestnetTaprootAdapter(options?: Omit<BitcoinTaprootOptions, 'network'>): BitcoinTaprootAdapter;
371
+ //# sourceMappingURL=bitcoin-taproot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitcoin-taproot.d.ts","sourceRoot":"","sources":["../../src/chains/bitcoin-taproot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK7D,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE1E,gCAAgC;AAChC,MAAM,WAAW,WAAW;IACxB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,0BAA0B;IAC1B,MAAM,EAAE;QACJ,SAAS,E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