@lifi/sdk-provider-bitcoin 4.0.0-beta.8 → 4.0.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.
- package/CHANGELOG.md +16 -0
- package/README.md +88 -5
- package/dist/cjs/BitcoinProvider.js +0 -1
- package/dist/cjs/BitcoinProvider.js.map +1 -1
- package/dist/cjs/actions/getBitcoinBalance.js +0 -1
- package/dist/cjs/actions/getBitcoinBalance.js.map +1 -1
- package/dist/cjs/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/cjs/client/publicClient.js +0 -1
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/BitcoinStepExecutor.js +0 -1
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +0 -1
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/errors/parseBitcoinErrors.js +0 -1
- package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/cjs/types.js +0 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/generateRedeemScript.js +0 -1
- package/dist/cjs/utils/generateRedeemScript.js.map +1 -1
- package/dist/cjs/utils/isPsbtFinalized.js.map +1 -1
- package/dist/cjs/utils/toBigmiChainId.js +0 -1
- package/dist/cjs/utils/toBigmiChainId.js.map +1 -1
- package/dist/cjs/utils/toXOnly.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/BitcoinProvider.js.map +1 -1
- package/dist/esm/actions/getBitcoinBalance.js.map +1 -1
- package/dist/esm/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/esm/client/publicClient.js.map +1 -1
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/generateRedeemScript.js.map +1 -1
- package/dist/esm/utils/isPsbtFinalized.d.ts.map +1 -1
- package/dist/esm/utils/isPsbtFinalized.js.map +1 -1
- package/dist/esm/utils/toBigmiChainId.js.map +1 -1
- package/dist/esm/utils/toXOnly.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +4 -3
- package/src/version.ts +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @lifi/sdk-provider-bitcoin
|
|
2
|
+
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#398](https://github.com/lifinance/sdk/pull/398) [`e4e4600`](https://github.com/lifinance/sdk/commit/e4e460063aa22d672f1ea3fd26ffa9faf2655398) Thanks [@chybisov](https://github.com/chybisov)! - Bump @bigmi/core to 0.8.1.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @lifi/sdk@4.0.0
|
|
11
|
+
|
|
12
|
+
## 4.0.0-beta.12
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#398](https://github.com/lifinance/sdk/pull/398) [`e4e4600`](https://github.com/lifinance/sdk/commit/e4e460063aa22d672f1ea3fd26ffa9faf2655398) Thanks [@chybisov](https://github.com/chybisov)! - Bump @bigmi/core to 0.8.1.
|
package/README.md
CHANGED
|
@@ -13,18 +13,23 @@
|
|
|
13
13
|
|
|
14
14
|
[**LI.FI SDK**](https://docs.li.fi/sdk/overview) features include:
|
|
15
15
|
|
|
16
|
+
- **Modular architecture** - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron)
|
|
16
17
|
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
|
|
17
18
|
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
|
|
18
19
|
- Easy tracking of the route and quote execution through the robust event and hooks handling
|
|
19
20
|
- Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
|
|
20
21
|
- Supports widely adopted industry standards, including [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
|
|
21
|
-
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/), [
|
|
22
|
+
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/) for EVM, [Solana Kit](https://github.com/solana-labs/solana-web3.js) for Solana, [Bigmi](https://github.com/lifinance/bigmi) for Bitcoin, [Mysten Sui SDK](https://github.com/MystenLabs/sui/tree/main/sdk) for Sui, [TronWeb](https://tronweb.network/) for Tron)
|
|
22
23
|
- Support for arbitrary contract calls on the destination chain
|
|
23
24
|
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
|
|
24
25
|
- Compatibility tested with Node.js and popular front-end tools like Vite
|
|
25
26
|
|
|
26
27
|
## Installation
|
|
27
28
|
|
|
29
|
+
The LI.FI SDK follows a modular architecture. Install the core SDK package and the provider packages for the blockchain ecosystems you need:
|
|
30
|
+
|
|
31
|
+
### Core SDK
|
|
32
|
+
|
|
28
33
|
```bash
|
|
29
34
|
pnpm add @lifi/sdk
|
|
30
35
|
```
|
|
@@ -35,17 +40,95 @@ or
|
|
|
35
40
|
npm install --save @lifi/sdk
|
|
36
41
|
```
|
|
37
42
|
|
|
43
|
+
### Provider Packages
|
|
44
|
+
|
|
45
|
+
Install provider packages based on the blockchain ecosystems you want to support:
|
|
46
|
+
|
|
47
|
+
**EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)**
|
|
48
|
+
```bash
|
|
49
|
+
pnpm add @lifi/sdk-provider-ethereum
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Solana**
|
|
53
|
+
```bash
|
|
54
|
+
pnpm add @lifi/sdk-provider-solana
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Bitcoin**
|
|
58
|
+
```bash
|
|
59
|
+
pnpm add @lifi/sdk-provider-bitcoin
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Sui**
|
|
63
|
+
```bash
|
|
64
|
+
pnpm add @lifi/sdk-provider-sui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Tron**
|
|
68
|
+
```bash
|
|
69
|
+
pnpm add @lifi/sdk-provider-tron
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Architecture
|
|
73
|
+
|
|
74
|
+
The LI.FI SDK uses a modular provider architecture:
|
|
75
|
+
|
|
76
|
+
- **`@lifi/sdk`** - Core SDK package containing shared functionality, actions, and execution logic
|
|
77
|
+
- **Provider packages** - Ecosystem-specific packages that handle wallet interactions and transaction execution for different blockchain types
|
|
78
|
+
|
|
79
|
+
This architecture allows you to:
|
|
80
|
+
- Install only the providers you need, reducing bundle size
|
|
81
|
+
- Use ecosystem-specific libraries optimized for each blockchain
|
|
82
|
+
- Maintain clean separation between core SDK logic and blockchain-specific implementations
|
|
83
|
+
|
|
38
84
|
## Quick Start
|
|
39
85
|
|
|
40
86
|
### Set up the SDK
|
|
41
87
|
|
|
42
|
-
|
|
88
|
+
Create SDK config with your integrator string and configure the providers for the blockchain ecosystems you want to support.
|
|
43
89
|
|
|
90
|
+
**For EVM chains:**
|
|
44
91
|
```ts
|
|
45
|
-
import {
|
|
92
|
+
import { createClient } from '@lifi/sdk'
|
|
93
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
94
|
+
import { createWalletClient, http } from 'viem'
|
|
95
|
+
import { mainnet } from 'viem/chains'
|
|
96
|
+
|
|
97
|
+
// Add your account (e.g. privateKeyToAccount, mnemonicToAccount)
|
|
98
|
+
const walletClient = createWalletClient({
|
|
99
|
+
account,
|
|
100
|
+
chain: mainnet,
|
|
101
|
+
transport: http(),
|
|
102
|
+
})
|
|
46
103
|
|
|
47
|
-
|
|
104
|
+
const client = createClient({
|
|
105
|
+
integrator: 'Your dApp/company name',
|
|
106
|
+
providers: [
|
|
107
|
+
EthereumProvider({
|
|
108
|
+
getWalletClient: () => Promise.resolve(walletClient),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**For multiple ecosystems:**
|
|
115
|
+
```ts
|
|
116
|
+
import { createClient } from '@lifi/sdk'
|
|
117
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
118
|
+
import { SolanaProvider } from '@lifi/sdk-provider-solana'
|
|
119
|
+
import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
120
|
+
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
121
|
+
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
122
|
+
|
|
123
|
+
const client = createClient({
|
|
48
124
|
integrator: 'Your dApp/company name',
|
|
125
|
+
providers: [
|
|
126
|
+
EthereumProvider({ /* options */ }),
|
|
127
|
+
SolanaProvider({ /* options */ }),
|
|
128
|
+
BitcoinProvider({ /* options */ }),
|
|
129
|
+
SuiProvider({ /* options */ }),
|
|
130
|
+
TronProvider({ /* options */ }),
|
|
131
|
+
],
|
|
49
132
|
})
|
|
50
133
|
```
|
|
51
134
|
|
|
@@ -56,7 +139,7 @@ Now you can interact with the SDK and for example request a quote.
|
|
|
56
139
|
```ts
|
|
57
140
|
import { ChainId, getQuote } from '@lifi/sdk'
|
|
58
141
|
|
|
59
|
-
const quote = await getQuote({
|
|
142
|
+
const quote = await getQuote(client, {
|
|
60
143
|
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
61
144
|
fromChain: ChainId.ARB,
|
|
62
145
|
toChain: ChainId.OPT,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./_virtual/_rolldown/runtime.js");
|
|
3
2
|
const require_actions_getBitcoinBalance = require("./actions/getBitcoinBalance.js");
|
|
4
3
|
const require_actions_resolveBitcoinAddress = require("./actions/resolveBitcoinAddress.js");
|
|
5
4
|
const require_core_BitcoinStepExecutor = require("./core/BitcoinStepExecutor.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinProvider.js","names":["ChainType","isUTXOAddress","resolveBitcoinAddress","getBitcoinBalance","BitcoinStepExecutor"],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BitcoinProvider.js","names":["ChainType","isUTXOAddress","resolveBitcoinAddress","getBitcoinBalance","BitcoinStepExecutor"],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;EACnB;EACA,WAAWC,YAAAA;EACX,gBAAgBC,sCAAAA;EAChB,YAAYC,kCAAAA;EACZ,MAAM,gBACJ,SAC8B;GAC9B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,yBAAyB;GAa3C,OAAO,IARcC,iCAAAA,oBAAoB;IACvC,QAAQ,MAHiB,SAAS,gBAAgB;IAIlD,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../_virtual/_rolldown/runtime.js");
|
|
3
2
|
const require_client_publicClient = require("../client/publicClient.js");
|
|
4
3
|
let _lifi_sdk = require("@lifi/sdk");
|
|
5
4
|
//#region src/actions/getBitcoinBalance.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBitcoinBalance.js","names":["getBitcoinPublicClient","ChainId"],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getBitcoinBalance.js","names":["getBitcoinPublicClient","ChainId"],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAEV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAGjE,MAAM,cAAc,MAAMA,4BAAAA,uBAAuB,QAAQC,UAAAA,QAAQ,GAAG;CACpE,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,WAAW,CACrD,YAAY,WAAW,EAAE,SAAS,cAAc,CAAC,GACjD,YAAY,cAAc,CAC5B,CAAC;CAED,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,IAAI,QAAQ,WAAW,aAGrB,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH;CACF,EAAE;CAGJ,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,QAAQ,QAAQ;EAChB;CACF,EAAE;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";;AAAA,eAAsB,sBACpB,MAC6B;
|
|
1
|
+
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";;AAAA,eAAsB,sBACpB,MAC6B;CAE7B,OAAO;AACT"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../_virtual/_rolldown/runtime.js");
|
|
3
2
|
const require_utils_toBigmiChainId = require("../utils/toBigmiChainId.js");
|
|
4
3
|
let _bigmi_core = require("@bigmi/core");
|
|
5
4
|
//#region src/client/publicClient.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,GACrB,KAAK,SAAA,GAAA,YAAA,MAC9B,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,YAAA,GAAA,YAAA,cAbmB;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAIA,6BAAAA,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,YAAA,GAAA,YAAA,WAAiC;GACjC,YAAA,GAAA,YAAA,UAAoB;gCACP;iCACC;6BACJ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,EACE,OAAOC,YAAAA,aAAa,EACpB,OAAOC,YAAAA,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../_virtual/_rolldown/runtime.js");
|
|
3
2
|
const require_client_publicClient = require("../client/publicClient.js");
|
|
4
3
|
const require_errors_parseBitcoinErrors = require("../errors/parseBitcoinErrors.js");
|
|
5
4
|
const require_core_tasks_BitcoinSignAndExecuteTask = require("./tasks/BitcoinSignAndExecuteTask.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","CheckBalanceTask","PrepareTransactionTask","BitcoinSignAndExecuteTask","BitcoinWaitForTransactionTask","WaitForTransactionStatusTask","TaskPipeline","parseBitcoinErrors","getBitcoinPublicClient"],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BitcoinStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","CheckBalanceTask","PrepareTransactionTask","BitcoinSignAndExecuteTask","BitcoinWaitForTransactionTask","WaitForTransactionStatusTask","TaskPipeline","parseBitcoinErrors","getBitcoinPublicClient"],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;;AAyBA,IAAa,sBAAb,cAAyCA,UAAAA,iBAAiB;CACxD;CAEA,YAAY,SAAqC;EAC/C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IAAI,KAAK,OAAO,SAAS,YAAY,KAAK,OAAO,aAC/C,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;CAEJ;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAIC,UAAAA,iBAAiB;GACrB,IAAIC,UAAAA,uBAAuB;GAC3B,IAAIC,6CAAAA,0BAA0B;GAC9B,IAAIC,iDAAAA,8BAA8B;GAClC,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EACA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,WAAW,oBAAoB,SACjC,oBAAoB,WAAW,SAC7BA,UAAAA,6BAA6B,OAC7BD,iDAAAA,8BAA8B,OAChCH,UAAAA,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAIA,OAAO,IAAIK,UAAAA,aAFQ,MAAM,MAAM,cAEE,CAAC;CACpC;CAEA,eACE,OACA,MACA,WACsBC,kCAAAA,mBAAmB,OAAO,MAAM,MAAM;CAE9D,gBAAyB,OACvB,gBACwC;EACxC,MAAM,EAAE,QAAQ,cAAc;EAE9B,MAAM,eAAe,MAAMC,4BAAAA,uBAAuB,QAAQ,UAAU,EAAE;EAEtE,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAGF,MAAM,yBAAyB,OAAA,GAAA,UAAA,2BAC7B,MACA,gBACF;EAEA,YAAY,IAAI;EAEhB,MAAM,UAAU;EAIhB,CAAA,GAAA,cAAA,YAAWC,uBAAG;EAEd,MAAM,OAAOC,cAAAA,KAAK,QAAQ,SAAS,EAAE,SAASC,cAAAA,SAAS,QAAQ,CAAC;EAEhE,KAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,eAAA,GAAA,YAAA,gBAHiB,MAAM,cACzBC,cAAAA,QAAQ,iBAAiB,MAAM,YAAY,QAAQD,cAAAA,SAAS,OAAO,IAClE,aAAa,SAAS,OACsB;GACjD,IAAI,YAAY,SAASE,YAAAA,YAAY,MAAM;IAKzC,IAAI,CAAC,MAAM,gBAAgB;KACzB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QAAQ;MACV,MAAM,iBAAiBC,sBAAAA,SAAAA,GAAAA,YAAAA,iBAAwB,MAAM,CAAC;MACtD,KAAK,YAAY,OAAO,EACtB,eACF,CAAC;KACH;IACF;IAGA,IAAI,CAAC,MAAM,aACT,KAAK,YAAY,OAAO,EACtB,aAAa,EACf,CAAC;GAEL;GAEA,IAAI,YAAY,SAASD,YAAAA,YAAY;QAC/B,CAAC,MAAM,cAAc;KACvB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QACF,KAAK,YAAY,OAAO,EACtB,cAAcE,mCAAAA,sBAAAA,GAAAA,YAAAA,iBAAqC,MAAM,CAAC,EAC5D,CAAC;IAEL;;EAEJ,CAAC;EAED,MAAM,eAAe,MAAM,KACzB,KAAK,KAAK,OACP,QAAQ,KAAK,OAAO,UAAU;GAC7B,MAAM,iBAAiB,MAAM,cACzBH,cAAAA,QAAQ,iBACN,MAAM,YAAY,QAClBD,cAAAA,SAAS,OACX,IACC,aAAa,SAAS;GAC3B,IAAI,IAAI,IAAI,cAAc,GACxB,IAAI,IAAI,cAAc,EAAG,eAAe,KAAK,KAAK;QAElD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,KAAK;GACxB,CAAC;GAEH,OAAO;EACT,mBAAG,IAAI,IAGL,CAAC,EACF,OAAO,CACZ;EAGA,MAAM,gBAAgB,OAAA,GAAA,YAAA,oBAAA,GAAA,YAAA,UAET,cAAc;GACrB,MAAM,KAAK,MAAM;GACH;GACd,UAAU;EACZ,CAAC,GACH;GACE,SAAS;GACT,eAAe,IAAIJ,UAAAA,iBACjBC,UAAAA,cAAc,oBACd,0BACF;EACF,CACF;EAEA,MAAM,aAAaE,cAAAA,KAAK,QAAQ,aAAa;EAE7C,IAAI,CAACM,8BAAAA,gBAAgB,UAAU,GAC7B,WAAW,kBAAkB;EAG/B,MAAM,QAAQ,WAAW,mBAAmB,EAAE,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;AAUA,IAAa,gCAAb,cAAmDA,UAAAA,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,oEACF;EAGF,YAAY,IAAI;EAEhB,IAAI;EACJ,MAAM,cAAc,OAAA,GAAA,YAAA,oBAAyB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;IAC/E,CAAC;GACH;EACF,CAAC;EAED,IAAI,sBAAsB,aACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,4BACF;EAGF,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;EACtE,CAAC;EAGH,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.js","names":["SDKError","TransactionError","LiFiErrorCode","BaseError","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.js","names":["SDKError","TransactionError","LiFiErrorCode","BaseError","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;CACtB,IAAI,aAAaA,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAIA,OAAO,IAAIA,UAAAA,SAFO,qBAAqB,CAEX,GAAG,MAAM,MAAM;AAC7C;AAEA,MAAM,wBAAwB,MAAW;CAEvC,IACE,EAAE,SAAS,WAAW,UAAU,KAChC,EAAE,OAAO,SAAS,WAAW,UAAU,GAEvC,OAAO,IAAIC,UAAAA,iBACTC,UAAAA,cAAc,qBACd,0IACA,CACF;CAEF,IAAI,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAU,EAAE,OAAO,WAAW,UAAU,GACxE,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAE3E,IAAI,EAAE,SAAS,MAAM,EAAE,SAAS,UAAU,EAAE,SAAS,QACnD,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,UAAU,EAAE,SAAS,CAAC;CAGlE,IAAI,aAAaC,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIC,UAAAA,aAAa,EAAE,WAAWC,UAAAA,aAAa,cAAc,CAAC;AACnE"}
|
package/dist/cjs/types.js
CHANGED
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;;AAuBA,SAAgB,kBACd,UACgC;CAChC,OAAO,SAAS,SAASA,UAAAA,UAAU;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRedeemScript.js","names":["payments"],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateRedeemScript.js","names":["payments"],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;;AAOA,MAAa,wBACX,cAGAA,cAAAA,SAAS,OAAO,EAAE,QAAQ,UAAU,CAAC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";;AAEA,SAAgB,gBAAgB,MAAqB;
|
|
1
|
+
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";;AAEA,SAAgB,gBAAgB,MAAqB;CACnD,IAAI;EACF,KAAK,mBAAmB;EACxB,OAAO;CACT,SAAS,GAAG;EACV,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;;AAGA,MAAa,kBAAkB,YAAmC;CAChE,QAAQ,SAAR;EACE,KAAKA,UAAAA,QAAQ,KACX,OAAOC,YAAAA,QAAa;EACtB,SACE,MAAM,IAAI,MAAM,gCAAgC,SAAS;CAC7D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toXOnly.js","names":[],"sources":["../../../src/utils/toXOnly.ts"],"sourcesContent":["// helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update\nexport const toXOnly = (pubKey: Uint8Array): Uint8Array =>\n pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)\n"],"mappings":";;AACA,MAAa,WAAW,WACtB,OAAO,WAAW,KAAK,SAAS,OAAO,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"toXOnly.js","names":[],"sources":["../../../src/utils/toXOnly.ts"],"sourcesContent":["// helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update\nexport const toXOnly = (pubKey: Uint8Array): Uint8Array =>\n pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)\n"],"mappings":";;AACA,MAAa,WAAW,WACtB,OAAO,WAAW,KAAK,SAAS,OAAO,SAAS,GAAG,EAAE"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/version.ts
|
|
3
3
|
const name = "@lifi/sdk-provider-bitcoin";
|
|
4
|
-
const version = "4.0.0
|
|
4
|
+
const version = "4.0.0";
|
|
5
5
|
//#endregion
|
|
6
6
|
exports.name = name;
|
|
7
7
|
exports.version = version;
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinProvider.js","names":[],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,
|
|
1
|
+
{"version":3,"file":"BitcoinProvider.js","names":[],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,YAAY;EACZ,MAAM,gBACJ,SAC8B;GAC9B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,yBAAyB;GAa3C,OAAO,IARc,oBAAoB;IACvC,QAAQ,MAHiB,SAAS,gBAAgB;IAIlD,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBitcoinBalance.js","names":[],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;
|
|
1
|
+
{"version":3,"file":"getBitcoinBalance.js","names":[],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAEV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAGjE,MAAM,cAAc,MAAM,uBAAuB,QAAQ,QAAQ,GAAG;CACpE,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,WAAW,CACrD,YAAY,WAAW,EAAE,SAAS,cAAc,CAAC,GACjD,YAAY,cAAc,CAC5B,CAAC;CAED,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,IAAI,QAAQ,WAAW,aAGrB,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH;CACF,EAAE;CAGJ,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,QAAQ,QAAQ;EAChB;CACF,EAAE;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";AAAA,eAAsB,sBACpB,MAC6B;
|
|
1
|
+
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";AAAA,eAAsB,sBACpB,MAC6B;CAE7B,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,
|
|
1
|
+
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,GACrB,KAAK,QACnC,KAAK,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,WAbM,aAAa;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAI,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,WAAW,UAAsB;GACjC,WAAW,SAAS;IAClB,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,EACE,OAAO,aAAa,EACpB,OAAO,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinStepExecutor.js","names":[],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,sBAAb,cAAyC,iBAAiB;CACxD;CAEA,YAAY,SAAqC;
|
|
1
|
+
{"version":3,"file":"BitcoinStepExecutor.js","names":[],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,sBAAb,cAAyC,iBAAiB;CACxD;CAEA,YAAY,SAAqC;EAC/C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IAAI,KAAK,OAAO,SAAS,YAAY,KAAK,OAAO,aAC/C,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,0BAA0B;GAC9B,IAAI,8BAA8B;GAClC,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EACA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,WAAW,oBAAoB,SACjC,oBAAoB,WAAW,SAC7B,6BAA6B,OAC7B,8BAA8B,OAChC,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAIA,OAAO,IAAI,aAFQ,MAAM,MAAM,cAEE,CAAC;CACpC;CAEA,eACE,OACA,MACA,WACsB,mBAAmB,OAAO,MAAM,MAAM;CAE9D,gBAAyB,OACvB,gBACwC;EACxC,MAAM,EAAE,QAAQ,cAAc;EAE9B,MAAM,eAAe,MAAM,uBAAuB,QAAQ,UAAU,EAAE;EAEtE,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,yBAAyB,MAAM,0BACnC,MACA,gBACF;EAEA,YAAY,IAAI;EAEhB,MAAM,UAAU;EAIhB,WAAW,GAAG;EAEd,MAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,SAAS,SAAS,QAAQ,CAAC;EAEhE,KAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,cAAc,eAHG,MAAM,cACzB,QAAQ,iBAAiB,MAAM,YAAY,QAAQ,SAAS,OAAO,IAClE,aAAa,SAAS,OACsB;GACjD,IAAI,YAAY,SAAS,YAAY,MAAM;IAKzC,IAAI,CAAC,MAAM,gBAAgB;KACzB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QAAQ;MACV,MAAM,iBAAiB,QAAQ,gBAAgB,MAAM,CAAC;MACtD,KAAK,YAAY,OAAO,EACtB,eACF,CAAC;KACH;IACF;IAGA,IAAI,CAAC,MAAM,aACT,KAAK,YAAY,OAAO,EACtB,aAAa,EACf,CAAC;GAEL;GAEA,IAAI,YAAY,SAAS,YAAY;QAC/B,CAAC,MAAM,cAAc;KACvB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QACF,KAAK,YAAY,OAAO,EACtB,cAAc,qBAAqB,gBAAgB,MAAM,CAAC,EAC5D,CAAC;IAEL;;EAEJ,CAAC;EAED,MAAM,eAAe,MAAM,KACzB,KAAK,KAAK,OACP,QAAQ,KAAK,OAAO,UAAU;GAC7B,MAAM,iBAAiB,MAAM,cACzB,QAAQ,iBACN,MAAM,YAAY,QAClB,SAAS,OACX,IACC,aAAa,SAAS;GAC3B,IAAI,IAAI,IAAI,cAAc,GACxB,IAAI,IAAI,cAAc,EAAG,eAAe,KAAK,KAAK;QAElD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,KAAK;GACxB,CAAC;GAEH,OAAO;EACT,mBAAG,IAAI,IAGL,CAAC,EACF,OAAO,CACZ;EAGA,MAAM,gBAAgB,MAAM,kBAExB,SAAS,cAAc;GACrB,MAAM,KAAK,MAAM;GACH;GACd,UAAU;EACZ,CAAC,GACH;GACE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,0BACF;EACF,CACF;EAEA,MAAM,aAAa,KAAK,QAAQ,aAAa;EAE7C,IAAI,CAAC,gBAAgB,UAAU,GAC7B,WAAW,kBAAkB;EAG/B,MAAM,QAAQ,WAAW,mBAAmB,EAAE,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AAUA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AAUA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAI,iBACR,cAAc,uBACd,oEACF;EAGF,YAAY,IAAI;EAEhB,IAAI;EACJ,MAAM,cAAc,MAAM,mBAAmB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;IAC/E,CAAC;GACH;EACF,CAAC;EAED,IAAI,sBAAsB,aACxB,MAAM,IAAI,iBACR,cAAc,qBACd,4BACF;EAGF,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;EACtE,CAAC;EAGH,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.js","names":[],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.js","names":[],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;CACtB,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAIA,OAAO,IAAI,SAFO,qBAAqB,CAEX,GAAG,MAAM,MAAM;AAC7C;AAEA,MAAM,wBAAwB,MAAW;CAEvC,IACE,EAAE,SAAS,WAAW,UAAU,KAChC,EAAE,OAAO,SAAS,WAAW,UAAU,GAEvC,OAAO,IAAI,iBACT,cAAc,qBACd,0IACA,CACF;CAEF,IAAI,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAU,EAAE,OAAO,WAAW,UAAU,GACxE,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAE3E,IAAI,EAAE,SAAS,MAAM,EAAE,SAAS,UAAU,EAAE,SAAS,QACnD,OAAO,IAAI,iBAAiB,cAAc,UAAU,EAAE,SAAS,CAAC;CAGlE,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE"}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;AAuBA,SAAgB,kBACd,UACgC;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;AAuBA,SAAgB,kBACd,UACgC;CAChC,OAAO,SAAS,SAAS,UAAU;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRedeemScript.js","names":[],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;AAOA,MAAa,wBACX,cAGA,SAAS,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"generateRedeemScript.js","names":[],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;AAOA,MAAa,wBACX,cAGA,SAAS,OAAO,EAAE,QAAQ,UAAU,CAAC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPsbtFinalized.d.ts","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"mappings":";;;iBAEgB,eAAA,CAAgB,
|
|
1
|
+
{"version":3,"file":"isPsbtFinalized.d.ts","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"mappings":";;;iBAEgB,eAAA,CAAgB,IAAM,EAAA,IAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";AAEA,SAAgB,gBAAgB,MAAqB;
|
|
1
|
+
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";AAEA,SAAgB,gBAAgB,MAAqB;CACnD,IAAI;EACF,KAAK,mBAAmB;EACxB,OAAO;CACT,SAAS,GAAG;EACV,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;AAGA,MAAa,kBAAkB,YAAmC;
|
|
1
|
+
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;AAGA,MAAa,kBAAkB,YAAmC;CAChE,QAAQ,SAAR;EACE,KAAKA,UAAQ,KACX,OAAOC,QAAa;EACtB,SACE,MAAM,IAAI,MAAM,gCAAgC,SAAS;CAC7D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toXOnly.js","names":[],"sources":["../../../src/utils/toXOnly.ts"],"sourcesContent":["// helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update\nexport const toXOnly = (pubKey: Uint8Array): Uint8Array =>\n pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)\n"],"mappings":";AACA,MAAa,WAAW,WACtB,OAAO,WAAW,KAAK,SAAS,OAAO,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"toXOnly.js","names":[],"sources":["../../../src/utils/toXOnly.ts"],"sourcesContent":["// helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update\nexport const toXOnly = (pubKey: Uint8Array): Uint8Array =>\n pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)\n"],"mappings":";AACA,MAAa,WAAW,WACtB,OAAO,WAAW,KAAK,SAAS,OAAO,SAAS,GAAG,EAAE"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-bitcoin",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "LI.FI Bitcoin SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,16 +28,17 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bigmi/core": "^0.8.
|
|
31
|
+
"@bigmi/core": "^0.8.1",
|
|
32
32
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
33
33
|
"bech32": "^2.0.0",
|
|
34
34
|
"bitcoinjs-lib": "^7.0.1",
|
|
35
|
-
"@lifi/sdk": "4.0.0
|
|
35
|
+
"@lifi/sdk": "4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
|
+
"CHANGELOG.md",
|
|
41
42
|
"dist/**",
|
|
42
43
|
"!dist/**/*.tsbuildinfo",
|
|
43
44
|
"src/**/*.ts",
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-bitcoin'
|
|
2
|
-
export const version = '4.0.0
|
|
2
|
+
export const version = '4.0.0'
|