@lifi/sdk-provider-bitcoin 4.0.1-alpha.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +88 -5
  3. package/dist/cjs/BitcoinProvider.d.ts +7 -2
  4. package/dist/cjs/BitcoinProvider.js +30 -34
  5. package/dist/cjs/BitcoinProvider.js.map +1 -1
  6. package/dist/cjs/_virtual/_rolldown/runtime.js +23 -0
  7. package/dist/cjs/actions/getBitcoinBalance.d.ts +7 -2
  8. package/dist/cjs/actions/getBitcoinBalance.js +21 -24
  9. package/dist/cjs/actions/getBitcoinBalance.js.map +1 -1
  10. package/dist/cjs/actions/resolveBitcoinAddress.d.ts +5 -1
  11. package/dist/cjs/actions/resolveBitcoinAddress.js +6 -4
  12. package/dist/cjs/actions/resolveBitcoinAddress.js.map +1 -1
  13. package/dist/cjs/client/publicClient.d.ts +14 -4
  14. package/dist/cjs/client/publicClient.js +38 -42
  15. package/dist/cjs/client/publicClient.js.map +1 -1
  16. package/dist/cjs/core/BitcoinStepExecutor.d.ts +19 -0
  17. package/dist/cjs/core/BitcoinStepExecutor.js +47 -0
  18. package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -0
  19. package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
  20. package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js +75 -0
  21. package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
  22. package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
  23. package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +38 -0
  24. package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
  25. package/dist/cjs/errors/parseBitcoinErrors.d.ts +7 -2
  26. package/dist/cjs/errors/parseBitcoinErrors.js +17 -26
  27. package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
  28. package/dist/cjs/index.d.ts +3 -3
  29. package/dist/cjs/index.js +5 -8
  30. package/dist/cjs/types.d.ts +18 -7
  31. package/dist/cjs/types.js +7 -5
  32. package/dist/cjs/types.js.map +1 -1
  33. package/dist/cjs/utils/generateRedeemScript.d.ts +10 -1
  34. package/dist/cjs/utils/generateRedeemScript.js +11 -5
  35. package/dist/cjs/utils/generateRedeemScript.js.map +1 -1
  36. package/dist/cjs/utils/isPsbtFinalized.d.ts +7 -2
  37. package/dist/cjs/utils/isPsbtFinalized.js +11 -10
  38. package/dist/cjs/utils/isPsbtFinalized.js.map +1 -1
  39. package/dist/cjs/utils/toBigmiChainId.d.ts +8 -3
  40. package/dist/cjs/utils/toBigmiChainId.js +10 -11
  41. package/dist/cjs/utils/toBigmiChainId.js.map +1 -1
  42. package/dist/cjs/utils/toXOnly.d.ts +5 -1
  43. package/dist/cjs/utils/toXOnly.js +4 -3
  44. package/dist/cjs/utils/toXOnly.js.map +1 -1
  45. package/dist/cjs/version.d.ts +6 -2
  46. package/dist/cjs/version.js +8 -5
  47. package/dist/cjs/version.js.map +1 -1
  48. package/dist/esm/BitcoinProvider.d.ts +7 -2
  49. package/dist/esm/BitcoinProvider.d.ts.map +1 -0
  50. package/dist/esm/BitcoinProvider.js +30 -32
  51. package/dist/esm/BitcoinProvider.js.map +1 -1
  52. package/dist/esm/actions/getBitcoinBalance.d.ts +7 -2
  53. package/dist/esm/actions/getBitcoinBalance.d.ts.map +1 -0
  54. package/dist/esm/actions/getBitcoinBalance.js +22 -22
  55. package/dist/esm/actions/getBitcoinBalance.js.map +1 -1
  56. package/dist/esm/actions/resolveBitcoinAddress.d.ts +5 -1
  57. package/dist/esm/actions/resolveBitcoinAddress.d.ts.map +1 -0
  58. package/dist/esm/actions/resolveBitcoinAddress.js +6 -3
  59. package/dist/esm/actions/resolveBitcoinAddress.js.map +1 -1
  60. package/dist/esm/client/publicClient.d.ts +13 -9
  61. package/dist/esm/client/publicClient.d.ts.map +1 -0
  62. package/dist/esm/client/publicClient.js +38 -46
  63. package/dist/esm/client/publicClient.js.map +1 -1
  64. package/dist/esm/core/BitcoinStepExecutor.d.ts +19 -0
  65. package/dist/esm/core/BitcoinStepExecutor.d.ts.map +1 -0
  66. package/dist/esm/core/BitcoinStepExecutor.js +46 -0
  67. package/dist/esm/core/BitcoinStepExecutor.js.map +1 -0
  68. package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
  69. package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +1 -0
  70. package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js +72 -0
  71. package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
  72. package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
  73. package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts.map +1 -0
  74. package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js +37 -0
  75. package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
  76. package/dist/esm/errors/parseBitcoinErrors.d.ts +7 -2
  77. package/dist/esm/errors/parseBitcoinErrors.d.ts.map +1 -0
  78. package/dist/esm/errors/parseBitcoinErrors.js +17 -24
  79. package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
  80. package/dist/esm/index.d.ts +3 -3
  81. package/dist/esm/index.js +3 -4
  82. package/dist/esm/package.json +1 -1
  83. package/dist/esm/types.d.ts +18 -7
  84. package/dist/esm/types.d.ts.map +1 -0
  85. package/dist/esm/types.js +7 -3
  86. package/dist/esm/types.js.map +1 -1
  87. package/dist/esm/utils/generateRedeemScript.d.ts +9 -5
  88. package/dist/esm/utils/generateRedeemScript.d.ts.map +1 -0
  89. package/dist/esm/utils/generateRedeemScript.js +10 -8
  90. package/dist/esm/utils/generateRedeemScript.js.map +1 -1
  91. package/dist/esm/utils/isPsbtFinalized.d.ts +7 -2
  92. package/dist/esm/utils/isPsbtFinalized.d.ts.map +1 -0
  93. package/dist/esm/utils/isPsbtFinalized.js +11 -8
  94. package/dist/esm/utils/isPsbtFinalized.js.map +1 -1
  95. package/dist/esm/utils/toBigmiChainId.d.ts +8 -3
  96. package/dist/esm/utils/toBigmiChainId.d.ts.map +1 -0
  97. package/dist/esm/utils/toBigmiChainId.js +11 -9
  98. package/dist/esm/utils/toBigmiChainId.js.map +1 -1
  99. package/dist/esm/utils/toXOnly.d.ts +5 -1
  100. package/dist/esm/utils/toXOnly.d.ts.map +1 -0
  101. package/dist/esm/utils/toXOnly.js +5 -2
  102. package/dist/esm/utils/toXOnly.js.map +1 -1
  103. package/dist/esm/version.d.ts +6 -2
  104. package/dist/esm/version.d.ts.map +1 -0
  105. package/dist/esm/version.js +6 -2
  106. package/dist/esm/version.js.map +1 -1
  107. package/package.json +7 -6
  108. package/src/BitcoinProvider.ts +1 -1
  109. package/src/actions/getBitcoinBalance.ts +15 -3
  110. package/src/client/publicClient.ts +1 -1
  111. package/src/core/BitcoinStepExecutor.ts +100 -0
  112. package/src/core/tasks/BitcoinSignAndExecuteTask.ts +168 -0
  113. package/src/core/tasks/BitcoinWaitForTransactionTask.ts +74 -0
  114. package/src/types.ts +13 -1
  115. package/src/utils/generateRedeemScript.ts +3 -1
  116. package/src/utils/toXOnly.ts +1 -1
  117. package/src/version.ts +1 -1
  118. package/dist/cjs/BitcoinStepExecutor.d.ts +0 -12
  119. package/dist/cjs/BitcoinStepExecutor.js +0 -198
  120. package/dist/cjs/BitcoinStepExecutor.js.map +0 -1
  121. package/dist/cjs/index.js.map +0 -1
  122. package/dist/esm/BitcoinStepExecutor.d.ts +0 -12
  123. package/dist/esm/BitcoinStepExecutor.js +0 -210
  124. package/dist/esm/BitcoinStepExecutor.js.map +0 -1
  125. package/dist/esm/index.js.map +0 -1
  126. package/dist/types/BitcoinProvider.d.ts +0 -3
  127. package/dist/types/BitcoinProvider.d.ts.map +0 -1
  128. package/dist/types/BitcoinStepExecutor.d.ts +0 -13
  129. package/dist/types/BitcoinStepExecutor.d.ts.map +0 -1
  130. package/dist/types/actions/getBitcoinBalance.d.ts +0 -3
  131. package/dist/types/actions/getBitcoinBalance.d.ts.map +0 -1
  132. package/dist/types/actions/resolveBitcoinAddress.d.ts +0 -2
  133. package/dist/types/actions/resolveBitcoinAddress.d.ts.map +0 -1
  134. package/dist/types/client/publicClient.d.ts +0 -12
  135. package/dist/types/client/publicClient.d.ts.map +0 -1
  136. package/dist/types/errors/parseBitcoinErrors.d.ts +0 -3
  137. package/dist/types/errors/parseBitcoinErrors.d.ts.map +0 -1
  138. package/dist/types/index.d.ts +0 -4
  139. package/dist/types/index.d.ts.map +0 -1
  140. package/dist/types/types.d.ts +0 -10
  141. package/dist/types/types.d.ts.map +0 -1
  142. package/dist/types/utils/generateRedeemScript.d.ts +0 -7
  143. package/dist/types/utils/generateRedeemScript.d.ts.map +0 -1
  144. package/dist/types/utils/isPsbtFinalized.d.ts +0 -3
  145. package/dist/types/utils/isPsbtFinalized.d.ts.map +0 -1
  146. package/dist/types/utils/toBigmiChainId.d.ts +0 -4
  147. package/dist/types/utils/toBigmiChainId.d.ts.map +0 -1
  148. package/dist/types/utils/toXOnly.d.ts +0 -2
  149. package/dist/types/utils/toXOnly.d.ts.map +0 -1
  150. package/dist/types/version.d.ts +0 -3
  151. package/dist/types/version.d.ts.map +0 -1
  152. package/src/BitcoinStepExecutor.ts +0 -333
