import{E as _o}from"./BlqqkVcP.js";import{E as vo,a as To}from"./De0Euczk.js";import{E as ko}from"./B-X9mpsG.js";import{_ as Io}from"./xARTK0KQ.js";import{ak as h,al as ln,ag as Ri,a7 as Oo,u as Dn,r as Lr,$ as Po,L as Ao,o as xo,c as Gn,w as Fr,a as Mr,b as lt,d as Vt,e as At,i as jn,D as No,ab as Bo,ac as Uo,f as Ho,t as Wn}from"./CT_r9YpW.js";import"./DIhqVT6U.js";import{_ as $i,s as Li}from"./QqWnl41F.js";import{u as Fi}from"./DDLMsdPy.js";import{S as Co}from"./BSVL8zcG.js";import"./Avsf-i3k.js";import"./CuA4w6C0.js";import"./CQrU1xbR.js";import"./DXr7LOgT.js";import"./wsOJkCCF.js";import"./BO3WGe0r.js";const Ro={解码交易:"Decode transaction",解码结果:"Decoded result",请输入内容:"Please enter content",请输入正确的Tr_3f32:"Please enter valid transaction hex",请选择:"Please choose"},$o={解码交易:"解码交易",解码结果:"解码结果",请输入内容:"请输入内容",请输入正确的Tr_3f32:"请输入正确的Transaction Hex",请选择:"请选择"},Lo={解码交易:"解碼交易",解码结果:"解碼結果",请输入内容:"請輸入內容",请输入正确的Tr_3f32:"請輸入正確的Transaction Hex",请选择:"請選擇"},Vn={en_US:Ro,zh_Hans_CN:$o,zh_Hant_HK:Lo};var ge={},re={},G={};Object.defineProperty(G,"__esModule",{value:!0});G.testnet=G.regtest=G.bitcoin=void 0;G.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};G.regtest={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};G.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Pt={},wr={},ne={},Ne={};Object.defineProperty(Ne,"__esModule",{value:!0});Ne.encode=Ne.decode=Ne.check=void 0;function Fo(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}Ne.check=Fo;function Mo(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}Ne.decode=Mo;function Ko(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=h.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}Ne.encode=Ko;var Ge={};Object.defineProperty(Ge,"__esModule",{value:!0});Ge.REVERSE_OPS=Ge.OPS=void 0;const nn={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Ge.OPS=nn;const Mi={};Ge.REVERSE_OPS=Mi;for(const e of Object.keys(nn)){const t=nn[e];Mi[t]=e}var Ke={};Object.defineProperty(Ke,"__esModule",{value:!0});Ke.decode=Ke.encode=Ke.encodingLength=void 0;const Me=Ge;function Ki(e){return e<Me.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Ke.encodingLength=Ki;function Do(e,t,r){const n=Ki(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(Me.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(Me.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(Me.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Ke.encode=Do;function Go(e,t){const r=e.readUInt8(t);let n,i;if(r<Me.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===Me.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===Me.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==Me.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Ke.decode=Go;var kt={};Object.defineProperty(kt,"__esModule",{value:!0});kt.encode=kt.decode=void 0;function jo(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const o=e.readUInt32LE(0),s=e.readUInt8(4);return s&128?-((s&-129)*4294967296+o):s*4294967296+o}let i=0;for(let o=0;o<n;++o)i|=e[o]<<8*o;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}kt.decode=jo;function Wo(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function Vo(e){let t=Math.abs(e);const r=Wo(t),n=h.allocUnsafe(r),i=e<0;for(let o=0;o<r;++o)n.writeUInt8(t&255,o),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}kt.encode=Vo;var It={},Y={},Dt={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};Dt.Null=Dt.Nil;for(var Xn in Dt)Dt[Xn].toJSON=(function(e){return e}).bind(null,Xn);var dn=Dt,ze=dn;function Di(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function bn(e){return ze.Nil(e)?"":Di(e.constructor)}function Xo(e){return ze.Function(e)?"":ze.String(e)?JSON.stringify(e):e&&ze.Object(e)?"":e}function gn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function hr(e){return ze.Function(e)?e.toJSON?e.toJSON():Di(e):ze.Array(e)?"Array":e&&ze.Object(e)?"Object":e!==void 0?e:""}function Gi(e,t,r){var n=Xo(t);return"Expected "+hr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Ue(e,t,r){r=r||bn(t),this.message=Gi(e,t,r),gn(this,Ue),this.__type=e,this.__value=t,this.__valueTypeName=r}Ue.prototype=Object.create(Error.prototype);Ue.prototype.constructor=Ue;function qo(e,t,r,n,i){var o='" of type ';return t==="key"&&(o='" with key type '),Gi('property "'+hr(r)+o+hr(e),n,i)}function Et(e,t,r,n,i){e?(i=i||bn(n),this.message=qo(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',gn(this,Ue),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Et.prototype=Object.create(Error.prototype);Et.prototype.constructor=Ue;function zo(e,t){return new Ue(e,{},t)}function Yo(e,t,r){return e instanceof Et?(t=t+"."+e.__property,e=new Et(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Ue&&(e=new Et(e.__type,t,r,e.__value,e.__valueTypeName)),gn(e),e}var ji={TfTypeError:Ue,TfPropertyTypeError:Et,tfCustomError:zo,tfSubError:Yo,tfJSON:hr,getValueTypeName:bn},Kr,qn;function Jo(){if(qn)return Kr;qn=1;var e=dn,t=ji;function r(m){return h.isBuffer(m)}function n(m){return typeof m=="string"&&/^([0-9a-f]{2})+$/i.test(m)}function i(m,C){var W=m.toJSON();function w(P){if(!m(P))return!1;if(P.length===C)return!0;throw t.tfCustomError(W+"(Length: "+C+")",W+"(Length: "+P.length+")")}return w.toJSON=function(){return W},w}var o=i.bind(null,e.Array),s=i.bind(null,r),c=i.bind(null,n),a=i.bind(null,e.String);function p(m,C,W){W=W||e.Number;function w(P,$){return W(P,$)&&P>m&&P<C}return w.toJSON=function(){return"".concat(W.toJSON()," between [").concat(m,", ").concat(C,"]")},w}var f=Math.pow(2,53)-1;function u(m){return typeof m=="number"&&isFinite(m)}function d(m){return m<<24>>24===m}function l(m){return m<<16>>16===m}function b(m){return(m|0)===m}function g(m){return typeof m=="number"&&m>=-f&&m<=f&&Math.floor(m)===m}function y(m){return(m&255)===m}function S(m){return(m&65535)===m}function v(m){return m>>>0===m}function _(m){return typeof m=="number"&&m>=0&&m<=f&&Math.floor(m)===m}var E={ArrayN:o,Buffer:r,BufferN:s,Finite:u,Hex:n,HexN:c,Int8:d,Int16:l,Int32:b,Int53:g,Range:p,StringN:a,UInt8:y,UInt16:S,UInt32:v,UInt53:_};for(var T in E)E[T].toJSON=(function(m){return m}).bind(null,T);return Kr=E,Kr}var jt=ji,q=dn,Te=jt.tfJSON,Wi=jt.TfTypeError,Vi=jt.TfPropertyTypeError,xt=jt.tfSubError,Qo=jt.getValueTypeName,xe={arrayOf:function(t,r){t=we(t),r=r||{};function n(i,o){return!q.Array(i)||q.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(s,c){try{return te(t,s,o)}catch(a){throw xt(a,c)}})}return n.toJSON=function(){var i="["+Te(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=we(t);function r(n,i){return q.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+Te(t)},r},map:function(t,r){t=we(t),r&&(r=we(r));function n(i,o){if(!q.Object(i)||q.Nil(i))return!1;for(var s in i){try{r&&te(r,s,o)}catch(a){throw xt(a,s,"key")}try{var c=i[s];te(t,c,o)}catch(a){throw xt(a,s)}}return!0}return r?n.toJSON=function(){return"{"+Te(r)+": "+Te(t)+"}"}:n.toJSON=function(){return"{"+Te(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=we(t[n]);function i(o,s){if(!q.Object(o)||q.Nil(o))return!1;var c;try{for(c in r){var a=r[c],p=o[c];te(a,p,s)}}catch(f){throw xt(f,c)}if(s){for(c in o)if(!r[c])throw new Vi(void 0,c)}return!0}return i.toJSON=function(){return Te(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(we);function r(n,i){return t.some(function(o){try{return te(o,n,i)}catch(s){return!1}})}return r.toJSON=function(){return t.map(Te).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(we);function r(n,i){return t.every(function(o){try{return te(o,n,i)}catch(s){return!1}})}return r.toJSON=function(){return t.map(Te).join(" & ")},r},quacksLike:function(t){function r(n){return t===Qo(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(we);function r(n,i){return q.Nil(n)||q.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(o,s){try{return te(o,n[s],i)}catch(c){throw xt(c,s)}})}return r.toJSON=function(){return"("+t.map(Te).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};xe.oneOf=xe.anyOf;function we(e){if(q.String(e))return e[0]==="?"?xe.maybe(e.slice(1)):q[e]||xe.quacksLike(e);if(e&&q.Object(e)){if(q.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return xe.arrayOf(e[0])}return xe.object(e)}else if(q.Function(e))return e;return xe.value(e)}function te(e,t,r,n){if(q.Function(e)){if(e(t,r))return!0;throw new Wi(n||e,t)}return te(we(e),t,r)}for(var De in q)te[De]=q[De];for(De in xe)te[De]=xe[De];var zn=Jo();for(De in zn)te[De]=zn[De];te.compile=we;te.TfTypeError=Wi;te.TfPropertyTypeError=Vi;var Zo=te;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Network=e.ECPoint=e.Satoshi=e.Signer=e.BIP32Path=e.UInt31=e.isPoint=e.typeforce=void 0;const t=ln;e.typeforce=Zo;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(l){if(!t.Buffer.isBuffer(l)||l.length<33)return!1;const b=l[0],g=l.slice(1,33);if(g.compare(r)===0||g.compare(n)>=0)return!1;if((b===2||b===3)&&l.length===33)return!0;const y=l.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:b===4&&l.length===65}e.isPoint=i;const o=Math.pow(2,31)-1;function s(l){return e.typeforce.UInt32(l)&&l<=o}e.UInt31=s;function c(l){return e.typeforce.String(l)&&!!l.match(/^(m\/)?(\d+'?\/)*\d+'?$/)}e.BIP32Path=c,c.toJSON=()=>"BIP32 derivation path";function a(l){return(e.typeforce.Buffer(l.publicKey)||typeof l.getPublicKey=="function")&&typeof l.sign=="function"}e.Signer=a;const p=21*1e14;function f(l){return e.typeforce.UInt53(l)&&l<=p}e.Satoshi=f,e.ECPoint=e.typeforce.quacksLike("Point"),e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.TAPLEAF_VERSION_MASK=254;function u(l){return!l||!("output"in l)||!t.Buffer.isBuffer(l.output)?!1:l.version!==void 0?(l.version&e.TAPLEAF_VERSION_MASK)===l.version:!0}e.isTapleaf=u;function d(l){return(0,e.Array)(l)?l.length!==2?!1:l.every(b=>d(b)):u(l)}e.isTaptree=d,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Y);Object.defineProperty(It,"__esModule",{value:!0});It.encode=It.decode=void 0;const Xi=Ne,sn=Y,{typeforce:ec}=sn,Yn=h.alloc(1,0);function Jn(e){let t=0;for(;e[t]===0;)++t;return t===e.length?Yn:(e=e.slice(t),e[0]&128?h.concat([Yn,e],1+e.length):e)}function Qn(e){e[0]===0&&(e=e.slice(1));const t=h.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}function tc(e){const t=e.readUInt8(e.length-1),r=t&-129;if(r<=0||r>=4)throw new Error("Invalid hashType "+t);const n=Xi.decode(e.slice(0,-1)),i=Qn(n.r),o=Qn(n.s);return{signature:h.concat([i,o],64),hashType:t}}It.decode=tc;function rc(e,t){ec({signature:sn.BufferN(64),hashType:sn.UInt8},{signature:e,hashType:t});const r=t&-129;if(r<=0||r>=4)throw new Error("Invalid hashType "+t);const n=h.allocUnsafe(1);n.writeUInt8(t,0);const i=Jn(e.slice(0,32)),o=Jn(e.slice(32,64));return h.concat([Xi.encode(i,o),n])}It.encode=rc;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=Ne,r=Ge;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Ke,i=kt,o=It,s=Y,{typeforce:c}=s,a=r.OPS.OP_RESERVED;function p(w){return s.Number(w)&&(w===r.OPS.OP_0||w>=r.OPS.OP_1&&w<=r.OPS.OP_16||w===r.OPS.OP_1NEGATE)}function f(w){return s.Buffer(w)||p(w)}function u(w){return s.Array(w)&&w.every(f)}e.isPushOnly=u;function d(w){return w.length-w.filter(f).length}e.countNonPushOnlyOPs=d;function l(w){if(w.length===0)return r.OPS.OP_0;if(w.length===1){if(w[0]>=1&&w[0]<=16)return a+w[0];if(w[0]===129)return r.OPS.OP_1NEGATE}}function b(w){return h.isBuffer(w)}function g(w){return s.Array(w)}function y(w){return h.isBuffer(w)}function S(w){if(b(w))return w;c(s.Array,w);const P=w.reduce((J,pe)=>y(pe)?pe.length===1&&l(pe)!==void 0?J+1:J+n.encodingLength(pe.length)+pe.length:J+1,0),$=h.allocUnsafe(P);let se=0;if(w.forEach(J=>{if(y(J)){const pe=l(J);if(pe!==void 0){$.writeUInt8(pe,se),se+=1;return}se+=n.encode($,J.length,se),J.copy($,se),se+=J.length}else $.writeUInt8(J,se),se+=1}),se!==$.length)throw new Error("Could not decode chunks");return $}e.compile=S;function v(w){if(g(w))return w;c(s.Buffer,w);const P=[];let $=0;for(;$<w.length;){const se=w[$];if(se>r.OPS.OP_0&&se<=r.OPS.OP_PUSHDATA4){const J=n.decode(w,$);if(J===null||($+=J.size,$+J.number>w.length))return null;const pe=w.slice($,$+J.number);$+=J.number;const Kn=l(pe);Kn!==void 0?P.push(Kn):P.push(pe)}else P.push(se),$+=1}return P}e.decompile=v;function _(w){return b(w)&&(w=v(w)),w.map(P=>{if(y(P)){const $=l(P);if($===void 0)return P.toString("hex");P=$}return r.REVERSE_OPS[P]}).join(" ")}e.toASM=_;function E(w){return c(s.String,w),S(w.split(" ").map(P=>r.OPS[P]!==void 0?r.OPS[P]:(c(s.Hex,P),h.from(P,"hex"))))}e.fromASM=E;function T(w){return w=v(w),c(u,w),w.map(P=>y(P)?P:P===r.OPS.OP_0?h.allocUnsafe(0):i.encode(P-a))}e.toStack=T;function m(w){return s.isPoint(w)}e.isCanonicalPubKey=m;function C(w){const P=w&-129;return P>0&&P<4}e.isDefinedHashType=C;function W(w){return!h.isBuffer(w)||!C(w[w.length-1])?!1:t.check(w.slice(0,-1))}e.isCanonicalScriptSignature=W,e.number=i,e.signature=o})(ne);var ce={};Object.defineProperty(ce,"__esModule",{value:!0});ce.value=ce.prop=void 0;function nc(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}ce.prop=nc;function ic(e){let t;return()=>(t!==void 0||(t=e()),t)}ce.value=ic;Object.defineProperty(wr,"__esModule",{value:!0});wr.p2data=void 0;const sc=G,cr=ne,ke=Y,Zn=ce,ei=cr.OPS;function oc(e,t){return e.length!==t.length?!1:e.every((r,n)=>r.equals(t[n]))}function cc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ke.typeforce)({network:ke.typeforce.maybe(ke.typeforce.Object),output:ke.typeforce.maybe(ke.typeforce.Buffer),data:ke.typeforce.maybe(ke.typeforce.arrayOf(ke.typeforce.Buffer))},e);const n={name:"embed",network:e.network||sc.bitcoin};if(Zn.prop(n,"output",()=>{if(e.data)return cr.compile([ei.OP_RETURN].concat(e.data))}),Zn.prop(n,"data",()=>{if(e.output)return cr.decompile(e.output).slice(1)}),t.validate&&e.output){const i=cr.decompile(e.output);if(i[0]!==ei.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(ke.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!oc(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}wr.p2data=cc;var Sr={};Object.defineProperty(Sr,"__esModule",{value:!0});Sr.p2ms=void 0;const ac=G,yt=ne,M=Y,Ce=ce,mt=yt.OPS,Xt=mt.OP_RESERVED;function ti(e,t){return e.length!==t.length?!1:e.every((r,n)=>r.equals(t[n]))}function uc(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(a){return yt.isCanonicalScriptSignature(a)||(t.allowIncomplete&&a===mt.OP_0)!==void 0}(0,M.typeforce)({network:M.typeforce.maybe(M.typeforce.Object),m:M.typeforce.maybe(M.typeforce.Number),n:M.typeforce.maybe(M.typeforce.Number),output:M.typeforce.maybe(M.typeforce.Buffer),pubkeys:M.typeforce.maybe(M.typeforce.arrayOf(M.isPoint)),signatures:M.typeforce.maybe(M.typeforce.arrayOf(r)),input:M.typeforce.maybe(M.typeforce.Buffer)},e);const i={network:e.network||ac.bitcoin};let o=[],s=!1;function c(a){s||(s=!0,o=yt.decompile(a),i.m=o[0]-Xt,i.n=o[o.length-2]-Xt,i.pubkeys=o.slice(1,-2))}if(Ce.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return yt.compile([].concat(Xt+e.m,e.pubkeys,Xt+i.n,mt.OP_CHECKMULTISIG))}),Ce.prop(i,"m",()=>{if(i.output)return c(i.output),i.m}),Ce.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Ce.prop(i,"pubkeys",()=>{if(e.output)return c(e.output),i.pubkeys}),Ce.prop(i,"signatures",()=>{if(e.input)return yt.decompile(e.input).slice(1)}),Ce.prop(i,"input",()=>{if(e.signatures)return yt.compile([mt.OP_0].concat(e.signatures))}),Ce.prop(i,"witness",()=>{if(i.input)return[]}),Ce.prop(i,"name",()=>{if(!(!i.m||!i.n))return"p2ms(".concat(i.m," of ").concat(i.n,")")}),t.validate){if(e.output){if(c(e.output),!M.typeforce.Number(o[0]))throw new TypeError("Output is invalid");if(!M.typeforce.Number(o[o.length-2]))throw new TypeError("Output is invalid");if(o[o.length-1]!==mt.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==o.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(a=>(0,M.isPoint)(a)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!ti(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==mt.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!ti(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}Sr.p2ms=uc;var Er={};Object.defineProperty(Er,"__esModule",{value:!0});Er.p2pk=void 0;const fc=G,wt=ne,he=Y,dt=ce,ri=wt.OPS;function pc(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,he.typeforce)({network:he.typeforce.maybe(he.typeforce.Object),output:he.typeforce.maybe(he.typeforce.Buffer),pubkey:he.typeforce.maybe(he.isPoint),signature:he.typeforce.maybe(wt.isCanonicalScriptSignature),input:he.typeforce.maybe(he.typeforce.Buffer)},e);const r=dt.value(()=>wt.decompile(e.input)),i={name:"p2pk",network:e.network||fc.bitcoin};if(dt.prop(i,"output",()=>{if(e.pubkey)return wt.compile([e.pubkey,ri.OP_CHECKSIG])}),dt.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),dt.prop(i,"signature",()=>{if(e.input)return r()[0]}),dt.prop(i,"input",()=>{if(e.signature)return wt.compile([e.signature])}),dt.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==ri.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,he.isPoint)(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!wt.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}Er.p2pk=pc;var _r={},_e={},Ot={};Object.defineProperty(Ot,"__esModule",{value:!0});Ot.ripemd160=Ot.RIPEMD160=void 0;const hc=$i,Ct=Fi,lc=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),qi=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),dc=qi.map(e=>(9*e+5)%16);let yn=[qi],mn=[dc];for(let e=0;e<4;e++)for(let t of[yn,mn])t.push(t[e].map(r=>lc[r]));const zi=[[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=>new Uint8Array(e)),bc=yn.map((e,t)=>e.map(r=>zi[t][r])),gc=mn.map((e,t)=>e.map(r=>zi[t][r])),yc=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),mc=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function ni(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const qt=new Uint32Array(16);class Yi extends hc.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(t,r){for(let l=0;l<16;l++,r+=4)qt[l]=t.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,c=this.h2|0,a=c,p=this.h3|0,f=p,u=this.h4|0,d=u;for(let l=0;l<5;l++){const b=4-l,g=yc[l],y=mc[l],S=yn[l],v=mn[l],_=bc[l],E=gc[l];for(let T=0;T<16;T++){const m=(0,Ct.rotl)(n+ni(l,o,c,p)+qt[S[T]]+g,_[T])+u|0;n=u,u=p,p=(0,Ct.rotl)(c,10)|0,c=o,o=m}for(let T=0;T<16;T++){const m=(0,Ct.rotl)(i+ni(b,s,a,f)+qt[v[T]]+y,E[T])+d|0;i=d,d=f,f=(0,Ct.rotl)(a,10)|0,a=s,s=m}}this.set(this.h1+c+f|0,this.h2+p+d|0,this.h3+u+i|0,this.h4+n+s|0,this.h0+o+a|0)}roundClean(){qt.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}Ot.RIPEMD160=Yi;Ot.ripemd160=(0,Ct.wrapConstructor)(()=>new Yi);var vr={};Object.defineProperty(vr,"__esModule",{value:!0});vr.sha1=void 0;const Dr=$i,ar=Fi,Nt=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Re=new Uint32Array(80);class wc extends Dr.HashMD{constructor(){super(64,20,8,!1),this.A=Nt[0]|0,this.B=Nt[1]|0,this.C=Nt[2]|0,this.D=Nt[3]|0,this.E=Nt[4]|0}get(){const{A:t,B:r,C:n,D:i,E:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0}process(t,r){for(let a=0;a<16;a++,r+=4)Re[a]=t.getUint32(r,!1);for(let a=16;a<80;a++)Re[a]=(0,ar.rotl)(Re[a-3]^Re[a-8]^Re[a-14]^Re[a-16],1);let{A:n,B:i,C:o,D:s,E:c}=this;for(let a=0;a<80;a++){let p,f;a<20?(p=(0,Dr.Chi)(i,o,s),f=1518500249):a<40?(p=i^o^s,f=1859775393):a<60?(p=(0,Dr.Maj)(i,o,s),f=2400959708):(p=i^o^s,f=3395469782);const u=(0,ar.rotl)(n,5)+p+c+f+Re[a]|0;c=s,s=o,o=(0,ar.rotl)(i,30),i=n,n=u}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,this.set(n,i,o,s,c)}roundClean(){Re.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}vr.sha1=(0,ar.wrapConstructor)(()=>new wc);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=Ot,r=vr,n=Li;function i(f){return h.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function o(f){return h.from((0,r.sha1)(Uint8Array.from(f)))}e.sha1=o;function s(f){return h.from((0,n.sha256)(Uint8Array.from(f)))}e.sha256=s;function c(f){return h.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(f))))}e.hash160=c;function a(f){return h.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(f))))}e.hash256=a,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":h.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":h.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":h.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:h.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:h.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:h.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:h.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":h.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":h.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function p(f,u){return s(h.concat([e.TAGGED_HASH_PREFIXES[f],u]))}e.taggedHash=p})(_e);function Sc(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,c=e.charAt(0),a=Math.log(s)/Math.log(256),p=Math.log(256)/Math.log(s);function f(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var b=0,g=0,y=0,S=l.length;y!==S&&l[y]===0;)y++,b++;for(var v=(S-y)*p+1>>>0,_=new Uint8Array(v);y!==S;){for(var E=l[y],T=0,m=v-1;(E!==0||T<g)&&m!==-1;m--,T++)E+=256*_[m]>>>0,_[m]=E%s>>>0,E=E/s>>>0;if(E!==0)throw new Error("Non-zero carry");g=T,y++}for(var C=v-g;C!==v&&_[C]===0;)C++;for(var W=c.repeat(b);C<v;++C)W+=e.charAt(_[C]);return W}function u(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;for(var b=0,g=0,y=0;l[b]===c;)g++,b++;for(var S=(l.length-b)*a+1>>>0,v=new Uint8Array(S);l[b];){var _=t[l.charCodeAt(b)];if(_===255)return;for(var E=0,T=S-1;(_!==0||E<y)&&T!==-1;T--,E++)_+=s*v[T]>>>0,v[T]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");y=E,b++}for(var m=S-y;m!==S&&v[m]===0;)m++;for(var C=new Uint8Array(g+(S-m)),W=g;m!==S;)C[W++]=v[m++];return C}function d(l){var b=u(l);if(b)return b;throw new Error("Non-base"+s+" character")}return{encode:f,decodeUnsafe:u,decode:d}}var Ec=Sc;const _c=Ec,vc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var Tc=_c(vc),Gr=Tc,kc=function(e){function t(o){var s=Uint8Array.from(o),c=e(s),a=s.length+4,p=new Uint8Array(a);return p.set(s,0),p.set(c.subarray(0,4),s.length),Gr.encode(p,a)}function r(o){var s=o.slice(0,-4),c=o.slice(-4),a=e(s);if(!(c[0]^a[0]|c[1]^a[1]|c[2]^a[2]|c[3]^a[3]))return s}function n(o){var s=Gr.decodeUnsafe(o);if(s)return r(s)}function i(o){var s=Gr.decode(o),c=r(s);if(!c)throw new Error("Invalid checksum");return c}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:ii}=Li,Ic=kc;function Oc(e){return ii(ii(e))}var wn=Ic(Oc);Object.defineProperty(_r,"__esModule",{value:!0});_r.p2pkh=void 0;const jr=_e,Pc=G,St=ne,Q=Y,Ie=ce,si=wn,$e=St.OPS;function Ac(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Q.typeforce)({network:Q.typeforce.maybe(Q.typeforce.Object),address:Q.typeforce.maybe(Q.typeforce.String),hash:Q.typeforce.maybe(Q.typeforce.BufferN(20)),output:Q.typeforce.maybe(Q.typeforce.BufferN(25)),pubkey:Q.typeforce.maybe(Q.isPoint),signature:Q.typeforce.maybe(St.isCanonicalScriptSignature),input:Q.typeforce.maybe(Q.typeforce.Buffer)},e);const r=Ie.value(()=>{const s=h.from(si.decode(e.address)),c=s.readUInt8(0),a=s.slice(1);return{version:c,hash:a}}),n=Ie.value(()=>St.decompile(e.input)),i=e.network||Pc.bitcoin,o={name:"p2pkh",network:i};if(Ie.prop(o,"address",()=>{if(!o.hash)return;const s=h.allocUnsafe(21);return s.writeUInt8(i.pubKeyHash,0),o.hash.copy(s,1),si.encode(s)}),Ie.prop(o,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||o.pubkey)return jr.hash160(e.pubkey||o.pubkey)}),Ie.prop(o,"output",()=>{if(o.hash)return St.compile([$e.OP_DUP,$e.OP_HASH160,o.hash,$e.OP_EQUALVERIFY,$e.OP_CHECKSIG])}),Ie.prop(o,"pubkey",()=>{if(e.input)return n()[1]}),Ie.prop(o,"signature",()=>{if(e.input)return n()[0]}),Ie.prop(o,"input",()=>{if(e.pubkey&&e.signature)return St.compile([e.signature,e.pubkey])}),Ie.prop(o,"witness",()=>{if(o.input)return[]}),t.validate){let s=h.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");s=r().hash}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==$e.OP_DUP||e.output[1]!==$e.OP_HASH160||e.output[2]!==20||e.output[23]!==$e.OP_EQUALVERIFY||e.output[24]!==$e.OP_CHECKSIG)throw new TypeError("Output is invalid");const c=e.output.slice(3,23);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch");s=c}if(e.pubkey){const c=jr.hash160(e.pubkey);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch");s=c}if(e.input){const c=n();if(c.length!==2)throw new TypeError("Input is invalid");if(!St.isCanonicalScriptSignature(c[0]))throw new TypeError("Input has invalid signature");if(!(0,Q.isPoint)(c[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(c[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(c[1]))throw new TypeError("Pubkey mismatch");const a=jr.hash160(c[1]);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}_r.p2pkh=Ac;var Tr={};Object.defineProperty(Tr,"__esModule",{value:!0});Tr.p2sh=void 0;const oi=_e,xc=G,ye=ne,U=Y,de=ce,ci=wn,Bt=ye.OPS;function Nc(e,t){return e.length!==t.length?!1:e.every((r,n)=>r.equals(t[n]))}function Bc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,U.typeforce)({network:U.typeforce.maybe(U.typeforce.Object),address:U.typeforce.maybe(U.typeforce.String),hash:U.typeforce.maybe(U.typeforce.BufferN(20)),output:U.typeforce.maybe(U.typeforce.BufferN(23)),redeem:U.typeforce.maybe({network:U.typeforce.maybe(U.typeforce.Object),output:U.typeforce.maybe(U.typeforce.Buffer),input:U.typeforce.maybe(U.typeforce.Buffer),witness:U.typeforce.maybe(U.typeforce.arrayOf(U.typeforce.Buffer))}),input:U.typeforce.maybe(U.typeforce.Buffer),witness:U.typeforce.maybe(U.typeforce.arrayOf(U.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||xc.bitcoin);const n={network:r},i=de.value(()=>{const c=h.from(ci.decode(e.address)),a=c.readUInt8(0),p=c.slice(1);return{version:a,hash:p}}),o=de.value(()=>ye.decompile(e.input)),s=de.value(()=>{const c=o(),a=c[c.length-1];return{network:r,output:a===Bt.OP_FALSE?h.from([]):a,input:ye.compile(c.slice(0,-1)),witness:e.witness||[]}});if(de.prop(n,"address",()=>{if(!n.hash)return;const c=h.allocUnsafe(21);return c.writeUInt8(n.network.scriptHash,0),n.hash.copy(c,1),ci.encode(c)}),de.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return oi.hash160(n.redeem.output)}),de.prop(n,"output",()=>{if(n.hash)return ye.compile([Bt.OP_HASH160,n.hash,Bt.OP_EQUAL])}),de.prop(n,"redeem",()=>{if(e.input)return s()}),de.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return ye.compile([].concat(ye.decompile(e.redeem.input),e.redeem.output))}),de.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),de.prop(n,"name",()=>{const c=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&c.push(n.redeem.name),c.join("-")}),t.validate){let c=h.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");c=i().hash}if(e.hash){if(c.length>0&&!c.equals(e.hash))throw new TypeError("Hash mismatch");c=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Bt.OP_HASH160||e.output[1]!==20||e.output[22]!==Bt.OP_EQUAL)throw new TypeError("Output is invalid");const p=e.output.slice(2,22);if(c.length>0&&!c.equals(p))throw new TypeError("Hash mismatch");c=p}const a=p=>{if(p.output){const f=ye.decompile(p.output);if(!f||f.length<1)throw new TypeError("Redeem.output too short");if(p.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ye.countNonPushOnlyOPs(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const u=oi.hash160(p.output);if(c.length>0&&!c.equals(u))throw new TypeError("Hash mismatch");c=u}if(p.input){const f=p.input.length>0,u=p.witness&&p.witness.length>0;if(!f&&!u)throw new TypeError("Empty input");if(f&&u)throw new TypeError("Input and witness provided");if(f){const d=ye.decompile(p.input);if(!ye.isPushOnly(d))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const p=o();if(!p||p.length<1)throw new TypeError("Input too short");if(!h.isBuffer(s().output))throw new TypeError("Input is invalid");a(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const p=s();if(e.redeem.output&&!e.redeem.output.equals(p.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(p.input))throw new TypeError("Redeem.input mismatch")}a(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!Nc(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}Tr.p2sh=Bc;var kr={},He={};Object.defineProperty(He,"__esModule",{value:!0});He.bech32m=He.bech32=void 0;const lr="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Ji={};for(let e=0;e<lr.length;e++){const t=lr.charAt(e);Ji[t]=e}function _t(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function ai(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=_t(t)^n>>5}t=_t(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=_t(t)^n&31}return t}function Sn(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,c=[];for(let a=0;a<e.length;++a)for(i=i<<t|e[a],o+=t;o>=r;)o-=r,c.push(i>>o&s);if(n)o>0&&c.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return c}function Uc(e){return Sn(e,8,5,!0)}function Hc(e){const t=Sn(e,5,8,!1);if(Array.isArray(t))return t}function Cc(e){const t=Sn(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Qi(e){let t;e==="bech32"?t=1:t=734539939;function r(s,c,a){if(a=a||90,s.length+7+c.length>a)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let p=ai(s);if(typeof p=="string")throw new Error(p);let f=s+"1";for(let u=0;u<c.length;++u){const d=c[u];if(d>>5)throw new Error("Non 5-bit word");p=_t(p)^d,f+=lr.charAt(d)}for(let u=0;u<6;++u)p=_t(p);p^=t;for(let u=0;u<6;++u){const d=p>>(5-u)*5&31;f+=lr.charAt(d)}return f}function n(s,c){if(c=c||90,s.length<8)return s+" too short";if(s.length>c)return"Exceeds length limit";const a=s.toLowerCase(),p=s.toUpperCase();if(s!==a&&s!==p)return"Mixed-case string "+s;s=a;const f=s.lastIndexOf("1");if(f===-1)return"No separator character for "+s;if(f===0)return"Missing prefix for "+s;const u=s.slice(0,f),d=s.slice(f+1);if(d.length<6)return"Data too short";let l=ai(u);if(typeof l=="string")return l;const b=[];for(let g=0;g<d.length;++g){const y=d.charAt(g),S=Ji[y];if(S===void 0)return"Unknown character "+y;l=_t(l)^S,!(g+6>=d.length)&&b.push(S)}return l!==t?"Invalid checksum for "+s:{prefix:u,words:b}}function i(s,c){const a=n(s,c);if(typeof a=="object")return a}function o(s,c){const a=n(s,c);if(typeof a=="object")return a;throw new Error(a)}return{decodeUnsafe:i,decode:o,encode:r,toWords:Uc,fromWordsUnsafe:Hc,fromWords:Cc}}He.bech32=Qi("bech32");He.bech32m=Qi("bech32m");Object.defineProperty(kr,"__esModule",{value:!0});kr.p2wpkh=void 0;const Wr=_e,Rc=G,ur=ne,K=Y,Le=ce,zt=He,ui=ur.OPS,$c=h.alloc(0);function Lc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,K.typeforce)({address:K.typeforce.maybe(K.typeforce.String),hash:K.typeforce.maybe(K.typeforce.BufferN(20)),input:K.typeforce.maybe(K.typeforce.BufferN(0)),network:K.typeforce.maybe(K.typeforce.Object),output:K.typeforce.maybe(K.typeforce.BufferN(22)),pubkey:K.typeforce.maybe(K.isPoint),signature:K.typeforce.maybe(ur.isCanonicalScriptSignature),witness:K.typeforce.maybe(K.typeforce.arrayOf(K.typeforce.Buffer))},e);const r=Le.value(()=>{const o=zt.bech32.decode(e.address),s=o.words.shift(),c=zt.bech32.fromWords(o.words);return{version:s,prefix:o.prefix,data:h.from(c)}}),n=e.network||Rc.bitcoin,i={name:"p2wpkh",network:n};if(Le.prop(i,"address",()=>{if(!i.hash)return;const o=zt.bech32.toWords(i.hash);return o.unshift(0),zt.bech32.encode(n.bech32,o)}),Le.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return Wr.hash160(e.pubkey||i.pubkey)}),Le.prop(i,"output",()=>{if(i.hash)return ur.compile([ui.OP_0,i.hash])}),Le.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Le.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Le.prop(i,"input",()=>{if(i.witness)return $c}),Le.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let o=h.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==ui.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(o.length>0&&!o.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");o=e.output.slice(2)}if(e.pubkey){const s=Wr.hash160(e.pubkey);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch");if(o=s,!(0,K.isPoint)(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!ur.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,K.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const s=Wr.hash160(e.witness[1]);if(o.length>0&&!o.equals(s))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}kr.p2wpkh=Lc;var Ir={};Object.defineProperty(Ir,"__esModule",{value:!0});Ir.p2wsh=void 0;const fi=_e,Fc=G,Ae=ne,B=Y,Oe=ce,Yt=He,pi=Ae.OPS,Vr=h.alloc(0);function Mc(e,t){return e.length!==t.length?!1:e.every((r,n)=>r.equals(t[n]))}function Jt(e){return!!(h.isBuffer(e)&&e.length===65&&e[0]===4&&(0,B.isPoint)(e))}function Kc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,B.typeforce)({network:B.typeforce.maybe(B.typeforce.Object),address:B.typeforce.maybe(B.typeforce.String),hash:B.typeforce.maybe(B.typeforce.BufferN(32)),output:B.typeforce.maybe(B.typeforce.BufferN(34)),redeem:B.typeforce.maybe({input:B.typeforce.maybe(B.typeforce.Buffer),network:B.typeforce.maybe(B.typeforce.Object),output:B.typeforce.maybe(B.typeforce.Buffer),witness:B.typeforce.maybe(B.typeforce.arrayOf(B.typeforce.Buffer))}),input:B.typeforce.maybe(B.typeforce.BufferN(0)),witness:B.typeforce.maybe(B.typeforce.arrayOf(B.typeforce.Buffer))},e);const r=Oe.value(()=>{const s=Yt.bech32.decode(e.address),c=s.words.shift(),a=Yt.bech32.fromWords(s.words);return{version:c,prefix:s.prefix,data:h.from(a)}}),n=Oe.value(()=>Ae.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Fc.bitcoin);const o={network:i};if(Oe.prop(o,"address",()=>{if(!o.hash)return;const s=Yt.bech32.toWords(o.hash);return s.unshift(0),Yt.bech32.encode(i.bech32,s)}),Oe.prop(o,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(o.redeem&&o.redeem.output)return fi.sha256(o.redeem.output)}),Oe.prop(o,"output",()=>{if(o.hash)return Ae.compile([pi.OP_0,o.hash])}),Oe.prop(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Vr,witness:e.witness.slice(0,-1)}}),Oe.prop(o,"input",()=>{if(o.witness)return Vr}),Oe.prop(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const s=Ae.toStack(n());return o.redeem=Object.assign({witness:s},e.redeem),o.redeem.input=Vr,[].concat(s,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Oe.prop(o,"name",()=>{const s=["p2wsh"];return o.redeem!==void 0&&o.redeem.name!==void 0&&s.push(o.redeem.name),s.join("-")}),t.validate){let s=h.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==pi.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const c=e.output.slice(2);if(s.length>0&&!s.equals(c))throw new TypeError("Hash mismatch");s=c}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const c=Ae.decompile(e.redeem.output);if(!c||c.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Ae.countNonPushOnlyOPs(c)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const a=fi.sha256(e.redeem.output);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.redeem.input&&!Ae.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!Mc(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Jt)||e.redeem.output&&(Ae.decompile(e.redeem.output)||[]).some(Jt))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const c=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(c))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(Jt)||(Ae.decompile(c)||[]).some(Jt))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}Ir.p2wsh=Kc;var Or={},je={};Object.defineProperty(je,"__esModule",{value:!0});je.getEccLib=je.initEccLib=void 0;const Mt={};function Dc(e){e?e!==Mt.eccLib&&(jc(e),Mt.eccLib=e):Mt.eccLib=e}je.initEccLib=Dc;function Gc(){if(!Mt.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Mt.eccLib}je.getEccLib=Gc;const Pe=e=>h.from(e,"hex");function jc(e){ae(typeof e.isXOnlyPoint=="function"),ae(e.isXOnlyPoint(Pe("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),ae(e.isXOnlyPoint(Pe("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),ae(e.isXOnlyPoint(Pe("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),ae(e.isXOnlyPoint(Pe("0000000000000000000000000000000000000000000000000000000000000001"))),ae(!e.isXOnlyPoint(Pe("0000000000000000000000000000000000000000000000000000000000000000"))),ae(!e.isXOnlyPoint(Pe("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),ae(typeof e.xOnlyPointAddTweak=="function"),Wc.forEach(t=>{const r=e.xOnlyPointAddTweak(Pe(t.pubkey),Pe(t.tweak));t.result===null?ae(r===null):(ae(r!==null),ae(r.parity===t.parity),ae(h.from(r.xOnlyPubkey).equals(Pe(t.result))))})}function ae(e){if(!e)throw new Error("ecc library invalid")}const Wc=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];var Pr={},D={},on=Ri.Buffer,Vc=9007199254740991;function En(e){if(e<0||e>Vc||e%1!==0)throw new RangeError("value out of range")}function Rt(e,t,r){if(En(e),t||(t=on.allocUnsafe(Zi(e))),!on.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Rt.bytes=1):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Rt.bytes=3):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Rt.bytes=5):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Rt.bytes=9),t}function $t(e,t){if(!on.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);var r=e.readUInt8(t);if(r<253)return $t.bytes=1,r;if(r===253)return $t.bytes=3,e.readUInt16LE(t+1);if(r===254)return $t.bytes=5,e.readUInt32LE(t+1);$t.bytes=9;var n=e.readUInt32LE(t+1),i=e.readUInt32LE(t+5),o=i*4294967296+n;return En(o),o}function Zi(e){return En(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var Xc={encode:Rt,decode:$t,encodingLength:Zi};Object.defineProperty(D,"__esModule",{value:!0});D.BufferReader=D.BufferWriter=D.cloneBuffer=D.reverseBuffer=D.writeUInt64LE=D.readUInt64LE=D.varuint=void 0;const Ye=Y,{typeforce:es}=Ye,Gt=Xc;D.varuint=Gt;function ts(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function rs(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,ts(n+r,9007199254740991),n+r}D.readUInt64LE=rs;function ns(e,t,r){return ts(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}D.writeUInt64LE=ns;function qc(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}D.reverseBuffer=qc;function zc(e){const t=h.allocUnsafe(e.length);return e.copy(t),t}D.cloneBuffer=zc;class _n{static withCapacity(t){return new _n(h.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,es(Ye.tuple(Ye.Buffer,Ye.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=ns(this.buffer,t,this.offset)}writeVarInt(t){Gt.encode(t,this.buffer,this.offset),this.offset+=Gt.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error("buffer size ".concat(this.buffer.length,", offset ").concat(this.offset))}}D.BufferWriter=_n;class Yc{constructor(t,r=0){this.buffer=t,this.offset=r,es(Ye.tuple(Ye.Buffer,Ye.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=rs(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=Gt.decode(this.buffer,this.offset);return this.offset+=Gt.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}D.BufferReader=Yc;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=ln,r=je,n=_e,i=D,o=Y;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const s=g=>"left"in g&&"right"in g;function c(g,y){if(g.length<33)throw new TypeError("The control-block length is too small. Got ".concat(g.length,", expected min 33."));const S=(g.length-33)/32;let v=y;for(let _=0;_<S;_++){const E=g.slice(33+32*_,65+32*_);v.compare(E)<0?v=l(v,E):v=l(E,v)}return v}e.rootHashFromPath=c;function a(g){if((0,o.isTapleaf)(g))return{hash:f(g)};const y=[a(g[0]),a(g[1])];y.sort((_,E)=>_.hash.compare(E.hash));const[S,v]=y;return{hash:l(S.hash,v.hash),left:S,right:v}}e.toHashTree=a;function p(g,y){if(s(g)){const S=p(g.left,y);if(S!==void 0)return[...S,g.right.hash];const v=p(g.right,y);if(v!==void 0)return[...v,g.left.hash]}else if(g.hash.equals(y))return[]}e.findScriptPath=p;function f(g){const y=g.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([y]),b(g.output)]))}e.tapleafHash=f;function u(g,y){return n.taggedHash("TapTweak",t.Buffer.concat(y?[g,y]:[g]))}e.tapTweakHash=u;function d(g,y){if(!t.Buffer.isBuffer(g)||g.length!==32||y&&y.length!==32)return null;const S=u(g,y),v=(0,r.getEccLib)().xOnlyPointAddTweak(g,S);return!v||v.xOnlyPubkey===null?null:{parity:v.parity,x:t.Buffer.from(v.xOnlyPubkey)}}e.tweakKey=d;function l(g,y){return n.taggedHash("TapBranch",t.Buffer.concat([g,y]))}function b(g){const y=i.varuint.encodingLength(g.length),S=t.Buffer.allocUnsafe(y);return i.varuint.encode(g.length,S),t.Buffer.concat([S,g])}})(Pr);Object.defineProperty(Or,"__esModule",{value:!0});Or.p2tr=void 0;const Qt=ln,Jc=G,cn=ne,O=Y,hi=je,ie=Pr,ue=ce,Zt=He,li=cn.OPS,di=1,Qc=80;function Zc(e,t){if(!e.address&&!e.output&&!e.pubkey&&!e.internalPubkey&&!(e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,O.typeforce)({address:O.typeforce.maybe(O.typeforce.String),input:O.typeforce.maybe(O.typeforce.BufferN(0)),network:O.typeforce.maybe(O.typeforce.Object),output:O.typeforce.maybe(O.typeforce.BufferN(34)),internalPubkey:O.typeforce.maybe(O.typeforce.BufferN(32)),hash:O.typeforce.maybe(O.typeforce.BufferN(32)),pubkey:O.typeforce.maybe(O.typeforce.BufferN(32)),signature:O.typeforce.maybe(O.typeforce.anyOf(O.typeforce.BufferN(64),O.typeforce.BufferN(65))),witness:O.typeforce.maybe(O.typeforce.arrayOf(O.typeforce.Buffer)),scriptTree:O.typeforce.maybe(O.isTaptree),redeem:O.typeforce.maybe({output:O.typeforce.maybe(O.typeforce.Buffer),redeemVersion:O.typeforce.maybe(O.typeforce.Number),witness:O.typeforce.maybe(O.typeforce.arrayOf(O.typeforce.Buffer))}),redeemVersion:O.typeforce.maybe(O.typeforce.Number)},e);const r=ue.value(()=>{const c=Zt.bech32m.decode(e.address),a=c.words.shift(),p=Zt.bech32m.fromWords(c.words);return{version:a,prefix:c.prefix,data:Qt.Buffer.from(p)}}),n=ue.value(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===Qc?e.witness.slice(0,-1):e.witness.slice()}),i=ue.value(()=>{if(e.scriptTree)return(0,ie.toHashTree)(e.scriptTree);if(e.hash)return{hash:e.hash}}),o=e.network||Jc.bitcoin,s={name:"p2tr",network:o};if(ue.prop(s,"address",()=>{if(!s.pubkey)return;const c=Zt.bech32m.toWords(s.pubkey);return c.unshift(di),Zt.bech32m.encode(o.bech32,c)}),ue.prop(s,"hash",()=>{const c=i();if(c)return c.hash;const a=n();if(a&&a.length>1){const p=a[a.length-1],f=p[0]&O.TAPLEAF_VERSION_MASK,u=a[a.length-2],d=(0,ie.tapleafHash)({output:u,version:f});return(0,ie.rootHashFromPath)(p,d)}return null}),ue.prop(s,"output",()=>{if(s.pubkey)return cn.compile([li.OP_1,s.pubkey])}),ue.prop(s,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:ie.LEAF_VERSION_TAPSCRIPT),ue.prop(s,"redeem",()=>{const c=n();if(!(!c||c.length<2))return{output:c[c.length-2],witness:c.slice(0,-2),redeemVersion:c[c.length-1][0]&O.TAPLEAF_VERSION_MASK}}),ue.prop(s,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.internalPubkey){const c=(0,ie.tweakKey)(s.internalPubkey,s.hash);if(c)return c.x}}),ue.prop(s,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const c=n();if(c&&c.length>1)return c[c.length-1].slice(1,33)}),ue.prop(s,"signature",()=>{if(e.signature)return e.signature;const c=n();if(!(!c||c.length!==1))return c[0]}),ue.prop(s,"witness",()=>{if(e.witness)return e.witness;const c=i();if(c&&e.redeem&&e.redeem.output&&e.internalPubkey){const a=(0,ie.tapleafHash)({output:e.redeem.output,version:s.redeemVersion}),p=(0,ie.findScriptPath)(c,a);if(!p)return;const f=(0,ie.tweakKey)(e.internalPubkey,c.hash);if(!f)return;const u=Qt.Buffer.concat([Qt.Buffer.from([s.redeemVersion|f.parity]),e.internalPubkey].concat(p));return[e.redeem.output,u]}if(e.signature)return[e.signature]}),t.validate){let c=Qt.Buffer.from([]);if(e.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==di)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");c=r().data}if(e.pubkey){if(c.length>0&&!c.equals(e.pubkey))throw new TypeError("Pubkey mismatch");c=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==li.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(c.length>0&&!c.equals(e.output.slice(2)))throw new TypeError("Pubkey mismatch");c=e.output.slice(2)}if(e.internalPubkey){const f=(0,ie.tweakKey)(e.internalPubkey,s.hash);if(c.length>0&&!c.equals(f.x))throw new TypeError("Pubkey mismatch");c=f.x}if(c&&c.length&&!(0,hi.getEccLib)().isXOnlyPoint(c))throw new TypeError("Invalid pubkey for p2tr");const a=i();if(e.hash&&a&&!e.hash.equals(a.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&a){const f=(0,ie.tapleafHash)({output:e.redeem.output,version:s.redeemVersion});if(!(0,ie.findScriptPath)(a,f))throw new TypeError("Redeem script not in tree")}const p=n();if(e.redeem&&s.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==s.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(cn.decompile(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(s.redeem.output&&!e.redeem.output.equals(s.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&s.redeem.witness&&!ea(e.redeem.witness,s.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(p&&p.length)if(p.length===1){if(e.signature&&!e.signature.equals(p[0]))throw new TypeError("Signature mismatch")}else{const f=p[p.length-1];if(f.length<33)throw new TypeError("The control-block length is too small. Got ".concat(f.length,", expected min 33."));if((f.length-33)%32!==0)throw new TypeError("The control-block length of ".concat(f.length," is incorrect!"));const u=(f.length-33)/32;if(u>128)throw new TypeError("The script path is too long. Got ".concat(u,", expected max 128."));const d=f.slice(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(d))throw new TypeError("Internal pubkey mismatch");if(!(0,hi.getEccLib)().isXOnlyPoint(d))throw new TypeError("Invalid internalPubkey for p2tr witness");const l=f[0]&O.TAPLEAF_VERSION_MASK,b=p[p.length-2],g=(0,ie.tapleafHash)({output:b,version:l}),y=(0,ie.rootHashFromPath)(f,g),S=(0,ie.tweakKey)(d,y);if(!S)throw new TypeError("Invalid outputKey for p2tr witness");if(c.length&&!c.equals(S.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(S.parity!==(f[0]&1))throw new Error("Incorrect parity")}}return Object.assign(s,e)}Or.p2tr=Zc;function ea(e,t){return e.length!==t.length?!1:e.every((r,n)=>r.equals(t[n]))}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=wr;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=Sr;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=Er;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=_r;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const o=Tr;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return o.p2sh}});const s=kr;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return s.p2wpkh}});const c=Ir;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return c.p2wsh}});const a=Or;Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return a.p2tr}})})(Pt);Object.defineProperty(re,"__esModule",{value:!0});re.toOutputScript=re.fromOutputScript=re.toBech32=re.toBase58Check=re.fromBech32=re.fromBase58Check=void 0;const is=G,Ee=Pt,ss=ne,er=Y,vt=He,os=wn,cs=40,as=2,us=16,fs=2,ps=80,hs="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function ta(e,t){const r=e.slice(2);if(r.length<as||r.length>cs)throw new TypeError("Invalid program length for segwit address");const n=e[0]-ps;if(n<fs||n>us)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(hs),bs(r,n,t.bech32)}function ls(e){const t=h.from(os.decode(e));if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");const r=t.readUInt8(0),n=t.slice(1);return{version:r,hash:n}}re.fromBase58Check=ls;function ds(e){let t,r;try{t=vt.bech32.decode(e)}catch(i){}if(t){if(r=t.words[0],r!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=vt.bech32m.decode(e),r=t.words[0],r===0)throw new TypeError(e+" uses wrong encoding");const n=vt.bech32.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:h.from(n)}}re.fromBech32=ds;function ra(e,t){(0,er.typeforce)((0,er.tuple)(er.Hash160bit,er.UInt8),arguments);const r=h.allocUnsafe(21);return r.writeUInt8(t,0),e.copy(r,1),os.encode(r)}re.toBase58Check=ra;function bs(e,t,r){const n=vt.bech32.toWords(e);return n.unshift(t),t===0?vt.bech32.encode(r,n):vt.bech32m.encode(r,n)}re.toBech32=bs;function na(e,t){t=t||is.bitcoin;try{return Ee.p2pkh({output:e,network:t}).address}catch(r){}try{return Ee.p2sh({output:e,network:t}).address}catch(r){}try{return Ee.p2wpkh({output:e,network:t}).address}catch(r){}try{return Ee.p2wsh({output:e,network:t}).address}catch(r){}try{return Ee.p2tr({output:e,network:t}).address}catch(r){}try{return ta(e,t)}catch(r){}throw new Error(ss.toASM(e)+" has no matching Address")}re.fromOutputScript=na;function ia(e,t){t=t||is.bitcoin;let r,n;try{r=ls(e)}catch(i){}if(r){if(r.version===t.pubKeyHash)return Ee.p2pkh({hash:r.hash}).output;if(r.version===t.scriptHash)return Ee.p2sh({hash:r.hash}).output}else{try{n=ds(e)}catch(i){}if(n){if(n.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(n.version===0){if(n.data.length===20)return Ee.p2wpkh({hash:n.data}).output;if(n.data.length===32)return Ee.p2wsh({hash:n.data}).output}else if(n.version===1){if(n.data.length===32)return Ee.p2tr({pubkey:n.data}).output}else if(n.version>=fs&&n.version<=us&&n.data.length>=as&&n.data.length<=cs)return console.warn(hs),ss.compile([n.version+ps,n.data])}}throw new Error(e+" has no matching Script")}re.toOutputScript=ia;var Ar={},xr={};Object.defineProperty(xr,"__esModule",{value:!0});xr.fastMerkleRoot=void 0;function sa(e,t){if(!Array.isArray(e))throw TypeError("Expected values Array");if(typeof t!="function")throw TypeError("Expected digest Function");let r=e.length;const n=e.concat();for(;r>1;){let i=0;for(let o=0;o<r;o+=2,++i){const s=n[o],c=o+1===r?s:n[o+1],a=h.concat([s,c]);n[i]=t(a)}r=i}return n[0]}xr.fastMerkleRoot=sa;var Ve={};Object.defineProperty(Ve,"__esModule",{value:!0});Ve.Transaction=void 0;const L=D,Z=_e,bi=ne,oa=ne,A=Y,{typeforce:be}=A;function me(e){const t=e.length;return L.varuint.encodingLength(t)+t}function ca(e){const t=e.length;return L.varuint.encodingLength(t)+e.reduce((r,n)=>r+me(n),0)}const Fe=h.allocUnsafe(0),gi=[],Xr=h.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),yi=h.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),aa=h.from("ffffffffffffffff","hex"),ua={script:Fe,valueBuffer:aa};function fa(e){return e.value!==void 0}class I{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new L.BufferReader(t),i=new I;i.version=n.readInt32();const o=n.readUInt8(),s=n.readUInt8();let c=!1;o===I.ADVANCED_TRANSACTION_MARKER&&s===I.ADVANCED_TRANSACTION_FLAG?c=!0:n.offset-=2;const a=n.readVarInt();for(let f=0;f<a;++f)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:gi});const p=n.readVarInt();for(let f=0;f<p;++f)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(c){for(let f=0;f<a;++f)i.ins[f].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return I.fromBuffer(h.from(t,"hex"),!1)}static isCoinbaseHash(t){be(A.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&I.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return be(A.tuple(A.Hash256bit,A.UInt32,A.maybe(A.UInt32),A.maybe(A.Buffer)),arguments),A.Null(n)&&(n=I.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Fe,sequence:n,witness:gi})-1}addOutput(t,r){return be(A.tuple(A.Buffer,A.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+L.varuint.encodingLength(this.ins.length)+L.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+me(i.script),0)+this.outs.reduce((n,i)=>n+8+me(i.script),0)+(r?this.ins.reduce((n,i)=>n+ca(i.witness),0):0)}clone(){const t=new I;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(be(A.tuple(A.UInt32,A.Buffer,A.Number),arguments),t>=this.ins.length)return yi;const i=bi.compile(bi.decompile(r).filter(c=>c!==oa.OPS.OP_CODESEPARATOR)),o=this.clone();if((n&31)===I.SIGHASH_NONE)o.outs=[],o.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)});else if((n&31)===I.SIGHASH_SINGLE){if(t>=this.outs.length)return yi;o.outs.length=t+1;for(let c=0;c<t;c++)o.outs[c]=ua;o.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)})}n&I.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[t]],o.ins[0].script=i):(o.ins.forEach(c=>{c.script=Fe}),o.ins[t].script=i);const s=h.allocUnsafe(o.byteLength(!1)+4);return s.writeInt32LE(n,s.length-4),o.__toBuffer(s,0,!1),Z.hash256(s)}hashForWitnessV1(t,r,n,i,o,s){if(be(A.tuple(A.UInt32,be.arrayOf(A.Buffer),be.arrayOf(A.Satoshi),A.UInt32),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const c=i===I.SIGHASH_DEFAULT?I.SIGHASH_ALL:i&I.SIGHASH_OUTPUT_MASK,p=(i&I.SIGHASH_INPUT_MASK)===I.SIGHASH_ANYONECANPAY,f=c===I.SIGHASH_NONE,u=c===I.SIGHASH_SINGLE;let d=Fe,l=Fe,b=Fe,g=Fe,y=Fe;if(!p){let E=L.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(T=>{E.writeSlice(T.hash),E.writeUInt32(T.index)}),d=Z.sha256(E.end()),E=L.BufferWriter.withCapacity(8*this.ins.length),n.forEach(T=>E.writeUInt64(T)),l=Z.sha256(E.end()),E=L.BufferWriter.withCapacity(r.map(me).reduce((T,m)=>T+m)),r.forEach(T=>E.writeVarSlice(T)),b=Z.sha256(E.end()),E=L.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(T=>E.writeUInt32(T.sequence)),g=Z.sha256(E.end())}if(f||u){if(u&&t<this.outs.length){const E=this.outs[t],T=L.BufferWriter.withCapacity(8+me(E.script));T.writeUInt64(E.value),T.writeVarSlice(E.script),y=Z.sha256(T.end())}}else{const E=this.outs.map(m=>8+me(m.script)).reduce((m,C)=>m+C),T=L.BufferWriter.withCapacity(E);this.outs.forEach(m=>{T.writeUInt64(m.value),T.writeVarSlice(m.script)}),y=Z.sha256(T.end())}const S=(o?2:0)+(s?1:0),v=174-(p?49:0)-(f?32:0)+(s?32:0)+(o?37:0),_=L.BufferWriter.withCapacity(v);if(_.writeUInt8(i),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(d),_.writeSlice(l),_.writeSlice(b),_.writeSlice(g),f||u||_.writeSlice(y),_.writeUInt8(S),p){const E=this.ins[t];_.writeSlice(E.hash),_.writeUInt32(E.index),_.writeUInt64(n[t]),_.writeVarSlice(r[t]),_.writeUInt32(E.sequence)}else _.writeUInt32(t);if(s){const E=L.BufferWriter.withCapacity(me(s));E.writeVarSlice(s),_.writeSlice(Z.sha256(E.end()))}return u&&_.writeSlice(y),o&&(_.writeSlice(o),_.writeUInt8(0),_.writeUInt32(4294967295)),Z.taggedHash("TapSighash",h.concat([h.from([0]),_.end()]))}hashForWitnessV0(t,r,n,i){be(A.tuple(A.UInt32,A.Buffer,A.Satoshi,A.UInt32),arguments);let o=h.from([]),s,c=Xr,a=Xr,p=Xr;if(i&I.SIGHASH_ANYONECANPAY||(o=h.allocUnsafe(36*this.ins.length),s=new L.BufferWriter(o,0),this.ins.forEach(u=>{s.writeSlice(u.hash),s.writeUInt32(u.index)}),a=Z.hash256(o)),!(i&I.SIGHASH_ANYONECANPAY)&&(i&31)!==I.SIGHASH_SINGLE&&(i&31)!==I.SIGHASH_NONE&&(o=h.allocUnsafe(4*this.ins.length),s=new L.BufferWriter(o,0),this.ins.forEach(u=>{s.writeUInt32(u.sequence)}),p=Z.hash256(o)),(i&31)!==I.SIGHASH_SINGLE&&(i&31)!==I.SIGHASH_NONE){const u=this.outs.reduce((d,l)=>d+8+me(l.script),0);o=h.allocUnsafe(u),s=new L.BufferWriter(o,0),this.outs.forEach(d=>{s.writeUInt64(d.value),s.writeVarSlice(d.script)}),c=Z.hash256(o)}else if((i&31)===I.SIGHASH_SINGLE&&t<this.outs.length){const u=this.outs[t];o=h.allocUnsafe(8+me(u.script)),s=new L.BufferWriter(o,0),s.writeUInt64(u.value),s.writeVarSlice(u.script),c=Z.hash256(o)}o=h.allocUnsafe(156+me(r)),s=new L.BufferWriter(o,0);const f=this.ins[t];return s.writeInt32(this.version),s.writeSlice(a),s.writeSlice(p),s.writeSlice(f.hash),s.writeUInt32(f.index),s.writeVarSlice(r),s.writeUInt64(n),s.writeUInt32(f.sequence),s.writeSlice(c),s.writeUInt32(this.locktime),s.writeUInt32(i),Z.hash256(o)}getHash(t){return t&&this.isCoinbase()?h.alloc(32,0):Z.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,L.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(t,r){be(A.tuple(A.Number,A.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){be(A.tuple(A.Number,[A.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=h.allocUnsafe(this.byteLength(n)));const i=new L.BufferWriter(t,r||0);i.writeInt32(this.version);const o=n&&this.hasWitnesses();return o&&(i.writeUInt8(I.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(I.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(s=>{i.writeSlice(s.hash),i.writeUInt32(s.index),i.writeVarSlice(s.script),i.writeUInt32(s.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(s=>{fa(s)?i.writeUInt64(s.value):i.writeSlice(s.valueBuffer),i.writeVarSlice(s.script)}),o&&this.ins.forEach(s=>{i.writeVector(s.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}Ve.Transaction=I;I.DEFAULT_SEQUENCE=4294967295;I.SIGHASH_DEFAULT=0;I.SIGHASH_ALL=1;I.SIGHASH_NONE=2;I.SIGHASH_SINGLE=3;I.SIGHASH_ANYONECANPAY=128;I.SIGHASH_OUTPUT_MASK=3;I.SIGHASH_INPUT_MASK=128;I.ADVANCED_TRANSACTION_MARKER=0;I.ADVANCED_TRANSACTION_FLAG=1;Object.defineProperty(Ar,"__esModule",{value:!0});Ar.Block=void 0;const Xe=D,qr=_e,pa=xr,ha=Ve,gs=Y,{typeforce:la}=gs,zr=new TypeError("Cannot compute merkle root for zero transactions"),mi=new TypeError("Cannot compute witness commit for non-segwit block");class qe{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(t){if(t.length<80)throw new Error("Buffer too small (< 80 bytes)");const r=new Xe.BufferReader(t),n=new qe;if(n.version=r.readInt32(),n.prevHash=r.readSlice(32),n.merkleRoot=r.readSlice(32),n.timestamp=r.readUInt32(),n.bits=r.readUInt32(),n.nonce=r.readUInt32(),t.length===80)return n;const i=()=>{const c=ha.Transaction.fromBuffer(r.buffer.slice(r.offset),!0);return r.offset+=c.byteLength(),c},o=r.readVarInt();n.transactions=[];for(let c=0;c<o;++c){const a=i();n.transactions.push(a)}const s=n.getWitnessCommit();return s&&(n.witnessCommit=s),n}static fromHex(t){return qe.fromBuffer(h.from(t,"hex"))}static calculateTarget(t){const r=((t&4278190080)>>24)-3,n=t&8388607,i=h.alloc(32,0);return i.writeUIntBE(n,29-r,3),i}static calculateMerkleRoot(t,r){if(la([{getHash:gs.Function}],t),t.length===0)throw zr;if(r&&!wi(t))throw mi;const n=t.map(o=>o.getHash(r)),i=(0,pa.fastMerkleRoot)(n,qr.hash256);return r?qr.hash256(h.concat([i,t[0].ins[0].witness[0]])):i}getWitnessCommit(){if(!wi(this.transactions))return null;const t=this.transactions[0].outs.filter(n=>n.script.slice(0,6).equals(h.from("6a24aa21a9ed","hex"))).map(n=>n.script.slice(6,38));if(t.length===0)return null;const r=t[t.length-1];return r instanceof h&&r.length===32?r:null}hasWitnessCommit(){return this.witnessCommit instanceof h&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return da(this.transactions)}weight(){const t=this.byteLength(!1,!1),r=this.byteLength(!1,!0);return t*3+r}byteLength(t,r=!0){return t||!this.transactions?80:80+Xe.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((n,i)=>n+i.byteLength(r),0)}getHash(){return qr.hash256(this.toBuffer(!0))}getId(){return(0,Xe.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const t=new Date(0);return t.setUTCSeconds(this.timestamp),t}toBuffer(t){const r=h.allocUnsafe(this.byteLength(t)),n=new Xe.BufferWriter(r);return n.writeInt32(this.version),n.writeSlice(this.prevHash),n.writeSlice(this.merkleRoot),n.writeUInt32(this.timestamp),n.writeUInt32(this.bits),n.writeUInt32(this.nonce),t||!this.transactions||(Xe.varuint.encode(this.transactions.length,r,n.offset),n.offset+=Xe.varuint.encode.bytes,this.transactions.forEach(i=>{const o=i.byteLength();i.toBuffer(r,n.offset),n.offset+=o})),r}toHex(t){return this.toBuffer(t).toString("hex")}checkTxRoots(){const t=this.hasWitnessCommit();return!t&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(t?this.__checkWitnessCommit():!0)}checkProofOfWork(){const t=(0,Xe.reverseBuffer)(this.getHash()),r=qe.calculateTarget(this.bits);return t.compare(r)<=0}__checkMerkleRoot(){if(!this.transactions)throw zr;const t=qe.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(t)===0}__checkWitnessCommit(){if(!this.transactions)throw zr;if(!this.hasWitnessCommit())throw mi;const t=qe.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(t)===0}}Ar.Block=qe;function wi(e){return e instanceof Array&&e[0]&&e[0].ins&&e[0].ins instanceof Array&&e[0].ins[0]&&e[0].ins[0].witness&&e[0].ins[0].witness instanceof Array&&e[0].ins[0].witness.length>0}function da(e){return e instanceof Array&&e.some(t=>typeof t=="object"&&t.ins instanceof Array&&t.ins.some(r=>typeof r=="object"&&r.witness instanceof Array&&r.witness.length>0))}var Nr={},vn={},Tn={},kn={},Wt={},Je={},j={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"}(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"}(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"}(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(j);var Qe={};Object.defineProperty(Qe,"__esModule",{value:!0});const ys=j,ba=e=>[...Array(e).keys()];function ga(e){if(e.key[0]!==ys.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+e.key.toString("hex"));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),r={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const n of ba(e.value.length/4-1)){const i=e.value.readUInt32LE(n*4+4),o=!!(i&2147483648),s=i&2147483647;r.path+="/"+s.toString(10)+(o?"'":"")}return r}Qe.decode=ga;function ya(e){const t=h.from([ys.GlobalTypes.GLOBAL_XPUB]),r=h.concat([t,e.extendedPubkey]),n=e.path.split("/"),i=h.allocUnsafe(n.length*4);e.masterFingerprint.copy(i,0);let o=4;return n.slice(1).forEach(s=>{const c=s.slice(-1)==="'";let a=2147483647&parseInt(c?s.slice(0,-1):s,10);c&&(a+=2147483648),i.writeUInt32LE(a,o),o+=4}),{key:r,value:i}}Qe.encode=ya;Qe.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function ma(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return h.isBuffer(t)&&t.length===78&&[2,3].indexOf(t[45])>-1&&h.isBuffer(r)&&r.length===4&&typeof n=="string"&&!!n.match(/^m(\/\d+'?)*$/)}Qe.check=ma;function wa(e,t,r){const n=t.extendedPubkey.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.extendedPubkey.equals(t.extendedPubkey)).length===0)}Qe.canAddToArray=wa;var In={};Object.defineProperty(In,"__esModule",{value:!0});const Sa=j;function Ea(e){return{key:h.from([Sa.GlobalTypes.UNSIGNED_TX]),value:e.toBuffer()}}In.encode=Ea;var Ze={};Object.defineProperty(Ze,"__esModule",{value:!0});const ms=j;function _a(e){if(e.key[0]!==ms.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+e.key.toString("hex"));return e.value}Ze.decode=_a;function va(e){return{key:h.from([ms.InputTypes.FINAL_SCRIPTSIG]),value:e}}Ze.encode=va;Ze.expected="Buffer";function Ta(e){return h.isBuffer(e)}Ze.check=Ta;function ka(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}Ze.canAdd=ka;var et={};Object.defineProperty(et,"__esModule",{value:!0});const ws=j;function Ia(e){if(e.key[0]!==ws.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+e.key.toString("hex"));return e.value}et.decode=Ia;function Oa(e){return{key:h.from([ws.InputTypes.FINAL_SCRIPTWITNESS]),value:e}}et.encode=Oa;et.expected="Buffer";function Pa(e){return h.isBuffer(e)}et.check=Pa;function Aa(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}et.canAdd=Aa;var tt={};Object.defineProperty(tt,"__esModule",{value:!0});const Ss=j;function xa(e){if(e.key[0]!==Ss.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+e.key.toString("hex"));return e.value}tt.decode=xa;function Na(e){return{key:h.from([Ss.InputTypes.NON_WITNESS_UTXO]),value:e}}tt.encode=Na;tt.expected="Buffer";function Ba(e){return h.isBuffer(e)}tt.check=Ba;function Ua(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}tt.canAdd=Ua;var rt={};Object.defineProperty(rt,"__esModule",{value:!0});const Es=j;function Ha(e){if(e.key[0]!==Es.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+e.key.toString("hex"));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1),signature:e.value}}rt.decode=Ha;function Ca(e){const t=h.from([Es.InputTypes.PARTIAL_SIG]);return{key:h.concat([t,e.pubkey]),value:e.signature}}rt.encode=Ca;rt.expected="{ pubkey: Buffer; signature: Buffer; }";function Ra(e){return h.isBuffer(e.pubkey)&&h.isBuffer(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&$a(e.signature)}rt.check=Ra;function $a(e){if(!h.isBuffer(e)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}function La(e,t,r){const n=t.pubkey.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.pubkey.equals(t.pubkey)).length===0)}rt.canAddToArray=La;var nt={};Object.defineProperty(nt,"__esModule",{value:!0});const _s=j;function Fa(e){if(e.key[0]!==_s.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+e.key.toString("hex"));return e.value.toString("utf8")}nt.decode=Fa;function Ma(e){return{key:h.from([_s.InputTypes.POR_COMMITMENT]),value:h.from(e,"utf8")}}nt.encode=Ma;nt.expected="string";function Ka(e){return typeof e=="string"}nt.check=Ka;function Da(e,t){return!!e&&!!t&&e.porCommitment===void 0}nt.canAdd=Da;var it={};Object.defineProperty(it,"__esModule",{value:!0});const vs=j;function Ga(e){if(e.key[0]!==vs.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+e.key.toString("hex"));return e.value.readUInt32LE(0)}it.decode=Ga;function ja(e){const t=h.from([vs.InputTypes.SIGHASH_TYPE]),r=h.allocUnsafe(4);return r.writeUInt32LE(e,0),{key:t,value:r}}it.encode=ja;it.expected="number";function Wa(e){return typeof e=="number"}it.check=Wa;function Va(e,t){return!!e&&!!t&&e.sighashType===void 0}it.canAdd=Va;var st={};Object.defineProperty(st,"__esModule",{value:!0});const Ts=j;function Xa(e){if(e.key[0]!==Ts.InputTypes.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+e.key.toString("hex"));if(!ks(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}st.decode=Xa;function qa(e){return{key:h.from([Ts.InputTypes.TAP_KEY_SIG]),value:e}}st.encode=qa;st.expected="Buffer";function ks(e){return h.isBuffer(e)&&(e.length===64||e.length===65)}st.check=ks;function za(e,t){return!!e&&!!t&&e.tapKeySig===void 0}st.canAdd=za;var ot={};Object.defineProperty(ot,"__esModule",{value:!0});const Is=j;function Ya(e){if(e.key[0]!==Is.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+e.key.toString("hex"));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+e.key.toString("hex"));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+e.key.toString("hex"));const r=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:r,leafVersion:t}}ot.decode=Ya;function Ja(e){const t=h.from([Is.InputTypes.TAP_LEAF_SCRIPT]),r=h.from([e.leafVersion]);return{key:h.concat([t,e.controlBlock]),value:h.concat([e.script,r])}}ot.encode=Ja;ot.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function Qa(e){return h.isBuffer(e.controlBlock)&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&h.isBuffer(e.script)}ot.check=Qa;function Za(e,t,r){const n=t.controlBlock.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.controlBlock.equals(t.controlBlock)).length===0)}ot.canAddToArray=Za;var ct={};Object.defineProperty(ct,"__esModule",{value:!0});const Os=j;function eu(e){if(e.key[0]!==Os.InputTypes.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+e.key.toString("hex"));if(!Ps(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}ct.decode=eu;function tu(e){return{key:h.from([Os.InputTypes.TAP_MERKLE_ROOT]),value:e}}ct.encode=tu;ct.expected="Buffer";function Ps(e){return h.isBuffer(e)&&e.length===32}ct.check=Ps;function ru(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}ct.canAdd=ru;var at={};Object.defineProperty(at,"__esModule",{value:!0});const As=j;function nu(e){if(e.key[0]!==As.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+e.key.toString("hex"));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+e.key.toString("hex"));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+e.key.toString("hex"));const t=e.key.slice(1,33),r=e.key.slice(33);return{pubkey:t,leafHash:r,signature:e.value}}at.decode=nu;function iu(e){const t=h.from([As.InputTypes.TAP_SCRIPT_SIG]);return{key:h.concat([t,e.pubkey,e.leafHash]),value:e.signature}}at.encode=iu;at.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function su(e){return h.isBuffer(e.pubkey)&&h.isBuffer(e.leafHash)&&h.isBuffer(e.signature)&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}at.check=su;function ou(e,t,r){const n=t.pubkey.toString("hex")+t.leafHash.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.pubkey.equals(t.pubkey)&&i.leafHash.equals(t.leafHash)).length===0)}at.canAddToArray=ou;var ut={},ve={},le={};Object.defineProperty(le,"__esModule",{value:!0});const cu=9007199254740991;function On(e){if(e<0||e>cu||e%1!==0)throw new RangeError("value out of range")}function Lt(e,t,r){if(On(e),t||(t=h.allocUnsafe(xs(e))),!h.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(Lt,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(Lt,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(Lt,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(Lt,{bytes:9})),t}le.encode=Lt;function Ft(e,t){if(!h.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);const r=e.readUInt8(t);if(r<253)return Object.assign(Ft,{bytes:1}),r;if(r===253)return Object.assign(Ft,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(Ft,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(Ft,{bytes:9});const n=e.readUInt32LE(t+1),o=e.readUInt32LE(t+5)*4294967296+n;return On(o),o}}le.decode=Ft;function xs(e){return On(e),e<253?1:e<=65535?3:e<=4294967295?5:9}le.encodingLength=xs;Object.defineProperty(ve,"__esModule",{value:!0});const tr=le;ve.range=e=>[...Array(e).keys()];function au(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}ve.reverseBuffer=au;function uu(e){const t=e.map(Ns);return t.push(h.from([0])),h.concat(t)}ve.keyValsToBuffer=uu;function Ns(e){const t=e.key.length,r=e.value.length,n=tr.encodingLength(t),i=tr.encodingLength(r),o=h.allocUnsafe(n+t+i+r);return tr.encode(t,o,0),e.key.copy(o,n),tr.encode(r,o,n+t),e.value.copy(o,n+t+i),o}ve.keyValToBuffer=Ns;function Bs(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function fu(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Bs(n+r,9007199254740991),n+r}ve.readUInt64LE=fu;function pu(e,t,r){return Bs(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}ve.writeUInt64LE=pu;Object.defineProperty(ut,"__esModule",{value:!0});const Us=j,Hs=ve,dr=le;function hu(e){if(e.key[0]!==Us.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+e.key.toString("hex"));const t=Hs.readUInt64LE(e.value,0);let r=8;const n=dr.decode(e.value,r);r+=dr.encodingLength(n);const i=e.value.slice(r);if(i.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:i,value:t}}ut.decode=hu;function lu(e){const{script:t,value:r}=e,n=dr.encodingLength(t.length),i=h.allocUnsafe(8+n+t.length);return Hs.writeUInt64LE(i,r,0),dr.encode(t.length,i,8),t.copy(i,8+n),{key:h.from([Us.InputTypes.WITNESS_UTXO]),value:i}}ut.encode=lu;ut.expected="{ script: Buffer; value: number; }";function du(e){return h.isBuffer(e.script)&&typeof e.value=="number"}ut.check=du;function bu(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}ut.canAdd=bu;var ft={};Object.defineProperty(ft,"__esModule",{value:!0});const Cs=j,an=le;function gu(e){if(e.key[0]!==Cs.OutputTypes.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+e.key.toString("hex"));let t=0;const r=[];for(;t<e.value.length;){const n=e.value[t++],i=e.value[t++],o=an.decode(e.value,t);t+=an.encodingLength(o),r.push({depth:n,leafVersion:i,script:e.value.slice(t,t+o)}),t+=o}return{leaves:r}}ft.decode=gu;function yu(e){const t=h.from([Cs.OutputTypes.TAP_TREE]),r=[].concat(...e.leaves.map(n=>[h.of(n.depth,n.leafVersion),an.encode(n.script.length),n.script]));return{key:t,value:h.concat(r)}}ft.encode=yu;ft.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function mu(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&h.isBuffer(t.script))}ft.check=mu;function wu(e,t){return!!e&&!!t&&e.tapTree===void 0}ft.canAdd=wu;var Br={};Object.defineProperty(Br,"__esModule",{value:!0});const Su=e=>[...Array(e).keys()],Eu=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function _u(e,t=Eu){function r(c){if(c.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+c.key.toString("hex"));const a=c.key.slice(1);if(!t(a))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+c.key.toString("hex"));if(c.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const p={masterFingerprint:c.value.slice(0,4),pubkey:a,path:"m"};for(const f of Su(c.value.length/4-1)){const u=c.value.readUInt32LE(f*4+4),d=!!(u&2147483648),l=u&2147483647;p.path+="/"+l.toString(10)+(d?"'":"")}return p}function n(c){const a=h.from([e]),p=h.concat([a,c.pubkey]),f=c.path.split("/"),u=h.allocUnsafe(f.length*4);c.masterFingerprint.copy(u,0);let d=4;return f.slice(1).forEach(l=>{const b=l.slice(-1)==="'";let g=2147483647&parseInt(b?l.slice(0,-1):l,10);b&&(g+=2147483648),u.writeUInt32LE(g,d),d+=4}),{key:p,value:u}}const i="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function o(c){return h.isBuffer(c.pubkey)&&h.isBuffer(c.masterFingerprint)&&typeof c.path=="string"&&t(c.pubkey)&&c.masterFingerprint.length===4}function s(c,a,p){const f=a.pubkey.toString("hex");return p.has(f)?!1:(p.add(f),c.filter(u=>u.pubkey.equals(a.pubkey)).length===0)}return{decode:r,encode:n,check:o,expected:i,canAddToArray:s}}Br.makeConverter=_u;var Pn={};Object.defineProperty(Pn,"__esModule",{value:!0});function vu(e){return t;function t(r){let n;if(e.includes(r.key[0])&&(n=r.key.slice(1),!(n.length===33||n.length===65)||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return n}}Pn.makeChecker=vu;var An={};Object.defineProperty(An,"__esModule",{value:!0});function Tu(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+s.key.toString("hex"));return s.value}function r(s){return{key:h.from([e]),value:s}}const n="Buffer";function i(s){return h.isBuffer(s)}function o(s,c){return!!s&&!!c&&s.redeemScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}An.makeConverter=Tu;var xn={};Object.defineProperty(xn,"__esModule",{value:!0});const rr=le,ku=Br,Iu=e=>e.length===32;function Ou(e){const t=ku.makeConverter(e,Iu);function r(s){const c=rr.decode(s.value),a=rr.encodingLength(c),p=t.decode({key:s.key,value:s.value.slice(a+c*32)}),f=new Array(c);for(let u=0,d=a;u<c;u++,d+=32)f[u]=s.value.slice(d,d+32);return Object.assign({},p,{leafHashes:f})}function n(s){const c=t.encode(s),a=rr.encodingLength(s.leafHashes.length),p=h.allocUnsafe(a);rr.encode(s.leafHashes.length,p);const f=h.concat([p,...s.leafHashes,c.value]);return Object.assign({},c,{value:f})}const i="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function o(s){return Array.isArray(s.leafHashes)&&s.leafHashes.every(c=>h.isBuffer(c)&&c.length===32)&&t.check(s)}return{decode:r,encode:n,check:o,expected:i,canAddToArray:t.canAddToArray}}xn.makeConverter=Ou;var Nn={};Object.defineProperty(Nn,"__esModule",{value:!0});function Pu(e){function t(s){if(s.key[0]!==e||s.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+s.key.toString("hex"));if(s.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return s.value}function r(s){return{key:h.from([e]),value:s}}const n="Buffer";function i(s){return h.isBuffer(s)&&s.length===32}function o(s,c){return!!s&&!!c&&s.tapInternalKey===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}Nn.makeConverter=Pu;var Bn={};Object.defineProperty(Bn,"__esModule",{value:!0});function Au(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+s.key.toString("hex"));return s.value}function r(s){return{key:h.from([e]),value:s}}const n="Buffer";function i(s){return h.isBuffer(s)}function o(s,c){return!!s&&!!c&&s.witnessScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}Bn.makeConverter=Au;Object.defineProperty(Je,"__esModule",{value:!0});const oe=j,xu=Qe,Nu=In,Bu=Ze,Uu=et,Hu=tt,Cu=rt,Ru=nt,$u=it,Lu=st,Fu=ot,Mu=ct,Ku=at,Du=ut,Gu=ft,Rs=Br,Un=Pn,$s=An,Ls=xn,Fs=Nn,Ms=Bn,ju={unsignedTx:Nu,globalXpub:xu,checkPubkey:Un.makeChecker([])};Je.globals=ju;const Wu={nonWitnessUtxo:Hu,partialSig:Cu,sighashType:$u,finalScriptSig:Bu,finalScriptWitness:Uu,porCommitment:Ru,witnessUtxo:Du,bip32Derivation:Rs.makeConverter(oe.InputTypes.BIP32_DERIVATION),redeemScript:$s.makeConverter(oe.InputTypes.REDEEM_SCRIPT),witnessScript:Ms.makeConverter(oe.InputTypes.WITNESS_SCRIPT),checkPubkey:Un.makeChecker([oe.InputTypes.PARTIAL_SIG,oe.InputTypes.BIP32_DERIVATION]),tapKeySig:Lu,tapScriptSig:Ku,tapLeafScript:Fu,tapBip32Derivation:Ls.makeConverter(oe.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:Fs.makeConverter(oe.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:Mu};Je.inputs=Wu;const Vu={bip32Derivation:Rs.makeConverter(oe.OutputTypes.BIP32_DERIVATION),redeemScript:$s.makeConverter(oe.OutputTypes.REDEEM_SCRIPT),witnessScript:Ms.makeConverter(oe.OutputTypes.WITNESS_SCRIPT),checkPubkey:Un.makeChecker([oe.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:Ls.makeConverter(oe.OutputTypes.TAP_BIP32_DERIVATION),tapTree:Gu,tapInternalKey:Fs.makeConverter(oe.OutputTypes.TAP_INTERNAL_KEY)};Je.outputs=Vu;Object.defineProperty(Wt,"__esModule",{value:!0});const N=Je,br=ve,Si=le,k=j;function Xu(e,t){let r=0;function n(){const y=Si.decode(e,r);r+=Si.encodingLength(y);const S=e.slice(r,r+y);return r+=y,S}function i(){const y=e.readUInt32BE(r);return r+=4,y}function o(){const y=e.readUInt8(r);return r+=1,y}function s(){const y=n(),S=n();return{key:y,value:S}}function c(){if(r>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const y=e.readUInt8(r)===0;return y&&r++,y}if(i()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(o()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const a=[],p={};for(;!c();){const y=s(),S=y.key.toString("hex");if(p[S])throw new Error("Format Error: Keys must be unique for global keymap: key "+S);p[S]=1,a.push(y)}const f=a.filter(y=>y.key[0]===k.GlobalTypes.UNSIGNED_TX);if(f.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const u=t(f[0].value),{inputCount:d,outputCount:l}=u.getInputOutputCounts(),b=[],g=[];for(const y of br.range(d)){const S={},v=[];for(;!c();){const _=s(),E=_.key.toString("hex");if(S[E])throw new Error("Format Error: Keys must be unique for each input: input index "+y+" key "+E);S[E]=1,v.push(_)}b.push(v)}for(const y of br.range(l)){const S={},v=[];for(;!c();){const _=s(),E=_.key.toString("hex");if(S[E])throw new Error("Format Error: Keys must be unique for each output: output index "+y+" key "+E);S[E]=1,v.push(_)}g.push(v)}return Ks(u,{globalMapKeyVals:a,inputKeyVals:b,outputKeyVals:g})}Wt.psbtFromBuffer=Xu;function X(e,t,r){if(!t.equals(h.from([r])))throw new Error("Format Error: Invalid ".concat(e," key: ").concat(t.toString("hex")))}Wt.checkKeyBuffer=X;function Ks(e,{globalMapKeyVals:t,inputKeyVals:r,outputKeyVals:n}){const i={unsignedTx:e};let o=0;for(const f of t)switch(f.key[0]){case k.GlobalTypes.UNSIGNED_TX:if(X("global",f.key,k.GlobalTypes.UNSIGNED_TX),o>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");o++;break;case k.GlobalTypes.GLOBAL_XPUB:i.globalXpub===void 0&&(i.globalXpub=[]),i.globalXpub.push(N.globals.globalXpub.decode(f));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(f)}const s=r.length,c=n.length,a=[],p=[];for(const f of br.range(s)){const u={};for(const d of r[f])switch(N.inputs.checkPubkey(d),d.key[0]){case k.InputTypes.NON_WITNESS_UTXO:if(X("input",d.key,k.InputTypes.NON_WITNESS_UTXO),u.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");u.nonWitnessUtxo=N.inputs.nonWitnessUtxo.decode(d);break;case k.InputTypes.WITNESS_UTXO:if(X("input",d.key,k.InputTypes.WITNESS_UTXO),u.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");u.witnessUtxo=N.inputs.witnessUtxo.decode(d);break;case k.InputTypes.PARTIAL_SIG:u.partialSig===void 0&&(u.partialSig=[]),u.partialSig.push(N.inputs.partialSig.decode(d));break;case k.InputTypes.SIGHASH_TYPE:if(X("input",d.key,k.InputTypes.SIGHASH_TYPE),u.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");u.sighashType=N.inputs.sighashType.decode(d);break;case k.InputTypes.REDEEM_SCRIPT:if(X("input",d.key,k.InputTypes.REDEEM_SCRIPT),u.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");u.redeemScript=N.inputs.redeemScript.decode(d);break;case k.InputTypes.WITNESS_SCRIPT:if(X("input",d.key,k.InputTypes.WITNESS_SCRIPT),u.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");u.witnessScript=N.inputs.witnessScript.decode(d);break;case k.InputTypes.BIP32_DERIVATION:u.bip32Derivation===void 0&&(u.bip32Derivation=[]),u.bip32Derivation.push(N.inputs.bip32Derivation.decode(d));break;case k.InputTypes.FINAL_SCRIPTSIG:X("input",d.key,k.InputTypes.FINAL_SCRIPTSIG),u.finalScriptSig=N.inputs.finalScriptSig.decode(d);break;case k.InputTypes.FINAL_SCRIPTWITNESS:X("input",d.key,k.InputTypes.FINAL_SCRIPTWITNESS),u.finalScriptWitness=N.inputs.finalScriptWitness.decode(d);break;case k.InputTypes.POR_COMMITMENT:X("input",d.key,k.InputTypes.POR_COMMITMENT),u.porCommitment=N.inputs.porCommitment.decode(d);break;case k.InputTypes.TAP_KEY_SIG:X("input",d.key,k.InputTypes.TAP_KEY_SIG),u.tapKeySig=N.inputs.tapKeySig.decode(d);break;case k.InputTypes.TAP_SCRIPT_SIG:u.tapScriptSig===void 0&&(u.tapScriptSig=[]),u.tapScriptSig.push(N.inputs.tapScriptSig.decode(d));break;case k.InputTypes.TAP_LEAF_SCRIPT:u.tapLeafScript===void 0&&(u.tapLeafScript=[]),u.tapLeafScript.push(N.inputs.tapLeafScript.decode(d));break;case k.InputTypes.TAP_BIP32_DERIVATION:u.tapBip32Derivation===void 0&&(u.tapBip32Derivation=[]),u.tapBip32Derivation.push(N.inputs.tapBip32Derivation.decode(d));break;case k.InputTypes.TAP_INTERNAL_KEY:X("input",d.key,k.InputTypes.TAP_INTERNAL_KEY),u.tapInternalKey=N.inputs.tapInternalKey.decode(d);break;case k.InputTypes.TAP_MERKLE_ROOT:X("input",d.key,k.InputTypes.TAP_MERKLE_ROOT),u.tapMerkleRoot=N.inputs.tapMerkleRoot.decode(d);break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(d)}a.push(u)}for(const f of br.range(c)){const u={};for(const d of n[f])switch(N.outputs.checkPubkey(d),d.key[0]){case k.OutputTypes.REDEEM_SCRIPT:if(X("output",d.key,k.OutputTypes.REDEEM_SCRIPT),u.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");u.redeemScript=N.outputs.redeemScript.decode(d);break;case k.OutputTypes.WITNESS_SCRIPT:if(X("output",d.key,k.OutputTypes.WITNESS_SCRIPT),u.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");u.witnessScript=N.outputs.witnessScript.decode(d);break;case k.OutputTypes.BIP32_DERIVATION:u.bip32Derivation===void 0&&(u.bip32Derivation=[]),u.bip32Derivation.push(N.outputs.bip32Derivation.decode(d));break;case k.OutputTypes.TAP_INTERNAL_KEY:X("output",d.key,k.OutputTypes.TAP_INTERNAL_KEY),u.tapInternalKey=N.outputs.tapInternalKey.decode(d);break;case k.OutputTypes.TAP_TREE:X("output",d.key,k.OutputTypes.TAP_TREE),u.tapTree=N.outputs.tapTree.decode(d);break;case k.OutputTypes.TAP_BIP32_DERIVATION:u.tapBip32Derivation===void 0&&(u.tapBip32Derivation=[]),u.tapBip32Derivation.push(N.outputs.tapBip32Derivation.decode(d));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(d)}p.push(u)}return{globalMap:i,inputs:a,outputs:p}}Wt.psbtFromKeyVals=Ks;var Ur={};Object.defineProperty(Ur,"__esModule",{value:!0});const Yr=Je,Ei=ve;function qu({globalMap:e,inputs:t,outputs:r}){const{globalKeyVals:n,inputKeyVals:i,outputKeyVals:o}=Ds({globalMap:e,inputs:t,outputs:r}),s=Ei.keyValsToBuffer(n),c=u=>u.length===0?[h.from([0])]:u.map(Ei.keyValsToBuffer),a=c(i),p=c(o),f=h.allocUnsafe(5);return f.writeUIntBE(482972169471,0,5),h.concat([f,s].concat(a,p))}Ur.psbtToBuffer=qu;const zu=(e,t)=>e.key.compare(t.key);function Jr(e,t){const r=new Set,n=Object.entries(e).reduce((o,[s,c])=>{if(s==="unknownKeyVals")return o;const a=t[s];if(a===void 0)return o;const p=(Array.isArray(c)?c:[c]).map(a.encode);return p.map(u=>u.key.toString("hex")).forEach(u=>{if(r.has(u))throw new Error("Serialize Error: Duplicate key: "+u);r.add(u)}),o.concat(p)},[]),i=e.unknownKeyVals?e.unknownKeyVals.filter(o=>!r.has(o.key.toString("hex"))):[];return n.concat(i).sort(zu)}function Ds({globalMap:e,inputs:t,outputs:r}){return{globalKeyVals:Jr(e,Yr.globals),inputKeyVals:t.map(n=>Jr(n,Yr.inputs)),outputKeyVals:r.map(n=>Jr(n,Yr.outputs))}}Ur.psbtToKeyVals=Ds;(function(e){function t(r){for(var n in r)e.hasOwnProperty(n)||(e[n]=r[n])}Object.defineProperty(e,"__esModule",{value:!0}),t(Wt),t(Ur)})(kn);Object.defineProperty(Tn,"__esModule",{value:!0});const Qr=kn;function Yu(e){const t=e[0],r=Qr.psbtToKeyVals(t),n=e.slice(1);if(n.length===0)throw new Error("Combine: Nothing to combine");const i=_i(t);if(i===void 0)throw new Error("Combine: Self missing transaction");const o=bt(r.globalKeyVals),s=r.inputKeyVals.map(bt),c=r.outputKeyVals.map(bt);for(const a of n){const p=_i(a);if(p===void 0||!p.toBuffer().equals(i.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const f=Qr.psbtToKeyVals(a);bt(f.globalKeyVals).forEach(Zr(o,r.globalKeyVals,f.globalKeyVals)),f.inputKeyVals.map(bt).forEach((b,g)=>b.forEach(Zr(s[g],r.inputKeyVals[g],f.inputKeyVals[g]))),f.outputKeyVals.map(bt).forEach((b,g)=>b.forEach(Zr(c[g],r.outputKeyVals[g],f.outputKeyVals[g])))}return Qr.psbtFromKeyVals(i,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}Tn.combine=Yu;function Zr(e,t,r){return n=>{if(e.has(n))return;const i=r.filter(o=>o.key.toString("hex")===n)[0];t.push(i),e.add(n)}}function _i(e){return e.globalMap.unsignedTx}function bt(e){const t=new Set;return e.forEach(r=>{const n=r.key.toString("hex");if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)}),t}var Hn={};(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=Je;function r(l,b){const g=l[b];if(g===void 0)throw new Error("No input #".concat(b));return g}e.checkForInput=r;function n(l,b){const g=l[b];if(g===void 0)throw new Error("No output #".concat(b));return g}e.checkForOutput=n;function i(l,b,g){if(l.key[0]<g)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(b&&b.filter(y=>y.key.equals(l.key)).length!==0)throw new Error("Duplicate Key: ".concat(l.key.toString("hex")))}e.checkHasKey=i;function o(l){let b=0;return Object.keys(l).forEach(g=>{Number(isNaN(Number(g)))&&b++}),b}e.getEnumLength=o;function s(l,b){let g=!1;if(b.nonWitnessUtxo||b.witnessUtxo){const y=!!b.redeemScript,S=!!b.witnessScript,v=!y||!!b.finalScriptSig,_=!S||!!b.finalScriptWitness,E=!!b.finalScriptSig||!!b.finalScriptWitness;g=v&&_&&E}if(g===!1)throw new Error("Input #".concat(l," has too much or too little data to clean"))}e.inputCheckUncleanFinalized=s;function c(l,b,g,y){throw new Error("Data for ".concat(l," key ").concat(b," is incorrect: Expected ")+"".concat(g," and got ").concat(JSON.stringify(y)))}function a(l){return(b,g)=>{for(const y of Object.keys(b)){const S=b[y],{canAdd:v,canAddToArray:_,check:E,expected:T}=t[l+"s"][y]||{},m=!!_;if(E)if(m){if(!Array.isArray(S)||g[y]&&!Array.isArray(g[y]))throw new Error("Key type ".concat(y," must be an array"));S.every(E)||c(l,y,T,S);const C=g[y]||[],W=new Set;if(!S.every(w=>_(C,w,W)))throw new Error("Can not add duplicate data to array");g[y]=C.concat(S)}else{if(E(S)||c(l,y,T,S),!v(g,S))throw new Error("Can not add duplicate data to ".concat(l));g[y]=S}}}}e.updateGlobal=a("global"),e.updateInput=a("input"),e.updateOutput=a("output");function p(l,b){const g=l.length-1,y=r(l,g);e.updateInput(b,y)}e.addInputAttributes=p;function f(l,b){const g=l.length-1,y=n(l,g);e.updateOutput(b,y)}e.addOutputAttributes=f;function u(l,b){if(!h.isBuffer(b)||b.length<4)throw new Error("Set Version: Invalid Transaction");return b.writeUInt32LE(l,0),b}e.defaultVersionSetter=u;function d(l,b){if(!h.isBuffer(b)||b.length<4)throw new Error("Set Locktime: Invalid Transaction");return b.writeUInt32LE(l,b.length-4),b}e.defaultLocktimeSetter=d})(Hn);Object.defineProperty(vn,"__esModule",{value:!0});const Ju=Tn,vi=kn,en=j,V=Hn;let Qu=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,r){const n=h.from(t,"base64");return this.fromBuffer(n,r)}static fromHex(t,r){const n=h.from(t,"hex");return this.fromBuffer(n,r)}static fromBuffer(t,r){const n=vi.psbtFromBuffer(t,r),i=new this(n.globalMap.unsignedTx);return Object.assign(i,n),i}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return vi.psbtToBuffer(this)}updateGlobal(t){return V.updateGlobal(t,this.globalMap),this}updateInput(t,r){const n=V.checkForInput(this.inputs,t);return V.updateInput(r,n),this}updateOutput(t,r){const n=V.checkForOutput(this.outputs,t);return V.updateOutput(r,n),this}addUnknownKeyValToGlobal(t){return V.checkHasKey(t,this.globalMap.unknownKeyVals,V.getEnumLength(en.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,r){const n=V.checkForInput(this.inputs,t);return V.checkHasKey(r,n.unknownKeyVals,V.getEnumLength(en.InputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addUnknownKeyValToOutput(t,r){const n=V.checkForOutput(this.outputs,t);return V.checkHasKey(r,n.unknownKeyVals,V.getEnumLength(en.OutputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.inputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(i=>this.addUnknownKeyValToInput(n,i)),V.addInputAttributes(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.outputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(i=>this.addUnknownKeyValToOutput(n,i)),V.addOutputAttributes(this.outputs,t),this}clearFinalizedInput(t){const r=V.checkForInput(this.inputs,t);V.inputCheckUncleanFinalized(t,r);for(const n of Object.keys(r))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(n)||delete r[n];return this}combine(...t){const r=Ju.combine([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};vn.Psbt=Qu;var H={},x={};Object.defineProperty(x,"__esModule",{value:!0});x.signatureBlocksAction=x.checkInputForSig=x.pubkeyInScript=x.pubkeyPositionInScript=x.witnessStackToScriptWitness=x.isP2TR=x.isP2SHScript=x.isP2WSHScript=x.isP2WPKH=x.isP2PKH=x.isP2PK=x.isP2MS=void 0;const Ti=le,Kt=ne,nr=Ve,Zu=_e,pt=Pt;function ht(e){return t=>{try{return e({output:t}),!0}catch(r){return!1}}}x.isP2MS=ht(pt.p2ms);x.isP2PK=ht(pt.p2pk);x.isP2PKH=ht(pt.p2pkh);x.isP2WPKH=ht(pt.p2wpkh);x.isP2WSHScript=ht(pt.p2wsh);x.isP2SHScript=ht(pt.p2sh);x.isP2TR=ht(pt.p2tr);function ef(e){let t=h.allocUnsafe(0);function r(s){t=h.concat([t,h.from(s)])}function n(s){const c=t.length,a=Ti.encodingLength(s);t=h.concat([t,h.allocUnsafe(a)]),Ti.encode(s,t,c)}function i(s){n(s.length),r(s)}function o(s){n(s.length),s.forEach(i)}return o(e),t}x.witnessStackToScriptWitness=ef;function Gs(e,t){const r=(0,Zu.hash160)(e),n=e.slice(1,33),i=Kt.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(o=>typeof o=="number"?!1:o.equals(e)||o.equals(r)||o.equals(n))}x.pubkeyPositionInScript=Gs;function tf(e,t){return Gs(e,t)!==-1}x.pubkeyInScript=tf;function rf(e,t){return nf(e).some(n=>js(n,Kt.signature.decode,t))}x.checkInputForSig=rf;function js(e,t,r){const{hashType:n}=t(e),i=[];switch(n&nr.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case nr.Transaction.SIGHASH_ALL:break;case nr.Transaction.SIGHASH_SINGLE:case nr.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}x.signatureBlocksAction=js;function nf(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=sf(e)}else t=e.partialSig;return t.map(r=>r.signature)}function sf(e){const t=e.finalScriptSig?Kt.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?Kt.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>h.isBuffer(n)&&Kt.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(H,"__esModule",{value:!0});H.checkTaprootInputForSigs=H.tapTreeFromList=H.tapTreeToList=H.tweakInternalPubKey=H.checkTaprootOutputFields=H.checkTaprootInputFields=H.isTaprootOutput=H.isTaprootInput=H.serializeTaprootSignature=H.tapScriptFinalizer=H.toXOnly=void 0;const Cn=Y,of=Ve,Hr=x,We=Pr,cf=Pt,af=x,uf=e=>e.length===32?e:e.slice(1,33);H.toXOnly=uf;function ff(e,t,r){const n=Pf(t,e,r);try{const o=If(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,Hr.witnessStackToScriptWitness)(o)}}catch(i){throw new Error("Can not finalize taproot input #".concat(e,": ").concat(i))}}H.tapScriptFinalizer=ff;function pf(e,t){const r=t?h.from([t]):h.from([]);return h.concat([e,r])}H.serializeTaprootSignature=pf;function fr(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,Hr.isP2TR)(e.witnessUtxo.script))}H.isTaprootInput=fr;function pr(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,Hr.isP2TR)(t))}H.isTaprootOutput=pr;function hf(e,t,r){vf(e,t,r),kf(e,t,r)}H.checkTaprootInputFields=hf;function lf(e,t,r){Tf(e,t,r),df(e,t)}H.checkTaprootOutputFields=lf;function df(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,o=bf(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}function bf(e,t){const r=t&&Ws(t.leaves),{output:n}=(0,cf.p2tr)({internalPubkey:e,scriptTree:r});return n}function gf(e,t){const r=t.tapInternalKey,n=r&&(0,We.tweakKey)(r,t.tapMerkleRoot);if(!n)throw new Error("Cannot tweak tap internal key for input #".concat(e,". Public key: ").concat(r&&r.toString("hex")));return n.x}H.tweakInternalPubKey=gf;function yf(e){if(!(0,Cn.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return un(e)}H.tapTreeToList=yf;function Ws(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:_f(e)}H.tapTreeFromList=Ws;function mf(e,t){return Sf(e).some(n=>(0,af.signatureBlocksAction)(n,wf,t))}H.checkTaprootInputForSigs=mf;function wf(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||of.Transaction.SIGHASH_DEFAULT}}function Sf(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=Ef(e.finalScriptWitness);r&&t.push(r)}return t}function Ef(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function un(e,t=[],r=0){if(r>We.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,Cn.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||We.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&un(e[0],t,r+1),e[1]&&un(e[1],t,r+1),t):[]}function _f(e){let t;for(const r of e)if(t=fn(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function fn(e,t,r=0){if(r>We.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,Cn.isTapleaf)(t))return;const n=fn(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=fn(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function vf(e,t,r){const n=fr(e)&&Tt(t),i=Tt(e)&&fr(t),o=e===t&&fr(t)&&Tt(t);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}function Tf(e,t,r){const n=pr(e)&&Tt(t),i=Tt(e)&&pr(t),o=e===t&&pr(t)&&Tt(t);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}function kf(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(o=>tn(o,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(o=>tn(o,t.tapMerkleRoot));if(!n||!i)throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>tn(i,e.tapMerkleRoot)))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}function tn(e,t){if(!t)return!0;const r=(0,We.tapleafHash)({output:e.script,version:e.leafVersion});return(0,We.rootHashFromPath)(e.controlBlock,r).equals(t)}function If(e,t){const r=(0,We.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>Of(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function Of(e,t){return Object.assign({positionInScript:(0,Hr.pubkeyPositionInScript)(t.pubkey,e)},t)}function Pf(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error("Can not finalize taproot input #".concat(t,". No tapleaf script signature provided."));const n=(e.tapLeafScript||[]).sort((i,o)=>i.controlBlock.length-o.controlBlock.length).find(i=>Af(i,e.tapScriptSig,r));if(!n)throw new Error("Can not finalize taproot input #".concat(t,". Signature for tapleaf script not found."));return n}function Af(e,t,r){const n=(0,We.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(o=>o.leafHash.equals(n))!==void 0}function Tt(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}Object.defineProperty(Nr,"__esModule",{value:!0});Nr.Psbt=void 0;const ki=vn,Ii=le,ee=Hn,Oi=re,gr=D,xf=G,fe=Pt,Nf=Pr,Be=ne,z=Ve,R=H,F=x,Bf={network:xf.bitcoin,maximumFeeRate:5e3};class yr{static fromBase64(t,r={}){const n=h.from(t,"base64");return this.fromBuffer(n,r)}static fromHex(t,r={}){const n=h.from(t,"hex");return this.fromBuffer(n,r)}static fromBuffer(t,r={}){const n=ki.Psbt.fromBuffer(t,Uf),i=new yr(r,n);return Lf(i.__CACHE.__TX,i.__CACHE),i}constructor(t={},r=new ki.Psbt(new Vs)){this.data=r,this.opts=Object.assign({},Bf,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const n=(i,o,s,c)=>Object.defineProperty(i,o,{enumerable:s,writable:c});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:(0,gr.cloneBuffer)(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let r;try{r=(0,Oi.fromOutputScript)(t.script,this.opts.network)}catch(n){}return{script:(0,gr.cloneBuffer)(t.script),value:t.value,address:r}})}combine(...t){return this.data.combine(...t.map(r=>r.data)),this}clone(){const t=yr.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){ir(t),this.opts.maximumFeeRate=t}setVersion(t){ir(t),Ut(this.data.inputs,"setVersion");const r=this.__CACHE;return r.__TX.version=t,r.__EXTRACTED_TX=void 0,this}setLocktime(t){ir(t),Ut(this.data.inputs,"setLocktime");const r=this.__CACHE;return r.__TX.locktime=t,r.__EXTRACTED_TX=void 0,this}setInputSequence(t,r){ir(r),Ut(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=t)throw new Error("Input index too high");return n.__TX.ins[t].sequence=r,n.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(r=>this.addInput(r)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,R.checkTaprootInputFields)(t,t,"addInput"),Ut(this.data.inputs,"addInput"),t.witnessScript&&mr(t.witnessScript);const r=this.__CACHE;this.data.addInput(t);const n=r.__TX.ins[r.__TX.ins.length-1];zs(r,n);const i=this.data.inputs.length-1,o=this.data.inputs[i];return o.nonWitnessUtxo&&hn(this.__CACHE,o,i),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(r=>this.addOutput(r)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");Ut(this.data.inputs,"addOutput");const{address:r}=t;if(typeof r=="string"){const{network:i}=this.opts,o=(0,Oi.toOutputScript)(r,i);t=Object.assign(t,{script:o})}(0,R.checkTaprootOutputFields)(t,t,"addOutput");const n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(Xs))throw new Error("Not finalized");const r=this.__CACHE;if(t||Cf(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return to(this.data.inputs,n,r,!0),n}getFeeRate(){return Bi("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return Bi("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,ee.checkForInput)(this.data.inputs,0),Ht(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,r){const n=(0,ee.checkForInput)(this.data.inputs,t);return(0,R.isTaprootInput)(n)?this._finalizeTaprootInput(t,n,void 0,r):this._finalizeInput(t,n,r)}finalizeTaprootInput(t,r,n=R.tapScriptFinalizer){const i=(0,ee.checkForInput)(this.data.inputs,t);if((0,R.isTaprootInput)(i))return this._finalizeTaprootInput(t,i,r,n);throw new Error("Cannot finalize input #".concat(t,". Not Taproot."))}_finalizeInput(t,r,n=Ff){const{script:i,isP2SH:o,isP2WSH:s,isSegwit:c}=Gf(t,r,this.__CACHE);if(!i)throw new Error("No script found for input #".concat(t));Rf(r);const{finalScriptSig:a,finalScriptWitness:p}=n(t,r,i,c,o,s);if(a&&this.data.updateInput(t,{finalScriptSig:a}),p&&this.data.updateInput(t,{finalScriptWitness:p}),!a&&!p)throw new Error("Unknown error finalizing input #".concat(t));return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,r,n,i=R.tapScriptFinalizer){if(!r.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing withness utxo."));if(r.tapKeySig){const o=fe.p2tr({output:r.witnessUtxo.script,signature:r.tapKeySig}),s=(0,F.witnessStackToScriptWitness)(o.witness);this.data.updateInput(t,{finalScriptWitness:s})}else{const{finalScriptWitness:o}=i(t,r,n);this.data.updateInput(t,{finalScriptWitness:o})}return this.data.clearFinalizedInput(t),this}getInputType(t){const r=(0,ee.checkForInput)(this.data.inputs,t),n=ro(t,r,this.__CACHE),i=Rr(n,t,"input",r.redeemScript||qf(r.finalScriptSig),r.witnessScript||zf(r.finalScriptWitness)),o=i.type==="raw"?"":i.type+"-",s=io(i.meaningfulScript);return o+s}inputHasPubkey(t,r){const n=(0,ee.checkForInput)(this.data.inputs,t);return Vf(r,n,t,this.__CACHE)}inputHasHDKey(t,r){const n=(0,ee.checkForInput)(this.data.inputs,t),i=Ai(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}outputHasPubkey(t,r){const n=(0,ee.checkForOutput)(this.data.outputs,t);return Xf(r,n,t,this.__CACHE)}outputHasHDKey(t,r){const n=(0,ee.checkForOutput)(this.data.outputs,t),i=Ai(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}validateSignaturesOfAllInputs(t){return(0,ee.checkForInput)(this.data.inputs,0),Ht(this.data.inputs.length).map(n=>this.validateSignaturesOfInput(n,t)).reduce((n,i)=>i===!0&&n,!0)}validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t];return(0,R.isTaprootInput)(i)?this.validateSignaturesOfTaprootInput(t,r,n):this._validateSignaturesOfInput(t,r,n)}_validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t],o=(i||{}).partialSig;if(!i||!o||o.length<1)throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");const s=n?o.filter(u=>u.pubkey.equals(n)):o;if(s.length<1)throw new Error("No signatures for this pubkey");const c=[];let a,p,f;for(const u of s){const d=Be.signature.decode(u.signature),{hash:l,script:b}=f!==d.hashType?Js(t,Object.assign({},i,{sighashType:d.hashType}),this.__CACHE,!0):{hash:a,script:p};f=d.hashType,a=l,p=b,qs(u.pubkey,b,"verify"),c.push(r(u.pubkey,l,d.signature))}return c.every(u=>u===!0)}validateSignaturesOfTaprootInput(t,r,n){const i=this.data.inputs[t],o=(i||{}).tapKeySig,s=(i||{}).tapScriptSig;if(!i&&!o&&!(s&&!s.length))throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");n=n&&(0,R.toXOnly)(n);const c=n?pn(t,i,this.data.inputs,n,this.__CACHE):Kf(t,i,this.data.inputs,this.__CACHE);if(!c.length)throw new Error("No signatures for this pubkey");const a=c.find(f=>!f.leafHash);let p=0;if(o&&a){if(!r(a.pubkey,a.hash,Hi(o)))return!1;p++}if(s)for(const f of s){const u=c.find(d=>f.pubkey.equals(d.pubkey));if(u){if(!r(f.pubkey,u.hash,Hi(f.signature)))return!1;p++}}return p>0}signAllInputsHD(t,r=[z.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const i of Ht(this.data.inputs.length))try{this.signInputHD(i,t,r),n.push(!0)}catch(o){n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,r=[z.Transaction.SIGHASH_ALL]){return new Promise((n,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=[],s=[];for(const c of Ht(this.data.inputs.length))s.push(this.signInputHDAsync(c,t,r).then(()=>{o.push(!0)},()=>{o.push(!1)}));return Promise.all(s).then(()=>{if(o.every(c=>c===!1))return i(new Error("No inputs were signed"));n()})})}signInputHD(t,r,n=[z.Transaction.SIGHASH_ALL]){if(!r||!r.publicKey||!r.fingerprint)throw new Error("Need HDSigner to sign input");return Ci(t,this.data.inputs,r).forEach(o=>this.signInput(t,o,n)),this}signInputHDAsync(t,r,n=[z.Transaction.SIGHASH_ALL]){return new Promise((i,o)=>{if(!r||!r.publicKey||!r.fingerprint)return o(new Error("Need HDSigner to sign input"));const c=Ci(t,this.data.inputs,r).map(a=>this.signInputAsync(t,a,n));return Promise.all(c).then(()=>{i()}).catch(o)})}signAllInputs(t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const i of Ht(this.data.inputs.length))try{this.signInput(i,t,r),n.push(!0)}catch(o){n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,r){return new Promise((n,i)=>{if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));const o=[],s=[];for(const[c]of this.data.inputs.entries())s.push(this.signInputAsync(c,t,r).then(()=>{o.push(!0)},()=>{o.push(!1)}));return Promise.all(s).then(()=>{if(o.every(c=>c===!1))return i(new Error("No inputs were signed"));n()})})}signInput(t,r,n){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=(0,ee.checkForInput)(this.data.inputs,t);return(0,R.isTaprootInput)(i)?this._signTaprootInput(t,i,r,void 0,n):this._signInput(t,r,n)}signTaprootInput(t,r,n,i){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=(0,ee.checkForInput)(this.data.inputs,t);if((0,R.isTaprootInput)(o))return this._signTaprootInput(t,o,r,n,i);throw new Error("Input #".concat(t," is not of type Taproot."))}_signInput(t,r,n=[z.Transaction.SIGHASH_ALL]){const{hash:i,sighashType:o}=Ui(this.data.inputs,t,r.publicKey,this.__CACHE,n),s=[{pubkey:r.publicKey,signature:Be.signature.encode(r.sign(i),o)}];return this.data.updateInput(t,{partialSig:s}),this}_signTaprootInput(t,r,n,i,o=[z.Transaction.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,o),c=s.filter(p=>!p.leafHash).map(p=>(0,R.serializeTaprootSignature)(n.signSchnorr(p.hash),r.sighashType))[0],a=s.filter(p=>!!p.leafHash).map(p=>({pubkey:(0,R.toXOnly)(n.publicKey),signature:(0,R.serializeTaprootSignature)(n.signSchnorr(p.hash),r.sighashType),leafHash:p.leafHash}));return c&&this.data.updateInput(t,{tapKeySig:c}),a.length&&this.data.updateInput(t,{tapScriptSig:a}),this}signInputAsync(t,r,n){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=(0,ee.checkForInput)(this.data.inputs,t);return(0,R.isTaprootInput)(i)?this._signTaprootInputAsync(t,i,r,void 0,n):this._signInputAsync(t,r,n)})}signTaprootInputAsync(t,r,n,i){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=(0,ee.checkForInput)(this.data.inputs,t);if((0,R.isTaprootInput)(o))return this._signTaprootInputAsync(t,o,r,n,i);throw new Error("Input #".concat(t," is not of type Taproot."))})}_signInputAsync(t,r,n=[z.Transaction.SIGHASH_ALL]){const{hash:i,sighashType:o}=Ui(this.data.inputs,t,r.publicKey,this.__CACHE,n);return Promise.resolve(r.sign(i)).then(s=>{const c=[{pubkey:r.publicKey,signature:Be.signature.encode(s,o)}];this.data.updateInput(t,{partialSig:c})})}async _signTaprootInputAsync(t,r,n,i,o=[z.Transaction.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,o),c=[],a=s.filter(f=>!f.leafHash)[0];if(a){const f=Promise.resolve(n.signSchnorr(a.hash)).then(u=>({tapKeySig:(0,R.serializeTaprootSignature)(u,r.sighashType)}));c.push(f)}const p=s.filter(f=>!!f.leafHash);if(p.length){const f=p.map(u=>Promise.resolve(n.signSchnorr(u.hash)).then(d=>({tapScriptSig:[{pubkey:(0,R.toXOnly)(n.publicKey),signature:(0,R.serializeTaprootSignature)(d,r.sighashType),leafHash:u.leafHash}]})));c.push(...f)}return Promise.all(c).then(f=>{f.forEach(u=>this.data.updateInput(t,u))})}checkTaprootHashesForSig(t,r,n,i,o){if(typeof n.signSchnorr!="function")throw new Error("Need Schnorr Signer to sign taproot input #".concat(t,"."));const s=pn(t,r,this.data.inputs,n.publicKey,this.__CACHE,i,o);if(!s||!s.length)throw new Error("Can not sign for input #".concat(t," with the key ").concat(n.publicKey.toString("hex")));return s}toBuffer(){return rn(this.__CACHE),this.data.toBuffer()}toHex(){return rn(this.__CACHE),this.data.toHex()}toBase64(){return rn(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,r){return r.witnessScript&&mr(r.witnessScript),(0,R.checkTaprootInputFields)(this.data.inputs[t],r,"updateInput"),this.data.updateInput(t,r),r.nonWitnessUtxo&&hn(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,r){const n=this.data.outputs[t];return(0,R.checkTaprootOutputFields)(n,r,"updateOutput"),this.data.updateOutput(t,r),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,r){return this.data.addUnknownKeyValToInput(t,r),this}addUnknownKeyValToOutput(t,r){return this.data.addUnknownKeyValToOutput(t,r),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}}Nr.Psbt=yr;const Uf=e=>new Vs(e);class Vs{constructor(t=h.from([2,0,0,0,0,0,0,0,0,0])){this.tx=z.Transaction.fromBuffer(t),$f(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!h.isBuffer(t.hash)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const r=typeof t.hash=="string"?(0,gr.reverseBuffer)(h.from(t.hash,"hex")):t.hash;this.tx.addInput(r,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!h.isBuffer(t.script)||typeof t.value!="number")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}}function Hf(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return Pi(1,e.partialSig);case"multisig":const n=fe.p2ms({output:t});return Pi(n.m,e.partialSig,n.pubkeys);default:return!1}}function rn(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function Pi(e,t,r){if(!t)return!1;let n;if(r?n=r.map(i=>{const o=Yf(i);return t.find(s=>s.pubkey.equals(o))}).filter(i=>!!i):n=t,n.length>e)throw new Error("Too many signatures");return n.length===e}function Xs(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function Ai(e){return t=>!(!t.masterFingerprint.equals(e.fingerprint)||!e.derivePath(t.path).publicKey.equals(t.pubkey))}function ir(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function Cf(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error("Warning: You are paying around ".concat((o/1e8).toFixed(8)," in ")+"fees, which is ".concat(n," satoshi per byte for a transaction ")+"with a VSize of ".concat(i," bytes (segwit counted as 0.25 byte per ")+"byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.")}function Ut(e,t){e.forEach(r=>{if((0,R.isTaprootInput)(r)?(0,R.checkTaprootInputForSigs)(r,t):(0,F.checkInputForSig)(r,t))throw new Error("Can not modify transaction, signatures exist.")})}function Rf(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(n=>{const{hashType:i}=Be.signature.decode(n.signature);if(r!==i)throw new Error("Signature sighash does not match input sighash type")})}function qs(e,t,r){if(!(0,F.pubkeyInScript)(e,t))throw new Error("Can not ".concat(r," for this input with the key ").concat(e.toString("hex")))}function $f(e){if(!e.ins.every(r=>r.script&&r.script.length===0&&r.witness&&r.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function Lf(e,t){e.ins.forEach(r=>{zs(t,r)})}function zs(e,t){const r=(0,gr.reverseBuffer)(h.from(t.hash)).toString("hex")+":"+t.index;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function Ys(e,t){return(r,n,i,o)=>{const s=e({redeem:{output:i}}).output;if(!n.equals(s))throw new Error("".concat(t," for ").concat(o," #").concat(r," doesn't match the scriptPubKey in the prevout"))}}const xi=Ys(fe.p2sh,"Redeem script"),Ni=Ys(fe.p2wsh,"Witness script");function Bi(e,t,r,n){if(!r.every(Xs))throw new Error("PSBT must be finalized to calculate ".concat(t));if(e==="__FEE_RATE"&&n.__FEE_RATE)return n.__FEE_RATE;if(e==="__FEE"&&n.__FEE)return n.__FEE;let i,o=!0;if(n.__EXTRACTED_TX?(i=n.__EXTRACTED_TX,o=!1):i=n.__TX.clone(),to(r,i,n,o),e==="__FEE_RATE")return n.__FEE_RATE;if(e==="__FEE")return n.__FEE}function Ff(e,t,r,n,i,o){const s=io(r);if(!Hf(t,r,s))throw new Error("Can not finalize input #".concat(e));return Mf(r,s,t.partialSig,n,i,o)}function Mf(e,t,r,n,i,o){let s,c;const a=Df(e,t,r),p=o?fe.p2wsh({redeem:a}):null,f=i?fe.p2sh({redeem:p||a}):null;return n?(p?c=(0,F.witnessStackToScriptWitness)(p.witness):c=(0,F.witnessStackToScriptWitness)(a.witness),f&&(s=f.input)):f?s=f.input:s=a.input,{finalScriptSig:s,finalScriptWitness:c}}function Ui(e,t,r,n,i){const o=(0,ee.checkForInput)(e,t),{hash:s,sighashType:c,script:a}=Js(t,o,n,!1,i);return qs(r,a,"sign"),{hash:s,sighashType:c}}function Js(e,t,r,n,i){const o=r.__TX,s=t.sighashType||z.Transaction.SIGHASH_ALL;Zs(s,i);let c,a;if(t.nonWitnessUtxo){const u=Cr(r,t,e),d=o.ins[e].hash,l=u.getHash();if(!d.equals(l))throw new Error("Non-witness UTXO hash for input #".concat(e," doesn't match the hash specified in the prevout"));const b=o.ins[e].index;a=u.outs[b]}else if(t.witnessUtxo)a=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:p,type:f}=Rr(a.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)c=o.hashForWitnessV0(e,p,a.value,s);else if((0,F.isP2WPKH)(p)){const u=fe.p2pkh({hash:p.slice(2)}).output;c=o.hashForWitnessV0(e,u,a.value,s)}else{if(t.nonWitnessUtxo===void 0&&r.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error("Input #".concat(e," has witnessUtxo but non-segwit script: ")+"".concat(p.toString("hex")));!n&&r.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecesor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),c=o.hashForSignature(e,p,s)}return{script:p,sighashType:s,hash:c}}function Kf(e,t,r,n){const i=[];if(t.tapInternalKey){const s=Qs(e,t,n);s&&i.push(s)}if(t.tapScriptSig){const s=t.tapScriptSig.map(c=>c.pubkey);i.push(...s)}return i.map(s=>pn(e,t,r,s,n)).flat()}function Qs(e,t,r){const{script:n}=Rn(e,t,r);return(0,F.isP2TR)(n)?n.subarray(2,34):null}function Hi(e){return e.length===64?e:e.subarray(0,64)}function pn(e,t,r,n,i,o,s){const c=i.__TX,a=t.sighashType||z.Transaction.SIGHASH_DEFAULT;Zs(a,s);const p=r.map((b,g)=>Rn(g,b,i)),f=p.map(b=>b.script),u=p.map(b=>b.value),d=[];if(t.tapInternalKey&&!o){const b=Qs(e,t,i)||h.from([]);if((0,R.toXOnly)(n).equals(b)){const g=c.hashForWitnessV1(e,f,u,a);d.push({pubkey:n,hash:g})}}const l=(t.tapLeafScript||[]).filter(b=>(0,F.pubkeyInScript)(n,b.script)).map(b=>{const g=(0,Nf.tapleafHash)({output:b.script,version:b.leafVersion});return Object.assign({hash:g},b)}).filter(b=>!o||o.equals(b.hash)).map(b=>{const g=c.hashForWitnessV1(e,f,u,z.Transaction.SIGHASH_DEFAULT,b.hash);return{pubkey:n,hash:g,leafHash:b.hash}});return d.concat(l)}function Zs(e,t){if(t&&t.indexOf(e)<0){const r=Wf(e);throw new Error("Sighash type is not allowed. Retry the sign method passing the "+"sighashTypes array of whitelisted types. Sighash type: ".concat(r))}}function Df(e,t,r){let n;switch(t){case"multisig":const i=jf(e,r);n=fe.p2ms({output:e,signatures:i});break;case"pubkey":n=fe.p2pk({output:e,signature:r[0].signature});break;case"pubkeyhash":n=fe.p2pkh({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=fe.p2wpkh({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break}return n}function Gf(e,t,r){const n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const o=Cr(r,t,e),s=n.ins[e].index;i.script=o.outs[s].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||(0,F.isP2WPKH)(i.script))&&(i.isSegwit=!0),i}function Ci(e,t,r){const n=(0,ee.checkForInput)(t,e);if(!n.bip32Derivation||n.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const i=n.bip32Derivation.map(s=>{if(s.masterFingerprint.equals(r.fingerprint))return s}).filter(s=>!!s);if(i.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(s=>{const c=r.derivePath(s.path);if(!s.pubkey.equals(c.publicKey))throw new Error("pubkey did not match bip32Derivation");return c})}function jf(e,t){return fe.p2ms({output:e}).pubkeys.map(n=>(t.filter(i=>i.pubkey.equals(n))[0]||{}).signature).filter(n=>!!n)}function eo(e){let t=0;function r(s){return t+=s,e.slice(t-s,t)}function n(){const s=Ii.decode(e,t);return t+=Ii.decode.bytes,s}function i(){return r(n())}function o(){const s=n(),c=[];for(let a=0;a<s;a++)c.push(i());return c}return o()}function Wf(e){let t=e&z.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(e&31){case z.Transaction.SIGHASH_ALL:t+="SIGHASH_ALL";break;case z.Transaction.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case z.Transaction.SIGHASH_NONE:t+="SIGHASH_NONE";break}return t}function hn(e,t,r){e.__NON_WITNESS_UTXO_BUF_CACHE[r]=t.nonWitnessUtxo;const n=z.Transaction.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[r]=n;const i=e,o=r;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const s=i.__NON_WITNESS_UTXO_BUF_CACHE[o],c=i.__NON_WITNESS_UTXO_TX_CACHE[o];if(s!==void 0)return s;{const a=c.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[o]=a,a}},set(s){i.__NON_WITNESS_UTXO_BUF_CACHE[o]=s}})}function to(e,t,r,n){let i=0;e.forEach((a,p)=>{if(n&&a.finalScriptSig&&(t.ins[p].script=a.finalScriptSig),n&&a.finalScriptWitness&&(t.ins[p].witness=eo(a.finalScriptWitness)),a.witnessUtxo)i+=a.witnessUtxo.value;else if(a.nonWitnessUtxo){const f=Cr(r,a,p),u=t.ins[p].index,d=f.outs[u];i+=d.value}});const o=t.outs.reduce((a,p)=>a+p.value,0),s=i-o;if(s<0)throw new Error("Outputs are spending more than Inputs");const c=t.virtualSize();r.__FEE=s,r.__EXTRACTED_TX=t,r.__FEE_RATE=Math.floor(s/c)}function Cr(e,t,r){const n=e.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||hn(e,t,r),n[r]}function ro(e,t,r){const{script:n}=Rn(e,t,r);return n}function Rn(e,t,r){if(t.witnessUtxo!==void 0)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(t.nonWitnessUtxo!==void 0){const i=Cr(r,t,e).outs[r.__TX.ins[e].index];return{script:i.script,value:i.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function Vf(e,t,r,n){const i=ro(r,t,n),{meaningfulScript:o}=Rr(i,r,"input",t.redeemScript,t.witnessScript);return(0,F.pubkeyInScript)(e,o)}function Xf(e,t,r,n){const i=n.__TX.outs[r].script,{meaningfulScript:o}=Rr(i,r,"output",t.redeemScript,t.witnessScript);return(0,F.pubkeyInScript)(e,o)}function qf(e){if(!e)return;const t=Be.decompile(e);if(!t)return;const r=t[t.length-1];if(!(!h.isBuffer(r)||no(r)||Jf(r)||!Be.decompile(r)))return r}function zf(e){if(!e)return;const t=eo(e),r=t[t.length-1];if(!(no(r)||!Be.decompile(r)))return r}function Yf(e){if(e.length===65){const t=e[64]&1,r=e.slice(0,33);return r[0]=2|t,r}return e.slice()}function no(e){return e.length===33&&Be.isCanonicalPubKey(e)}function Jf(e){return Be.isCanonicalScriptSignature(e)}function Rr(e,t,r,n,i){const o=(0,F.isP2SHScript)(e),s=o&&n&&(0,F.isP2WSHScript)(n),c=(0,F.isP2WSHScript)(e);if(o&&n===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((c||s)&&i===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let a;return s?(a=i,xi(t,e,n,r),Ni(t,n,i,r),mr(a)):c?(a=i,Ni(t,e,i,r),mr(a)):o?(a=n,xi(t,e,n,r)):a=e,{meaningfulScript:a,type:s?"p2sh-p2wsh":o?"p2sh":c?"p2wsh":"raw"}}function mr(e){if((0,F.isP2WPKH)(e)||(0,F.isP2SHScript)(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function io(e){return(0,F.isP2WPKH)(e)?"witnesspubkeyhash":(0,F.isP2PKH)(e)?"pubkeyhash":(0,F.isP2MS)(e)?"multisig":(0,F.isP2PK)(e)?"pubkey":"nonstandard"}function Ht(e){return[...Array(e).keys()]}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=re;e.address=t;const r=_e;e.crypto=r;const n=G;e.networks=n;const i=Pt;e.payments=i;const o=ne;e.script=o;var s=Ar;Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return s.Block}});var c=Nr;Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=Ge;Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var p=Ve;Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return p.Transaction}});var f=je;Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(ge);var $n={name:"BitcoinCash",per1:1e8,unit:"BCH"},Qf=Object.assign({},{hashGenesisBlock:"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",port:8333,portRpc:8332,protocol:{magic:3908297187},seedsDns:["seed.bitcoinabc.org","seed-abc.bitcoinforks.org","btccash-seeder.bitcoinunlimited.info","seed.bitprim.org","seed.deadalnix.me","seeder.criptolayer.net"],versions:{bip32:{private:76066276,public:76067358},bip44:145,private:128,public:0,scripthash:5}},$n),Zf=Object.assign({},{hashGenesisBlock:"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",port:18333,portRpc:18332,protocol:{magic:4109624820},seedsDns:["testnet-seed.bitcoinabc.org","testnet-seed-abc.bitcoinforks.org","testnet-seed.bitprim.org","testnet-seed.deadalnix.me","testnet-seeder.criptolayer.net"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},$n),ep=Object.assign({},{hashGenesisBlock:"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",port:18444,portRpc:18332,protocol:{magic:4206867930},seedsDns:[],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},$n),tp={main:Qf,test:Zf,regtest:ep},rp={name:"BlackCoin",per1:1e8,unit:"BLK"},np=Object.assign({},{hashGenesisBlock:"000001faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563",port:15714,portRpc:15715,protocol:{magic:86127984},seedsDns:["rat4.blackcoin.co","seed.blackcoin.co","archon.darkfox.id.au","foxy.seeds.darkfox.id.au","6.syllabear.us.to","bcseed.syllabear.us.to"],versions:{bip32:{private:76066276,public:76067358},bip44:10,private:153,public:25,scripthash:85}},rp),ip={main:np,test:null},$r={name:"Bitcoin",per1:1e8,unit:"BTC",messagePrefix:"Bitcoin Signed Message:\n"},sp=Object.assign({},{hashGenesisBlock:"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",port:8333,portRpc:8332,protocol:{magic:3652501241},bech32:"bc",seedsDns:["seed.bitcoin.sipa.be","dnsseed.bluematt.me","seed.bitcoinstats.com","seed.bitcoin.jonasschnelli.ch","seed.btc.petertodd.org","seed.bitcoin.sprovoost.nl","dnsseed.emzy.de"],versions:{bip32:{private:76066276,public:76067358},bip44:0,private:128,public:0,scripthash:5}},$r),op=Object.assign({},{hashGenesisBlock:"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",port:18333,portRpc:18332,protocol:{magic:118034699},bech32:"tb",seedsDns:["testnet-seed.alexykot.me","testnet-seed.bitcoin.schildbach.de","testnet-seed.bitcoin.petertodd.org","testnet-seed.bluematt.me"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},$r),cp=Object.assign({},{hashGenesisBlock:"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",port:18444,portRpc:18332,protocol:{magic:3669344250},bech32:"bcrt",seedsDns:[],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},$r),ap=Object.assign({},{hashGenesisBlock:"f67ad7695d9b662a72ff3d8edbbb2de0bfa67b13974bb9910d116d5cbd863e68",port:18555,portRpc:18556,protocol:{magic:303307798},bech32:"sb",seedsDns:[],versions:{bip32:{private:69253376,public:69254458},bip44:115,private:100,public:63,scripthash:123}},$r),up={main:sp,test:op,regtest:cp,simnet:ap},so={name:"Bitcoin Gold",unit:"BTG"},fp=Object.assign({},{hashGenesisBlock:"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",port:8338,protocol:{magic:1148012513},bech32:"btg",seedsDns:["eu-dnsseed.bitcoingold-official.org","dnsseed.bitcoingold.org","dnsseed.btcgpu.org"],versions:{bip32:{private:76066276,public:76067358},bip44:156,private:128,public:38,scripthash:23}},so),pp=Object.assign({},{hashGenesisBlock:"0x00000000e0781ebe24b91eedc293adfea2f557b53ec379e78959de3853e6f9f6",port:18338,portRpc:18332,protocol:{magic:1164855522},bech32:"tbtg",seedsDns:["test-dnsseed.bitcoingold.org","test-dnsseed.btcgpu.org","eu-test-dnsseed.bitcoingold-official.org"],versions:{bip32:{private:70615956,public:70617039},bip44:156,private:239,public:111,scripthash:196}},so),hp={main:fp,test:pp},Ln={name:"c0ban",unit:"RYO"},lp=Object.assign({},{hashGenesisBlock:"000000005184ffce04351e687a3965b300ee011d26b2089232cd039273be4a67",port:3881,portRpc:3882,protocol:{magic:1851928675},seedsDns:["jp01.dnsseed.c0ban.com","kr01.dnsseed.c0ban.com"],versions:{bip32:{private:76066276,public:76067358},bip44:88888,private:136,public:18,scripthash:28}},Ln),dp=Object.assign({},{hashGenesisBlock:"000000005184ffce04351e687a3965b300ee011d26b2089232cd039273be4a67",port:13881,portRpc:13882,protocol:{magic:2390917251},seedsDns:[],versions:{bip32:{private:70812552,public:72910728},bip44:1,private:238,public:118,scripthash:198}},Ln),bp=Object.assign({},{hashGenesisBlock:"3249e44acac8fc67e6b94e882525cea6f5a9853e1ff7b4a1d5f470b23ff8ae11",port:23881,portRpc:23882,protocol:{magic:3669344250},seedsDns:[],versions:{bip32:{private:70617039,public:70615956},bip44:1,private:239,public:111,scripthash:196}},Ln),gp={main:lp,test:dp,regtest:bp},oo={name:"CityCoin",isProofOfStake:!0},yp=Object.assign({},{unit:"CITY",hashGenesisBlock:"00000b0517068e602ed5279c20168cfa1e69884ee4e784909652da34c361bff2",port:4333,portRpc:4334,protocol:{magic:1129601281},seedsDns:["seed.city-chain.org","seed.city-coin.org","seed.citychain.foundation","seed.liberstad.com"],versions:{bip32:{private:76066276,public:76067358},bip44:1926,private:237,public:28,scripthash:88}},oo),mp=Object.assign({},{unit:"TCITY",hashGenesisBlock:"00077765f625cc2cb6266544ff7d5a462f25be14ea1116dc2bd2fec17e40a5e3",port:24333,portRpc:24334,protocol:{magic:1129600001},seedsDns:["testseed.city-chain.org","testseed.city-coin.org","testseed.citychain.foundation"],versions:{bip32:{private:76066276,public:76067358},bip44:1926,private:194,public:66,scripthash:196}},oo),wp={main:yp,test:mp},co={name:"Dash",unit:"DASH"},Sp=Object.assign({},{hashGenesisBlock:"00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6",port:9999,portRpc:9998,protocol:{magic:3177909439},seedsDns:["dash.org","dnsseed.dash.org","dashdot.io","dnsseed.dashdot.io","masternode.io","dnsseed.masternode.io","dashpay.io","dnsseed.dashpay.io"],versions:{bip32:{private:76066276,public:76067358},bip44:5,private:204,public:76,scripthash:16}},co),Ep=Object.assign({},{hashGenesisBlock:"00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c",port:19999,portRpc:19998,seedsDns:["dashdot.io","testnet-seed.dashdot.io","masternode.io","test.dnsseed.masternode.io"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:140,scripthash:19}},co),_p={main:Sp,test:Ep},ao={name:"Denarius",unit:"DNR"},vp=Object.assign({},{hashGenesisBlock:"00000d5dbbda01621cfc16bbc1f9bf3264d641a5dbf0de89fd0182c2c4828fcd",port:33339,portRpc:32339,protocol:{magic:3035624186},seedsDns:["denariusexplorer.org","denarius.host","denarius.tech","denarius.network"],versions:{bip32:{private:76066276,public:76067358},bip44:116,private:158,public:30,scripthash:90}},ao),Tp=Object.assign({},{hashGenesisBlock:"000086bfe8264d241f7f8e5393f747784b8ca2aa98bdd066278d590462a4fdb4",versions:{bip44:1,private:140,public:18,scripthash:116}},ao),kp={main:vp,test:Tp},uo={name:"Decred",unit:"DCR"},Ip=Object.assign({},{hashGenesisBlock:"298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980",port:9108,portRpc:9109,protocol:{magic:4177573081},seedsDns:["mainnet-seed.decred.mindcry.org","mainnet-seed.decred.netpurgatory.com","mainnet.decredseed.org","mainnet-seed.decred.org"],versions:{bip32:{private:50177256,public:50178342},bip44:42,private:8926,public:1855,scripthash:1818}},uo),Op=Object.assign({},{hashGenesisBlock:"5b7466edf6739adc9b32aaedc54e24bdc59a05f0ced855088835fe3cbe58375f",port:19108,portRpc:19109,protocol:{magic:1223139429},seedsDns:["testnet-seed.decred.mindcry.org","testnet-seed.decred.netpurgatory.org","testnet.decredseed.org","testnet-seed.decred.org"],versions:{bip32:{private:70615959,public:70617041},bip44:42,private:8974,public:3873,scripthash:3836}},uo),Pp={main:Ip,test:Op},Ap={name:"DigiByte",per1:1e8,unit:"DGB"},xp=Object.assign({},{hashGenesisBlock:"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",port:12024,portRpc:14022,protocol:{magic:4207130330},bech32:"dgb",seedsDns:["seed.digibyte.io","digiexplorer.info","digihash.co"],versions:{bip44:2147483668,private:128,public:30,scripthash:63,scripthash2:5}},Ap),Np={main:xp},fo={name:"Dogecoin",unit:"DOGE"},Bp=Object.assign({},{hashGenesisBlock:"1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691",port:22556,protocol:{magic:3233857728},seedsDns:["seed.multidoge.org","seed2.multidoge.org"],versions:{bip32:{private:49988504,public:49990397},bip44:3,private:158,public:30,scripthash:22}},fo),Up=Object.assign({},{hashGenesisBlock:"bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e",port:44556,protocol:{magic:4240553948},seedsDns:["testseed.jrn.me.uk"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:241,public:113,scripthash:196}},fo),Hp={main:Bp,test:Up},Fn={name:"Groestlcoin",per1:1e8,unit:"GRS",messagePrefix:"GroestlCoin Signed Message:\n"},Cp=Object.assign({},{hashGenesisBlock:"00000ac5927c594d49cc0bdb81759d0da8297eb614683d3acb62f0703b639023",port:1331,portRpc:1441,protocol:{magic:3568615161},bech32:"grs",seedsDns:["dnsseed1.groestlcoin.org","dnsseed2.groestlcoin.org","dnsseed3.groestlcoin.org","dnsseed4.groestlcoin.org"],versions:{bip32:{private:76066276,public:76067358},bip44:17,private:128,public:36,scripthash:5}},Fn),Rp=Object.assign({},{hashGenesisBlock:"0x000000ffbb50fc9898cdd36ec163e6ba23230164c0052a28876255b7dcf2cd36",port:17777,portRpc:17766,protocol:{magic:118034699},bech32:"tgrs",seedsDns:["testnet-seed1.groestlcoin.org","testnet-seed2.groestlcoin.org"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},Fn),$p=Object.assign({},{hashGenesisBlock:"0x000000ffbb50fc9898cdd36ec163e6ba23230164c0052a28876255b7dcf2cd36",port:18888,portRpc:18443,protocol:{magic:3669344250},bech32:"grsrt",seedsDns:[],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},Fn),Lp={main:Cp,test:Rp,regtest:$p},po={name:"Litecoin",unit:"LTC"},Fp=Object.assign({},{hashGenesisBlock:"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",port:9333,protocol:{magic:3686187259},bech32:"ltc",seedsDns:["dnsseed.litecointools.com","dnsseed.litecoinpool.org","dnsseed.ltc.xurious.com","dnsseed.koin-project.com","dnsseed.weminemnc.com"],versions:{bip32:{private:27106558,public:27108450},bip44:2,private:176,public:48,scripthash:50,scripthash2:5}},po),Mp=Object.assign({},{hashGenesisBlock:"f5ae71e26c74beacc88382716aced69cddf3dffff24f384e1808905e0188f68f",bech32:"tltc",versions:{bip32:{private:70709117,public:70711009},bip44:1,private:239,public:111,scripthash:58,scripthash2:196}},po),Kp={main:Fp,test:Mp},ho={name:"Viacoin",unit:"VIA"},Dp=Object.assign({},{hashGenesisBlock:"4e9b54001f9976049830128ec0331515eaabe35a70970d79971da1539a400ba1",port:5223,protocol:{magic:3418777615},seedsDns:["seed.viacoin.net","viaseeder.barbatos.fr","mainnet.viacoin.net"],versions:{bip32:{private:76066276,public:76067358},bip44:14,private:199,public:71,scripthash:33}},ho),Gp=Object.assign({},{hashGenesisBlock:"770aa712aa08fdcbdecc1c8df1b3e2d4e17a7cf6e63a28b785b32e74c96cb27d",port:25223,protocol:{magic:2465187241},seedsDns:["testnet.viacoin.net","seed-testnet.viacoin.net"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:255,public:127,scripthash:196}},ho),jp={main:Dp,test:Gp},lo={name:"Monacoin",unit:"MONA"},Wp=Object.assign({},{hashGenesisBlock:"ff9f1c0116d19de7c9963845e129f9ed1bfc0b376eb54fd7afa42e0d418c8bb6",port:9401,portRpc:9402,protocol:{magic:3686187259},bech32:"mona",seedsDns:["dnsseed.monacoin.org"],versions:{bip32:{private:76066276,public:76067358},bip44:22,private:176,private2:178,public:50,scripthash:55,scripthash2:5}},lo),Vp=Object.assign({},{hashGenesisBlock:"a2b106ceba3be0c6d097b2a6a6aacf9d638ba8258ae478158f449c321061e0b2",port:19403,portRpc:19402,protocol:{magic:4056470269},bech32:"tmona",seedsDns:["testnet-dnsseed.monacoin.org"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:117,scripthash2:196}},lo),Xp={main:Wp,test:Vp},qp={name:"NuBits",per1:1e6,unit:"NBT"},zp=Object.assign({},{hashGenesisBlock:"000003cc2da5a0a289ad0a590c20a8b975219ddc1204efd169e947dd4cbad73f",port:7890,portRpc:14002,protocol:{magic:3652501241},seedsDns:[],versions:{bip32:{private:76066276,public:76067358},bip44:12,private:150,public:25,scripthash:26}},qp),Yp={main:zp},Jp={name:"Namecoin",unit:"NMC"},Qp=Object.assign({},{hashGenesisBlock:"000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770",versions:{bip44:7,private:180,public:52,scripthash:5}},Jp),Zp={main:Qp,test:null},bo={name:"Peercoin",per1:1e6,unit:"PPC",messagePrefix:"Peercoin Signed Message:\n"},eh=Object.assign({},{hashGenesisBlock:"0000000032fe677166d54963b62a4677d8957e87c508eaa4fd7eb1c880cd27e3",port:9901,portRpc:9902,protocol:{magic:3857311974},seedsDns:["seed.peercoin.net","seed2.peercoin.net","seed.peercoin-library.org","ppcseed.ns.7server.net"],versions:{bip32:{private:76066276,public:76067358},bip44:6,private:183,public:55,scripthash:117}},bo),th=Object.assign({},{hashGenesisBlock:"00000001f757bb737f6596503e17cd17b0658ce630cc727c0cca81aec47c9f06",port:9903,portRpc:9904,protocol:{magic:4022399691},seedsDns:["tseed.peercoin.net","tseed2.peercoin.net","tseed.peercoin-library.org"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},bo),rh={main:eh,test:th},nh={name:"Qtum",unit:"QTUM"},ih=Object.assign({},{hashGenesisBlock:"000075aef83cf2853580f8ae8ce6f8c3096cfa21d98334d6e3f95e5582ed986c",port:3888,protocol:{magic:3550924785},bech32:"qc",seedsDns:["qtum3.dynu.net"],versions:{bip32:{private:76066276,public:76067358},bip44:2301,private:128,public:58,scripthash:50}},nh),sh={main:ih},go={name:"Ravencoin",unit:"RVN"},oh=Object.assign({},{hashGenesisBlock:"0000006b444bc2f2ffe627be9d9e7e7a0730000870ef6eb6da46c8eae389df90",port:8767,protocol:{magic:1314275666},bech32:"rc",seedsDns:["seed-raven.bitactivate.com","seed-raven.ravencoin.com","seed-raven.ravencoin.org"],versions:{bip32:{private:76066276,public:76067358},bip44:175,private:128,public:60,scripthash:122}},go),ch=Object.assign({},{hashGenesisBlock:"000000ecfc5e6324a079542221d00e10362bdc894d56500c414060eea8a3ad5a",port:18770,protocol:{magic:1414420050},bech32:"tr",seedsDns:["seed-testnet-raven.bitactivate.com","seed-testnet-raven.ravencoin.com","seed-testnet-raven.ravencoin.org"],versions:{bip32:{private:70615956,public:70617039},bip44:1,private:239,public:111,scripthash:196}},go),ah={main:oh,test:ch},yo={name:"ReddCoin",unit:"RDD"},uh=Object.assign({},{hashGenesisBlock:"b868e0d95a3c3c0e0dadc67ee587aaf9dc8acbf99e3b4b3110fad4eb74c1decc",versions:{bip44:4,private:189,public:61,scripthash:5}},yo),fh=Object.assign({},{hashGenesisBlock:"a12ac9bd4cd26262c53a6277aafc61fe9dfe1e2b05eaa1ca148a5be8b394e35a",versions:{bip44:1,private:239,public:111,scripthash:196}},yo),ph={main:uh,test:fh},Mn={name:"Vertcoin",unit:"VTC"},hh=Object.assign({},{hashGenesisBlock:"4d96a915f49d40b1e5c2844d1ee2dccb90013a990ccea12c492d22110489f0c4",port:5889,protocol:{magic:3669344250},bech32:"vtc",seedsDns:["useast1.vtconline.org","vtc.gertjaap.org","seed.vtc.bryangoodson.org","dnsseed.pknight.ca","seed.orderofthetaco.org","seed.alexturek.org","vertcoin.mbl.cash"],versions:{bip32:{private:76066276,public:76067358},bip44:28,private:128,public:71,scripthash:5}},Mn),lh=Object.assign({},{hashGenesisBlock:"cee8f24feb7a64c8f07916976aa4855decac79b6741a8ec2e32e2747497ad2c9",port:15889,protocol:{magic:1953654134},bech32:"tvtc",seedsDns:["jlovejoy.mit.edu","gertjaap.ddns.net","fr1.vtconline.org","tvtc.vertcoin.org"],versions:{bip32:{private:70615956,public:70617039},private:239,public:74,scripthash:196}},Mn),dh=Object.assign({},{hashGenesisBlock:"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",port:18444,protocol:{magic:3669344250},seedsDns:[],versions:{bip32:{private:70615956,public:70617039},private:239,public:111,scripthash:196}},Mn),bh={main:hh,test:lh,regtest:dh},mo={name:"x42",isProofOfStake:!0},gh=Object.assign({},{unit:"x42",hashGenesisBlock:"04ffe583707a96c1c2eb54af33a4b1dc6d9d8e09fea8c9a7b097ba88f0cb64c4",port:52342,portRpc:52343,protocol:{magic:55731778},seedsDns:["mainnet1.x42seed.host","mainnetnode1.x42seed.host","tech.x42.cloud","x42.seed.blockcore.net"],versions:{bip32:{private:76066276,public:76067358},bip44:424242,private:203,public:75,scripthash:125}},mo),yh=Object.assign({},{unit:"Tx42",hashGenesisBlock:"a92bf124a1e6f237015440d5f1e1999bdef8e321f2d3fdc367eb2f7733b17854",port:62342,portRpc:62343,protocol:{magic:72508994},seedsDns:["testnet1.x42seed.host"],versions:{bip32:{private:76066276,public:76067358},bip44:424242,private:193,public:65,scripthash:196}},mo),mh={main:gh,test:yh},wo={name:"Zcash",unit:"ZEC"},wh=Object.assign({},{hashGenesisBlock:"00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08",port:8233,portRpc:8232,protocol:{magic:1680337188},seedsDns:["dnsseed.z.cash","dnsseed.str4d.xyz","dnsseed.znodes.org"],versions:{bip32:{private:76066276,public:76067358},bip44:133,private:128,public:7352,scripthash:7357}},wo),Sh=Object.assign({},{hashGenesisBlock:"0x05a60a92d99d85997cce3b87616c089f6124d7342af37106edc76126334a2c38",port:18233,portRpc:18232,protocol:{magic:3220773626},seedsDns:["dnsseed.testnet.z.cash"],versions:{bip32:{private:70615956,public:70617039},bip44:133,private:239,public:7461,scripthash:7354}},wo),Eh={main:wh,test:Sh},_h=Ri.Buffer,So=[tp,ip,up,hp,gp,wp,_p,kp,Pp,Np,Hp,Lp,Kp,jp,Xp,Yp,Zp,rh,sh,ah,ph,bh,mh,Eh],Se={};So.forEach(function(e){var t=e.main.unit.toLowerCase(),r=e.main.name.toLowerCase();e.main.testnet=!1,e.main.toBitcoinJS=sr.bind(e.main),e.main.toBitcore=or.bind(e.main),Se[t]=e.main,Se[r]=e.main,e.test&&(e.test.testnet=!0,e.test.toBitcoinJS=sr.bind(e.test),e.test.toBitcore=or.bind(e.test),Se[t+"-test"]=e.test,Se[r+"-test"]=e.test),e.regtest&&(e.regtest.testnet=!0,e.regtest.toBitcoinJS=sr.bind(e.regtest),e.regtest.toBitcore=or.bind(e.regtest),Se[t+"-regtest"]=e.regtest,Se[r+"-regtest"]=e.regtest),e.simnet&&(e.simnet.testnet=!0,e.simnet.toBitcoinJS=sr.bind(e.simnet),e.simnet.toBitcore=or.bind(e.simnet),Se[t+"-simnet"]=e.simnet,Se[r+"-simnet"]=e.simnet)});function Eo(e){var t=e.toLowerCase();return t in Se?Se[t]:null}So.forEach(function(e){Eo[e.main.name.toLowerCase()]=e});function sr(){return Object.assign({},this,{messagePrefix:this.messagePrefix||""+this.name+" Signed Message:\n",bech32:this.bech32,bip32:{public:(this.versions.bip32||{}).public,private:(this.versions.bip32||{}).private},pubKeyHash:this.versions.public,scriptHash:this.versions.scripthash,wif:this.versions.private,dustThreshold:null})}function or(){var e=_h.allocUnsafe(4);return e.writeUInt32BE(this.protocol?this.protocol.magic:0,0),e=e.readUInt32LE(0),Object.assign({},this,{name:this.testnet?"testnet":"livenet",alias:this.testnet?"testnet":"mainnet",pubkeyhash:this.versions.public,privatekey:this.versions.private,scripthash:this.versions.scripthash,xpubkey:(this.versions.bip32||{}).public,xprivkey:(this.versions.bip32||{}).private,networkMagic:e,port:this.port,dnsSeeds:this.seedsDns||[]})}var vh=Eo;const gt=Oo(vh),Th={class:"flex mt-20 items-center space-x-20"},kh={class:"mt-30"},Ih={class:"label"},Oh={class:"output-result"},jh={__name:"decodetx",setup(e){const t=u=>{const l=Dn().$lang.value||"zh_Hans_CN",b=Vn[l]||Vn.zh_Hans_CN||{};return b[u]===void 0?u:b[u]},r=Dn(),n=Lr("01000000017967a5185e907a25225574544c31f7b059c1a191d65b53dcc1554d339c4f9efc010000006a47304402206a2eb16b7b92051d0fa38c133e67684ed064effada1d7f925c842da401d4f22702201f196b10e6e4b4a9fff948e5c5d71ec5da53e90529c8dbd122bff2b1d21dc8a90121039b7bcd0824b9a9164f7ba098408e63e5b7e3cf90835cceb19868f54f8961a825ffffffff014baf2100000000001976a914db4d1141d0048b1ed15839d0b7a4c488cd368b0e88ac00000000"),i=Lr("bitcoinTest"),o=Po([{label:"Bitcoin",value:"bitcoin"},{label:"Bitcoin Testnet",value:"bitcoinTest"},{label:"Litecoin",value:"litecoin"},{label:"Litecoin Testnet",value:"litecoinTest"},{label:"Dogecoin",value:"dogecoin"},{label:"Dogecoin Testnet",value:"dogecoinTest"}]),s=Lr(),c=Ao(()=>{switch(i.value){case"bitcoinTest":return gt.bitcoin.test.toBitcoinJS();case"litecoin":return gt.litecoin.main.toBitcoinJS();case"litecoinTest":return gt.litecoin.test.toBitcoinJS();case"dogecoin":return gt.dogecoin.main.toBitcoinJS();case"dogecoinTest":return gt.dogecoin.test.toBitcoinJS();default:return gt.bitcoin.main.toBitcoinJS()}}),a=u=>{try{return ge.address.fromOutputScript(u,c.value).toString()}catch(d){}return""},p=u=>{const d=c.value;try{return ge.payments.p2pkh({output:u,network:d}),"Pay To Public Key Hash"}catch(l){}try{return ge.payments.p2sh({output:u,network:d}),"Pay To Script Hash"}catch(l){}try{return ge.payments.p2wpkh({output:u,network:d}),"Pay To Witness Public Key Hash"}catch(l){}try{return ge.payments.p2wsh({output:u,network:d}),"Pay To Witness Script Hash"}catch(l){}try{return ge.payments.p2tr({output:u,network:d}),"Pay to Taproot"}catch(l){}try{return ge.payments.p2ms({output:u,network:d}),"Pay To Multi Pubkey Hash"}catch(l){}try{return ge.payments.p2pk({output:u,network:d}),"Pay To Pubkey"}catch(l){}try{return _toFutureSegwitAddress(u,d)}catch(l){}return""},f=()=>{try{const u=ge.Transaction.fromHex(n.value),d={...u,size:u.toHex().length/2,virtualSize:u.virtualSize(),hash:u.getHash().reverse().toString("hex")};delete d.ins,delete d.outs,d.inputs=u.ins.map(l=>({...l,script:l.script.toString("hex"),hash:l.hash.reverse().toString("hex"),witness:l.witness.map(g=>g.toString("hex"))})),d.outputs=u.outs.map(l=>{const b={...l,script:l.script.toString("hex")},g=a(l.script);g&&(b.address=g);const y=p(l.script);return y&&(b.scriptType=y),b}),s.value=d}catch(u){r.$message.error(t("请输入正确的Tr_3f32"))}};return xo(()=>{f()}),(u,d)=>{const l=_o,b=vo,g=To,y=ko,S=Io;return Mr(),Gn(S,{class:"p-decodetx"},{default:Fr(()=>[d[4]||(d[4]=lt("p",{class:"label"},"Transaction Hex",-1)),Vt(l,{modelValue:At(n),"onUpdate:modelValue":d[0]||(d[0]=v=>jn(n)?n.value=v:null),type:"textarea",placeholder:t("请输入内容"),rows:6,resize:"none"},null,8,["modelValue","placeholder"]),lt("div",Th,[d[3]||(d[3]=lt("p",{class:"label pb-0"},"Network",-1)),Vt(g,{modelValue:At(i),"onUpdate:modelValue":d[1]||(d[1]=v=>jn(i)?i.value=v:null),placeholder:t("请选择"),class:"input-select"},{default:Fr(()=>[(Mr(!0),No(Uo,null,Bo(At(o),v=>(Mr(),Gn(b,{key:v.value,label:v.label,value:v.value},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder"])]),Vt(y,{class:"w-200 mt-30",type:"primary",onClick:d[2]||(d[2]=v=>f())},{default:Fr(()=>[Ho(Wn(t("解码交易")),1)]),_:1}),lt("div",kh,[lt("p",Ih,Wn(t("解码结果")),1),lt("div",Oh,[Vt(At(Co),{data:At(s),"show-length":"","show-line":"","show-line-number":"","show-icon":""},null,8,["data"])])])]),_:1})}}};export{jh as default};
