@lifi/sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
31 lines • 1.07 kB
JavaScript
import { ChainId as BigmiChainId } from '@bigmi/core';
import { ChainId } from '@lifi/types';
import { payments } from 'bitcoinjs-lib';
export function isPsbtFinalized(psbt) {
try {
psbt.extractTransaction();
return true;
}
catch (_) {
return false;
}
}
// helper function to convert full public key (33 bytes) to x-only compressed format (32 bytes) required after taproot update
export const toXOnly = (pubKey) => pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
export const toBigmiChainId = (chainId) => {
switch (chainId) {
case ChainId.BTC:
return BigmiChainId.BITCOIN_MAINNET;
default:
throw new Error(`Unsupported chainId mapping: ${chainId}`);
}
};
/**
* Generate redeem script for P2SH addresses
* @param publicKey
* @returns redeem script
*/
export const generateRedeemScript = (publicKey) =>
// P2SH addresses are created by hashing the public key and using the result as the script
payments.p2wpkh({ pubkey: publicKey }).output;
//# sourceMappingURL=utils.js.map