@lifi/sdk-provider-bitcoin 4.0.0-alpha.21 → 4.0.0-alpha.23
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/dist/cjs/BitcoinProvider.d.ts +7 -2
- package/dist/cjs/BitcoinProvider.js +31 -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 +17 -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 +15 -4
- package/dist/cjs/client/publicClient.js +39 -42
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/BitcoinStepExecutor.d.ts +16 -12
- package/dist/cjs/core/BitcoinStepExecutor.js +46 -51
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.d.ts +9 -4
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js +73 -99
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.d.ts +9 -4
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +37 -43
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/errors/parseBitcoinErrors.d.ts +7 -2
- package/dist/cjs/errors/parseBitcoinErrors.js +18 -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 +17 -12
- package/dist/cjs/types.js +8 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/generateRedeemScript.d.ts +10 -1
- package/dist/cjs/utils/generateRedeemScript.js +12 -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 +11 -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 +17 -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 +14 -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 +16 -12
- package/dist/esm/core/BitcoinStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/BitcoinStepExecutor.js +45 -50
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts +9 -4
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js +71 -105
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts +9 -4
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js +36 -40
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- 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 +17 -12
- 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 +6 -6
- package/src/core/BitcoinStepExecutor.ts +4 -2
- package/src/utils/generateRedeemScript.ts +3 -1
- package/src/utils/toXOnly.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/cjs/index.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/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 -11
- package/dist/types/client/publicClient.d.ts.map +0 -1
- package/dist/types/core/BitcoinStepExecutor.d.ts +0 -16
- package/dist/types/core/BitcoinStepExecutor.d.ts.map +0 -1
- package/dist/types/core/tasks/BitcoinSignAndExecuteTask.d.ts +0 -6
- package/dist/types/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +0 -1
- package/dist/types/core/tasks/BitcoinWaitForTransactionTask.d.ts +0 -6
- package/dist/types/core/tasks/BitcoinWaitForTransactionTask.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 -16
- 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
|
@@ -1,106 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
signingIndexes: [index],
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return map;
|
|
76
|
-
}, new Map())
|
|
77
|
-
.values());
|
|
78
|
-
// We give users 10 minutes to sign the transaction or it should be considered expired
|
|
79
|
-
const signedPsbtHex = await withTimeout(() => signPsbt(walletClient, {
|
|
80
|
-
psbt: psbt.toHex(),
|
|
81
|
-
inputsToSign: inputsToSign,
|
|
82
|
-
finalize: false,
|
|
83
|
-
}), {
|
|
84
|
-
timeout: 600_000,
|
|
85
|
-
errorInstance: new TransactionError(LiFiErrorCode.TransactionExpired, 'Transaction has expired.'),
|
|
86
|
-
});
|
|
87
|
-
const signedPsbt = Psbt.fromHex(signedPsbtHex);
|
|
88
|
-
if (!isPsbtFinalized(signedPsbt)) {
|
|
89
|
-
signedPsbt.finalizeAllInputs();
|
|
90
|
-
}
|
|
91
|
-
const txHex = signedPsbt.extractTransaction().toHex();
|
|
92
|
-
const txHash = await publicClient.sendUTXOTransaction({
|
|
93
|
-
hex: txHex,
|
|
94
|
-
});
|
|
95
|
-
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
96
|
-
txHash: txHash,
|
|
97
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
|
|
98
|
-
txHex,
|
|
99
|
-
signedAt: Date.now(),
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
status: 'COMPLETED',
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
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
|
+
|
|
106
72
|
//# sourceMappingURL=BitcoinSignAndExecuteTask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinSignAndExecuteTask.js","
|
|
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,OACrC;AAED,MAAI,CAAC,OACH,OAAM,IAAI,iBACR,cAAc,uBACd,mDACD;EAGH,MAAM,yBAAyB,MAAM,0BACnC,MACA,iBACD;AAED,cAAY,KAAK;EAEjB,MAAM,UAAU;AAIhB,aAAW,IAAI;EAEf,MAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,SAAS,SAAS,SAAS,CAAC;AAEjE,OAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,cAAc,eAHG,MAAM,cACzB,QAAQ,iBAAiB,MAAM,YAAY,QAAQ,SAAS,QAAQ,GACnE,aAAa,SAAS,QACuB;AAClD,OAAI,YAAY,SAAS,YAAY,MAAM;AAKzC,QAAI,CAAC,MAAM,gBAAgB;KACzB,MAAM,SAAS,aAAa,SAAS;AACrC,SAAI,QAAQ;MACV,MAAM,iBAAiB,QAAQ,gBAAgB,OAAO,CAAC;AACvD,WAAK,YAAY,OAAO,EACtB,gBACD,CAAC;;;AAKN,QAAI,CAAC,MAAM,YACT,MAAK,YAAY,OAAO,EACtB,aAAa,GACd,CAAC;;AAIN,OAAI,YAAY,SAAS,YAAY;QAC/B,CAAC,MAAM,cAAc;KACvB,MAAM,SAAS,aAAa,SAAS;AACrC,SAAI,OACF,MAAK,YAAY,OAAO,EACtB,cAAc,qBAAqB,gBAAgB,OAAO,CAAC,EAC5D,CAAC;;;IAIR;EAEF,MAAM,eAAe,MAAM,KACzB,KAAK,KAAK,OACP,QAAQ,KAAK,OAAO,UAAU;GAC7B,MAAM,iBAAiB,MAAM,cACzB,QAAQ,iBACN,MAAM,YAAY,QAClB,SAAS,QACV,GACA,aAAa,SAAS;AAC3B,OAAI,IAAI,IAAI,eAAe,CACzB,KAAI,IAAI,eAAe,CAAE,eAAe,KAAK,MAAM;OAEnD,KAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,MAAM;IACxB,CAAC;AAEJ,UAAO;qBACN,IAAI,KAGJ,CAAC,CACH,QAAQ,CACZ;EAGD,MAAM,gBAAgB,MAAM,kBAExB,SAAS,cAAc;GACrB,MAAM,KAAK,OAAO;GACJ;GACd,UAAU;GACX,CAAC,EACJ;GACE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,2BACD;GACF,CACF;EAED,MAAM,aAAa,KAAK,QAAQ,cAAc;AAE9C,MAAI,CAAC,gBAAgB,WAAW,CAC9B,YAAW,mBAAmB;EAGhC,MAAM,QAAQ,WAAW,oBAAoB,CAAC,OAAO;EAErD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,OACN,CAAC;AAEF,gBAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,KAAK;GACrB,CAAC;AAEF,SAAO,EACL,QAAQ,aACT"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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>;
|
|
5
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"}
|
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
import { waitForTransaction } from
|
|
2
|
-
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return { status: 'COMPLETED' };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
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
|
+
|
|
41
37
|
//# sourceMappingURL=BitcoinWaitForTransactionTask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWaitForTransactionTask.js","
|
|
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,OACrC;EAED,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;AAEvB,MAAI,CAAC,UAAU,CAAC,MACd,OAAM,IAAI,iBACR,cAAc,uBACd,qEACD;AAGH,cAAY,KAAK;EAEjB,IAAI;EACJ,MAAM,cAAc,MAAM,mBAAmB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;AACxB,wBAAoB,SAAS;AAC7B,kBAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;KAC9E,CAAC;;GAEL,CAAC;AAEF,MAAI,sBAAsB,YACxB,OAAM,IAAI,iBACR,cAAc,qBACd,6BACD;AAGH,MAAI,YAAY,SAAS,OACvB,eAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;GACrE,CAAC;AAGJ,MAAI,kBACF,eAAc,aAAa,MAAM,OAAO,MAAM,OAAO;AAGvD,SAAO,EAAE,QAAQ,aAAa"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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","
|
|
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;AACtB,KAAI,aAAa,UAAU;AACzB,IAAE,OAAO,EAAE,QAAQ;AACnB,IAAE,SAAS,EAAE,UAAU;AACvB,SAAO;;AAKT,QAAO,IAAI,SAFO,qBAAqB,EAAE,EAEV,MAAM,OAAO;;AAG9C,MAAM,wBAAwB,MAAW;AAEvC,KACE,EAAE,SAAS,WAAW,WAAW,IACjC,EAAE,OAAO,SAAS,WAAW,WAAW,CAExC,QAAO,IAAI,iBACT,cAAc,qBACd,0IACA,EACD;AAEH,KAAI,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAU,EAAE,OAAO,WAAW,WAAW,CACzE,QAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,EAAE;AAE5E,KAAI,EAAE,SAAS,MAAM,EAAE,SAAS,UAAU,EAAE,SAAS,OACnD,QAAO,IAAI,iBAAiB,cAAc,UAAU,EAAE,SAAS,EAAE;AAGnE,KAAI,aAAa,UACf,QAAO;AAGT,QAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,EAAE"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { isBitcoinProvider }
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
export { isBitcoinProvider }
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { BitcoinProvider } from "./BitcoinProvider.js";
|
|
2
|
+
import { isBitcoinProvider } from "./types.js";
|
|
3
|
+
export { BitcoinProvider, isBitcoinProvider };
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":
|
|
1
|
+
{"type":"module","sideEffects":false}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
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>;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
interface BitcoinStepExecutorContext extends StepExecutorContext {
|
|
10
|
+
walletClient: Client;
|
|
11
|
+
publicClient: PublicClient;
|
|
12
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
interface BitcoinSDKProvider extends SDKProvider {
|
|
15
|
+
setOptions(options: BitcoinProviderOptions): void;
|
|
14
16
|
}
|
|
15
|
-
|
|
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
|
|
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;AAChC,QAAO,SAAS,SAAS,UAAU"}
|
|
@@ -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,WAAW,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,IAAA,EAAM,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;AACnD,KAAI;AACF,OAAK,oBAAoB;AACzB,SAAO;UACA,GAAG;AACV,SAAO"}
|