@babylonlabs-io/ts-sdk 0.15.2 → 0.15.3
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/{challengeAssert-CenzzhZU.js → challengeAssert-C5DQSUnp.js} +249 -265
- package/dist/challengeAssert-C5DQSUnp.js.map +1 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs +2 -0
- package/dist/challengeAssert-D7SqsNpQ.cjs.map +1 -0
- package/dist/errors-BZc3Urez.cjs +2 -0
- package/dist/errors-BZc3Urez.cjs.map +1 -0
- package/dist/{errors-C5aW6wrA.js → errors-UqmtfBtv.js} +189 -188
- package/dist/errors-UqmtfBtv.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +2 -2
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts +2 -13
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/scripts/payout.d.ts +7 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +17 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +2 -2
- package/package.json +3 -3
- package/dist/challengeAssert-BpzES0KW.cjs +0 -2
- package/dist/challengeAssert-BpzES0KW.cjs.map +0 -1
- package/dist/challengeAssert-CenzzhZU.js.map +0 -1
- package/dist/errors-C5aW6wrA.js.map +0 -1
- package/dist/errors-DD3lnhb0.cjs +0 -2
- package/dist/errors-DD3lnhb0.cjs.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var he=Object.defineProperty;var fe=(e,t,n)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var p=(e,t,n)=>fe(e,typeof t!="symbol"?t+"":t,n);const A=require("bitcoinjs-lib"),B=require("buffer"),y=require("./challengeAssert-D7SqsNpQ.cjs"),$=require("viem"),Pt=require("@babylonlabs-io/babylon-tbv-rust-wasm");function de(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 pe=de(A);function Ct(e,t,n,s){if(!Number.isInteger(s)||s<1)throw new Error(`Invalid numOutputs: expected a positive integer, got ${s}`);if(e.length===0)throw new Error("Insufficient funds: no UTXOs available");const r=e.filter(l=>{const h=B.Buffer.from(l.scriptPubKey,"hex");return!!A.script.decompile(h)});if(r.length===0)throw new Error("Insufficient funds: no valid UTXOs available (all have invalid scripts)");const o=[...r].sort((l,h)=>h.value-l.value),i=[];let a=0n,c=0n;for(const l of o){i.push(l),a+=BigInt(l.value);const h=i.length*y.P2TR_INPUT_SIZE,u=s*y.MAX_NON_LEGACY_OUTPUT_SIZE,f=h+u+y.TX_BUFFER_SIZE_OVERHEAD;if(c=BigInt(Math.ceil(f*n))+BigInt(y.rateBasedTxBufferFee(n)),a-t-c>y.DUST_THRESHOLD){const g=BigInt(Math.ceil(y.MAX_NON_LEGACY_OUTPUT_SIZE*n));c+=g}if(a>=t+c){const g=a-t-c;return{selectedUTXOs:i,totalValue:a,fee:c,changeAmount:g}}}throw new Error(`Insufficient funds: need ${t+c} sats (${t} pegin + ${c} fee), have ${a} sats`)}function ge(e){return e>y.DUST_THRESHOLD}function be(){return y.BTC_DUST_SAT}function it(e){const t=e.startsWith("0x")?e.slice(2):e;return`0x${A.Transaction.fromHex(t).getId()}`}function ye(e,t,n){if(y.ensureEcc(),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=y.getNetwork(n),r=new A.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=A.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 xe(e,t,n){const s=A.Transaction.fromHex(e),r=new A.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 f={script:B.Buffer.from(a.scriptPubKey,"hex"),value:a.value};r.addInput({hash:i.hash,index:i.index,sequence:i.sequence,witnessUtxo:f,tapInternalKey:n})}for(const o of s.outs)r.addOutput({script:o.script,value:o.value});return r.toHex()}var Y=(e=>(e.P2PKH="P2PKH",e.P2SH="P2SH",e.P2WPKH="P2WPKH",e.P2WSH="P2WSH",e.P2TR="P2TR",e.UNKNOWN="UNKNOWN",e))(Y||{});function Ft(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=Ft(n);switch(s){case Y.P2WPKH:return{witnessUtxo:{script:n,value:e.value}};case Y.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 Y.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 ct(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 we=21e6*1e8,Lt=1e4;function Rt(e){return Number.isInteger(e)&&e>0&&e<=we}function me(e){return Number.isInteger(e)&&e>0&&e<=Lt}function Wt(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 ut(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 Kt(e,t){return ut(`${t}/tx/${e}`)}async function Pe(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 Mt(e,t,n){const s=await Kt(e,n);if(!Wt(t,s.vout.length))throw new Error(`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`);const r=s.vout[t];if(!Rt(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 Te(e,t){try{const n=await ut(`${t}/address/${e}/utxo`),s=await ut(`${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(!Wt(o.vout))throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);if(!Rt(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 ve(e){return Vt[e]}async function He(e,t){return ut(`${t}/address/${e}/txs`)}async function ke(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 ≤ ${Lt}`);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 G=[{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:"depositorWotsPkHash",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:"depositorWotsPkHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"payable"},{type:"function",name:"submitPeginRequestBatch",inputs:[{name:"depositor",type:"address",internalType:"address"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"requests",type:"tuple[]",internalType:"struct IBTCVaultRegistry.BatchPeginRequest[]",components:[{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:"hashlock",type:"bytes32",internalType:"bytes32"},{name:"htlcVout",type:"uint8",internalType:"uint8"},{name:"referralCode",type:"uint32",internalType:"uint32"},{name:"depositorPayoutBtcAddress",type:"bytes",internalType:"bytes"},{name:"depositorWotsPkHash",type:"bytes32",internalType:"bytes32"}]}],outputs:[{name:"vaultIds",type:"bytes32[]",internalType:"bytes32[]"}],stateMutability:"payable"},{type:"function",name:"activateVaultWithSecret",inputs:[{name:"vaultId",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"},{name:"activationMetadata",type:"bytes",internalType:"bytes"}],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:"createdAt",type:"uint256",internalType:"uint256"},{name:"verifiedAt",type:"uint256",internalType:"uint256"},{name:"depositorWotsPkHash",type:"bytes32",internalType:"bytes32"},{name:"hashlock",type:"bytes32",internalType:"bytes32"},{name:"htlcVout",type:"uint8",internalType:"uint8"},{name:"depositorPopSignature",type:"bytes",internalType:"bytes"},{name:"prePeginTxHash",type:"bytes32",internalType:"bytes32"}]}],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:[]}],M={"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 lt(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 Ee(e){const t=lt(e);if(t){const n=t.substring(0,10);return M[t]??M[n]}}function Ie(e){const t=lt(e);if(t===void 0)return!1;const n=t.substring(0,10);return t in M||n in M}function D(e){console.error("[Contract Error] Raw error:",e);const t=lt(e);if(console.error("[Contract Error] Extracted error data:",t),t){const s=t.substring(0,10),r=M[t]??M[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)}`)}const Se=0;function Be(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}):Mt(e,t,s)}const Tt=12e4;class Ae{constructor(t){p(this,"config");this.config=t}async preparePegin(t){const n=await this.config.btcWallet.getPublicKeyHex(),s=n.length===66?n.slice(2):n,r=y.stripHexPrefix(t.vaultProviderBtcPubkey),o=t.vaultKeeperBtcPubkeys.map(y.stripHexPrefix),i=t.universalChallengerBtcPubkeys.map(y.stripHexPrefix);if(t.hashlocks.length!==t.amounts.length)throw new Error(`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`);if(t.hashlocks.length===0)throw new Error("hashlocks must contain at least one entry");const a=o.length,c={depositorPubkey:s,vaultProviderPubkey:r,vaultKeeperPubkeys:o,universalChallengerPubkeys:i,hashlocks:t.hashlocks,timelockRefund:t.timelockRefund,pegInAmounts:t.amounts,feeRate:t.protocolFeeRate,numLocalChallengers:a,councilQuorum:t.councilQuorum,councilSize:t.councilSize,network:this.config.btcNetwork},l=await y.buildPrePeginPsbt(c),h=Ct([...t.availableUTXOs],l.totalOutputValue,t.mempoolFeeRate,y.peginOutputCount(l.htlcValues.length)),u=y.getNetwork(this.config.btcNetwork),f=y.fundPeginTransaction({unfundedTxHex:l.psbtHex,selectedUTXOs:h.selectedUTXOs,changeAddress:t.changeAddress,changeAmount:h.changeAmount,network:u}),x=y.stripHexPrefix(it(f)),g=[],w=[],T=[];for(let d=0;d<t.hashlocks.length;d++){const m=await y.buildPeginTxFromFundedPrePegin({prePeginParams:c,timelockPegin:t.timelockPegin,fundedPrePeginTxHex:f,htlcVout:d}),H=await y.buildPeginInputPsbt({peginTxHex:m.txHex,fundedPrePeginTxHex:f,depositorPubkey:s,vaultProviderPubkey:r,vaultKeeperPubkeys:o,universalChallengerPubkeys:i,hashlock:t.hashlocks[d],timelockRefund:t.timelockRefund,network:this.config.btcNetwork});g.push(m),w.push(H.psbtHex),T.push(ct(n,1))}const P=await this.signPsbtsWithFallback(w,T),b=[];for(let d=0;d<P.length;d++){const m=y.extractPeginInputSignature(P[d],s),H=y.finalizePeginInputPsbt(P[d]);b.push({htlcVout:d,htlcValue:l.htlcValues[d],peginTxHex:H,peginTxid:g[d].txid,peginInputSignature:m,vaultScriptPubKey:g[d].vaultScriptPubKey})}return{fundedPrePeginTxHex:f,prePeginTxid:x,unsignedPrePeginTxHex:l.psbtHex,perVault:b,selectedUTXOs:h.selectedUTXOs,fee:h.fee,changeAmount:h.changeAmount}}async signPsbtsWithFallback(t,n){if(typeof this.config.btcWallet.signPsbts=="function"){const r=await this.config.btcWallet.signPsbts(t,n);if(r.length!==t.length)throw new Error(`Expected ${t.length} signed PSBTs but received ${r.length}`);return r}const s=[];for(let r=0;r<t.length;r++){const o=await this.config.btcWallet.signPsbt(t[r],n[r]);s.push(o)}return s}async signAndBroadcast(t){const{fundedPrePeginTxHex:n,depositorBtcPubkey:s}=t,r=n.startsWith("0x")?n.slice(2):n,o=A.Transaction.fromHex(r);if(o.ins.length===0)throw new Error("Transaction has no inputs");const i=new A.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(b=>{const d=B.Buffer.from(b.hash).reverse().toString("hex"),m=b.index;return Be(d,m,t.localPrevouts,l).then(H=>({input:b,utxoData:H,txid:d,vout:m}))}),u=await Promise.all(h),f=u.reduce((b,d)=>b+BigInt(d.utxoData.value),0n),x=o.outs.reduce((b,d)=>b+BigInt(d.value),0n);if(f<x)throw new Error(`UTXO value mismatch: total input value (${f} sat) is less than total output value (${x} sat). This may indicate the mempool API returned manipulated UTXO data.`);for(const{input:b,utxoData:d,txid:m,vout:H}of u){const v=_t({value:d.value,scriptPubKey:d.scriptPubKey},c);i.addInput({hash:b.hash,index:b.index,sequence:b.sequence,...v})}for(const b of o.outs)i.addOutput({script:b.script,value:b.value});const g=await this.config.btcWallet.signPsbt(i.toHex()),w=A.Psbt.fromHex(g);try{w.finalizeAllInputs()}catch(b){if(!w.data.inputs.every(m=>m.finalScriptWitness||m.finalScriptSig))throw new Error(`PSBT finalization failed and wallet did not auto-finalize: ${b}`)}const T=w.extractTransaction().toHex();return await Dt(T,l)}async registerPeginOnChain(t){const{depositorBtcPubkey:n,unsignedPrePeginTx:s,depositorSignedPeginTx:r,vaultProvider:o,hashlock:i,htlcVout:a,onPopSigned:c,depositorPayoutBtcAddress:l,depositorWotsPkHash:h,preSignedBtcPopSignature:u}=t;if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const f=this.config.ethWallet.account.address,x=await this.resolvePopSignature(f,u);c&&await c();const g=y.ensureHexPrefix(n),w=y.ensureHexPrefix(s),T=y.ensureHexPrefix(r),P=await this.resolvePayoutScriptPubKey(l),b=it(T),d=await Pt.deriveVaultId(y.stripHexPrefix(b),y.stripHexPrefix(f)),m=y.ensureHexPrefix(d);if(await this.checkVaultExists(m))throw new Error(`Vault already exists (ID: ${m}, peginTxHash: ${b}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`);const v=$.createPublicClient({chain:this.config.ethChain,transport:$.http()});let E;try{E=await v.readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:G,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 I=$.encodeFunctionData({abi:G,functionName:"submitPeginRequest",args:[f,g,x,w,T,o,i,a,P,h]});let S;try{S=await v.estimateGas({to:this.config.vaultContracts.btcVaultRegistry,data:I,value:E,account:this.config.ethWallet.account.address})}catch(_){D(_)}let F;try{F=await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultRegistry,data:I,value:E,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:S})}catch(_){D(_)}const X=await v.waitForTransactionReceipt({hash:F,timeout:Tt});return X.status==="reverted"&&D(new Error(`Transaction reverted. Hash: ${F}. Check the transaction on block explorer for details.`)),{ethTxHash:X.transactionHash,vaultId:m,peginTxHash:b,btcPopSignature:x}}async registerPeginBatchOnChain(t){const{vaultProvider:n,requests:s,preSignedBtcPopSignature:r,onPopSigned:o}=t;if(s.length===0)throw new Error("Batch pegin requires at least one request");if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const i=this.config.ethWallet.account.address,a=await this.resolvePopSignature(i,r);o&&await o();const c=[];for(const b of s)c.push(await this.resolvePayoutScriptPubKey(b.depositorPayoutBtcAddress));const l=[];for(const b of s){const d=y.ensureHexPrefix(b.depositorSignedPeginTx),m=it(d),H=await Pt.deriveVaultId(y.stripHexPrefix(m),y.stripHexPrefix(i)),v=y.ensureHexPrefix(H);if(await this.checkVaultExists(v))throw new Error(`Vault already exists (ID: ${v}, peginTxHash: ${m}). To create a new vault, use different UTXOs or a different amount.`);l.push({vaultId:v,peginTxHash:m})}const h=$.createPublicClient({chain:this.config.ethChain,transport:$.http()});let u;try{u=await h.readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:G,functionName:"getPegInFee",args:[n]})}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 f=u*BigInt(s.length),x=s.map((b,d)=>({depositorBtcPubKey:y.ensureHexPrefix(b.depositorBtcPubkey),btcPopSignature:a,unsignedPrePeginTx:y.ensureHexPrefix(b.unsignedPrePeginTx),depositorSignedPeginTx:y.ensureHexPrefix(b.depositorSignedPeginTx),hashlock:b.hashlock,htlcVout:b.htlcVout,referralCode:Se,depositorPayoutBtcAddress:c[d],depositorWotsPkHash:b.depositorWotsPkHash})),g=$.encodeFunctionData({abi:G,functionName:"submitPeginRequestBatch",args:[i,n,x]});let w;try{w=await h.estimateGas({to:this.config.vaultContracts.btcVaultRegistry,data:g,value:f,account:this.config.ethWallet.account.address})}catch(b){D(b)}let T;try{T=await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultRegistry,data:g,value:f,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:w})}catch(b){D(b)}const P=await h.waitForTransactionReceipt({hash:T,timeout:Tt});return P.status==="reverted"&&D(new Error(`Batch transaction reverted. Hash: ${T}. Check the transaction on block explorer for details.`)),{ethTxHash:P.transactionHash,vaults:l,btcPopSignature:a}}async checkVaultExists(t){try{return(await $.createPublicClient({chain:this.config.ethChain,transport:$.http()}).readContract({address:this.config.vaultContracts.btcVaultRegistry,abi:G,functionName:"getBTCVault",args:[t]})).depositor!==$.zeroAddress}catch{return!1}}async resolvePayoutScriptPubKey(t){y.ensureEcc();let n;if(t)n=t;else{n=await this.config.btcWallet.getAddress();const r=await this.config.btcWallet.getPublicKeyHex();if(!y.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=y.getNetwork(this.config.btcNetwork);try{return`0x${pe.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 Ue{constructor(t){p(this,"config");this.config=t}async signPayoutTransaction(t){this.validatePayoutOutputs(t.payoutTxHex,t.registeredPayoutScriptPubKey);const n=await this.config.btcWallet.getPublicKeyHex(),{depositorPubkey:s}=y.validateWalletPubkey(n,t.depositorBtcPubkey),r=await y.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,ct(n,1));return{signature:y.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){this.validatePayoutOutputs(c.payoutTxHex,c.registeredPayoutScriptPubKey);const{depositorPubkey:l}=y.validateWalletPubkey(n,c.depositorBtcPubkey);o.push(l);const h=await y.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(ct(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=y.extractPayoutSignature(i[c],l);a.push({payoutSignature:h,depositorBtcPubkey:l})}return a}validatePayoutOutputs(t,n){if(!y.isValidHex(n))throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");const s=B.Buffer.from(y.stripHexPrefix(n),"hex"),r=A.Transaction.fromHex(y.stripHexPrefix(t));if(r.outs.length===0)throw new Error("Payout transaction has no outputs");if(!r.outs.reduce((i,a)=>a.value>i.value?a:i).script.equals(s))throw new Error("Payout transaction does not pay to the registered depositor payout address")}}function Oe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function K(e,t=""){if(!Number.isSafeInteger(e)||e<0){const n=t&&`"${t}" `;throw new Error(`${n}expected integer >= 0, got ${e}`)}}function N(e,t,n=""){const s=Oe(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 Nt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");K(e.outputLen),K(e.blockLen)}function z(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 Xt(e,t){N(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 $e(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function U(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function at(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function O(e,t){return e<<32-t|e>>>t}function Q(e,t){return e<<t|e>>>32-t>>>0}const Ce=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Fe(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]=Fe(e[t]);return e}const vt=Ce?e=>e:_e;function Le(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ht(e,t=""){return typeof e=="string"?Le(e):N(e,void 0,t)}function Re(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 ht(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 qt=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});class jt{constructor(t,n){p(this,"oHash");p(this,"iHash");p(this,"blockLen");p(this,"outputLen");p(this,"finished",!1);p(this,"destroyed",!1);if(Nt(t),N(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),U(r)}update(t){return z(this),this.iHash.update(t),this}digestInto(t){z(this),N(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 yt=(e,t,n)=>new jt(e,t).update(n).digest();yt.create=(e,t)=>new jt(e,t);function We(e,t,n){return e&t^~e&n}function Ve(e,t,n){return e&t^e&n^t&n}class xt{constructor(t,n,s,r){p(this,"blockLen");p(this,"outputLen");p(this,"padOffset");p(this,"isLE");p(this,"buffer");p(this,"view");p(this,"finished",!1);p(this,"length",0);p(this,"pos",0);p(this,"destroyed",!1);this.blockLen=t,this.outputLen=n,this.padOffset=s,this.isLE=r,this.buffer=new Uint8Array(t),this.view=at(this.buffer)}update(t){z(this),N(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=at(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){z(this),Xt(t,this),this.finished=!0;const{buffer:n,view:s,blockLen:r,isLE:o}=this;let{pos:i}=this;n[i++]=128,U(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=at(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 L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),k=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)),Ke=Gt.map(e=>(9*e+5)%16),zt=(()=>{const n=[[Gt],[Ke]];for(let s=0;s<4;s++)for(let r of n)r.push(r[s].map(o=>De[o]));return n})(),Zt=zt[0],Jt=zt[1],Yt=[[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)),Me=Zt.map((e,t)=>e.map(n=>Yt[t][n])),Ne=Jt.map((e,t)=>e.map(n=>Yt[t][n])),Xe=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),qe=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function kt(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 tt=new Uint32Array(16);class je extends xt{constructor(){super(64,20,8,!0);p(this,"h0",1732584193);p(this,"h1",-271733879);p(this,"h2",-1732584194);p(this,"h3",271733878);p(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 g=0;g<16;g++,s+=4)tt[g]=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,f=this.h4|0,x=f;for(let g=0;g<5;g++){const w=4-g,T=Xe[g],P=qe[g],b=Zt[g],d=Jt[g],m=Me[g],H=Ne[g];for(let v=0;v<16;v++){const E=Q(r+kt(g,i,c,h)+tt[b[v]]+T,m[v])+f|0;r=f,f=h,h=Q(c,10)|0,c=i,i=E}for(let v=0;v<16;v++){const E=Q(o+kt(w,a,l,u)+tt[d[v]]+P,H[v])+x|0;o=x,x=u,u=Q(l,10)|0,l=a,a=E}}this.set(this.h1+c+u|0,this.h2+h+x|0,this.h3+f+o|0,this.h4+r+a|0,this.h0+i+l|0)}roundClean(){U(tt)}destroy(){this.destroyed=!0,U(this.buffer),this.set(0,0,0,0,0)}}const Ge=ht(()=>new je),et=BigInt(2**32-1),Et=BigInt(32);function ze(e,t=!1){return t?{h:Number(e&et),l:Number(e>>Et&et)}:{h:Number(e>>Et&et)|0,l:Number(e&et)|0}}function Qt(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}=ze(e[o],t);[s[o],r[o]]=[i,a]}return[s,r]}const It=(e,t,n)=>e>>>n,St=(e,t,n)=>e<<32-n|t>>>n,q=(e,t,n)=>e>>>n|t<<32-n,j=(e,t,n)=>e<<32-n|t>>>n,nt=(e,t,n)=>e<<64-n|t>>>n-32,st=(e,t,n)=>e>>>n-32|t<<64-n,Ze=(e,t,n)=>e<<n|t>>>32-n,Je=(e,t,n)=>t<<n|e>>>32-n,Ye=(e,t,n)=>t<<n-32|e>>>64-n,Qe=(e,t,n)=>e<<n-32|t>>>64-n;function C(e,t,n,s){const r=(t>>>0)+(s>>>0);return{h:e+n+(r/2**32|0)|0,l:r|0}}const tn=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),en=(e,t,n,s)=>t+n+s+(e/2**32|0)|0,nn=(e,t,n,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),sn=(e,t,n,s,r)=>t+n+s+r+(e/2**32|0)|0,rn=(e,t,n,s,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0)+(r>>>0),on=(e,t,n,s,r,o)=>t+n+s+r+o+(e/2**32|0)|0,an=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]),R=new Uint32Array(64);class cn extends xt{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)R[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const f=R[u-15],x=R[u-2],g=O(f,7)^O(f,18)^f>>>3,w=O(x,17)^O(x,19)^x>>>10;R[u]=w+R[u-7]+g+R[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 f=O(a,6)^O(a,11)^O(a,25),x=h+f+We(a,c,l)+an[u]+R[u]|0,w=(O(s,2)^O(s,13)^O(s,22))+Ve(s,r,o)|0;h=l,l=c,c=a,a=i+x|0,i=o,o=r,r=s,s=x+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(){U(R)}destroy(){this.set(0,0,0,0,0,0,0,0),U(this.buffer)}}class un extends cn{constructor(){super(32);p(this,"A",L[0]|0);p(this,"B",L[1]|0);p(this,"C",L[2]|0);p(this,"D",L[3]|0);p(this,"E",L[4]|0);p(this,"F",L[5]|0);p(this,"G",L[6]|0);p(this,"H",L[7]|0)}}const te=Qt(["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))),ln=te[0],hn=te[1],W=new Uint32Array(80),V=new Uint32Array(80);class fn extends xt{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:f,Gh:x,Gl:g,Hh:w,Hl:T}=this;return[t,n,s,r,o,i,a,c,l,h,u,f,x,g,w,T]}set(t,n,s,r,o,i,a,c,l,h,u,f,x,g,w,T){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=f|0,this.Gh=x|0,this.Gl=g|0,this.Hh=w|0,this.Hl=T|0}process(t,n){for(let d=0;d<16;d++,n+=4)W[d]=t.getUint32(n),V[d]=t.getUint32(n+=4);for(let d=16;d<80;d++){const m=W[d-15]|0,H=V[d-15]|0,v=q(m,H,1)^q(m,H,8)^It(m,H,7),E=j(m,H,1)^j(m,H,8)^St(m,H,7),I=W[d-2]|0,S=V[d-2]|0,F=q(I,S,19)^nt(I,S,61)^It(I,S,6),X=j(I,S,19)^st(I,S,61)^St(I,S,6),_=nn(E,X,V[d-7],V[d-16]),ft=sn(_,v,F,W[d-7],W[d-16]);W[d]=ft|0,V[d]=_|0}let{Ah:s,Al:r,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:f,Fh:x,Fl:g,Gh:w,Gl:T,Hh:P,Hl:b}=this;for(let d=0;d<80;d++){const m=q(u,f,14)^q(u,f,18)^nt(u,f,41),H=j(u,f,14)^j(u,f,18)^st(u,f,41),v=u&x^~u&w,E=f&g^~f&T,I=rn(b,H,E,hn[d],V[d]),S=on(I,P,m,v,ln[d],W[d]),F=I|0,X=q(s,r,28)^nt(s,r,34)^nt(s,r,39),_=j(s,r,28)^st(s,r,34)^st(s,r,39),ft=s&o^s&a^o&a,le=r&i^r&c^i&c;P=w|0,b=T|0,w=x|0,T=g|0,x=u|0,g=f|0,{h:u,l:f}=C(l|0,h|0,S|0,F|0),l=a|0,h=c|0,a=o|0,c=i|0,o=s|0,i=r|0;const mt=tn(F,_,le);s=en(mt,S,X,ft),r=mt|0}({h:s,l:r}=C(this.Ah|0,this.Al|0,s|0,r|0)),{h:o,l:i}=C(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=C(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=C(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:f}=C(this.Eh|0,this.El|0,u|0,f|0),{h:x,l:g}=C(this.Fh|0,this.Fl|0,x|0,g|0),{h:w,l:T}=C(this.Gh|0,this.Gl|0,w|0,T|0),{h:P,l:b}=C(this.Hh|0,this.Hl|0,P|0,b|0),this.set(s,r,o,i,a,c,l,h,u,f,x,g,w,T,P,b)}roundClean(){U(W,V)}destroy(){U(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class dn extends fn{constructor(){super(64);p(this,"Ah",k[0]|0);p(this,"Al",k[1]|0);p(this,"Bh",k[2]|0);p(this,"Bl",k[3]|0);p(this,"Ch",k[4]|0);p(this,"Cl",k[5]|0);p(this,"Dh",k[6]|0);p(this,"Dl",k[7]|0);p(this,"Eh",k[8]|0);p(this,"El",k[9]|0);p(this,"Fh",k[10]|0);p(this,"Fl",k[11]|0);p(this,"Gh",k[12]|0);p(this,"Gl",k[13]|0);p(this,"Hh",k[14]|0);p(this,"Hl",k[15]|0)}}const pn=ht(()=>new un,qt(1)),ee=ht(()=>new dn,qt(3)),gn=BigInt(0),Z=BigInt(1),bn=BigInt(2),yn=BigInt(7),xn=BigInt(256),wn=BigInt(113),ne=[],se=[],re=[];for(let e=0,t=Z,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],ne.push(2*(5*s+n)),se.push((e+1)*(e+2)/2%64);let r=gn;for(let o=0;o<7;o++)t=(t<<Z^(t>>yn)*wn)%xn,t&bn&&(r^=Z<<(Z<<BigInt(o))-Z);re.push(r)}const oe=Qt(re,!0),mn=oe[0],Pn=oe[1],Bt=(e,t,n)=>n>32?Ye(e,t,n):Ze(e,t,n),At=(e,t,n)=>n>32?Qe(e,t,n):Je(e,t,n);function Tn(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=Bt(l,h,1)^n[a],f=At(l,h,1)^n[a+1];for(let x=0;x<50;x+=10)e[i+x]^=u,e[i+x+1]^=f}let r=e[2],o=e[3];for(let i=0;i<24;i++){const a=se[i],c=Bt(r,o,a),l=At(r,o,a),h=ne[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]^=Pn[s]}U(n)}class wt{constructor(t,n,s,r=!1,o=24){p(this,"state");p(this,"pos",0);p(this,"posOut",0);p(this,"finished",!1);p(this,"state32");p(this,"destroyed",!1);p(this,"blockLen");p(this,"suffix");p(this,"outputLen");p(this,"enableXOF",!1);p(this,"rounds");if(this.blockLen=t,this.suffix=n,this.outputLen=s,this.enableXOF=r,this.rounds=o,K(s,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=$e(this.state)}clone(){return this._cloneInto()}keccak(){vt(this.state32),Tn(this.state32,this.rounds),vt(this.state32),this.posOut=0,this.pos=0}update(t){z(this),N(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){z(this,!1),N(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 K(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Xt(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,U(this.state)}_cloneInto(t){const{blockLen:n,suffix:s,outputLen:r,rounds:o,enableXOF:i}=this;return t||(t=new wt(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 vn=(e,t,n,s={})=>ht(()=>new wt(t,e,n),s),Hn=vn(1,136,32);function kn(e,t,n,s){Nt(e);const r=Re({dkLen:32,asyncTick:10},s),{c:o,dkLen:i,asyncTick:a}=r;if(K(o,"c"),K(i,"dkLen"),K(a,"asyncTick"),o<1)throw new Error("iterations (c) must be >= 1");const c=Ht(t,"password"),l=Ht(n,"salt"),h=new Uint8Array(i),u=yt.create(e,c),f=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:h,PRF:u,PRFSalt:f}}function En(e,t,n,s,r){return e.destroy(),t.destroy(),s&&s.destroy(),U(r),n}function In(e,t,n,s){const{c:r,dkLen:o,DK:i,PRF:a,PRFSalt:c}=kn(e,t,n,s);let l;const h=new Uint8Array(4),u=at(h),f=new Uint8Array(a.outputLen);for(let x=1,g=0;g<o;x++,g+=a.outputLen){const w=i.subarray(g,g+a.outputLen);u.setInt32(0,x,!1),(l=c._cloneInto(l)).update(h).digestInto(f),w.set(f.subarray(0,w.length));for(let T=1;T<r;T++){a._cloneInto(l).update(f).digestInto(f);for(let P=0;P<w.length;P++)w[P]^=f[P]}}return En(a,c,i,l,f)}function ie(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function Sn(e){const t=ie(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}const Bn=e=>ie("mnemonic"+e);function An(e,t=""){return In(ee,Sn(e).nfkd,Bn(t),{c:2048,dkLen:64})}const Un=508,Ut=16,rt=32,ot=64,Ot=5,On=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 dt(e){return new TextEncoder().encode(e)}function pt(e){const t=new Uint8Array(On);return new DataView(t.buffer).setUint32(0,e.length,!1),J(t,e)}function gt(e,t){return yt(ee,e,t)}function $t(e){return Ge(pn(e))}const bt=e=>Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("");function ae(e){const t=An(e),n=new Uint8Array(t);return t.fill(0),n}async function ce(e,t,n,s){if(e.length!==ot)throw new Error(`WOTS seed must be ${ot} bytes, got ${e.length}`);t=y.stripHexPrefix(t),n=y.stripHexPrefix(n);const r=e.slice(rt,ot),o=e.slice(0,rt),i=[r,o];try{const a=J(pt(dt(t)),pt(dt(n)),pt(dt(s))),c=J(o,a);i.push(c);const l=gt(r,c);i.push(l);const h=l.slice(0,rt),u=l.slice(rt,ot);i.push(h,u);const f=[],x=[],g=[],w=[];let T=!1;try{for(let P=0;P<Un;P++){const b=new Uint8Array(Ot);b[0]=0,new DataView(b.buffer).setUint32(1,P,!1);const d=new Uint8Array(Ot);d[0]=1,new DataView(d.buffer).setUint32(1,P,!1);const m=J(h,b),H=J(h,d),v=gt(u,m),E=gt(u,H);try{const I=v.slice(0,Ut),S=E.slice(0,Ut);f.push(I),x.push(S),g.push($t(I)),w.push($t(S))}finally{m.fill(0),H.fill(0),v.fill(0),E.fill(0)}}return T=!0,{falsePreimages:f,truePreimages:x,falseHashes:g,trueHashes:w}}finally{if(!T){for(const P of f)P.fill(0);for(const P of x)P.fill(0)}}}finally{for(const a of i)a.fill(0)}}function $n(e){return{false_list:e.falseHashes.map(bt),true_list:e.trueHashes.map(bt)}}function ue(e){if(e.falseHashes.length===0||e.trueHashes.length===0)throw new Error("computeWotsPkHash: 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=Hn(s);return`0x${bt(o)}`}async function Cn(e,t,n,s){const r=ae(e);try{const o=await ce(r,t,n,s);try{return ue(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 Fn(e){const t=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return t.includes("wots")&&t.includes("hash")&&t.includes("does not match")}exports.BTCVaultRegistryABI=G;exports.BitcoinScriptType=Y;exports.CONTRACT_ERRORS=M;exports.MEMPOOL_API_URLS=Vt;exports.PayoutManager=Ue;exports.PeginManager=Ae;exports.calculateBtcTxHash=it;exports.computeWotsPkHash=ue;exports.createSplitTransaction=ye;exports.createSplitTransactionPsbt=xe;exports.createTaprootScriptPathSignOptions=ct;exports.deriveWotsKeypair=ce;exports.deriveWotsPkHash=Cn;exports.extractErrorData=lt;exports.getAddressTxs=He;exports.getAddressUtxos=Te;exports.getContractErrorMessage=Ee;exports.getDustThreshold=be;exports.getMempoolApiUrl=ve;exports.getNetworkFees=ke;exports.getPsbtInputFields=_t;exports.getScriptType=Ft;exports.getTxHex=Pe;exports.getTxInfo=Kt;exports.getUtxoInfo=Mt;exports.handleContractError=D;exports.isKnownContractError=Ie;exports.isWotsMismatchError=Fn;exports.keypairToPublicKey=$n;exports.mnemonicToWotsSeed=ae;exports.pushTx=Dt;exports.selectUtxosForPegin=Ct;exports.shouldAddChangeOutput=ge;
|
|
2
|
+
//# sourceMappingURL=errors-BZc3Urez.cjs.map
|