@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.
- package/CHANGELOG.md +23 -0
- package/README.md +88 -5
- package/dist/cjs/BitcoinProvider.d.ts +7 -2
- package/dist/cjs/BitcoinProvider.js +30 -34
- package/dist/cjs/BitcoinProvider.js.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.js +23 -0
- package/dist/cjs/actions/getBitcoinBalance.d.ts +7 -2
- package/dist/cjs/actions/getBitcoinBalance.js +21 -24
- package/dist/cjs/actions/getBitcoinBalance.js.map +1 -1
- package/dist/cjs/actions/resolveBitcoinAddress.d.ts +5 -1
- package/dist/cjs/actions/resolveBitcoinAddress.js +6 -4
- package/dist/cjs/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/cjs/client/publicClient.d.ts +14 -4
- package/dist/cjs/client/publicClient.js +38 -42
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/BitcoinStepExecutor.d.ts +19 -0
- package/dist/cjs/core/BitcoinStepExecutor.js +47 -0
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js +75 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +38 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/cjs/errors/parseBitcoinErrors.d.ts +7 -2
- package/dist/cjs/errors/parseBitcoinErrors.js +17 -26
- package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +5 -8
- package/dist/cjs/types.d.ts +18 -7
- package/dist/cjs/types.js +7 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/generateRedeemScript.d.ts +10 -1
- package/dist/cjs/utils/generateRedeemScript.js +11 -5
- package/dist/cjs/utils/generateRedeemScript.js.map +1 -1
- package/dist/cjs/utils/isPsbtFinalized.d.ts +7 -2
- package/dist/cjs/utils/isPsbtFinalized.js +11 -10
- package/dist/cjs/utils/isPsbtFinalized.js.map +1 -1
- package/dist/cjs/utils/toBigmiChainId.d.ts +8 -3
- package/dist/cjs/utils/toBigmiChainId.js +10 -11
- package/dist/cjs/utils/toBigmiChainId.js.map +1 -1
- package/dist/cjs/utils/toXOnly.d.ts +5 -1
- package/dist/cjs/utils/toXOnly.js +4 -3
- package/dist/cjs/utils/toXOnly.js.map +1 -1
- package/dist/cjs/version.d.ts +6 -2
- package/dist/cjs/version.js +8 -5
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/BitcoinProvider.d.ts +7 -2
- package/dist/esm/BitcoinProvider.d.ts.map +1 -0
- package/dist/esm/BitcoinProvider.js +30 -32
- package/dist/esm/BitcoinProvider.js.map +1 -1
- package/dist/esm/actions/getBitcoinBalance.d.ts +7 -2
- package/dist/esm/actions/getBitcoinBalance.d.ts.map +1 -0
- package/dist/esm/actions/getBitcoinBalance.js +22 -22
- package/dist/esm/actions/getBitcoinBalance.js.map +1 -1
- package/dist/esm/actions/resolveBitcoinAddress.d.ts +5 -1
- package/dist/esm/actions/resolveBitcoinAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveBitcoinAddress.js +6 -3
- package/dist/esm/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/esm/client/publicClient.d.ts +13 -9
- package/dist/esm/client/publicClient.d.ts.map +1 -0
- package/dist/esm/client/publicClient.js +38 -46
- package/dist/esm/client/publicClient.js.map +1 -1
- package/dist/esm/core/BitcoinStepExecutor.d.ts +19 -0
- package/dist/esm/core/BitcoinStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/BitcoinStepExecutor.js +46 -0
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js +72 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js +37 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseBitcoinErrors.d.ts +7 -2
- package/dist/esm/errors/parseBitcoinErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseBitcoinErrors.js +17 -24
- package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/package.json +1 -1
- package/dist/esm/types.d.ts +18 -7
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +7 -3
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/generateRedeemScript.d.ts +9 -5
- package/dist/esm/utils/generateRedeemScript.d.ts.map +1 -0
- package/dist/esm/utils/generateRedeemScript.js +10 -8
- package/dist/esm/utils/generateRedeemScript.js.map +1 -1
- package/dist/esm/utils/isPsbtFinalized.d.ts +7 -2
- package/dist/esm/utils/isPsbtFinalized.d.ts.map +1 -0
- package/dist/esm/utils/isPsbtFinalized.js +11 -8
- package/dist/esm/utils/isPsbtFinalized.js.map +1 -1
- package/dist/esm/utils/toBigmiChainId.d.ts +8 -3
- package/dist/esm/utils/toBigmiChainId.d.ts.map +1 -0
- package/dist/esm/utils/toBigmiChainId.js +11 -9
- package/dist/esm/utils/toBigmiChainId.js.map +1 -1
- package/dist/esm/utils/toXOnly.d.ts +5 -1
- package/dist/esm/utils/toXOnly.d.ts.map +1 -0
- package/dist/esm/utils/toXOnly.js +5 -2
- package/dist/esm/utils/toXOnly.js.map +1 -1
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +7 -6
- package/src/BitcoinProvider.ts +1 -1
- package/src/actions/getBitcoinBalance.ts +15 -3
- package/src/client/publicClient.ts +1 -1
- package/src/core/BitcoinStepExecutor.ts +100 -0
- package/src/core/tasks/BitcoinSignAndExecuteTask.ts +168 -0
- package/src/core/tasks/BitcoinWaitForTransactionTask.ts +74 -0
- package/src/types.ts +13 -1
- package/src/utils/generateRedeemScript.ts +3 -1
- package/src/utils/toXOnly.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/cjs/BitcoinStepExecutor.d.ts +0 -12
- package/dist/cjs/BitcoinStepExecutor.js +0 -198
- package/dist/cjs/BitcoinStepExecutor.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/BitcoinStepExecutor.d.ts +0 -12
- package/dist/esm/BitcoinStepExecutor.js +0 -210
- package/dist/esm/BitcoinStepExecutor.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/types/BitcoinProvider.d.ts +0 -3
- package/dist/types/BitcoinProvider.d.ts.map +0 -1
- package/dist/types/BitcoinStepExecutor.d.ts +0 -13
- package/dist/types/BitcoinStepExecutor.d.ts.map +0 -1
- package/dist/types/actions/getBitcoinBalance.d.ts +0 -3
- package/dist/types/actions/getBitcoinBalance.d.ts.map +0 -1
- package/dist/types/actions/resolveBitcoinAddress.d.ts +0 -2
- package/dist/types/actions/resolveBitcoinAddress.d.ts.map +0 -1
- package/dist/types/client/publicClient.d.ts +0 -12
- package/dist/types/client/publicClient.d.ts.map +0 -1
- package/dist/types/errors/parseBitcoinErrors.d.ts +0 -3
- package/dist/types/errors/parseBitcoinErrors.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -10
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils/generateRedeemScript.d.ts +0 -7
- package/dist/types/utils/generateRedeemScript.d.ts.map +0 -1
- package/dist/types/utils/isPsbtFinalized.d.ts +0 -3
- package/dist/types/utils/isPsbtFinalized.d.ts.map +0 -1
- package/dist/types/utils/toBigmiChainId.d.ts +0 -4
- package/dist/types/utils/toBigmiChainId.d.ts.map +0 -1
- package/dist/types/utils/toXOnly.d.ts +0 -2
- package/dist/types/utils/toXOnly.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -3
- package/dist/types/version.d.ts.map +0 -1
- package/src/BitcoinStepExecutor.ts +0 -333
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
9
|
+
interface BitcoinStepExecutorContext extends StepExecutorContext {
|
|
10
|
+
walletClient: Client;
|
|
11
|
+
publicClient: PublicClient;
|
|
12
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
8
13
|
}
|
|
9
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
1
|
+
import { payments } from "bitcoinjs-lib";
|
|
2
|
+
//#region src/utils/generateRedeemScript.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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","
|
|
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
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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","
|
|
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
|
|
2
|
-
import { ChainId } from
|
|
3
|
-
|
|
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
|
|
2
|
-
import { ChainId } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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","
|
|
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"}
|
|
@@ -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
|
-
|
|
2
|
-
|
|
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","
|
|
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
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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"}
|
package/dist/esm/version.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","
|
|
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
|
|
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/
|
|
21
|
-
"typings": "./dist/
|
|
20
|
+
"types": "./dist/esm/index.d.ts",
|
|
21
|
+
"typings": "./dist/esm/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"types": "./dist/
|
|
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.
|
|
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
|
|
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",
|
package/src/BitcoinProvider.ts
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
+
}
|