@lifi/sdk-provider-bitcoin 4.0.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @lifi/sdk-provider-bitcoin
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`bf3d047`](https://github.com/lifinance/sdk/commit/bf3d047ebdc9a8b3a5a6362f65d25aa1eb652ffa)]:
8
+ - @lifi/sdk@4.0.1
9
+
3
10
  ## 4.0.0
4
11
 
5
12
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,GACrB,KAAK,SAAA,GAAA,YAAA,MAC9B,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,YAAA,GAAA,YAAA,cAbmB;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAIA,6BAAAA,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,YAAA,GAAA,YAAA,WAAiC;GACjC,YAAA,GAAA,YAAA,UAAoB;gCACP;iCACC;6BACJ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,EACE,OAAOC,YAAAA,aAAa,EACpB,OAAOC,YAAAA,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
1
+ {"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,EAAA,CACrB,KAAK,SAAA,GAAA,YAAA,KAAA,CAC9B,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,YAAA,GAAA,YAAA,aAAA,CAbmB;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAIA,6BAAAA,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,YAAA,GAAA,YAAA,UAAA,CAAiC;GACjC,YAAA,GAAA,YAAA,SAAA,CAAoB;gCACP;iCACC;6BACJ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,CAAC,CACC,OAAOC,YAAAA,aAAa,CAAC,CACrB,OAAOC,YAAAA,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,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C3B,IAAI,IAAI,IAAI,cAAc,GACxB,IAAI,IAAI,cAAc,EAAG,eAAe,KAAK,KAAK;QAElD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,KAAK;GACxB,CAAC;GAEH,OAAO;EACT,mBAAG,IAAI,IAGL,CAAC,EACF,OAAO,CACZ;EAGA,MAAM,gBAAgB,OAAA,GAAA,YAAA,oBAAA,GAAA,YAAA,UAET,cAAc;GACrB,MAAM,KAAK,MAAM;GACH;GACd,UAAU;EACZ,CAAC,GACH;GACE,SAAS;GACT,eAAe,IAAIJ,UAAAA,iBACjBC,UAAAA,cAAc,oBACd,0BACF;EACF,CACF;EAEA,MAAM,aAAaE,cAAAA,KAAK,QAAQ,aAAa;EAE7C,IAAI,CAACM,8BAAAA,gBAAgB,UAAU,GAC7B,WAAW,kBAAkB;EAG/B,MAAM,QAAQ,WAAW,mBAAmB,EAAE,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
1
+ {"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WAC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M,cACzBH,cAAAA,QAAQ,iBACN,MAAM,YAAY,QAClBD,cAAAA,SAAS,OACX,IACC,aAAa,SAAS;GAC3B,IAAI,IAAI,IAAI,cAAc,GACxB,IAAI,IAAI,cAAc,CAAC,CAAE,eAAe,KAAK,KAAK;QAElD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,KAAK;GACxB,CAAC;GAEH,OAAO;EACT,mBAAG,IAAI,IAGL,CAAC,CAAC,CACH,OAAO,CACZ;EAGA,MAAM,gBAAgB,OAAA,GAAA,YAAA,YAAA,QAAA,GAAA,YAAA,SAAA,CAET,cAAc;GACrB,MAAM,KAAK,MAAM;GACH;GACd,UAAU;EACZ,CAAC,GACH;GACE,SAAS;GACT,eAAe,IAAIJ,UAAAA,iBACjBC,UAAAA,cAAc,oBACd,0BACF;EACF,CACF;EAEA,MAAM,aAAaE,cAAAA,KAAK,QAAQ,aAAa;EAE7C,IAAI,CAACM,8BAAAA,gBAAgB,UAAU,GAC7B,WAAW,kBAAkB;EAG/B,MAAM,QAAQ,WAAW,mBAAmB,CAAC,CAAC,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;AAUA,IAAa,gCAAb,cAAmDA,UAAAA,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,oEACF;EAGF,YAAY,IAAI;EAEhB,IAAI;EACJ,MAAM,cAAc,OAAA,GAAA,YAAA,oBAAyB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;IAC/E,CAAC;GACH;EACF,CAAC;EAED,IAAI,sBAAsB,aACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,4BACF;EAGF,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;EACtE,CAAC;EAGH,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
1
+ {"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;AAUA,IAAa,gCAAb,cAAmDA,UAAAA,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,oEACF;EAGF,YAAY,IAAI;EAEhB,IAAI;EACJ,MAAM,cAAc,OAAA,GAAA,YAAA,mBAAA,CAAyB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;IAC/E,CAAC;GACH;EACF,CAAC;EAED,IAAI,sBAAsB,aACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,4BACF;EAGF,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;EACtE,CAAC;EAGH,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateRedeemScript.js","names":["payments"],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;;AAOA,MAAa,wBACX,cAGAA,cAAAA,SAAS,OAAO,EAAE,QAAQ,UAAU,CAAC,EAAE"}
1
+ {"version":3,"file":"generateRedeemScript.js","names":["payments"],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;;AAOA,MAAa,wBACX,cAGAA,cAAAA,SAAS,OAAO,EAAE,QAAQ,UAAU,CAAC,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-bitcoin";
3
- declare const version = "4.0.0";
3
+ declare const version = "4.0.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/version.ts
3
3
  const name = "@lifi/sdk-provider-bitcoin";
4
- const version = "4.0.0";
4
+ const version = "4.0.1";
5
5
  //#endregion
6
6
  exports.name = name;
7
7
  exports.version = version;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,GACrB,KAAK,QACnC,KAAK,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,WAbM,aAAa;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAI,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,WAAW,UAAsB;GACjC,WAAW,SAAS;IAClB,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,EACE,OAAO,aAAa,EACpB,OAAO,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
1
+ {"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,EAAA,CACrB,KAAK,QACnC,KAAK,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,WAbM,aAAa;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAI,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,WAAW,UAAsB;GACjC,WAAW,SAAS;IAClB,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,CAAC,CACC,OAAO,aAAa,CAAC,CACrB,OAAO,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAA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MAAM,kBAExB,SAAS,cAAc;GACrB,MAAM,KAAK,MAAM;GACH;GACd,UAAU;EACZ,CAAC,GACH;GACE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,0BACF;EACF,CACF;EAEA,MAAM,aAAa,KAAK,QAAQ,aAAa;EAE7C,IAAI,CAAC,gBAAgB,UAAU,GAC7B,WAAW,kBAAkB;EAG/B,MAAM,QAAQ,WAAW,mBAAmB,EAAE,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
1
+ {"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,yBAAyB,MAAM,0BACnC,MACA,gBACF;EAEA,YAAY,IAAI;EAEhB,MAAM,UAAU;EAIhB,WAAW,GAAG;EAEd,MAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,SAAS,SAAS,QAAQ,CAAC;EAEhE,KAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,cAAc,eAHG,MAAM,cACzB,QAAQ,iBAA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BAAmB,CAAC,CAAC,MAAM;EAEpD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,MACP,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO,EACL,QAAQ,YACV;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateRedeemScript.js","names":[],"sources":["../../../src/utils/generateRedeemScript.ts"],"sourcesContent":["import { payments } from 'bitcoinjs-lib'\n\n/**\n * Generate redeem script for P2SH addresses\n * @param publicKey\n * @returns redeem script\n */\nexport const generateRedeemScript = (\n publicKey: Uint8Array\n): Uint8Array | undefined =>\n // P2SH addresses are created by hashing the public key and using the result as the script\n payments.p2wpkh({ pubkey: publicKey }).output\n"],"mappings":";;;;;;;AAOA,MAAa,wBACX,cAGA,SAAS,OAAO,EAAE,QAAQ,UAAU,CAAC,EAAE"}
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,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-bitcoin";
3
- declare const version = "4.0.0";
3
+ declare const version = "4.0.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-bitcoin";
3
- const version = "4.0.0";
3
+ const version = "4.0.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
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.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": {
@@ -32,7 +32,7 @@
32
32
  "@bitcoinerlab/secp256k1": "^1.2.0",
33
33
  "bech32": "^2.0.0",
34
34
  "bitcoinjs-lib": "^7.0.1",
35
- "@lifi/sdk": "4.0.0"
35
+ "@lifi/sdk": "4.0.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-bitcoin'
2
- export const version = '4.0.0'
2
+ export const version = '4.0.1'