@@ -1,24 +1,24 @@
1
- import { ChainId, } from '@lifi/sdk';
2
- import { getBitcoinPublicClient } from '../client/publicClient.js';
3
- export const getBitcoinBalance = async (client, walletAddress, tokens) => {
4
- if (tokens.length === 0) {
5
- return [];
6
- }
7
- const { chainId } = tokens[0];
8
- for (const token of tokens) {
9
- if (token.chainId !== chainId) {
10
- console.warn('Requested tokens have to be on the same chain.');
11
- }
12
- }
13
- const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC);
14
- const [balance, blockCount] = await Promise.all([
15
- bigmiClient.getBalance({ address: walletAddress }),
16
- bigmiClient.getBlockCount(),
17
- ]);
18
- return tokens.map((token) => ({
19
- ...token,
20
- amount: balance,
21
- blockNumber: BigInt(blockCount),
22
- }));
1
+ import { getBitcoinPublicClient } from "../client/publicClient.js";
2
+ import { ChainId } from "@lifi/sdk";
3
+ //#region src/actions/getBitcoinBalance.ts
4
+ const getBitcoinBalance = async (client, walletAddress, tokens) => {
5
+ if (tokens.length === 0) return [];
6
+ const { chainId } = tokens[0];
7
+ for (const token of tokens) if (token.chainId !== chainId) console.warn("Requested tokens have to be on the same chain.");
8
+ const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC);
9
+ const [balance, blockCount] = await Promise.allSettled([bigmiClient.getBalance({ address: walletAddress }), bigmiClient.getBlockCount()]);
10
+ const blockNumber = blockCount.status === "fulfilled" ? BigInt(blockCount.value) : 0n;
11
+ if (balance.status !== "fulfilled") return tokens.map((token) => ({
12
+ ...token,
13
+ blockNumber
14
+ }));
15
+ return tokens.map((token) => ({
16
+ ...token,
17
+ amount: balance.value,
18
+ blockNumber
19
+ }));
23
20
  };
