@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,9 +1,20 @@
1
- import type { Client } from '@bigmi/core';
2
- import { type SDKProvider } from '@lifi/sdk';
3
- export interface BitcoinProviderOptions {
4
- getWalletClient?: () => Promise<Client>;
1
+ import { PublicClient } from "./client/publicClient.js";
2
+ import { Client } from "@bigmi/core";
3
+ import { LiFiStepExtended, SDKProvider, StepExecutorContext } from "@lifi/sdk";
4
+
5
+ //#region src/types.d.ts
6
+ interface BitcoinProviderOptions {
7
+ getWalletClient?: () => Promise<Client>;
5
8
  }
6
- export interface BitcoinSDKProvider extends SDKProvider {
7
- setOptions(options: BitcoinProviderOptions): void;
9
+ interface BitcoinStepExecutorContext extends StepExecutorContext {
10
+ walletClient: Client;
11
+ publicClient: PublicClient;
12
+ checkClient: (step: LiFiStepExtended) => void;
8
13
  }
9
- export declare function isBitcoinProvider(provider: SDKProvider): provider is BitcoinSDKProvider;
14
+ interface BitcoinSDKProvider extends SDKProvider {
15
+ setOptions(options: BitcoinProviderOptions): void;
16
+ }
17
+ declare function isBitcoinProvider(provider: SDKProvider): provider is BitcoinSDKProvider;
18
+ //#endregion
19
+ export { BitcoinProviderOptions, BitcoinSDKProvider, BitcoinStepExecutorContext, isBitcoinProvider };
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;;UASiB,sBAAA;EACf,eAAA,SAAwB,OAAA,CAAQ,MAAA;AAAA;AAAA,UAGjB,0BAAA,SAAmC,mBAAA;EAClD,YAAA,EAAc,MAAA;EACd,YAAA,EAAc,YAAA;EACd,WAAA,GAAc,IAAA,EAAM,gBAAA;AAAA;AAAA,UAGL,kBAAA,SAA2B,WAAA;EAC1C,UAAA,CAAW,OAAA,EAAS,sBAAA;AAAA;AAAA,iBAGN,iBAAA,CACd,QAAA,EAAU,WAAA,GACT,QAAA,IAAY,kBAAA"}
package/dist/esm/types.js CHANGED
@@ -1,5 +1,9 @@
1
- import { ChainType } from '@lifi/sdk';
2
- export function isBitcoinProvider(provider) {
3
- return provider.type === ChainType.UTXO;
1
+ import { ChainType } from "@lifi/sdk";
2
+ //#region src/types.ts
3
+ function isBitcoinProvider(provider) {
4
+ return provider.type === ChainType.UTXO;
4
5
  }
6
+ //#endregion
7
+ export { isBitcoinProvider };
8
+
5
9
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,WAAW,CAAA;AAUvD,MAAM,UAAU,iBAAiB,CAC/B,QAAqB;IAErB,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAA;AACzC,CAAC"}
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,6 +1,10 @@
1
+ //#region src/utils/generateRedeemScript.d.ts
1
2
  /**
2
- * Generate redeem script for P2SH addresses
3
- * @param publicKey
4
- * @returns redeem script
5
- */
6
- export declare const generateRedeemScript: (publicKey: Uint8Array) => Uint8Array<ArrayBufferLike> | undefined;
3
+ * Generate redeem script for P2SH addresses
4
+ * @param publicKey
5
+ * @returns redeem script
6
+ */
7
+ declare const generateRedeemScript: (publicKey: Uint8Array) => Uint8Array | undefined;
8
+ //#endregion
9
+ export { generateRedeemScript };
10
+ //# sourceMappingURL=generateRedeemScript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateRedeemScript.d.ts","names":[],"sources":["../../../src/utils/generateRedeemScript.ts"],"mappings":";;AAOA;;;;cAAa,oBAAA,GACX,SAAA,EAAW,UAAA,KACV,UAAA"}
@@ -1,10 +1,12 @@
1
- import { payments } from 'bitcoinjs-lib';
1
+ import { payments } from "bitcoinjs-lib";
2
+ //#region src/utils/generateRedeemScript.ts
2
3
  /**
3
- * Generate redeem script for P2SH addresses
4
- * @param publicKey
5
- * @returns redeem script
6
- */
7
- export const generateRedeemScript = (publicKey) =>
8
- // P2SH addresses are created by hashing the public key and using the result as the script
9
- payments.p2wpkh({ pubkey: publicKey }).output;
4
+ * Generate redeem script for P2SH addresses
5
+ * @param publicKey
6
+ * @returns redeem script
7
+ */
8
+ const generateRedeemScript = (publicKey) => payments.p2wpkh({ pubkey: publicKey }).output;
9
+ //#endregion
10
+ export { generateRedeemScript };
11
+
10
12
  //# sourceMappingURL=generateRedeemScript.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateRedeemScript.js","sourceRoot":"","sources":["../../../src/utils/generateRedeemScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAqB,EAAE,EAAE;AAC5D,0FAA0F;AAC1F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAA"}
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,CAAC,CAAC"}
@@ -1,2 +1,7 @@
1
- import type { Psbt } from 'bitcoinjs-lib';
2
- export declare function isPsbtFinalized(psbt: Psbt): boolean;
1
+ import { Psbt } from "bitcoinjs-lib";
2
+
3
+ //#region src/utils/isPsbtFinalized.d.ts
4
+ declare function isPsbtFinalized(psbt: Psbt): boolean;
5
+ //#endregion
6
+ export { isPsbtFinalized };
7
+ //# sourceMappingURL=isPsbtFinalized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isPsbtFinalized.d.ts","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"mappings":";;;iBAEgB,eAAA,CAAgB,IAAM,EAAA,IAAA"}
@@ -1,10 +1,13 @@
1
- export function isPsbtFinalized(psbt) {
2
- try {
3
- psbt.extractTransaction();
4
- return true;
5
- }
6
- catch (_) {
7
- return false;
8
- }
1
+ //#region src/utils/isPsbtFinalized.ts
2
+ function isPsbtFinalized(psbt) {
3
+ try {
4
+ psbt.extractTransaction();
5
+ return true;
6
+ } catch (_) {
7
+ return false;
8
+ }
9
9
  }
10
+ //#endregion
11
+ export { isPsbtFinalized };
12
+
10
13
  //# sourceMappingURL=isPsbtFinalized.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isPsbtFinalized.js","sourceRoot":"","sources":["../../../src/utils/isPsbtFinalized.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,IAAU;IACxC,IAAI,CAAC;QACH,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
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,3 +1,8 @@
1
- import { ChainId as BigmiChainId } from '@bigmi/core';
2
- import { ChainId } from '@lifi/sdk';
3
- export declare const toBigmiChainId: (chainId: ChainId) => BigmiChainId;
1
+ import { ChainId } from "@bigmi/core";
2
+ import { ChainId as ChainId$1 } from "@lifi/sdk";
3
+
4
+ //#region src/utils/toBigmiChainId.d.ts
5
+ declare const toBigmiChainId: (chainId: ChainId$1) => ChainId;
6
+ //#endregion
7
+ export { toBigmiChainId };
8
+ //# sourceMappingURL=toBigmiChainId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toBigmiChainId.d.ts","names":[],"sources":["../../../src/utils/toBigmiChainId.ts"],"mappings":";;;;cAGa,cAAA,GAAkB,OAAA,EAAS,SAAA,KAAU,OAAA"}
@@ -1,11 +1,13 @@
1
- import { ChainId as BigmiChainId } from '@bigmi/core';
2
- import { ChainId } from '@lifi/sdk';
3
- export const toBigmiChainId = (chainId) => {
4
- switch (chainId) {
5
- case ChainId.BTC:
6
- return BigmiChainId.BITCOIN_MAINNET;
7
- default:
8
- throw new Error(`Unsupported chainId mapping: ${chainId}`);
9
- }
1
+ import { ChainId } from "@bigmi/core";
2
+ import { ChainId as ChainId$1 } from "@lifi/sdk";
3
+ //#region src/utils/toBigmiChainId.ts
4
+ const toBigmiChainId = (chainId) => {
5
+ switch (chainId) {
6
+ case ChainId$1.BTC: return ChainId.BITCOIN_MAINNET;
7
+ default: throw new Error(`Unsupported chainId mapping: ${chainId}`);
8
+ }
10
9
  };
10
+ //#endregion
11
+ export { toBigmiChainId };
12
+
11
13
  //# sourceMappingURL=toBigmiChainId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toBigmiChainId.js","sourceRoot":"","sources":["../../../src/utils/toBigmiChainId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAgB,EAAE;IAC/D,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,OAAO,CAAC,GAAG;YACd,OAAO,YAAY,CAAC,eAAe,CAAA;QACrC;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAA;IAC9D,CAAC;AACH,CAAC,CAAA"}
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,5 @@
1
- export declare const toXOnly: (pubKey: Uint8Array) => Uint8Array<ArrayBufferLike>;
1
+ //#region src/utils/toXOnly.d.ts
2
+ declare const toXOnly: (pubKey: Uint8Array) => Uint8Array;
3
+ //#endregion
4
+ export { toXOnly };
5
+ //# sourceMappingURL=toXOnly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toXOnly.d.ts","names":[],"sources":["../../../src/utils/toXOnly.ts"],"mappings":";cACa,OAAA,GAAW,MAAA,EAAQ,UAAA,KAAa,UAAA"}
@@ -1,3 +1,6 @@
1
- // helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update
2
- export const toXOnly = (pubKey) => pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
1
+ //#region src/utils/toXOnly.ts
2
+ const toXOnly = (pubKey) => pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
3
+ //#endregion
4
+ export { toXOnly };
5
+
3
6
  //# sourceMappingURL=toXOnly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toXOnly.js","sourceRoot":"","sources":["../../../src/utils/toXOnly.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAkB,EAAE,EAAE,CAC5C,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA"}
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"}
@@ -1,2 +1,6 @@
1
- export declare const name = "@lifi/sdk-provider-bitcoin";
2
- export declare const version = "4.0.1-alpha.0";
1
+ //#region src/version.d.ts
2
+ declare const name = "@lifi/sdk-provider-bitcoin";
3
+ declare const version = "4.0.1";
4
+ //#endregion
5
+ export { name, version };
6
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","names":[],"sources":["../../src/version.ts"],"mappings":";cAAa,IAAA;AAAA,cACA,OAAA"}
@@ -1,3 +1,7 @@
1
- export const name = '@lifi/sdk-provider-bitcoin';
2
- export const version = '4.0.1-alpha.0';
1
+ //#region src/version.ts
2
+ const name = "@lifi/sdk-provider-bitcoin";
3
+ const version = "4.0.1";
4
+ //#endregion
5
+ export { name, version };
6
+
3
7
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,4BAA4B,CAAA;AAChD,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAA"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.1'\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.1-alpha.0",
3
+ "version": "4.0.1",
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": {
@@ -17,27 +17,28 @@
17
17
  "sideEffects": false,
18
18
  "main": "./dist/cjs/index.js",
19
19
  "module": "./dist/esm/index.js",
20
- "types": "./dist/types/index.d.ts",
21
- "typings": "./dist/types/index.d.ts",
20
+ "types": "./dist/esm/index.d.ts",
21
+ "typings": "./dist/esm/index.d.ts",
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/types/index.d.ts",
24
+ "types": "./dist/esm/index.d.ts",
25
25
  "import": "./dist/esm/index.js",
26
26
  "default": "./dist/cjs/index.js"
27
27
  },
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@bigmi/core": "^0.6.5",
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.1-alpha.0"
35
+ "@lifi/sdk": "4.0.1"
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",
@@ -2,7 +2,7 @@ import { isUTXOAddress } from '@bigmi/core'
2
2
  import { ChainType, type StepExecutorOptions } from '@lifi/sdk'
3
3
  import { getBitcoinBalance } from './actions/getBitcoinBalance.js'
4
4
  import { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'
5
- import { BitcoinStepExecutor } from './BitcoinStepExecutor.js'
5
+ import { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'
6
6
  import type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'
7
7
 
8
8
  export function BitcoinProvider(
@@ -21,14 +21,26 @@ export const getBitcoinBalance = async (
21
21
  }
22
22
  }
23
23
  const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)
24
- const [balance, blockCount] = await Promise.all([
24
+ const [balance, blockCount] = await Promise.allSettled([
25
25
  bigmiClient.getBalance({ address: walletAddress }),
26
26
  bigmiClient.getBlockCount(),
27
27
  ])
28
28
 
29
+ const blockNumber =
30
+ blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n
31
+
32
+ if (balance.status !== 'fulfilled') {
33
+ // RPC failed — leave amount undefined so callers can distinguish
34
+ // an unknown balance from a known zero.
35
+ return tokens.map((token) => ({
36
+ ...token,
37
+ blockNumber,
38
+ }))
39
+ }
40
+
29
41
  return tokens.map((token) => ({
30
42
  ...token,
31
- amount: balance,
32
- blockNumber: BigInt(blockCount),
43
+ amount: balance.value,
44
+ blockNumber,
33
45
  }))
34
46
  }
@@ -20,7 +20,7 @@ import {
20
20
  import type { SDKClient } from '@lifi/sdk'
21
21
  import { toBigmiChainId } from '../utils/toBigmiChainId.js'
22
22
 
23
- type PublicClient = Client<
23
+ export type PublicClient = Client<
24
24
  FallbackTransport<readonly HttpTransport[]>,
25
25
  Chain,
26
26
  Account | undefined,
@@ -0,0 +1,100 @@
1
+ import type { Client } from '@bigmi/core'
2
+ import {
3
+ BaseStepExecutor,
4
+ CheckBalanceTask,
5
+ type ExecutionAction,
6
+ LiFiErrorCode,
7
+ type LiFiStepExtended,
8
+ PrepareTransactionTask,
9
+ type SDKError,
10
+ type StepExecutorBaseContext,
11
+ type StepExecutorOptions,
12
+ TaskPipeline,
13
+ TransactionError,
14
+ WaitForTransactionStatusTask,
15
+ } from '@lifi/sdk'
16
+ import { getBitcoinPublicClient } from '../client/publicClient.js'
17
+ import { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'
18
+ import type { BitcoinStepExecutorContext } from '../types.js'
19
+ import { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'
20
+ import { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'
21
+
22
+ interface BitcoinStepExecutorOptions extends StepExecutorOptions {
23
+ client: Client
24
+ }
25
+
26
+ export class BitcoinStepExecutor extends BaseStepExecutor {
27
+ private client: Client
28
+
29
+ constructor(options: BitcoinStepExecutorOptions) {
30
+ super(options)
31
+ this.client = options.client
32
+ }
33
+
34
+ checkClient = (step: LiFiStepExtended): void => {
35
+ // TODO: check chain and possibly implement chain switch?
36
+ // Prevent execution of the quote by wallet different from the one which requested the quote
37
+ if (this.client.account?.address !== step.action.fromAddress) {
38
+ throw new TransactionError(
39
+ LiFiErrorCode.WalletChangedDuringExecution,
40
+ 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'
41
+ )
42
+ }
43
+ }
44
+
45
+ override createPipeline = (
46
+ context: BitcoinStepExecutorContext
47
+ ): TaskPipeline => {
48
+ const { step, isBridgeExecution } = context
49
+
50
+ const tasks = [
51
+ new CheckBalanceTask(),
52
+ new PrepareTransactionTask(),
53
+ new BitcoinSignAndExecuteTask(),
54
+ new BitcoinWaitForTransactionTask(),
55
+ new WaitForTransactionStatusTask(
56
+ isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'
57
+ ),
58
+ ]
59
+ const swapOrBridgeAction = this.statusManager.findAction(
60
+ step,
61
+ isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
62
+ )
63
+
64
+ const taskName = swapOrBridgeAction?.txHash
65
+ ? swapOrBridgeAction?.status === 'DONE'
66
+ ? WaitForTransactionStatusTask.name
67
+ : BitcoinWaitForTransactionTask.name
68
+ : CheckBalanceTask.name
69
+
70
+ const firstTaskIndex = tasks.findIndex(
71
+ (task) => task.constructor.name === taskName
72
+ )
73
+
74
+ const tasksToRun = tasks.slice(firstTaskIndex)
75
+
76
+ return new TaskPipeline(tasksToRun)
77
+ }
78
+
79
+ override parseErrors = (
80
+ error: Error,
81
+ step?: LiFiStepExtended,
82
+ action?: ExecutionAction
83
+ ): Promise<SDKError> => parseBitcoinErrors(error, step, action)
84
+
85
+ override createContext = async (
86
+ baseContext: StepExecutorBaseContext
87
+ ): Promise<BitcoinStepExecutorContext> => {
88
+ const { client, fromChain } = baseContext
89
+
90
+ const publicClient = await getBitcoinPublicClient(client, fromChain.id)
91
+
92
+ return {
93
+ ...baseContext,
94
+ pollingIntervalMs: 10_000,
95
+ checkClient: this.checkClient,
96
+ walletClient: this.client,
97
+ publicClient,
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,168 @@
1
+ import {
2
+ AddressType,
3
+ getAddressInfo,
4
+ hexToUnit8Array,
5
+ signPsbt,
6
+ withTimeout,
7
+ } from '@bigmi/core'
8
+ import * as ecc from '@bitcoinerlab/secp256k1'
9
+ import {
10
+ BaseStepExecutionTask,
11
+ getTransactionRequestData,
12
+ LiFiErrorCode,
13
+ type TaskResult,
14
+ TransactionError,
15
+ } from '@lifi/sdk'
16
+ import { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'
17
+ import type { BitcoinStepExecutorContext } from '../../types.js'
18
+ import { generateRedeemScript } from '../../utils/generateRedeemScript.js'
19
+ import { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'
20
+ import { toXOnly } from '../../utils/toXOnly.js'
21
+
22
+ export class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {
23
+ async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {
24
+ const {
25
+ step,
26
+ walletClient,
27
+ statusManager,
28
+ executionOptions,
29
+ fromChain,
30
+ publicClient,
31
+ checkClient,
32
+ isBridgeExecution,
33
+ } = context
34
+
35
+ const action = statusManager.findAction(
36
+ step,
37
+ isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
38
+ )
39
+
40
+ if (!action) {
41
+ throw new TransactionError(
42
+ LiFiErrorCode.TransactionUnprepared,
43
+ 'Unable to prepare transaction. Action not found.'
44
+ )
45
+ }
46
+
47
+ const transactionRequestData = await getTransactionRequestData(
48
+ step,
49
+ executionOptions
50
+ )
51
+
52
+ checkClient(step)
53
+
54
+ const psbtHex = transactionRequestData
55
+
56
+ // Initialize ECC library required for Taproot operations
57
+ // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot
58
+ initEccLib(ecc)
59
+
60
+ const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })
61
+
62
+ psbt.data.inputs.forEach((input, index) => {
63
+ const accountAddress = input.witnessUtxo
64
+ ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)
65
+ : (walletClient.account?.address as string)
66
+ const addressInfo = getAddressInfo(accountAddress)
67
+ if (addressInfo.type === AddressType.p2tr) {
68
+ // Taproot (P2TR) addresses require specific PSBT fields for proper signing
69
+
70
+ // tapInternalKey: Required for Taproot key-path spending
71
+ // Most wallets / libraries usually handle this already
72
+ if (!input.tapInternalKey) {
73
+ const pubKey = walletClient.account?.publicKey
74
+ if (pubKey) {
75
+ const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))
76
+ psbt.updateInput(index, {
77
+ tapInternalKey,
78
+ })
79
+ }
80
+ }
81
+ // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults
82
+ // check if sighashType is default (0) or not set (undefined)
83
+ if (!input.sighashType) {
84
+ psbt.updateInput(index, {
85
+ sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1
86
+ })
87
+ }
88
+ }
89
+ // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending
90
+ if (addressInfo.type === AddressType.p2sh) {
91
+ if (!input.redeemScript) {
92
+ const pubKey = walletClient.account?.publicKey
93
+ if (pubKey) {
94
+ psbt.updateInput(index, {
95
+ redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),
96
+ })
97
+ }
98
+ }
99
+ }
100
+ })
101
+
102
+ const inputsToSign = Array.from(
103
+ psbt.data.inputs
104
+ .reduce((map, input, index) => {
105
+ const accountAddress = input.witnessUtxo
106
+ ? address.fromOutputScript(
107
+ input.witnessUtxo.script,
108
+ networks.bitcoin
109
+ )
110
+ : (walletClient.account?.address as string)
111
+ if (map.has(accountAddress)) {
112
+ map.get(accountAddress)!.signingIndexes.push(index)
113
+ } else {
114
+ map.set(accountAddress, {
115
+ address: accountAddress,
116
+ sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1
117
+ signingIndexes: [index],
118
+ })
119
+ }
120
+ return map
121
+ }, new Map<
122
+ string,
123
+ { address: string; sigHash: number; signingIndexes: number[] }
124
+ >())
125
+ .values()
126
+ )
127
+
128
+ // We give users 10 minutes to sign the transaction or it should be considered expired
129
+ const signedPsbtHex = await withTimeout(
130
+ () =>
131
+ signPsbt(walletClient, {
132
+ psbt: psbt.toHex(),
133
+ inputsToSign: inputsToSign,
134
+ finalize: false,
135
+ }),
136
+ {
137
+ timeout: 600_000,
138
+ errorInstance: new TransactionError(
139
+ LiFiErrorCode.TransactionExpired,
140
+ 'Transaction has expired.'
141
+ ),
142
+ }
143
+ )
144
+
145
+ const signedPsbt = Psbt.fromHex(signedPsbtHex)
146
+
147
+ if (!isPsbtFinalized(signedPsbt)) {
148
+ signedPsbt.finalizeAllInputs()
149
+ }
150
+
151
+ const txHex = signedPsbt.extractTransaction().toHex()
152
+
153
+ const txHash = await publicClient.sendUTXOTransaction({
154
+ hex: txHex,
155
+ })
156
+
157
+ statusManager.updateAction(step, action.type, 'PENDING', {
158
+ txHash: txHash,
159
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
160
+ txHex,
161
+ signedAt: Date.now(),
162
+ })
163
+
164
+ return {
165
+ status: 'COMPLETED',
166
+ }
167
+ }
168
+ }