@multiplechain/bitcoin 0.4.23 → 0.4.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -131,5 +131,5 @@ const B=f.fromX(!1,O.slice(1,S.TAPROOT_CONTROL_BASE_SIZE));//! The output pubkey
131
131
  const C=f.fromX(!1,I),P=S.computeTaprootMerkleRoot(O,R);return C.checkTapTweak(B,P,O)}catch{return!1}},S.prototype.step=function(){var O=(this.flags&S.SCRIPT_VERIFY_MINIMALDATA)!==0,I=this.vfExec.indexOf(!1)===-1,R,B,C,P,L,H,K,V,te,U,j,D,b,a,h,u,p;this.execdata=this.execdata||{},this.execdata.codeseparatorPosInit||(this.execdata.codeseparatorPos=new n(4294967295),this.execdata.codeseparatorPosInit=!0);var y=this.script.chunks[this.pc];this.pc++;var m=y.opcodenum;if(t.isUndefined(m))return this.errstr="SCRIPT_ERR_UNDEFINED_OPCODE",!1;if(y.buf&&y.buf.length>S.MAX_SCRIPT_ELEMENT_SIZE)return this.errstr="SCRIPT_ERR_PUSH_SIZE",!1;if((this.sigversion===i.Version.BASE||this.sigversion===i.Version.WITNESS_V0)&&m>r.OP_16&&++this.nOpCount>201)return this.errstr="SCRIPT_ERR_OP_COUNT",!1;if(m===r.OP_CAT||m===r.OP_SUBSTR||m===r.OP_LEFT||m===r.OP_RIGHT||m===r.OP_INVERT||m===r.OP_AND||m===r.OP_OR||m===r.OP_XOR||m===r.OP_2MUL||m===r.OP_2DIV||m===r.OP_MUL||m===r.OP_DIV||m===r.OP_MOD||m===r.OP_LSHIFT||m===r.OP_RSHIFT)return this.errstr="SCRIPT_ERR_DISABLED_OPCODE",!1;if(m==r.OP_CODESEPARATOR&&this.sigversion===i.Version.BASE&&this.flags&S.SCRIPT_VERIFY_CONST_SCRIPTCODE)return this.errstr="SCRIPT_ERR_OP_CODESEPARATOR",!1;if(I&&0<=m&&m<=r.OP_PUSHDATA4){if(O&&!this.script.checkMinimalPush(this.pc-1))return this.errstr="SCRIPT_ERR_MINIMALDATA",!1;if(!y.buf)this.stack.push(S.false);else{if(y.len!==y.buf.length)throw new Error("Length of push value not equal to length of data");this.stack.push(y.buf)}}else if(I||r.OP_IF<=m&&m<=r.OP_ENDIF)switch(m){case r.OP_1NEGATE:case r.OP_1:case r.OP_2:case r.OP_3:case r.OP_4:case r.OP_5:case r.OP_6:case r.OP_7:case r.OP_8:case r.OP_9:case r.OP_10:case r.OP_11:case r.OP_12:case r.OP_13:case r.OP_14:case r.OP_15:case r.OP_16:L=m-(r.OP_1-1),R=new n(L).toScriptNumBuffer(),this.stack.push(R);break;case r.OP_NOP:break;case r.OP_NOP2:case r.OP_CHECKLOCKTIMEVERIFY:if(!(this.flags&S.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)){if(this.flags&S.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS)return this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS",!1;break}if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;var w=n.fromScriptNumBuffer(this.stack[this.stack.length-1],O,5);if(w.lt(new n(0)))return this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME",!1;if(!this.checkLockTime(w))return this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME",!1;break;case r.OP_NOP3:case r.OP_CHECKSEQUENCEVERIFY:if(!(this.flags&S.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY)){if(this.flags&S.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS)return this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS",!1;break}if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;var d=n.fromScriptNumBuffer(this.stack[this.stack.length-1],O,5);if(d.lt(new n(0)))return this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME",!1;if(d&S.SEQUENCE_LOCKTIME_DISABLE_FLAG)break;if(!this.checkSequence(d))return this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME",!1;break;case r.OP_NOP1:case r.OP_NOP4:case r.OP_NOP5:case r.OP_NOP6:case r.OP_NOP7:case r.OP_NOP8:case r.OP_NOP9:case r.OP_NOP10:if(this.flags&S.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS)return this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS",!1;break;case r.OP_IF:case r.OP_NOTIF:{if(u=!1,I){if(this.stack.length<1)return this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL",!1;if(R=this.stack[this.stack.length-1],this.sigversion===i.Version.TAPSCRIPT&&(R.length>1||R.length===1&&R[0]!==1))return this.errstr="SCRIPT_ERR_TAPSCRIPT_MINIMALIF",!1;if(this.sigversion===i.Version.WITNESS_V0&&this.flags&S.SCRIPT_VERIFY_MINIMALIF){if(R=this.stack[this.stack.length-1],R.length>1)return this.errstr="SCRIPT_ERR_MINIMALIF",!1;if(R.length==1&&R[0]!=1)return this.errstr="SCRIPT_ERR_MINIMALIF",!1}u=S.castToBool(R),m===r.OP_NOTIF&&(u=!u),this.stack.pop()}this.vfExec.push(u)}break;case r.OP_ELSE:{if(this.vfExec.length===0)return this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL",!1;this.vfExec[this.vfExec.length-1]=!this.vfExec[this.vfExec.length-1]}break;case r.OP_ENDIF:{if(this.vfExec.length===0)return this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL",!1;this.vfExec.pop()}break;case r.OP_VERIFY:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;if(R=this.stack[this.stack.length-1],u=S.castToBool(R),u)this.stack.pop();else return this.errstr="SCRIPT_ERR_VERIFY",!1}break;case r.OP_RETURN:return this.errstr="SCRIPT_ERR_OP_RETURN",!1;case r.OP_TOALTSTACK:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.altstack.push(this.stack.pop())}break;case r.OP_FROMALTSTACK:{if(this.altstack.length<1)return this.errstr="SCRIPT_ERR_INVALID_ALTSTACK_OPERATION",!1;this.stack.push(this.altstack.pop())}break;case r.OP_2DROP:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.pop(),this.stack.pop()}break;case r.OP_2DUP:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;B=this.stack[this.stack.length-2],C=this.stack[this.stack.length-1],this.stack.push(B),this.stack.push(C)}break;case r.OP_3DUP:{if(this.stack.length<3)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;B=this.stack[this.stack.length-3],C=this.stack[this.stack.length-2];var c=this.stack[this.stack.length-1];this.stack.push(B),this.stack.push(C),this.stack.push(c)}break;case r.OP_2OVER:{if(this.stack.length<4)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;B=this.stack[this.stack.length-4],C=this.stack[this.stack.length-3],this.stack.push(B),this.stack.push(C)}break;case r.OP_2ROT:{if(this.stack.length<6)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;P=this.stack.splice(this.stack.length-6,2),this.stack.push(P[0]),this.stack.push(P[1])}break;case r.OP_2SWAP:{if(this.stack.length<4)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;P=this.stack.splice(this.stack.length-4,2),this.stack.push(P[0]),this.stack.push(P[1])}break;case r.OP_IFDUP:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;R=this.stack[this.stack.length-1],u=S.castToBool(R),u&&this.stack.push(R)}break;case r.OP_DEPTH:R=new n(this.stack.length).toScriptNumBuffer(),this.stack.push(R);break;case r.OP_DROP:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.pop()}break;case r.OP_DUP:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.push(this.stack[this.stack.length-1])}break;case r.OP_NIP:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.splice(this.stack.length-2,1)}break;case r.OP_OVER:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.push(this.stack[this.stack.length-2])}break;case r.OP_PICK:case r.OP_ROLL:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;if(R=this.stack[this.stack.length-1],V=n.fromScriptNumBuffer(R,O),L=V.toNumber(),this.stack.pop(),L<0||L>=this.stack.length)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;R=this.stack[this.stack.length-L-1],m===r.OP_ROLL&&this.stack.splice(this.stack.length-L-1,1),this.stack.push(R)}break;case r.OP_ROT:{if(this.stack.length<3)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;H=this.stack[this.stack.length-3],K=this.stack[this.stack.length-2];var x=this.stack[this.stack.length-1];this.stack[this.stack.length-3]=K,this.stack[this.stack.length-2]=x,this.stack[this.stack.length-1]=H}break;case r.OP_SWAP:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;H=this.stack[this.stack.length-2],K=this.stack[this.stack.length-1],this.stack[this.stack.length-2]=K,this.stack[this.stack.length-1]=H}break;case r.OP_TUCK:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;this.stack.splice(this.stack.length-2,0,this.stack[this.stack.length-1])}break;case r.OP_SIZE:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;V=new n(this.stack[this.stack.length-1].length),this.stack.push(V.toScriptNumBuffer())}break;case r.OP_EQUAL:case r.OP_EQUALVERIFY:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;B=this.stack[this.stack.length-2],C=this.stack[this.stack.length-1];var M=B.toString("hex")===C.toString("hex");if(this.stack.pop(),this.stack.pop(),this.stack.push(M?S.true:S.false),m===r.OP_EQUALVERIFY)if(M)this.stack.pop();else return this.errstr="SCRIPT_ERR_EQUALVERIFY",!1}break;case r.OP_1ADD:case r.OP_1SUB:case r.OP_NEGATE:case r.OP_ABS:case r.OP_NOT:case r.OP_0NOTEQUAL:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;switch(R=this.stack[this.stack.length-1],V=n.fromScriptNumBuffer(R,O),m){case r.OP_1ADD:V=V.add(n.One);break;case r.OP_1SUB:V=V.sub(n.One);break;case r.OP_NEGATE:V=V.neg();break;case r.OP_ABS:V.cmp(n.Zero)<0&&(V=V.neg());break;case r.OP_NOT:V=new n((V.cmp(n.Zero)===0)+0);break;case r.OP_0NOTEQUAL:V=new n((V.cmp(n.Zero)!==0)+0);break}this.stack.pop(),this.stack.push(V.toScriptNumBuffer())}break;case r.OP_ADD:case r.OP_SUB:case r.OP_BOOLAND:case r.OP_BOOLOR:case r.OP_NUMEQUAL:case r.OP_NUMEQUALVERIFY:case r.OP_NUMNOTEQUAL:case r.OP_LESSTHAN:case r.OP_GREATERTHAN:case r.OP_LESSTHANOREQUAL:case r.OP_GREATERTHANOREQUAL:case r.OP_MIN:case r.OP_MAX:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;switch(te=n.fromScriptNumBuffer(this.stack[this.stack.length-2],O),U=n.fromScriptNumBuffer(this.stack[this.stack.length-1],O),V=new n(0),m){case r.OP_ADD:V=te.add(U);break;case r.OP_SUB:V=te.sub(U);break;case r.OP_BOOLAND:V=new n((te.cmp(n.Zero)!==0&&U.cmp(n.Zero)!==0)+0);break;case r.OP_BOOLOR:V=new n((te.cmp(n.Zero)!==0||U.cmp(n.Zero)!==0)+0);break;case r.OP_NUMEQUAL:V=new n((te.cmp(U)===0)+0);break;case r.OP_NUMEQUALVERIFY:V=new n((te.cmp(U)===0)+0);break;case r.OP_NUMNOTEQUAL:V=new n((te.cmp(U)!==0)+0);break;case r.OP_LESSTHAN:V=new n((te.cmp(U)<0)+0);break;case r.OP_GREATERTHAN:V=new n((te.cmp(U)>0)+0);break;case r.OP_LESSTHANOREQUAL:V=new n((te.cmp(U)<=0)+0);break;case r.OP_GREATERTHANOREQUAL:V=new n((te.cmp(U)>=0)+0);break;case r.OP_MIN:V=te.cmp(U)<0?te:U;break;case r.OP_MAX:V=te.cmp(U)>0?te:U;break}if(this.stack.pop(),this.stack.pop(),this.stack.push(V.toScriptNumBuffer()),m===r.OP_NUMEQUALVERIFY)if(S.castToBool(this.stack[this.stack.length-1]))this.stack.pop();else return this.errstr="SCRIPT_ERR_NUMEQUALVERIFY",!1}break;case r.OP_WITHIN:{if(this.stack.length<3)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;te=n.fromScriptNumBuffer(this.stack[this.stack.length-3],O),U=n.fromScriptNumBuffer(this.stack[this.stack.length-2],O);var N=n.fromScriptNumBuffer(this.stack[this.stack.length-1],O);u=U.cmp(te)<=0&&te.cmp(N)<0,this.stack.pop(),this.stack.pop(),this.stack.pop(),this.stack.push(u?S.true:S.false)}break;case r.OP_RIPEMD160:case r.OP_SHA1:case r.OP_SHA256:case r.OP_HASH160:case r.OP_HASH256:{if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;R=this.stack[this.stack.length-1];var Y;m===r.OP_RIPEMD160?Y=s.ripemd160(R):m===r.OP_SHA1?Y=s.sha1(R):m===r.OP_SHA256?Y=s.sha256(R):m===r.OP_HASH160?Y=s.sha256ripemd160(R):m===r.OP_HASH256&&(Y=s.sha256sha256(R)),this.stack.pop(),this.stack.push(Y)}break;case r.OP_CODESEPARATOR:this.pbegincodehash=this.pc,this.execdata.codeseparatorPos=this.pc-1;break;case r.OP_CHECKSIG:case r.OP_CHECKSIGVERIFY:{if(this.stack.length<2)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;j=this.stack[this.stack.length-2],D=this.stack[this.stack.length-1];const{success:ve,result:me}=this._evalCheckSig(j,D);if(!me)return!1;if(this.stack.pop(),this.stack.pop(),this.stack.push(ve?S.true:S.false),m===r.OP_CHECKSIGVERIFY)if(ve)this.stack.pop();else return this.errstr="SCRIPT_ERR_CHECKSIGVERIFY",!1}break;case r.OP_CHECKSIGADD:{if(this.sigversion==i.Version.BASE||this.sigversion==i.Version.WITNESS_V0)return this.errstr="SCRIPT_ERR_BAD_OPCODE",!1;if(this.stack.length<3)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;let ve=this.stack[this.stack.length-3],me=this.stack[this.stack.length-2],_e=this.stack[this.stack.length-1];me=n.fromScriptNumBuffer(me,O);const{success:Pe,result:qe}=this._evalCheckSig(ve,_e);if(!qe)return!1;this.stack.pop(),this.stack.pop(),this.stack.pop(),this.stack.push(me.addn(Pe?1:0).toScriptNumBuffer())}break;case r.OP_CHECKMULTISIG:case r.OP_CHECKMULTISIGVERIFY:{var se=1;if(this.stack.length<se)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;var Z=n.fromScriptNumBuffer(this.stack[this.stack.length-se],O).toNumber();if(Z<0||Z>20)return this.errstr="SCRIPT_ERR_PUBKEY_COUNT",!1;if(this.nOpCount+=Z,this.nOpCount>201)return this.errstr="SCRIPT_ERR_OP_COUNT",!1;var W=++se;se+=Z;var Q=Z+2;if(this.stack.length<se)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;var ee=n.fromScriptNumBuffer(this.stack[this.stack.length-se],O).toNumber();if(ee<0||ee>Z)return this.errstr="SCRIPT_ERR_SIG_COUNT",!1;var ce=++se;if(se+=ee,this.stack.length<se)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;b=new e().set({chunks:this.script.chunks.slice(this.pbegincodehash)});for(var X=0;X<ee;X++)j=this.stack[this.stack.length-ce-X],b.findAndDelete(new e().add(j));for(p=!0;p&&ee>0;){if(j=this.stack[this.stack.length-ce],D=this.stack[this.stack.length-W],!this.checkSignatureEncoding(j)||!this.checkPubkeyEncoding(D))return!1;var $;try{a=i.fromTxFormat(j),h=f.fromBuffer(D,!1),$=this.tx.verifySignature(a,h,this.nin,b,this.sigversion,this.satoshis,this.execdata)}catch{$=!1}$&&(ce++,ee--),W++,Z--,ee>Z&&(p=!1)}for(;se-- >1;){if(!p&&this.flags&S.SCRIPT_VERIFY_NULLFAIL&&!Q&&this.stack[this.stack.length-1].length)return this.errstr="SCRIPT_ERR_NULLFAIL",!1;Q>0&&Q--,this.stack.pop()}if(this.stack.length<1)return this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION",!1;if(this.flags&S.SCRIPT_VERIFY_NULLDUMMY&&this.stack[this.stack.length-1].length)return this.errstr="SCRIPT_ERR_SIG_NULLDUMMY",!1;if(this.stack.pop(),this.stack.push(p?S.true:S.false),m===r.OP_CHECKMULTISIGVERIFY)if(p)this.stack.pop();else return this.errstr="SCRIPT_ERR_CHECKMULTISIGVERIFY",!1}break;default:return this.errstr="SCRIPT_ERR_BAD_OPCODE",!1}return this.stack.length+this.altstack.length>S.MAX_STACK_SIZE?(this.errstr="SCRIPT_ERR_STACK_SIZE",!1):!0},$g}var G_;function ti(){return G_||(G_=1,Sl.exports=E_(),Sl.exports.Interpreter=W_()),Sl.exports}var Zg,$_;function Ds(){if($_)return Zg;$_=1;var t=Xt,e=$t,r=Oi,n=ah,s=kH,i=Jo,f=kr,l=nn,g=Us();function _(A,S,O,I){if(!(this instanceof _))return new _(A,S,O);if(t.isArray(A)&&t.isNumber(S))return _.createMultisig(A,S,O,!1,I);if(A instanceof _)return A;if(e.checkArgument(A,"First argument is required, please include address data.","guide/address.html"),S&&!i.get(S))throw new TypeError('Second argument must be "livenet" or "testnet".');if(O&&O!==_.PayToPublicKeyHash&&O!==_.PayToScriptHash&&O!==_.PayToWitnessPublicKeyHash&&O!==_.PayToWitnessScriptHash&&O!==_.PayToTaproot)throw new TypeError('Third argument must be "pubkeyhash", "scripthash", "witnesspubkeyhash", "witnessscripthash", or "taproot".');var R=this._classifyArguments(A,S,O);return R.network=R.network||i.get(S)||i.defaultNetwork,R.type=R.type||O||_.PayToPublicKeyHash,l.defineImmutable(this,{hashBuffer:R.hashBuffer,network:R.network,type:R.type}),this}_.prototype._classifyArguments=function(A,S,O){if((A instanceof pe||A instanceof Uint8Array)&&(A.length===20||A.length===32))return _._transformHash(A,S,O);if((A instanceof pe||A instanceof Uint8Array)&&A.length>=21)return _._transformBuffer(A,S,O);if(A instanceof g)return _._transformPublicKey(A,S,O);if(A instanceof E)return _._transformScript(A,S);if(typeof A=="string")return _._transformString(A,S,O);if(t.isObject(A))return _._transformObject(A);throw new TypeError("First argument is an unrecognized data format.")},_.PayToPublicKeyHash="pubkeyhash",_.PayToScriptHash="scripthash",_.PayToWitnessPublicKeyHash="witnesspubkeyhash",_.PayToWitnessScriptHash="witnessscripthash",_.PayToTaproot="taproot",_._transformHash=function(A,S,O){var I={};if(!(A instanceof pe)&&!(A instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(A.length!==20&&A.length!==32)throw new TypeError("Address hashbuffers must be either 20 or 32 bytes.");return I.hashBuffer=A,I.network=i.get(S)||i.defaultNetwork,I.type=O,I},_._transformObject=function(A){return e.checkArgument(A.hash||A.hashBuffer,"Must provide a `hash` or `hashBuffer` property"),e.checkArgument(A.type,"Must provide a `type` property"),{hashBuffer:A.hash?pe.from(A.hash,"hex"):A.hashBuffer,network:i.get(A.network)||i.defaultNetwork,type:A.type}},_._classifyFromVersion=function(A){var S={};if(A.length>21){var O=s.decode(A.toString("utf8"));if(O.version!==0&&O.version!==1)throw new TypeError("Only witness v0 and v1 addresses are supported.");if(O.version===0)if(O.data.length===20)S.type=_.PayToWitnessPublicKeyHash;else if(O.data.length===32)S.type=_.PayToWitnessScriptHash;else throw new TypeError("Witness data must be either 20 or 32 bytes.");else if(O.version===1)if(O.data.length===32)S.type=_.PayToTaproot;else throw new TypeError("Witness data must be 32 bytes for v1");S.network=i.get(O.prefix,"bech32prefix")}else{var I=i.get(A[0],"pubkeyhash"),R=i.get(A[0],"scripthash");I?(S.network=I,S.type=_.PayToPublicKeyHash):R&&(S.network=R,S.type=_.PayToScriptHash)}return S},_._transformBuffer=function(A,S,O){var I={};if(!(A instanceof pe)&&!(A instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(A.length<21)throw new TypeError("Address buffer is incorrect length.");var R=i.get(S),B=_._classifyFromVersion(A);if(S&&!R)throw new TypeError("Unknown network");if(!B.network||R&&R.xpubkey!==B.network.xpubkey)throw new TypeError("Address has mismatched network type.");if(!B.type||O&&O!==B.type)throw new TypeError("Address has mismatched type.");return A.length>21?I.hashBuffer=s.decode(A.toString("utf8")).data:I.hashBuffer=A.slice(1),I.network=R||B.network,I.type=B.type,I},_._transformPublicKey=function(A,S,O){var I={};if(!(A instanceof g))throw new TypeError("Address must be an instance of PublicKey.");if(O&&O!==_.PayToScriptHash&&O!==_.PayToWitnessPublicKeyHash&&O!==_.PayToPublicKeyHash&&O!==_.PayToTaproot)throw new TypeError("Type must be either pubkeyhash, witnesspubkeyhash, scripthash, or taproot to transform public key.");if(!A.compressed&&(O===_.PayToScriptHash||O===_.PayToWitnessPublicKeyHash))throw new TypeError("Witness addresses must use compressed public keys.");return O===_.PayToScriptHash?I.hashBuffer=f.sha256ripemd160(E.buildWitnessV0Out(A).toBuffer()):O===_.PayToTaproot?I.hashBuffer=A.createTapTweak().tweakedPubKey:I.hashBuffer=f.sha256ripemd160(A.toBuffer()),I.type=O||_.PayToPublicKeyHash,I},_._transformScript=function(A,S){e.checkArgument(A instanceof E,"script must be a Script instance");var O=A.getAddressInfo(S);if(!O)throw new r.Script.CantDeriveAddress(A);return O},_.createMultisig=function(A,S,O,I,R){if(O=O||A[0].network||i.defaultNetwork,R&&R!==_.PayToScriptHash&&R!==_.PayToWitnessScriptHash)throw new TypeError("Type must be either scripthash or witnessscripthash to create multisig.");if(I||R===_.PayToWitnessScriptHash){A=t.map(A,g);for(var B=0;B<A.length;B++)if(!A[B].compressed)throw new TypeError("Witness addresses must use compressed public keys.")}var C=E.buildMultisigOut(A,S);return I?_.payingTo(E.buildWitnessMultisigOutFromScript(C),O):_.payingTo(C,O,R)},_._transformString=function(A,S,O){if(typeof A!="string")throw new TypeError("data parameter supplied is not a string.");if(A.length>100)throw new TypeError("address string is too long");if(S&&!i.get(S))throw new TypeError("Unknown network");A=A.trim();try{var R=_._transformBuffer(pe.from(A,"utf8"),S,O);return R}catch(B){if(O===_.PayToWitnessPublicKeyHash||O===_.PayToWitnessScriptHash||O===_.PayToTaproot)throw B}var I=n.decode(A),R=_._transformBuffer(I,S,O);return R},_.fromPublicKey=function(A,S,O){var I=_._transformPublicKey(A,S,O);return S=S||i.defaultNetwork,new _(I.hashBuffer,S,I.type)},_.fromPublicKeyHash=function(A,S){var O=_._transformHash(A);return new _(O.hashBuffer,S,_.PayToPublicKeyHash)},_.fromScriptHash=function(A,S,R){e.checkArgument(A,"hash parameter is required");var I=_._transformHash(A);if(R===_.PayToWitnessScriptHash&&A.length!==32)throw new TypeError("Address hashbuffer must be exactly 32 bytes for v0 witness script hash.");var R=R||_.PayToScriptHash;return new _(I.hashBuffer,S,R)},_.payingTo=function(A,S,R){e.checkArgument(A,"script is required"),e.checkArgument(A instanceof E,"script must be instance of Script");var I;R===_.PayToWitnessScriptHash?I=f.sha256(A.toBuffer()):I=f.sha256ripemd160(A.toBuffer());var R=R||_.PayToScriptHash;return _.fromScriptHash(I,S,R)},_.fromScript=function(A,S){e.checkArgument(A instanceof E,"script must be a Script instance");var O=_._transformScript(A,S);return new _(O.hashBuffer,S,O.type)},_.fromBuffer=function(A,S,O){var I=_._transformBuffer(A,S,O);return new _(I.hashBuffer,I.network,I.type)},_.fromString=function(A,S,O){var I=_._transformString(A,S,O);return new _(I.hashBuffer,I.network,I.type)},_.fromObject=function(S){e.checkState(l.isHexa(S.hash),'Unexpected hash property, "'+S.hash+'", expected to be hex.');var O=pe.from(S.hash,"hex");return new _(O,S.network,S.type)},_.getValidationError=function(A,S,O){var I;try{new _(A,S,O)}catch(R){I=R}return I},_.isValid=function(A,S,O){return!_.getValidationError(A,S,O)},_.prototype.isPayToPublicKeyHash=function(){return this.type===_.PayToPublicKeyHash},_.prototype.isPayToScriptHash=function(){return this.type===_.PayToScriptHash},_.prototype.isPayToWitnessPublicKeyHash=function(){return this.type===_.PayToWitnessPublicKeyHash},_.prototype.isPayToWitnessScriptHash=function(){return this.type===_.PayToWitnessScriptHash},_.prototype.isPayToTaproot=function(){return this.type===_.PayToTaproot},_.prototype.toBuffer=function(){if(this.isPayToWitnessPublicKeyHash()||this.isPayToWitnessScriptHash())return pe.from(this.toString(),"utf8");var A=pe.from([this.network[this.type]]);return pe.concat([A,this.hashBuffer])},_.prototype.toObject=_.prototype.toJSON=function(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}},_.prototype.toString=function(){if(this.isPayToWitnessPublicKeyHash()||this.isPayToWitnessScriptHash()||this.isPayToTaproot()){let A=this.network.bech32prefix,S=0,O=s.encodings.BECH32;return this.isPayToTaproot()&&(S=1,O=s.encodings.BECH32M),s.encode(A,S,this.hashBuffer,O)}return n.encode(this.toBuffer())},_.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"},Zg=_;var E=ti();return Zg}function rf(){}rf.getRandomBuffer=function(t){return pt.browser?rf.getRandomBufferBrowser(t):rf.getRandomBufferNode(t)},rf.getRandomBufferNode=function(t){var e=qo();return e.randomBytes(t)},rf.getRandomBufferBrowser=function(t){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)var e=window.crypto;else if(window.msCrypto&&window.msCrypto.getRandomValues)var e=window.msCrypto;else throw new Error("window.crypto.getRandomValues not available");var r=new Uint8Array(t);e.getRandomValues(r);var n=pe.from(r);return n},rf.getPseudoRandomBuffer=function(t){for(var e=4294967296,r=pe.alloc(t),n,s=0;s<=t;s++){var i=Math.floor(s/4),f=s-i*4;f===0?(n=Math.random()*e,r[s]=n&255):r[s]=(n=n>>>8)&255}return r};var Rl=rf,Xg,Z_;function nf(){if(Z_)return Xg;Z_=1;var t=Xt,e=Ds(),r=ah,n=sn,s=nn,i=Jo,f=Zo,l=Us(),g=Rl,_=$t;const E=Xa;function A(S,O){if(!(this instanceof A))return new A(S,O);if(S instanceof A)return S;var I=this._classifyArguments(S,O);if(!I.bn||I.bn.cmp(new n(0))===0)throw new TypeError("Number can not be equal to zero, undefined, null or false");if(!I.bn.lt(f.getN()))throw new TypeError("Number must be less than N");if(typeof I.network>"u")throw new TypeError('Must specify the network ("livenet" or "testnet")');return s.defineImmutable(this,{bn:I.bn,compressed:I.compressed,network:I.network}),Object.defineProperty(this,"publicKey",{configurable:!1,enumerable:!0,get:this.toPublicKey.bind(this)}),this}return A.prototype._classifyArguments=function(S,O){var I={compressed:!0,network:O?i.get(O):i.defaultNetwork};if(t.isUndefined(S)||t.isNull(S))I.bn=A._getRandomBN();else if(S instanceof n)I.bn=S;else if(S instanceof pe||S instanceof Uint8Array)I=A._transformBuffer(S,O);else if(S.bn&&S.network)I=A._transformObject(S);else if(!O&&i.get(S))I.bn=A._getRandomBN(),I.network=i.get(S);else if(typeof S=="string")s.isHexa(S)?I.bn=new n(pe.from(S,"hex")):I=A._transformWIF(S,O);else throw new TypeError("First argument is an unrecognized data type.");return I},A._getRandomBN=function(){var S,O;do{var I=g.getRandomBuffer(32);O=n.fromBuffer(I),S=O.lt(f.getN())}while(!S);return O},A._transformBuffer=function(S,O){var I={};if(S.length===32)return A._transformBNBuffer(S,O);if(I.network=i.get(S[0],"privatekey"),!I.network)throw new Error("Invalid network");if(O&&I.network!==i.get(O))throw new TypeError("Private key network mismatch");if(S.length===34&&S[33]===1)I.compressed=!0;else if(S.length===33)I.compressed=!1;else throw new Error("Length of buffer must be 33 (uncompressed) or 34 (compressed)");return I.bn=n.fromBuffer(S.slice(1,33)),I},A._transformBNBuffer=function(S,O){var I={};return I.network=i.get(O)||i.defaultNetwork,I.bn=n.fromBuffer(S),I.compressed=!1,I},A._transformWIF=function(S,O){return A._transformBuffer(r.decode(S),O)},A.fromBuffer=function(S,O){return new A(S,O)},A._transformObject=function(S){var O=new n(S.bn,"hex"),I=i.get(S.network);return{bn:O,network:I,compressed:S.compressed}},A.fromString=A.fromWIF=function(S){return _.checkArgument(t.isString(S),"First argument is expected to be a string."),new A(S)},A.fromObject=function(S){return _.checkArgument(t.isObject(S),"First argument is expected to be an object."),new A(S)},A.fromRandom=function(S){var O=A._getRandomBN();return new A(O,S)},A.getValidationError=function(S,O){var I;try{new A(S,O)}catch(R){I=R}return I},A.isValid=function(S,O){return S?!A.getValidationError(S,O):!1},A.prototype.toString=function(){return this.toBuffer().toString("hex")},A.prototype.toWIF=function(){var S=this.network,O=this.compressed,I;return O?I=pe.concat([pe.from([S.privatekey]),this.bn.toBuffer({size:32}),pe.from([1])]):I=pe.concat([pe.from([S.privatekey]),this.bn.toBuffer({size:32})]),r.encode(I)},A.prototype.toBigNumber=function(){return this.bn},A.prototype.toBuffer=function(){return this.bn.toBuffer({size:32})},A.prototype.toBufferNoPadding=function(){return this.bn.toBuffer()},A.prototype.toPublicKey=function(){return this._pubkey||(this._pubkey=l.fromPrivateKey(this)),this._pubkey},A.prototype.toAddress=function(S,O){var I=this.toPublicKey();return e.fromPublicKey(I,S||this.network,O)},A.prototype.toObject=A.prototype.toJSON=function(){return{bn:this.bn.toString("hex"),compressed:this.compressed,network:this.network.toString()}},A.prototype.createTapTweak=function(S){const O=f.getN(),I=f.getG().mul(this.bn),R=I.y.isEven()?this.bn:O.sub(this.bn),B=new E("TapTweak");B.write(I.x.toBuffer({size:32})),S&&(_.checkArgument(pe.isBuffer(S)&&S.length===32,"merkleRoot must be 32 byte buffer"),B.write(S));const C=B.finalize();return _.checkState(n.fromBuffer(C).lt(O),"TapTweak hash failed secp256k1 order check"),{tweakedPrivKey:R.add(new n(C)).mod(O).toBuffer({size:32})}},A.prototype.inspect=function(){var S=this.compressed?"":", uncompressed";return"<PrivateKey: "+this.toString()+", network: "+this.network+S+">"},Xg=A,Xg}var Jg,X_;function Us(){if(X_)return Jg;X_=1;var t=sn,e=Zo,r=kr,n=nn,s=Jo,i=Xt,f=$t;const l=Xa;function g(_,E){if(!(this instanceof g))return new g(_,E);if(f.checkArgument(_,"First argument is required, please include public key data."),_ instanceof g)return _;E=E||{};var A=this._classifyArgs(_,E);return A.point.validate(),n.defineImmutable(this,{point:A.point,compressed:A.compressed,network:A.network||s.defaultNetwork}),this}return g.prototype._classifyArgs=function(_,E){var A={compressed:i.isUndefined(E.compressed)||E.compressed};if(_ instanceof e)A.point=_;else if(_.x&&_.y)A=g._transformObject(_);else if(typeof _=="string")A=g._transformDER(pe.from(_,"hex"));else if(g._isBuffer(_))A=g._transformDER(_);else if(g._isPrivateKey(_))A=g._transformPrivateKey(_);else throw new TypeError("First argument is an unrecognized data format.");return A.network||(A.network=i.isUndefined(E.network)?void 0:s.get(E.network)),A},g._isPrivateKey=function(_){var E=nf();return _ instanceof E},g._isBuffer=function(_){return _ instanceof pe||_ instanceof Uint8Array},g._transformPrivateKey=function(_){f.checkArgument(g._isPrivateKey(_),"Must be an instance of PrivateKey");var E={};return E.point=e.getG().mul(_.bn),E.compressed=_.compressed,E.network=_.network,E},g._transformDER=function(_,E){f.checkArgument(g._isBuffer(_),"Must be a hex buffer of DER encoded public key");var A={};E=i.isUndefined(E)?!0:E;var S,O,I,R;if(_[0]===4||!E&&(_[0]===6||_[0]===7)){if(I=_.slice(1,33),R=_.slice(33,65),I.length!==32||R.length!==32||_.length!==65)throw new TypeError("Length of x and y must be 32 bytes");S=new t(I),O=new t(R),A.point=new e(S,O),A.compressed=!1}else if(_[0]===3)I=_.slice(1),S=new t(I),A=g._transformX(!0,S),A.compressed=!0;else if(_[0]===2)I=_.slice(1),S=new t(I),A=g._transformX(!1,S),A.compressed=!0;else throw new TypeError("Invalid DER format public key");return A},g._transformX=function(_,E){f.checkArgument(typeof _=="boolean","Must specify whether y is odd or not (true or false)");var A={};return A.point=e.fromX(_,E),A},g._transformObject=function(_){var E=new t(_.x,"hex"),A=new t(_.y,"hex"),S=new e(E,A);return new g(S,{compressed:_.compressed})},g.fromPrivateKey=function(_){f.checkArgument(g._isPrivateKey(_),"Must be an instance of PrivateKey");var E=g._transformPrivateKey(_);return new g(E.point,{compressed:E.compressed,network:E.network})},g.fromBuffer=function(_,E){return f.checkArgument(g._isBuffer(_),"Must be a hex buffer of DER encoded public key or 32 byte X coordinate (taproot)"),_.length===32?g.fromX(!1,_):g.fromDER(_,E)},g.fromDER=function(_,E){f.checkArgument(g._isBuffer(_),"Must be a hex buffer of DER encoded public key");var A=g._transformDER(_,E);return new g(A.point,{compressed:A.compressed})},g.fromPoint=function(_,E){return f.checkArgument(_ instanceof e,"First argument must be an instance of Point."),new g(_,{compressed:E})},g.fromString=function(_,E){var A=pe.from(_,E||"hex"),S=g._transformDER(A);return new g(S.point,{compressed:S.compressed})},g.fromX=function(_,E){var A=g._transformX(_,E);return new g(A.point,{compressed:A.compressed})},g.fromTaproot=function(_){return typeof _=="string"&&n.isHexaString(_)&&(_=pe.from(_,"hex")),f.checkArgument(pe.isBuffer(_),"hexBuf must be a hex string or buffer"),f.checkArgument(_.length===32,"Taproot public keys must be 32 bytes"),new g.fromX(!1,_)},g.isValidTaproot=function(_){try{return!!g.fromTaproot(_)}catch{return!1}},g.prototype.computeTapTweakHash=function(_){const E=new l("TapTweak");E.write(this.point.x.toBuffer({size:32})),_&&(f.checkArgument(pe.isBuffer(_)&&_.length===32,"merkleRoot must be 32 byte buffer"),E.write(_));const A=E.finalize(),S=e.getN();return f.checkState(t.fromBuffer(A).lt(S),"TapTweak hash failed secp256k1 order check"),A},g.prototype.checkTapTweak=function(_,E,A){pe.isBuffer(_)&&(_=g.fromTaproot(_));const S=_.computeTapTweakHash(E),I=_.point.liftX().add(this.point.curve.g.mul(t.fromBuffer(S)));return this.point.x.eq(I.x)&&I.y.mod(new t(2)).eq(new t(A[0]&1))},g.prototype.createTapTweak=function(_){f.checkArgument(_==null||pe.isBuffer(_)&&_.length===32,"merkleRoot must be a 32 byte buffer");let E=this.computeTapTweakHash(_);E=new t(E);const A=this.point.liftX().add(e.getG().mul(E));return{parity:A.y.isEven()?0:1,tweakedPubKey:A.x.toBuffer()}},g.getValidationError=function(_){var E;try{new g(_)}catch(A){E=A}return E},g.isValid=function(_){return!g.getValidationError(_)},g.prototype.toObject=g.prototype.toJSON=function(){return{x:this.point.getX().toString("hex",2),y:this.point.getY().toString("hex",2),compressed:this.compressed}},g.prototype.toBuffer=g.prototype.toDER=function(){var _=this.point.getX(),E=this.point.getY(),A=_.toBuffer({size:32}),S=E.toBuffer({size:32}),O;if(this.compressed){var I=S[S.length-1]%2;return I?O=pe.from([3]):O=pe.from([2]),pe.concat([O,A])}else return O=pe.from([4]),pe.concat([O,A,S])},g.prototype._getID=function(){return r.sha256ripemd160(this.toBuffer())},g.prototype.toAddress=function(_,E){var A=Ds();return A.fromPublicKey(this,_||this.network,E)},g.prototype.toString=function(){return this.toDER().toString("hex")},g.prototype.inspect=function(){return"<PublicKey: "+this.toString()+(this.compressed?"":", uncompressed")+">"},Jg=g,Jg}var J_;function Tl(){if(J_)return rl.exports;J_=1;const t=sn,e=Zo,r=Pn,n=Us(),s=Rl,i=kr,f=ur,l=$t,g=function(C,P,L){for(var H=0;H<4;H++){var K;try{K=_(C,P,H)}catch(V){console.error(V);continue}if(K.point.eq(L.point))return P.i=H,P.compressed=L.compressed,P}throw new Error("Unable to find valid recovery factor")},_=function(C,P,L){l.checkArgument(L===0||L===1||L===2||L===3,new Error("i must be equal to 0, 1, 2, or 3"));var H=t.fromBuffer(C),K=P.r,V=P.s,te=L&1,U=L>>1,j=e.getN(),D=e.getG(),b=U?K.add(j):K,a=e.fromX(te,b),h=a.mul(j);if(!h.isInfinity())throw new Error("nR is not a valid curve point");var u=H.neg().umod(j),p=K.invm(j),y=a.mul(V).add(D.mul(u)).mul(p),m=n.fromPoint(y,P.compressed);return m},E=function(C,P){return _(C,P,P.i)},A=function(){var C=e.getN(),P;do P=t.fromBuffer(s.getRandomBuffer(32));while(!(P.lt(C)&&P.gt(t.Zero)));return P},S=function(C,P,L){L||(L=0);var H=pe.alloc(32);H.fill(1);var K=pe.alloc(32);K.fill(0);var V=P.bn.toBuffer({size:32});K=i.sha256hmac(pe.concat([H,pe.from([0]),V,C]),K),H=i.sha256hmac(H,K),K=i.sha256hmac(pe.concat([H,pe.from([1]),V,C]),K),H=i.sha256hmac(H,K),H=i.sha256hmac(H,K);for(var te=t.fromBuffer(H),U=e.getN(),j=0;j<L||!(te.lt(U)&&te.gt(t.Zero));j++)K=i.sha256hmac(pe.concat([H,pe.from([0])]),K),H=i.sha256hmac(H,K),H=i.sha256hmac(H,K),te=t.fromBuffer(H);return te},O=function(C){return C.gt(new t("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))&&(C=e.getN().sub(C)),C},I=function(C,P,L){const{endian:H="big",randomK:K=!1}=L||{};l.checkState(f.isBuffer(C)&&C.length===32,"hashbuf must be a 32 byte buffer"),l.checkState(P&&P.bn,"privkey must be a PrivateKey");var V=P.bn;C=pe.from(C),H==="little"&&C.reverse();var te=t.fromBuffer(C),U=e.getN(),j=e.getG(),D=0,b,a,h,u;do b=K?A():S(C,P,D),D++,a=j.mul(b),h=a.x.umod(U),u=b.invm(U).mul(te.add(V.mul(h))).umod(U);while(h.cmp(t.Zero)<=0||u.cmp(t.Zero)<=0);return u=O(u),new r({s:u,r:h,compressed:P.publicKey.compressed})},R=function(C,P,L,H){const{endian:K="big"}=H||{};if(!f.isBuffer(C)||C.length!==32)return"hashbuf must be a 32 byte buffer";var V=P.r,te=P.s;if(!(V.gt(t.Zero)&&V.lt(e.getN()))||!(te.gt(t.Zero)&&te.lt(e.getN())))return"r and s not in range";var U=t.fromBuffer(C,{endian:K}),j=e.getN(),D=te.invm(j),b=D.mul(U).umod(j),a=D.mul(V).umod(j),h=e.getG().mulAdd(b,L.point,a);if(h.isInfinity())return"p is infinity";if(h.getX().umod(j).cmp(V)!==0)return"Invalid signature"},B=function(C,P,L,H){if(!L)throw new Error("pubkey required for signature verification");if(L=new n(L),!P)throw new Error("signature required for verification");return P=new r(P),!R(C,P,L,H)};return rl.exports={sign:I,verify:B,verificationError:R,calci:g,recoverPublicKey:E},rl.exports.__testing__={getDeterministicK:S,getPublicKey:_,getRandomK:A,toLowS:O},rl.exports}var Y_=on,Q_=da,WH=sn,as=function t(e){if(!(this instanceof t))return new t(e);if(pe.isBuffer(e))this.buf=e;else if(typeof e=="number"){var r=e;this.fromNumber(r)}else if(e instanceof WH){var n=e;this.fromBN(n)}else if(e){var s=e;this.set(s)}};as.prototype.set=function(t){return this.buf=t.buf||this.buf,this},as.prototype.fromString=function(t){return this.set({buf:pe.from(t,"hex")}),this},as.prototype.toString=function(){return this.buf.toString("hex")},as.prototype.fromBuffer=function(t){return this.buf=t,this},as.prototype.fromBufferReader=function(t){return this.buf=t.readVarintBuf(),this},as.prototype.fromBN=function(t){return this.buf=Y_().writeVarintBN(t).concat(),this},as.prototype.fromNumber=function(t){return this.buf=Y_().writeVarintNum(t).concat(),this},as.prototype.toBuffer=function(){return this.buf},as.prototype.toBN=function(){return Q_(this.buf).readVarintBN()},as.prototype.toNumber=function(){return Q_(this.buf).readVarintNum()};var GH=as,Ol={exports:{}},Pl=Xt,hh=sn,Pu=ur,Bl=da,$H=on,ZH=kr,e7=$t,XH=486604799,Kt=function t(e){if(!(this instanceof t))return new t(e);var r=t._from(e);return this.version=r.version,this.prevHash=r.prevHash,this.merkleRoot=r.merkleRoot,this.time=r.time,this.timestamp=r.time,this.bits=r.bits,this.nonce=r.nonce,r.hash&&e7.checkState(this.hash===r.hash,"Argument object hash property does not match block hash."),this};Kt._from=function(e){var r={};if(Pu.isBuffer(e))r=Kt._fromBufferReader(Bl(e));else if(Pl.isObject(e))r=Kt._fromObject(e);else throw new TypeError("Unrecognized argument for BlockHeader");return r},Kt._fromObject=function(e){e7.checkArgument(e,"data is required");var r=e.prevHash,n=e.merkleRoot;Pl.isString(e.prevHash)&&(r=Pu.reverse(pe.from(e.prevHash,"hex"))),Pl.isString(e.merkleRoot)&&(n=Pu.reverse(pe.from(e.merkleRoot,"hex")));var s={hash:e.hash,version:e.version,prevHash:r,merkleRoot:n,time:e.time,timestamp:e.time,bits:e.bits,nonce:e.nonce};return s},Kt.fromObject=function(e){var r=Kt._fromObject(e);return new Kt(r)},Kt.fromRawBlock=function(e){Pu.isBuffer(e)||(e=pe.from(e,"binary"));var r=Bl(e);r.pos=Kt.Constants.START_OF_HEADER;var n=Kt._fromBufferReader(r);return new Kt(n)},Kt.fromBuffer=function(e){var r=Kt._fromBufferReader(Bl(e));return new Kt(r)},Kt.fromString=function(e){var r=pe.from(e,"hex");return Kt.fromBuffer(r)},Kt._fromBufferReader=function(e){var r={};return r.version=e.readInt32LE(),r.prevHash=e.read(32),r.merkleRoot=e.read(32),r.time=e.readUInt32LE(),r.bits=e.readUInt32LE(),r.nonce=e.readUInt32LE(),r},Kt.fromBufferReader=function(e){var r=Kt._fromBufferReader(e);return new Kt(r)},Kt.prototype.toObject=Kt.prototype.toJSON=function(){return{hash:this.hash,version:this.version,prevHash:Pu.reverse(this.prevHash).toString("hex"),merkleRoot:Pu.reverse(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}},Kt.prototype.toBuffer=function(){return this.toBufferWriter().concat()},Kt.prototype.toString=function(){return this.toBuffer().toString("hex")},Kt.prototype.toBufferWriter=function(e){return e||(e=new $H),e.writeInt32LE(this.version),e.write(this.prevHash),e.write(this.merkleRoot),e.writeUInt32LE(this.time),e.writeUInt32LE(this.bits),e.writeUInt32LE(this.nonce),e},Kt.prototype.getTargetDifficulty=function(e){e=e||this.bits;for(var r=new hh(e&16777215),n=8*((e>>>24)-3);n-- >0;)r=r.mul(new hh(2));return r},Kt.prototype.getDifficulty=function(){var e=this.getTargetDifficulty(XH).mul(new hh(Math.pow(10,8))),r=this.getTargetDifficulty(),n=e.div(r).toString(10),s=n.length-8;return n=n.slice(0,s)+"."+n.slice(s),parseFloat(n)},Kt.prototype._getHash=function(){var e=this.toBuffer();return ZH.sha256sha256(e)};var t7={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=Bl(this._getHash()).readReverse().toString("hex")),this._id},set:Pl.noop};Object.defineProperty(Kt.prototype,"id",t7),Object.defineProperty(Kt.prototype,"hash",t7),Kt.prototype.validTimestamp=function(){var e=Math.round(new Date().getTime()/1e3);return!(this.time>e+Kt.Constants.MAX_TIME_OFFSET)},Kt.prototype.validProofOfWork=function(){var e=new hh(this.id,"hex"),r=this.getTargetDifficulty();return!(e.cmp(r)>0)},Kt.prototype.inspect=function(){return"<BlockHeader "+this.id+">"},Kt.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:2*60*60,LARGEST_HASH:new hh("10000000000000000000000000000000000000000000000000000000000000000","hex")};var Cl=Kt,Yg=Xt,r7=Cl,n7=sn,i7=ur,Qg=da,JH=on,YH=kr,em=Ml(),s7=$t;function Ut(t){return this instanceof Ut?(Yg.extend(this,Ut._from(t)),this):new Ut(t)}Ut.MAX_BLOCK_SIZE=1e6,Ut._from=function(e){var r={};if(i7.isBuffer(e))r=Ut._fromBufferReader(Qg(e));else if(Yg.isObject(e))r=Ut._fromObject(e);else throw new TypeError("Unrecognized argument for Block");return r},Ut._fromObject=function(e){var r=[];e.transactions.forEach(function(s){s instanceof em?r.push(s):r.push(em().fromObject(s))});var n={header:r7.fromObject(e.header),transactions:r};return n},Ut.fromObject=function(e){var r=Ut._fromObject(e);return new Ut(r)},Ut._fromBufferReader=function(e){var r={};s7.checkState(!e.finished(),"No block data received"),r.header=r7.fromBufferReader(e);var n=e.readVarintNum();r.transactions=[];for(var s=0;s<n;s++)r.transactions.push(em().fromBufferReader(e));return r},Ut.fromBufferReader=function(e){s7.checkArgument(e,"br is required");var r=Ut._fromBufferReader(e);return new Ut(r)},Ut.fromBuffer=function(e){return Ut.fromBufferReader(new Qg(e))},Ut.fromString=function(e){var r=pe.from(e,"hex");return Ut.fromBuffer(r)},Ut.fromRawBlock=function(e){i7.isBuffer(e)||(e=pe.from(e,"binary"));var r=Qg(e);r.pos=Ut.Values.START_OF_BLOCK;var n=Ut._fromBufferReader(r);return new Ut(n)},Ut.prototype.toObject=Ut.prototype.toJSON=function(){var e=[];return this.transactions.forEach(function(r){e.push(r.toObject())}),{header:this.header.toObject(),transactions:e}},Ut.prototype.toBuffer=function(){return this.toBufferWriter().concat()},Ut.prototype.toString=function(){return this.toBuffer().toString("hex")},Ut.prototype.toBufferWriter=function(e){e||(e=new JH),e.write(this.header.toBuffer()),e.writeVarintNum(this.transactions.length);for(var r=0;r<this.transactions.length;r++)this.transactions[r].toBufferWriter(e);return e},Ut.prototype.getTransactionHashes=function(){var e=[];if(this.transactions.length===0)return[Ut.Values.NULL_HASH];for(var r=0;r<this.transactions.length;r++)e.push(this.transactions[r]._getHash());return e},Ut.prototype.getMerkleTree=function(){for(var e=this.getTransactionHashes(),r=0,n=this.transactions.length;n>1;n=Math.floor((n+1)/2)){for(var s=0;s<n;s+=2){var i=Math.min(s+1,n-1),f=pe.concat([e[r+s],e[r+i]]);e.push(YH.sha256sha256(f))}r+=n}return e},Ut.prototype.getMerkleRoot=function(){var e=this.getMerkleTree();return e[e.length-1]},Ut.prototype.validMerkleRoot=function(){var e=new n7(this.header.merkleRoot.toString("hex"),"hex"),r=new n7(this.getMerkleRoot().toString("hex"),"hex");return e.cmp(r)===0},Ut.prototype._getHash=function(){return this.header._getHash()};var a7={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=this.header.id),this._id},set:Yg.noop};Object.defineProperty(Ut.prototype,"id",a7),Object.defineProperty(Ut.prototype,"hash",a7),Ut.prototype.inspect=function(){return"<Block "+this.id+">"},Ut.Values={START_OF_BLOCK:8,NULL_HASH:pe.from("0000000000000000000000000000000000000000000000000000000000000000","hex")};var QH=Ut,sf=Xt,tm=Cl,rm=ur,o7=da,eq=on,tq=kr,f7=Ml(),nm=Oi,af=$t;function gr(t){if(!(this instanceof gr))return new gr(t);var e={};if(rm.isBuffer(t))e=gr._fromBufferReader(o7(t));else if(sf.isObject(t)){var r;t.header instanceof tm?r=t.header:r=tm.fromObject(t.header),e={header:r,numTransactions:t.numTransactions,hashes:t.hashes,flags:t.flags}}else throw new TypeError("Unrecognized argument for MerkleBlock");return sf.extend(this,e),this._flagBitsUsed=0,this._hashesUsed=0,this}gr.fromBuffer=function(e){return gr.fromBufferReader(o7(e))},gr.fromBufferReader=function(e){return new gr(gr._fromBufferReader(e))},gr.prototype.toBuffer=function(){return this.toBufferWriter().concat()},gr.prototype.toBufferWriter=function(e){e||(e=new eq),e.write(this.header.toBuffer()),e.writeUInt32LE(this.numTransactions),e.writeVarintNum(this.hashes.length);for(var r=0;r<this.hashes.length;r++)e.write(pe.from(this.hashes[r],"hex"));for(e.writeVarintNum(this.flags.length),r=0;r<this.flags.length;r++)e.writeUInt8(this.flags[r]);return e},gr.prototype.toObject=gr.prototype.toJSON=function(){return{header:this.header.toObject(),numTransactions:this.numTransactions,hashes:this.hashes,flags:this.flags}},gr.prototype.validMerkleTree=function(){if(af.checkState(sf.isArray(this.flags),"MerkleBlock flags is not an array"),af.checkState(sf.isArray(this.hashes),"MerkleBlock hashes is not an array"),this.hashes.length>this.numTransactions||this.flags.length*8<this.hashes.length)return!1;var e=this._calcTreeHeight(),r={hashesUsed:0,flagBitsUsed:0},n=this._traverseMerkleTree(e,0,r);return r.hashesUsed!==this.hashes.length?!1:rm.equals(n,this.header.merkleRoot)},gr.prototype.filterdTxsHash=function(){if(af.checkState(sf.isArray(this.flags),"MerkleBlock flags is not an array"),af.checkState(sf.isArray(this.hashes),"MerkleBlock hashes is not an array"),this.hashes.length>this.numTransactions)throw new nm.MerkleBlock.InvalidMerkleTree;if(this.flags.length*8<this.hashes.length)throw new nm.MerkleBlock.InvalidMerkleTree;if(this.hashes.length===1)return[];var e=this._calcTreeHeight(),r={hashesUsed:0,flagBitsUsed:0},n=this._traverseMerkleTree(e,0,r,!0);if(r.hashesUsed!==this.hashes.length)throw new nm.MerkleBlock.InvalidMerkleTree;return n},gr.prototype._traverseMerkleTree=function(e,r,n,i){n=n||{},n.txs=n.txs||[],n.flagBitsUsed=n.flagBitsUsed||0,n.hashesUsed=n.hashesUsed||0;var i=i||!1;if(n.flagBitsUsed>this.flags.length*8)return null;var f=this.flags[n.flagBitsUsed>>3]>>>(n.flagBitsUsed++&7)&1;if(e===0||!f){if(n.hashesUsed>=this.hashes.length)return null;var l=this.hashes[n.hashesUsed++];return e===0&&f&&n.txs.push(l),pe.from(l,"hex")}else{var g=this._traverseMerkleTree(e-1,r*2,n),_=g;return r*2+1<this._calcTreeWidth(e-1)&&(_=this._traverseMerkleTree(e-1,r*2+1,n)),i?n.txs:tq.sha256sha256(new pe.concat([g,_]))}},gr.prototype._calcTreeWidth=function(e){return this.numTransactions+(1<<e)-1>>e},gr.prototype._calcTreeHeight=function(){for(var e=0;this._calcTreeWidth(e)>1;)e++;return e},gr.prototype.hasTransaction=function(e){af.checkArgument(!sf.isUndefined(e),"tx cannot be undefined"),af.checkArgument(e instanceof f7||typeof e=="string",'Invalid tx given, tx must be a "string" or "Transaction"');var r=e;e instanceof f7&&(r=rm.reverse(pe.from(e.id,"hex")).toString("hex"));var n=[],s=this._calcTreeHeight();return this._traverseMerkleTree(s,0,{txs:n}),n.indexOf(r)!==-1},gr._fromBufferReader=function(e){af.checkState(!e.finished(),"No merkleblock data received");var r={};r.header=tm.fromBufferReader(e),r.numTransactions=e.readUInt32LE();var n=e.readVarintNum();r.hashes=[];for(var s=0;s<n;s++)r.hashes.push(e.read(32).toString("hex"));var i=e.readVarintNum();for(r.flags=[],s=0;s<i;s++)r.flags.push(e.readUInt8());return r},gr.fromObject=function(e){return new gr(e)};var u7=gr;Ol.exports=QH,Ol.exports.BlockHeader=Cl,Ol.exports.MerkleBlock=u7;var rq=Ol.exports,im,c7;function h7(){if(c7)return im;c7=1;var t=Xt,e=$t,r=sn,n=wl,s=ah,i=kr,f=l7(),l=Jo,g=Zo,_=Us(),E=Oi,A=E,S=E.HDPublicKey,O=du(),I=nn,R=ur;function B(C){if(C instanceof B)return C;if(!(this instanceof B))return new B(C);if(C)if(t.isString(C)||R.isBuffer(C)){var P=B.getSerializedError(C);if(P){if(R.isBuffer(C)&&!B.getSerializedError(C.toString()))return this._buildFromSerialized(C.toString());if(P instanceof S.ArgumentIsPrivateExtended)return new f(C).hdPublicKey;throw P}else return this._buildFromSerialized(C)}else{if(t.isObject(C))return C instanceof f?this._buildFromPrivate(C):this._buildFromObject(C);throw new S.UnrecognizedArgument(C)}else throw new S.MustSupplyArgument}return B.isValidPath=function(C){if(t.isString(C)){var P=f._getDerivationIndexes(C);return P!==null&&t.every(P,B.isValidPath)}return t.isNumber(C)?C>=0&&C<B.Hardened:!1},B.prototype.derive=function(C,P){return this.deriveChild(C,P)},B.prototype.deriveChild=function(C,P){if(t.isNumber(C))return this._deriveWithNumber(C,P);if(t.isString(C))return this._deriveFromString(C);throw new S.InvalidDerivationArgument(C)},B.prototype._deriveWithNumber=function(C,P){if(C>=B.Hardened||P)throw new S.InvalidIndexCantDeriveHardened;if(C<0)throw new S.InvalidPath(C);var L=R.integerAsBuffer(C),H=R.concat([this.publicKey.toBuffer(),L]),K=i.sha512hmac(H,this._buffers.chainCode),V=r.fromBuffer(K.slice(0,32),{size:32}),te=K.slice(32,64),U;try{U=_.fromPoint(g.getG().mul(V).add(this.publicKey.point))}catch{return this._deriveWithNumber(C+1)}var j=new B({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:C,chainCode:te,publicKey:U});return j},B.prototype._deriveFromString=function(C){if(t.includes(C,"'"))throw new S.InvalidIndexCantDeriveHardened;if(!B.isValidPath(C))throw new S.InvalidPath(C);var P=f._getDerivationIndexes(C),L=P.reduce(function(H,K){return H._deriveWithNumber(K)},this);return L},B.isValidSerialized=function(C,P){return t.isNull(B.getSerializedError(C,P))},B.getSerializedError=function(C,P){if(!(t.isString(C)||R.isBuffer(C)))return new S.UnrecognizedArgument("expected buffer or string");if(!n.validCharacters(C))return new A.InvalidB58Char("(unknown)",C);try{C=s.decode(C)}catch{return new A.InvalidB58Checksum(C)}if(C.length!==B.DataSize)return new S.InvalidLength(C);if(!t.isUndefined(P)){var L=B._validateNetwork(C,P);if(L)return L}var H=R.integerFromBuffer(C.slice(0,4));return H===l.livenet.xprivkey||H===l.testnet.xprivkey?new S.ArgumentIsPrivateExtended:null},B._validateNetwork=function(C,P){var L=l.get(P);if(!L)return new A.InvalidNetworkArgument(P);var H=C.slice(B.VersionStart,B.VersionEnd);return R.integerFromBuffer(H)!==L.xpubkey?new A.InvalidNetwork(H):null},B.prototype._buildFromPrivate=function(C){var P=t.clone(C._buffers),L=g.getG().mul(r.fromBuffer(P.privateKey));return P.publicKey=g.pointToCompressed(L),P.version=R.integerAsBuffer(l.get(R.integerFromBuffer(P.version)).xpubkey),P.privateKey=void 0,P.checksum=void 0,P.xprivkey=void 0,this._buildFromBuffers(P)},B.prototype._buildFromObject=function(C){var P={version:C.network?R.integerAsBuffer(l.get(C.network).xpubkey):C.version,depth:t.isNumber(C.depth)?R.integerAsSingleByteBuffer(C.depth):C.depth,parentFingerPrint:t.isNumber(C.parentFingerPrint)?R.integerAsBuffer(C.parentFingerPrint):C.parentFingerPrint,childIndex:t.isNumber(C.childIndex)?R.integerAsBuffer(C.childIndex):C.childIndex,chainCode:t.isString(C.chainCode)?pe.from(C.chainCode,"hex"):C.chainCode,publicKey:t.isString(C.publicKey)?pe.from(C.publicKey,"hex"):R.isBuffer(C.publicKey)?C.publicKey:C.publicKey.toBuffer(),checksum:t.isNumber(C.checksum)?R.integerAsBuffer(C.checksum):C.checksum};return this._buildFromBuffers(P)},B.prototype._buildFromSerialized=function(C){var P=s.decode(C),L={version:P.slice(B.VersionStart,B.VersionEnd),depth:P.slice(B.DepthStart,B.DepthEnd),parentFingerPrint:P.slice(B.ParentFingerPrintStart,B.ParentFingerPrintEnd),childIndex:P.slice(B.ChildIndexStart,B.ChildIndexEnd),chainCode:P.slice(B.ChainCodeStart,B.ChainCodeEnd),publicKey:P.slice(B.PublicKeyStart,B.PublicKeyEnd),checksum:P.slice(B.ChecksumStart,B.ChecksumEnd),xpubkey:C};return this._buildFromBuffers(L)},B.prototype._buildFromBuffers=function(C){B._validateBufferArguments(C),I.defineImmutable(this,{_buffers:C});var P=[C.version,C.depth,C.parentFingerPrint,C.childIndex,C.chainCode,C.publicKey],L=R.concat(P),H=s.checksum(L);if(!C.checksum||!C.checksum.length)C.checksum=H;else if(C.checksum.toString("hex")!==H.toString("hex"))throw new A.InvalidB58Checksum(L,H);var K=l.get(R.integerFromBuffer(C.version)),V;V=s.encode(R.concat(P)),C.xpubkey=pe.from(V);var te=new _(C.publicKey,{network:K}),U=B.ParentFingerPrintSize,j=i.sha256ripemd160(te.toBuffer()).slice(0,U);return I.defineImmutable(this,{xpubkey:V,network:K,depth:R.integerFromSingleByteBuffer(C.depth),publicKey:te,fingerPrint:j}),this},B._validateBufferArguments=function(C){var P=function(L,H){var K=C[L];O(R.isBuffer(K),L+" argument is not a buffer, it's "+typeof K),O(K.length===H,L+" has not the expected size: found "+K.length+", expected "+H)};P("version",B.VersionSize),P("depth",B.DepthSize),P("parentFingerPrint",B.ParentFingerPrintSize),P("childIndex",B.ChildIndexSize),P("chainCode",B.ChainCodeSize),P("publicKey",B.PublicKeySize),C.checksum&&C.checksum.length&&P("checksum",B.CheckSumSize)},B.fromString=function(C){return e.checkArgument(t.isString(C),"No valid string was provided"),new B(C)},B.fromObject=function(C){return e.checkArgument(t.isObject(C),"No valid argument was provided"),new B(C)},B.prototype.toString=function(){return this.xpubkey},B.prototype.inspect=function(){return"<HDPublicKey: "+this.xpubkey+">"},B.prototype.toObject=B.prototype.toJSON=function(){return{network:l.get(R.integerFromBuffer(this._buffers.version)).name,depth:R.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:R.integerFromBuffer(this.fingerPrint),parentFingerPrint:R.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:R.integerFromBuffer(this._buffers.childIndex),chainCode:R.bufferToHex(this._buffers.chainCode),publicKey:this.publicKey.toString(),checksum:R.integerFromBuffer(this._buffers.checksum),xpubkey:this.xpubkey}},B.fromBuffer=function(C){return new B(C)},B.prototype.toBuffer=function(){return R.copy(this._buffers.xpubkey)},B.Hardened=2147483648,B.RootElementAlias=["m","M"],B.VersionSize=4,B.DepthSize=1,B.ParentFingerPrintSize=4,B.ChildIndexSize=4,B.ChainCodeSize=32,B.PublicKeySize=33,B.CheckSumSize=4,B.DataSize=78,B.SerializedByteSize=82,B.VersionStart=0,B.VersionEnd=B.VersionStart+B.VersionSize,B.DepthStart=B.VersionEnd,B.DepthEnd=B.DepthStart+B.DepthSize,B.ParentFingerPrintStart=B.DepthEnd,B.ParentFingerPrintEnd=B.ParentFingerPrintStart+B.ParentFingerPrintSize,B.ChildIndexStart=B.ParentFingerPrintEnd,B.ChildIndexEnd=B.ChildIndexStart+B.ChildIndexSize,B.ChainCodeStart=B.ChildIndexEnd,B.ChainCodeEnd=B.ChainCodeStart+B.ChainCodeSize,B.PublicKeyStart=B.ChainCodeEnd,B.PublicKeyEnd=B.PublicKeyStart+B.PublicKeySize,B.ChecksumStart=B.PublicKeyEnd,B.ChecksumEnd=B.ChecksumStart+B.CheckSumSize,O(B.PublicKeyEnd===B.DataSize),O(B.ChecksumEnd===B.SerializedByteSize),im=B,im}var sm,d7;function l7(){if(d7)return sm;d7=1;var t=du(),e=Dr,r=Xt,n=$t,s=sn,i=wl,f=ah,l=kr,g=Jo,_=Zo,E=nf(),A=Rl,S=Oi,O=S.HDPrivateKey,I=ur,R=nn,B=128,C=1/8,P=512;function L(H){if(H instanceof L)return H;if(!(this instanceof L))return new L(H);if(!H)return this._generateRandomly();if(g.get(H))return this._generateRandomly(H);if(r.isString(H)||I.isBuffer(H))if(L.isValidSerialized(H))this._buildFromSerialized(H);else if(R.isValidJSON(H))this._buildFromJSON(H);else if(I.isBuffer(H)&&L.isValidSerialized(H.toString()))this._buildFromSerialized(H.toString());else throw L.getSerializedError(H);else if(r.isObject(H))this._buildFromObject(H);else throw new O.UnrecognizedArgument(H)}return L.isValidPath=function(H,K){if(r.isString(H)){var V=L._getDerivationIndexes(H);return V!==null&&r.every(V,L.isValidPath)}return r.isNumber(H)?(H<L.Hardened&&K===!0&&(H+=L.Hardened),H>=0&&H<L.MaxIndex):!1},L._getDerivationIndexes=function(H){var K=H.split("/");if(r.includes(L.RootElementAlias,H))return[];if(!r.includes(L.RootElementAlias,K[0]))return null;var V=K.slice(1).map(function(te){var U=te.slice(-1)==="'";if(U&&(te=te.slice(0,-1)),!te||te[0]==="-")return NaN;var j=+te;return U&&(j+=L.Hardened),j});return r.some(V,isNaN)?null:V},L.prototype.derive=function(H,K){return this.deriveNonCompliantChild(H,K)},L.prototype.deriveChild=function(H,K){if(r.isNumber(H))return this._deriveWithNumber(H,K);if(r.isString(H))return this._deriveFromString(H);throw new O.InvalidDerivationArgument(H)},L.prototype.deriveNonCompliantChild=function(H,K){if(r.isNumber(H))return this._deriveWithNumber(H,K,!0);if(r.isString(H))return this._deriveFromString(H,!0);throw new O.InvalidDerivationArgument(H)},L.prototype._deriveWithNumber=function(H,K,V){if(!L.isValidPath(H,K))throw new O.InvalidPath(H);K=H>=L.Hardened?!0:K,H<L.Hardened&&K===!0&&(H+=L.Hardened);var te=I.integerAsBuffer(H),U;if(K&&V){var j=this.privateKey.bn.toBuffer();U=I.concat([pe.from([0]),j,te])}else if(K){var D=this.privateKey.bn.toBuffer({size:32});t(D.length===32,"length of private key buffer is expected to be 32 bytes"),U=I.concat([pe.from([0]),D,te])}else U=I.concat([this.publicKey.toBuffer(),te]);var b=l.sha512hmac(U,this._buffers.chainCode),a=s.fromBuffer(b.slice(0,32),{size:32}),h=b.slice(32,64),u=a.add(this.privateKey.toBigNumber()).umod(_.getN()).toBuffer({size:32});if(!E.isValid(u))return this._deriveWithNumber(H+1,null,V);var p=new L({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:H,chainCode:h,privateKey:u});return p},L.prototype._deriveFromString=function(H,K){if(!L.isValidPath(H))throw new O.InvalidPath(H);var V=L._getDerivationIndexes(H),te=V.reduce(function(U,j){return U._deriveWithNumber(j,null,K)},this);return te},L.isValidSerialized=function(H,K){return!L.getSerializedError(H,K)},L.getSerializedError=function(H,K){if(!(r.isString(H)||I.isBuffer(H)))return new O.UnrecognizedArgument("Expected string or buffer");if(!i.validCharacters(H))return new S.InvalidB58Char("(unknown)",H);try{H=f.decode(H)}catch{return new S.InvalidB58Checksum(H)}if(H.length!==L.DataLength)return new O.InvalidLength(H);if(!r.isUndefined(K)){var V=L._validateNetwork(H,K);if(V)return V}return null},L._validateNetwork=function(H,K){var V=g.get(K);if(!V)return new S.InvalidNetworkArgument(K);var te=H.slice(0,4);return I.integerFromBuffer(te)!==V.xprivkey?new S.InvalidNetwork(te):null},L.fromString=function(H){return n.checkArgument(r.isString(H),"No valid string was provided"),new L(H)},L.fromObject=function(H){return n.checkArgument(r.isObject(H),"No valid argument was provided"),new L(H)},L.prototype._buildFromJSON=function(H){return this._buildFromObject(JSON.parse(H))},L.prototype._buildFromObject=function(H){var K={version:H.network?I.integerAsBuffer(g.get(H.network).xprivkey):H.version,depth:r.isNumber(H.depth)?I.integerAsSingleByteBuffer(H.depth):H.depth,parentFingerPrint:r.isNumber(H.parentFingerPrint)?I.integerAsBuffer(H.parentFingerPrint):H.parentFingerPrint,childIndex:r.isNumber(H.childIndex)?I.integerAsBuffer(H.childIndex):H.childIndex,chainCode:r.isString(H.chainCode)?pe.from(H.chainCode,"hex"):H.chainCode,privateKey:r.isString(H.privateKey)&&R.isHexa(H.privateKey)?pe.from(H.privateKey,"hex"):H.privateKey,checksum:H.checksum?H.checksum.length?H.checksum:I.integerAsBuffer(H.checksum):void 0};return this._buildFromBuffers(K)},L.prototype._buildFromSerialized=function(H){var K=f.decode(H),V={version:K.slice(L.VersionStart,L.VersionEnd),depth:K.slice(L.DepthStart,L.DepthEnd),parentFingerPrint:K.slice(L.ParentFingerPrintStart,L.ParentFingerPrintEnd),childIndex:K.slice(L.ChildIndexStart,L.ChildIndexEnd),chainCode:K.slice(L.ChainCodeStart,L.ChainCodeEnd),privateKey:K.slice(L.PrivateKeyStart,L.PrivateKeyEnd),checksum:K.slice(L.ChecksumStart,L.ChecksumEnd),xprivkey:H};return this._buildFromBuffers(V)},L.prototype._generateRandomly=function(H){return L.fromSeed(A.getRandomBuffer(64),H)},L.fromSeed=function(H,K){if(R.isHexaString(H)&&(H=pe.from(H,"hex")),!pe.isBuffer(H))throw new O.InvalidEntropyArgument(H);if(H.length<B*C)throw new O.InvalidEntropyArgument.NotEnoughEntropy(H);if(H.length>P*C)throw new O.InvalidEntropyArgument.TooMuchEntropy(H);var V=l.sha512hmac(H,pe.from("Bitcoin seed"));return new L({network:g.get(K)||g.defaultNetwork,depth:0,parentFingerPrint:0,childIndex:0,privateKey:V.slice(0,32),chainCode:V.slice(32,64)})},L.prototype._calcHDPublicKey=function(){if(!this._hdPublicKey){var H=h7();this._hdPublicKey=new H(this)}},L.prototype._buildFromBuffers=function(H){L._validateBufferArguments(H),R.defineImmutable(this,{_buffers:H});var K=[H.version,H.depth,H.parentFingerPrint,H.childIndex,H.chainCode,I.emptyBuffer(1),H.privateKey],V=e.Buffer.concat(K);if(!H.checksum||!H.checksum.length)H.checksum=f.checksum(V);else if(H.checksum.toString()!==f.checksum(V).toString())throw new S.InvalidB58Checksum(V);var te=g.get(I.integerFromBuffer(H.version)),U;U=f.encode(e.Buffer.concat(K)),H.xprivkey=pe.from(U);var j=new E(s.fromBuffer(H.privateKey),te),D=j.toPublicKey(),b=L.ParentFingerPrintSize,a=l.sha256ripemd160(D.toBuffer()).slice(0,b);return R.defineImmutable(this,{xprivkey:U,network:te,depth:I.integerFromSingleByteBuffer(H.depth),privateKey:j,publicKey:D,fingerPrint:a}),this._hdPublicKey=null,Object.defineProperty(this,"hdPublicKey",{configurable:!1,enumerable:!0,get:function(){return this._calcHDPublicKey(),this._hdPublicKey}}),Object.defineProperty(this,"xpubkey",{configurable:!1,enumerable:!0,get:function(){return this._calcHDPublicKey(),this._hdPublicKey.xpubkey}}),this},L._validateBufferArguments=function(H){var K=function(V,te){var U=H[V];t(I.isBuffer(U),V+" argument is not a buffer"),t(U.length===te,V+" has not the expected size: found "+U.length+", expected "+te)};K("version",L.VersionSize),K("depth",L.DepthSize),K("parentFingerPrint",L.ParentFingerPrintSize),K("childIndex",L.ChildIndexSize),K("chainCode",L.ChainCodeSize),K("privateKey",L.PrivateKeySize),H.checksum&&H.checksum.length&&K("checksum",L.CheckSumSize)},L.prototype.toString=function(){return this.xprivkey},L.prototype.inspect=function(){return"<HDPrivateKey: "+this.xprivkey+">"},L.prototype.toObject=L.prototype.toJSON=function(){return{network:g.get(I.integerFromBuffer(this._buffers.version),"xprivkey").name,depth:I.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:I.integerFromBuffer(this.fingerPrint),parentFingerPrint:I.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:I.integerFromBuffer(this._buffers.childIndex),chainCode:I.bufferToHex(this._buffers.chainCode),privateKey:this.privateKey.toBuffer().toString("hex"),checksum:I.integerFromBuffer(this._buffers.checksum),xprivkey:this.xprivkey}},L.fromBuffer=function(H){return new L(H.toString())},L.prototype.toBuffer=function(){return I.copy(this._buffers.xprivkey)},L.DefaultDepth=0,L.DefaultFingerprint=0,L.DefaultChildIndex=0,L.Hardened=2147483648,L.MaxIndex=2*L.Hardened,L.RootElementAlias=["m","M","m'","M'"],L.VersionSize=4,L.DepthSize=1,L.ParentFingerPrintSize=4,L.ChildIndexSize=4,L.ChainCodeSize=32,L.PrivateKeySize=32,L.CheckSumSize=4,L.DataLength=78,L.SerializedByteSize=82,L.VersionStart=0,L.VersionEnd=L.VersionStart+L.VersionSize,L.DepthStart=L.VersionEnd,L.DepthEnd=L.DepthStart+L.DepthSize,L.ParentFingerPrintStart=L.DepthEnd,L.ParentFingerPrintEnd=L.ParentFingerPrintStart+L.ParentFingerPrintSize,L.ChildIndexStart=L.ParentFingerPrintEnd,L.ChildIndexEnd=L.ChildIndexStart+L.ChildIndexSize,L.ChainCodeStart=L.ChildIndexEnd,L.ChainCodeEnd=L.ChainCodeStart+L.ChainCodeSize,L.PrivateKeyStart=L.ChainCodeEnd+1,L.PrivateKeyEnd=L.PrivateKeyStart+L.PrivateKeySize,L.ChecksumStart=L.PrivateKeyEnd,L.ChecksumEnd=L.ChecksumStart+L.CheckSumSize,t(L.ChecksumEnd===L.SerializedByteSize),sm=L,sm}var dh=Xt,nq=nf(),iq=Us(),kl=Ds(),p7=on,lh=Tl(),am=Pn,sq=kr.sha256sha256,aq=nn,eo=$t;function Tr(t){return this instanceof Tr?(eo.checkArgument(dh.isString(t),"First argument should be a string"),this.message=t,this):new Tr(t)}Tr.MAGIC_BYTES=pe.from(`Bitcoin Signed Message:
132
132
  `),Tr.prototype.magicHash=function(){var e=p7.varintBufNum(Tr.MAGIC_BYTES.length),r=pe.from(this.message),n=p7.varintBufNum(r.length),s=pe.concat([e,Tr.MAGIC_BYTES,n,r]),i=sq(s);return i},Tr.prototype._sign=function(e){eo.checkArgument(e instanceof nq,"First argument should be an instance of PrivateKey");const r=this.magicHash(),n=lh.sign(r,e,{randomK:!0});return lh.calci(r,n,e.toPublicKey()),n},Tr.prototype.sign=function(e){var r=this._sign(e);return r.toCompact().toString("base64")},Tr.prototype._verify=function(e,r){eo.checkArgument(e instanceof iq,"First argument should be an instance of PublicKey"),eo.checkArgument(r instanceof am,"Second argument should be an instance of Signature");var n=this.magicHash(),s=lh.verify(n,r,e);return s||(this.error="The signature was invalid"),s},Tr.prototype.verify=function(e,r){eo.checkArgument(e),eo.checkArgument(r&&dh.isString(r)),dh.isString(e)&&(e=kl.fromString(e));var n=am.fromCompact(pe.from(r,"base64"));const s=this.magicHash();var i=lh.recoverPublicKey(s,n),f=kl.fromPublicKey(i,e.network);return e.toString()!==f.toString()?(this.error="The signature did not match the message digest",!1):this._verify(i,n)},Tr.prototype.recoverPublicKey=function(e,r){eo.checkArgument(e),eo.checkArgument(r&&dh.isString(r)),dh.isString(e)&&(e=kl.fromString(e));var n=am.fromCompact(pe.from(r,"base64"));const s=this.magicHash();var i=lh.recoverPublicKey(s,n),f=kl.fromPublicKey(i,e.network);return e.toString()!==f.toString()&&(this.error="The signature did not match the message digest"),i.toString()},Tr.fromString=function(t){return new Tr(t)},Tr.fromJSON=function(e){return aq.isValidJSON(e)&&(e=JSON.parse(e)),new Tr(e.message)},Tr.prototype.toObject=function(){return{message:this.message}},Tr.prototype.toJSON=function(){return JSON.stringify(this.toObject())},Tr.prototype.toString=function(){return this.message},Tr.prototype.inspect=function(){return"<Message: "+this.toString()+">"};var oq=Tr;ti();var Nl={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Nl.exports,function(t,e){(function(r){var n=e&&!e.nodeType&&e,s=t&&!t.nodeType&&t,i=typeof ht=="object"&&ht;(i.global===i||i.window===i||i.self===i)&&(r=i);var f,l=2147483647,g=36,_=1,E=26,A=38,S=700,O=72,I=128,R="-",B=/^xn--/,C=/[^\x20-\x7E]/,P=/[\x2E\u3002\uFF0E\uFF61]/g,L={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},H=g-_,K=Math.floor,V=String.fromCharCode,te;function U(c){throw new RangeError(L[c])}function j(c,x){for(var M=c.length,N=[];M--;)N[M]=x(c[M]);return N}function D(c,x){var M=c.split("@"),N="";M.length>1&&(N=M[0]+"@",c=M[1]),c=c.replace(P,".");var Y=c.split("."),se=j(Y,x).join(".");return N+se}function b(c){for(var x=[],M=0,N=c.length,Y,se;M<N;)Y=c.charCodeAt(M++),Y>=55296&&Y<=56319&&M<N?(se=c.charCodeAt(M++),(se&64512)==56320?x.push(((Y&1023)<<10)+(se&1023)+65536):(x.push(Y),M--)):x.push(Y);return x}function a(c){return j(c,function(x){var M="";return x>65535&&(x-=65536,M+=V(x>>>10&1023|55296),x=56320|x&1023),M+=V(x),M}).join("")}function h(c){return c-48<10?c-22:c-65<26?c-65:c-97<26?c-97:g}function u(c,x){return c+22+75*(c<26)-((x!=0)<<5)}function p(c,x,M){var N=0;for(c=M?K(c/S):c>>1,c+=K(c/x);c>H*E>>1;N+=g)c=K(c/H);return K(N+(H+1)*c/(c+A))}function y(c){var x=[],M=c.length,N,Y=0,se=I,Z=O,W,Q,ee,ce,X,$,ve,me,_e;for(W=c.lastIndexOf(R),W<0&&(W=0),Q=0;Q<W;++Q)c.charCodeAt(Q)>=128&&U("not-basic"),x.push(c.charCodeAt(Q));for(ee=W>0?W+1:0;ee<M;){for(ce=Y,X=1,$=g;ee>=M&&U("invalid-input"),ve=h(c.charCodeAt(ee++)),(ve>=g||ve>K((l-Y)/X))&&U("overflow"),Y+=ve*X,me=$<=Z?_:$>=Z+E?E:$-Z,!(ve<me);$+=g)_e=g-me,X>K(l/_e)&&U("overflow"),X*=_e;N=x.length+1,Z=p(Y-ce,N,ce==0),K(Y/N)>l-se&&U("overflow"),se+=K(Y/N),Y%=N,x.splice(Y++,0,se)}return a(x)}function m(c){var x,M,N,Y,se,Z,W,Q,ee,ce,X,$=[],ve,me,_e,Pe;for(c=b(c),ve=c.length,x=I,M=0,se=O,Z=0;Z<ve;++Z)X=c[Z],X<128&&$.push(V(X));for(N=Y=$.length,Y&&$.push(R);N<ve;){for(W=l,Z=0;Z<ve;++Z)X=c[Z],X>=x&&X<W&&(W=X);for(me=N+1,W-x>K((l-M)/me)&&U("overflow"),M+=(W-x)*me,x=W,Z=0;Z<ve;++Z)if(X=c[Z],X<x&&++M>l&&U("overflow"),X==x){for(Q=M,ee=g;ce=ee<=se?_:ee>=se+E?E:ee-se,!(Q<ce);ee+=g)Pe=Q-ce,_e=g-ce,$.push(V(u(ce+Pe%_e,0))),Q=K(Pe/_e);$.push(V(u(Q,0))),se=p(M,me,N==Y),M=0,++N}++M,++x}return $.join("")}function w(c){return D(c,function(x){return B.test(x)?y(x.slice(4).toLowerCase()):x})}function d(c){return D(c,function(x){return C.test(x)?"xn--"+m(x):x})}if(f={version:"1.4.1",ucs2:{decode:b,encode:a},decode:y,encode:m,toASCII:d,toUnicode:w},n&&s)if(t.exports==n)s.exports=f;else for(te in f)f.hasOwnProperty(te)&&(n[te]=f[te]);else r.punycode=f})(ht)}(Nl,Nl.exports);var fq=Nl.exports;const uq=Ep(fq);function cq(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var hq=function(t,e,r,n){e=e||"&",r=r||"=";var s={};if(typeof t!="string"||t.length===0)return s;var i=/\+/g;t=t.split(e);var f=1e3;n&&typeof n.maxKeys=="number"&&(f=n.maxKeys);var l=t.length;f>0&&l>f&&(l=f);for(var g=0;g<l;++g){var _=t[g].replace(i,"%20"),E=_.indexOf(r),A,S,O,I;E>=0?(A=_.substr(0,E),S=_.substr(E+1)):(A=_,S=""),O=decodeURIComponent(A),I=decodeURIComponent(S),cq(s,O)?dq(s[O])?s[O].push(I):s[O]=[s[O],I]:s[O]=I}return s},dq=Array.isArray||function(t){return Object.prototype.toString.call(t)==="[object Array]"},ph=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}},lq=function(t,e,r,n){return e=e||"&",r=r||"=",t===null&&(t=void 0),typeof t=="object"?v7(vq(t),function(s){var i=encodeURIComponent(ph(s))+r;return pq(t[s])?v7(t[s],function(f){return i+encodeURIComponent(ph(f))}).join(e):i+encodeURIComponent(ph(t[s]))}).join(e):n?encodeURIComponent(ph(n))+r+encodeURIComponent(ph(t)):""},pq=Array.isArray||function(t){return Object.prototype.toString.call(t)==="[object Array]"};function v7(t,e){if(t.map)return t.map(e);for(var r=[],n=0;n<t.length;n++)r.push(e(t[n],n));return r}var vq=Object.keys||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.push(r);return e},b7,g7,bq=g7=hq,gq=b7=lq;function mq(t){return encodeURIComponent(t)}function yq(t){return decodeURIComponent(t)}var wq={decode:bq,encode:gq,parse:g7,stringify:b7,escape:mq,unescape:yq},_q={isString:function(t){return typeof t=="string"},isObject:function(t){return typeof t=="object"&&t!==null},isNull:function(t){return t===null},isNullOrUndefined:function(t){return t==null}},Aq=uq,Fs=_q,Sq=vh,xq=Lq,m7=Dq,Eq=Nq,Iq=ki;function ki(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var Mq=/^([a-z0-9.+-]+:)/i,Rq=/:[0-9]*$/,Tq=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,Oq=["<",">",'"',"`"," ","\r",`
133
133
  `," "],Pq=["{","}","|","\\","^","`"].concat(Oq),om=["'"].concat(Pq),y7=["%","/","?",";","#"].concat(om),w7=["/","?","#"],Bq=255,_7=/^[+a-z0-9A-Z_-]{0,63}$/,Cq=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,kq={javascript:!0,"javascript:":!0},fm={javascript:!0,"javascript:":!0},Bu={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},um=wq;function vh(t,e,r){if(t&&Fs.isObject(t)&&t instanceof ki)return t;var n=new ki;return n.parse(t,e,r),n}ki.prototype.parse=function(t,e,r){if(!Fs.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var n=t.indexOf("?"),s=n!==-1&&n<t.indexOf("#")?"?":"#",i=t.split(s),f=/\\/g;i[0]=i[0].replace(f,"/"),t=i.join(s);var l=t;if(l=l.trim(),!r&&t.split("#").length===1){var g=Tq.exec(l);if(g)return this.path=l,this.href=l,this.pathname=g[1],g[2]?(this.search=g[2],e?this.query=um.parse(this.search.substr(1)):this.query=this.search.substr(1)):e&&(this.search="",this.query={}),this}var _=Mq.exec(l);if(_){_=_[0];var E=_.toLowerCase();this.protocol=E,l=l.substr(_.length)}if(r||_||l.match(/^\/\/[^@\/]+@[^@\/]+/)){var A=l.substr(0,2)==="//";A&&!(_&&fm[_])&&(l=l.substr(2),this.slashes=!0)}if(!fm[_]&&(A||_&&!Bu[_])){for(var S=-1,O=0;O<w7.length;O++){var I=l.indexOf(w7[O]);I!==-1&&(S===-1||I<S)&&(S=I)}var R,B;S===-1?B=l.lastIndexOf("@"):B=l.lastIndexOf("@",S),B!==-1&&(R=l.slice(0,B),l=l.slice(B+1),this.auth=decodeURIComponent(R)),S=-1;for(var O=0;O<y7.length;O++){var I=l.indexOf(y7[O]);I!==-1&&(S===-1||I<S)&&(S=I)}S===-1&&(S=l.length),this.host=l.slice(0,S),l=l.slice(S),this.parseHost(),this.hostname=this.hostname||"";var C=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!C)for(var P=this.hostname.split(/\./),O=0,L=P.length;O<L;O++){var H=P[O];if(H&&!H.match(_7)){for(var K="",V=0,te=H.length;V<te;V++)H.charCodeAt(V)>127?K+="x":K+=H[V];if(!K.match(_7)){var U=P.slice(0,O),j=P.slice(O+1),D=H.match(Cq);D&&(U.push(D[1]),j.unshift(D[2])),j.length&&(l="/"+j.join(".")+l),this.hostname=U.join(".");break}}}this.hostname.length>Bq?this.hostname="":this.hostname=this.hostname.toLowerCase(),C||(this.hostname=Aq.toASCII(this.hostname));var b=this.port?":"+this.port:"",a=this.hostname||"";this.host=a+b,this.href+=this.host,C&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),l[0]!=="/"&&(l="/"+l))}if(!kq[E])for(var O=0,L=om.length;O<L;O++){var h=om[O];if(l.indexOf(h)!==-1){var u=encodeURIComponent(h);u===h&&(u=escape(h)),l=l.split(h).join(u)}}var p=l.indexOf("#");p!==-1&&(this.hash=l.substr(p),l=l.slice(0,p));var y=l.indexOf("?");if(y!==-1?(this.search=l.substr(y),this.query=l.substr(y+1),e&&(this.query=um.parse(this.query)),l=l.slice(0,y)):e&&(this.search="",this.query={}),l&&(this.pathname=l),Bu[E]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var b=this.pathname||"",m=this.search||"";this.path=b+m}return this.href=this.format(),this};function Nq(t){return Fs.isString(t)&&(t=vh(t)),t instanceof ki?t.format():ki.prototype.format.call(t)}ki.prototype.format=function(){var t=this.auth||"";t&&(t=encodeURIComponent(t),t=t.replace(/%3A/i,":"),t+="@");var e=this.protocol||"",r=this.pathname||"",n=this.hash||"",s=!1,i="";this.host?s=t+this.host:this.hostname&&(s=t+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(s+=":"+this.port)),this.query&&Fs.isObject(this.query)&&Object.keys(this.query).length&&(i=um.stringify(this.query));var f=this.search||i&&"?"+i||"";return e&&e.substr(-1)!==":"&&(e+=":"),this.slashes||(!e||Bu[e])&&s!==!1?(s="//"+(s||""),r&&r.charAt(0)!=="/"&&(r="/"+r)):s||(s=""),n&&n.charAt(0)!=="#"&&(n="#"+n),f&&f.charAt(0)!=="?"&&(f="?"+f),r=r.replace(/[?#]/g,function(l){return encodeURIComponent(l)}),f=f.replace("#","%23"),e+s+r+f+n};function Lq(t,e){return vh(t,!1,!0).resolve(e)}ki.prototype.resolve=function(t){return this.resolveObject(vh(t,!1,!0)).format()};function Dq(t,e){return t?vh(t,!1,!0).resolveObject(e):e}ki.prototype.resolveObject=function(t){if(Fs.isString(t)){var e=new ki;e.parse(t,!1,!0),t=e}for(var r=new ki,n=Object.keys(this),s=0;s<n.length;s++){var i=n[s];r[i]=this[i]}if(r.hash=t.hash,t.href==="")return r.href=r.format(),r;if(t.slashes&&!t.protocol){for(var f=Object.keys(t),l=0;l<f.length;l++){var g=f[l];g!=="protocol"&&(r[g]=t[g])}return Bu[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(t.protocol&&t.protocol!==r.protocol){if(!Bu[t.protocol]){for(var _=Object.keys(t),E=0;E<_.length;E++){var A=_[E];r[A]=t[A]}return r.href=r.format(),r}if(r.protocol=t.protocol,!t.host&&!fm[t.protocol]){for(var L=(t.pathname||"").split("/");L.length&&!(t.host=L.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),L[0]!==""&&L.unshift(""),L.length<2&&L.unshift(""),r.pathname=L.join("/")}else r.pathname=t.pathname;if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search){var S=r.pathname||"",O=r.search||"";r.path=S+O}return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var I=r.pathname&&r.pathname.charAt(0)==="/",R=t.host||t.pathname&&t.pathname.charAt(0)==="/",B=R||I||r.host&&t.pathname,C=B,P=r.pathname&&r.pathname.split("/")||[],L=t.pathname&&t.pathname.split("/")||[],H=r.protocol&&!Bu[r.protocol];if(H&&(r.hostname="",r.port=null,r.host&&(P[0]===""?P[0]=r.host:P.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(L[0]===""?L[0]=t.host:L.unshift(t.host)),t.host=null),B=B&&(L[0]===""||P[0]==="")),R)r.host=t.host||t.host===""?t.host:r.host,r.hostname=t.hostname||t.hostname===""?t.hostname:r.hostname,r.search=t.search,r.query=t.query,P=L;else if(L.length)P||(P=[]),P.pop(),P=P.concat(L),r.search=t.search,r.query=t.query;else if(!Fs.isNullOrUndefined(t.search)){if(H){r.hostname=r.host=P.shift();var K=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;K&&(r.auth=K.shift(),r.host=r.hostname=K.shift())}return r.search=t.search,r.query=t.query,(!Fs.isNull(r.pathname)||!Fs.isNull(r.search))&&(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!P.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var V=P.slice(-1)[0],te=(r.host||t.host||P.length>1)&&(V==="."||V==="..")||V==="",U=0,j=P.length;j>=0;j--)V=P[j],V==="."?P.splice(j,1):V===".."?(P.splice(j,1),U++):U&&(P.splice(j,1),U--);if(!B&&!C)for(;U--;U)P.unshift("..");B&&P[0]!==""&&(!P[0]||P[0].charAt(0)!=="/")&&P.unshift(""),te&&P.join("/").substr(-1)!=="/"&&P.push("");var D=P[0]===""||P[0]&&P[0].charAt(0)==="/";if(H){r.hostname=r.host=D?"":P.length?P.shift():"";var K=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;K&&(r.auth=K.shift(),r.host=r.hostname=K.shift())}return B=B||r.host&&P.length,B&&!D&&P.unshift(""),P.length?r.pathname=P.join("/"):(r.pathname=null,r.path=null),(!Fs.isNull(r.pathname)||!Fs.isNull(r.search))&&(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},ki.prototype.parseHost=function(){var t=this.host,e=Rq.exec(t);e&&(e=e[0],e!==":"&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)};function Uq(t,e){for(var r=0,n=t.length-1;n>=0;n--){var s=t[n];s==="."?t.splice(n,1):s===".."?(t.splice(n,1),r++):r&&(t.splice(n,1),r--)}if(e)for(;r--;r)t.unshift("..");return t}function Fq(){for(var t="",e=!1,r=arguments.length-1;r>=-1&&!e;r--){var n=r>=0?arguments[r]:"/";if(typeof n!="string")throw new TypeError("Arguments to path.resolve must be strings");if(!n)continue;t=n+"/"+t,e=n.charAt(0)==="/"}return t=Uq(Hq(t.split("/"),function(s){return!!s}),!e).join("/"),(e?"/":"")+t||"."}function Hq(t,e){if(t.filter)return t.filter(e);for(var r=[],n=0;n<t.length;n++)e(t[n],n,t)&&r.push(t[n]);return r}var A7=function(t){function e(){var n=this||self;return delete t.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();t.defineProperty(t.prototype,"__magic__",{configurable:!0,get:e});var r=__magic__;return r}(Object),qq=Eq,S7=Sq,x7=xq,E7=Iq,to=A7.URL,I7=A7.URLSearchParams,zq=/%/g,jq=/\\/g,Kq=/\n/g,Vq=/\r/g,Wq=/\t/g,Gq=47;function $q(t){var e=t??null;return!!(e!==null&&(e!=null&&e.href)&&(e!=null&&e.origin))}function Zq(t){if(t.hostname!=="")throw new TypeError('File URL host must be "localhost" or empty on browser');for(var e=t.pathname,r=0;r<e.length;r++)if(e[r]==="%"){var n=e.codePointAt(r+2)|32;if(e[r+1]==="2"&&n===102)throw new TypeError("File URL path must not include encoded / characters")}return decodeURIComponent(e)}function Xq(t){return t.includes("%")&&(t=t.replace(zq,"%25")),t.includes("\\")&&(t=t.replace(jq,"%5C")),t.includes(`
134
- `)&&(t=t.replace(Kq,"%0A")),t.includes("\r")&&(t=t.replace(Vq,"%0D")),t.includes(" ")&&(t=t.replace(Wq,"%09")),t}var M7=function(e){if(typeof e>"u")throw new TypeError('The "domain" argument must be specified');return new to("http://"+e).hostname},R7=function(e){if(typeof e>"u")throw new TypeError('The "domain" argument must be specified');return new to("http://"+e).hostname},T7=function(e){var r=new to("file://"),n=Fq(e),s=e.charCodeAt(e.length-1);return s===Gq&&n[n.length-1]!=="/"&&(n+="/"),r.pathname=Xq(n),r},O7=function(e){if(!$q(e)&&typeof e!="string")throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type '+typeof e+" ("+e+")");var r=new to(e);if(r.protocol!=="file:")throw new TypeError("The URL must be of scheme file");return Zq(r)},P7=function(e,r){var n,s,i;if(r===void 0&&(r={}),!(e instanceof to))return qq(e);if(typeof r!="object"||r===null)throw new TypeError('The "options" argument must be of type object.');var f=(n=r.auth)!=null?n:!0,l=(s=r.fragment)!=null?s:!0,g=(i=r.search)!=null?i:!0,_=new to(e.toString());return f||(_.username="",_.password=""),l||(_.hash=""),g||(_.search=""),_.toString()},Jq={format:P7,parse:S7,resolve:x7,resolveObject:m7,Url:E7,URL:to,URLSearchParams:I7,domainToASCII:M7,domainToUnicode:R7,pathToFileURL:T7,fileURLToPath:O7};const Yq=C2(Object.freeze(Object.defineProperty({__proto__:null,URL:to,URLSearchParams:I7,Url:E7,default:Jq,domainToASCII:M7,domainToUnicode:R7,fileURLToPath:O7,format:P7,parse:S7,pathToFileURL:T7,resolve:x7,resolveObject:m7},Symbol.toStringTag,{value:"Module"})));var B7=Xt,C7=Yq,k7=Ds(),N7=Kg,xr=function(t,e){if(!(this instanceof xr))return new xr(t,e);if(this.extras={},this.knownParams=e||[],this.address=this.network=this.amount=this.message=null,typeof t=="string"){var r=xr.parse(t);r.amount&&(r.amount=this._parseAmount(r.amount)),this._fromObject(r)}else if(typeof t=="object")this._fromObject(t);else throw new TypeError("Unrecognized data format.")};xr.fromString=function(e){if(typeof e!="string")throw new TypeError("Expected a string");return new xr(e)},xr.fromObject=function(e){return new xr(e)},xr.isValid=function(t,e){try{new xr(t,e)}catch{return!1}return!0},xr.parse=function(t){var e=C7.parse(t,!0);if(e.protocol!=="bitcoin:")throw new TypeError("Invalid bitcoin URI");var r=/[^:]*:\/?\/?([^?]*)/.exec(t);return e.query.address=r&&r[1]||void 0,e.query},xr.Members=["address","amount","message","label","r"],xr.prototype._fromObject=function(t){if(!k7.isValid(t.address))throw new TypeError("Invalid bitcoin address");this.address=new k7(t.address),this.network=this.address.network,this.amount=t.amount;for(var e in t)if(!(e==="address"||e==="amount")){if(/^req-/.exec(e)&&this.knownParams.indexOf(e)===-1)throw Error("Unknown required argument "+e);var r=xr.Members.indexOf(e)>-1?this:this.extras;r[e]=t[e]}},xr.prototype._parseAmount=function(t){if(t=Number(t),isNaN(t))throw new TypeError("Invalid amount");return N7.fromBTC(t).toSatoshis()},xr.prototype.toObject=xr.prototype.toJSON=function(){for(var e={},r=0;r<xr.Members.length;r++){var n=xr.Members[r];this.hasOwnProperty(n)&&typeof this[n]<"u"&&(e[n]=this[n].toString())}return B7.extend(e,this.extras),e},xr.prototype.toString=function(){var t={};return this.amount&&(t.amount=N7.fromSatoshis(this.amount).toBTC()),this.message&&(t.message=this.message),this.label&&(t.label=this.label),this.r&&(t.r=this.r),B7.extend(t,this.extras),C7.format({protocol:"bitcoin:",host:this.address,query:t})},xr.prototype.inspect=function(){return"<URI: "+this.toString()+">"};var Qq=xr;(function(t){var e=t.exports;e.version="v"+DD.version,e.versionGuard=function(r){if(r!==void 0){var n="More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.";throw new Error(n)}},e.versionGuard(ht._bitcore),ht._bitcore=e.version,e.crypto={},e.crypto.BN=sn,e.crypto.ECDSA=Tl(),e.crypto.Schnorr=M_,e.crypto.Hash=kr,e.crypto.Random=Rl,e.crypto.Point=Zo,e.crypto.Signature=Pn,e.crypto.TaggedHash=Xa,e.encoding={},e.encoding.Base58=wl,e.encoding.Base58Check=ah,e.encoding.BufferReader=da,e.encoding.BufferWriter=on,e.encoding.Varint=GH,e.util={},e.util.buffer=ur,e.util.js=nn,e.util.preconditions=$t,e.errors=Oi,e.Address=Ds(),e.Block=rq,e.MerkleBlock=u7,e.BlockHeader=Cl,e.HDPrivateKey=l7(),e.HDPublicKey=h7(),e.Message=oq,e.Networks=Jo,e.Opcode=Mg,e.PrivateKey=nf(),e.PublicKey=Us(),e.Script=ti(),e.Transaction=Ml(),e.URI=Qq,e.Unit=Kg,e.deps={},e.deps.bnjs=V8,e.deps.bs58=p_,e.deps.Buffer=pe,e.deps.elliptic=Qb,e.deps._=Xt,e.Transaction.sighash=Qa()})(K8);var L7=K8.exports;const bh=Ep(L7),ez=Zn({__proto__:null,default:bh},[L7]),of=t=>u1.div(t,1e8,8),D7=t=>u1.mul(t,1e8,8),tz=Object.freeze(Object.defineProperty({__proto__:null,base58Decode:PI,base58Encode:OI,bufferToString:BI,checkWebSocket:f1,fromSatoshi:of,hexToNumber:TI,isMobile:LI,isNumeric:kI,isWebview:DI,math:u1,numberToHex:RI,objectsEqual:Dy,sleep:Ly,stringToBuffer:CI,toHex:Cy,toReadableString:NI,toSatoshi:D7},Symbol.toStringTag,{value:"Module"}));class U7{constructor(e,r){St(this,"rawData");St(this,"signedData");St(this,"provider");this.rawData=e,this.provider=r??Ca.instance}async sign(e){return this.rawData.bitcoreLib.sign(e),this.signedData=this.rawData.bitcoreLib.serialize(),this}async send(){var e;try{return(await nr({method:"POST",url:this.provider.createEndpoint("tx"),data:this.signedData})).data}catch(r){throw new Error(JSON.stringify((e=r.response)==null?void 0:e.data))}}getRawData(){return this.rawData}getSignedData(){return this.signedData??""}}class rz{constructor(e){St(this,"provider");this.provider=e??Ca.instance}getName(){return"Bitcoin"}getSymbol(){return"BTC"}getDecimals(){return 8}async getBalance(e){const r=this.provider.createEndpoint("address/"+e),n=await nr.get(r).then(i=>i.data),s=n.chain_stats.funded_txo_sum-n.chain_stats.spent_txo_sum;return of(s)}async transfer(e,r,n){if(n<0)throw new Error(tn.INVALID_AMOUNT);if(n>await this.getBalance(e))throw new Error(tn.INSUFFICIENT_BALANCE);if(e===r)throw new Error(tn.INVALID_ADDRESS);const s=[],i=new bh.Transaction,f=new bh.Address(e),l=D7(n),g=await nr.get(this.provider.createEndpoint("address/"+e+"/utxo")).then(_=>_.data);for(const _ of g)s.push(new bh.Transaction.UnspentOutput({txId:_.txid,satoshis:_.value,address:f,outputIndex:_.vout,script:bh.Script.fromAddress(f)}));return i.from(s),i.change(e),i.to(r,l),new U7({sender:e,receiver:r,amount:l,bitcoreLib:i})}}const nz=Object.freeze(Object.defineProperty({__proto__:null,Coin:rz},Symbol.toStringTag,{value:"Module"}));let F7=0;class cm{constructor(e,r){St(this,"id");St(this,"provider");St(this,"data",null);this.id=e,this.provider=r??Ca.instance}async getData(){var e;if(this.data!==null)return this.data;try{const r=(await nr.get(this.provider.createEndpoint("tx/"+this.id))).data;return(r==null?void 0:r.txid)!==this.id?this.data=null:this.data=r}catch(r){console.error("MC Bitcoin TX getData",r);const n=r;if(String((e=n==null?void 0:n.response)==null?void 0:e.data).includes("Transaction not found")){if(F7>5)throw new Error(tn.TRANSACTION_NOT_FOUND);return F7++,await Ly(2e3),await this.getData()}throw new Error(tn.RPC_REQUEST_ERROR)}}async wait(e=4e3){return await new Promise((r,n)=>{const s=async()=>{try{const i=await this.getStatus();if(i===en.CONFIRMED){r(en.CONFIRMED);return}else if(i===en.FAILED){n(en.FAILED);return}setTimeout(s,e)}catch(i){console.error("MC Bitcoin TX wait",i),n(en.FAILED)}};s()})}getId(){return this.id}async getType(){return Ia.COIN}getUrl(){return this.provider.explorer+"tx/"+this.id}async getSigner(){const e=await this.getData();return(e==null?void 0:e.vin[0].prevout.scriptpubkey_address)??""}async getFee(){const e=await this.getData();return of((e==null?void 0:e.fee)??0)}async getBlockNumber(){var r;const e=await this.getData();return((r=e==null?void 0:e.status)==null?void 0:r.block_height)??0}async getBlockTimestamp(){var r;const e=await this.getData();return((r=e==null?void 0:e.status)==null?void 0:r.block_time)??0}async getBlockConfirmationCount(){var n;const e=await this.getData();return e===null?0:(await nr.get(this.provider.createEndpoint("blocks/tip/height"))).data-((n=e==null?void 0:e.status)==null?void 0:n.block_height)}async getStatus(){var r;const e=await this.getData();return e===null?en.PENDING:((r=e.status)==null?void 0:r.block_height)!==void 0?e.status.confirmed?en.CONFIRMED:en.FAILED:en.PENDING}}class H7 extends cm{async getReceiver(){const e=await this.getData();return(e==null?void 0:e.vout[0].scriptpubkey_address)??""}async getSender(){return await this.getSigner()}async getAmount(){const e=await this.getData();return of((e==null?void 0:e.vout[0].value)??0)}async verifyTransfer(e,r,n){if(await this.getStatus()===en.PENDING)return en.PENDING;if(await this.getAmount()!==n)return en.FAILED;if(e===js.INCOMING){if((await this.getReceiver()).toLowerCase()!==r.toLowerCase())return en.FAILED}else if((await this.getSender()).toLowerCase()!==r.toLowerCase())return en.FAILED;return en.CONFIRMED}}const iz=Object.freeze(Object.defineProperty({__proto__:null,CoinTransaction:H7,Transaction:cm},Symbol.toStringTag,{value:"Module"}));var Cu=null;typeof WebSocket<"u"?Cu=WebSocket:typeof MozWebSocket<"u"?Cu=MozWebSocket:typeof Ch<"u"?Cu=Ch.WebSocket||Ch.MozWebSocket:typeof window<"u"?Cu=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(Cu=self.WebSocket||self.MozWebSocket);const sz=Cu;class az{constructor(e,r,n){St(this,"type");St(this,"provider");St(this,"status",!1);St(this,"callbacks",[]);St(this,"triggeredTransactions",[]);St(this,"filter");St(this,"webSocket");St(this,"dynamicStop",()=>{});this.type=e,this.filter=r??{},this.provider=n??Ca.instance}stop(){this.status&&(this.status=!1,this.dynamicStop())}start(){this.status||(this.status=!0,this[A2[this.type]]())}getStatus(){return this.status}async on(e){if(this.webSocket===void 0)try{await f1(this.provider.wsUrl),this.webSocket=new sz(this.provider.wsUrl)}catch(r){throw new Error("WebSocket connection is not available"+(r instanceof Error?": "+r.message:""))}return this.start(),this.callbacks.push(e),!0}trigger(e){this.triggeredTransactions.includes(e.id)||(this.triggeredTransactions.push(e.id),this.callbacks.forEach(r=>{r(e)}))}createMessage(e){let r;if(this.provider.isTestnet())r=JSON.stringify({"track-address":e});else if(this.provider.blockCypherToken!==void 0){const n={event:"unconfirmed-tx",token:this.provider.blockCypherToken};e!==void 0&&(n.address=e),r=JSON.stringify(n)}else r=JSON.stringify({op:"unconfirmed_sub"});return this.dynamicStop=()=>{this.provider.blockCypherToken===void 0&&this.webSocket.send(JSON.stringify({op:"unconfirmed_unsub"})),this.webSocket.close()},r}getValues(e){var n,s;const r={txId:""};if(console.log("Received data:",e),this.provider.isTestnet()){const i=((n=e["address-transactions"])==null?void 0:n[0])??((s=e["block-transactions"])==null?void 0:s[0]);r.txId=i.txid,r.sender=i.vin[0].prevout.scriptpubkey_address,r.receiver=i.vout[0].scriptpubkey_address,r.amount=of(i.vout[0].value)}else this.provider.blockCypherToken!==void 0?(r.txId=e.hash,r.sender=e.inputs[0].addresses[0],r.receiver=e.outputs[0].addresses[0],r.amount=of(e.outputs[0].value)):(r.txId=e.x.hash,r.receiver=e.x.out[0].addr,r.sender=e.x.inputs[0].prev_out.addr,r.amount=of(e.x.out[0].value));return r}generalProcess(){var r,n;if(this.provider.isTestnet()&&((r=this.filter)==null?void 0:r.signer)===void 0)throw new Error("General transaction listener must have a signer filter in testnet.");const e=this.createMessage((n=this.filter)==null?void 0:n.signer);this.webSocket.addEventListener("open",()=>{this.webSocket.send(e)}),this.webSocket.addEventListener("message",async s=>{var l,g;const i=JSON.parse(s.data);if(i.loadingIndicators)return;const f=this.getValues(i);((l=this.filter)==null?void 0:l.signer)!==void 0&&((g=f.sender)==null?void 0:g.toLowerCase())!==this.filter.signer.toLowerCase()||this.trigger(new cm(f.txId))})}contractProcess(){throw new Error("This method is not implemented for Bitcoin.")}coinProcess(){const e=this.filter;if(e.signer!==void 0&&e.sender!==void 0&&e.signer!==e.sender)throw new Error("Sender and signer must be the same in coin transactions. Or only one of them can be defined.");const r=e.sender??e.signer,n=this.createMessage(e.receiver);this.webSocket.addEventListener("open",()=>{this.webSocket.send(n)}),this.webSocket.addEventListener("message",async s=>{var E,A;const i=JSON.parse(s.data);if(i.loadingIndicators)return;const f={},l={};if(i.event&&String(i.event).includes("events limit reached"))throw new Error("BlockCypher events limit reached.");const g=this.getValues(i);if(r!==void 0&&(f.sender=r.toLowerCase(),l.sender=(E=g.sender)==null?void 0:E.toLowerCase()),e.receiver!==void 0&&(f.receiver=e.receiver.toLowerCase(),l.receiver=(A=g.receiver)==null?void 0:A.toLowerCase()),!Dy(f,l))return;const _=new H7(g.txId);e.amount!==void 0&&g.amount!==e.amount||this.trigger(_)})}tokenProcess(){throw new Error("This method is not implemented for Bitcoin.")}nftProcess(){throw new Error("This method is not implemented for Bitcoin.")}}const oz=Object.freeze(Object.defineProperty({__proto__:null,TransactionListener:az,TransactionSigner:U7},Symbol.toStringTag,{value:"Module"})),hm={},fz={Wallet:UI,registerAdapter:t=>{if(Object.values(hm).find(e=>e.id===t.id)!==void 0)throw new Error(`Adapter with id ${t.id} already exists`);hm[t.id]=t},adapters:Object.assign(hm,LD)};wr.Provider=Ca,wr.assets=nz,wr.bitcore=ez,wr.browser=fz,wr.models=iz,wr.services=oz,wr.types=fS,wr.utils=tz,Object.defineProperty(wr,Symbol.toStringTag,{value:"Module"})});
134
+ `)&&(t=t.replace(Kq,"%0A")),t.includes("\r")&&(t=t.replace(Vq,"%0D")),t.includes(" ")&&(t=t.replace(Wq,"%09")),t}var M7=function(e){if(typeof e>"u")throw new TypeError('The "domain" argument must be specified');return new to("http://"+e).hostname},R7=function(e){if(typeof e>"u")throw new TypeError('The "domain" argument must be specified');return new to("http://"+e).hostname},T7=function(e){var r=new to("file://"),n=Fq(e),s=e.charCodeAt(e.length-1);return s===Gq&&n[n.length-1]!=="/"&&(n+="/"),r.pathname=Xq(n),r},O7=function(e){if(!$q(e)&&typeof e!="string")throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type '+typeof e+" ("+e+")");var r=new to(e);if(r.protocol!=="file:")throw new TypeError("The URL must be of scheme file");return Zq(r)},P7=function(e,r){var n,s,i;if(r===void 0&&(r={}),!(e instanceof to))return qq(e);if(typeof r!="object"||r===null)throw new TypeError('The "options" argument must be of type object.');var f=(n=r.auth)!=null?n:!0,l=(s=r.fragment)!=null?s:!0,g=(i=r.search)!=null?i:!0,_=new to(e.toString());return f||(_.username="",_.password=""),l||(_.hash=""),g||(_.search=""),_.toString()},Jq={format:P7,parse:S7,resolve:x7,resolveObject:m7,Url:E7,URL:to,URLSearchParams:I7,domainToASCII:M7,domainToUnicode:R7,pathToFileURL:T7,fileURLToPath:O7};const Yq=C2(Object.freeze(Object.defineProperty({__proto__:null,URL:to,URLSearchParams:I7,Url:E7,default:Jq,domainToASCII:M7,domainToUnicode:R7,fileURLToPath:O7,format:P7,parse:S7,pathToFileURL:T7,resolve:x7,resolveObject:m7},Symbol.toStringTag,{value:"Module"})));var B7=Xt,C7=Yq,k7=Ds(),N7=Kg,xr=function(t,e){if(!(this instanceof xr))return new xr(t,e);if(this.extras={},this.knownParams=e||[],this.address=this.network=this.amount=this.message=null,typeof t=="string"){var r=xr.parse(t);r.amount&&(r.amount=this._parseAmount(r.amount)),this._fromObject(r)}else if(typeof t=="object")this._fromObject(t);else throw new TypeError("Unrecognized data format.")};xr.fromString=function(e){if(typeof e!="string")throw new TypeError("Expected a string");return new xr(e)},xr.fromObject=function(e){return new xr(e)},xr.isValid=function(t,e){try{new xr(t,e)}catch{return!1}return!0},xr.parse=function(t){var e=C7.parse(t,!0);if(e.protocol!=="bitcoin:")throw new TypeError("Invalid bitcoin URI");var r=/[^:]*:\/?\/?([^?]*)/.exec(t);return e.query.address=r&&r[1]||void 0,e.query},xr.Members=["address","amount","message","label","r"],xr.prototype._fromObject=function(t){if(!k7.isValid(t.address))throw new TypeError("Invalid bitcoin address");this.address=new k7(t.address),this.network=this.address.network,this.amount=t.amount;for(var e in t)if(!(e==="address"||e==="amount")){if(/^req-/.exec(e)&&this.knownParams.indexOf(e)===-1)throw Error("Unknown required argument "+e);var r=xr.Members.indexOf(e)>-1?this:this.extras;r[e]=t[e]}},xr.prototype._parseAmount=function(t){if(t=Number(t),isNaN(t))throw new TypeError("Invalid amount");return N7.fromBTC(t).toSatoshis()},xr.prototype.toObject=xr.prototype.toJSON=function(){for(var e={},r=0;r<xr.Members.length;r++){var n=xr.Members[r];this.hasOwnProperty(n)&&typeof this[n]<"u"&&(e[n]=this[n].toString())}return B7.extend(e,this.extras),e},xr.prototype.toString=function(){var t={};return this.amount&&(t.amount=N7.fromSatoshis(this.amount).toBTC()),this.message&&(t.message=this.message),this.label&&(t.label=this.label),this.r&&(t.r=this.r),B7.extend(t,this.extras),C7.format({protocol:"bitcoin:",host:this.address,query:t})},xr.prototype.inspect=function(){return"<URI: "+this.toString()+">"};var Qq=xr;(function(t){var e=t.exports;e.version="v"+DD.version,e.versionGuard=function(r){if(r!==void 0){var n="More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.";throw new Error(n)}},e.versionGuard(ht._bitcore),ht._bitcore=e.version,e.crypto={},e.crypto.BN=sn,e.crypto.ECDSA=Tl(),e.crypto.Schnorr=M_,e.crypto.Hash=kr,e.crypto.Random=Rl,e.crypto.Point=Zo,e.crypto.Signature=Pn,e.crypto.TaggedHash=Xa,e.encoding={},e.encoding.Base58=wl,e.encoding.Base58Check=ah,e.encoding.BufferReader=da,e.encoding.BufferWriter=on,e.encoding.Varint=GH,e.util={},e.util.buffer=ur,e.util.js=nn,e.util.preconditions=$t,e.errors=Oi,e.Address=Ds(),e.Block=rq,e.MerkleBlock=u7,e.BlockHeader=Cl,e.HDPrivateKey=l7(),e.HDPublicKey=h7(),e.Message=oq,e.Networks=Jo,e.Opcode=Mg,e.PrivateKey=nf(),e.PublicKey=Us(),e.Script=ti(),e.Transaction=Ml(),e.URI=Qq,e.Unit=Kg,e.deps={},e.deps.bnjs=V8,e.deps.bs58=p_,e.deps.Buffer=pe,e.deps.elliptic=Qb,e.deps._=Xt,e.Transaction.sighash=Qa()})(K8);var L7=K8.exports;const bh=Ep(L7),ez=Zn({__proto__:null,default:bh},[L7]),of=t=>u1.div(t,1e8,8),D7=t=>u1.mul(t,1e8,8),tz=Object.freeze(Object.defineProperty({__proto__:null,base58Decode:PI,base58Encode:OI,bufferToString:BI,checkWebSocket:f1,fromSatoshi:of,hexToNumber:TI,isMobile:LI,isNumeric:kI,isWebview:DI,math:u1,numberToHex:RI,objectsEqual:Dy,sleep:Ly,stringToBuffer:CI,toHex:Cy,toReadableString:NI,toSatoshi:D7},Symbol.toStringTag,{value:"Module"}));class U7{constructor(e,r){St(this,"rawData");St(this,"signedData");St(this,"provider");this.rawData=e,this.provider=r??Ca.instance}async sign(e){return this.rawData.bitcoreLib.sign(e),this.signedData=this.rawData.bitcoreLib.serialize(),this}async send(){var e;try{return(await nr({method:"POST",url:this.provider.createEndpoint("tx"),data:this.signedData})).data}catch(r){throw new Error(JSON.stringify((e=r.response)==null?void 0:e.data))}}getRawData(){return this.rawData}getSignedData(){return this.signedData??""}}class rz{constructor(e){St(this,"provider");this.provider=e??Ca.instance}getName(){return"Bitcoin"}getSymbol(){return"BTC"}getDecimals(){return 8}async getBalance(e){const r=this.provider.createEndpoint("address/"+e),n=await nr.get(r).then(i=>i.data),s=n.chain_stats.funded_txo_sum-n.chain_stats.spent_txo_sum;return of(s)}async transfer(e,r,n){if(n<0)throw new Error(tn.INVALID_AMOUNT);if(n>await this.getBalance(e))throw new Error(tn.INSUFFICIENT_BALANCE);if(e===r)throw new Error(tn.INVALID_ADDRESS);const s=[],i=new bh.Transaction,f=new bh.Address(e),l=D7(n),g=await nr.get(this.provider.createEndpoint("address/"+e+"/utxo")).then(_=>_.data);for(const _ of g)s.push(new bh.Transaction.UnspentOutput({txId:_.txid,satoshis:_.value,address:f,outputIndex:_.vout,script:bh.Script.fromAddress(f)}));return i.from(s),i.change(e),i.to(r,l),new U7({sender:e,receiver:r,amount:l,bitcoreLib:i})}}const nz=Object.freeze(Object.defineProperty({__proto__:null,Coin:rz},Symbol.toStringTag,{value:"Module"}));let F7=0;class cm{constructor(e,r){St(this,"id");St(this,"provider");St(this,"data",null);this.id=e,this.provider=r??Ca.instance}async getData(){var e;if(this.data!==null)return this.data;try{const r=(await nr.get(this.provider.createEndpoint("tx/"+this.id))).data;return(r==null?void 0:r.txid)!==this.id?this.data=null:this.data=r}catch(r){console.error("MC Bitcoin TX getData",r);const n=r;if(String((e=n==null?void 0:n.response)==null?void 0:e.data).includes("Transaction not found")){if(F7>5)throw new Error(tn.TRANSACTION_NOT_FOUND);return F7++,await Ly(2e3),await this.getData()}throw new Error(tn.RPC_REQUEST_ERROR)}}async wait(e=4e3){return await new Promise((r,n)=>{const s=async()=>{try{const i=await this.getStatus();if(i===en.CONFIRMED){r(en.CONFIRMED);return}else if(i===en.FAILED){n(en.FAILED);return}setTimeout(s,e)}catch(i){console.error("MC Bitcoin TX wait",i),n(en.FAILED)}};s()})}getId(){return this.id}async getType(){return Ia.COIN}getUrl(){return this.provider.explorer+"tx/"+this.id}async getSigner(){const e=await this.getData();return(e==null?void 0:e.vin[0].prevout.scriptpubkey_address)??""}async getFee(){const e=await this.getData();return of((e==null?void 0:e.fee)??0)}async getBlockNumber(){var r;const e=await this.getData();return((r=e==null?void 0:e.status)==null?void 0:r.block_height)??0}async getBlockTimestamp(){var r;const e=await this.getData();return((r=e==null?void 0:e.status)==null?void 0:r.block_time)??0}async getBlockConfirmationCount(){var n;const e=await this.getData();return e===null?0:(await nr.get(this.provider.createEndpoint("blocks/tip/height"))).data-((n=e==null?void 0:e.status)==null?void 0:n.block_height)}async getStatus(){var r;const e=await this.getData();return e===null?en.PENDING:((r=e.status)==null?void 0:r.block_height)!==void 0?e.status.confirmed?en.CONFIRMED:en.FAILED:en.PENDING}}class H7 extends cm{async getReceiver(){const e=await this.getData();return(e==null?void 0:e.vout[0].scriptpubkey_address)??""}async getSender(){return await this.getSigner()}async getAmount(){const e=await this.getData();return of((e==null?void 0:e.vout[0].value)??0)}async verifyTransfer(e,r,n){if(await this.getStatus()===en.PENDING)return en.PENDING;if(await this.getAmount()!==n)return en.FAILED;if(e===js.INCOMING){if((await this.getReceiver()).toLowerCase()!==r.toLowerCase())return en.FAILED}else if((await this.getSender()).toLowerCase()!==r.toLowerCase())return en.FAILED;return en.CONFIRMED}}const iz=Object.freeze(Object.defineProperty({__proto__:null,CoinTransaction:H7,Transaction:cm},Symbol.toStringTag,{value:"Module"}));var Cu=null;typeof WebSocket<"u"?Cu=WebSocket:typeof MozWebSocket<"u"?Cu=MozWebSocket:typeof Ch<"u"?Cu=Ch.WebSocket||Ch.MozWebSocket:typeof window<"u"?Cu=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(Cu=self.WebSocket||self.MozWebSocket);const sz=Cu;class az{constructor(e,r,n){St(this,"type");St(this,"provider");St(this,"status",!1);St(this,"callbacks",[]);St(this,"triggeredTransactions",[]);St(this,"filter");St(this,"webSocket");St(this,"dynamicStop",()=>{});this.type=e,this.filter=r??{},this.provider=n??Ca.instance}stop(){this.status&&(this.status=!1,this.dynamicStop())}start(){this.status||(this.status=!0,this[A2[this.type]]())}getStatus(){return this.status}async on(e){if(this.webSocket===void 0)try{await f1(this.provider.wsUrl),this.webSocket=new sz(this.provider.wsUrl)}catch(r){throw new Error("WebSocket connection is not available"+(r instanceof Error?": "+r.message:""))}return this.start(),this.callbacks.push(e),!0}trigger(e){this.triggeredTransactions.includes(e.id)||(this.triggeredTransactions.push(e.id),this.callbacks.forEach(r=>{r(e)}))}createMessage(e){let r;if(this.provider.isTestnet())r=JSON.stringify({"track-address":e});else if(this.provider.blockCypherToken!==void 0){const n={event:"unconfirmed-tx",token:this.provider.blockCypherToken};e!==void 0&&(n.address=e),r=JSON.stringify(n)}else r=JSON.stringify({op:"unconfirmed_sub"});return this.dynamicStop=()=>{this.provider.blockCypherToken===void 0&&this.webSocket.send(JSON.stringify({op:"unconfirmed_unsub"})),this.webSocket.close()},r}getValues(e){var n,s;const r={txId:""};if(this.provider.isTestnet()){const i=((n=e["address-transactions"])==null?void 0:n[0])??((s=e["block-transactions"])==null?void 0:s[0]);r.txId=i.txid,r.sender=i.vin[0].prevout.scriptpubkey_address,r.receiver=i.vout[0].scriptpubkey_address,r.amount=of(i.vout[0].value)}else this.provider.blockCypherToken!==void 0?(r.txId=e.hash,r.sender=e.inputs[0].addresses[0],r.receiver=e.outputs[0].addresses[0],r.amount=of(e.outputs[0].value)):(r.txId=e.x.hash,r.receiver=e.x.out[0].addr,r.sender=e.x.inputs[0].prev_out.addr,r.amount=of(e.x.out[0].value));return r}generalProcess(){var r,n;if(this.provider.isTestnet()&&((r=this.filter)==null?void 0:r.signer)===void 0)throw new Error("General transaction listener must have a signer filter in testnet.");const e=this.createMessage((n=this.filter)==null?void 0:n.signer);this.webSocket.addEventListener("open",()=>{this.webSocket.send(e)}),this.webSocket.addEventListener("message",async s=>{var l,g;const i=JSON.parse(s.data);if(i.loadingIndicators)return;const f=this.getValues(i);((l=this.filter)==null?void 0:l.signer)!==void 0&&((g=f.sender)==null?void 0:g.toLowerCase())!==this.filter.signer.toLowerCase()||this.trigger(new cm(f.txId))})}contractProcess(){throw new Error("This method is not implemented for Bitcoin.")}coinProcess(){const e=this.filter;if(e.signer!==void 0&&e.sender!==void 0&&e.signer!==e.sender)throw new Error("Sender and signer must be the same in coin transactions. Or only one of them can be defined.");const r=e.sender??e.signer,n=this.createMessage(e.receiver);this.webSocket.addEventListener("open",()=>{this.webSocket.send(n)}),this.webSocket.addEventListener("message",async s=>{var E,A;const i=JSON.parse(s.data);if(i.loadingIndicators)return;const f={},l={};if(i.event&&String(i.event).includes("events limit reached"))throw new Error("BlockCypher events limit reached.");const g=this.getValues(i);if(r!==void 0&&(f.sender=r.toLowerCase(),l.sender=(E=g.sender)==null?void 0:E.toLowerCase()),e.receiver!==void 0&&(f.receiver=e.receiver.toLowerCase(),l.receiver=(A=g.receiver)==null?void 0:A.toLowerCase()),!Dy(f,l))return;const _=new H7(g.txId);e.amount!==void 0&&g.amount!==e.amount||this.trigger(_)})}tokenProcess(){throw new Error("This method is not implemented for Bitcoin.")}nftProcess(){throw new Error("This method is not implemented for Bitcoin.")}}const oz=Object.freeze(Object.defineProperty({__proto__:null,TransactionListener:az,TransactionSigner:U7},Symbol.toStringTag,{value:"Module"})),hm={},fz={Wallet:UI,registerAdapter:t=>{if(Object.values(hm).find(e=>e.id===t.id)!==void 0)throw new Error(`Adapter with id ${t.id} already exists`);hm[t.id]=t},adapters:Object.assign(hm,LD)};wr.Provider=Ca,wr.assets=nz,wr.bitcore=ez,wr.browser=fz,wr.models=iz,wr.services=oz,wr.types=fS,wr.utils=tz,Object.defineProperty(wr,Symbol.toStringTag,{value:"Module"})});
135
135
  //# sourceMappingURL=index.umd.js.map