21
+ //#endregion
22
+ export { getBitcoinBalance };
23
+
24
24
  //# sourceMappingURL=getBitcoinBalance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBitcoinBalance.js","sourceRoot":"","sources":["../../../src/actions/getBitcoinBalance.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAIR,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAElE,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,MAAiB,EACjB,aAAqB,EACrB,MAAe,EACS,EAAE;IAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACrE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC9C,WAAW,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;QAClD,WAAW,CAAC,aAAa,EAAE;KAC5B,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5B,GAAG,KAAK;QACR,MAAM,EAAE,OAAO;QACf,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;KAChC,CAAC,CAAC,CAAA;AACL,CAAC,CAAA"}
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,5 @@
1
- export declare function resolveBitcoinAddress(name: string): Promise<string | undefined>;
1
+ //#region src/actions/resolveBitcoinAddress.d.ts
2
+ declare function resolveBitcoinAddress(name: string): Promise<string | undefined>;
3
+ //#endregion
4
+ export { resolveBitcoinAddress };
5
+ //# sourceMappingURL=resolveBitcoinAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveBitcoinAddress.d.ts","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"mappings":";iBAAsB,qBAAA,CACpB,IAAA,WACC,OAAA"}
@@ -1,5 +1,8 @@
1
- export async function resolveBitcoinAddress(name) {
2
- // Not supported on UTXO yet
3
- return name;
1
+ //#region src/actions/resolveBitcoinAddress.ts
2
+ async function resolveBitcoinAddress(name) {
3
+ return name;
4
4
  }
5
+ //#endregion
6
+ export { resolveBitcoinAddress };
7
+
5
8
  //# sourceMappingURL=resolveBitcoinAddress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveBitcoinAddress.js","sourceRoot":"","sources":["../../../src/actions/resolveBitcoinAddress.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAAY;IAEZ,4BAA4B;IAC5B,OAAO,IAAI,CAAA;AACb,CAAC"}
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,11 +1,15 @@
1
- import { type Account, type Chain, type Client, type FallbackTransport, type HttpTransport, type PublicActions, type UTXOSchema, type WalletActions } from '@bigmi/core';
2
- import type { SDKClient } from '@lifi/sdk';
1
+ import { Account, Chain, Client, FallbackTransport, HttpTransport, PublicActions, UTXOSchema, WalletActions } from "@bigmi/core";
2
+ import { SDKClient } from "@lifi/sdk";
3
+
4
+ //#region src/client/publicClient.d.ts
3
5
  type PublicClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, Account | undefined, UTXOSchema, PublicActions & WalletActions>;
4
6
  /**
5
- * Get an instance of a provider for a specific chain
6
- * @param client - The SDK client
7
- * @param chainId - Id of the chain the provider is for
8
- * @returns The public client for the given chain
9
- */
10
- export declare const getBitcoinPublicClient: (client: SDKClient, chainId: number) => Promise<PublicClient>;
11
- export {};
7
+ * Get an instance of a provider for a specific chain
8
+ * @param client - The SDK client
9
+ * @param chainId - Id of the chain the provider is for
10
+ * @returns The public client for the given chain
11
+ */
12
+ declare const getBitcoinPublicClient: (client: SDKClient, chainId: number) => Promise<PublicClient>;
13
+ //#endregion
14
+ export { PublicClient, getBitcoinPublicClient };
15
+ //# sourceMappingURL=publicClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicClient.d.ts","names":[],"sources":["../../../src/client/publicClient.ts"],"mappings":";;;;KAsBY,YAAA,GAAe,MAAA,CACzB,iBAAA,UAA2B,aAAA,KAC3B,KAAA,EACA,OAAA,cACA,UAAA,EACA,aAAA,GAAgB,aAAA;;AALlB;;;;;cAiBa,sBAAA,GACX,MAAA,EAAQ,SAAA,EACR,OAAA,aACC,OAAA,CAAQ,YAAA"}
@@ -1,50 +1,42 @@
1
- import { blockchair, blockcypher, createClient, fallback, http, mempool, publicActions, rpcSchema, walletActions, } from '@bigmi/core';
2
- import { toBigmiChainId } from '../utils/toBigmiChainId.js';
3
- // cached providers
1
+ import { toBigmiChainId } from "../utils/toBigmiChainId.js";
2
+ import { blockchair, blockcypher, createClient, fallback, http, mempool, publicActions, rpcSchema, walletActions } from "@bigmi/core";
3
+ //#region src/client/publicClient.ts
4
4
  const publicClients = {};
5
5
  /**
6
- * Get an instance of a provider for a specific chain
7
- * @param client - The SDK client
8
- * @param chainId - Id of the chain the provider is for
9
- * @returns The public client for the given chain
10
- */
11
- export const getBitcoinPublicClient = async (client, chainId) => {
12
- if (!publicClients[chainId]) {
13
- const urls = await client.getRpcUrlsByChainId(chainId);
14
- const fallbackTransports = urls.map((url) => http(url, {
15
- fetchOptions: {
16
- method: 'POST',
17
- },
18
- }));
19
- const _chain = await client.getChainById(chainId);
20
- const chain = {
21
- ..._chain,
22
- ..._chain.metamask,
23
- id: toBigmiChainId(_chain.id),
24
- name: _chain.metamask.chainName,
25
- rpcUrls: {
26
- default: { http: _chain.metamask.rpcUrls },
27
- public: { http: _chain.metamask.rpcUrls },
28
- },
29
- };
30
- const bigmiClient = createClient({
31
- chain,
32
- rpcSchema: rpcSchema(),
33
- transport: fallback([
34
- blockchair(),
35
- blockcypher(),
36
- mempool(),
37
- ...fallbackTransports,
38
- ]),
39
- pollingInterval: 10_000,
40
- })
41
- .extend(publicActions)
42
- .extend(walletActions);
43
- publicClients[chainId] = bigmiClient;
44
- }
45
- if (!publicClients[chainId]) {
46
- throw new Error(`Unable to configure provider for chain ${chainId}`);
47
- }
48
- return publicClients[chainId];
6
+ * Get an instance of a provider for a specific chain
7
+ * @param client - The SDK client
8
+ * @param chainId - Id of the chain the provider is for
9
+ * @returns The public client for the given chain
10
+ */
11
+ const getBitcoinPublicClient = async (client, chainId) => {
12
+ if (!publicClients[chainId]) {
13
+ const fallbackTransports = (await client.getRpcUrlsByChainId(chainId)).map((url) => http(url, { fetchOptions: { method: "POST" } }));
14
+ const _chain = await client.getChainById(chainId);
15
+ publicClients[chainId] = createClient({
16
+ chain: {
17
+ ..._chain,
18
+ ..._chain.metamask,
19
+ id: toBigmiChainId(_chain.id),
20
+ name: _chain.metamask.chainName,
21
+ rpcUrls: {
22
+ default: { http: _chain.metamask.rpcUrls },
23
+ public: { http: _chain.metamask.rpcUrls }
24
+ }
25
+ },
26
+ rpcSchema: rpcSchema(),
27
+ transport: fallback([
28
+ blockchair(),
29
+ blockcypher(),
30
+ mempool(),
31
+ ...fallbackTransports
32
+ ]),
33
+ pollingInterval: 1e4
34
+ }).extend(publicActions).extend(walletActions);
35
+ }
36
+ if (!publicClients[chainId]) throw new Error(`Unable to configure provider for chain ${chainId}`);
37
+ return publicClients[chainId];
49
38
  };
39
+ //#endregion
40
+ export { getBitcoinPublicClient };
41
+
50
42
  //# sourceMappingURL=publicClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"publicClient.js","sourceRoot":"","sources":["../../../src/client/publicClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,WAAW,EAGX,YAAY,EAEZ,QAAQ,EAER,IAAI,EACJ,OAAO,EAEP,aAAa,EACb,SAAS,EAGT,aAAa,GACd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAU3D,mBAAmB;AACnB,MAAM,aAAa,GAAiC,EAAE,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EACzC,MAAiB,EACjB,OAAe,EACQ,EAAE;IACzB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QACtD,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAC1C,IAAI,CAAC,GAAG,EAAE;YACR,YAAY,EAAE;gBACZ,MAAM,EAAE,MAAM;aACf;SACF,CAAC,CACH,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QACjD,MAAM,KAAK,GAAU;YACnB,GAAG,MAAM;YACT,GAAG,MAAM,CAAC,QAAQ;YAClB,EAAE,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YAC/B,OAAO,EAAE;gBACP,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;gBAC1C,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;aAC1C;SACF,CAAA;QACD,MAAM,WAAW,GAAG,YAAY,CAAC;YAC/B,KAAK;YACL,SAAS,EAAE,SAAS,EAAc;YAClC,SAAS,EAAE,QAAQ,CAAC;gBAClB,UAAU,EAAE;gBACZ,WAAW,EAAE;gBACb,OAAO,EAAE;gBACT,GAAG,kBAAkB;aACtB,CAAC;YACF,eAAe,EAAE,MAAM;SACxB,CAAC;aACC,MAAM,CAAC,aAAa,CAAC;aACrB,MAAM,CAAC,aAAa,CAAC,CAAA;QACxB,aAAa,CAAC,OAAO,CAAC,GAAG,WAAW,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,0CAA0C,OAAO,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,OAAO,aAAa,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAA"}
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,EAAA,CACrB,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,CAAC,CACC,OAAO,aAAa,CAAC,CACrB,OAAO,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
@@ -0,0 +1,19 @@
1
+ import { BitcoinStepExecutorContext } from "../types.js";
2
+ import { Client } from "@bigmi/core";
3
+ import { BaseStepExecutor, ExecutionAction, LiFiStepExtended, SDKError, StepExecutorBaseContext, StepExecutorOptions, TaskPipeline } from "@lifi/sdk";
4
+
5
+ //#region src/core/BitcoinStepExecutor.d.ts
6
+ interface BitcoinStepExecutorOptions extends StepExecutorOptions {
7
+ client: Client;
8
+ }
9
+ declare class BitcoinStepExecutor extends BaseStepExecutor {
10
+ private client;
11
+ constructor(options: BitcoinStepExecutorOptions);
12
+ checkClient: (step: LiFiStepExtended) => void;
13
+ override createPipeline: (context: BitcoinStepExecutorContext) => TaskPipeline;
14
+ override parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
15
+ override createContext: (baseContext: StepExecutorBaseContext) => Promise<BitcoinStepExecutorContext>;
16
+ }
17
+ //#endregion
18
+ export { BitcoinStepExecutor };
19
+ //# sourceMappingURL=BitcoinStepExecutor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinStepExecutor.d.ts","names":[],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"mappings":";;;;;UAqBU,0BAAA,SAAmC,mBAAA;EAC3C,MAAA,EAAQ,MAAA;AAAA;AAAA,cAGG,mBAAA,SAA4B,gBAAA;EAAA,QAC/B,MAAA;EAER,WAAA,CAAY,OAAA,EAAS,0BAAA;EAKrB,WAAA,GAAe,IAAA,EAAM,gBAAA;EAAA,SAWZ,cAAA,GACP,OAAA,EAAS,0BAAA,KACR,YAAA;EAAA,SAgCM,WAAA,GACP,KAAA,EAAO,KAAA,EACP,IAAA,GAAO,gBAAA,EACP,MAAA,GAAS,eAAA,KACR,OAAA,CAAQ,QAAA;EAAA,SAEF,aAAA,GACP,WAAA,EAAa,uBAAA,KACZ,OAAA,CAAQ,0BAAA;AAAA"}
@@ -0,0 +1,46 @@
1
+ import { getBitcoinPublicClient } from "../client/publicClient.js";
2
+ import { parseBitcoinErrors } from "../errors/parseBitcoinErrors.js";
3
+ import { BitcoinSignAndExecuteTask } from "./tasks/BitcoinSignAndExecuteTask.js";
4
+ import { BitcoinWaitForTransactionTask } from "./tasks/BitcoinWaitForTransactionTask.js";
5
+ import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, PrepareTransactionTask, TaskPipeline, TransactionError, WaitForTransactionStatusTask } from "@lifi/sdk";
6
+ //#region src/core/BitcoinStepExecutor.ts
7
+ var BitcoinStepExecutor = class extends BaseStepExecutor {
8
+ client;
9
+ constructor(options) {
10
+ super(options);
11
+ this.client = options.client;
12
+ }
13
+ checkClient = (step) => {
14
+ if (this.client.account?.address !== step.action.fromAddress) throw new TransactionError(LiFiErrorCode.WalletChangedDuringExecution, "The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.");
15
+ };
16
+ createPipeline = (context) => {
17
+ const { step, isBridgeExecution } = context;
18
+ const tasks = [
19
+ new CheckBalanceTask(),
20
+ new PrepareTransactionTask(),
21
+ new BitcoinSignAndExecuteTask(),
22
+ new BitcoinWaitForTransactionTask(),
23
+ new WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
24
+ ];
25
+ const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
26
+ const taskName = swapOrBridgeAction?.txHash ? swapOrBridgeAction?.status === "DONE" ? WaitForTransactionStatusTask.name : BitcoinWaitForTransactionTask.name : CheckBalanceTask.name;
27
+ const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
28
+ return new TaskPipeline(tasks.slice(firstTaskIndex));
29
+ };
30
+ parseErrors = (error, step, action) => parseBitcoinErrors(error, step, action);
31
+ createContext = async (baseContext) => {
32
+ const { client, fromChain } = baseContext;
33
+ const publicClient = await getBitcoinPublicClient(client, fromChain.id);
34
+ return {
35
+ ...baseContext,
36
+ pollingIntervalMs: 1e4,
37
+ checkClient: this.checkClient,
38
+ walletClient: this.client,
39
+ publicClient
40
+ };
41
+ };
42
+ };
43
+ //#endregion
44
+ export { BitcoinStepExecutor };
45
+
46
+ //# sourceMappingURL=BitcoinStepExecutor.js.map
@@ -0,0 +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;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"}
@@ -0,0 +1,10 @@
1
+ import { BitcoinStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+
4
+ //#region src/core/tasks/BitcoinSignAndExecuteTask.d.ts
5
+ declare class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {
6
+ run(context: BitcoinStepExecutorContext): Promise<TaskResult>;
7
+ }
8
+ //#endregion
9
+ export { BitcoinSignAndExecuteTask };
10
+ //# sourceMappingURL=BitcoinSignAndExecuteTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"mappings":";;;;cAqBa,yBAAA,SAAkC,qBAAA;EAC7C,GAAA,CAAU,OAAA,EAAS,0BAAA,GAA6B,OAAA,CAAQ,UAAA;AAAA"}
@@ -0,0 +1,72 @@
1
+ import { generateRedeemScript } from "../../utils/generateRedeemScript.js";
2
+ import { isPsbtFinalized } from "../../utils/isPsbtFinalized.js";
3
+ import { toXOnly } from "../../utils/toXOnly.js";
4
+ import { AddressType, getAddressInfo, hexToUnit8Array, signPsbt, withTimeout } from "@bigmi/core";
5
+ import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, getTransactionRequestData } from "@lifi/sdk";
6
+ import * as ecc from "@bitcoinerlab/secp256k1";
7
+ import { Psbt, address, initEccLib, networks } from "bitcoinjs-lib";
8
+ //#region src/core/tasks/BitcoinSignAndExecuteTask.ts
9
+ var BitcoinSignAndExecuteTask = class extends BaseStepExecutionTask {
10
+ async run(context) {
11
+ const { step, walletClient, statusManager, executionOptions, fromChain, publicClient, checkClient, isBridgeExecution } = context;
12
+ const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
13
+ if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
14
+ const transactionRequestData = await getTransactionRequestData(step, executionOptions);
15
+ checkClient(step);
16
+ const psbtHex = transactionRequestData;
17
+ initEccLib(ecc);
18
+ const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin });
19
+ psbt.data.inputs.forEach((input, index) => {
20
+ const addressInfo = getAddressInfo(input.witnessUtxo ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin) : walletClient.account?.address);
21
+ if (addressInfo.type === AddressType.p2tr) {
22
+ if (!input.tapInternalKey) {
23
+ const pubKey = walletClient.account?.publicKey;
24
+ if (pubKey) {
25
+ const tapInternalKey = toXOnly(hexToUnit8Array(pubKey));
26
+ psbt.updateInput(index, { tapInternalKey });
27
+ }
28
+ }
29
+ if (!input.sighashType) psbt.updateInput(index, { sighashType: 1 });
30
+ }
31
+ if (addressInfo.type === AddressType.p2sh) {
32
+ if (!input.redeemScript) {
33
+ const pubKey = walletClient.account?.publicKey;
34
+ if (pubKey) psbt.updateInput(index, { redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)) });
35
+ }
36
+ }
37
+ });
38
+ const inputsToSign = Array.from(psbt.data.inputs.reduce((map, input, index) => {
39
+ const accountAddress = input.witnessUtxo ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin) : walletClient.account?.address;
40
+ if (map.has(accountAddress)) map.get(accountAddress).signingIndexes.push(index);
41
+ else map.set(accountAddress, {
42
+ address: accountAddress,
43
+ sigHash: 1,
44
+ signingIndexes: [index]
45
+ });
46
+ return map;
47
+ }, /* @__PURE__ */ new Map()).values());
48
+ const signedPsbtHex = await withTimeout(() => signPsbt(walletClient, {
49
+ psbt: psbt.toHex(),
50
+ inputsToSign,
51
+ finalize: false
52
+ }), {
53
+ timeout: 6e5,
54
+ errorInstance: new TransactionError(LiFiErrorCode.TransactionExpired, "Transaction has expired.")
55
+ });
56
+ const signedPsbt = Psbt.fromHex(signedPsbtHex);
57
+ if (!isPsbtFinalized(signedPsbt)) signedPsbt.finalizeAllInputs();
58
+ const txHex = signedPsbt.extractTransaction().toHex();
59
+ const txHash = await publicClient.sendUTXOTransaction({ hex: txHex });
60
+ statusManager.updateAction(step, action.type, "PENDING", {
61
+ txHash,
62
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
63
+ txHex,
64
+ signedAt: Date.now()
65
+ });
66
+ return { status: "COMPLETED" };
67
+ }
68
+ };
69
+ //#endregion
70
+ export { BitcoinSignAndExecuteTask };
71
+
72
+ //# sourceMappingURL=BitcoinSignAndExecuteTask.js.map
@@ -0,0 +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,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,CAAC,CAAE,eAAe,KAAK,KAAK;QAElD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,KAAK;GACxB,CAAC;GAEH,OAAO;EACT,mBAAG,IAAI,IAGL,CAAC,CAAC,CACH,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,CAAC,CAAC,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"}
@@ -0,0 +1,10 @@
1
+ import { BitcoinStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+
4
+ //#region src/core/tasks/BitcoinWaitForTransactionTask.d.ts
5
+ declare class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {
6
+ run(context: BitcoinStepExecutorContext): Promise<TaskResult>;
7
+ }
8
+ //#endregion
9
+ export { BitcoinWaitForTransactionTask };
10
+ //# sourceMappingURL=BitcoinWaitForTransactionTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"mappings":";;;;cAUa,6BAAA,SAAsC,qBAAA;EACjD,GAAA,CAAU,OAAA,EAAS,0BAAA,GAA6B,OAAA,CAAQ,UAAA;AAAA"}
@@ -0,0 +1,37 @@
1
+ import { waitForTransaction } from "@bigmi/core";
2
+ import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
3
+ //#region src/core/tasks/BitcoinWaitForTransactionTask.ts
4
+ var BitcoinWaitForTransactionTask = class extends BaseStepExecutionTask {
5
+ async run(context) {
6
+ const { step, statusManager, fromChain, isBridgeExecution, walletClient, publicClient, checkClient } = context;
7
+ const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
8
+ const txHex = action?.txHex;
9
+ const txHash = action?.txHash;
10
+ if (!txHash || !txHex) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Transaction hash or hex is not set.");
11
+ checkClient(step);
12
+ let replacementReason;
13
+ const transaction = await waitForTransaction(publicClient, {
14
+ txId: txHash,
15
+ txHex,
16
+ senderAddress: walletClient.account?.address,
17
+ onReplaced: (response) => {
18
+ replacementReason = response.reason;
19
+ statusManager.updateAction(step, action.type, "PENDING", {
20
+ txHash: response.transaction.txid,
21
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`
22
+ });
23
+ }
24
+ });
25
+ if (replacementReason === "cancelled") throw new TransactionError(LiFiErrorCode.TransactionCanceled, "User canceled transaction.");
26
+ if (transaction.txid !== txHash) statusManager.updateAction(step, action.type, "PENDING", {
27
+ txHash: transaction.txid,
28
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`
29
+ });
30
+ if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
31
+ return { status: "COMPLETED" };
32
+ }
33
+ };
34
+ //#endregion
35
+ export { BitcoinWaitForTransactionTask };
36
+
37
+ //# sourceMappingURL=BitcoinWaitForTransactionTask.js.map
@@ -0,0 +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,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,2 +1,7 @@
1
- import { type ExecutionAction, type LiFiStep, SDKError } from '@lifi/sdk';
2
- export declare const parseBitcoinErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
1
+ import { ExecutionAction, LiFiStep, SDKError } from "@lifi/sdk";
2
+
3
+ //#region src/errors/parseBitcoinErrors.d.ts
4
+ declare const parseBitcoinErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
5
+ //#endregion
6
+ export { parseBitcoinErrors };
7
+ //# sourceMappingURL=parseBitcoinErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseBitcoinErrors.d.ts","names":[],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"mappings":";;;cAWa,kBAAA,GACX,CAAA,EAAG,KAAA,EACH,IAAA,GAAO,QAAA,EACP,MAAA,GAAS,eAAA,KACR,OAAA,CAAQ,QAAA"}
@@ -1,28 +1,21 @@
1
- import { BaseError, ErrorMessage, LiFiErrorCode, SDKError, TransactionError, UnknownError, } from '@lifi/sdk';
2
- export const parseBitcoinErrors = async (e, step, action) => {
3
- if (e instanceof SDKError) {
4
- e.step = e.step ?? step;
5
- e.action = e.action ?? action;
6
- return e;
7
- }
8
- const baseError = handleSpecificErrors(e);
9
- return new SDKError(baseError, step, action);
1
+ import { BaseError, ErrorMessage, LiFiErrorCode, SDKError, TransactionError, UnknownError } from "@lifi/sdk";
2
+ //#region src/errors/parseBitcoinErrors.ts
3
+ const parseBitcoinErrors = async (e, step, action) => {
4
+ if (e instanceof SDKError) {
5
+ e.step = e.step ?? step;
6
+ e.action = e.action ?? action;
7
+ return e;
8
+ }
9
+ return new SDKError(handleSpecificErrors(e), step, action);
10
10
  };
11
11
  const handleSpecificErrors = (e) => {
12
- // txn-mempool-conflict
13
- if (e.details?.includes?.('conflict') ||
14
- e.cause?.message?.includes?.('conflict')) {
15
- return new TransactionError(LiFiErrorCode.TransactionConflict, 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.', e);
16
- }
17
- if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {
18
- return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
19
- }
20
- if (e.code === -5 || e.code === -32700 || e.code === -32064) {
21
- return new TransactionError(LiFiErrorCode.NotFound, e.message, e);
22
- }
23
- if (e instanceof BaseError) {
24
- return e;
25
- }
26
- return new UnknownError(e.message || ErrorMessage.UnknownError, e);
12
+ if (e.details?.includes?.("conflict") || e.cause?.message?.includes?.("conflict")) return new TransactionError(LiFiErrorCode.TransactionConflict, "Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.", e);
13
+ if (e.code === 4001 || e.code === -32e3 || e.cause?.includes?.("rejected")) return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
14
+ if (e.code === -5 || e.code === -32700 || e.code === -32064) return new TransactionError(LiFiErrorCode.NotFound, e.message, e);
15
+ if (e instanceof BaseError) return e;
16
+ return new UnknownError(e.message || ErrorMessage.UnknownError, e);
27
17
  };
18
+ //#endregion
19
+ export { parseBitcoinErrors };
20
+
28
21
  //# sourceMappingURL=parseBitcoinErrors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseBitcoinErrors.js","sourceRoot":"","sources":["../../../src/errors/parseBitcoinErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EAEZ,aAAa,EAEb,QAAQ,EACR,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAA;AAElB,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,CAAQ,EACR,IAAe,EACf,MAAwB,EACL,EAAE;IACrB,IAAI,CAAC,YAAY,QAAQ,EAAE,CAAC;QAC1B,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAA;QACvB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAA;QAC7B,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAA;IAEzC,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAAC,CAAM,EAAE,EAAE;IACtC,uBAAuB;IACvB,IACE,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC;QACjC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EACxC,CAAC;QACD,OAAO,IAAI,gBAAgB,CACzB,aAAa,CAAC,mBAAmB,EACjC,wIAAwI,EACxI,CAAC,CACF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5E,OAAO,IAAI,gBAAgB,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IAC5E,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5D,OAAO,IAAI,gBAAgB,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,IAAI,CAAC,YAAY,SAAS,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,IAAI,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;AACpE,CAAC,CAAA"}
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"}
@@ -1,3 +1,3 @@
1
- export { BitcoinProvider } from './BitcoinProvider.js';
2
- export type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js';
3
- export { isBitcoinProvider } from './types.js';
1
+ import { BitcoinProviderOptions, BitcoinSDKProvider, isBitcoinProvider } from "./types.js";
2
+ import { BitcoinProvider } from "./BitcoinProvider.js";
3
+ export { BitcoinProvider, type BitcoinProviderOptions, type BitcoinSDKProvider, isBitcoinProvider };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // biome-ignore lint/performance/noBarrelFile: module entrypoint
2
- export { BitcoinProvider } from './BitcoinProvider.js';
3
- export { isBitcoinProvider } from './types.js';
4
- //# sourceMappingURL=index.js.map
1
+ import { BitcoinProvider } from "./BitcoinProvider.js";
2
+ import { isBitcoinProvider } from "./types.js";
3
+ export { BitcoinProvider, isBitcoinProvider };
@@ -1 +1 @@
1
- {"type": "module","sideEffects":false}
1
+ {"type":"module","sideEffects":false}