@babylonlabs-io/ts-sdk 0.8.1 → 0.10.0
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/errors-CIDTtluC.cjs +2 -0
- package/dist/errors-CIDTtluC.cjs.map +1 -0
- package/dist/errors-fLxe1eml.js +2086 -0
- package/dist/errors-fLxe1eml.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +73 -69
- package/dist/index.js.map +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.d.ts +2 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +6 -5
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/index.d.ts +2 -4
- package/dist/shared/wallets/index.d.ts.map +1 -1
- package/dist/shared/wallets/interfaces/index.d.ts +1 -1
- package/dist/shared/wallets/interfaces/index.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +1 -0
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +62 -55
- package/dist/tbv/core/lamport/__tests__/derivation.test.d.ts +2 -0
- package/dist/tbv/core/lamport/__tests__/derivation.test.d.ts.map +1 -0
- package/dist/tbv/core/lamport/derivation.d.ts +78 -0
- package/dist/tbv/core/lamport/derivation.d.ts.map +1 -0
- package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts +9 -0
- package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts.map +1 -0
- package/dist/tbv/core/lamport/errors.d.ts +7 -0
- package/dist/tbv/core/lamport/errors.d.ts.map +1 -0
- package/dist/tbv/core/lamport/index.d.ts +5 -0
- package/dist/tbv/core/lamport/index.d.ts.map +1 -0
- package/dist/tbv/core/lamport/types.d.ts +33 -0
- package/dist/tbv/core/lamport/types.d.ts.map +1 -0
- package/dist/tbv/core/managers/PeginManager.d.ts +10 -31
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/utils/__tests__/signing.test.d.ts +2 -0
- package/dist/tbv/core/utils/__tests__/signing.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.d.ts +1 -0
- package/dist/tbv/core/utils/index.d.ts.map +1 -1
- package/dist/{shared/wallets/signOptions.d.ts → tbv/core/utils/signing.d.ts} +2 -2
- package/dist/tbv/core/utils/signing.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +62 -55
- package/dist/{shared/wallets/mocks → testing}/MockBitcoinWallet.d.ts +2 -2
- package/dist/testing/MockBitcoinWallet.d.ts.map +1 -0
- package/dist/testing/MockEthereumWallet.d.ts.map +1 -0
- package/dist/testing/__tests__/MockEthereumWallet.test.d.ts +2 -0
- package/dist/testing/__tests__/MockEthereumWallet.test.d.ts.map +1 -0
- package/dist/testing/index.cjs +2 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/{MockEthereumWallet-ibdry7pZ.js → testing/index.js} +6 -8
- package/dist/testing/index.js.map +1 -0
- package/package.json +8 -1
- package/dist/MockEthereumWallet-CKQlH2AM.cjs +0 -2
- package/dist/MockEthereumWallet-CKQlH2AM.cjs.map +0 -1
- package/dist/MockEthereumWallet-ibdry7pZ.js.map +0 -1
- package/dist/PayoutManager-6IBl1Fdt.js +0 -1203
- package/dist/PayoutManager-6IBl1Fdt.js.map +0 -1
- package/dist/PayoutManager-EZFN4Y4Z.cjs +0 -2
- package/dist/PayoutManager-EZFN4Y4Z.cjs.map +0 -1
- package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts +0 -2
- package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts.map +0 -1
- package/dist/shared/wallets/__tests__/signOptions.test.d.ts +0 -2
- package/dist/shared/wallets/__tests__/signOptions.test.d.ts.map +0 -1
- package/dist/shared/wallets/mocks/MockBitcoinWallet.d.ts.map +0 -1
- package/dist/shared/wallets/mocks/MockEthereumWallet.d.ts.map +0 -1
- package/dist/shared/wallets/mocks/index.d.ts.map +0 -1
- package/dist/shared/wallets/signOptions.d.ts.map +0 -1
- package/dist/signOptions-Deg5lCoC.cjs +0 -2
- package/dist/signOptions-Deg5lCoC.cjs.map +0 -1
- package/dist/signOptions-Drwr3bXB.js +0 -16
- package/dist/signOptions-Drwr3bXB.js.map +0 -1
- /package/dist/{shared/wallets/mocks → testing}/MockEthereumWallet.d.ts +0 -0
- /package/dist/{shared/wallets/mocks → testing}/index.d.ts +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var le=Object.defineProperty;var he=(e,t,n)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var f=(e,t,n)=>he(e,typeof t!="symbol"?t+"":t,n);const L=require("bitcoinjs-lib"),B=require("buffer"),m=require("./challengeAssert-DDceAi0r.cjs"),W=require("viem"),Pt=require("@babylonlabs-io/babylon-tbv-rust-wasm");function fe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const de=fe(L);function Ot(e,t,n){if(e.length===0)throw new Error("Insufficient funds: no UTXOs available");const s=e.filter(c=>{const l=B.Buffer.from(c.scriptPubKey,"hex");return!!L.script.decompile(l)});if(s.length===0)throw new Error("Insufficient funds: no valid UTXOs available (all have invalid scripts)");const r=[...s].sort((c,l)=>l.value-c.value),o=[];let i=0n,a=0n;for(const c of r){o.push(c),i+=BigInt(c.value);const l=o.length*m.P2TR_INPUT_SIZE,h=2*m.MAX_NON_LEGACY_OUTPUT_SIZE,u=l+h+m.TX_BUFFER_SIZE_OVERHEAD;if(a=BigInt(Math.ceil(u*n))+BigInt(m.rateBasedTxBufferFee(n)),i-t-a>m.DUST_THRESHOLD){const p=BigInt(Math.ceil(m.MAX_NON_LEGACY_OUTPUT_SIZE*n));a+=p}if(i>=t+a){const p=i-t-a;return{selectedUTXOs:o,totalValue:i,fee:a,changeAmount:p}}}throw new Error(`Insufficient funds: need ${t+a} sats (${t} pegin + ${a} fee), have ${i} sats`)}function pe(e){return e>m.DUST_THRESHOLD}function be(){return m.BTC_DUST_SAT}function bt(e){const t=e.startsWith("0x")?e.slice(2):e;return`0x${L.Transaction.fromHex(t).getId()}`}function xe(e,t,n){if(e.length===0)throw new Error("No input UTXOs provided for split transaction");if(t.length===0)throw new Error("No outputs specified for split transaction");for(const c of t)if(c.amount<=0n)throw new Error(`Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`);const s=m.getNetwork(n),r=new L.Transaction;r.version=2;for(const c of e){const l=B.Buffer.from(c.txid,"hex").reverse();r.addInput(l,c.vout)}const o=[];for(let c=0;c<t.length;c++){const l=t[c];let h;try{h=L.address.toOutputScript(l.address,s)}catch(u){throw new Error(`Failed to decode address "${l.address}": ${u instanceof Error?u.message:String(u)}`)}r.addOutput(h,Number(l.amount)),o.push({txid:"",vout:c,value:Number(l.amount),scriptPubKey:h.toString("hex")})}const i=r.toHex(),a=r.getId();for(const c of o)c.txid=a;return{txHex:i,txid:a,outputs:o}}function ge(e,t,n){const s=L.Transaction.fromHex(e),r=new L.Psbt;if(r.setVersion(s.version),r.setLocktime(s.locktime),!B.Buffer.isBuffer(n)||n.length!==32)throw new Error(`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${B.Buffer.isBuffer(n)?`${n.length}-byte Buffer`:typeof n}`);if(t.length!==s.ins.length)throw new Error(`UTXO count mismatch: transaction has ${s.ins.length} input${s.ins.length!==1?"s":""}, but ${t.length} UTXO${t.length!==1?"s were":" was"} provided`);for(let o=0;o<s.ins.length;o++){const i=s.ins[o],a=t[o];if(!a)throw new Error(`Missing UTXO data for input ${o}`);const c=B.Buffer.from(i.hash).reverse().toString("hex"),l=i.index;if(a.txid!==c||a.vout!==l)throw new Error(`Input ${o} outpoint mismatch: transaction expects ${c}:${l}, but UTXO ${a.txid}:${a.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`);const h=B.Buffer.from(a.scriptPubKey,"hex");if(!(h.length===34&&h[0]===81&&h[1]===32))throw new Error(`Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${a.scriptPubKey.substring(0,20)}...`);const d={script:B.Buffer.from(a.scriptPubKey,"hex"),value:a.value};r.addInput({hash:i.hash,index:i.index,sequence:i.sequence,witnessUtxo:d,tapInternalKey:n})}for(const o of s.outs)r.addOutput({script:o.script,value:o.value});return r.toHex()}var G=(e=>(e.P2PKH="P2PKH",e.P2SH="P2SH",e.P2WPKH="P2WPKH",e.P2WSH="P2WSH",e.P2TR="P2TR",e.UNKNOWN="UNKNOWN",e))(G||{});function $t(e){const t=e.length;return t===25&&e[0]===118&&e[1]===169&&e[2]===20&&e[23]===136&&e[24]===172?"P2PKH":t===23&&e[0]===169&&e[1]===20&&e[22]===135?"P2SH":t===22&&e[0]===0&&e[1]===20?"P2WPKH":t===34&&e[0]===0&&e[1]===32?"P2WSH":t===34&&e[0]===81&&e[1]===32?"P2TR":"UNKNOWN"}function _t(e,t){const n=B.Buffer.from(e.scriptPubKey,"hex"),s=$t(n);switch(s){case G.P2WPKH:return{witnessUtxo:{script:n,value:e.value}};case G.P2WSH:{if(!e.witnessScript)throw new Error("Missing witnessScript for P2WSH input");return{witnessUtxo:{script:n,value:e.value},witnessScript:B.Buffer.from(e.witnessScript,"hex")}}case G.P2TR:{if(t&&t.length!==32)throw new Error(`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`);return{witnessUtxo:{script:n,value:e.value},...t&&{tapInternalKey:t}}}default:throw new Error(`Unsupported script type: ${s}`)}}function it(e,t){if(!Number.isInteger(t)||t<1)throw new Error(`inputCount must be a positive integer, got ${t}`);return{autoFinalized:!1,signInputs:Array.from({length:t},(n,s)=>({index:s,publicKey:e,disableTweakSigner:!0}))}}const ye=21e6*1e8,Ft=1e4;function Ct(e){return Number.isInteger(e)&&e>0&&e<=ye}function me(e){return Number.isInteger(e)&&e>0&&e<=Ft}function Rt(e,t){return!Number.isInteger(e)||e<0?!1:t===void 0||e<t}const Vt={mainnet:"https://mempool.space/api",testnet:"https://mempool.space/testnet/api",signet:"https://mempool.space/signet/api"};async function at(e,t){try{const n=await fetch(e,t);if(!n.ok){const r=await n.text();throw new Error(`Mempool API error (${n.status}): ${r||n.statusText}`)}const s=n.headers.get("content-type");return s!=null&&s.includes("application/json")?await n.json():await n.text()}catch(n){throw n instanceof Error?new Error(`Failed to fetch from mempool API: ${n.message}`):new Error("Failed to fetch from mempool API: Unknown error")}}async function Dt(e,t){try{const n=await fetch(`${t}/tx`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}});if(!n.ok){const r=await n.text();let o;try{o=JSON.parse(r).message}catch{o=r}throw new Error(o||`Failed to broadcast transaction: ${n.statusText}`)}return await n.text()}catch(n){throw n instanceof Error?new Error(`Failed to broadcast BTC transaction: ${n.message}`):new Error("Failed to broadcast BTC transaction: Unknown error")}}async function Wt(e,t){return at(`${t}/tx/${e}`)}async function we(e,t){try{const n=await fetch(`${t}/tx/${e}/hex`);if(!n.ok){const s=await n.text();throw new Error(`Mempool API error (${n.status}): ${s||n.statusText}`)}return await n.text()}catch(n){throw n instanceof Error?new Error(`Failed to get transaction hex for ${e}: ${n.message}`):new Error(`Failed to get transaction hex for ${e}: Unknown error`)}}async function Kt(e,t,n){const s=await Wt(e,n);if(!Rt(t,s.vout.length))throw new Error(`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`);const r=s.vout[t];if(!Ct(r.value))throw new Error(`Invalid UTXO value ${r.value} for ${e}:${t}`);return{txid:e,vout:t,value:r.value,scriptPubKey:r.scriptpubkey}}async function Pe(e,t){try{const n=await at(`${t}/address/${e}/utxo`),s=await at(`${t}/v1/validate-address/${e}`);if(!s.isvalid)throw new Error(`Invalid Bitcoin address: ${e}. Mempool API validation failed.`);for(const o of n){if(!Rt(o.vout))throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);if(!Ct(o.value))throw new Error(`Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`)}return n.sort((o,i)=>i.value-o.value).map(o=>({txid:o.txid,vout:o.vout,value:o.value,scriptPubKey:s.scriptPubKey,confirmed:o.status.confirmed}))}catch(n){throw n instanceof Error?new Error(`Failed to get UTXOs for address ${e}: ${n.message}`):new Error(`Failed to get UTXOs for address ${e}: Unknown error`)}}function Te(e){return Vt[e]}async function ve(e,t){return at(`${t}/address/${e}/txs`)}async function He(e){const t=await fetch(`${e}/v1/fees/recommended`);if(!t.ok)throw new Error(`Failed to fetch network fees: ${t.status} ${t.statusText}`);const n=await t.json(),s=["fastestFee","halfHourFee","hourFee","economyFee","minimumFee"];for(const r of s)if(!me(n[r]))throw new Error(`Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Ft}`);if(n.minimumFee>n.economyFee||n.economyFee>n.hourFee||n.hourFee>n.halfHourFee||n.halfHourFee>n.fastestFee)throw new Error(`Fee rate ordering violation from mempool API: expected minimumFee (${n.minimumFee}) <= economyFee (${n.economyFee}) <= hourFee (${n.hourFee}) <= halfHourFee (${n.halfHourFee}) <= fastestFee (${n.fastestFee}).`);return n}const st=[{type:"function",name:"submitPeginRequest",inputs:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"btcPopSignature",type:"bytes",internalType:"bytes"},{name:"unsignedPrePeginTx",type:"bytes",internalType:"bytes"},{name:"depositorSignedPeginTx",type:"bytes",internalType:"bytes"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"hashlock",type:"bytes32",internalType:"bytes32"},{name:"htlcVout",type:"uint8",internalType:"uint8"},{name:"depositorPayoutBtcAddress",type:"bytes",internalType:"bytes"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"payable"},{type:"function",name:"submitPeginRequest",inputs:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"btcPopSignature",type:"bytes",internalType:"bytes"},{name:"unsignedPrePeginTx",type:"bytes",internalType:"bytes"},{name:"depositorSignedPeginTx",type:"bytes",internalType:"bytes"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"hashlock",type:"bytes32",internalType:"bytes32"},{name:"htlcVout",type:"uint8",internalType:"uint8"},{name:"referralCode",type:"uint32",internalType:"uint32"},{name:"depositorPayoutBtcAddress",type:"bytes",internalType:"bytes"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"payable"},{type:"function",name:"activateVaultWithSecret",inputs:[{name:"vaultId",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"getPegInFee",inputs:[{name:"vaultProvider",type:"address",internalType:"address"}],outputs:[{name:"totalFee",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getBTCVault",inputs:[{name:"vaultId",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"vault",type:"tuple",internalType:"struct IBTCVaultRegistry.BTCVault",components:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"depositorSignedPeginTx",type:"bytes",internalType:"bytes"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"status",type:"uint8",internalType:"enum IBTCVaultRegistry.BTCVaultStatus"},{name:"applicationEntryPoint",type:"address",internalType:"address"},{name:"universalChallengersVersion",type:"uint16",internalType:"uint16"},{name:"appVaultKeepersVersion",type:"uint16",internalType:"uint16"},{name:"offchainParamsVersion",type:"uint16",internalType:"uint16"},{name:"proverProgramVersion",type:"uint16",internalType:"uint16"},{name:"createdAt",type:"uint256",internalType:"uint256"},{name:"verifiedAt",type:"uint256",internalType:"uint256"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"},{name:"hashlock",type:"bytes32",internalType:"bytes32"},{name:"htlcVout",type:"uint8",internalType:"uint8"}]}],stateMutability:"view"},{type:"error",name:"InvalidPeginFee",inputs:[{name:"provided",type:"uint256",internalType:"uint256"},{name:"required",type:"uint256",internalType:"uint256"}]},{type:"error",name:"InvalidSecret",inputs:[]},{type:"error",name:"ActivationDeadlineExpired",inputs:[]},{type:"error",name:"InvalidHashlock",inputs:[]},{type:"error",name:"DuplicateHashlock",inputs:[]},{type:"error",name:"CapExceeded",inputs:[]},{type:"error",name:"InvalidOutputIndex",inputs:[]},{type:"error",name:"PeginSignaturesIncomplete",inputs:[]}],V={"0x04aabf33":"Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.","0x4fec082d":"Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.","0x6cc363a5":"Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.","0x6c3f2bf6":"Invalid BTC public key: The Bitcoin public key format is invalid.","0x2c5211c6":"Invalid amount: The deposit amount is invalid or below the minimum required.","0x0405f772":"Application not registered: The application controller is not registered in the system.","0x24e165cc":"Invalid provider status: The vault provider is not in a valid state to accept deposits.","0xd92e233d":"Zero address: One of the required addresses is the zero address.","0x65aa7007":"BTC key mismatch: The Bitcoin public key does not match the expected key.","0x82b42900":"Unauthorized: You must be the depositor or vault provider to submit this transaction.","0x8baa579f":"Invalid signature: The BTC proof of possession signature could not be verified.","0x2f9d01e9":"Invalid BTC transaction: The Bitcoin transaction format is invalid.","0x5a3c6b3e":"Vault provider not registered: The selected vault provider is not registered.","0x979f4518":"Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."};function ct(e){if(!e||typeof e!="object")return;const t=e;if(typeof t.data=="string"&&t.data.startsWith("0x"))return t.data;if(typeof t.details=="string"&&t.details.startsWith("0x"))return t.details;let n=t.cause,s=0;const r=5;for(;n&&typeof n=="object"&&s<r;){const a=n;if(typeof a.data=="string"&&a.data.startsWith("0x"))return a.data;n=a.cause,s++}const i=(typeof t.message=="string"?t.message:"").match(/\b(0x[a-fA-F0-9]{8})\b/);if(i)return i[1]}function ke(e){const t=ct(e);if(t){const n=t.substring(0,10);return V[t]??V[n]}}function Ie(e){const t=ct(e);if(t===void 0)return!1;const n=t.substring(0,10);return t in V||n in V}function rt(e){console.error("[Contract Error] Raw error:",e);const t=ct(e);if(console.error("[Contract Error] Extracted error data:",t),t){const s=t.substring(0,10),r=V[t]??V[s];if(r)throw console.error("[Contract Error] Known error:",r),new Error(r)}const n=(e==null?void 0:e.message)||"";if(n.includes("gas limit too high")||n.includes("21000000")||n.includes("Internal JSON-RPC error")){const s=t?` (error code: ${t})`:"";throw console.error("[Contract Error] Transaction rejected. Error code:",t,"Message:",n),new Error(`Transaction failed: The contract rejected this transaction${s}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`)}throw e instanceof Error?(console.error("[Contract Error] Unhandled error:",e.message),e):new Error(`Contract call failed: ${String(e)}`)}function Ee(e,t,n,s){const r=n==null?void 0:n[`${e}:${t}`];return r?Promise.resolve({txid:e,vout:t,value:r.value,scriptPubKey:r.scriptPubKey}):Kt(e,t,s)}const Se=12e4;class Be{constructor(t){f(this,"config");this.config=t}async preparePegin(t){const n=await this.config.btcWallet.getPublicKeyHex(),s=n.length===66?n.slice(2):n,r=m.stripHexPrefix(t.vaultProviderBtcPubkey),o=t.vaultKeeperBtcPubkeys.map(m.stripHexPrefix),i=t.universalChallengerBtcPubkeys.map(m.stripHexPrefix);if(t.hashlocks.length!==1)throw new Error("hashlocks must contain exactly one entry (batched deposits not yet supported)");const a=o.length,c={depositorPubkey:s,vaultProviderPubkey:r,vaultKeeperPubkeys:o,universalChallengerPubkeys:i,hashlocks:t.hashlocks,timelockRefund:t.timelockRefund,pegInAmount:t.amount,feeRate:t.protocolFeeRate,numLocalChallengers:a,councilQuorum:t.councilQuorum,councilSize:t.councilSize,network:this.config.btcNetwork},l=await m.buildPrePeginPsbt(c),h=Ot([...t.availableUTXOs],l.totalOutputValue,t.mempoolFeeRate),u=m.getNetwork(this.config.btcNetwork),d=m.fundPeginTransaction({unfundedTxHex:l.psbtHex,selectedUTXOs:h.selectedUTXOs,changeAddress:t.changeAddress,changeAmount:h.changeAmount,network:u}),p=m.stripHexPrefix(bt(d)),b=await m.buildPeginTxFromFundedPrePegin({prePeginParams:c,timelockPegin:t.timelockPegin,fundedPrePeginTxHex:d,htlcVout:Pt.SINGLE_DEPOSIT_HTLC_VOUT}),w=await m.buildPeginInputPsbt({peginTxHex:b.txHex,fundedPrePeginTxHex:d,depositorPubkey:s,vaultProviderPubkey:r,vaultKeeperPubkeys:o,universalChallengerPubkeys:i,hashlock:t.hashlocks[0],timelockRefund:t.timelockRefund,network:this.config.btcNetwork}),x=await this.config.btcWallet.signPsbt(w.psbtHex,it(n,1)),y=m.extractPeginInputSignature(x,s),P=m.finalizePeginInputPsbt(x);return{fundedPrePeginTxHex:d,htlcValue:l.htlcValue,signedPeginInputPsbtHex:x,peginInputSignature:y,vaultScriptPubKey:b.vaultScriptPubKey,peginTxHex:P,prePeginTxid:p,peginTxid:b.txid,selectedUTXOs:h.selectedUTXOs,fee:h.fee,changeAmount:h.changeAmount}}async signAndBroadcast(t){const{fundedPrePeginTxHex:n,depositorBtcPubkey:s}=t,r=n.startsWith("0x")?n.slice(2):n,o=L.Transaction.fromHex(r);if(o.ins.length===0)throw new Error("Transaction has no inputs");const i=new L.Psbt;i.setVersion(o.version),i.setLocktime(o.locktime);const a=s.startsWith("0x")?s.slice(2):s;if(a.length!==64||!/^[0-9a-fA-F]+$/.test(a))throw new Error("Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)");const c=B.Buffer.from(a,"hex");if(c.length!==32)throw new Error(`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`);const l=this.config.mempoolApiUrl,h=o.ins.map(x=>{const y=B.Buffer.from(x.hash).reverse().toString("hex"),P=x.index;return Ee(y,P,t.localPrevouts,l).then(g=>({input:x,utxoData:g,txid:y,vout:P}))}),u=await Promise.all(h);for(const{input:x,utxoData:y,txid:P,vout:g}of u){const T=_t({value:y.value,scriptPubKey:y.scriptPubKey},c);i.addInput({hash:x.hash,index:x.index,sequence:x.sequence,...T})}for(const x of o.outs)i.addOutput({script:x.script,value:x.value});const d=await this.config.btcWallet.signPsbt(i.toHex()),p=L.Psbt.fromHex(d);try{p.finalizeAllInputs()}catch(x){if(!p.data.inputs.every(P=>P.finalScriptWitness||P.finalScriptSig))throw new Error(`PSBT finalization failed and wallet did not auto-finalize: ${x}`)}const b=p.extractTransaction().toHex();return await Dt(b,l)}async registerPeginOnChain(t){const{depositorBtcPubkey:n,unsignedPrePeginTx:s,depositorSignedPeginTx:r,vaultProvider:o,hashlock:i,onPopSigned:a,depositorPayoutBtcAddress:c,depositorLamportPkHash:l,preSignedBtcPopSignature:h}=t;if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const u=this.config.ethWallet.account.address,d=await this.resolvePopSignature(u,h);a&&await a();const p=m.ensureHexPrefix(n),b=m.ensureHexPrefix(s),w=m.ensureHexPrefix(r),x=await this.resolvePayoutScriptPubKey(c),y=bt(w);if(await this.checkVaultExists(y))throw new Error(`Vault already exists for this transaction (ID: ${y}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`);const g=W.createPublicClient({chain:this.config.ethChain,transport:W.http()});let T;try{T=await g.readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:st,functionName:"getPegInFee",args:[o]})}catch{throw new Error("Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.")}const H=W.encodeFunctionData({abi:st,functionName:"submitPeginRequest",args:[u,p,d,b,w,o,i,Pt.SINGLE_DEPOSIT_HTLC_VOUT,x,l]});let v;try{v=await g.estimateGas({to:this.config.vaultContracts.btcVaultRegistry,data:H,value:T,account:this.config.ethWallet.account.address})}catch(k){rt(k)}let S;try{S=await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultRegistry,data:H,value:T,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:v})}catch(k){rt(k)}const E=await g.waitForTransactionReceipt({hash:S,timeout:Se});return E.status==="reverted"&&rt(new Error(`Transaction reverted. Hash: ${S}. Check the transaction on block explorer for details.`)),{ethTxHash:E.transactionHash,vaultId:y,btcPopSignature:d}}async checkVaultExists(t){try{return(await W.createPublicClient({chain:this.config.ethChain,transport:W.http()}).readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:st,functionName:"getBTCVault",args:[t]})).depositor!==W.zeroAddress}catch{return!1}}async resolvePayoutScriptPubKey(t){let n;if(t)n=t;else{n=await this.config.btcWallet.getAddress();const r=await this.config.btcWallet.getPublicKeyHex();if(!m.isAddressFromPublicKey(n,r,this.config.btcNetwork))throw new Error("The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit).")}const s=m.getNetwork(this.config.btcNetwork);try{return`0x${de.address.toOutputScript(n,s).toString("hex")}`}catch{throw new Error(`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`)}}async resolvePopSignature(t,n){if(n)return n;const s=this.config.vaultContracts.btcVaultRegistry,r=`${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`,o=await this.config.btcWallet.signMessage(r,"bip322-simple");return o.startsWith("0x")?o:`0x${B.Buffer.from(o,"base64").toString("hex")}`}getNetwork(){return this.config.btcNetwork}getVaultContractAddress(){return this.config.vaultContracts.btcVaultRegistry}}class Ae{constructor(t){f(this,"config");this.config=t}async signPayoutTransaction(t){const n=await this.config.btcWallet.getPublicKeyHex(),{depositorPubkey:s}=m.validateWalletPubkey(n,t.depositorBtcPubkey),r=await m.buildPayoutPsbt({payoutTxHex:t.payoutTxHex,peginTxHex:t.peginTxHex,assertTxHex:t.assertTxHex,depositorBtcPubkey:s,vaultProviderBtcPubkey:t.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:t.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:t.universalChallengerBtcPubkeys,timelockPegin:t.timelockPegin,network:this.config.network}),o=await this.config.btcWallet.signPsbt(r.psbtHex,it(n,1));return{signature:m.extractPayoutSignature(o,s),depositorBtcPubkey:s}}getNetwork(){return this.config.network}supportsBatchSigning(){return typeof this.config.btcWallet.signPsbts=="function"}async signPayoutTransactionsBatch(t){if(!this.supportsBatchSigning())throw new Error("Wallet does not support batch signing (signPsbts method not available)");const n=await this.config.btcWallet.getPublicKeyHex(),s=[],r=[],o=[];for(const c of t){const{depositorPubkey:l}=m.validateWalletPubkey(n,c.depositorBtcPubkey);o.push(l);const h=await m.buildPayoutPsbt({payoutTxHex:c.payoutTxHex,peginTxHex:c.peginTxHex,assertTxHex:c.assertTxHex,depositorBtcPubkey:l,vaultProviderBtcPubkey:c.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:c.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:c.universalChallengerBtcPubkeys,timelockPegin:c.timelockPegin,network:this.config.network});s.push(h.psbtHex),r.push(it(n,1))}const i=await this.config.btcWallet.signPsbts(s,r);if(i.length!==t.length)throw new Error(`Expected ${t.length} signed PSBTs but received ${i.length}`);const a=[];for(let c=0;c<t.length;c++){const l=o[c],h=m.extractPayoutSignature(i[c],l);a.push({payoutSignature:h,depositorBtcPubkey:l})}return a}}function Ue(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function R(e,t=""){if(!Number.isSafeInteger(e)||e<0){const n=t&&`"${t}" `;throw new Error(`${n}expected integer >= 0, got ${e}`)}}function D(e,t,n=""){const s=Ue(e),r=e==null?void 0:e.length,o=t!==void 0;if(!s||o&&r!==t){const i=n&&`"${n}" `,a=o?` of length ${t}`:"",c=s?`length=${r}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Mt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");R(e.outputLen),R(e.blockLen)}function N(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Nt(e,t){D(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}function Le(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function A(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ot(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function U(e,t){return e<<32-t|e>>>t}function Z(e,t){return e<<t|e>>>32-t>>>0}const Oe=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function $e(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function _e(e){for(let t=0;t<e.length;t++)e[t]=$e(e[t]);return e}const Tt=Oe?e=>e:_e;function Fe(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function vt(e,t=""){return typeof e=="string"?Fe(e):D(e,void 0,t)}function Ce(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(e,t)}function ut(e,t={}){const n=(r,o)=>e(o).update(r).digest(),s=e(void 0);return n.outputLen=s.outputLen,n.blockLen=s.blockLen,n.create=r=>e(r),Object.assign(n,t),Object.freeze(n)}const Xt=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});class jt{constructor(t,n){f(this,"oHash");f(this,"iHash");f(this,"blockLen");f(this,"outputLen");f(this,"finished",!1);f(this,"destroyed",!1);if(Mt(t),D(n,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,r=new Uint8Array(s);r.set(n.length>s?t.create().update(n).digest():n);for(let o=0;o<r.length;o++)r[o]^=54;this.iHash.update(r),this.oHash=t.create();for(let o=0;o<r.length;o++)r[o]^=106;this.oHash.update(r),A(r)}update(t){return N(this),this.iHash.update(t),this}digestInto(t){N(this),D(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:s,finished:r,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=r,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const gt=(e,t,n)=>new jt(e,t).update(n).digest();gt.create=(e,t)=>new jt(e,t);function Re(e,t,n){return e&t^~e&n}function Ve(e,t,n){return e&t^e&n^t&n}class yt{constructor(t,n,s,r){f(this,"blockLen");f(this,"outputLen");f(this,"padOffset");f(this,"isLE");f(this,"buffer");f(this,"view");f(this,"finished",!1);f(this,"length",0);f(this,"pos",0);f(this,"destroyed",!1);this.blockLen=t,this.outputLen=n,this.padOffset=s,this.isLE=r,this.buffer=new Uint8Array(t),this.view=ot(this.buffer)}update(t){N(this),D(t);const{view:n,buffer:s,blockLen:r}=this,o=t.length;for(let i=0;i<o;){const a=Math.min(r-this.pos,o-i);if(a===r){const c=ot(t);for(;r<=o-i;i+=r)this.process(c,i);continue}s.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){N(this),Nt(t,this),this.finished=!0;const{buffer:n,view:s,blockLen:r,isLE:o}=this;let{pos:i}=this;n[i++]=128,A(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(s,0),i=0);for(let u=i;u<r;u++)n[u]=0;s.setBigUint64(r-8,BigInt(this.length*8),o),this.process(s,0);const a=ot(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],o)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const s=t.slice(0,n);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:s,length:r,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=r,t.pos=a,r%n&&t.buffer.set(s),t}clone(){return this._cloneInto()}}const $=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),I=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),De=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Gt=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),We=Gt.map(e=>(9*e+5)%16),qt=(()=>{const n=[[Gt],[We]];for(let s=0;s<4;s++)for(let r of n)r.push(r[s].map(o=>De[o]));return n})(),zt=qt[0],Zt=qt[1],Jt=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Ke=zt.map((e,t)=>e.map(n=>Jt[t][n])),Me=Zt.map((e,t)=>e.map(n=>Jt[t][n])),Ne=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Xe=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Ht(e,t,n,s){return e===0?t^n^s:e===1?t&n|~t&s:e===2?(t|~n)^s:e===3?t&s|n&~s:t^(n|~s)}const J=new Uint32Array(16);class je extends yt{constructor(){super(64,20,8,!0);f(this,"h0",1732584193);f(this,"h1",-271733879);f(this,"h2",-1732584194);f(this,"h3",271733878);f(this,"h4",-1009589776)}get(){const{h0:n,h1:s,h2:r,h3:o,h4:i}=this;return[n,s,r,o,i]}set(n,s,r,o,i){this.h0=n|0,this.h1=s|0,this.h2=r|0,this.h3=o|0,this.h4=i|0}process(n,s){for(let b=0;b<16;b++,s+=4)J[b]=n.getUint32(s,!0);let r=this.h0|0,o=r,i=this.h1|0,a=i,c=this.h2|0,l=c,h=this.h3|0,u=h,d=this.h4|0,p=d;for(let b=0;b<5;b++){const w=4-b,x=Ne[b],y=Xe[b],P=zt[b],g=Zt[b],T=Ke[b],H=Me[b];for(let v=0;v<16;v++){const S=Z(r+Ht(b,i,c,h)+J[P[v]]+x,T[v])+d|0;r=d,d=h,h=Z(c,10)|0,c=i,i=S}for(let v=0;v<16;v++){const S=Z(o+Ht(w,a,l,u)+J[g[v]]+y,H[v])+p|0;o=p,p=u,u=Z(l,10)|0,l=a,a=S}}this.set(this.h1+c+u|0,this.h2+h+p|0,this.h3+d+o|0,this.h4+r+a|0,this.h0+i+l|0)}roundClean(){A(J)}destroy(){this.destroyed=!0,A(this.buffer),this.set(0,0,0,0,0)}}const Ge=ut(()=>new je),Y=BigInt(2**32-1),kt=BigInt(32);function qe(e,t=!1){return t?{h:Number(e&Y),l:Number(e>>kt&Y)}:{h:Number(e>>kt&Y)|0,l:Number(e&Y)|0}}function Yt(e,t=!1){const n=e.length;let s=new Uint32Array(n),r=new Uint32Array(n);for(let o=0;o<n;o++){const{h:i,l:a}=qe(e[o],t);[s[o],r[o]]=[i,a]}return[s,r]}const It=(e,t,n)=>e>>>n,Et=(e,t,n)=>e<<32-n|t>>>n,K=(e,t,n)=>e>>>n|t<<32-n,M=(e,t,n)=>e<<32-n|t>>>n,Q=(e,t,n)=>e<<64-n|t>>>n-32,tt=(e,t,n)=>e>>>n-32|t<<64-n,ze=(e,t,n)=>e<<n|t>>>32-n,Ze=(e,t,n)=>t<<n|e>>>32-n,Je=(e,t,n)=>t<<n-32|e>>>64-n,Ye=(e,t,n)=>e<<n-32|t>>>64-n;function O(e,t,n,s){const r=(t>>>0)+(s>>>0);return{h:e+n+(r/2**32|0)|0,l:r|0}}const Qe=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),tn=(e,t,n,s)=>t+n+s+(e/2**32|0)|0,en=(e,t,n,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),nn=(e,t,n,s,r)=>t+n+s+r+(e/2**32|0)|0,sn=(e,t,n,s,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0)+(r>>>0),rn=(e,t,n,s,r,o)=>t+n+s+r+o+(e/2**32|0)|0,on=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_=new Uint32Array(64);class an extends yt{constructor(t){super(64,t,8,!1)}get(){const{A:t,B:n,C:s,D:r,E:o,F:i,G:a,H:c}=this;return[t,n,s,r,o,i,a,c]}set(t,n,s,r,o,i,a,c){this.A=t|0,this.B=n|0,this.C=s|0,this.D=r|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let u=0;u<16;u++,n+=4)_[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const d=_[u-15],p=_[u-2],b=U(d,7)^U(d,18)^d>>>3,w=U(p,17)^U(p,19)^p>>>10;_[u]=w+_[u-7]+b+_[u-16]|0}let{A:s,B:r,C:o,D:i,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const d=U(a,6)^U(a,11)^U(a,25),p=h+d+Re(a,c,l)+on[u]+_[u]|0,w=(U(s,2)^U(s,13)^U(s,22))+Ve(s,r,o)|0;h=l,l=c,c=a,a=i+p|0,i=o,o=r,r=s,s=p+w|0}s=s+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(s,r,o,i,a,c,l,h)}roundClean(){A(_)}destroy(){this.set(0,0,0,0,0,0,0,0),A(this.buffer)}}class cn extends an{constructor(){super(32);f(this,"A",$[0]|0);f(this,"B",$[1]|0);f(this,"C",$[2]|0);f(this,"D",$[3]|0);f(this,"E",$[4]|0);f(this,"F",$[5]|0);f(this,"G",$[6]|0);f(this,"H",$[7]|0)}}const Qt=Yt(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),un=Qt[0],ln=Qt[1],F=new Uint32Array(80),C=new Uint32Array(80);class hn extends yt{constructor(t){super(128,t,16,!1)}get(){const{Ah:t,Al:n,Bh:s,Bl:r,Ch:o,Cl:i,Dh:a,Dl:c,Eh:l,El:h,Fh:u,Fl:d,Gh:p,Gl:b,Hh:w,Hl:x}=this;return[t,n,s,r,o,i,a,c,l,h,u,d,p,b,w,x]}set(t,n,s,r,o,i,a,c,l,h,u,d,p,b,w,x){this.Ah=t|0,this.Al=n|0,this.Bh=s|0,this.Bl=r|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=h|0,this.Fh=u|0,this.Fl=d|0,this.Gh=p|0,this.Gl=b|0,this.Hh=w|0,this.Hl=x|0}process(t,n){for(let g=0;g<16;g++,n+=4)F[g]=t.getUint32(n),C[g]=t.getUint32(n+=4);for(let g=16;g<80;g++){const T=F[g-15]|0,H=C[g-15]|0,v=K(T,H,1)^K(T,H,8)^It(T,H,7),S=M(T,H,1)^M(T,H,8)^Et(T,H,7),E=F[g-2]|0,k=C[g-2]|0,q=K(E,k,19)^Q(E,k,61)^It(E,k,6),lt=M(E,k,19)^tt(E,k,61)^Et(E,k,6),z=en(S,lt,C[g-7],C[g-16]),ht=nn(z,v,q,F[g-7],F[g-16]);F[g]=ht|0,C[g]=z|0}let{Ah:s,Al:r,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:d,Fh:p,Fl:b,Gh:w,Gl:x,Hh:y,Hl:P}=this;for(let g=0;g<80;g++){const T=K(u,d,14)^K(u,d,18)^Q(u,d,41),H=M(u,d,14)^M(u,d,18)^tt(u,d,41),v=u&p^~u&w,S=d&b^~d&x,E=sn(P,H,S,ln[g],C[g]),k=rn(E,y,T,v,un[g],F[g]),q=E|0,lt=K(s,r,28)^Q(s,r,34)^Q(s,r,39),z=M(s,r,28)^tt(s,r,34)^tt(s,r,39),ht=s&o^s&a^o&a,ue=r&i^r&c^i&c;y=w|0,P=x|0,w=p|0,x=b|0,p=u|0,b=d|0,{h:u,l:d}=O(l|0,h|0,k|0,q|0),l=a|0,h=c|0,a=o|0,c=i|0,o=s|0,i=r|0;const wt=Qe(q,z,ue);s=tn(wt,k,lt,ht),r=wt|0}({h:s,l:r}=O(this.Ah|0,this.Al|0,s|0,r|0)),{h:o,l:i}=O(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=O(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=O(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:d}=O(this.Eh|0,this.El|0,u|0,d|0),{h:p,l:b}=O(this.Fh|0,this.Fl|0,p|0,b|0),{h:w,l:x}=O(this.Gh|0,this.Gl|0,w|0,x|0),{h:y,l:P}=O(this.Hh|0,this.Hl|0,y|0,P|0),this.set(s,r,o,i,a,c,l,h,u,d,p,b,w,x,y,P)}roundClean(){A(F,C)}destroy(){A(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class fn extends hn{constructor(){super(64);f(this,"Ah",I[0]|0);f(this,"Al",I[1]|0);f(this,"Bh",I[2]|0);f(this,"Bl",I[3]|0);f(this,"Ch",I[4]|0);f(this,"Cl",I[5]|0);f(this,"Dh",I[6]|0);f(this,"Dl",I[7]|0);f(this,"Eh",I[8]|0);f(this,"El",I[9]|0);f(this,"Fh",I[10]|0);f(this,"Fl",I[11]|0);f(this,"Gh",I[12]|0);f(this,"Gl",I[13]|0);f(this,"Hh",I[14]|0);f(this,"Hl",I[15]|0)}}const dn=ut(()=>new cn,Xt(1)),te=ut(()=>new fn,Xt(3)),pn=BigInt(0),X=BigInt(1),bn=BigInt(2),xn=BigInt(7),gn=BigInt(256),yn=BigInt(113),ee=[],ne=[],se=[];for(let e=0,t=X,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],ee.push(2*(5*s+n)),ne.push((e+1)*(e+2)/2%64);let r=pn;for(let o=0;o<7;o++)t=(t<<X^(t>>xn)*yn)%gn,t&bn&&(r^=X<<(X<<BigInt(o))-X);se.push(r)}const re=Yt(se,!0),mn=re[0],wn=re[1],St=(e,t,n)=>n>32?Je(e,t,n):ze(e,t,n),Bt=(e,t,n)=>n>32?Ye(e,t,n):Ze(e,t,n);function Pn(e,t=24){const n=new Uint32Array(10);for(let s=24-t;s<24;s++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const a=(i+8)%10,c=(i+2)%10,l=n[c],h=n[c+1],u=St(l,h,1)^n[a],d=Bt(l,h,1)^n[a+1];for(let p=0;p<50;p+=10)e[i+p]^=u,e[i+p+1]^=d}let r=e[2],o=e[3];for(let i=0;i<24;i++){const a=ne[i],c=St(r,o,a),l=Bt(r,o,a),h=ee[i];r=e[h],o=e[h+1],e[h]=c,e[h+1]=l}for(let i=0;i<50;i+=10){for(let a=0;a<10;a++)n[a]=e[i+a];for(let a=0;a<10;a++)e[i+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=mn[s],e[1]^=wn[s]}A(n)}class mt{constructor(t,n,s,r=!1,o=24){f(this,"state");f(this,"pos",0);f(this,"posOut",0);f(this,"finished",!1);f(this,"state32");f(this,"destroyed",!1);f(this,"blockLen");f(this,"suffix");f(this,"outputLen");f(this,"enableXOF",!1);f(this,"rounds");if(this.blockLen=t,this.suffix=n,this.outputLen=s,this.enableXOF=r,this.rounds=o,R(s,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Le(this.state)}clone(){return this._cloneInto()}keccak(){Tt(this.state32),Pn(this.state32,this.rounds),Tt(this.state32),this.posOut=0,this.pos=0}update(t){N(this),D(t);const{blockLen:n,state:s}=this,r=t.length;for(let o=0;o<r;){const i=Math.min(n-this.pos,r-o);for(let a=0;a<i;a++)s[this.pos++]^=t[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:s,blockLen:r}=this;t[s]^=n,(n&128)!==0&&s===r-1&&this.keccak(),t[r-1]^=128,this.keccak()}writeInto(t){N(this,!1),D(t),this.finish();const n=this.state,{blockLen:s}=this;for(let r=0,o=t.length;r<o;){this.posOut>=s&&this.keccak();const i=Math.min(s-this.posOut,o-r);t.set(n.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return R(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Nt(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,A(this.state)}_cloneInto(t){const{blockLen:n,suffix:s,outputLen:r,rounds:o,enableXOF:i}=this;return t||(t=new mt(n,s,r,i,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=s,t.outputLen=r,t.enableXOF=i,t.destroyed=this.destroyed,t}}const Tn=(e,t,n,s={})=>ut(()=>new mt(t,e,n),s),vn=Tn(1,136,32);function Hn(e,t,n,s){Mt(e);const r=Ce({dkLen:32,asyncTick:10},s),{c:o,dkLen:i,asyncTick:a}=r;if(R(o,"c"),R(i,"dkLen"),R(a,"asyncTick"),o<1)throw new Error("iterations (c) must be >= 1");const c=vt(t,"password"),l=vt(n,"salt"),h=new Uint8Array(i),u=gt.create(e,c),d=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:h,PRF:u,PRFSalt:d}}function kn(e,t,n,s,r){return e.destroy(),t.destroy(),s&&s.destroy(),A(r),n}function In(e,t,n,s){const{c:r,dkLen:o,DK:i,PRF:a,PRFSalt:c}=Hn(e,t,n,s);let l;const h=new Uint8Array(4),u=ot(h),d=new Uint8Array(a.outputLen);for(let p=1,b=0;b<o;p++,b+=a.outputLen){const w=i.subarray(b,b+a.outputLen);u.setInt32(0,p,!1),(l=c._cloneInto(l)).update(h).digestInto(d),w.set(d.subarray(0,w.length));for(let x=1;x<r;x++){a._cloneInto(l).update(d).digestInto(d);for(let y=0;y<w.length;y++)w[y]^=d[y]}}return kn(a,c,i,l,d)}function oe(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function En(e){const t=oe(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}const Sn=e=>oe("mnemonic"+e);function Bn(e,t=""){return In(te,En(e).nfkd,Sn(t),{c:2048,dkLen:64})}const An=508,At=16,et=32,nt=64,Ut=5,Un=4;function j(...e){const t=e.reduce((r,o)=>r+o.length,0),n=new Uint8Array(t);let s=0;for(const r of e)n.set(r,s),s+=r.length;return n}function ft(e){return new TextEncoder().encode(e)}function dt(e){const t=new Uint8Array(Un);return new DataView(t.buffer).setUint32(0,e.length,!1),j(t,e)}function pt(e,t){return gt(te,e,t)}function Lt(e){return Ge(dn(e))}const xt=e=>Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("");function ie(e){const t=Bn(e);return new Uint8Array(t)}async function ae(e,t,n,s){if(e.length!==nt)throw new Error(`Lamport seed must be ${nt} bytes, got ${e.length}`);t=m.stripHexPrefix(t),n=m.stripHexPrefix(n);const r=e.slice(et,nt),o=e.slice(0,et),i=[r,o];try{const a=j(dt(ft(t)),dt(ft(n)),dt(ft(s))),c=j(o,a);i.push(c);const l=pt(r,c);i.push(l);const h=l.slice(0,et),u=l.slice(et,nt);i.push(h,u);const d=[],p=[],b=[],w=[];let x=!1;try{for(let y=0;y<An;y++){const P=new Uint8Array(Ut);P[0]=0,new DataView(P.buffer).setUint32(1,y,!1);const g=new Uint8Array(Ut);g[0]=1,new DataView(g.buffer).setUint32(1,y,!1);const T=j(h,P),H=j(h,g),v=pt(u,T),S=pt(u,H);try{const E=v.slice(0,At),k=S.slice(0,At);d.push(E),p.push(k),b.push(Lt(E)),w.push(Lt(k))}finally{T.fill(0),H.fill(0),v.fill(0),S.fill(0)}}return x=!0,{falsePreimages:d,truePreimages:p,falseHashes:b,trueHashes:w}}finally{if(!x){for(const y of d)y.fill(0);for(const y of p)y.fill(0)}}}finally{for(const a of i)a.fill(0)}}function Ln(e){return{false_list:e.falseHashes.map(xt),true_list:e.trueHashes.map(xt)}}function ce(e){if(e.falseHashes.length===0||e.trueHashes.length===0)throw new Error("computeLamportPkHash: keypair hash arrays must not be empty");const t=e.falseHashes[0].length,n=(e.falseHashes.length+e.trueHashes.length)*t,s=new Uint8Array(n);let r=0;for(const i of e.falseHashes)s.set(i,r),r+=t;for(const i of e.trueHashes)s.set(i,r),r+=t;const o=vn(s);return`0x${xt(o)}`}async function On(e,t,n,s){const r=ie(e);try{const o=await ae(r,t,n,s);try{return ce(o)}finally{for(const i of o.falsePreimages)i.fill(0);for(const i of o.truePreimages)i.fill(0)}}finally{r.fill(0)}}function $n(e){const t=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return t.includes("lamport")&&t.includes("hash")&&t.includes("does not match")}exports.BTCVaultRegistryABI=st;exports.BitcoinScriptType=G;exports.CONTRACT_ERRORS=V;exports.MEMPOOL_API_URLS=Vt;exports.PayoutManager=Ae;exports.PeginManager=Be;exports.calculateBtcTxHash=bt;exports.computeLamportPkHash=ce;exports.createSplitTransaction=xe;exports.createSplitTransactionPsbt=ge;exports.createTaprootScriptPathSignOptions=it;exports.deriveLamportKeypair=ae;exports.deriveLamportPkHash=On;exports.extractErrorData=ct;exports.getAddressTxs=ve;exports.getAddressUtxos=Pe;exports.getContractErrorMessage=ke;exports.getDustThreshold=be;exports.getMempoolApiUrl=Te;exports.getNetworkFees=He;exports.getPsbtInputFields=_t;exports.getScriptType=$t;exports.getTxHex=we;exports.getTxInfo=Wt;exports.getUtxoInfo=Kt;exports.handleContractError=rt;exports.isKnownContractError=Ie;exports.isLamportMismatchError=$n;exports.keypairToPublicKey=Ln;exports.mnemonicToLamportSeed=ie;exports.pushTx=Dt;exports.selectUtxosForPegin=Ot;exports.shouldAddChangeOutput=pe;
|
|
2
|
+
//# sourceMappingURL=errors-CIDTtluC.cjs.map
|