@btc-vision/bitcoin 6.4.4 → 6.4.5
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/browser/index.js +1 -1
- package/package.json +1 -1
package/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
var t={34:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+t.key.toString("hex"));if(65!==t.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+t.key.toString("hex"));if(64!==t.value.length&&65!==t.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1,33),leafHash:t.key.slice(33),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_SCRIPT_SIG]);return{key:n.concat([e,t.pubkey,t.leafHash]),value:t.signature}},e.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.leafHash)&&n.isBuffer(t.signature)&&32===t.pubkey.length&&32===t.leafHash.length&&(64===t.signature.length||65===t.signature.length)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex")+e.leafHash.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey)&&t.leafHash.equals(e.leafHash))).length)}},61:(t,e,r)=>{var n=r(113);function i(t){return t.name||t.toString().match(/function (.*?)\s*\(/)[1]}function o(t){return n.Nil(t)?"":i(t.constructor)}function u(t,e){Error.captureStackTrace&&Error.captureStackTrace(t,e)}function a(t){return n.Function(t)?t.toJSON?t.toJSON():i(t):n.Array(t)?"Array":t&&n.Object(t)?"Object":void 0!==t?t:""}function s(t,e,r){var i=function(t){return n.Function(t)?"":n.String(t)?JSON.stringify(t):t&&n.Object(t)?"":t}(e);return"Expected "+a(t)+", got"+(""!==r?" "+r:"")+(""!==i?" "+i:"")}function f(t,e,r){r=r||o(e),this.message=s(t,e,r),u(this,f),this.__type=t,this.__value=e,this.__valueTypeName=r}function c(t,e,r,n,i){t?(i=i||o(n),this.message=function(t,e,r,n,i){var o='" of type ';return"key"===e&&(o='" with key type '),s('property "'+a(r)+o+a(t),n,i)}(t,r,e,n,i)):this.message='Unexpected property "'+e+'"',u(this,f),this.__label=r,this.__property=e,this.__type=t,this.__value=n,this.__valueTypeName=i}f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,c.prototype=Object.create(Error.prototype),c.prototype.constructor=f,t.exports={TfTypeError:f,TfPropertyTypeError:c,tfCustomError:function(t,e){return new f(t,{},e)},tfSubError:function(t,e,r){return t instanceof c?(e=e+"."+t.__property,t=new c(t.__type,e,t.__label,t.__value,t.__valueTypeName)):t instanceof f&&(t=new c(t.__type,e,r,t.__value,t.__valueTypeName)),u(t),t},tfJSON:a,getValueTypeName:o}},80:(t,e)=>{var r,n,i;Object.defineProperty(e,"__esModule",{value:!0}),(i=e.GlobalTypes||(e.GlobalTypes={}))[i.UNSIGNED_TX=0]="UNSIGNED_TX",i[i.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(n=e.InputTypes||(e.InputTypes={}))[n.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",n[n.WITNESS_UTXO=1]="WITNESS_UTXO",n[n.PARTIAL_SIG=2]="PARTIAL_SIG",n[n.SIGHASH_TYPE=3]="SIGHASH_TYPE",n[n.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",n[n.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",n[n.BIP32_DERIVATION=6]="BIP32_DERIVATION",n[n.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",n[n.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",n[n.POR_COMMITMENT=9]="POR_COMMITMENT",n[n.TAP_KEY_SIG=19]="TAP_KEY_SIG",n[n.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",n[n.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",n[n.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",n[n.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",n[n.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT",e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(r=e.OutputTypes||(e.OutputTypes={}))[r.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",r[r.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",r[r.BIP32_DERIVATION=2]="BIP32_DERIVATION",r[r.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",r[r.TAP_TREE=6]="TAP_TREE",r[r.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION",e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]},113:t=>{var e={Array:function(t){return null!=t&&t.constructor===Array},Boolean:function(t){return"boolean"==typeof t},Function:function(t){return"function"==typeof t},Nil:function(t){return null==t},Number:function(t){return"number"==typeof t},Object:function(t){return"object"==typeof t},String:function(t){return"string"==typeof t},"":function(){return!0}};for(var r in e.Null=e.Nil,e)e[r].toJSON=function(t){return t}.bind(null,r);t.exports=e},133:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394);function o(t){const e=t.key.length,r=t.value.length,o=i.encodingLength(e),u=i.encodingLength(r),a=n.allocUnsafe(o+e+u+r);return i.encode(e,a,0),t.key.copy(a,o),i.encode(r,a,o+e),t.value.copy(a,o+e+u),a}function u(t,e){if("number"!=typeof t)throw new Error("cannot write a non-number as a number");if(t<0)throw new Error("specified a negative value for writing an unsigned value");if(t>e)throw new Error("RangeError: value out of range");if(Math.floor(t)!==t)throw new Error("value has a fractional component")}e.range=t=>[...Array(t).keys()],e.reverseBuffer=function(t){if(t.length<1)return t;let e=t.length-1,r=0;for(let n=0;n<t.length/2;n++)r=t[n],t[n]=t[e],t[e]=r,e--;return t},e.keyValsToBuffer=function(t){const e=t.map(o);return e.push(n.from([0])),n.concat(e)},e.keyValToBuffer=o,e.readUInt64LE=function(t,e){const r=t.readUInt32LE(e);let n=t.readUInt32LE(e+4);return n*=4294967296,u(n+r,9007199254740991),n+r},e.writeUInt64LE=function(t,e,r){return u(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}},213:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.encode=function(t){return{key:n.from([i.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}}},223:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t||1!==e.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+e.key.toString("hex"));if(32!==e.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)&&32===t.length},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.tapInternalKey}}}},238:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133);e.psbtToBuffer=function({globalMap:t,inputs:e,outputs:r}){const{globalKeyVals:i,inputKeyVals:u,outputKeyVals:a}=s({globalMap:t,inputs:e,outputs:r}),f=o.keyValsToBuffer(i),c=t=>0===t.length?[n.from([0])]:t.map(o.keyValsToBuffer),h=c(u),p=c(a),l=n.allocUnsafe(5);return l.writeUIntBE(482972169471,0,5),n.concat([l,f].concat(h,p))};const u=(t,e)=>t.key.compare(e.key);function a(t,e){const r=new Set,n=Object.entries(t).reduce(((t,[n,i])=>{if("unknownKeyVals"===n)return t;const o=e[n];if(void 0===o)return t;const u=(Array.isArray(i)?i:[i]).map(o.encode);return u.map((t=>t.key.toString("hex"))).forEach((t=>{if(r.has(t))throw new Error("Serialize Error: Duplicate key: "+t);r.add(t)})),t.concat(u)}),[]),i=t.unknownKeyVals?t.unknownKeyVals.filter((t=>!r.has(t.key.toString("hex")))):[];return n.concat(i).sort(u)}function s({globalMap:t,inputs:e,outputs:r}){return{globalKeyVals:a(t,i.globals),inputKeyVals:e.map((t=>a(t,i.inputs))),outputKeyVals:r.map((t=>a(t,i.outputs)))}}e.psbtToKeyVals=s},251:(t,e)=>{e.read=function(t,e,r,n,i){var o,u,a=8*i-n-1,s=(1<<a)-1,f=s>>1,c=-7,h=r?i-1:0,p=r?-1:1,l=t[e+h];for(h+=p,o=l&(1<<-c)-1,l>>=-c,c+=a;c>0;o=256*o+t[e+h],h+=p,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=p,c-=8);if(0===o)o=1-f;else{if(o===s)return u?NaN:1/0*(l?-1:1);u+=Math.pow(2,n),o-=f}return(l?-1:1)*u*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var u,a,s,f=8*o-i-1,c=(1<<f)-1,h=c>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,u=c):(u=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-u))<1&&(u--,s*=2),(e+=u+h>=1?p/s:p*Math.pow(2,1-h))*s>=2&&(u++,s/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(e*s-1)*Math.pow(2,i),u+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),u=0));i>=8;t[r+l]=255&a,l+=d,a/=256,i-=8);for(u=u<<i|a,f+=i;f>0;t[r+l]=255&u,l+=d,u/=256,f-=8);t[r+l-d]|=128*y}},263:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133),u=r(394),a=r(80);function s(t,e,r){if(!e.equals(n.from([r])))throw new Error(`Format Error: Invalid ${t} key: ${e.toString("hex")}`)}function f(t,{globalMapKeyVals:e,inputKeyVals:r,outputKeyVals:n}){const u={unsignedTx:t};let f=0;for(const t of e)switch(t.key[0]){case a.GlobalTypes.UNSIGNED_TX:if(s("global",t.key,a.GlobalTypes.UNSIGNED_TX),f>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");f++;break;case a.GlobalTypes.GLOBAL_XPUB:void 0===u.globalXpub&&(u.globalXpub=[]),u.globalXpub.push(i.globals.globalXpub.decode(t));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(t)}const c=r.length,h=n.length,p=[],l=[];for(const t of o.range(c)){const e={};for(const n of r[t])switch(i.inputs.checkPubkey(n),n.key[0]){case a.InputTypes.NON_WITNESS_UTXO:if(s("input",n.key,a.InputTypes.NON_WITNESS_UTXO),void 0!==e.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");e.nonWitnessUtxo=i.inputs.nonWitnessUtxo.decode(n);break;case a.InputTypes.WITNESS_UTXO:if(s("input",n.key,a.InputTypes.WITNESS_UTXO),void 0!==e.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");e.witnessUtxo=i.inputs.witnessUtxo.decode(n);break;case a.InputTypes.PARTIAL_SIG:void 0===e.partialSig&&(e.partialSig=[]),e.partialSig.push(i.inputs.partialSig.decode(n));break;case a.InputTypes.SIGHASH_TYPE:if(s("input",n.key,a.InputTypes.SIGHASH_TYPE),void 0!==e.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");e.sighashType=i.inputs.sighashType.decode(n);break;case a.InputTypes.REDEEM_SCRIPT:if(s("input",n.key,a.InputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");e.redeemScript=i.inputs.redeemScript.decode(n);break;case a.InputTypes.WITNESS_SCRIPT:if(s("input",n.key,a.InputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");e.witnessScript=i.inputs.witnessScript.decode(n);break;case a.InputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.inputs.bip32Derivation.decode(n));break;case a.InputTypes.FINAL_SCRIPTSIG:s("input",n.key,a.InputTypes.FINAL_SCRIPTSIG),e.finalScriptSig=i.inputs.finalScriptSig.decode(n);break;case a.InputTypes.FINAL_SCRIPTWITNESS:s("input",n.key,a.InputTypes.FINAL_SCRIPTWITNESS),e.finalScriptWitness=i.inputs.finalScriptWitness.decode(n);break;case a.InputTypes.POR_COMMITMENT:s("input",n.key,a.InputTypes.POR_COMMITMENT),e.porCommitment=i.inputs.porCommitment.decode(n);break;case a.InputTypes.TAP_KEY_SIG:s("input",n.key,a.InputTypes.TAP_KEY_SIG),e.tapKeySig=i.inputs.tapKeySig.decode(n);break;case a.InputTypes.TAP_SCRIPT_SIG:void 0===e.tapScriptSig&&(e.tapScriptSig=[]),e.tapScriptSig.push(i.inputs.tapScriptSig.decode(n));break;case a.InputTypes.TAP_LEAF_SCRIPT:void 0===e.tapLeafScript&&(e.tapLeafScript=[]),e.tapLeafScript.push(i.inputs.tapLeafScript.decode(n));break;case a.InputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.inputs.tapBip32Derivation.decode(n));break;case a.InputTypes.TAP_INTERNAL_KEY:s("input",n.key,a.InputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.inputs.tapInternalKey.decode(n);break;case a.InputTypes.TAP_MERKLE_ROOT:s("input",n.key,a.InputTypes.TAP_MERKLE_ROOT),e.tapMerkleRoot=i.inputs.tapMerkleRoot.decode(n);break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(n)}p.push(e)}for(const t of o.range(h)){const e={};for(const r of n[t])switch(i.outputs.checkPubkey(r),r.key[0]){case a.OutputTypes.REDEEM_SCRIPT:if(s("output",r.key,a.OutputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");e.redeemScript=i.outputs.redeemScript.decode(r);break;case a.OutputTypes.WITNESS_SCRIPT:if(s("output",r.key,a.OutputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");e.witnessScript=i.outputs.witnessScript.decode(r);break;case a.OutputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.outputs.bip32Derivation.decode(r));break;case a.OutputTypes.TAP_INTERNAL_KEY:s("output",r.key,a.OutputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.outputs.tapInternalKey.decode(r);break;case a.OutputTypes.TAP_TREE:s("output",r.key,a.OutputTypes.TAP_TREE),e.tapTree=i.outputs.tapTree.decode(r);break;case a.OutputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.outputs.tapBip32Derivation.decode(r));break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(r)}l.push(e)}return{globalMap:u,inputs:p,outputs:l}}e.psbtFromBuffer=function(t,e){let r=0;function n(){const e=u.decode(t,r);r+=u.encodingLength(e);const n=t.slice(r,r+e);return r+=e,n}function i(){return{key:n(),value:n()}}function s(){if(r>=t.length)throw new Error("Format Error: Unexpected End of PSBT");const e=0===t.readUInt8(r);return e&&r++,e}if(1886610036!==function(){const e=t.readUInt32BE(r);return r+=4,e}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const e=t.readUInt8(r);return r+=1,e}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const c=[],h={};for(;!s();){const t=i(),e=t.key.toString("hex");if(h[e])throw new Error("Format Error: Keys must be unique for global keymap: key "+e);h[e]=1,c.push(t)}const p=c.filter((t=>t.key[0]===a.GlobalTypes.UNSIGNED_TX));if(1!==p.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const l=e(p[0].value),{inputCount:d,outputCount:y}=l.getInputOutputCounts(),g=[],w=[];for(const t of o.range(d)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each input: input index "+t+" key "+o);e[o]=1,r.push(n)}g.push(r)}for(const t of o.range(y)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each output: output index "+t+" key "+o);e[o]=1,r.push(n)}w.push(r)}return f(l,{globalMapKeyVals:c,inputKeyVals:g,outputKeyVals:w})},e.checkKeyBuffer=s,e.psbtFromKeyVals=f},287:(t,e,r)=>{const n=r(526),i=r(251),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=s,e.IS=50;const u=2147483647;function a(t){if(t>u)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|y(t,e);let n=a(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(z(t,Uint8Array)){const e=new Uint8Array(t);return l(e.buffer,e.byteOffset,e.byteLength)}return p(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(z(t,ArrayBuffer)||t&&z(t.buffer,ArrayBuffer))return l(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(z(t,SharedArrayBuffer)||t&&z(t.buffer,SharedArrayBuffer)))return l(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|d(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||$(t.length)?a(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return c(t),a(t<0?0:0|d(t))}function p(t){const e=t.length<0?0:0|d(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function d(t){if(t>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return 0|t}function y(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||z(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return q(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return X(t).length;default:if(i)return n?-1:q(t).length;e=(""+e).toLowerCase(),i=!0}}function g(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return O(this,e,r);case"latin1":case"binary":return P(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function v(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),$(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let o,u=1,a=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;u=2,a/=2,s/=2,r/=2}function f(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}if(i){let n=-1;for(o=r;o<a;o++)if(f(t,o)===f(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===s)return n*u}else-1!==n&&(o-=o-n),n=-1}else for(r+s>a&&(r=a-s),o=r;o>=0;o--){let r=!0;for(let n=0;n<s;n++)if(f(t,o+n)!==f(e,n)){r=!1;break}if(r)return o}return-1}function b(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let u;for(n>o/2&&(n=o/2),u=0;u<n;++u){const n=parseInt(e.substr(2*u,2),16);if($(n))return u;t[r+u]=n}return u}function E(t,e,r,n){return Y(q(e,t.length-r),t,r,n)}function S(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function I(t,e,r,n){return Y(X(e),t,r,n)}function T(t,e,r,n){return Y(function(t,e){let r,n,i;const o=[];for(let u=0;u<t.length&&!((e-=2)<0);++u)r=t.charCodeAt(u),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function k(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,u=e>239?4:e>223?3:e>191?2:1;if(i+u<=r){let r,n,a,s;switch(u){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(s=(31&e)<<6|63&r,s>127&&(o=s));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(s=(15&e)<<12|(63&r)<<6|63&n,s>2047&&(s<55296||s>57343)&&(o=s));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(s=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,s>65535&&s<1114112&&(o=s))}}null===o?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=u}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=A));return r}(n)}s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return c(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(z(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=y,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)w(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)w(this,e,e+3),w(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)w(this,e,e+7),w(this,e+1,e+6),w(this,e+2,e+5),w(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?k(this,0,t):g.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},o&&(s.prototype[o]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),u=(r>>>=0)-(e>>>=0);const a=Math.min(o,u),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<a;++t)if(f[t]!==c[t]){o=f[t],u=c[t];break}return o<u?-1:u<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return v(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return v(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return S(this,t,e,r);case"base64":return I(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function O(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function P(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function U(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=J[t[n]];return i}function N(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function x(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i){F(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,r}function H(t,e,r,n,i){F(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=u,u>>=8,t[r+2]=u,u>>=8,t[r+1]=u,u>>=8,t[r]=u,r+8}function R(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,r,n,o){return e=+e,r>>>=0,o||R(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function D(t,e,r,n,o){return e=+e,r>>>=0,o||R(t,0,r,8),i.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=Q((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=Q((function(t,e=0){return H(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=0,o=1,u=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=r-1,o=1,u=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=Q((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=Q((function(t,e=0){return H(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return D(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return D(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),u=o.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%u]}return this};const V={};function K(t,e,r){V[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function M(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,n,i,o){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=o>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** ${8*(o+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new V.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,r){G(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||j(e,t.length-(r+1))}(n,i,o)}function G(t,e){if("number"!=typeof t)throw new V.ERR_INVALID_ARG_TYPE(e,"number",t)}function j(t,e,r){if(Math.floor(t)!==t)throw G(t,r),new V.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new V.ERR_BUFFER_OUT_OF_BOUNDS;throw new V.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}K("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),K("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),K("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=M(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=M(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function q(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let u=0;u<n;++u){if(r=t.charCodeAt(u),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function X(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function z(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function $(t){return t!=t}const J=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function Q(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}},307:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.redeemScript}}}},343:(t,e)=>{e.p2=e.I=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<32;t++){const e=r.charAt(t);n[e]=t}function i(t){const e=t>>25;return(33554431&t)<<5^996825010&-(1&e)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=i(e)^n>>5}e=i(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=i(e)^31&n}return e}function u(t,e,r,n){let i=0,o=0;const u=(1<<r)-1,a=[];for(let n=0;n<t.length;++n)for(i=i<<e|t[n],o+=e;o>=r;)o-=r,a.push(i>>o&u);if(n)o>0&&a.push(i<<r-o&u);else{if(o>=e)return"Excess padding";if(i<<r-o&u)return"Non-zero padding"}return a}function a(t){return u(t,8,5,!0)}function s(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e}function f(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function c(t){let e;function u(t,r){if(r=r||90,t.length<8)return t+" too short";if(t.length>r)return"Exceeds length limit";const u=t.toLowerCase(),a=t.toUpperCase();if(t!==u&&t!==a)return"Mixed-case string "+t;const s=(t=u).lastIndexOf("1");if(-1===s)return"No separator character for "+t;if(0===s)return"Missing prefix for "+t;const f=t.slice(0,s),c=t.slice(s+1);if(c.length<6)return"Data too short";let h=o(f);if("string"==typeof h)return h;const p=[];for(let t=0;t<c.length;++t){const e=c.charAt(t),r=n[e];if(void 0===r)return"Unknown character "+e;h=i(h)^r,t+6>=c.length||p.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:p}}return e="bech32"===t?1:734539939,{decodeUnsafe:function(t,e){const r=u(t,e);if("object"==typeof r)return r},decode:function(t,e){const r=u(t,e);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,n,u){if(u=u||90,t.length+7+n.length>u)throw new TypeError("Exceeds length limit");let a=o(t=t.toLowerCase());if("string"==typeof a)throw new Error(a);let s=t+"1";for(let t=0;t<n.length;++t){const e=n[t];if(e>>5)throw new Error("Non 5-bit word");a=i(a)^e,s+=r.charAt(e)}for(let t=0;t<6;++t)a=i(a);a^=e;for(let t=0;t<6;++t)s+=r.charAt(a>>5*(5-t)&31);return s},toWords:a,fromWordsUnsafe:s,fromWords:f}}e.I=c("bech32"),e.p2=c("bech32m")},344:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+t.key.toString("hex"));return t.value.readUInt32LE(0)},e.encode=function(t){const e=n.from([i.InputTypes.SIGHASH_TYPE]),r=n.allocUnsafe(4);return r.writeUInt32LE(t,0),{key:e,value:r}},e.expected="number",e.check=function(t){return"number"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.sighashType}},394:(t,e,r)=>{var n=r(287).hp;function i(t){if(t<0||t>9007199254740991||t%1!=0)throw new RangeError("value out of range")}function o(t){return i(t),t<253?1:t<=65535?3:t<=4294967295?5:9}Object.defineProperty(e,"__esModule",{value:!0}),e.encode=function t(e,r,u){if(i(e),r||(r=n.allocUnsafe(o(e))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return u||(u=0),e<253?(r.writeUInt8(e,u),Object.assign(t,{bytes:1})):e<=65535?(r.writeUInt8(253,u),r.writeUInt16LE(e,u+1),Object.assign(t,{bytes:3})):e<=4294967295?(r.writeUInt8(254,u),r.writeUInt32LE(e,u+1),Object.assign(t,{bytes:5})):(r.writeUInt8(255,u),r.writeUInt32LE(e>>>0,u+1),r.writeUInt32LE(e/4294967296|0,u+5),Object.assign(t,{bytes:9})),r},e.decode=function t(e,r){if(!n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");r||(r=0);const o=e.readUInt8(r);if(o<253)return Object.assign(t,{bytes:1}),o;if(253===o)return Object.assign(t,{bytes:3}),e.readUInt16LE(r+1);if(254===o)return Object.assign(t,{bytes:5}),e.readUInt32LE(r+1);{Object.assign(t,{bytes:9});const n=e.readUInt32LE(r+1),o=4294967296*e.readUInt32LE(r+5)+n;return i(o),o}},e.encodingLength=o},412:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.makeChecker=function(t){return function(e){let r;if(t.includes(e.key[0])&&(r=e.key.slice(1),33!==r.length&&65!==r.length||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+e.key.toString("hex"));return r}}},431:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.NON_WITNESS_UTXO]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.nonWitnessUtxo}},454:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&32===t.length}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_MERKLE_ROOT||1!==t.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_MERKLE_ROOT]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapMerkleRoot}},457:(t,e,r)=>{function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),n(r(263)),n(r(238))},526:(t,e)=>{e.byteLength=function(t){var e=a(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=a(t),u=o[0],s=o[1],f=new i(function(t,e,r){return 3*(e+r)/4-r}(0,u,s)),c=0,h=s>0?u-4:u;for(r=0;r<h;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],f[c++]=e>>16&255,f[c++]=e>>8&255,f[c++]=255&e;return 2===s&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,f[c++]=255&e),1===s&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,f[c++]=e>>8&255,f[c++]=255&e),f},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],u=16383,a=0,f=n-i;a<f;a+=u)o.push(s(t,a,a+u>f?f:a+u));return 1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0;u<64;++u)r[u]=o[u],n[o.charCodeAt(u)]=u;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(t,e,n){for(var i,o,u=[],a=e;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),u.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return u.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},542:(t,e,r)=>{var n=r(287).hp,i=r(113),o=r(61);function u(t){return n.isBuffer(t)}function a(t){return"string"==typeof t&&/^([0-9a-f]{2})+$/i.test(t)}function s(t,e){var r=t.toJSON();function n(n){if(!t(n))return!1;if(n.length===e)return!0;throw o.tfCustomError(r+"(Length: "+e+")",r+"(Length: "+n.length+")")}return n.toJSON=function(){return r},n}var f=s.bind(null,i.Array),c=s.bind(null,u),h=s.bind(null,a),p=s.bind(null,i.String),l=Math.pow(2,53)-1,d={ArrayN:f,Buffer:u,BufferN:c,Finite:function(t){return"number"==typeof t&&isFinite(t)},Hex:a,HexN:h,Int8:function(t){return t<<24>>24===t},Int16:function(t){return t<<16>>16===t},Int32:function(t){return(0|t)===t},Int53:function(t){return"number"==typeof t&&t>=-l&&t<=l&&Math.floor(t)===t},Range:function(t,e,r){function n(n,i){return r(n,i)&&n>t&&n<e}return r=r||i.Number,n.toJSON=function(){return`${r.toJSON()} between [${t}, ${e}]`},n},StringN:p,UInt8:function(t){return(255&t)===t},UInt16:function(t){return(65535&t)===t},UInt32:function(t){return t>>>0===t},UInt53:function(t){return"number"==typeof t&&t>=0&&t<=l&&Math.floor(t)===t}};for(var y in d)d[y].toJSON=function(t){return t}.bind(null,y);t.exports=d},545:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=t=>33===t.length&&[2,3].includes(t[0])||65===t.length&&4===t[0];e.makeConverter=function(t,e=i){return{decode:function(r){if(r.key[0]!==t)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+r.key.toString("hex"));const n=r.key.slice(1);if(!e(n))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+r.key.toString("hex"));if(r.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:r.value.slice(0,4),pubkey:n,path:"m"};for(const t of(o=r.value.length/4-1,[...Array(o).keys()])){const e=r.value.readUInt32LE(4*t+4),n=!!(2147483648&e),o=2147483647&e;i.path+="/"+o.toString(10)+(n?"'":"")}var o;return i},encode:function(e){const r=n.from([t]),i=n.concat([r,e.pubkey]),o=e.path.split("/"),u=n.allocUnsafe(4*o.length);e.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:i,value:u}},check:function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.masterFingerprint)&&"string"==typeof t.path&&e(t.pubkey)&&4===t.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}}}},578:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.witnessScript}}}},605:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTSIG]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptSig}},614:(t,e,r)=>{var n=r(287).hp;const i=r(863),o=r(457),u=r(80),a=r(699);e.i=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,e){const r=n.from(t,"base64");return this.fromBuffer(r,e)}static fromHex(t,e){const r=n.from(t,"hex");return this.fromBuffer(r,e)}static fromBuffer(t,e){const r=o.psbtFromBuffer(t,e),n=new this(r.globalMap.unsignedTx);return Object.assign(n,r),n}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return o.psbtToBuffer(this)}updateGlobal(t){return a.updateGlobal(t,this.globalMap),this}updateInput(t,e){const r=a.checkForInput(this.inputs,t);return a.updateInput(e,r),this}updateOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.updateOutput(e,r),this}addUnknownKeyValToGlobal(t){return a.checkHasKey(t,this.globalMap.unknownKeyVals,a.getEnumLength(u.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,e){const r=a.checkForInput(this.inputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.InputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addUnknownKeyValToOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.OutputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToInput(r,t))),a.addInputAttributes(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToOutput(r,t))),a.addOutputAttributes(this.outputs,t),this}clearFinalizedInput(t){const e=a.checkForInput(this.inputs,t);a.inputCheckUncleanFinalized(t,e);for(const t of Object.keys(e))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(t)||delete e[t];return this}combine(...t){const e=i.combine([this].concat(t));return Object.assign(this,e),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}},636:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394),o=r(545),u=t=>32===t.length;e.makeConverter=function(t){const e=o.makeConverter(t,u);return{decode:function(t){const r=i.decode(t.value),n=i.encodingLength(r),o=e.decode({key:t.key,value:t.value.slice(n+32*r)}),u=new Array(r);for(let e=0,i=n;e<r;e++,i+=32)u[e]=t.value.slice(i,i+32);return Object.assign({},o,{leafHashes:u})},encode:function(t){const r=e.encode(t),o=i.encodingLength(t.leafHashes.length),u=n.allocUnsafe(o);i.encode(t.leafHashes.length,u);const a=n.concat([u,...t.leafHashes,r.value]);return Object.assign({},r,{value:a})},check:function(t){return Array.isArray(t.leafHashes)&&t.leafHashes.every((t=>n.isBuffer(t)&&32===t.length))&&e.check(t)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:e.canAddToArray}}},676:(t,e,r)=>{var n=r(61),i=r(113),o=n.tfJSON,u=n.TfTypeError,a=n.TfPropertyTypeError,s=n.tfSubError,f=n.getValueTypeName,c={arrayOf:function(t,e){function r(r,n){return!!i.Array(r)&&!i.Nil(r)&&!(void 0!==e.minLength&&r.length<e.minLength)&&!(void 0!==e.maxLength&&r.length>e.maxLength)&&(void 0===e.length||r.length===e.length)&&r.every((function(e,r){try{return p(t,e,n)}catch(t){throw s(t,r)}}))}return t=h(t),e=e||{},r.toJSON=function(){var r="["+o(t)+"]";return void 0!==e.length?r+="{"+e.length+"}":void 0===e.minLength&&void 0===e.maxLength||(r+="{"+(void 0===e.minLength?0:e.minLength)+","+(void 0===e.maxLength?1/0:e.maxLength)+"}"),r},r},maybe:function t(e){function r(r,n){return i.Nil(r)||e(r,n,t)}return e=h(e),r.toJSON=function(){return"?"+o(e)},r},map:function(t,e){function r(r,n){if(!i.Object(r))return!1;if(i.Nil(r))return!1;for(var o in r){try{e&&p(e,o,n)}catch(t){throw s(t,o,"key")}try{var u=r[o];p(t,u,n)}catch(t){throw s(t,o)}}return!0}return t=h(t),e&&(e=h(e)),r.toJSON=e?function(){return"{"+o(e)+": "+o(t)+"}"}:function(){return"{"+o(t)+"}"},r},object:function(t){var e={};for(var r in t)e[r]=h(t[r]);function n(t,r){if(!i.Object(t))return!1;if(i.Nil(t))return!1;var n;try{for(n in e)p(e[n],t[n],r)}catch(t){throw s(t,n)}if(r)for(n in t)if(!e[n])throw new a(void 0,n);return!0}return n.toJSON=function(){return o(e)},n},anyOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.some((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join("|")},e},allOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.every((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join(" & ")},e},quacksLike:function(t){function e(e){return t===f(e)}return e.toJSON=function(){return t},e},tuple:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return!i.Nil(e)&&!i.Nil(e.length)&&(!r||e.length===t.length)&&t.every((function(t,n){try{return p(t,e[n],r)}catch(t){throw s(t,n)}}))}return e.toJSON=function(){return"("+t.map(o).join(", ")+")"},e},value:function(t){function e(e){return e===t}return e.toJSON=function(){return t},e}};function h(t){if(i.String(t))return"?"===t[0]?c.maybe(t.slice(1)):i[t]||c.quacksLike(t);if(t&&i.Object(t)){if(i.Array(t)){if(1!==t.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(t[0])}return c.object(t)}return i.Function(t)?t:c.value(t)}function p(t,e,r,n){if(i.Function(t)){if(t(e,r))return!0;throw new u(n||t,e)}return p(h(t),e,r)}for(var l in c.oneOf=c.anyOf,i)p[l]=i[l];for(l in c)p[l]=c[l];var d=r(542);for(l in d)p[l]=d[l];p.compile=h,p.TfTypeError=u,p.TfPropertyTypeError=a,t.exports=p},695:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+t.key.toString("hex"));if((t.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+t.key.toString("hex"));const e=t.value[t.value.length-1];if((254&t.key[1])!==e)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+t.key.toString("hex"));const r=t.value.slice(0,-1);return{controlBlock:t.key.slice(1),script:r,leafVersion:e}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_LEAF_SCRIPT]),r=n.from([t.leafVersion]);return{key:n.concat([e,t.controlBlock]),value:n.concat([t.script,r])}},e.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",e.check=function(t){return n.isBuffer(t.controlBlock)&&(t.controlBlock.length-1)%32==0&&(254&t.controlBlock[0])===t.leafVersion&&n.isBuffer(t.script)},e.canAddToArray=function(t,e,r){const n=e.controlBlock.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.controlBlock.equals(e.controlBlock))).length)}},699:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706);function o(t,e){const r=t[e];if(void 0===r)throw new Error(`No input #${e}`);return r}function u(t,e){const r=t[e];if(void 0===r)throw new Error(`No output #${e}`);return r}function a(t,e,r,n){throw new Error(`Data for ${t} key ${e} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function s(t){return(e,r)=>{for(const n of Object.keys(e)){const o=e[n],{canAdd:u,canAddToArray:s,check:f,expected:c}=i[t+"s"][n]||{};if(f)if(s){if(!Array.isArray(o)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);o.every(f)||a(t,n,c,o);const e=r[n]||[],i=new Set;if(!o.every((t=>s(e,t,i))))throw new Error("Can not add duplicate data to array");r[n]=e.concat(o)}else{if(f(o)||a(t,n,c,o),!u(r,o))throw new Error(`Can not add duplicate data to ${t}`);r[n]=o}}}}e.checkForInput=o,e.checkForOutput=u,e.checkHasKey=function(t,e,r){if(t.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(e&&0!==e.filter((e=>e.key.equals(t.key))).length)throw new Error(`Duplicate Key: ${t.key.toString("hex")}`)},e.getEnumLength=function(t){let e=0;return Object.keys(t).forEach((t=>{Number(isNaN(Number(t)))&&e++})),e},e.inputCheckUncleanFinalized=function(t,e){let r=!1;if(e.nonWitnessUtxo||e.witnessUtxo){const t=!!e.redeemScript,n=!!e.witnessScript,i=!t||!!e.finalScriptSig,o=!n||!!e.finalScriptWitness,u=!!e.finalScriptSig||!!e.finalScriptWitness;r=i&&o&&u}if(!1===r)throw new Error(`Input #${t} has too much or too little data to clean`)},e.updateGlobal=s("global"),e.updateInput=s("input"),e.updateOutput=s("output"),e.addInputAttributes=function(t,r){const n=o(t,t.length-1);e.updateInput(r,n)},e.addOutputAttributes=function(t,r){const n=u(t,t.length-1);e.updateOutput(r,n)},e.defaultVersionSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Version: Invalid Transaction");return e.writeUInt32LE(t,0),e},e.defaultLocktimeSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Locktime: Invalid Transaction");return e.writeUInt32LE(t,e.length-4),e}},706:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(80),i=r(834),o=r(213),u=r(605),a=r(795),s=r(431),f=r(907),c=r(949),h=r(344),p=r(760),l=r(695),d=r(454),y=r(34),g=r(926),w=r(851),v=r(545),m=r(412),b=r(307),E=r(636),S=r(223),I=r(578),T={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=T;const _={nonWitnessUtxo:s,partialSig:f,sighashType:h,finalScriptSig:u,finalScriptWitness:a,porCommitment:c,witnessUtxo:g,bip32Derivation:v.makeConverter(n.InputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.InputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:p,tapScriptSig:y,tapLeafScript:l,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:S.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:d};e.inputs=_;const k={bip32Derivation:v.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.OutputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:E.makeConverter(n.OutputTypes.TAP_BIP32_DERIVATION),tapTree:w,tapInternalKey:S.makeConverter(n.OutputTypes.TAP_INTERNAL_KEY)};e.outputs=k},760:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&(64===t.length||65===t.length)}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_KEY_SIG||1!==t.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_KEY_SIG]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapKeySig}},795:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptWitness}},834:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const e=t.key.slice(1),r={masterFingerprint:t.value.slice(0,4),extendedPubkey:e,path:"m"};for(const e of(n=t.value.length/4-1,[...Array(n).keys()])){const n=t.value.readUInt32LE(4*e+4),i=!!(2147483648&n),o=2147483647&n;r.path+="/"+o.toString(10)+(i?"'":"")}var n;return r},e.encode=function(t){const e=n.from([i.GlobalTypes.GLOBAL_XPUB]),r=n.concat([e,t.extendedPubkey]),o=t.path.split("/"),u=n.allocUnsafe(4*o.length);t.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:r,value:u}},e.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",e.check=function(t){const e=t.extendedPubkey,r=t.masterFingerprint,i=t.path;return n.isBuffer(e)&&78===e.length&&[2,3].indexOf(e[45])>-1&&n.isBuffer(r)&&4===r.length&&"string"==typeof i&&!!i.match(/^m(\/\d+'?)*$/)},e.canAddToArray=function(t,e,r){const n=e.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.extendedPubkey.equals(e.extendedPubkey))).length)}},851:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(394);e.decode=function(t){if(t.key[0]!==i.OutputTypes.TAP_TREE||1!==t.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+t.key.toString("hex"));let e=0;const r=[];for(;e<t.value.length;){const n=t.value[e++],i=t.value[e++],u=o.decode(t.value,e);e+=o.encodingLength(u),r.push({depth:n,leafVersion:i,script:t.value.slice(e,e+u)}),e+=u}return{leaves:r}},e.encode=function(t){const e=n.from([i.OutputTypes.TAP_TREE]),r=[].concat(...t.leaves.map((t=>[n.of(t.depth,t.leafVersion),o.encode(t.script.length),t.script])));return{key:e,value:n.concat(r)}},e.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",e.check=function(t){return Array.isArray(t.leaves)&&t.leaves.every((t=>t.depth>=0&&t.depth<=128&&(254&t.leafVersion)===t.leafVersion&&n.isBuffer(t.script)))},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapTree}},863:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(457);function i(t,e,r){return n=>{if(t.has(n))return;const i=r.filter((t=>t.key.toString("hex")===n))[0];e.push(i),t.add(n)}}function o(t){return t.globalMap.unsignedTx}function u(t){const e=new Set;return t.forEach((t=>{const r=t.key.toString("hex");if(e.has(r))throw new Error("Combine: KeyValue Map keys should be unique");e.add(r)})),e}e.combine=function(t){const e=t[0],r=n.psbtToKeyVals(e),a=t.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const s=o(e);if(void 0===s)throw new Error("Combine: Self missing transaction");const f=u(r.globalKeyVals),c=r.inputKeyVals.map(u),h=r.outputKeyVals.map(u);for(const t of a){const e=o(t);if(void 0===e||!e.toBuffer().equals(s.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const a=n.psbtToKeyVals(t);u(a.globalKeyVals).forEach(i(f,r.globalKeyVals,a.globalKeyVals)),a.inputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(c[e],r.inputKeyVals[e],a.inputKeyVals[e])))),a.outputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(h[e],r.outputKeyVals[e],a.outputKeyVals[e]))))}return n.psbtFromKeyVals(s,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}},907:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+t.key.toString("hex"));if(34!==t.key.length&&66!==t.key.length||![2,3,4].includes(t.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.PARTIAL_SIG]);return{key:n.concat([e,t.pubkey]),value:t.signature}},e.expected="{ pubkey: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.signature)&&[33,65].includes(t.pubkey.length)&&[2,3,4].includes(t.pubkey[0])&&function(t){if(!n.isBuffer(t)||t.length<9)return!1;if(48!==t[0])return!1;if(t.length!==t[1]+3)return!1;if(2!==t[2])return!1;const e=t[3];if(e>33||e<1)return!1;if(2!==t[3+e+1])return!1;const r=t[3+e+2];return!(r>33||r<1)&&t.length===3+e+2+r+2}(t.signature)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}},926:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(133),u=r(394);e.decode=function(t){if(t.key[0]!==i.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+t.key.toString("hex"));const e=o.readUInt64LE(t.value,0);let r=8;const n=u.decode(t.value,r);r+=u.encodingLength(n);const a=t.value.slice(r);if(a.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:a,value:e}},e.encode=function(t){const{script:e,value:r}=t,a=u.encodingLength(e.length),s=n.allocUnsafe(8+a+e.length);return o.writeUInt64LE(s,r,0),u.encode(e.length,s,8),e.copy(s,8+a),{key:n.from([i.InputTypes.WITNESS_UTXO]),value:s}},e.expected="{ script: Buffer; value: number; }",e.check=function(t){return n.isBuffer(t.script)&&"number"==typeof t.value},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.witnessUtxo}},949:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+t.key.toString("hex"));return t.value.toString("utf8")},e.encode=function(t){return{key:n.from([i.InputTypes.POR_COMMITMENT]),value:n.from(t,"utf8")}},e.expected="string",e.check=function(t){return"string"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.porCommitment}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{bitcoin:()=>p,bitcoinCash:()=>m,bitcoinCashTestnet:()=>b,dash:()=>E,dashTestnet:()=>S,dogecoin:()=>y,dogecoinTestnet:()=>g,litecoin:()=>w,litecoinTestnet:()=>v,regtest:()=>l,testnet:()=>d});var i={};r.r(i),r.d(i,{decode:()=>tt,encode:()=>et});var o={};r.r(o),r.d(o,{decode:()=>xt,encode:()=>Bt});var u={};r.r(u),r.d(u,{OPS:()=>W,compile:()=>Gt,countNonPushOnlyOPs:()=>Vt,decompile:()=>jt,fromASM:()=>qt,isCanonicalPubKey:()=>Yt,isCanonicalScriptSignature:()=>$t,isDefinedHashType:()=>zt,isPushOnly:()=>Dt,number:()=>Jt,signature:()=>Qt,toASM:()=>Wt,toStack:()=>Xt});var a={};r.r(a),r.d(a,{fromBase58Check:()=>ce,fromBech32:()=>he,fromOutputScript:()=>de,toBase58Check:()=>pe,toBech32:()=>le,toFutureOPNetAddress:()=>fe,toOutputScript:()=>ye});var s={};r.r(s),r.d(s,{TAGGED_HASH_PREFIXES:()=>Ge,TAGS:()=>Fe,hash160:()=>Ke,hash256:()=>Me,ripemd160:()=>Le,sha1:()=>De,sha256:()=>Ve,taggedHash:()=>je});var f={};r.r(f),r.d(f,{decode:()=>rr,encode:()=>er,encodingLength:()=>nr});var c={};r.r(c),r.d(c,{Transaction:()=>Zn});var h={};r.r(h),r.d(h,{LEAF_VERSION_TAPSCRIPT:()=>br,MAX_TAPTREE_DEPTH:()=>Er,PaymentType:()=>ji,findScriptPath:()=>_r,p2data:()=>Br,p2ms:()=>Rr,p2op:()=>Ti,p2pk:()=>Dr,p2pkh:()=>Xi,p2sh:()=>kn,p2tr:()=>Un,p2wpkh:()=>Cn,p2wsh:()=>Vn,prop:()=>Ur,rootHashFromPath:()=>Ir,tapTweakHash:()=>Ar,tapleafHash:()=>kr,toHashTree:()=>Tr,tweakKey:()=>Or,value:()=>Nr});var p={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bech32Opnet:"op",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},l={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bech32Opnet:"opr",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},d={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bech32Opnet:"opt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},y={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},g={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},w={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bech32Opnet:"opl",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},v={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bech32Opnet:"oplt",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},m={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bech32Opnet:"opbch",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},b={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bech32Opnet:"opbcht",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},E={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},S={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},I=r(343);function T(t,...e){if(!((r=t)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function _(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function k(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function A(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function O(t,e){return t<<32-e|t>>>e}function P(t,e){return t<<e|t>>>32-e>>>0}function U(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),T(t),t}class N{}function x(t){const e=e=>t().update(U(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function B(t,e,r){return t&e^~t&r}function C(t,e,r){return t&e^t&r^e&r}class H extends N{constructor(t,e,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(t),this.view=A(this.buffer)}update(t){_(this),T(t=U(t));const{view:e,buffer:r,blockLen:n}=this,i=t.length;for(let o=0;o<i;){const u=Math.min(n-this.pos,i-o);if(u!==n)r.set(t.subarray(o,o+u),this.pos),this.pos+=u,o+=u,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=A(t);for(;n<=i-o;o+=n)this.process(e,o)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){_(this),function(t,e){T(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;e[o++]=128,k(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let t=o;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),u=Number(r>>i&o),a=Number(r&o),s=n?4:0,f=n?0:4;t.setUint32(e+s,u,n),t.setUint32(e+f,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const u=A(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const s=a/4,f=this.get();if(s>f.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<s;t++)u.setUint32(4*t,f[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:u}=this;return t.destroyed=o,t.finished=i,t.length=n,t.pos=u,n%e&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const R=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),L=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),D=new Uint32Array(64);class V extends H{constructor(t=32){super(64,t,8,!1),this.A=0|R[0],this.B=0|R[1],this.C=0|R[2],this.D=0|R[3],this.E=0|R[4],this.F=0|R[5],this.G=0|R[6],this.H=0|R[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:u,H:a}=this;return[t,e,r,n,i,o,u,a]}set(t,e,r,n,i,o,u,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|u,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)D[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=D[t-15],r=D[t-2],n=O(e,7)^O(e,18)^e>>>3,i=O(r,17)^O(r,19)^r>>>10;D[t]=i+D[t-7]+n+D[t-16]|0}let{A:r,B:n,C:i,D:o,E:u,F:a,G:s,H:f}=this;for(let t=0;t<64;t++){const e=f+(O(u,6)^O(u,11)^O(u,25))+B(u,a,s)+L[t]+D[t]|0,c=(O(r,2)^O(r,13)^O(r,22))+C(r,n,i)|0;f=s,s=a,a=u,u=o+e|0,o=i,i=n,n=r,r=e+c|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,a=a+this.F|0,s=s+this.G|0,f=f+this.H|0,this.set(r,n,i,o,u,a,s,f)}roundClean(){k(D)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}const K=x((()=>new V)),M=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let t=0;t<e.length;t++)e[t]=255;for(let r=0;r<t.length;r++){const n=t.charAt(r),i=n.charCodeAt(0);if(255!==e[i])throw new TypeError(n+" is ambiguous");e[i]=r}const r=t.length,n=t.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function u(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;let o=0,u=0,a=0;for(;t[o]===n;)u++,o++;const s=(t.length-o)*i+1>>>0,f=new Uint8Array(s);for(;t[o];){let n=e[t.charCodeAt(o)];if(255===n)return;let i=0;for(let t=s-1;(0!==n||i<a)&&-1!==t;t--,i++)n+=r*f[t]>>>0,f[t]=n%256>>>0,n=n/256>>>0;if(0!==n)throw new Error("Non-zero carry");a=i,o++}let c=s-a;for(;c!==s&&0===f[c];)c++;const h=new Uint8Array(u+(s-c));let p=u;for(;c!==s;)h[p++]=f[c++];return h}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";let i=0,u=0,a=0;const s=e.length;for(;a!==s&&0===e[a];)a++,i++;const f=(s-a)*o+1>>>0,c=new Uint8Array(f);for(;a!==s;){let t=e[a],n=0;for(let e=f-1;(0!==t||n<u)&&-1!==e;e--,n++)t+=256*c[e]>>>0,c[e]=t%r>>>0,t=t/r>>>0;if(0!==t)throw new Error("Non-zero carry");u=n,a++}let h=f-u;for(;h!==f&&0===c[h];)h++;let p=n.repeat(i);for(;h<f;++h)p+=t.charAt(c[h]);return p},decodeUnsafe:u,decode:function(t){const e=u(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),F=function(t){function e(e){var r=e.slice(0,-4),n=e.slice(-4),i=t(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(e){var r=Uint8Array.from(e),n=t(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),M.encode(o)},decode:function(t){var r=e(M.decode(t));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(t){var r=M.decodeUnsafe(t);if(null!=r)return e(r)}}}((function(t){return K(K(t))}));var G=r(287).hp;function j(t,e){var r=t.length,n=e.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&t[0])throw new Error("R value is negative");if(128&e[0])throw new Error("S value is negative");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("R value excessively padded");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("S value excessively padded");var i=G.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=t.length,t.copy(i,4),i[4+r]=2,i[5+r]=e.length,e.copy(i,6+r),i}for(var W={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},q={},X=0,Y=Object.keys(W);X<Y.length;X++){var z=Y[X],$=W[z];q[$]=z}function J(t){return t<W.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function Q(t,e){var r,n,i=t.readUInt8(e);if(i<W.OP_PUSHDATA1)r=i,n=1;else if(i===W.OP_PUSHDATA1){if(e+2>t.length)return null;r=t.readUInt8(e+1),n=2}else if(i===W.OP_PUSHDATA2){if(e+3>t.length)return null;r=t.readUInt16LE(e+1),n=3}else{if(e+5>t.length)return null;if(i!==W.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=t.readUInt32LE(e+1),n=5}return{opcode:i,number:r,size:n}}var Z=r(287).hp;function tt(t,e,r){e=e||4,r=void 0===r||r;var n=t.length;if(0===n)return 0;if(n>e)throw new TypeError("Script number overflow");if(r&&!(127&t[n-1]||!(n<=1)&&128&t[n-2]))throw new Error("Non-minimally encoded script number");if(5===n){var i=t.readUInt32LE(0),o=t.readUInt8(4);return 128&o?-(4294967296*(-129&o)+i):4294967296*o+i}for(var u=0,a=0;a<n;++a)u|=t[a]<<8*a;return 128&t[n-1]?-(u&~(128<<8*(n-1))):u}function et(t){for(var e=Math.abs(t),r=function(t){return t>2147483647?5:t>8388607?4:t>32767?3:t>127?2:t>0?1:0}(e),n=Z.allocUnsafe(r),i=t<0,o=0;o<r;++o)n.writeUInt8(255&e,o),e>>=8;return 128&n[r-1]?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}var rt=r(287),nt=r(676),it=r.n(nt)(),ot=rt.hp.alloc(32,0),ut=rt.hp.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function at(t,e){return t.length===e.length&&t.every((function(t,r){return t.equals(e[r])}))}function st(t){if(!rt.hp.isBuffer(t))return!1;if(t.length<33)return!1;var e=t[0],r=t.slice(1,33);if(0===r.compare(ot))return!1;if(r.compare(ut)>=0)return!1;if((2===e||3===e)&&33===t.length)return!0;if(65!==t.length)return!1;var n=t.slice(33);return!(0===n.compare(ot)||n.compare(ut)>=0||4!==e&&6!==e&&7!==e)}function ft(t){return it.UInt53(t)&&t<=21e14}var ct=254;function ht(t){return!(!t||!("output"in t)||!rt.hp.isBuffer(t.output)||void 0!==t.version&&(t.version&ct)!==t.version)}function pt(t){return gt(t)?2===t.length&&t.every((function(t){return pt(t)})):ht(t)}it.BufferN(32);var lt=it.BufferN(20),dt=it.BufferN(32),yt=it.Number,gt=it.Array,wt=(it.Boolean,it.String),vt=it.Buffer,mt=it.Hex,bt=it.maybe,Et=it.tuple,St=it.UInt8,It=it.UInt32,Tt=it.Function,_t=it.BufferN,kt=it.Null,At=(it.oneOf,r(287).hp),Ot=it,Pt=At.alloc(1,0);function Ut(t){for(var e=0;0===t[e];)++e;return e===t.length?Pt:128&(t=t.slice(e))[0]?At.concat([Pt,t],1+t.length):t}function Nt(t){0===t[0]&&(t=t.slice(1));var e=At.alloc(32,0),r=Math.max(0,32-t.length);return t.copy(e,r),e}function xt(t){var e=t.readUInt8(t.length-1);if(!zt(e))throw new Error("Invalid hashType "+e);var r=function(t){if(t.length<8)throw new Error("DER sequence length is too short");if(t.length>72)throw new Error("DER sequence length is too long");if(48!==t[0])throw new Error("Expected DER sequence");if(t[1]!==t.length-2)throw new Error("DER sequence length is invalid");if(2!==t[2])throw new Error("Expected DER integer");var e=t[3];if(0===e)throw new Error("R length is zero");if(5+e>=t.length)throw new Error("R length is too long");if(2!==t[4+e])throw new Error("Expected DER integer (2)");var r=t[5+e];if(0===r)throw new Error("S length is zero");if(6+e+r!==t.length)throw new Error("S length is invalid");if(128&t[4])throw new Error("R value is negative");if(e>1&&0===t[4]&&!(128&t[5]))throw new Error("R value excessively padded");if(128&t[e+6])throw new Error("S value is negative");if(r>1&&0===t[e+6]&&!(128&t[e+7]))throw new Error("S value excessively padded");return{r:t.slice(4,4+e),s:t.slice(6+e)}}(t.slice(0,-1)),n=Nt(r.r),i=Nt(r.s);return{signature:At.concat([n,i],64),hashType:e}}function Bt(t,e){if(Ot({signature:_t(64),hashType:St},{signature:t,hashType:e}),!zt(e))throw new Error("Invalid hashType "+e);var r=At.allocUnsafe(1);r.writeUInt8(e,0);var n=Ut(t.slice(0,32)),i=Ut(t.slice(32,64));return At.concat([j(n,i),r])}var Ct=r(287).hp,Ht=it,Rt=W.OP_RESERVED;function Lt(t){return vt(t)||function(t){return yt(t)&&(t===W.OP_0||t>=W.OP_1&&t<=W.OP_16||t===W.OP_1NEGATE)}(t)}function Dt(t){return gt(t)&&t.every(Lt)}function Vt(t){return t.length-t.filter(Lt).length}function Kt(t){return 0===t.length?W.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Rt+t[0]:129===t[0]?W.OP_1NEGATE:void 0:void 0}function Mt(t){return Ct.isBuffer(t)}function Ft(t){return Ct.isBuffer(t)}function Gt(t){if(Mt(t))return t;Ht(gt,t);var e=t.reduce((function(t,e){return Ft(e)?1===e.length&&void 0!==Kt(e)?t+1:t+J(e.length)+e.length:t+1}),0),r=Ct.allocUnsafe(e),n=0;if(t.forEach((function(t){if(Ft(t)){var e=Kt(t);if(void 0!==e)return r.writeUInt8(e,n),void(n+=1);n+=function(t,e,r){var n=J(e);return 1===n?t.writeUInt8(e,r):2===n?(t.writeUInt8(W.OP_PUSHDATA1,r),t.writeUInt8(e,r+1)):3===n?(t.writeUInt8(W.OP_PUSHDATA2,r),t.writeUInt16LE(e,r+1)):(t.writeUInt8(W.OP_PUSHDATA4,r),t.writeUInt32LE(e,r+1)),n}(r,t.length,n),t.copy(r,n),n+=t.length}else r.writeUInt8(t,n),n+=1})),n!==r.length)throw new Error("Could not decode chunks");return r}function jt(t){if(gt(t))return t;Ht(vt,t);for(var e=[],r=0;r<t.length;){var n=t[r];if(n>W.OP_0&&n<=W.OP_PUSHDATA4){var i=Q(t,r);if(null===i)return null;if((r+=i.size)+i.number>t.length)return null;var o=t.slice(r,r+i.number);r+=i.number;var u=Kt(o);void 0!==u?e.push(u):e.push(o)}else e.push(n),r+=1}return e}function Wt(t){if(Mt(t)&&(t=jt(t)),!t)throw new Error("Could not convert invalid chunks to ASM");return t.map((function(t){if(Ft(t)){var e=Kt(t);if(void 0===e)return t.toString("hex");t=e}return q[t]})).join(" ")}function qt(t){return Ht(wt,t),Gt(t.split(" ").map((function(t){return void 0!==W[t]?W[t]:(Ht(mt,t),Ct.from(t,"hex"))})))}function Xt(t){return t=jt(t),Ht(Dt,t),t.map((function(t){return Ft(t)?t:t===W.OP_0?Ct.allocUnsafe(0):et(t-Rt)}))}function Yt(t){return st(t)}function zt(t){var e=-129&t;return e>0&&e<4}function $t(t){return!!Ct.isBuffer(t)&&!!zt(t[t.length-1])&&function(t){if(t.length<8)return!1;if(t.length>72)return!1;if(48!==t[0])return!1;if(t[1]!==t.length-2)return!1;if(2!==t[2])return!1;var e=t[3];if(0===e)return!1;if(5+e>=t.length)return!1;if(2!==t[4+e])return!1;var r=t[5+e];return!(0===r||6+e+r!==t.length||128&t[4]||e>1&&0===t[4]&&!(128&t[5])||128&t[e+6]||r>1&&0===t[e+6]&&!(128&t[e+7]))}(t.slice(0,-1))}var Jt=i,Qt=o,Zt=r(287).hp;function te(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ee=40,re=2,ne=15,ie=16,oe=16,ue=2,ae=80,se="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function fe(t,e){if(!Zt.isBuffer(t))throw new TypeError("output must be a Buffer");if(!e.bech32Opnet)throw new Error("Network does not support opnet");var r,n=t[0],i=1;if(t[1]<76)r=t[1],i=2;else{if(76!==t[1])throw new TypeError("Unsupported push opcode in script");r=t[2],i=3}var o=t.subarray(i,i+r);if(o.length<re||o.length>ee)throw new TypeError("Invalid program length for segwit address");var u=n===W.OP_0?0:n>=W.OP_1&&n<=W.OP_16?n-(W.OP_1-1):-1;if(u<ne||u>ie)throw new TypeError("Invalid segwit version ".concat(u));var a,s=[u].concat(function(t){if(Array.isArray(t))return te(t)}(a=I.p2.toWords(o))||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(a)||function(t,e){if(t){if("string"==typeof t)return te(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?te(t,e):void 0}}(a)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());return I.p2.encode(e.bech32Opnet,s)}function ce(t){var e=Zt.from(F.decode(t));if(e.length<21)throw new TypeError(t+" is too short");if(e.length>21)throw new TypeError(t+" is too long");return{version:e.readUInt8(0),hash:e.subarray(1)}}function he(t){var e,r;try{e=I.I.decode(t)}catch(t){}if(e){if(0!==(r=e.words[0]))throw new TypeError(t+" uses wrong encoding")}else if(0===(r=(e=I.p2.decode(t)).words[0]))throw new TypeError(t+" uses wrong encoding");var n=I.I.fromWords(e.words.slice(1));return{version:r,prefix:e.prefix,data:Zt.from(n)}}function pe(t,e){it(Et(lt,St),arguments);var r=Zt.allocUnsafe(21);return r.writeUInt8(e,0),t.copy(r,1),F.encode(r)}function le(t,e,r,n){var i=I.I.toWords(t);return i.unshift(e),e===oe&&n?I.p2.encode(n,i):0===e?I.I.encode(r,i):I.p2.encode(r,i)}function de(t,e){e=e||p;try{return Xi({output:t,network:e}).address}catch(t){}try{return kn({output:t,network:e}).address}catch(t){}try{return Cn({output:t,network:e}).address}catch(t){}try{return Vn({output:t,network:e}).address}catch(t){}try{return Un({output:t,network:e}).address}catch(t){}try{return fe(t,e)}catch(t){}try{return function(t,e){var r=t.subarray(2);if(r.length<re||r.length>ee)throw new TypeError("Invalid program length for segwit address");var n=t[0]-ae;if(n<ue||n>ne)throw new TypeError("Invalid version for segwit address");if(t[1]!==r.length)throw new TypeError("Invalid script for segwit address ".concat(t[1]," !== ").concat(r.length));return le(r,n,e.bech32,e.bech32Opnet)}(t,e)}catch(t){}throw new Error(Wt(t)+" has no matching Address")}function ye(t,e){var r,n;e=e||p;try{r=ce(t)}catch(t){}if(r){if(r.version===e.pubKeyHash)return Xi({hash:r.hash}).output;if(r.version===e.scriptHash)return kn({hash:r.hash}).output}else{try{n=he(t)}catch(t){}if(n){if(n.prefix!==e.bech32&&e.bech32Opnet&&n.prefix!==e.bech32Opnet)throw new Error(t+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return Cn({hash:n.data}).output;if(32===n.data.length)return Vn({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return Un({pubkey:n.data}).output}else{if(n.version===oe){if(!e.bech32Opnet)throw new Error(t+" has an invalid prefix");return Ti({program:n.data,network:e}).output}if(n.version>=ue&&n.version<=ne&&n.data.length>=re&&n.data.length<=ee)return n.version!==oe&&console.warn(se),Gt([n.version+ae,n.data])}}}return Zt.from(t,"hex")}const ge=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),we=new Uint32Array(80);class ve extends H{constructor(){super(64,20,8,!1),this.A=0|ge[0],this.B=0|ge[1],this.C=0|ge[2],this.D=0|ge[3],this.E=0|ge[4]}get(){const{A:t,B:e,C:r,D:n,E:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)we[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)we[t]=P(we[t-3]^we[t-8]^we[t-14]^we[t-16],1);let{A:r,B:n,C:i,D:o,E:u}=this;for(let t=0;t<80;t++){let e,a;t<20?(e=B(n,i,o),a=1518500249):t<40?(e=n^i^o,a=1859775393):t<60?(e=C(n,i,o),a=2400959708):(e=n^i^o,a=3395469782);const s=P(r,5)+e+u+a+we[t]|0;u=o,o=i,i=P(n,30),n=r,r=s}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,this.set(r,n,i,o,u)}roundClean(){k(we)}destroy(){this.set(0,0,0,0,0),k(this.buffer)}}const me=x((()=>new ve)),be=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ee=(()=>Uint8Array.from(new Array(16).fill(0).map(((t,e)=>e))))(),Se=(()=>Ee.map((t=>(9*t+5)%16)))(),Ie=(()=>{const t=[[Ee],[Se]];for(let e=0;e<4;e++)for(let r of t)r.push(r[e].map((t=>be[t])));return t})(),Te=(()=>Ie[0])(),_e=(()=>Ie[1])(),ke=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((t=>Uint8Array.from(t))),Ae=Te.map(((t,e)=>t.map((t=>ke[e][t])))),Oe=_e.map(((t,e)=>t.map((t=>ke[e][t])))),Pe=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ue=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Ne(t,e,r,n){return 0===t?e^r^n:1===t?e&r|~e&n:2===t?(e|~r)^n:3===t?e&n|r&~n:e^(r|~n)}const xe=new Uint32Array(16);class Be extends H{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:r,h3:n,h4:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.h0=0|t,this.h1=0|e,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)xe[r]=t.getUint32(e,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,u=0|this.h2,a=u,s=0|this.h3,f=s,c=0|this.h4,h=c;for(let t=0;t<5;t++){const e=4-t,p=Pe[t],l=Ue[t],d=Te[t],y=_e[t],g=Ae[t],w=Oe[t];for(let e=0;e<16;e++){const n=P(r+Ne(t,i,u,s)+xe[d[e]]+p,g[e])+c|0;r=c,c=s,s=0|P(u,10),u=i,i=n}for(let t=0;t<16;t++){const r=P(n+Ne(e,o,a,f)+xe[y[t]]+l,w[t])+h|0;n=h,h=f,f=0|P(a,10),a=o,o=r}}this.set(this.h1+u+f|0,this.h2+s+h|0,this.h3+c+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){k(xe)}destroy(){this.destroyed=!0,k(this.buffer),this.set(0,0,0,0,0)}}const Ce=x((()=>new Be)),He=me;var Re=r(287).hp;function Le(t){return Re.from(Ce(Uint8Array.from(t)))}function De(t){return Re.from(He(Uint8Array.from(t)))}function Ve(t){return Re.from(K(Uint8Array.from(t)))}function Ke(t){return Re.from(Ce(K(Uint8Array.from(t))))}function Me(t){return Re.from(K(K(Uint8Array.from(t))))}var Fe=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],Ge={"BIP0340/challenge":Re.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Re.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Re.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Re.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Re.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Re.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Re.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Re.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Re.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function je(t,e){return Ve(Re.concat([Ge[t],e]))}var We=r(287).hp,qe={};function Xe(t){var e;t?t!==qe.eccLib&&($e("function"==typeof(e=t).isXOnlyPoint),$e(e.isXOnlyPoint(ze("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),$e(e.isXOnlyPoint(ze("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),$e(e.isXOnlyPoint(ze("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),$e(e.isXOnlyPoint(ze("0000000000000000000000000000000000000000000000000000000000000001"))),$e(!e.isXOnlyPoint(ze("0000000000000000000000000000000000000000000000000000000000000000"))),$e(!e.isXOnlyPoint(ze("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),$e("function"==typeof e.xOnlyPointAddTweak),Je.forEach((function(t){var r=e.xOnlyPointAddTweak(ze(t.pubkey),ze(t.tweak));null===t.result?$e(null===r):($e(null!==r),$e(r.parity===t.parity),$e(We.from(r.xOnlyPubkey).equals(ze(t.result))))})),qe.eccLib=t):qe.eccLib=t}function Ye(){if(!qe.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return qe.eccLib}var ze=function(t){return We.from(t,"hex")};function $e(t){if(!t)throw new Error("ecc library invalid")}var Je=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];const Qe="0123456789abcdefABCDEF";Qe.split("").map((t=>t.codePointAt(0))),Array(256).fill(!0).map(((t,e)=>{const r=String.fromCodePoint(e),n=Qe.indexOf(r);return n<0?void 0:n<16?n:n-6})),new TextEncoder,new TextDecoder;const Ze=t=>{if(t<0||t>0xffffffffffffffffn)throw new RangeError("value out of range")};function tr(t){"number"==typeof t?function(t){if(t<0||t>Number.MAX_SAFE_INTEGER||t%1!=0)throw new RangeError("value out of range")}(t):Ze(t)}function er(t,e,r){tr(t),void 0===r&&(r=0),void 0===e&&(e=new Uint8Array(nr(t)));let n=0;return t<253?(e.set([Number(t)],r),n=1):t<=65535?(e.set([253],r),function(t,e,r,n){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255):(t[e]=r>>8&255,t[e+1]=255&r)}(e,r+1,Number(t),"LE"),n=3):t<=4294967295?(e.set([254],r),function(t,e,r,n){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255):(t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r)}(e,r+1,Number(t),"LE"),n=5):(e.set([255],r),function(t,e,r,n){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);"LE"===n?(t[e]=Number(0xffn&r),t[e+1]=Number(r>>8n&0xffn),t[e+2]=Number(r>>16n&0xffn),t[e+3]=Number(r>>24n&0xffn),t[e+4]=Number(r>>32n&0xffn),t[e+5]=Number(r>>40n&0xffn),t[e+6]=Number(r>>48n&0xffn),t[e+7]=Number(r>>56n&0xffn)):(t[e]=Number(r>>56n&0xffn),t[e+1]=Number(r>>48n&0xffn),t[e+2]=Number(r>>40n&0xffn),t[e+3]=Number(r>>32n&0xffn),t[e+4]=Number(r>>24n&0xffn),t[e+5]=Number(r>>16n&0xffn),t[e+6]=Number(r>>8n&0xffn),t[e+7]=Number(0xffn&r))}(e,r+1,BigInt(t),"LE"),n=9),{buffer:e,bytes:n}}function rr(t,e){void 0===e&&(e=0);const r=t.at(e);if(void 0===r)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(253===r){const r=function(t,e,r){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+1],r=(r<<8)+t[e],r}{let r=0;return r=(r<<8)+t[e],r=(r<<8)+t[e+1],r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}if(254===r){const r=function(t,e,r){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+3]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e]>>>0,r}{let r=0;return r=(r<<8)+t[e]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+3]>>>0,r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}{const r=function(t,e,r){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(t[e+7]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e]),r}{let r=0n;return r=(r<<8n)+BigInt(t[e]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+7]),r}}(t,e+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function nr(t){return tr(t),t<253?1:t<=65535?3:t<=4294967295?5:9}var ir=r(287).hp;function or(t){return or="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},or(t)}function ur(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ar(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,fr(n.key),n)}}function sr(t,e,r){return e&&ar(t.prototype,e),r&&ar(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function fr(t){var e=function(t){if("object"!=or(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=or(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==or(e)?e:e+""}var cr=it;function hr(t,e){if("number"!=typeof t)throw new Error("cannot write a non-number as a number");if(t<0)throw new Error("specified a negative value for writing an unsigned value");if(t>e)throw new Error("RangeError: value out of range");if(Math.floor(t)!==t)throw new Error("value has a fractional component")}function pr(t,e){var r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return hr((n*=4294967296)+r,9007199254740991),n+r}function lr(t,e,r){return hr(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}function dr(t){if(t.length<1)return t;for(var e=t.length-1,r=0,n=0;n<t.length/2;n++)r=t[n],t[n]=t[e],t[e]=r,e--;return t}function yr(t){var e=ir.allocUnsafe(t.length);return t.copy(e),e}var gr=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;ur(this,t),this.buffer=e,this.offset=r,cr(Et(vt,It),[e,r])}return sr(t,[{key:"writeUInt8",value:function(t){this.offset=this.buffer.writeUInt8(t,this.offset)}},{key:"writeInt32",value:function(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}},{key:"writeUInt32",value:function(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}},{key:"writeUInt64",value:function(t){this.offset=lr(this.buffer,t,this.offset)}},{key:"writeVarInt",value:function(t){var e=er(t,this.buffer,this.offset);this.offset+=e.bytes}},{key:"writeSlice",value:function(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}},{key:"writeVarSlice",value:function(t){this.writeVarInt(t.length),this.writeSlice(t)}},{key:"writeVector",value:function(t){var e=this;this.writeVarInt(t.length),t.forEach((function(t){return e.writeVarSlice(t)}))}},{key:"end",value:function(){if(this.buffer.length===this.offset)return this.buffer;throw new Error("buffer size ".concat(this.buffer.length,", offset ").concat(this.offset))}}],[{key:"withCapacity",value:function(e){return new t(ir.alloc(e))}}])}(),wr=function(){return sr((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;ur(this,t),this.buffer=e,this.offset=r,cr(Et(vt,It),[e,r])}),[{key:"readUInt8",value:function(){var t=this.buffer.readUInt8(this.offset);return this.offset++,t}},{key:"readInt32",value:function(){var t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt32",value:function(){var t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt64",value:function(){var t=pr(this.buffer,this.offset);return this.offset+=8,t}},{key:"readVarInt",value:function(){var t=rr(this.buffer,this.offset);return this.offset+=t.bytes,t.numberValue||0}},{key:"readSlice",value:function(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");var e=this.buffer.subarray(this.offset,this.offset+t);return this.offset+=t,e}},{key:"readVarSlice",value:function(){return this.readSlice(this.readVarInt())}},{key:"readVector",value:function(){for(var t=this.readVarInt(),e=[],r=0;r<t;r++)e.push(this.readVarSlice());return e}}])}();function vr(t){return function(t){if(Array.isArray(t))return mr(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return mr(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?mr(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function mr(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var br=192,Er=128,Sr=function(t){return"left"in t&&"right"in t};function Ir(t,e){if(t.length<33)throw new TypeError("The control-block length is too small. Got ".concat(t.length,", expected min 33."));for(var r=(t.length-33)/32,n=e,i=0;i<r;i++){var o=t.slice(33+32*i,65+32*i);n=n.compare(o)<0?Pr(n,o):Pr(o,n)}return n}function Tr(t){if(ht(t))return{hash:kr(t)};var e=[Tr(t[0]),Tr(t[1])];e.sort((function(t,e){return t.hash.compare(e.hash)}));var r=e[0],n=e[1];return{hash:Pr(r.hash,n.hash),left:r,right:n}}function _r(t,e){if(Sr(t)){var r=_r(t.left,e);if(void 0!==r)return[].concat(vr(r),[t.right.hash]);var n=_r(t.right,e);if(void 0!==n)return[].concat(vr(n),[t.left.hash])}else if(t.hash.equals(e))return[]}function kr(t){var e,r,n,i=t.version||br;return je("TapLeaf",rt.hp.concat([rt.hp.from([i]),(e=t.output,r=nr(e.length),n=rt.hp.allocUnsafe(r),er(e.length,n),rt.hp.concat([n,e]))]))}function Ar(t,e){return je("TapTweak",rt.hp.concat(e?[t,e]:[t]))}function Or(t,e){if(!rt.hp.isBuffer(t))return null;if(32!==t.length)return null;if(e&&32!==e.length)return null;var r=Ar(t,e),n=Ye().xOnlyPointAddTweak(t,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:rt.hp.from(n.xOnlyPubkey)}:null}function Pr(t,e){return je("TapBranch",rt.hp.concat([t,e]))}function Ur(t,e,r){Object.defineProperty(t,e,{configurable:!0,enumerable:!0,get:function(){var t=r.call(this);return this[e]=t,t},set:function(t){Object.defineProperty(this,e,{configurable:!0,enumerable:!0,value:t,writable:!0})}})}function Nr(t){var e;return function(){return void 0!==e?e:e=t()}}var xr=W;function Br(t,e){if(!t.data&&!t.output)throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),data:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network||p,n={name:ji.Embed,network:r,data:[]};if(Ur(n,"output",(function(){if(t.data)return Gt([xr.OP_RETURN].concat(t.data))})),Ur(n,"data",(function(){if(t.output){var e=jt(t.output);if(null!=e)return e.slice(1)}})),e.validate&&t.output){var i=jt(t.output);if(i[0]!==xr.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(it.Buffer))throw new TypeError("Output is invalid");if(t.data&&!at(t.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,t)}var Cr=W,Hr=Cr.OP_RESERVED;function Rr(t,e){if(!(t.input||t.output||t.pubkeys&&void 0!==t.m||t.signatures))throw new TypeError("Not enough data");function r(t){return $t(t)||void 0!==(e.allowIncomplete&&t===Cr.OP_0)}e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),m:it.maybe(it.Number),n:it.maybe(it.Number),output:it.maybe(it.Buffer),pubkeys:it.maybe(it.arrayOf(st)),signatures:it.maybe(it.arrayOf(r)),input:it.maybe(it.Buffer)},t);var n={network:t.network||p,name:ji.P2MS},i=[],o=!1;function u(t){o||(o=!0,i=jt(t),n.m=i[0]-Hr,n.n=i[i.length-2]-Hr,n.pubkeys=i.slice(1,-2))}if(Ur(n,"output",(function(){if(t.m&&n.n&&t.pubkeys)return Gt([].concat(Hr+t.m,t.pubkeys,Hr+n.n,Cr.OP_CHECKMULTISIG))})),Ur(n,"m",(function(){if(n.output)return u(n.output),n.m})),Ur(n,"n",(function(){if(n.pubkeys)return n.pubkeys.length})),Ur(n,"pubkeys",(function(){if(t.output)return u(t.output),n.pubkeys})),Ur(n,"signatures",(function(){if(t.input){var e=jt(t.input);if(null!=e)return e.slice(1)}})),Ur(n,"input",(function(){if(t.signatures)return Gt([Cr.OP_0].concat(t.signatures))})),Ur(n,"witness",(function(){if(n.input)return[]})),Ur(n,"name",(function(){if(n.m&&n.n)return"p2ms(".concat(n.m," of ").concat(n.n,")")})),e.validate){if(t.output){if(u(t.output),!it.Number(i[0]))throw new TypeError("Output is invalid");if(!it.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Cr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every((function(t){return st(t)})))throw new TypeError("Output is invalid");if(void 0!==t.m&&t.m!==n.m)throw new TypeError("m mismatch");if(void 0!==t.n&&t.n!==n.n)throw new TypeError("n mismatch");if(t.pubkeys&&!at(t.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(t.pubkeys){if(void 0!==t.n&&t.n!==t.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=t.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(t.signatures){if(t.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(t.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(t.input){if(t.input[0]!==Cr.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(t.signatures&&!at(t.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==t.m&&t.m!==t.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,t)}var Lr=W;function Dr(t,e){if(!(t.input||t.output||t.pubkey||t.input||t.signature))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Nr((function(){return jt(t.input)})),n=t.network||p,i={name:ji.P2PK,network:n,pubkey:void 0};if(Ur(i,"output",(function(){if(t.pubkey)return Gt([t.pubkey,Lr.OP_CHECKSIG])})),Ur(i,"pubkey",(function(){if(t.output)return t.output.slice(1,-1)})),Ur(i,"signature",(function(){if(t.input)return r()[0]})),Ur(i,"input",(function(){if(t.signature)return Gt([t.signature])})),Ur(i,"witness",(function(){if(i.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Lr.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!st(i.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&!t.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&!t.input.equals(i.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!$t(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,t)}const Vr=2n**256n,Kr=Vr-0x1000003d1n,Mr=Vr-0x14551231950b75fc4402da1732fc9bebfn,Fr=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gr=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,jr={p:Kr,n:Mr,a:0n,b:7n,Gx:Fr,Gy:Gr},Wr=t=>tn(tn(t*t)*t+jr.b),qr=(t="")=>{throw new Error(t)},Xr=t=>"bigint"==typeof t,Yr=t=>"string"==typeof t,zr=t=>Xr(t)&&0n<t&&t<Kr,$r=t=>Xr(t)&&0n<t&&t<Mr,Jr=(t,e)=>!(t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?qr("Uint8Array expected"):t,Qr=t=>new Uint8Array(t),Zr=(t,e)=>Jr(Yr(t)?fn(t):Qr(Jr(t)),e),tn=(t,e=Kr)=>{const r=t%e;return r>=0n?r:e+r},en=t=>t instanceof rn?t:qr("Point expected");class rn{constructor(t,e,r){this.px=t,this.py=e,this.pz=r,Object.freeze(this)}static fromAffine(t){return 0n===t.x&&0n===t.y?on:new rn(t.x,t.y,1n)}static fromHex(t){let e;const r=(t=Zr(t))[0],n=t.subarray(1),i=hn(n,0,32),o=t.length;if(33===o&&[2,3].includes(r)){zr(i)||qr("Point hex invalid: x not FE");let t=gn(Wr(i));!(1&~r)!=(1n===(1n&t))&&(t=tn(-t)),e=new rn(i,t,1n)}return 65===o&&4===r&&(e=new rn(i,hn(n,32,64),1n)),e?e.ok():qr("Point invalid: not on curve")}static fromPrivateKey(t){return nn.mul(wn(t))}get x(){return this.aff().x}get y(){return this.aff().y}equals(t){const{px:e,py:r,pz:n}=this,{px:i,py:o,pz:u}=en(t),a=tn(e*u),s=tn(i*n),f=tn(r*u),c=tn(o*n);return a===s&&f===c}negate(){return new rn(this.px,tn(-this.py),this.pz)}double(){return this.add(this)}add(t){const{px:e,py:r,pz:n}=this,{px:i,py:o,pz:u}=en(t),{a,b:s}=jr;let f=0n,c=0n,h=0n;const p=tn(3n*s);let l=tn(e*i),d=tn(r*o),y=tn(n*u),g=tn(e+r),w=tn(i+o);g=tn(g*w),w=tn(l+d),g=tn(g-w),w=tn(e+n);let v=tn(i+u);return w=tn(w*v),v=tn(l+y),w=tn(w-v),v=tn(r+n),f=tn(o+u),v=tn(v*f),f=tn(d+y),v=tn(v-f),h=tn(a*w),f=tn(p*y),h=tn(f+h),f=tn(d-h),h=tn(d+h),c=tn(f*h),d=tn(l+l),d=tn(d+l),y=tn(a*y),w=tn(p*w),d=tn(d+y),y=tn(l-y),y=tn(a*y),w=tn(w+y),l=tn(d*w),c=tn(c+l),l=tn(v*w),f=tn(g*f),f=tn(f-l),l=tn(g*d),h=tn(v*h),h=tn(h+l),new rn(f,c,h)}mul(t,e=!0){if(!e&&0n===t)return on;if($r(t)||qr("scalar invalid"),this.equals(nn))return Sn(t).p;let r=on,n=nn;for(let i=this;t>0n;i=i.double(),t>>=1n)1n&t?r=r.add(i):e&&(n=n.add(i));return r}mulAddQUns(t,e,r){return this.mul(e,!1).add(t.mul(r,!1)).ok()}toAffine(){const{px:t,py:e,pz:r}=this;if(this.equals(on))return{x:0n,y:0n};if(1n===r)return{x:t,y:e};const n=yn(r,Kr);return 1n!==tn(r*n)&&qr("inverse invalid"),{x:tn(t*n),y:tn(e*n)}}assertValidity(){const{x:t,y:e}=this.aff();return zr(t)&&zr(e)||qr("Point invalid: x or y"),tn(e*e)===Wr(t)?this:qr("Point invalid: not on curve")}multiply(t){return this.mul(t)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(t=!0){const{x:e,y:r}=this.aff();return(t?0n===(1n&r)?"02":"03":"04")+ln(e)+(t?"":ln(r))}toRawBytes(t=!0){return fn(this.toHex(t))}}rn.BASE=new rn(Fr,Gr,1n),rn.ZERO=new rn(0n,1n,0n);const{BASE:nn,ZERO:on}=rn,un=(t,e)=>t.toString(16).padStart(e,"0"),an=t=>Array.from(Jr(t)).map((t=>un(t,2))).join(""),sn=t=>t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0,fn=t=>{const e="hex invalid";if(!Yr(t))return qr(e);const r=t.length,n=r/2;if(r%2)return qr(e);const i=Qr(n);for(let r=0,o=0;r<n;r++,o+=2){const n=sn(t.charCodeAt(o)),u=sn(t.charCodeAt(o+1));if(void 0===n||void 0===u)return qr(e);i[r]=16*n+u}return i},cn=t=>BigInt("0x"+(an(t)||"0")),hn=(t,e,r)=>cn(t.slice(e,r)),pn=t=>Xr(t)&&t>=0n&&t<Vr?fn(un(t,64)):qr("bigint expected"),ln=t=>an(pn(t)),dn=(...t)=>{const e=Qr(t.reduce(((t,e)=>t+Jr(e).length),0));let r=0;return t.forEach((t=>{e.set(t,r),r+=t.length})),e},yn=(t,e)=>{(0n===t||e<=0n)&&qr("no inverse n="+t+" mod="+e);let r=tn(t,e),n=e,i=0n,o=1n,u=1n,a=0n;for(;0n!==r;){const t=n/r,e=n%r,s=i-u*t,f=o-a*t;n=r,r=e,i=u,o=a,u=s,a=f}return 1n===n?tn(i,e):qr("no inverse")},gn=t=>{let e=1n;for(let r=t,n=(Kr+1n)/4n;n>0n;n>>=1n)1n&n&&(e=e*r%Kr),r=r*r%Kr;return tn(e*e)===t?e:qr("sqrt invalid")},wn=t=>(Xr(t)||(t=cn(Zr(t,32))),$r(t)?t:qr("private key invalid 3")),vn=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;let mn;const bn={hexToBytes:fn,bytesToHex:an,concatBytes:dn,bytesToNumberBE:cn,numberToBytesBE:pn,mod:tn,invert:yn,hmacSha256Async:async(t,...e)=>{const r=vn(),n=r&&r.subtle;if(!n)return qr("etc.hmacSha256Async or crypto.subtle must be defined");const i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Qr(await n.sign("HMAC",i,dn(...e)))},hmacSha256Sync:mn,hashToPrivateKey:t=>{((t=Zr(t)).length<40||t.length>1024)&&qr("expected 40-1024b");const e=tn(cn(t),Mr-1n);return pn(e+1n)},randomBytes:(t=32)=>{const e=vn();return e&&e.getRandomValues||qr("crypto.getRandomValues must be defined"),e.getRandomValues(Qr(t))}};let En;Object.defineProperties(bn,{hmacSha256Sync:{configurable:!1,get:()=>mn,set(t){mn||(mn=t)}}});const Sn=t=>{const e=En||(En=(()=>{const t=[];let e=nn,r=e;for(let n=0;n<33;n++){r=e,t.push(r);for(let n=1;n<128;n++)r=r.add(e),t.push(r);e=r.double()}return t})()),r=(t,e)=>{let r=e.negate();return t?r:e};let n=on,i=nn;const o=BigInt(255),u=BigInt(8);for(let a=0;a<33;a++){const s=128*a;let f=Number(t&o);t>>=u,f>128&&(f-=256,t+=1n);const c=s,h=s+Math.abs(f)-1,p=a%2!=0,l=f<0;0===f?i=i.add(r(p,e[c])):n=n.add(r(l,e[h]))}return{p:n,f:i}};var In=r(394),Tn=r(287).hp,_n=W;function kn(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(23)),redeem:it.maybe({network:it.maybe(it.Object),output:it.maybe(it.Buffer),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network;r||(r=t.redeem&&t.redeem.network||p);var n={network:r,name:ji.P2SH},i=Nr((function(){var e=Tn.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),o=Nr((function(){return jt(t.input)})),u=Nr((function(){var e=o(),n=e[e.length-1];return{network:r,output:n===_n.OP_FALSE?Tn.from([]):n,input:Gt(e.slice(0,-1)),witness:t.witness||[]}}));if(Ur(n,"address",(function(){if(n.hash){var t=Tn.allocUnsafe(21);return t.writeUInt8(n.network.scriptHash,0),n.hash.copy(t,1),F.encode(t)}})),Ur(n,"hash",(function(){return t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?Ke(n.redeem.output):void 0})),Ur(n,"output",(function(){if(n.hash)return Gt([_n.OP_HASH160,n.hash,_n.OP_EQUAL])})),Ur(n,"redeem",(function(){if(t.input)return u()})),Ur(n,"input",(function(){if(t.redeem&&t.redeem.input&&t.redeem.output)return Gt([].concat(jt(t.redeem.input),t.redeem.output))})),Ur(n,"witness",(function(){return n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0})),Ur(n,"name",(function(){var t=["p2sh"];return void 0!==n.redeem&&void 0!==n.redeem.name&&t.push(n.redeem.name),t.join("-")})),e.validate){var a=Tn.from([]);if(t.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");a=i().hash}if(t.hash){if(a.length>0&&!a.equals(t.hash))throw new TypeError("Hash mismatch");a=t.hash}if(t.output){if(23!==t.output.length||t.output[0]!==_n.OP_HASH160||20!==t.output[1]||t.output[22]!==_n.OP_EQUAL)throw new TypeError("Output is invalid");var s=t.output.slice(2,22);if(a.length>0&&!a.equals(s))throw new TypeError("Hash mismatch");a=s}var f=function(t){if(t.output){var e=jt(t.output);if(!e||e.length<1)throw new TypeError("Redeem.output too short");if(t.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(Vt(e)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");var r=Ke(t.output);if(a.length>0&&!a.equals(r))throw new TypeError("Hash mismatch");a=r}if(t.input){var n=t.input.length>0,i=t.witness&&t.witness.length>0;if(!n&&!i)throw new TypeError("Empty input");if(n&&i)throw new TypeError("Input and witness provided");if(n&&!Dt(jt(t.input)))throw new TypeError("Non push-only scriptSig")}};if(t.input){var c=o();if(!c||c.length<1)throw new TypeError("Input too short");if(!Tn.isBuffer(u().output))throw new TypeError("Input is invalid");f(u())}if(t.redeem){if(t.redeem.network&&t.redeem.network!==r)throw new TypeError("Network mismatch");if(t.input){var h=u();if(t.redeem.output&&!t.redeem.output.equals(h.output))throw new TypeError("Redeem.output mismatch");if(t.redeem.input&&!t.redeem.input.equals(h.input))throw new TypeError("Redeem.input mismatch")}f(t.redeem)}if(t.witness&&t.redeem&&t.redeem.witness&&!at(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var An=W,On=1,Pn=80;function Un(t,e){if(!(t.address||t.output||t.pubkey||t.internalPubkey||t.witness&&t.witness.length>1))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(34)),internalPubkey:it.maybe(it.BufferN(32)),hash:it.maybe(it.BufferN(32)),pubkey:it.maybe(it.BufferN(32)),signature:it.maybe(it.anyOf(it.BufferN(64),it.BufferN(65))),witness:it.maybe(it.arrayOf(it.Buffer)),scriptTree:it.maybe(pt),redeem:it.maybe({output:it.maybe(it.Buffer),redeemVersion:it.maybe(it.Number),witness:it.maybe(it.arrayOf(it.Buffer))}),redeemVersion:it.maybe(it.Number)},t);var r=Nr((function(){return he(t.address)})),n=Nr((function(){if(t.witness&&t.witness.length)return t.witness.length>=2&&t.witness[t.witness.length-1][0]===Pn?t.witness.slice(0,-1):t.witness.slice()})),i=Nr((function(){return t.scriptTree?Tr(t.scriptTree):t.hash?{hash:t.hash}:void 0})),o=t.network||p,u={name:ji.P2TR,network:o};if(Ur(u,"address",(function(){if(u.pubkey){var t=I.p2.toWords(u.pubkey);return t.unshift(On),I.p2.encode(o.bech32,t)}})),Ur(u,"hash",(function(){var t=i();if(t)return t.hash;var e=n();if(e&&e.length>1){var r=e[e.length-1],o=r[0]&ct;return Ir(r,kr({output:e[e.length-2],version:o}))}})),Ur(u,"output",(function(){if(u.pubkey)return Gt([An.OP_1,u.pubkey])})),Ur(u,"redeemVersion",(function(){return t.redeemVersion?t.redeemVersion:t.redeem&&void 0!==t.redeem.redeemVersion&&null!==t.redeem.redeemVersion?t.redeem.redeemVersion:br})),Ur(u,"redeem",(function(){var t=n();if(t&&!(t.length<2))return{output:t[t.length-2],witness:t.slice(0,-2),redeemVersion:t[t.length-1][0]&ct}})),Ur(u,"pubkey",(function(){if(t.pubkey)return t.pubkey;if(t.output)return t.output.slice(2);if(t.address)return r().data;if(u.internalPubkey){var e=Or(u.internalPubkey,u.hash);if(e)return e.x}})),Ur(u,"internalPubkey",(function(){if(t.internalPubkey)return t.internalPubkey;var e=n();return e&&e.length>1?e[e.length-1].slice(1,33):void 0})),Ur(u,"signature",(function(){if(t.signature)return t.signature;var e=n();return e&&1===e.length?e[0]:void 0})),Ur(u,"witness",(function(){if(t.witness)return t.witness;var e=i();if(e&&t.redeem&&t.redeem.output&&t.internalPubkey){var r=_r(e,kr({output:t.redeem.output,version:u.redeemVersion}));if(!r)return;var n=Or(t.internalPubkey,e.hash);if(!n)return;var o=rt.hp.concat([rt.hp.from([u.redeemVersion|n.parity]),t.internalPubkey].concat(r));return[t.redeem.output,o]}return t.signature?[t.signature]:void 0})),e.validate){var a=rt.hp.from([]);if(t.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==On)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");a=r().data}if(t.pubkey){if(a.length>0&&!a.equals(t.pubkey))throw new TypeError("Pubkey mismatch");a=t.pubkey}if(t.output){if(34!==t.output.length||t.output[0]!==An.OP_1||32!==t.output[1])throw new TypeError("Output is invalid");if(a.length>0&&!a.equals(t.output.slice(2)))throw new TypeError("Pubkey mismatch");a=t.output.slice(2)}if(t.internalPubkey){var s=Or(t.internalPubkey,u.hash);if(a.length>0&&!a.equals(s.x))throw new TypeError("Pubkey mismatch");a=s.x}var f=i();if(t.hash&&f&&!t.hash.equals(f.hash))throw new TypeError("Hash mismatch");if(t.redeem&&t.redeem.output&&f&&!_r(f,kr({output:t.redeem.output,version:u.redeemVersion})))throw new TypeError("Redeem script not in tree");var c=n();if(t.redeem&&u.redeem){if(t.redeem.redeemVersion&&t.redeem.redeemVersion!==u.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(t.redeem.output){if(0===jt(t.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(u.redeem.output&&!t.redeem.output.equals(u.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(t.redeem.witness&&u.redeem.witness&&!at(t.redeem.witness,u.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(c&&c.length)if(1===c.length){if(t.signature&&!t.signature.equals(c[0]))throw new TypeError("Signature mismatch")}else{var h=c[c.length-1];if(h.length<33)throw new TypeError("The control-block length is too small. Got ".concat(h.length,", expected min 33."));if((h.length-33)%32!=0)throw new TypeError("The control-block length of ".concat(h.length," is incorrect!"));var l=(h.length-33)/32;if(l>128)throw new TypeError("The script path is too long. Got ".concat(l,", expected max 128."));var d=h.slice(1,33);if(t.internalPubkey&&!t.internalPubkey.equals(d))throw new TypeError("Internal pubkey mismatch");if(!Ye().isXOnlyPoint(d))throw new TypeError("Invalid internalPubkey for p2tr witness");var y=h[0]&ct,g=Or(d,Ir(h,kr({output:c[c.length-2],version:y})));if(!g)throw new TypeError("Invalid outputKey for p2tr witness");if(a.length&&!a.equals(g.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(g.parity!==(1&h[0]))throw new Error("Incorrect parity")}}return Object.assign(u,t)}var Nn=r(287).hp,xn=W,Bn=Nn.alloc(0);function Cn(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(22)),pubkey:it.maybe(st),signature:it.maybe($t),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Nr((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Nn.from(n)}})),n=t.network||p,i={name:ji.P2WPKH,network:n};if(Ur(i,"address",(function(){if(i.hash){var t=I.I.toWords(i.hash);return t.unshift(0),I.I.encode(n.bech32,t)}})),Ur(i,"hash",(function(){return t.output?t.output.slice(2,22):t.address?r().data:t.pubkey||i.pubkey?Ke(t.pubkey||i.pubkey):void 0})),Ur(i,"output",(function(){if(i.hash)return Gt([xn.OP_0,i.hash])})),Ur(i,"pubkey",(function(){return t.pubkey?t.pubkey:t.witness?t.witness[1]:void 0})),Ur(i,"signature",(function(){if(t.witness)return t.witness[0]})),Ur(i,"input",(function(){if(i.witness)return Bn})),Ur(i,"witness",(function(){if(t.pubkey&&t.signature)return[t.signature,t.pubkey]})),e.validate){var o=Nn.from([]);if(t.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");o=r().data}if(t.hash){if(o.length>0&&!o.equals(t.hash))throw new TypeError("Hash mismatch");o=t.hash}if(t.output){if(22!==t.output.length||t.output[0]!==xn.OP_0||20!==t.output[1])throw new TypeError("Output is invalid");if(o.length>0&&!o.equals(t.output.slice(2)))throw new TypeError("Hash mismatch");o=t.output.slice(2)}if(t.pubkey){var u=Ke(t.pubkey);if(o.length>0&&!o.equals(u))throw new TypeError("Hash mismatch");if(o=u,!st(t.pubkey)||33!==t.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(t.witness){if(2!==t.witness.length)throw new TypeError("Witness is invalid");if(!$t(t.witness[0]))throw new TypeError("Witness has invalid signature");if(!st(t.witness[1])||33!==t.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(t.signature&&!t.signature.equals(t.witness[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(t.witness[1]))throw new TypeError("Pubkey mismatch");var a=Ke(t.witness[1]);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(i,t)}var Hn=r(287).hp,Rn=W,Ln=Hn.alloc(0);function Dn(t){return!(!Hn.isBuffer(t)||65!==t.length||4!==t[0]||!st(t))}function Vn(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(32)),output:it.maybe(it.BufferN(34)),redeem:it.maybe({input:it.maybe(it.Buffer),network:it.maybe(it.Object),output:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.BufferN(0)),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Nr((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Hn.from(n)}})),n=Nr((function(){return jt(t.redeem.input)})),i=t.network;i||(i=t.redeem&&t.redeem.network||p);var o={network:i,name:ji.P2WSH};if(Ur(o,"address",(function(){if(o.hash){var t=I.I.toWords(o.hash);return t.unshift(0),I.I.encode(i.bech32,t)}})),Ur(o,"hash",(function(){return t.output?t.output.slice(2):t.address?r().data:o.redeem&&o.redeem.output?Ve(o.redeem.output):void 0})),Ur(o,"output",(function(){if(o.hash)return Gt([Rn.OP_0,o.hash])})),Ur(o,"redeem",(function(){if(t.witness)return{output:t.witness[t.witness.length-1],input:Ln,witness:t.witness.slice(0,-1)}})),Ur(o,"input",(function(){if(o.witness)return Ln})),Ur(o,"witness",(function(){if(t.redeem&&t.redeem.input&&t.redeem.input.length>0&&t.redeem.output&&t.redeem.output.length>0){var e=Xt(n());return o.redeem=Object.assign({witness:e},t.redeem),o.redeem.input=Ln,[].concat(e,t.redeem.output)}if(t.redeem&&t.redeem.output&&t.redeem.witness)return[].concat(t.redeem.witness,t.redeem.output)})),Ur(o,"name",(function(){var t=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&t.push(o.redeem.name),t.join("-")})),e.validate){var u=Hn.from([]);if(t.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");u=r().data}if(t.hash){if(u.length>0&&!u.equals(t.hash))throw new TypeError("Hash mismatch");u=t.hash}if(t.output){if(34!==t.output.length||t.output[0]!==Rn.OP_0||32!==t.output[1])throw new TypeError("Output is invalid");var a=t.output.slice(2);if(u.length>0&&!u.equals(a))throw new TypeError("Hash mismatch");u=a}if(t.redeem){if(t.redeem.network&&t.redeem.network!==i)throw new TypeError("Network mismatch");if(t.redeem.input&&t.redeem.input.length>0&&t.redeem.witness&&t.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(t.redeem.output){var s=jt(t.redeem.output);if(!s||s.length<1)throw new TypeError("Redeem.output is invalid");if(t.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Vt(s)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");var f=Ve(t.redeem.output);if(u.length>0&&!u.equals(f))throw new TypeError("Hash mismatch");u=f}if(t.redeem.input&&!Dt(n()))throw new TypeError("Non push-only scriptSig");if(t.witness&&t.redeem.witness&&!at(t.witness,t.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(t.redeem.input&&n().some(Dn)||t.redeem.output&&(jt(t.redeem.output)||[]).some(Dn))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(t.witness&&t.witness.length>0){var c=t.witness[t.witness.length-1];if(t.redeem&&t.redeem.output&&!t.redeem.output.equals(c))throw new TypeError("Witness and redeem.output mismatch");if(t.witness.some(Dn)||(jt(c)||[]).some(Dn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,t)}var Kn=r(287).hp;function Mn(t){return Mn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Mn(t)}function Fn(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,jn(n.key),n)}}function Gn(t,e,r){return(e=jn(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function jn(t){var e=function(t){if("object"!=Mn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Mn(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Mn(e)?e:e+""}var Wn=it;function qn(t){var e=t.length;return nr(e)+e}var Xn=Kn.allocUnsafe(0),Yn=[],zn=Kn.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),$n=Kn.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Jn=Kn.from("ffffffffffffffff","hex"),Qn={script:Xn,valueBuffer:Jn},Zn=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Gn(this,"version",1),Gn(this,"locktime",0),Gn(this,"ins",[]),Gn(this,"outs",[])}return e=t,r=[{key:"isCoinbase",value:function(){return 1===this.ins.length&&t.isCoinbaseHash(this.ins[0].hash)}},{key:"addInput",value:function(e,r,n,i){return Wn(Et(dt,It,bt(It),bt(vt)),arguments),kt(n)&&(n=t.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:r,script:i||Xn,sequence:n,witness:Yn})-1}},{key:"addOutput",value:function(t,e){return Wn(Et(vt,ft),arguments),this.outs.push({script:t,value:e})-1}},{key:"hasWitnesses",value:function(){return this.ins.some((function(t){return 0!==t.witness.length}))}},{key:"weight",value:function(){return 3*this.byteLength(!1)+this.byteLength(!0)}},{key:"virtualSize",value:function(){return Math.ceil(this.weight()/4)}},{key:"byteLength",value:function(){var t=(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&this.hasWitnesses();return(t?10:8)+nr(this.ins.length)+nr(this.outs.length)+this.ins.reduce((function(t,e){return t+40+qn(e.script)}),0)+this.outs.reduce((function(t,e){return t+8+qn(e.script)}),0)+(t?this.ins.reduce((function(t,e){return t+(nr((r=e.witness).length)+r.reduce((function(t,e){return t+qn(e)}),0));var r}),0):0)}},{key:"clone",value:function(){var e=new t;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map((function(t){return{hash:t.hash,index:t.index,script:t.script,sequence:t.sequence,witness:t.witness}})),e.outs=this.outs.map((function(t){return{script:t.script,value:t.value}})),e}},{key:"hashForSignature",value:function(e,r,n){if(Wn(Et(It,vt,yt),arguments),e>=this.ins.length)return $n;var i=Gt(jt(r).filter((function(t){return t!==W.OP_CODESEPARATOR}))),o=this.clone();if((31&n)===t.SIGHASH_NONE)o.outs=[],o.ins.forEach((function(t,r){r!==e&&(t.sequence=0)}));else if((31&n)===t.SIGHASH_SINGLE){if(e>=this.outs.length)return $n;o.outs.length=e+1;for(var u=0;u<e;u++)o.outs[u]=Qn;o.ins.forEach((function(t,r){r!==e&&(t.sequence=0)}))}n&t.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[e]],o.ins[0].script=i):(o.ins.forEach((function(t){t.script=Xn})),o.ins[e].script=i);var a=Kn.allocUnsafe(o.byteLength(!1)+4);return a.writeInt32LE(n,a.length-4),o.__toBuffer(a,0,!1),Me(a)}},{key:"hashForWitnessV1",value:function(e,r,n,i,o,u){if(Wn(Et(It,Wn.arrayOf(vt),Wn.arrayOf(ft),It),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");var a=i===t.SIGHASH_DEFAULT?t.SIGHASH_ALL:i&t.SIGHASH_OUTPUT_MASK,s=(i&t.SIGHASH_INPUT_MASK)===t.SIGHASH_ANYONECANPAY,f=a===t.SIGHASH_NONE,c=a===t.SIGHASH_SINGLE,h=Xn,p=Xn,l=Xn,d=Xn,y=Xn;if(!s){var g=gr.withCapacity(36*this.ins.length);this.ins.forEach((function(t){g.writeSlice(t.hash),g.writeUInt32(t.index)})),h=Ve(g.end()),g=gr.withCapacity(8*this.ins.length),n.forEach((function(t){return g.writeUInt64(t)})),p=Ve(g.end()),g=gr.withCapacity(r.map(qn).reduce((function(t,e){return t+e}))),r.forEach((function(t){return g.writeVarSlice(t)})),l=Ve(g.end()),g=gr.withCapacity(4*this.ins.length),this.ins.forEach((function(t){return g.writeUInt32(t.sequence)})),d=Ve(g.end())}if(f||c){if(c&&e<this.outs.length){var w=this.outs[e],v=gr.withCapacity(8+qn(w.script));v.writeUInt64(w.value),v.writeVarSlice(w.script),y=Ve(v.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");var m=this.outs.map((function(t){return 8+qn(t.script)})).reduce((function(t,e){return t+e})),b=gr.withCapacity(m);this.outs.forEach((function(t){b.writeUInt64(t.value),b.writeVarSlice(t.script)})),y=Ve(b.end())}var E=(o?2:0)+(u?1:0),S=174-(s?49:0)-(f?32:0)+(u?32:0)+(o?37:0),I=gr.withCapacity(S);if(I.writeUInt8(i),I.writeInt32(this.version),I.writeUInt32(this.locktime),I.writeSlice(h),I.writeSlice(p),I.writeSlice(l),I.writeSlice(d),f||c||I.writeSlice(y),I.writeUInt8(E),s){var T=this.ins[e];I.writeSlice(T.hash),I.writeUInt32(T.index),I.writeUInt64(n[e]),I.writeVarSlice(r[e]),I.writeUInt32(T.sequence)}else I.writeUInt32(e);if(u){var _=gr.withCapacity(qn(u));_.writeVarSlice(u),I.writeSlice(Ve(_.end()))}return c&&I.writeSlice(y),o&&(I.writeSlice(o),I.writeUInt8(0),I.writeUInt32(4294967295)),je("TapSighash",Kn.concat([Kn.from([0]),I.end()]))}},{key:"hashForWitnessV0",value:function(e,r,n,i){Wn(Et(It,vt,ft,It),arguments);var o,u=Kn.from([]),a=zn,s=zn,f=zn;if(i&t.SIGHASH_ANYONECANPAY||(u=Kn.allocUnsafe(36*this.ins.length),o=new gr(u,0),this.ins.forEach((function(t){o.writeSlice(t.hash),o.writeUInt32(t.index)})),s=Me(u)),i&t.SIGHASH_ANYONECANPAY||(31&i)===t.SIGHASH_SINGLE||(31&i)===t.SIGHASH_NONE||(u=Kn.allocUnsafe(4*this.ins.length),o=new gr(u,0),this.ins.forEach((function(t){o.writeUInt32(t.sequence)})),f=Me(u)),(31&i)!==t.SIGHASH_SINGLE&&(31&i)!==t.SIGHASH_NONE){var c=this.outs.reduce((function(t,e){return t+8+qn(e.script)}),0);u=Kn.allocUnsafe(c),o=new gr(u,0),this.outs.forEach((function(t){o.writeUInt64(t.value),o.writeVarSlice(t.script)})),a=Me(u)}else if((31&i)===t.SIGHASH_SINGLE&&e<this.outs.length){var h=this.outs[e];u=Kn.allocUnsafe(8+qn(h.script)),(o=new gr(u,0)).writeUInt64(h.value),o.writeVarSlice(h.script),a=Me(u)}u=Kn.allocUnsafe(156+qn(r)),o=new gr(u,0);var p=this.ins[e];return o.writeInt32(this.version),o.writeSlice(s),o.writeSlice(f),o.writeSlice(p.hash),o.writeUInt32(p.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(p.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Me(u)}},{key:"getHash",value:function(t){return t&&this.isCoinbase()?Kn.alloc(32,0):Me(this.__toBuffer(void 0,void 0,t))}},{key:"getId",value:function(){return dr(this.getHash(!1)).toString("hex")}},{key:"toBuffer",value:function(t,e){return this.__toBuffer(t,e,!0)}},{key:"toHex",value:function(){return this.toBuffer(void 0,void 0).toString("hex")}},{key:"setInputScript",value:function(t,e){Wn(Et(yt,vt),arguments),this.ins[t].script=e}},{key:"setWitness",value:function(t,e){Wn(Et(yt,[vt]),arguments),this.ins[t].witness=e}},{key:"__toBuffer",value:function(e,r){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];e||(e=Kn.allocUnsafe(this.byteLength(n)));var i=new gr(e,r||0);i.writeInt32(this.version);var o=n&&this.hasWitnesses();return o&&(i.writeUInt8(t.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(t.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach((function(t){i.writeSlice(t.hash),i.writeUInt32(t.index),i.writeVarSlice(t.script),i.writeUInt32(t.sequence)})),i.writeVarInt(this.outs.length),this.outs.forEach((function(t){void 0!==t.value?i.writeUInt64(t.value):i.writeSlice(t.valueBuffer),i.writeVarSlice(t.script)})),o&&this.ins.forEach((function(t){i.writeVector(t.witness)})),i.writeUInt32(this.locktime),void 0!==r?e.slice(r,i.offset):e}}],n=[{key:"fromBuffer",value:function(e,r){var n=new wr(e),i=new t;i.version=n.readInt32();var o=n.readUInt8(),u=n.readUInt8(),a=!1;o===t.ADVANCED_TRANSACTION_MARKER&&u===t.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;for(var s=n.readVarInt(),f=0;f<s;++f){var c=n.readSlice(32),h=n.readUInt32(),p=n.readVarSlice(),l=n.readUInt32();i.ins.push({hash:c,index:h,script:p,sequence:l,witness:Yn})}for(var d=n.readVarInt(),y=0;y<d;++y)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(var g=0;g<s;++g)i.ins[g].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==e.length)throw new Error("Transaction has unexpected data");return i}},{key:"fromHex",value:function(e){return t.fromBuffer(Kn.from(e,"hex"),!1)}},{key:"isCoinbaseHash",value:function(t){Wn(dt,t);for(var e=0;e<32;++e)if(0!==t[e])return!1;return!0}}],r&&Fn(e.prototype,r),n&&Fn(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();Gn(Zn,"DEFAULT_SEQUENCE",4294967295),Gn(Zn,"SIGHASH_DEFAULT",0),Gn(Zn,"SIGHASH_ALL",1),Gn(Zn,"SIGHASH_NONE",2),Gn(Zn,"SIGHASH_SINGLE",3),Gn(Zn,"SIGHASH_ANYONECANPAY",128),Gn(Zn,"SIGHASH_OUTPUT_MASK",3),Gn(Zn,"SIGHASH_INPUT_MASK",128),Gn(Zn,"ADVANCED_TRANSACTION_MARKER",0),Gn(Zn,"ADVANCED_TRANSACTION_FLAG",1);var ti=r(287).hp;function ei(t,e){if(t){if("string"==typeof t)return ri(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ri(t,e):void 0}}function ri(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ni=function(t){var e=32===t.length?t:t.slice(1,33);return ti.isBuffer(e)?e:ti.from(e)};function ii(t,e,r){var n=function(t,e,r){if(!t.tapScriptSig||!t.tapScriptSig.length)throw new Error("Can not finalize taproot input #".concat(e,". No tapleaf script signature provided."));var n=(t.tapLeafScript||[]).sort((function(t,e){return t.controlBlock.length-e.controlBlock.length})).find((function(e){return function(t,e,r){var n=kr({output:t.script,version:t.leafVersion});return(!r||r.equals(n))&&void 0!==e.find((function(t){return t.leafHash.equals(n)}))}(e,t.tapScriptSig,r)}));if(!n)throw new Error("Can not finalize taproot input #".concat(e,". Signature for tapleaf script not found."));return n}(e,t,r);try{var i=function(t,e){var r=kr({output:e.script,version:e.leafVersion});return(t.tapScriptSig||[]).filter((function(t){return t.leafHash.equals(r)})).map((function(t){return function(t,e){return Object.assign({positionInScript:Vi(e.pubkey,t)},e)}(e.script,t)})).sort((function(t,e){return e.positionInScript-t.positionInScript})).map((function(t){return t.signature}))}(e,n);return{finalScriptWitness:Hi(i.concat(n.script).concat(n.controlBlock))}}catch(e){throw new Error("Can not finalize taproot input #".concat(t,": ").concat(e))}}function oi(t,e){var r=e?ti.from([e]):ti.from([]);return ti.concat([t,r])}function ui(t){return t&&!!(t.tapInternalKey||t.tapMerkleRoot||t.tapLeafScript&&t.tapLeafScript.length||t.tapBip32Derivation&&t.tapBip32Derivation.length||t.witnessUtxo&&Bi(t.witnessUtxo.script))}function ai(t,e){return t&&!!(t.tapInternalKey||t.tapTree||t.tapBip32Derivation&&t.tapBip32Derivation.length||e&&Bi(e))}function si(t,e,r){!function(t,e,r){var n=ui(t)&&mi(e),i=mi(t)&&ui(e),o=t===e&&ui(e)&&mi(e);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}(t,e,r),function(t,e,r){if(e.tapMerkleRoot){var n=(e.tapLeafScript||[]).every((function(t){return vi(t,e.tapMerkleRoot)})),i=(t.tapLeafScript||[]).every((function(t){return vi(t,e.tapMerkleRoot)}));if(!n||!i)throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}else if(t.tapMerkleRoot&&!(e.tapLeafScript||[]).every((function(e){return vi(e,t.tapMerkleRoot)})))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}(t,e,r)}function fi(t,e,r){!function(t,e,r){var n=ai(t)&&mi(e),i=mi(t)&&ai(e),o=t===e&&ai(e)&&mi(e);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}(t,e,r),function(t,e){if(e.tapTree||e.tapInternalKey){var r=e.tapInternalKey||t.tapInternalKey,n=e.tapTree||t.tapTree;if(r){var i=t.script,o=function(t,e){return Un({internalPubkey:t,scriptTree:e&&pi(e.leaves)}).output}(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}}(t,e)}function ci(t,e){var r=e.tapInternalKey,n=r&&Or(r,e.tapMerkleRoot);if(!n)throw new Error("Cannot tweak tap internal key for input #".concat(t,". Public key: ").concat(r&&r.toString("hex")));return n.x}function hi(t){if(!pt(t))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return gi(t)}function pi(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 1===t.length&&0===t[0].depth?{output:t[0].script,version:t[0].leafVersion}:function(t){var e,r,n=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=ei(t))){e&&(t=e);var r=0,n=function(){};return{s:n,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,u=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return o=t.done,t},e:function(t){u=!0,i=t},f:function(){try{o||null==e.return||e.return()}finally{if(u)throw i}}}}(t);try{for(n.s();!(r=n.n()).done;)if(!(e=wi(r.value,e)))throw new Error("No room left to insert tapleaf in tree")}catch(t){n.e(t)}finally{n.f()}return e}(t)}function li(t,e){var r=function(t){var e,r=[];if(t.tapKeySig&&r.push(t.tapKeySig),t.tapScriptSig&&r.push.apply(r,function(t){if(Array.isArray(t))return ri(t)}(e=t.tapScriptSig.map((function(t){return t.signature})))||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||ei(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),!r.length){var n=yi(t.finalScriptWitness);n&&r.push(n)}return r}(t);return r.some((function(t){return Fi(t,di,e)}))}function di(t){return{signature:t.slice(0,64),hashType:t.slice(64)[0]||Zn.SIGHASH_DEFAULT}}function yi(t){if(t){var e=t.slice(2);return 64===e.length||65===e.length?e:void 0}}function gi(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>Er)throw new Error("Max taptree depth exceeded.");return t?ht(t)?(e.push({depth:r,leafVersion:t.version||br,script:t.output}),e):(t[0]&&gi(t[0],e,r+1),t[1]&&gi(t[1],e,r+1),e):[]}function wi(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>Er)throw new Error("Max taptree depth exceeded.");if(t.depth===r)return e?void 0:{output:t.script,version:t.leafVersion};if(!ht(e)){var n=wi(t,e&&e[0],r+1);if(n)return[n,e&&e[1]];var i=wi(t,e&&e[1],r+1);return i?[e&&e[0],i]:void 0}}function vi(t,e){if(!e)return!0;var r=kr({output:t.script,version:t.leafVersion});return Ir(t.controlBlock,r).equals(e)}function mi(t){return t&&!!(t.redeemScript||t.witnessScript||t.bip32Derivation&&t.bip32Derivation.length)}var bi=W,Ei=16,Si=2,Ii=40;function Ti(t,e){if(!(t.address||t.output||t.program||void 0!==t.deploymentVersion&&t.hash160))throw new TypeError("At least one of address, output or program must be provided");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),output:it.maybe(it.Buffer),program:it.maybe(it.Buffer),network:it.maybe(it.Object),deploymentVersion:it.maybe(it.Number),hash160:it.maybe(it.BufferN(20))},t);var r=Nr((function(){return he(t.address)})),n=t.network||p,i={name:ji.P2OP,network:n,deploymentVersion:0};if(Ur(i,"program",(function(){if(t.program)return t.program;if(t.output){if(t.output[0]!==bi.OP_16)throw new TypeError("Invalid P2OP script");var e,n=1;if(t.output[1]<76)e=t.output[1],n=2;else{if(76!==t.output[1])throw new TypeError("Unsupported push opcode in P2OP script");e=t.output[2],n=3}return t.output.slice(n,n+e)}return t.address?r().data:void 0})),Ur(i,"deploymentVersion",(function(){if(i.program)return i.program[0]})),Ur(i,"hash160",(function(){if(i.program)return i.program.slice(1)})),Ur(i,"output",(function(){if(i.program)return Gt([bi.OP_16,i.program])})),Ur(i,"address",(function(){if(i.program){if(!n.bech32Opnet)throw new TypeError("Network does not support opnet");var t=I.p2.toWords(i.program);return t.unshift(Ei),I.p2.encode(n.bech32Opnet,t)}})),e.validate){var o=rt.hp.alloc(0);if(t.address){var u=r();if(n.bech32Opnet!==u.prefix)throw new TypeError("Invalid prefix or network mismatch");if(u.version!==Ei)throw new TypeError("Invalid witness version for p2op");if(u.data.length<Si||u.data.length>Ii)throw new TypeError("Invalid witness program length");o=u.data}if(t.program){if(o.length&&!o.equals(t.program))throw new TypeError("Program mismatch");o=t.program}if(t.output){var a=i.program;if(o.length&&!o.equals(a))throw new TypeError("Program mismatch (output vs other source)");o=a}if(o.length<Si||o.length>Ii)throw new TypeError("Witness program must be 2–40 bytes");if(void 0!==t.deploymentVersion&&t.deploymentVersion!==o[0])throw new TypeError("deploymentVersion mismatch");if(t.hash160&&!t.hash160.equals(o.slice(1)))throw new TypeError("hash160 mismatch")}return Object.assign(i,t)}var _i=r(287).hp;function ki(t){return function(e){try{return t({output:e}),!0}catch(t){return!1}}}var Ai=ki(Rr),Oi=ki(Dr),Pi=ki(Xi),Ui=ki(Cn),Ni=ki(Vn),xi=ki(kn),Bi=ki(Un),Ci=ki(Ti);function Hi(t){var e,r=_i.allocUnsafe(0);function n(t){var e=r.length,n=In.encodingLength(t);r=_i.concat([r,_i.allocUnsafe(n)]),In.encode(t,r,e)}return n((e=t).length),e.forEach((function(t){n(t.length),function(t){r=_i.concat([r,_i.from(t)])}(t)})),r}function Ri(t){if(32!==t.length){if([33,65].includes(t.length)){var e;try{e=rn.fromHex(t)}catch(t){throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}var r=Li(e.x),n=Li(e.y),i=e.y%2n===0n?6:7,o=_i.alloc(65);return o[0]=i,r.copy(o,1),n.copy(o,33),{hybrid:o,uncompressed:_i.concat([_i.from([4]),r,n])}}console.warn("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed)."))}}function Li(t){var e=t.toString(16);return(e=e.padStart(64,"0")).length>64&&(e=e.slice(-64)),_i.from(e,"hex")}function Di(t,e){if(t.equals(e))return!0;if(65===t.length&&65===e.length){var r=_i.from(t),n=_i.from(e);return 6!==r[0]&&7!==r[0]||(r[0]=4),6!==n[0]&&7!==n[0]||(n[0]=4),r.equals(n)}return!1}function Vi(t,e){var r=jt(e);if(null===r)throw new Error("Unknown script error");var n=Ke(t),i=ni(t),o=Ri(t),u=null!=o&&o.hybrid?Ke(o.hybrid):void 0,a=null!=o&&o.uncompressed?Ke(o.uncompressed):void 0;return r.findIndex((function(e){if("number"==typeof e)return!1;if(Di(e,t))return!0;if(Di(e,i))return!0;if(e.equals(n))return!0;if(o){if(Di(e,o.uncompressed))return!0;if(Di(e,o.hybrid))return!0;if(u&&e.equals(u)||a&&e.equals(a))return!0}}))}function Ki(t,e){return-1!==Vi(t,e)}function Mi(t,e){var r=function(t){var e=[];if(0===(t.partialSig||[]).length){if(!t.finalScriptSig&&!t.finalScriptWitness)return[];e=Gi(t)}else e=t.partialSig;return e.map((function(t){return t.signature}))}(t);return r.some((function(t){return Fi(t,Qt.decode,e)}))}function Fi(t,e,r){var n=e(t).hashType,i=[];switch(n&Zn.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case Zn.SIGHASH_ALL:break;case Zn.SIGHASH_SINGLE:case Zn.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function Gi(t){var e=t.finalScriptSig&&jt(t.finalScriptSig)||[],r=t.finalScriptWitness&&jt(t.finalScriptWitness)||[];return e.concat(r).filter((function(t){return _i.isBuffer(t)&&$t(t)})).map((function(t){return{signature:t}}))}var ji,Wi=r(287).hp,qi=W;function Xi(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(25)),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Nr((function(){var e=Wi.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),n=Nr((function(){return jt(t.input)})),i=t.network||p,o={name:ji.P2PKH,network:i,hash:void 0};if(Ur(o,"address",(function(){if(o.hash){var t=Wi.allocUnsafe(21);return t.writeUInt8(i.pubKeyHash,0),o.hash.copy(t,1),F.encode(t)}})),Ur(o,"hash",(function(){return t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?Ke(t.pubkey||o.pubkey):void 0})),Ur(o,"output",(function(){if(o.hash)return Gt([qi.OP_DUP,qi.OP_HASH160,o.hash,qi.OP_EQUALVERIFY,qi.OP_CHECKSIG])})),Ur(o,"pubkey",(function(){if(t.input)return n()[1]})),Ur(o,"signature",(function(){if(t.input)return n()[0]})),Ur(o,"input",(function(){if(t.pubkey&&t.signature){var e=t.pubkey;if(t.useHybrid||t.useUncompressed){var r=Ri(t.pubkey);r&&(e=t.useUncompressed?r.uncompressed:r.hybrid)}return Gt([t.signature,e])}})),Ur(o,"witness",(function(){if(o.input)return[]})),e.validate){var u=Wi.from([]);if(t.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");u=r().hash}if(t.hash){if(u.length>0&&!u.equals(t.hash))throw new TypeError("Hash mismatch");u=t.hash}if(t.output){if(25!==t.output.length||t.output[0]!==qi.OP_DUP||t.output[1]!==qi.OP_HASH160||20!==t.output[2]||t.output[23]!==qi.OP_EQUALVERIFY||t.output[24]!==qi.OP_CHECKSIG)throw new TypeError("Output is invalid");var a=t.output.slice(3,23);if(u.length>0&&!u.equals(a))throw new TypeError("Hash mismatch");u=a}if(t.pubkey){var s=Ke(t.pubkey),f=u.length>0&&!u.equals(s);if(f&&(33===t.pubkey.length&&(2===t.pubkey[0]||3===t.pubkey[0])||65===t.pubkey.length&&4===t.pubkey[0])){var c=Ri(t.pubkey);if(c){var h=Ke(c.uncompressed);if(u.equals(h))f=!1,t.useUncompressed=!0;else{var l=Ke(c.hybrid);(f=!u.equals(l))||(t.useHybrid=!0)}}}if(f)throw new TypeError("Hash mismatch");u=s}if(t.input){var d=n();if(2!==d.length)throw new TypeError("Input is invalid");if(!$t(d[0]))throw new TypeError("Input has invalid signature");if(!st(d[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&!t.signature.equals(d[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(d[1]))throw new TypeError("Pubkey mismatch");var y=Ke(d[1]);if(u.length>0&&!u.equals(y))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,t)}!function(t){t.P2PK="p2pk",t.P2PKH="p2pkh",t.P2SH="p2sh",t.P2MS="p2ms",t.P2WPKH="p2wpkh",t.P2WSH="p2wsh",t.P2TR="p2tr",t.P2OP="p2op",t.Embed="embed",t.ScriptRedeem="scriptRedeem"}(ji||(ji={}));var Yi=r(287).hp,zi=r(287).hp;function $i(t){return $i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$i(t)}function Ji(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Zi(n.key),n)}}function Qi(t,e,r){return(e=Zi(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Zi(t){var e=function(t){if("object"!=$i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=$i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$i(e)?e:e+""}var to=it,eo=new TypeError("Cannot compute merkle root for zero transactions"),ro=new TypeError("Cannot compute witness commit for non-segwit block"),no=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Qi(this,"version",1),Qi(this,"prevHash",void 0),Qi(this,"merkleRoot",void 0),Qi(this,"timestamp",0),Qi(this,"witnessCommit",void 0),Qi(this,"bits",0),Qi(this,"nonce",0),Qi(this,"transactions",void 0)}return e=t,r=[{key:"getWitnessCommit",value:function(){if(!io(this.transactions))return null;var t=this.transactions[0].outs.filter((function(t){return t.script.slice(0,6).equals(zi.from("6a24aa21a9ed","hex"))})).map((function(t){return t.script.slice(6,38)}));if(0===t.length)return null;var e=t[t.length-1];return e instanceof zi&&32===e.length?e:null}},{key:"hasWitnessCommit",value:function(){return this.witnessCommit instanceof zi&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}},{key:"hasWitness",value:function(){return(t=this.transactions)instanceof Array&&t.some((function(t){return"object"===$i(t)&&t.ins instanceof Array&&t.ins.some((function(t){return"object"===$i(t)&&t.witness instanceof Array&&t.witness.length>0}))}));var t}},{key:"weight",value:function(){return 3*this.byteLength(!1,!1)+this.byteLength(!1,!0)}},{key:"byteLength",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t||!this.transactions?80:80+nr(this.transactions.length)+this.transactions.reduce((function(t,r){return t+r.byteLength(e)}),0)}},{key:"getHash",value:function(){return Me(this.toBuffer(!0))}},{key:"getId",value:function(){return dr(this.getHash()).toString("hex")}},{key:"getUTCDate",value:function(){var t=new Date(0);return t.setUTCSeconds(this.timestamp),t}},{key:"toBuffer",value:function(t){var e=zi.allocUnsafe(this.byteLength(t)),r=new gr(e);if(r.writeInt32(this.version),r.writeSlice(this.prevHash),r.writeSlice(this.merkleRoot),r.writeUInt32(this.timestamp),r.writeUInt32(this.bits),r.writeUInt32(this.nonce),t||!this.transactions)return e;var n=er(this.transactions.length,e,r.offset);return r.offset+=n.bytes,this.transactions.forEach((function(t){var n=t.byteLength();t.toBuffer(e,r.offset),r.offset+=n})),e}},{key:"toHex",value:function(t){return this.toBuffer(t).toString("hex")}},{key:"checkTxRoots",value:function(){var t=this.hasWitnessCommit();return!(!t&&this.hasWitness())&&this.__checkMerkleRoot()&&(!t||this.__checkWitnessCommit())}},{key:"checkProofOfWork",value:function(){var e=dr(this.getHash()),r=t.calculateTarget(this.bits);return e.compare(r)<=0}},{key:"__checkMerkleRoot",value:function(){if(!this.transactions)throw eo;var e=t.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}},{key:"__checkWitnessCommit",value:function(){if(!this.transactions)throw eo;if(!this.hasWitnessCommit())throw ro;var e=t.calculateMerkleRoot(this.transactions,!0);return 0===this.witnessCommit.compare(e)}}],n=[{key:"fromBuffer",value:function(e){if(e.length<80)throw new Error("Buffer too small (< 80 bytes)");var r=new wr(e),n=new t;if(n.version=r.readInt32(),n.prevHash=r.readSlice(32),n.merkleRoot=r.readSlice(32),n.timestamp=r.readUInt32(),n.bits=r.readUInt32(),n.nonce=r.readUInt32(),80===e.length)return n;var i=function(){var t=Zn.fromBuffer(r.buffer.slice(r.offset),!0);return r.offset+=t.byteLength(),t},o=r.readVarInt();n.transactions=[];for(var u=0;u<o;++u){var a=i();n.transactions.push(a)}var s=n.getWitnessCommit();return s&&(n.witnessCommit=s),n}},{key:"fromHex",value:function(e){return t.fromBuffer(zi.from(e,"hex"))}},{key:"calculateTarget",value:function(t){var e=((4278190080&t)>>24)-3,r=8388607&t,n=zi.alloc(32,0);return n.writeUIntBE(r,29-e,3),n}},{key:"calculateMerkleRoot",value:function(t,e){if(to([{getHash:Tt}],t),0===t.length)throw eo;if(e&&!io(t))throw ro;var r=function(t,e){if(!Array.isArray(t))throw TypeError("Expected values Array");if("function"!=typeof e)throw TypeError("Expected digest Function");for(var r=t.length,n=t.concat();r>1;){for(var i=0,o=0;o<r;o+=2,++i){var u=n[o],a=o+1===r?u:n[o+1],s=Yi.concat([u,a]);n[i]=e(s)}r=i}return n[0]}(t.map((function(t){return t.getHash(e)})),Me);return e?Me(zi.concat([r,t[0].ins[0].witness[0]])):r}}],r&&Ji(e.prototype,r),n&&Ji(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function io(t){return t instanceof Array&&t[0]&&t[0].ins&&t[0].ins instanceof Array&&t[0].ins[0]&&t[0].ins[0].witness&&t[0].ins[0].witness instanceof Array&&t[0].ins[0].witness.length>0}var oo=r(614),uo=r(699),ao=r(287).hp;function so(t){return so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},so(t)}function fo(){fo=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function s(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(e,r,n,i){var o=r&&r.prototype instanceof p?r:p,u=Object.create(o.prototype);return s(u,"_invoke",function(e,r,n){var i=1;return function(o,u){if(3===i)throw Error("Generator is already running");if(4===i){if("throw"===o)throw u;return{value:t,done:!0}}for(n.method=o,n.arg=u;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===i)throw i=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=3;var f=c(e,r,n);if("normal"===f.type){if(i=n.done?4:2,f.arg===h)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(i=4,n.method="throw",n.arg=f.arg)}}}(e,n,new T(i||[])),!0),u}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h={};function p(){}function l(){}function d(){}var y={};s(y,o,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(_([])));w&&w!==r&&n.call(w,o)&&(y=w);var v=d.prototype=p.prototype=Object.create(y);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(i,o,u,a){var s=c(t[i],t,o);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==so(h)&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(h).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,a)}))}a(s.arg)}var i;s(this,"_invoke",(function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}),!0)}function E(e,r){var n=r.method,i=e.i[n];if(i===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,E(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=c(i,e.i,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,h;var u=o.arg;return u?u.done?(r[e.r]=u.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,h):u:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function S(t){this.tryEntries.push(t)}function I(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function T(t){this.tryEntries=[[-1]],t.forEach(S,this),this.reset(!0)}function _(e){if(null!=e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,u=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return u.next=u}}throw new TypeError(so(e)+" is not iterable")}return l.prototype=d,s(v,"constructor",d),s(d,"constructor",l),l.displayName=s(d,a,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,a,"GeneratorFunction")),t.prototype=Object.create(v),t},e.awrap=function(t){return{__await:t}},m(b.prototype),s(b.prototype,u,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new b(f(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},m(v),s(v,a,"Generator"),s(v,o,(function(){return this})),s(v,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},e.values=_,T.prototype={constructor:T,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){u.type="throw",u.arg=e,r.next=t}for(var i=r.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o[4],a=this.prev,s=o[1],f=o[2];if(-1===o[0])return n("end"),!1;if(!s&&!f)throw Error("try statement without catch or finally");if(null!=o[0]&&o[0]<=a){if(a<s)return this.method="next",this.arg=t,n(s),!0;if(a<f)return n(f),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var i=n;break}}i&&("break"===t||"continue"===t)&&i[0]<=e&&e<=i[2]&&(i=null);var o=i?i[4]:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i[2],h):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),I(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var i=n.arg;I(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:_(e),r,n},"next"===this.method&&(this.arg=t),h}},e}function co(t,e,r,n,i,o,u){try{var a=t[o](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,i)}function ho(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){co(o,n,i,u,a,"next",t)}function a(t){co(o,n,i,u,a,"throw",t)}u(void 0)}))}}function po(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=yo(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){a=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(a)throw o}}}}function lo(t){return function(t){if(Array.isArray(t))return go(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||yo(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function yo(t,e){if(t){if("string"==typeof t)return go(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?go(t,e):void 0}}function go(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function wo(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function vo(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,bo(n.key),n)}}function mo(t,e,r){return e&&vo(t.prototype,e),r&&vo(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function bo(t){var e=function(t){if("object"!=so(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=so(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==so(e)?e:e+""}var Eo={network:p,maximumFeeRate:5e3},So=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new oo.i(new To);wo(this,t),this.data=r,this.opts=Object.assign({},Eo,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},0===this.data.inputs.length&&this.setVersion(2);var n=function(t,e,r,n){Object.defineProperty(t,e,{enumerable:r,writable:n})};n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}return mo(t,[{key:"inputCount",get:function(){return this.data.inputs.length}},{key:"version",get:function(){return this.__CACHE.__TX.version},set:function(t){this.setVersion(t)}},{key:"locktime",get:function(){return this.__CACHE.__TX.locktime},set:function(t){this.setLocktime(t)}},{key:"txInputs",get:function(){return this.__CACHE.__TX.ins.map((function(t){return{hash:yr(t.hash),index:t.index,sequence:t.sequence}}))}},{key:"txOutputs",get:function(){var t=this;return this.__CACHE.__TX.outs.map((function(e){var r;try{r=de(e.script,t.opts.network)}catch(t){}return{script:yr(e.script),value:e.value,address:r}}))}},{key:"combine",value:function(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=this.data).combine.apply(t,lo(r.map((function(t){return t.data})))),this}},{key:"clone",value:function(){return t.fromBuffer(this.data.toBuffer(),JSON.parse(JSON.stringify(this.opts)))}},{key:"setMaximumFeeRate",value:function(t){Po(t),this.opts.maximumFeeRate=t}},{key:"setVersion",value:function(t){Po(t),Uo(this.data.inputs,"setVersion");var e=this.__CACHE;return e.__TX.version=t,e.__EXTRACTED_TX=void 0,this}},{key:"setLocktime",value:function(t){Po(t),Uo(this.data.inputs,"setLocktime");var e=this.__CACHE;return e.__TX.locktime=t,e.__EXTRACTED_TX=void 0,this}},{key:"setInputSequence",value:function(t,e){Po(e),Uo(this.data.inputs,"setInputSequence");var r=this.__CACHE;if(r.__TX.ins.length<=t)throw new Error("Input index too high");return r.__TX.ins[t].sequence=e,r.__EXTRACTED_TX=void 0,this}},{key:"addInputs",value:function(t){var e=this,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t.forEach((function(t){return e.addInput(t,r)})),this}},{key:"addInput",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!t||void 0===t.hash||void 0===t.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");si(t,t,"addInput"),e&&Uo(this.data.inputs,"addInput"),t.witnessScript&&tu(t.witnessScript);var r=this.__CACHE;this.data.addInput(t),xo(r,r.__TX.ins[r.__TX.ins.length-1]);var n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&Xo(this.__CACHE,i,n),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}},{key:"addOutputs",value:function(t){var e=this;return t.forEach((function(t){return e.addOutput(t)})),this}},{key:"addOutput",value:function(t){if(arguments.length>1||!t||void 0===t.value||void 0===t.address&&void 0===t.script)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");Uo(this.data.inputs,"addOutput");var e=t.address;if("string"==typeof e){var r=ye(e,this.opts.network);t=Object.assign({},t,{script:r})}fi(t,t,"addOutput");var n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}},{key:"extractTransaction",value:function(t,e){if(e&&(this.data.inputs=this.data.inputs.filter((function(t){return!t.partialSig}))),!this.data.inputs.every(Ao))throw new Error("Not finalized");var r=this.__CACHE;if(t||function(t,e,r){var n=e.__FEE_RATE||t.getFeeRate(),i=e.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error("Warning: You are paying around ".concat((o/1e8).toFixed(8)," in ")+"fees, which is ".concat(n," satoshi per byte for a transaction ")+"with a VSize of ".concat(i," bytes (segwit counted as 0.25 byte per ")+"byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.")}(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;var n=r.__TX.clone();return Yo(this.data.inputs,n,r,!0,e),n}},{key:"getFeeRate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Ro("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE,t)}},{key:"getFee",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Ro("__FEE","fee",this.data.inputs,this.__CACHE,t)}},{key:"finalizeAllInputs",value:function(){var t=this;return(0,uo.checkForInput)(this.data.inputs,0),ru(this.data.inputs.length).forEach((function(e){return t.finalizeInput(e)})),this}},{key:"finalizeInput",value:function(t,e,r){var n=(0,uo.checkForInput)(this.data.inputs,t);return ui(n)?this._finalizeTaprootInput(t,n,void 0,e):this._finalizeInput(t,n,e,null==r||r)}},{key:"finalizeTaprootInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ii,n=(0,uo.checkForInput)(this.data.inputs,t);if(ui(n))return this._finalizeTaprootInput(t,n,e,r);throw new Error("Cannot finalize input #".concat(t,". Not Taproot."))}},{key:"getInputType",value:function(t){var e=(0,uo.checkForInput)(this.data.inputs,t),r=Zo($o(t,e,this.__CACHE),t,"input",e.redeemScript||function(t){if(t){var e=jt(t);if(e){var r=e[e.length-1];if(ao.isBuffer(r)&&!Qo(r)&&!$t(r))if(jt(r))return r}}}(e.finalScriptSig),e.witnessScript||function(t){if(t){var e=qo(t),r=e[e.length-1];if(!Qo(r)&&jt(r))return r}}(e.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+eu(r.meaningfulScript)}},{key:"inputHasPubkey",value:function(t,e){return function(t,e,r,n){return Ki(t,Zo($o(r,e,n),r,"input",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,uo.checkForInput)(this.data.inputs,t),t,this.__CACHE)}},{key:"inputHasHDKey",value:function(t,e){var r=(0,uo.checkForInput)(this.data.inputs,t),n=Oo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"outputHasPubkey",value:function(t,e){return function(t,e,r,n){return Ki(t,Zo(n.__TX.outs[r].script,r,"output",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,uo.checkForOutput)(this.data.outputs,t),t,this.__CACHE)}},{key:"outputHasHDKey",value:function(t,e){var r=(0,uo.checkForOutput)(this.data.outputs,t),n=Oo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"validateSignaturesOfAllInputs",value:function(t){var e=this;return(0,uo.checkForInput)(this.data.inputs,0),ru(this.data.inputs.length).map((function(r){return e.validateSignaturesOfInput(r,t)})).reduce((function(t,e){return!0===e&&t}),!0)}},{key:"validateSignaturesOfInput",value:function(t,e,r){return ui(this.data.inputs[t])?this.validateSignaturesOfTaprootInput(t,e,r):this._validateSignaturesOfInput(t,e,r)}},{key:"signAllInputsHD",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[Zn.SIGHASH_ALL];if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");var r,n=[],i=po(ru(this.data.inputs.length));try{for(i.s();!(r=i.n()).done;){var o=r.value;try{this.signInputHD(o,t,e),n.push(!0)}catch(t){n.push(!1)}}}catch(t){i.e(t)}finally{i.f()}if(n.every((function(t){return!1===t})))throw new Error("No inputs were signed");return this}},{key:"signAllInputsHDAsync",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[Zn.SIGHASH_ALL];return new Promise((function(n,i){if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));var o,u=[],a=[],s=po(ru(e.data.inputs.length));try{for(s.s();!(o=s.n()).done;){var f=o.value;a.push(e.signInputHDAsync(f,t,r).then((function(){u.push(!0)}),(function(){u.push(!1)})))}}catch(t){s.e(t)}finally{s.f()}return Promise.all(a).then((function(){if(u.every((function(t){return!1===t})))return i(new Error("No inputs were signed"));n()}))}))}},{key:"signInputHD",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL];if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");return Wo(t,this.data.inputs,e).forEach((function(e){return r.signInput(t,e,n)})),this}},{key:"signInputHDAsync",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL];return new Promise((function(i,o){if(!e||!e.publicKey||!e.fingerprint)return o(new Error("Need HDSigner to sign input"));var u=Wo(t,r.data.inputs,e).map((function(e){return r.signInputAsync(t,e,n)}));return Promise.all(u).then((function(){i()})).catch(o)}))}},{key:"signAllInputs",value:function(t,e){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");var r,n=[],i=po(ru(this.data.inputs.length));try{for(i.s();!(r=i.n()).done;){var o=r.value;try{this.signInput(o,t,e),n.push(!0)}catch(t){n.push(!1)}}}catch(t){i.e(t)}finally{i.f()}if(n.every((function(t){return!1===t})))throw new Error("No inputs were signed");return this}},{key:"signAllInputsAsync",value:function(t,e){var r=this;return new Promise((function(n,i){if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));var o,u,a,s=[],f=[],c=po(r.data.inputs.entries());try{for(c.s();!(o=c.n()).done;){var h=(u=o.value,a=1,function(t){if(Array.isArray(t))return t}(u)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,u,a=[],s=!0,f=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=o.call(r)).done)&&(a.push(n.value),a.length!==e);s=!0);}catch(t){f=!0,i=t}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(f)throw i}}return a}}(u,a)||yo(u,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0];f.push(r.signInputAsync(h,t,e).then((function(){s.push(!0)}),(function(){s.push(!1)})))}}catch(t){c.e(t)}finally{c.f()}return Promise.all(f).then((function(){if(s.every((function(t){return!1===t})))return i(new Error("No inputs were signed"));n()}))}))}},{key:"signInput",value:function(t,e,r){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var n=(0,uo.checkForInput)(this.data.inputs,t);return ui(n)?this._signTaprootInput(t,n,e,void 0,r):this._signInput(t,e,r)}},{key:"signTaprootInput",value:function(t,e,r,n){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var i=(0,uo.checkForInput)(this.data.inputs,t);if(ui(i))return this._signTaprootInput(t,i,e,r,n);throw new Error("Input #".concat(t," is not of type Taproot."))}},{key:"signInputAsync",value:function(t,e,r){var n=this;return Promise.resolve().then((function(){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var i=(0,uo.checkForInput)(n.data.inputs,t);return ui(i)?n._signTaprootInputAsync(t,i,e,void 0,r):n._signInputAsync(t,e,r)}))}},{key:"signTaprootInputAsync",value:function(t,e,r,n){var i=this;return Promise.resolve().then((function(){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var o=(0,uo.checkForInput)(i.data.inputs,t);if(ui(o))return i._signTaprootInputAsync(t,o,e,r,n);throw new Error("Input #".concat(t," is not of type Taproot."))}))}},{key:"toBuffer",value:function(){return _o(this.__CACHE),this.data.toBuffer()}},{key:"toHex",value:function(){return _o(this.__CACHE),this.data.toHex()}},{key:"toBase64",value:function(){return _o(this.__CACHE),this.data.toBase64()}},{key:"updateGlobal",value:function(t){return this.data.updateGlobal(t),this}},{key:"updateInput",value:function(t,e){return e.witnessScript&&tu(e.witnessScript),si(this.data.inputs[t],e,"updateInput"),this.data.updateInput(t,e),e.nonWitnessUtxo&&Xo(this.__CACHE,this.data.inputs[t],t),this}},{key:"updateOutput",value:function(t,e){return fi(this.data.outputs[t],e,"updateOutput"),this.data.updateOutput(t,e),this}},{key:"addUnknownKeyValToGlobal",value:function(t){return this.data.addUnknownKeyValToGlobal(t),this}},{key:"addUnknownKeyValToInput",value:function(t,e){return this.data.addUnknownKeyValToInput(t,e),this}},{key:"addUnknownKeyValToOutput",value:function(t,e){return this.data.addUnknownKeyValToOutput(t,e),this}},{key:"clearFinalizedInput",value:function(t){return this.data.clearFinalizedInput(t),this}},{key:"checkTaprootHashesForSig",value:function(t,e,r,n,i){if("function"!=typeof r.signSchnorr)throw new Error("Need Schnorr Signer to sign taproot input #".concat(t,"."));var o=Go(t,e,this.data.inputs,r.publicKey,this.__CACHE,n,i);if(!o||!o.length)throw new Error("Can not sign for input #".concat(t," with the key ").concat(r.publicKey.toString("hex")));return o}},{key:"_finalizeInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Lo,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=function(t,e,r){var n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!e.redeemScript,i.isP2WSH=!!e.witnessScript,e.witnessScript)i.script=e.witnessScript;else if(e.redeemScript)i.script=e.redeemScript;else if(e.nonWitnessUtxo){var o=zo(r,e,t),u=n.ins[t].index;i.script=o.outs[u].script}else e.witnessUtxo&&(i.script=e.witnessUtxo.script);return(e.witnessScript||Ui(i.script))&&(i.isSegwit=!0),i}(t,e,this.__CACHE),o=i.script,u=i.isP2SH,a=i.isP2WSH,s=i.isSegwit;if(!o)throw new Error("No script found for input #".concat(t));!function(t){if(t.sighashType&&t.partialSig){var e=t.partialSig,r=t.sighashType;e.forEach((function(t){var e=Qt.decode(t.signature).hashType;if(r!==e)throw new Error("Signature sighash does not match input sighash type")}))}}(e);var f=r(t,e,o,s,u,a,n),c=f.finalScriptSig,h=f.finalScriptWitness;if(c&&this.data.updateInput(t,{finalScriptSig:c}),h&&this.data.updateInput(t,{finalScriptWitness:h}),!c&&!h)throw new Error("Unknown error finalizing input #".concat(t));return this.data.clearFinalizedInput(t),this}},{key:"_finalizeTaprootInput",value:function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ii;if(!e.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing witness utxo."));if(e.tapKeySig){var i=Hi(Un({output:e.witnessUtxo.script,signature:e.tapKeySig}).witness);this.data.updateInput(t,{finalScriptWitness:i})}else{var o=n(t,e,r).finalScriptWitness;this.data.updateInput(t,{finalScriptWitness:o})}return this.data.clearFinalizedInput(t),this}},{key:"_validateSignaturesOfInput",value:function(t,e,r){var n=this.data.inputs[t],i=(n||{}).partialSig;if(!n||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof e)throw new Error("Need validator function to validate signatures");var o=r?i.filter((function(t){return t.pubkey.equals(r)})):i;if(o.length<1)throw new Error("No signatures for this pubkey");var u,a,s,f,c=[],h=po(o);try{for(h.s();!(f=h.n()).done;){var p=f.value,l=Qt.decode(p.signature),d=s!==l.hashType?Ko(t,Object.assign({},n,{sighashType:l.hashType}),this.__CACHE,!0):{hash:u,script:a},y=d.hash,g=d.script;s=l.hashType,u=y,a=g,No(p.pubkey,g,"verify"),c.push(e(p.pubkey,y,l.signature))}}catch(t){h.e(t)}finally{h.f()}return c.every((function(t){return!0===t}))}},{key:"validateSignaturesOfTaprootInput",value:function(t,e,r){var n=this.data.inputs[t],i=(n||{}).tapKeySig,o=(n||{}).tapScriptSig;if(!n&&!i&&(!o||o.length))throw new Error("No signatures to validate");if("function"!=typeof e)throw new Error("Need validator function to validate signatures");var u=(r=r&&ni(r))?Go(t,n,this.data.inputs,r,this.__CACHE):function(t,e,r,n){var i=[];if(e.tapInternalKey){var o=Mo(t,e,n);o&&i.push(o)}if(e.tapScriptSig){var u=e.tapScriptSig.map((function(t){return t.pubkey}));i.push.apply(i,lo(u))}return i.map((function(i){return Go(t,e,r,i,n)})).flat()}(t,n,this.data.inputs,this.__CACHE);if(!u.length)throw new Error("No signatures for this pubkey");var a=u.find((function(t){return!t.leafHash})),s=0;if(i&&a){if(!e(a.pubkey,a.hash,Fo(i)))return!1;s++}if(o){var f,c=po(o);try{var h,p=function(){var t=f.value,r=u.find((function(e){return t.pubkey.equals(e.pubkey)}));if(r){if(!e(t.pubkey,r.hash,Fo(t.signature)))return{v:!1};s++}};for(c.s();!(f=c.n()).done;)if(h=p())return h.v}catch(t){c.e(t)}finally{c.f()}}return s>0}},{key:"_signInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL],n=Vo(this.data.inputs,t,e.publicKey,this.__CACHE,r),i=n.hash,o=n.sighashType,u=[{pubkey:e.publicKey,signature:Qt.encode(e.sign(i),o)}];return this.data.updateInput(t,{partialSig:u}),this}},{key:"_signTaprootInput",value:function(t,e,r,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[Zn.SIGHASH_DEFAULT],o=this.checkTaprootHashesForSig(t,e,r,n,i),u=o.filter((function(t){return!t.leafHash})).map((function(t){return oi(r.signSchnorr(t.hash),e.sighashType)}))[0],a=o.filter((function(t){return!!t.leafHash})).map((function(t){return{pubkey:ni(r.publicKey),signature:oi(r.signSchnorr(t.hash),e.sighashType),leafHash:t.leafHash}}));return u&&this.data.updateInput(t,{tapKeySig:u}),a.length&&this.data.updateInput(t,{tapScriptSig:a}),this}},{key:"_signInputAsync",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL],i=Vo(this.data.inputs,t,e.publicKey,this.__CACHE,n),o=i.hash,u=i.sighashType;return Promise.resolve(e.sign(o)).then((function(n){var i=[{pubkey:e.publicKey,signature:Qt.encode(n,u)}];r.data.updateInput(t,{partialSig:i})}))}},{key:"_signTaprootInputAsync",value:(e=ho(fo().mark((function t(e,r,n,i){var o,u,a,s,f,c,h,p,l,d,y,g=arguments;return fo().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=g.length>4&&void 0!==g[4]?g[4]:[Zn.SIGHASH_DEFAULT],u=this.checkTaprootHashesForSig(e,r,n,i,o),a=[],s=u.filter((function(t){return!t.leafHash}))[0],s&&(f=Promise.resolve(n.signSchnorr(s.hash)).then((function(t){return{tapKeySig:oi(t,r.sighashType)}})),a.push(f)),c=u.filter((function(t){return!!t.leafHash})),c.length&&(h=c.map(function(){var t=ho(fo().mark((function t(e){var i,o;return fo().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.signSchnorr(e.hash);case 2:return i=t.sent,o=[{pubkey:ni(n.publicKey),signature:oi(i,r.sighashType),leafHash:e.leafHash}],t.abrupt("return",{tapScriptSig:o});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),a.push.apply(a,lo(h))),t.next=9,Promise.all(a);case 9:p=t.sent,l=po(p);try{for(l.s();!(d=l.n()).done;)y=d.value,this.data.updateInput(e,y)}catch(t){l.e(t)}finally{l.f()}case 12:case"end":return t.stop()}}),t,this)}))),function(t,r,n,i){return e.apply(this,arguments)})}],[{key:"fromBase64",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=ao.from(t,"base64");return this.fromBuffer(r,e)}},{key:"fromHex",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=ao.from(t,"hex");return this.fromBuffer(r,e)}},{key:"fromBuffer",value:function(e){var r,n,i=new t(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},oo.i.fromBuffer(e,Io));return r=i.__CACHE.__TX,n=i.__CACHE,r.ins.forEach((function(t){xo(n,t)})),i}}]);var e}(),Io=function(t){return new To(t)},To=function(){return mo((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ao.from([2,0,0,0,0,0,0,0,0,0]);wo(this,t),this.tx=Zn.fromBuffer(e),function(t){if(!t.ins.every((function(t){return t.script&&0===t.script.length&&t.witness&&0===t.witness.length})))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}),[{key:"getInputOutputCounts",value:function(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}},{key:"addInput",value:function(t){if(void 0===t.hash||void 0===t.index||!ao.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");var e="string"==typeof t.hash?dr(ao.from(t.hash,"hex")):t.hash;this.tx.addInput(e,t.index,t.sequence)}},{key:"addOutput",value:function(t){if(void 0===t.script||void 0===t.value||!ao.isBuffer(t.script)||"number"!=typeof t.value)throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}},{key:"toBuffer",value:function(){return this.tx.toBuffer()}}])}();function _o(t){if(!1!==t.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function ko(t,e,r){if(!e)return!1;var n;if((n=r?r.map((function(t){var r=function(t){if(65===t.length){var e=1&t[64],r=t.slice(0,33);return r[0]=2|e,r}return t.slice()}(t);return e.find((function(t){return t.pubkey.equals(r)}))})).filter((function(t){return!!t})):e).length>t)throw new Error("Too many signatures");return n.length===t}function Ao(t){return!!t.finalScriptSig||!!t.finalScriptWitness}function Oo(t){return function(e){return!!e.masterFingerprint.equals(t.fingerprint)&&!!t.derivePath(e.path).publicKey.equals(e.pubkey)}}function Po(t){if("number"!=typeof t||t!==Math.floor(t)||t>4294967295||t<0)throw new Error("Invalid 32 bit integer")}function Uo(t,e){t.forEach((function(t){if(ui(t)?li(t,e):Mi(t,e))throw new Error("Can not modify transaction, signatures exist.")}))}function No(t,e,r){if(!Ki(t,e))throw new Error("Can not ".concat(r," for this input with the key ").concat(t.toString("hex")))}function xo(t,e){var r=dr(ao.from(e.hash)).toString("hex")+":"+e.index;if(t.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");t.__TX_IN_CACHE[r]=1}function Bo(t,e){return function(r,n,i,o){var u=t({redeem:{output:i}}).output;if(!n.equals(u))throw new Error("".concat(e," for ").concat(o," #").concat(r," doesn't match the scriptPubKey in the prevout"))}}var Co=Bo(kn,"Redeem script"),Ho=Bo(Vn,"Witness script");function Ro(t,e,r,n){var i,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!r.every(Ao))throw new Error("PSBT must be finalized to calculate ".concat(e));if("__FEE_RATE"===t&&n.__FEE_RATE)return n.__FEE_RATE;if("__FEE"===t&&n.__FEE)return n.__FEE;var u=!0;return n.__EXTRACTED_TX?(i=n.__EXTRACTED_TX,u=!1):i=n.__TX.clone(),Yo(r,i,n,u,o),"__FEE_RATE"===t?n.__FEE_RATE:"__FEE"===t?n.__FEE:void 0}function Lo(t,e,r,n,i,o){var u=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],a=eu(r);if(!function(t,e,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return ko(1,t.partialSig);case"multisig":var n=Rr({output:e});return ko(n.m,t.partialSig,n.pubkeys);case"nonstandard":return!0;default:return!1}}(e,r,a)&&u)throw new Error("Can not finalize input #".concat(t));return Do(r,a,e.partialSig,n,i,o)}function Do(t,e,r,n,i,o){var u,a,s=function(t,e,r){var n;switch(e){case"multisig":var i=function(t,e){return Rr({output:t}).pubkeys.map((function(t){return(e.filter((function(e){return e.pubkey.equals(t)}))[0]||{}).signature})).filter((function(t){return!!t}))}(t,r);n=Rr({output:t,signatures:i});break;case"pubkey":n=Dr({output:t,signature:r[0].signature});break;case"pubkeyhash":n=Xi({output:t,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=Cn({output:t,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(t,e,r),f=o?Vn({redeem:s}):null,c=i?kn({redeem:f||s}):null;return n?(a=Hi(f?f.witness:s.witness),c&&(u=c.input)):u=c?c.input:s.input,{finalScriptSig:u,finalScriptWitness:a}}function Vo(t,e,r,n,i){var o=Ko(e,(0,uo.checkForInput)(t,e),n,!1,i),u=o.hash,a=o.sighashType;return No(r,o.script,"sign"),{hash:u,sighashType:a}}function Ko(t,e,r,n,i){var o,u,a=r.__TX,s=e.sighashType||Zn.SIGHASH_ALL;if(jo(s,i),e.nonWitnessUtxo){var f=zo(r,e,t),c=a.ins[t].hash,h=f.getHash();if(!c.equals(h))throw new Error("Non-witness UTXO hash for input #".concat(t," doesn't match the hash specified in the prevout"));var p=a.ins[t].index;u=f.outs[p]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}var l=Zo(u.script,t,"input",e.redeemScript,e.witnessScript),d=l.meaningfulScript,y=l.type;if(["p2sh-p2wsh","p2wsh"].indexOf(y)>=0)o=a.hashForWitnessV0(t,d,u.value,s);else if(Ui(d)){var g=Xi({hash:d.slice(2)}).output;o=a.hashForWitnessV0(t,g,u.value,s)}else{if(void 0===e.nonWitnessUtxo&&!1===r.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Input #".concat(t," has witnessUtxo but non-segwit script: ")+"".concat(d.toString("hex")));n||!1===r.__UNSAFE_SIGN_NONSEGWIT||console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),o=a.hashForSignature(t,d,s)}return{script:d,sighashType:s,hash:o}}function Mo(t,e,r){var n=Jo(t,e,r).script;return Bi(n)?n.subarray(2,34):null}function Fo(t){return 64===t.length?t:t.subarray(0,64)}function Go(t,e,r,n,i,o,u){var a=i.__TX,s=e.sighashType||Zn.SIGHASH_DEFAULT;jo(s,u);var f=r.map((function(t,e){return Jo(e,t,i)})),c=f.map((function(t){return t.script})),h=f.map((function(t){return t.value})),p=[];if(e.tapInternalKey&&!o){var l=Mo(t,e,i)||ao.from([]);if(ni(n).equals(l)){var d=a.hashForWitnessV1(t,c,h,s);p.push({pubkey:n,hash:d})}}var y=(e.tapLeafScript||[]).filter((function(t){return Ki(n,t.script)})).map((function(t){var e=kr({output:t.script,version:t.leafVersion});return Object.assign({hash:e},t)})).filter((function(t){return!o||o.equals(t.hash)})).map((function(e){var r=a.hashForWitnessV1(t,c,h,s,e.hash);return{pubkey:n,hash:r,leafHash:e.hash}}));return p.concat(y)}function jo(t,e){if(e&&e.indexOf(t)<0){var r=function(t){var e=t&Zn.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&t){case Zn.SIGHASH_ALL:e+="SIGHASH_ALL";break;case Zn.SIGHASH_SINGLE:e+="SIGHASH_SINGLE";break;case Zn.SIGHASH_NONE:e+="SIGHASH_NONE"}return e}(t);throw new Error("Sighash type is not allowed. Retry the sign method passing the "+"sighashTypes array of whitelisted types. Sighash type: ".concat(r))}}function Wo(t,e,r){var n=(0,uo.checkForInput)(e,t);if(!n.bip32Derivation||0===n.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");var i=n.bip32Derivation.map((function(t){return t.masterFingerprint.equals(r.fingerprint)?t:void 0})).filter((function(t){return!!t}));if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map((function(t){var e=r.derivePath(t.path);if(!t.pubkey.equals(e.publicKey))throw new Error("pubkey did not match bip32Derivation");return e}))}function qo(t){var e=0;function r(){var r=In.decode(t,e);return e+=In.decode.bytes,r}return function(){for(var n=r(),i=[],o=0;o<n;o++)i.push((u=void 0,u=r(),e+=u,t.slice(e-u,e)));var u;return i}()}function Xo(t,e,r){t.__NON_WITNESS_UTXO_BUF_CACHE[r]=e.nonWitnessUtxo,t.__NON_WITNESS_UTXO_TX_CACHE[r]=Zn.fromBuffer(e.nonWitnessUtxo);var n=t,i=r;delete e.nonWitnessUtxo,Object.defineProperty(e,"nonWitnessUtxo",{enumerable:!0,get:function(){var t=n.__NON_WITNESS_UTXO_BUF_CACHE[i],e=n.__NON_WITNESS_UTXO_TX_CACHE[i];if(void 0!==t)return t;var r=e.toBuffer();return n.__NON_WITNESS_UTXO_BUF_CACHE[i]=r,r},set:function(t){n.__NON_WITNESS_UTXO_BUF_CACHE[i]=t}})}function Yo(t,e,r,n,i){var o=0;t.forEach((function(t,i){if(n&&t.finalScriptSig&&(e.ins[i].script=t.finalScriptSig),n&&t.finalScriptWitness&&(e.ins[i].witness=qo(t.finalScriptWitness)),t.witnessUtxo)o+=t.witnessUtxo.value;else if(t.nonWitnessUtxo){var u=zo(r,t,i),a=e.ins[i].index,s=u.outs[a];o+=s.value}}));var u=e.outs.reduce((function(t,e){return t+e.value}),0),a=o-u;if(!i&&a<0)throw new Error("Outputs are spending more than Inputs");var s=e.virtualSize();r.__FEE=a,r.__EXTRACTED_TX=e,r.__FEE_RATE=Math.floor(a/s)}function zo(t,e,r){var n=t.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||Xo(t,e,r),n[r]}function $o(t,e,r){return Jo(t,e,r).script}function Jo(t,e,r){if(void 0!==e.witnessUtxo)return{script:e.witnessUtxo.script,value:e.witnessUtxo.value};if(void 0!==e.nonWitnessUtxo){var n=zo(r,e,t).outs[r.__TX.ins[t].index];return{script:n.script,value:n.value}}throw new Error("Can't find pubkey in input without Utxo data")}function Qo(t){return 33===t.length&&Yt(t)}function Zo(t,e,r,n,i){var o,u=xi(t),a=u&&n&&Ni(n),s=Ni(t);if(u&&void 0===n)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((s||a)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");return a?(o=i,Co(e,t,n,r),Ho(e,n,i,r),tu(o)):s?(o=i,Ho(e,t,i,r),tu(o)):u?(o=n,Co(e,t,n,r)):o=t,{meaningfulScript:o,type:a?"p2sh-p2wsh":u?"p2sh":s?"p2wsh":"raw"}}function tu(t){if(Ui(t)||xi(t))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function eu(t){return Ui(t)?"witnesspubkeyhash":Pi(t)?"pubkeyhash":Ai(t)?"multisig":Oi(t)?"pubkey":"nonstandard"}function ru(t){return lo(Array(t).keys())}const nu={networks:n,address:a,payments:h,script:u,crypto:s,Transaction:c};export{no as Block,wr as BufferReader,gr as BufferWriter,br as LEAF_VERSION_TAPSCRIPT,Er as MAX_TAPTREE_DEPTH,ji as PaymentType,So as Psbt,Ge as TAGGED_HASH_PREFIXES,Fe as TAGS,ct as TAPLEAF_VERSION_MASK,Zn as Transaction,a as address,Li as bigIntTo32Bytes,Mi as checkInputForSig,si as checkTaprootInputFields,li as checkTaprootInputForSigs,fi as checkTaprootOutputFields,yr as cloneBuffer,s as crypto,Ri as decompressPublicKey,nu as default,_r as findScriptPath,ce as fromBase58Check,he as fromBech32,de as fromOutputScript,Lo as getFinalScripts,Gi as getPsigsFromInputFinalScripts,yi as getTapKeySigFromWitness,Ke as hash160,Me as hash256,Xe as initEccLib,Ai as isP2MS,Ci as isP2OP,Oi as isP2PK,Pi as isP2PKH,xi as isP2SHScript,Bi as isP2TR,Ui as isP2WPKH,Ni as isP2WSHScript,ui as isTaprootInput,ai as isTaprootOutput,n as networks,W as opcodes,h as payments,Do as prepareFinalScripts,Ki as pubkeyInScript,Vi as pubkeyPositionInScript,Di as pubkeysMatch,pr as readUInt64LE,dr as reverseBuffer,Le as ripemd160,Ir as rootHashFromPath,u as script,oi as serializeTaprootSignature,De as sha1,Ve as sha256,Fi as signatureBlocksAction,je as taggedHash,ii as tapScriptFinalizer,pi as tapTreeFromList,hi as tapTreeToList,Ar as tapTweakHash,kr as tapleafHash,pe as toBase58Check,le as toBech32,fe as toFutureOPNetAddress,Tr as toHashTree,ye as toOutputScript,ni as toXOnly,ci as tweakInternalPubKey,Or as tweakKey,f as varuint,Hi as witnessStackToScriptWitness,lr as writeUInt64LE};
|
|
2
|
+
var t={34:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+t.key.toString("hex"));if(65!==t.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+t.key.toString("hex"));if(64!==t.value.length&&65!==t.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1,33),leafHash:t.key.slice(33),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_SCRIPT_SIG]);return{key:n.concat([e,t.pubkey,t.leafHash]),value:t.signature}},e.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.leafHash)&&n.isBuffer(t.signature)&&32===t.pubkey.length&&32===t.leafHash.length&&(64===t.signature.length||65===t.signature.length)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex")+e.leafHash.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey)&&t.leafHash.equals(e.leafHash))).length)}},61:(t,e,r)=>{var n=r(113);function i(t){return t.name||t.toString().match(/function (.*?)\s*\(/)[1]}function o(t){return n.Nil(t)?"":i(t.constructor)}function u(t,e){Error.captureStackTrace&&Error.captureStackTrace(t,e)}function a(t){return n.Function(t)?t.toJSON?t.toJSON():i(t):n.Array(t)?"Array":t&&n.Object(t)?"Object":void 0!==t?t:""}function s(t,e,r){var i=function(t){return n.Function(t)?"":n.String(t)?JSON.stringify(t):t&&n.Object(t)?"":t}(e);return"Expected "+a(t)+", got"+(""!==r?" "+r:"")+(""!==i?" "+i:"")}function f(t,e,r){r=r||o(e),this.message=s(t,e,r),u(this,f),this.__type=t,this.__value=e,this.__valueTypeName=r}function c(t,e,r,n,i){t?(i=i||o(n),this.message=function(t,e,r,n,i){var o='" of type ';return"key"===e&&(o='" with key type '),s('property "'+a(r)+o+a(t),n,i)}(t,r,e,n,i)):this.message='Unexpected property "'+e+'"',u(this,f),this.__label=r,this.__property=e,this.__type=t,this.__value=n,this.__valueTypeName=i}f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,c.prototype=Object.create(Error.prototype),c.prototype.constructor=f,t.exports={TfTypeError:f,TfPropertyTypeError:c,tfCustomError:function(t,e){return new f(t,{},e)},tfSubError:function(t,e,r){return t instanceof c?(e=e+"."+t.__property,t=new c(t.__type,e,t.__label,t.__value,t.__valueTypeName)):t instanceof f&&(t=new c(t.__type,e,r,t.__value,t.__valueTypeName)),u(t),t},tfJSON:a,getValueTypeName:o}},80:(t,e)=>{var r,n,i;Object.defineProperty(e,"__esModule",{value:!0}),(i=e.GlobalTypes||(e.GlobalTypes={}))[i.UNSIGNED_TX=0]="UNSIGNED_TX",i[i.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(n=e.InputTypes||(e.InputTypes={}))[n.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",n[n.WITNESS_UTXO=1]="WITNESS_UTXO",n[n.PARTIAL_SIG=2]="PARTIAL_SIG",n[n.SIGHASH_TYPE=3]="SIGHASH_TYPE",n[n.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",n[n.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",n[n.BIP32_DERIVATION=6]="BIP32_DERIVATION",n[n.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",n[n.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",n[n.POR_COMMITMENT=9]="POR_COMMITMENT",n[n.TAP_KEY_SIG=19]="TAP_KEY_SIG",n[n.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",n[n.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",n[n.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",n[n.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",n[n.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT",e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(r=e.OutputTypes||(e.OutputTypes={}))[r.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",r[r.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",r[r.BIP32_DERIVATION=2]="BIP32_DERIVATION",r[r.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",r[r.TAP_TREE=6]="TAP_TREE",r[r.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION",e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]},113:t=>{var e={Array:function(t){return null!=t&&t.constructor===Array},Boolean:function(t){return"boolean"==typeof t},Function:function(t){return"function"==typeof t},Nil:function(t){return null==t},Number:function(t){return"number"==typeof t},Object:function(t){return"object"==typeof t},String:function(t){return"string"==typeof t},"":function(){return!0}};for(var r in e.Null=e.Nil,e)e[r].toJSON=function(t){return t}.bind(null,r);t.exports=e},133:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394);function o(t){const e=t.key.length,r=t.value.length,o=i.encodingLength(e),u=i.encodingLength(r),a=n.allocUnsafe(o+e+u+r);return i.encode(e,a,0),t.key.copy(a,o),i.encode(r,a,o+e),t.value.copy(a,o+e+u),a}function u(t,e){if("number"!=typeof t)throw new Error("cannot write a non-number as a number");if(t<0)throw new Error("specified a negative value for writing an unsigned value");if(t>e)throw new Error("RangeError: value out of range");if(Math.floor(t)!==t)throw new Error("value has a fractional component")}e.range=t=>[...Array(t).keys()],e.reverseBuffer=function(t){if(t.length<1)return t;let e=t.length-1,r=0;for(let n=0;n<t.length/2;n++)r=t[n],t[n]=t[e],t[e]=r,e--;return t},e.keyValsToBuffer=function(t){const e=t.map(o);return e.push(n.from([0])),n.concat(e)},e.keyValToBuffer=o,e.readUInt64LE=function(t,e){const r=t.readUInt32LE(e);let n=t.readUInt32LE(e+4);return n*=4294967296,u(n+r,9007199254740991),n+r},e.writeUInt64LE=function(t,e,r){return u(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}},213:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.encode=function(t){return{key:n.from([i.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}}},223:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t||1!==e.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+e.key.toString("hex"));if(32!==e.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)&&32===t.length},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.tapInternalKey}}}},238:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133);e.psbtToBuffer=function({globalMap:t,inputs:e,outputs:r}){const{globalKeyVals:i,inputKeyVals:u,outputKeyVals:a}=s({globalMap:t,inputs:e,outputs:r}),f=o.keyValsToBuffer(i),c=t=>0===t.length?[n.from([0])]:t.map(o.keyValsToBuffer),h=c(u),p=c(a),l=n.allocUnsafe(5);return l.writeUIntBE(482972169471,0,5),n.concat([l,f].concat(h,p))};const u=(t,e)=>t.key.compare(e.key);function a(t,e){const r=new Set,n=Object.entries(t).reduce(((t,[n,i])=>{if("unknownKeyVals"===n)return t;const o=e[n];if(void 0===o)return t;const u=(Array.isArray(i)?i:[i]).map(o.encode);return u.map((t=>t.key.toString("hex"))).forEach((t=>{if(r.has(t))throw new Error("Serialize Error: Duplicate key: "+t);r.add(t)})),t.concat(u)}),[]),i=t.unknownKeyVals?t.unknownKeyVals.filter((t=>!r.has(t.key.toString("hex")))):[];return n.concat(i).sort(u)}function s({globalMap:t,inputs:e,outputs:r}){return{globalKeyVals:a(t,i.globals),inputKeyVals:e.map((t=>a(t,i.inputs))),outputKeyVals:r.map((t=>a(t,i.outputs)))}}e.psbtToKeyVals=s},251:(t,e)=>{e.read=function(t,e,r,n,i){var o,u,a=8*i-n-1,s=(1<<a)-1,f=s>>1,c=-7,h=r?i-1:0,p=r?-1:1,l=t[e+h];for(h+=p,o=l&(1<<-c)-1,l>>=-c,c+=a;c>0;o=256*o+t[e+h],h+=p,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=p,c-=8);if(0===o)o=1-f;else{if(o===s)return u?NaN:1/0*(l?-1:1);u+=Math.pow(2,n),o-=f}return(l?-1:1)*u*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var u,a,s,f=8*o-i-1,c=(1<<f)-1,h=c>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,u=c):(u=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-u))<1&&(u--,s*=2),(e+=u+h>=1?p/s:p*Math.pow(2,1-h))*s>=2&&(u++,s/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(e*s-1)*Math.pow(2,i),u+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),u=0));i>=8;t[r+l]=255&a,l+=d,a/=256,i-=8);for(u=u<<i|a,f+=i;f>0;t[r+l]=255&u,l+=d,u/=256,f-=8);t[r+l-d]|=128*y}},263:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133),u=r(394),a=r(80);function s(t,e,r){if(!e.equals(n.from([r])))throw new Error(`Format Error: Invalid ${t} key: ${e.toString("hex")}`)}function f(t,{globalMapKeyVals:e,inputKeyVals:r,outputKeyVals:n}){const u={unsignedTx:t};let f=0;for(const t of e)switch(t.key[0]){case a.GlobalTypes.UNSIGNED_TX:if(s("global",t.key,a.GlobalTypes.UNSIGNED_TX),f>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");f++;break;case a.GlobalTypes.GLOBAL_XPUB:void 0===u.globalXpub&&(u.globalXpub=[]),u.globalXpub.push(i.globals.globalXpub.decode(t));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(t)}const c=r.length,h=n.length,p=[],l=[];for(const t of o.range(c)){const e={};for(const n of r[t])switch(i.inputs.checkPubkey(n),n.key[0]){case a.InputTypes.NON_WITNESS_UTXO:if(s("input",n.key,a.InputTypes.NON_WITNESS_UTXO),void 0!==e.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");e.nonWitnessUtxo=i.inputs.nonWitnessUtxo.decode(n);break;case a.InputTypes.WITNESS_UTXO:if(s("input",n.key,a.InputTypes.WITNESS_UTXO),void 0!==e.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");e.witnessUtxo=i.inputs.witnessUtxo.decode(n);break;case a.InputTypes.PARTIAL_SIG:void 0===e.partialSig&&(e.partialSig=[]),e.partialSig.push(i.inputs.partialSig.decode(n));break;case a.InputTypes.SIGHASH_TYPE:if(s("input",n.key,a.InputTypes.SIGHASH_TYPE),void 0!==e.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");e.sighashType=i.inputs.sighashType.decode(n);break;case a.InputTypes.REDEEM_SCRIPT:if(s("input",n.key,a.InputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");e.redeemScript=i.inputs.redeemScript.decode(n);break;case a.InputTypes.WITNESS_SCRIPT:if(s("input",n.key,a.InputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");e.witnessScript=i.inputs.witnessScript.decode(n);break;case a.InputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.inputs.bip32Derivation.decode(n));break;case a.InputTypes.FINAL_SCRIPTSIG:s("input",n.key,a.InputTypes.FINAL_SCRIPTSIG),e.finalScriptSig=i.inputs.finalScriptSig.decode(n);break;case a.InputTypes.FINAL_SCRIPTWITNESS:s("input",n.key,a.InputTypes.FINAL_SCRIPTWITNESS),e.finalScriptWitness=i.inputs.finalScriptWitness.decode(n);break;case a.InputTypes.POR_COMMITMENT:s("input",n.key,a.InputTypes.POR_COMMITMENT),e.porCommitment=i.inputs.porCommitment.decode(n);break;case a.InputTypes.TAP_KEY_SIG:s("input",n.key,a.InputTypes.TAP_KEY_SIG),e.tapKeySig=i.inputs.tapKeySig.decode(n);break;case a.InputTypes.TAP_SCRIPT_SIG:void 0===e.tapScriptSig&&(e.tapScriptSig=[]),e.tapScriptSig.push(i.inputs.tapScriptSig.decode(n));break;case a.InputTypes.TAP_LEAF_SCRIPT:void 0===e.tapLeafScript&&(e.tapLeafScript=[]),e.tapLeafScript.push(i.inputs.tapLeafScript.decode(n));break;case a.InputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.inputs.tapBip32Derivation.decode(n));break;case a.InputTypes.TAP_INTERNAL_KEY:s("input",n.key,a.InputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.inputs.tapInternalKey.decode(n);break;case a.InputTypes.TAP_MERKLE_ROOT:s("input",n.key,a.InputTypes.TAP_MERKLE_ROOT),e.tapMerkleRoot=i.inputs.tapMerkleRoot.decode(n);break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(n)}p.push(e)}for(const t of o.range(h)){const e={};for(const r of n[t])switch(i.outputs.checkPubkey(r),r.key[0]){case a.OutputTypes.REDEEM_SCRIPT:if(s("output",r.key,a.OutputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");e.redeemScript=i.outputs.redeemScript.decode(r);break;case a.OutputTypes.WITNESS_SCRIPT:if(s("output",r.key,a.OutputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");e.witnessScript=i.outputs.witnessScript.decode(r);break;case a.OutputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.outputs.bip32Derivation.decode(r));break;case a.OutputTypes.TAP_INTERNAL_KEY:s("output",r.key,a.OutputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.outputs.tapInternalKey.decode(r);break;case a.OutputTypes.TAP_TREE:s("output",r.key,a.OutputTypes.TAP_TREE),e.tapTree=i.outputs.tapTree.decode(r);break;case a.OutputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.outputs.tapBip32Derivation.decode(r));break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(r)}l.push(e)}return{globalMap:u,inputs:p,outputs:l}}e.psbtFromBuffer=function(t,e){let r=0;function n(){const e=u.decode(t,r);r+=u.encodingLength(e);const n=t.slice(r,r+e);return r+=e,n}function i(){return{key:n(),value:n()}}function s(){if(r>=t.length)throw new Error("Format Error: Unexpected End of PSBT");const e=0===t.readUInt8(r);return e&&r++,e}if(1886610036!==function(){const e=t.readUInt32BE(r);return r+=4,e}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const e=t.readUInt8(r);return r+=1,e}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const c=[],h={};for(;!s();){const t=i(),e=t.key.toString("hex");if(h[e])throw new Error("Format Error: Keys must be unique for global keymap: key "+e);h[e]=1,c.push(t)}const p=c.filter((t=>t.key[0]===a.GlobalTypes.UNSIGNED_TX));if(1!==p.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const l=e(p[0].value),{inputCount:d,outputCount:y}=l.getInputOutputCounts(),g=[],w=[];for(const t of o.range(d)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each input: input index "+t+" key "+o);e[o]=1,r.push(n)}g.push(r)}for(const t of o.range(y)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each output: output index "+t+" key "+o);e[o]=1,r.push(n)}w.push(r)}return f(l,{globalMapKeyVals:c,inputKeyVals:g,outputKeyVals:w})},e.checkKeyBuffer=s,e.psbtFromKeyVals=f},287:(t,e,r)=>{const n=r(526),i=r(251),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=s,e.IS=50;const u=2147483647;function a(t){if(t>u)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|y(t,e);let n=a(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(z(t,Uint8Array)){const e=new Uint8Array(t);return l(e.buffer,e.byteOffset,e.byteLength)}return p(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(z(t,ArrayBuffer)||t&&z(t.buffer,ArrayBuffer))return l(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(z(t,SharedArrayBuffer)||t&&z(t.buffer,SharedArrayBuffer)))return l(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|d(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||$(t.length)?a(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return c(t),a(t<0?0:0|d(t))}function p(t){const e=t.length<0?0:0|d(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function d(t){if(t>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return 0|t}function y(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||z(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return q(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return X(t).length;default:if(i)return n?-1:q(t).length;e=(""+e).toLowerCase(),i=!0}}function g(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return O(this,e,r);case"latin1":case"binary":return P(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function v(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),$(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let o,u=1,a=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;u=2,a/=2,s/=2,r/=2}function f(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}if(i){let n=-1;for(o=r;o<a;o++)if(f(t,o)===f(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===s)return n*u}else-1!==n&&(o-=o-n),n=-1}else for(r+s>a&&(r=a-s),o=r;o>=0;o--){let r=!0;for(let n=0;n<s;n++)if(f(t,o+n)!==f(e,n)){r=!1;break}if(r)return o}return-1}function b(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let u;for(n>o/2&&(n=o/2),u=0;u<n;++u){const n=parseInt(e.substr(2*u,2),16);if($(n))return u;t[r+u]=n}return u}function E(t,e,r,n){return Y(q(e,t.length-r),t,r,n)}function S(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function I(t,e,r,n){return Y(X(e),t,r,n)}function T(t,e,r,n){return Y(function(t,e){let r,n,i;const o=[];for(let u=0;u<t.length&&!((e-=2)<0);++u)r=t.charCodeAt(u),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function k(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,u=e>239?4:e>223?3:e>191?2:1;if(i+u<=r){let r,n,a,s;switch(u){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(s=(31&e)<<6|63&r,s>127&&(o=s));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(s=(15&e)<<12|(63&r)<<6|63&n,s>2047&&(s<55296||s>57343)&&(o=s));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(s=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,s>65535&&s<1114112&&(o=s))}}null===o?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=u}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=A));return r}(n)}s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return c(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(z(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=y,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)w(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)w(this,e,e+3),w(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)w(this,e,e+7),w(this,e+1,e+6),w(this,e+2,e+5),w(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?k(this,0,t):g.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},o&&(s.prototype[o]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),u=(r>>>=0)-(e>>>=0);const a=Math.min(o,u),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<a;++t)if(f[t]!==c[t]){o=f[t],u=c[t];break}return o<u?-1:u<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return v(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return v(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return S(this,t,e,r);case"base64":return I(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function O(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function P(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function U(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=J[t[n]];return i}function N(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function x(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i){F(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,r}function H(t,e,r,n,i){F(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=u,u>>=8,t[r+2]=u,u>>=8,t[r+1]=u,u>>=8,t[r]=u,r+8}function R(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,r,n,o){return e=+e,r>>>=0,o||R(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function V(t,e,r,n,o){return e=+e,r>>>=0,o||R(t,0,r,8),i.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=Q((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=Q((function(t,e=0){return H(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=0,o=1,u=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=r-1,o=1,u=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=Q((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=Q((function(t,e=0){return H(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return V(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return V(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),u=o.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%u]}return this};const D={};function K(t,e,r){D[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function M(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,n,i,o){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=o>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** ${8*(o+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new D.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,r){G(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||j(e,t.length-(r+1))}(n,i,o)}function G(t,e){if("number"!=typeof t)throw new D.ERR_INVALID_ARG_TYPE(e,"number",t)}function j(t,e,r){if(Math.floor(t)!==t)throw G(t,r),new D.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new D.ERR_BUFFER_OUT_OF_BOUNDS;throw new D.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}K("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),K("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),K("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=M(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=M(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function q(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let u=0;u<n;++u){if(r=t.charCodeAt(u),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function X(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function z(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function $(t){return t!=t}const J=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function Q(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}},307:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.redeemScript}}}},343:(t,e)=>{e.p2=e.I=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<32;t++){const e=r.charAt(t);n[e]=t}function i(t){const e=t>>25;return(33554431&t)<<5^996825010&-(1&e)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=i(e)^n>>5}e=i(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=i(e)^31&n}return e}function u(t,e,r,n){let i=0,o=0;const u=(1<<r)-1,a=[];for(let n=0;n<t.length;++n)for(i=i<<e|t[n],o+=e;o>=r;)o-=r,a.push(i>>o&u);if(n)o>0&&a.push(i<<r-o&u);else{if(o>=e)return"Excess padding";if(i<<r-o&u)return"Non-zero padding"}return a}function a(t){return u(t,8,5,!0)}function s(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e}function f(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function c(t){let e;function u(t,r){if(r=r||90,t.length<8)return t+" too short";if(t.length>r)return"Exceeds length limit";const u=t.toLowerCase(),a=t.toUpperCase();if(t!==u&&t!==a)return"Mixed-case string "+t;const s=(t=u).lastIndexOf("1");if(-1===s)return"No separator character for "+t;if(0===s)return"Missing prefix for "+t;const f=t.slice(0,s),c=t.slice(s+1);if(c.length<6)return"Data too short";let h=o(f);if("string"==typeof h)return h;const p=[];for(let t=0;t<c.length;++t){const e=c.charAt(t),r=n[e];if(void 0===r)return"Unknown character "+e;h=i(h)^r,t+6>=c.length||p.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:p}}return e="bech32"===t?1:734539939,{decodeUnsafe:function(t,e){const r=u(t,e);if("object"==typeof r)return r},decode:function(t,e){const r=u(t,e);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,n,u){if(u=u||90,t.length+7+n.length>u)throw new TypeError("Exceeds length limit");let a=o(t=t.toLowerCase());if("string"==typeof a)throw new Error(a);let s=t+"1";for(let t=0;t<n.length;++t){const e=n[t];if(e>>5)throw new Error("Non 5-bit word");a=i(a)^e,s+=r.charAt(e)}for(let t=0;t<6;++t)a=i(a);a^=e;for(let t=0;t<6;++t)s+=r.charAt(a>>5*(5-t)&31);return s},toWords:a,fromWordsUnsafe:s,fromWords:f}}e.I=c("bech32"),e.p2=c("bech32m")},344:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+t.key.toString("hex"));return t.value.readUInt32LE(0)},e.encode=function(t){const e=n.from([i.InputTypes.SIGHASH_TYPE]),r=n.allocUnsafe(4);return r.writeUInt32LE(t,0),{key:e,value:r}},e.expected="number",e.check=function(t){return"number"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.sighashType}},394:(t,e,r)=>{var n=r(287).hp;function i(t){if(t<0||t>9007199254740991||t%1!=0)throw new RangeError("value out of range")}function o(t){return i(t),t<253?1:t<=65535?3:t<=4294967295?5:9}Object.defineProperty(e,"__esModule",{value:!0}),e.encode=function t(e,r,u){if(i(e),r||(r=n.allocUnsafe(o(e))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return u||(u=0),e<253?(r.writeUInt8(e,u),Object.assign(t,{bytes:1})):e<=65535?(r.writeUInt8(253,u),r.writeUInt16LE(e,u+1),Object.assign(t,{bytes:3})):e<=4294967295?(r.writeUInt8(254,u),r.writeUInt32LE(e,u+1),Object.assign(t,{bytes:5})):(r.writeUInt8(255,u),r.writeUInt32LE(e>>>0,u+1),r.writeUInt32LE(e/4294967296|0,u+5),Object.assign(t,{bytes:9})),r},e.decode=function t(e,r){if(!n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");r||(r=0);const o=e.readUInt8(r);if(o<253)return Object.assign(t,{bytes:1}),o;if(253===o)return Object.assign(t,{bytes:3}),e.readUInt16LE(r+1);if(254===o)return Object.assign(t,{bytes:5}),e.readUInt32LE(r+1);{Object.assign(t,{bytes:9});const n=e.readUInt32LE(r+1),o=4294967296*e.readUInt32LE(r+5)+n;return i(o),o}},e.encodingLength=o},412:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.makeChecker=function(t){return function(e){let r;if(t.includes(e.key[0])&&(r=e.key.slice(1),33!==r.length&&65!==r.length||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+e.key.toString("hex"));return r}}},431:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.NON_WITNESS_UTXO]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.nonWitnessUtxo}},454:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&32===t.length}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_MERKLE_ROOT||1!==t.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_MERKLE_ROOT]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapMerkleRoot}},457:(t,e,r)=>{function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),n(r(263)),n(r(238))},526:(t,e)=>{e.byteLength=function(t){var e=a(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=a(t),u=o[0],s=o[1],f=new i(function(t,e,r){return 3*(e+r)/4-r}(0,u,s)),c=0,h=s>0?u-4:u;for(r=0;r<h;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],f[c++]=e>>16&255,f[c++]=e>>8&255,f[c++]=255&e;return 2===s&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,f[c++]=255&e),1===s&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,f[c++]=e>>8&255,f[c++]=255&e),f},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],u=16383,a=0,f=n-i;a<f;a+=u)o.push(s(t,a,a+u>f?f:a+u));return 1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0;u<64;++u)r[u]=o[u],n[o.charCodeAt(u)]=u;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(t,e,n){for(var i,o,u=[],a=e;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),u.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return u.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},542:(t,e,r)=>{var n=r(287).hp,i=r(113),o=r(61);function u(t){return n.isBuffer(t)}function a(t){return"string"==typeof t&&/^([0-9a-f]{2})+$/i.test(t)}function s(t,e){var r=t.toJSON();function n(n){if(!t(n))return!1;if(n.length===e)return!0;throw o.tfCustomError(r+"(Length: "+e+")",r+"(Length: "+n.length+")")}return n.toJSON=function(){return r},n}var f=s.bind(null,i.Array),c=s.bind(null,u),h=s.bind(null,a),p=s.bind(null,i.String),l=Math.pow(2,53)-1,d={ArrayN:f,Buffer:u,BufferN:c,Finite:function(t){return"number"==typeof t&&isFinite(t)},Hex:a,HexN:h,Int8:function(t){return t<<24>>24===t},Int16:function(t){return t<<16>>16===t},Int32:function(t){return(0|t)===t},Int53:function(t){return"number"==typeof t&&t>=-l&&t<=l&&Math.floor(t)===t},Range:function(t,e,r){function n(n,i){return r(n,i)&&n>t&&n<e}return r=r||i.Number,n.toJSON=function(){return`${r.toJSON()} between [${t}, ${e}]`},n},StringN:p,UInt8:function(t){return(255&t)===t},UInt16:function(t){return(65535&t)===t},UInt32:function(t){return t>>>0===t},UInt53:function(t){return"number"==typeof t&&t>=0&&t<=l&&Math.floor(t)===t}};for(var y in d)d[y].toJSON=function(t){return t}.bind(null,y);t.exports=d},545:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=t=>33===t.length&&[2,3].includes(t[0])||65===t.length&&4===t[0];e.makeConverter=function(t,e=i){return{decode:function(r){if(r.key[0]!==t)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+r.key.toString("hex"));const n=r.key.slice(1);if(!e(n))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+r.key.toString("hex"));if(r.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:r.value.slice(0,4),pubkey:n,path:"m"};for(const t of(o=r.value.length/4-1,[...Array(o).keys()])){const e=r.value.readUInt32LE(4*t+4),n=!!(2147483648&e),o=2147483647&e;i.path+="/"+o.toString(10)+(n?"'":"")}var o;return i},encode:function(e){const r=n.from([t]),i=n.concat([r,e.pubkey]),o=e.path.split("/"),u=n.allocUnsafe(4*o.length);e.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:i,value:u}},check:function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.masterFingerprint)&&"string"==typeof t.path&&e(t.pubkey)&&4===t.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}}}},578:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.witnessScript}}}},605:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTSIG]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptSig}},614:(t,e,r)=>{var n=r(287).hp;const i=r(863),o=r(457),u=r(80),a=r(699);e.i=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,e){const r=n.from(t,"base64");return this.fromBuffer(r,e)}static fromHex(t,e){const r=n.from(t,"hex");return this.fromBuffer(r,e)}static fromBuffer(t,e){const r=o.psbtFromBuffer(t,e),n=new this(r.globalMap.unsignedTx);return Object.assign(n,r),n}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return o.psbtToBuffer(this)}updateGlobal(t){return a.updateGlobal(t,this.globalMap),this}updateInput(t,e){const r=a.checkForInput(this.inputs,t);return a.updateInput(e,r),this}updateOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.updateOutput(e,r),this}addUnknownKeyValToGlobal(t){return a.checkHasKey(t,this.globalMap.unknownKeyVals,a.getEnumLength(u.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,e){const r=a.checkForInput(this.inputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.InputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addUnknownKeyValToOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.OutputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToInput(r,t))),a.addInputAttributes(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToOutput(r,t))),a.addOutputAttributes(this.outputs,t),this}clearFinalizedInput(t){const e=a.checkForInput(this.inputs,t);a.inputCheckUncleanFinalized(t,e);for(const t of Object.keys(e))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(t)||delete e[t];return this}combine(...t){const e=i.combine([this].concat(t));return Object.assign(this,e),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}},636:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394),o=r(545),u=t=>32===t.length;e.makeConverter=function(t){const e=o.makeConverter(t,u);return{decode:function(t){const r=i.decode(t.value),n=i.encodingLength(r),o=e.decode({key:t.key,value:t.value.slice(n+32*r)}),u=new Array(r);for(let e=0,i=n;e<r;e++,i+=32)u[e]=t.value.slice(i,i+32);return Object.assign({},o,{leafHashes:u})},encode:function(t){const r=e.encode(t),o=i.encodingLength(t.leafHashes.length),u=n.allocUnsafe(o);i.encode(t.leafHashes.length,u);const a=n.concat([u,...t.leafHashes,r.value]);return Object.assign({},r,{value:a})},check:function(t){return Array.isArray(t.leafHashes)&&t.leafHashes.every((t=>n.isBuffer(t)&&32===t.length))&&e.check(t)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:e.canAddToArray}}},676:(t,e,r)=>{var n=r(61),i=r(113),o=n.tfJSON,u=n.TfTypeError,a=n.TfPropertyTypeError,s=n.tfSubError,f=n.getValueTypeName,c={arrayOf:function(t,e){function r(r,n){return!!i.Array(r)&&!i.Nil(r)&&!(void 0!==e.minLength&&r.length<e.minLength)&&!(void 0!==e.maxLength&&r.length>e.maxLength)&&(void 0===e.length||r.length===e.length)&&r.every((function(e,r){try{return p(t,e,n)}catch(t){throw s(t,r)}}))}return t=h(t),e=e||{},r.toJSON=function(){var r="["+o(t)+"]";return void 0!==e.length?r+="{"+e.length+"}":void 0===e.minLength&&void 0===e.maxLength||(r+="{"+(void 0===e.minLength?0:e.minLength)+","+(void 0===e.maxLength?1/0:e.maxLength)+"}"),r},r},maybe:function t(e){function r(r,n){return i.Nil(r)||e(r,n,t)}return e=h(e),r.toJSON=function(){return"?"+o(e)},r},map:function(t,e){function r(r,n){if(!i.Object(r))return!1;if(i.Nil(r))return!1;for(var o in r){try{e&&p(e,o,n)}catch(t){throw s(t,o,"key")}try{var u=r[o];p(t,u,n)}catch(t){throw s(t,o)}}return!0}return t=h(t),e&&(e=h(e)),r.toJSON=e?function(){return"{"+o(e)+": "+o(t)+"}"}:function(){return"{"+o(t)+"}"},r},object:function(t){var e={};for(var r in t)e[r]=h(t[r]);function n(t,r){if(!i.Object(t))return!1;if(i.Nil(t))return!1;var n;try{for(n in e)p(e[n],t[n],r)}catch(t){throw s(t,n)}if(r)for(n in t)if(!e[n])throw new a(void 0,n);return!0}return n.toJSON=function(){return o(e)},n},anyOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.some((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join("|")},e},allOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.every((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join(" & ")},e},quacksLike:function(t){function e(e){return t===f(e)}return e.toJSON=function(){return t},e},tuple:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return!i.Nil(e)&&!i.Nil(e.length)&&(!r||e.length===t.length)&&t.every((function(t,n){try{return p(t,e[n],r)}catch(t){throw s(t,n)}}))}return e.toJSON=function(){return"("+t.map(o).join(", ")+")"},e},value:function(t){function e(e){return e===t}return e.toJSON=function(){return t},e}};function h(t){if(i.String(t))return"?"===t[0]?c.maybe(t.slice(1)):i[t]||c.quacksLike(t);if(t&&i.Object(t)){if(i.Array(t)){if(1!==t.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(t[0])}return c.object(t)}return i.Function(t)?t:c.value(t)}function p(t,e,r,n){if(i.Function(t)){if(t(e,r))return!0;throw new u(n||t,e)}return p(h(t),e,r)}for(var l in c.oneOf=c.anyOf,i)p[l]=i[l];for(l in c)p[l]=c[l];var d=r(542);for(l in d)p[l]=d[l];p.compile=h,p.TfTypeError=u,p.TfPropertyTypeError=a,t.exports=p},695:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+t.key.toString("hex"));if((t.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+t.key.toString("hex"));const e=t.value[t.value.length-1];if((254&t.key[1])!==e)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+t.key.toString("hex"));const r=t.value.slice(0,-1);return{controlBlock:t.key.slice(1),script:r,leafVersion:e}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_LEAF_SCRIPT]),r=n.from([t.leafVersion]);return{key:n.concat([e,t.controlBlock]),value:n.concat([t.script,r])}},e.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",e.check=function(t){return n.isBuffer(t.controlBlock)&&(t.controlBlock.length-1)%32==0&&(254&t.controlBlock[0])===t.leafVersion&&n.isBuffer(t.script)},e.canAddToArray=function(t,e,r){const n=e.controlBlock.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.controlBlock.equals(e.controlBlock))).length)}},699:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706);function o(t,e){const r=t[e];if(void 0===r)throw new Error(`No input #${e}`);return r}function u(t,e){const r=t[e];if(void 0===r)throw new Error(`No output #${e}`);return r}function a(t,e,r,n){throw new Error(`Data for ${t} key ${e} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function s(t){return(e,r)=>{for(const n of Object.keys(e)){const o=e[n],{canAdd:u,canAddToArray:s,check:f,expected:c}=i[t+"s"][n]||{};if(f)if(s){if(!Array.isArray(o)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);o.every(f)||a(t,n,c,o);const e=r[n]||[],i=new Set;if(!o.every((t=>s(e,t,i))))throw new Error("Can not add duplicate data to array");r[n]=e.concat(o)}else{if(f(o)||a(t,n,c,o),!u(r,o))throw new Error(`Can not add duplicate data to ${t}`);r[n]=o}}}}e.checkForInput=o,e.checkForOutput=u,e.checkHasKey=function(t,e,r){if(t.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(e&&0!==e.filter((e=>e.key.equals(t.key))).length)throw new Error(`Duplicate Key: ${t.key.toString("hex")}`)},e.getEnumLength=function(t){let e=0;return Object.keys(t).forEach((t=>{Number(isNaN(Number(t)))&&e++})),e},e.inputCheckUncleanFinalized=function(t,e){let r=!1;if(e.nonWitnessUtxo||e.witnessUtxo){const t=!!e.redeemScript,n=!!e.witnessScript,i=!t||!!e.finalScriptSig,o=!n||!!e.finalScriptWitness,u=!!e.finalScriptSig||!!e.finalScriptWitness;r=i&&o&&u}if(!1===r)throw new Error(`Input #${t} has too much or too little data to clean`)},e.updateGlobal=s("global"),e.updateInput=s("input"),e.updateOutput=s("output"),e.addInputAttributes=function(t,r){const n=o(t,t.length-1);e.updateInput(r,n)},e.addOutputAttributes=function(t,r){const n=u(t,t.length-1);e.updateOutput(r,n)},e.defaultVersionSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Version: Invalid Transaction");return e.writeUInt32LE(t,0),e},e.defaultLocktimeSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Locktime: Invalid Transaction");return e.writeUInt32LE(t,e.length-4),e}},706:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(80),i=r(834),o=r(213),u=r(605),a=r(795),s=r(431),f=r(907),c=r(949),h=r(344),p=r(760),l=r(695),d=r(454),y=r(34),g=r(926),w=r(851),v=r(545),m=r(412),b=r(307),E=r(636),S=r(223),I=r(578),T={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=T;const _={nonWitnessUtxo:s,partialSig:f,sighashType:h,finalScriptSig:u,finalScriptWitness:a,porCommitment:c,witnessUtxo:g,bip32Derivation:v.makeConverter(n.InputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.InputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:p,tapScriptSig:y,tapLeafScript:l,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:S.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:d};e.inputs=_;const k={bip32Derivation:v.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.OutputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:E.makeConverter(n.OutputTypes.TAP_BIP32_DERIVATION),tapTree:w,tapInternalKey:S.makeConverter(n.OutputTypes.TAP_INTERNAL_KEY)};e.outputs=k},760:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&(64===t.length||65===t.length)}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_KEY_SIG||1!==t.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_KEY_SIG]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapKeySig}},795:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptWitness}},834:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const e=t.key.slice(1),r={masterFingerprint:t.value.slice(0,4),extendedPubkey:e,path:"m"};for(const e of(n=t.value.length/4-1,[...Array(n).keys()])){const n=t.value.readUInt32LE(4*e+4),i=!!(2147483648&n),o=2147483647&n;r.path+="/"+o.toString(10)+(i?"'":"")}var n;return r},e.encode=function(t){const e=n.from([i.GlobalTypes.GLOBAL_XPUB]),r=n.concat([e,t.extendedPubkey]),o=t.path.split("/"),u=n.allocUnsafe(4*o.length);t.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:r,value:u}},e.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",e.check=function(t){const e=t.extendedPubkey,r=t.masterFingerprint,i=t.path;return n.isBuffer(e)&&78===e.length&&[2,3].indexOf(e[45])>-1&&n.isBuffer(r)&&4===r.length&&"string"==typeof i&&!!i.match(/^m(\/\d+'?)*$/)},e.canAddToArray=function(t,e,r){const n=e.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.extendedPubkey.equals(e.extendedPubkey))).length)}},851:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(394);e.decode=function(t){if(t.key[0]!==i.OutputTypes.TAP_TREE||1!==t.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+t.key.toString("hex"));let e=0;const r=[];for(;e<t.value.length;){const n=t.value[e++],i=t.value[e++],u=o.decode(t.value,e);e+=o.encodingLength(u),r.push({depth:n,leafVersion:i,script:t.value.slice(e,e+u)}),e+=u}return{leaves:r}},e.encode=function(t){const e=n.from([i.OutputTypes.TAP_TREE]),r=[].concat(...t.leaves.map((t=>[n.of(t.depth,t.leafVersion),o.encode(t.script.length),t.script])));return{key:e,value:n.concat(r)}},e.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",e.check=function(t){return Array.isArray(t.leaves)&&t.leaves.every((t=>t.depth>=0&&t.depth<=128&&(254&t.leafVersion)===t.leafVersion&&n.isBuffer(t.script)))},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapTree}},863:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(457);function i(t,e,r){return n=>{if(t.has(n))return;const i=r.filter((t=>t.key.toString("hex")===n))[0];e.push(i),t.add(n)}}function o(t){return t.globalMap.unsignedTx}function u(t){const e=new Set;return t.forEach((t=>{const r=t.key.toString("hex");if(e.has(r))throw new Error("Combine: KeyValue Map keys should be unique");e.add(r)})),e}e.combine=function(t){const e=t[0],r=n.psbtToKeyVals(e),a=t.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const s=o(e);if(void 0===s)throw new Error("Combine: Self missing transaction");const f=u(r.globalKeyVals),c=r.inputKeyVals.map(u),h=r.outputKeyVals.map(u);for(const t of a){const e=o(t);if(void 0===e||!e.toBuffer().equals(s.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const a=n.psbtToKeyVals(t);u(a.globalKeyVals).forEach(i(f,r.globalKeyVals,a.globalKeyVals)),a.inputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(c[e],r.inputKeyVals[e],a.inputKeyVals[e])))),a.outputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(h[e],r.outputKeyVals[e],a.outputKeyVals[e]))))}return n.psbtFromKeyVals(s,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}},907:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+t.key.toString("hex"));if(34!==t.key.length&&66!==t.key.length||![2,3,4].includes(t.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.PARTIAL_SIG]);return{key:n.concat([e,t.pubkey]),value:t.signature}},e.expected="{ pubkey: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.signature)&&[33,65].includes(t.pubkey.length)&&[2,3,4].includes(t.pubkey[0])&&function(t){if(!n.isBuffer(t)||t.length<9)return!1;if(48!==t[0])return!1;if(t.length!==t[1]+3)return!1;if(2!==t[2])return!1;const e=t[3];if(e>33||e<1)return!1;if(2!==t[3+e+1])return!1;const r=t[3+e+2];return!(r>33||r<1)&&t.length===3+e+2+r+2}(t.signature)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}},926:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(133),u=r(394);e.decode=function(t){if(t.key[0]!==i.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+t.key.toString("hex"));const e=o.readUInt64LE(t.value,0);let r=8;const n=u.decode(t.value,r);r+=u.encodingLength(n);const a=t.value.slice(r);if(a.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:a,value:e}},e.encode=function(t){const{script:e,value:r}=t,a=u.encodingLength(e.length),s=n.allocUnsafe(8+a+e.length);return o.writeUInt64LE(s,r,0),u.encode(e.length,s,8),e.copy(s,8+a),{key:n.from([i.InputTypes.WITNESS_UTXO]),value:s}},e.expected="{ script: Buffer; value: number; }",e.check=function(t){return n.isBuffer(t.script)&&"number"==typeof t.value},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.witnessUtxo}},949:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+t.key.toString("hex"));return t.value.toString("utf8")},e.encode=function(t){return{key:n.from([i.InputTypes.POR_COMMITMENT]),value:n.from(t,"utf8")}},e.expected="string",e.check=function(t){return"string"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.porCommitment}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{bitcoin:()=>p,bitcoinCash:()=>m,bitcoinCashTestnet:()=>b,dash:()=>E,dashTestnet:()=>S,dogecoin:()=>y,dogecoinTestnet:()=>g,litecoin:()=>w,litecoinTestnet:()=>v,regtest:()=>l,testnet:()=>d});var i={};r.r(i),r.d(i,{decode:()=>tt,encode:()=>et});var o={};r.r(o),r.d(o,{decode:()=>xt,encode:()=>Bt});var u={};r.r(u),r.d(u,{OPS:()=>W,compile:()=>Gt,countNonPushOnlyOPs:()=>Dt,decompile:()=>jt,fromASM:()=>qt,isCanonicalPubKey:()=>Yt,isCanonicalScriptSignature:()=>$t,isDefinedHashType:()=>zt,isPushOnly:()=>Vt,number:()=>Jt,signature:()=>Qt,toASM:()=>Wt,toStack:()=>Xt});var a={};r.r(a),r.d(a,{fromBase58Check:()=>ce,fromBech32:()=>he,fromOutputScript:()=>de,toBase58Check:()=>pe,toBech32:()=>le,toFutureOPNetAddress:()=>fe,toOutputScript:()=>ye});var s={};r.r(s),r.d(s,{TAGGED_HASH_PREFIXES:()=>Ge,TAGS:()=>Fe,hash160:()=>Ke,hash256:()=>Me,ripemd160:()=>Le,sha1:()=>Ve,sha256:()=>De,taggedHash:()=>je});var f={};r.r(f),r.d(f,{decode:()=>rr,encode:()=>er,encodingLength:()=>nr});var c={};r.r(c),r.d(c,{Transaction:()=>Zn});var h={};r.r(h),r.d(h,{LEAF_VERSION_TAPSCRIPT:()=>br,MAX_TAPTREE_DEPTH:()=>Er,PaymentType:()=>Wi,findScriptPath:()=>_r,p2data:()=>Br,p2ms:()=>Rr,p2op:()=>_i,p2pk:()=>Vr,p2pkh:()=>Yi,p2sh:()=>kn,p2tr:()=>Un,p2wpkh:()=>Cn,p2wsh:()=>Dn,prop:()=>Ur,rootHashFromPath:()=>Ir,tapTweakHash:()=>Ar,tapleafHash:()=>kr,toHashTree:()=>Tr,tweakKey:()=>Or,value:()=>Nr});var p={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bech32Opnet:"op",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},l={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bech32Opnet:"opr",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},d={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bech32Opnet:"opt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},y={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},g={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},w={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bech32Opnet:"opl",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},v={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bech32Opnet:"oplt",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},m={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bech32Opnet:"opbch",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},b={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bech32Opnet:"opbcht",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},E={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},S={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},I=r(343);function T(t,...e){if(!((r=t)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function _(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function k(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function A(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function O(t,e){return t<<32-e|t>>>e}function P(t,e){return t<<e|t>>>32-e>>>0}function U(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),T(t),t}class N{}function x(t){const e=e=>t().update(U(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function B(t,e,r){return t&e^~t&r}function C(t,e,r){return t&e^t&r^e&r}class H extends N{constructor(t,e,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(t),this.view=A(this.buffer)}update(t){_(this),T(t=U(t));const{view:e,buffer:r,blockLen:n}=this,i=t.length;for(let o=0;o<i;){const u=Math.min(n-this.pos,i-o);if(u!==n)r.set(t.subarray(o,o+u),this.pos),this.pos+=u,o+=u,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=A(t);for(;n<=i-o;o+=n)this.process(e,o)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){_(this),function(t,e){T(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;e[o++]=128,k(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let t=o;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),u=Number(r>>i&o),a=Number(r&o),s=n?4:0,f=n?0:4;t.setUint32(e+s,u,n),t.setUint32(e+f,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const u=A(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const s=a/4,f=this.get();if(s>f.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<s;t++)u.setUint32(4*t,f[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:u}=this;return t.destroyed=o,t.finished=i,t.length=n,t.pos=u,n%e&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const R=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),L=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),V=new Uint32Array(64);class D extends H{constructor(t=32){super(64,t,8,!1),this.A=0|R[0],this.B=0|R[1],this.C=0|R[2],this.D=0|R[3],this.E=0|R[4],this.F=0|R[5],this.G=0|R[6],this.H=0|R[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:u,H:a}=this;return[t,e,r,n,i,o,u,a]}set(t,e,r,n,i,o,u,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|u,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)V[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=V[t-15],r=V[t-2],n=O(e,7)^O(e,18)^e>>>3,i=O(r,17)^O(r,19)^r>>>10;V[t]=i+V[t-7]+n+V[t-16]|0}let{A:r,B:n,C:i,D:o,E:u,F:a,G:s,H:f}=this;for(let t=0;t<64;t++){const e=f+(O(u,6)^O(u,11)^O(u,25))+B(u,a,s)+L[t]+V[t]|0,c=(O(r,2)^O(r,13)^O(r,22))+C(r,n,i)|0;f=s,s=a,a=u,u=o+e|0,o=i,i=n,n=r,r=e+c|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,a=a+this.F|0,s=s+this.G|0,f=f+this.H|0,this.set(r,n,i,o,u,a,s,f)}roundClean(){k(V)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}const K=x((()=>new D)),M=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let t=0;t<e.length;t++)e[t]=255;for(let r=0;r<t.length;r++){const n=t.charAt(r),i=n.charCodeAt(0);if(255!==e[i])throw new TypeError(n+" is ambiguous");e[i]=r}const r=t.length,n=t.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function u(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;let o=0,u=0,a=0;for(;t[o]===n;)u++,o++;const s=(t.length-o)*i+1>>>0,f=new Uint8Array(s);for(;t[o];){let n=e[t.charCodeAt(o)];if(255===n)return;let i=0;for(let t=s-1;(0!==n||i<a)&&-1!==t;t--,i++)n+=r*f[t]>>>0,f[t]=n%256>>>0,n=n/256>>>0;if(0!==n)throw new Error("Non-zero carry");a=i,o++}let c=s-a;for(;c!==s&&0===f[c];)c++;const h=new Uint8Array(u+(s-c));let p=u;for(;c!==s;)h[p++]=f[c++];return h}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";let i=0,u=0,a=0;const s=e.length;for(;a!==s&&0===e[a];)a++,i++;const f=(s-a)*o+1>>>0,c=new Uint8Array(f);for(;a!==s;){let t=e[a],n=0;for(let e=f-1;(0!==t||n<u)&&-1!==e;e--,n++)t+=256*c[e]>>>0,c[e]=t%r>>>0,t=t/r>>>0;if(0!==t)throw new Error("Non-zero carry");u=n,a++}let h=f-u;for(;h!==f&&0===c[h];)h++;let p=n.repeat(i);for(;h<f;++h)p+=t.charAt(c[h]);return p},decodeUnsafe:u,decode:function(t){const e=u(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),F=function(t){function e(e){var r=e.slice(0,-4),n=e.slice(-4),i=t(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(e){var r=Uint8Array.from(e),n=t(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),M.encode(o)},decode:function(t){var r=e(M.decode(t));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(t){var r=M.decodeUnsafe(t);if(null!=r)return e(r)}}}((function(t){return K(K(t))}));var G=r(287).hp;function j(t,e){var r=t.length,n=e.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&t[0])throw new Error("R value is negative");if(128&e[0])throw new Error("S value is negative");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("R value excessively padded");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("S value excessively padded");var i=G.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=t.length,t.copy(i,4),i[4+r]=2,i[5+r]=e.length,e.copy(i,6+r),i}for(var W={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},q={},X=0,Y=Object.keys(W);X<Y.length;X++){var z=Y[X],$=W[z];q[$]=z}function J(t){return t<W.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function Q(t,e){var r,n,i=t.readUInt8(e);if(i<W.OP_PUSHDATA1)r=i,n=1;else if(i===W.OP_PUSHDATA1){if(e+2>t.length)return null;r=t.readUInt8(e+1),n=2}else if(i===W.OP_PUSHDATA2){if(e+3>t.length)return null;r=t.readUInt16LE(e+1),n=3}else{if(e+5>t.length)return null;if(i!==W.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=t.readUInt32LE(e+1),n=5}return{opcode:i,number:r,size:n}}var Z=r(287).hp;function tt(t,e,r){e=e||4,r=void 0===r||r;var n=t.length;if(0===n)return 0;if(n>e)throw new TypeError("Script number overflow");if(r&&!(127&t[n-1]||!(n<=1)&&128&t[n-2]))throw new Error("Non-minimally encoded script number");if(5===n){var i=t.readUInt32LE(0),o=t.readUInt8(4);return 128&o?-(4294967296*(-129&o)+i):4294967296*o+i}for(var u=0,a=0;a<n;++a)u|=t[a]<<8*a;return 128&t[n-1]?-(u&~(128<<8*(n-1))):u}function et(t){for(var e=Math.abs(t),r=function(t){return t>2147483647?5:t>8388607?4:t>32767?3:t>127?2:t>0?1:0}(e),n=Z.allocUnsafe(r),i=t<0,o=0;o<r;++o)n.writeUInt8(255&e,o),e>>=8;return 128&n[r-1]?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}var rt=r(287),nt=r(676),it=r.n(nt)(),ot=rt.hp.alloc(32,0),ut=rt.hp.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function at(t,e){return t.length===e.length&&t.every((function(t,r){return t.equals(e[r])}))}function st(t){if(!rt.hp.isBuffer(t))return!1;if(t.length<33)return!1;var e=t[0],r=t.slice(1,33);if(0===r.compare(ot))return!1;if(r.compare(ut)>=0)return!1;if((2===e||3===e)&&33===t.length)return!0;if(65!==t.length)return!1;var n=t.slice(33);return!(0===n.compare(ot)||n.compare(ut)>=0||4!==e&&6!==e&&7!==e)}function ft(t){return it.UInt53(t)&&t<=21e14}var ct=254;function ht(t){return!(!t||!("output"in t)||!rt.hp.isBuffer(t.output)||void 0!==t.version&&(t.version&ct)!==t.version)}function pt(t){return gt(t)?2===t.length&&t.every((function(t){return pt(t)})):ht(t)}it.BufferN(32);var lt=it.BufferN(20),dt=it.BufferN(32),yt=it.Number,gt=it.Array,wt=(it.Boolean,it.String),vt=it.Buffer,mt=it.Hex,bt=it.maybe,Et=it.tuple,St=it.UInt8,It=it.UInt32,Tt=it.Function,_t=it.BufferN,kt=it.Null,At=(it.oneOf,r(287).hp),Ot=it,Pt=At.alloc(1,0);function Ut(t){for(var e=0;0===t[e];)++e;return e===t.length?Pt:128&(t=t.slice(e))[0]?At.concat([Pt,t],1+t.length):t}function Nt(t){0===t[0]&&(t=t.slice(1));var e=At.alloc(32,0),r=Math.max(0,32-t.length);return t.copy(e,r),e}function xt(t){var e=t.readUInt8(t.length-1);if(!zt(e))throw new Error("Invalid hashType "+e);var r=function(t){if(t.length<8)throw new Error("DER sequence length is too short");if(t.length>72)throw new Error("DER sequence length is too long");if(48!==t[0])throw new Error("Expected DER sequence");if(t[1]!==t.length-2)throw new Error("DER sequence length is invalid");if(2!==t[2])throw new Error("Expected DER integer");var e=t[3];if(0===e)throw new Error("R length is zero");if(5+e>=t.length)throw new Error("R length is too long");if(2!==t[4+e])throw new Error("Expected DER integer (2)");var r=t[5+e];if(0===r)throw new Error("S length is zero");if(6+e+r!==t.length)throw new Error("S length is invalid");if(128&t[4])throw new Error("R value is negative");if(e>1&&0===t[4]&&!(128&t[5]))throw new Error("R value excessively padded");if(128&t[e+6])throw new Error("S value is negative");if(r>1&&0===t[e+6]&&!(128&t[e+7]))throw new Error("S value excessively padded");return{r:t.slice(4,4+e),s:t.slice(6+e)}}(t.slice(0,-1)),n=Nt(r.r),i=Nt(r.s);return{signature:At.concat([n,i],64),hashType:e}}function Bt(t,e){if(Ot({signature:_t(64),hashType:St},{signature:t,hashType:e}),!zt(e))throw new Error("Invalid hashType "+e);var r=At.allocUnsafe(1);r.writeUInt8(e,0);var n=Ut(t.slice(0,32)),i=Ut(t.slice(32,64));return At.concat([j(n,i),r])}var Ct=r(287).hp,Ht=it,Rt=W.OP_RESERVED;function Lt(t){return vt(t)||function(t){return yt(t)&&(t===W.OP_0||t>=W.OP_1&&t<=W.OP_16||t===W.OP_1NEGATE)}(t)}function Vt(t){return gt(t)&&t.every(Lt)}function Dt(t){return t.length-t.filter(Lt).length}function Kt(t){return 0===t.length?W.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Rt+t[0]:129===t[0]?W.OP_1NEGATE:void 0:void 0}function Mt(t){return Ct.isBuffer(t)}function Ft(t){return Ct.isBuffer(t)}function Gt(t){if(Mt(t))return t;Ht(gt,t);var e=t.reduce((function(t,e){return Ft(e)?1===e.length&&void 0!==Kt(e)?t+1:t+J(e.length)+e.length:t+1}),0),r=Ct.allocUnsafe(e),n=0;if(t.forEach((function(t){if(Ft(t)){var e=Kt(t);if(void 0!==e)return r.writeUInt8(e,n),void(n+=1);n+=function(t,e,r){var n=J(e);return 1===n?t.writeUInt8(e,r):2===n?(t.writeUInt8(W.OP_PUSHDATA1,r),t.writeUInt8(e,r+1)):3===n?(t.writeUInt8(W.OP_PUSHDATA2,r),t.writeUInt16LE(e,r+1)):(t.writeUInt8(W.OP_PUSHDATA4,r),t.writeUInt32LE(e,r+1)),n}(r,t.length,n),t.copy(r,n),n+=t.length}else r.writeUInt8(t,n),n+=1})),n!==r.length)throw new Error("Could not decode chunks");return r}function jt(t){if(gt(t))return t;Ht(vt,t);for(var e=[],r=0;r<t.length;){var n=t[r];if(n>W.OP_0&&n<=W.OP_PUSHDATA4){var i=Q(t,r);if(null===i)return null;if((r+=i.size)+i.number>t.length)return null;var o=t.slice(r,r+i.number);r+=i.number;var u=Kt(o);void 0!==u?e.push(u):e.push(o)}else e.push(n),r+=1}return e}function Wt(t){if(Mt(t)&&(t=jt(t)),!t)throw new Error("Could not convert invalid chunks to ASM");return t.map((function(t){if(Ft(t)){var e=Kt(t);if(void 0===e)return t.toString("hex");t=e}return q[t]})).join(" ")}function qt(t){return Ht(wt,t),Gt(t.split(" ").map((function(t){return void 0!==W[t]?W[t]:(Ht(mt,t),Ct.from(t,"hex"))})))}function Xt(t){return t=jt(t),Ht(Vt,t),t.map((function(t){return Ft(t)?t:t===W.OP_0?Ct.allocUnsafe(0):et(t-Rt)}))}function Yt(t){return st(t)}function zt(t){var e=-129&t;return e>0&&e<4}function $t(t){return!!Ct.isBuffer(t)&&!!zt(t[t.length-1])&&function(t){if(t.length<8)return!1;if(t.length>72)return!1;if(48!==t[0])return!1;if(t[1]!==t.length-2)return!1;if(2!==t[2])return!1;var e=t[3];if(0===e)return!1;if(5+e>=t.length)return!1;if(2!==t[4+e])return!1;var r=t[5+e];return!(0===r||6+e+r!==t.length||128&t[4]||e>1&&0===t[4]&&!(128&t[5])||128&t[e+6]||r>1&&0===t[e+6]&&!(128&t[e+7]))}(t.slice(0,-1))}var Jt=i,Qt=o,Zt=r(287).hp;function te(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ee=40,re=2,ne=15,ie=16,oe=16,ue=2,ae=80,se="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function fe(t,e){if(!Zt.isBuffer(t))throw new TypeError("output must be a Buffer");if(!e.bech32Opnet)throw new Error("Network does not support opnet");var r,n=t[0],i=1;if(t[1]<76)r=t[1],i=2;else{if(76!==t[1])throw new TypeError("Unsupported push opcode in script");r=t[2],i=3}var o=t.subarray(i,i+r);if(o.length<re||o.length>ee)throw new TypeError("Invalid program length for segwit address");var u=n===W.OP_0?0:n>=W.OP_1&&n<=W.OP_16?n-(W.OP_1-1):-1;if(u<ne||u>ie)throw new TypeError("Invalid segwit version ".concat(u));var a,s=[u].concat(function(t){if(Array.isArray(t))return te(t)}(a=I.p2.toWords(o))||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(a)||function(t,e){if(t){if("string"==typeof t)return te(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?te(t,e):void 0}}(a)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());return I.p2.encode(e.bech32Opnet,s)}function ce(t){var e=Zt.from(F.decode(t));if(e.length<21)throw new TypeError(t+" is too short");if(e.length>21)throw new TypeError(t+" is too long");return{version:e.readUInt8(0),hash:e.subarray(1)}}function he(t){var e,r;try{e=I.I.decode(t)}catch(t){}if(e){if(0!==(r=e.words[0]))throw new TypeError(t+" uses wrong encoding")}else if(0===(r=(e=I.p2.decode(t)).words[0]))throw new TypeError(t+" uses wrong encoding");var n=I.I.fromWords(e.words.slice(1));return{version:r,prefix:e.prefix,data:Zt.from(n)}}function pe(t,e){it(Et(lt,St),arguments);var r=Zt.allocUnsafe(21);return r.writeUInt8(e,0),t.copy(r,1),F.encode(r)}function le(t,e,r,n){var i=I.I.toWords(t);return i.unshift(e),e===oe&&n?I.p2.encode(n,i):0===e?I.I.encode(r,i):I.p2.encode(r,i)}function de(t,e){e=e||p;try{return Yi({output:t,network:e}).address}catch(t){}try{return kn({output:t,network:e}).address}catch(t){}try{return Cn({output:t,network:e}).address}catch(t){}try{return Dn({output:t,network:e}).address}catch(t){}try{return Un({output:t,network:e}).address}catch(t){}try{return fe(t,e)}catch(t){}try{return function(t,e){var r=t.subarray(2);if(r.length<re||r.length>ee)throw new TypeError("Invalid program length for segwit address");var n=t[0]-ae;if(n<ue||n>ne)throw new TypeError("Invalid version for segwit address");if(t[1]!==r.length)throw new TypeError("Invalid script for segwit address ".concat(t[1]," !== ").concat(r.length));return le(r,n,e.bech32,e.bech32Opnet)}(t,e)}catch(t){}throw new Error(Wt(t)+" has no matching Address")}function ye(t,e){var r,n;e=e||p;try{r=ce(t)}catch(t){}if(r){if(r.version===e.pubKeyHash)return Yi({hash:r.hash}).output;if(r.version===e.scriptHash)return kn({hash:r.hash}).output}else{try{n=he(t)}catch(t){}if(n){if(n.prefix!==e.bech32&&e.bech32Opnet&&n.prefix!==e.bech32Opnet)throw new Error(t+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return Cn({hash:n.data}).output;if(32===n.data.length)return Dn({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return Un({pubkey:n.data}).output}else{if(n.version===oe){if(!e.bech32Opnet)throw new Error(t+" has an invalid prefix");return _i({program:n.data,network:e}).output}if(n.version>=ue&&n.version<=ne&&n.data.length>=re&&n.data.length<=ee)return n.version!==oe&&console.warn(se),Gt([n.version+ae,n.data])}}}return Zt.from(t,"hex")}const ge=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),we=new Uint32Array(80);class ve extends H{constructor(){super(64,20,8,!1),this.A=0|ge[0],this.B=0|ge[1],this.C=0|ge[2],this.D=0|ge[3],this.E=0|ge[4]}get(){const{A:t,B:e,C:r,D:n,E:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)we[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)we[t]=P(we[t-3]^we[t-8]^we[t-14]^we[t-16],1);let{A:r,B:n,C:i,D:o,E:u}=this;for(let t=0;t<80;t++){let e,a;t<20?(e=B(n,i,o),a=1518500249):t<40?(e=n^i^o,a=1859775393):t<60?(e=C(n,i,o),a=2400959708):(e=n^i^o,a=3395469782);const s=P(r,5)+e+u+a+we[t]|0;u=o,o=i,i=P(n,30),n=r,r=s}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,this.set(r,n,i,o,u)}roundClean(){k(we)}destroy(){this.set(0,0,0,0,0),k(this.buffer)}}const me=x((()=>new ve)),be=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ee=(()=>Uint8Array.from(new Array(16).fill(0).map(((t,e)=>e))))(),Se=(()=>Ee.map((t=>(9*t+5)%16)))(),Ie=(()=>{const t=[[Ee],[Se]];for(let e=0;e<4;e++)for(let r of t)r.push(r[e].map((t=>be[t])));return t})(),Te=(()=>Ie[0])(),_e=(()=>Ie[1])(),ke=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((t=>Uint8Array.from(t))),Ae=Te.map(((t,e)=>t.map((t=>ke[e][t])))),Oe=_e.map(((t,e)=>t.map((t=>ke[e][t])))),Pe=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ue=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Ne(t,e,r,n){return 0===t?e^r^n:1===t?e&r|~e&n:2===t?(e|~r)^n:3===t?e&n|r&~n:e^(r|~n)}const xe=new Uint32Array(16);class Be extends H{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:r,h3:n,h4:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.h0=0|t,this.h1=0|e,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)xe[r]=t.getUint32(e,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,u=0|this.h2,a=u,s=0|this.h3,f=s,c=0|this.h4,h=c;for(let t=0;t<5;t++){const e=4-t,p=Pe[t],l=Ue[t],d=Te[t],y=_e[t],g=Ae[t],w=Oe[t];for(let e=0;e<16;e++){const n=P(r+Ne(t,i,u,s)+xe[d[e]]+p,g[e])+c|0;r=c,c=s,s=0|P(u,10),u=i,i=n}for(let t=0;t<16;t++){const r=P(n+Ne(e,o,a,f)+xe[y[t]]+l,w[t])+h|0;n=h,h=f,f=0|P(a,10),a=o,o=r}}this.set(this.h1+u+f|0,this.h2+s+h|0,this.h3+c+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){k(xe)}destroy(){this.destroyed=!0,k(this.buffer),this.set(0,0,0,0,0)}}const Ce=x((()=>new Be)),He=me;var Re=r(287).hp;function Le(t){return Re.from(Ce(Uint8Array.from(t)))}function Ve(t){return Re.from(He(Uint8Array.from(t)))}function De(t){return Re.from(K(Uint8Array.from(t)))}function Ke(t){return Re.from(Ce(K(Uint8Array.from(t))))}function Me(t){return Re.from(K(K(Uint8Array.from(t))))}var Fe=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],Ge={"BIP0340/challenge":Re.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Re.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Re.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Re.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Re.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Re.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Re.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Re.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Re.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function je(t,e){return De(Re.concat([Ge[t],e]))}var We=r(287).hp,qe={};function Xe(t){var e;t?t!==qe.eccLib&&($e("function"==typeof(e=t).isXOnlyPoint),$e(e.isXOnlyPoint(ze("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),$e(e.isXOnlyPoint(ze("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),$e(e.isXOnlyPoint(ze("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),$e(e.isXOnlyPoint(ze("0000000000000000000000000000000000000000000000000000000000000001"))),$e(!e.isXOnlyPoint(ze("0000000000000000000000000000000000000000000000000000000000000000"))),$e(!e.isXOnlyPoint(ze("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),$e("function"==typeof e.xOnlyPointAddTweak),Je.forEach((function(t){var r=e.xOnlyPointAddTweak(ze(t.pubkey),ze(t.tweak));null===t.result?$e(null===r):($e(null!==r),$e(r.parity===t.parity),$e(We.from(r.xOnlyPubkey).equals(ze(t.result))))})),qe.eccLib=t):qe.eccLib=t}function Ye(){if(!qe.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return qe.eccLib}var ze=function(t){return We.from(t,"hex")};function $e(t){if(!t)throw new Error("ecc library invalid")}var Je=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];const Qe="0123456789abcdefABCDEF";Qe.split("").map((t=>t.codePointAt(0))),Array(256).fill(!0).map(((t,e)=>{const r=String.fromCodePoint(e),n=Qe.indexOf(r);return n<0?void 0:n<16?n:n-6})),new TextEncoder,new TextDecoder;const Ze=t=>{if(t<0||t>0xffffffffffffffffn)throw new RangeError("value out of range")};function tr(t){"number"==typeof t?function(t){if(t<0||t>Number.MAX_SAFE_INTEGER||t%1!=0)throw new RangeError("value out of range")}(t):Ze(t)}function er(t,e,r){tr(t),void 0===r&&(r=0),void 0===e&&(e=new Uint8Array(nr(t)));let n=0;return t<253?(e.set([Number(t)],r),n=1):t<=65535?(e.set([253],r),function(t,e,r,n){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255):(t[e]=r>>8&255,t[e+1]=255&r)}(e,r+1,Number(t),"LE"),n=3):t<=4294967295?(e.set([254],r),function(t,e,r,n){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255):(t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r)}(e,r+1,Number(t),"LE"),n=5):(e.set([255],r),function(t,e,r,n){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);"LE"===n?(t[e]=Number(0xffn&r),t[e+1]=Number(r>>8n&0xffn),t[e+2]=Number(r>>16n&0xffn),t[e+3]=Number(r>>24n&0xffn),t[e+4]=Number(r>>32n&0xffn),t[e+5]=Number(r>>40n&0xffn),t[e+6]=Number(r>>48n&0xffn),t[e+7]=Number(r>>56n&0xffn)):(t[e]=Number(r>>56n&0xffn),t[e+1]=Number(r>>48n&0xffn),t[e+2]=Number(r>>40n&0xffn),t[e+3]=Number(r>>32n&0xffn),t[e+4]=Number(r>>24n&0xffn),t[e+5]=Number(r>>16n&0xffn),t[e+6]=Number(r>>8n&0xffn),t[e+7]=Number(0xffn&r))}(e,r+1,BigInt(t),"LE"),n=9),{buffer:e,bytes:n}}function rr(t,e){void 0===e&&(e=0);const r=t.at(e);if(void 0===r)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(253===r){const r=function(t,e,r){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+1],r=(r<<8)+t[e],r}{let r=0;return r=(r<<8)+t[e],r=(r<<8)+t[e+1],r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}if(254===r){const r=function(t,e,r){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+3]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e]>>>0,r}{let r=0;return r=(r<<8)+t[e]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+3]>>>0,r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}{const r=function(t,e,r){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(t[e+7]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e]),r}{let r=0n;return r=(r<<8n)+BigInt(t[e]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+7]),r}}(t,e+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function nr(t){return tr(t),t<253?1:t<=65535?3:t<=4294967295?5:9}var ir=r(287).hp;function or(t){return or="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},or(t)}function ur(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ar(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,fr(n.key),n)}}function sr(t,e,r){return e&&ar(t.prototype,e),r&&ar(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function fr(t){var e=function(t){if("object"!=or(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=or(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==or(e)?e:e+""}var cr=it;function hr(t,e){if("number"!=typeof t)throw new Error("cannot write a non-number as a number");if(t<0)throw new Error("specified a negative value for writing an unsigned value");if(t>e)throw new Error("RangeError: value out of range");if(Math.floor(t)!==t)throw new Error("value has a fractional component")}function pr(t,e){var r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return hr((n*=4294967296)+r,9007199254740991),n+r}function lr(t,e,r){return hr(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}function dr(t){if(t.length<1)return t;for(var e=t.length-1,r=0,n=0;n<t.length/2;n++)r=t[n],t[n]=t[e],t[e]=r,e--;return t}function yr(t){var e=ir.allocUnsafe(t.length);return t.copy(e),e}var gr=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;ur(this,t),this.buffer=e,this.offset=r,cr(Et(vt,It),[e,r])}return sr(t,[{key:"writeUInt8",value:function(t){this.offset=this.buffer.writeUInt8(t,this.offset)}},{key:"writeInt32",value:function(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}},{key:"writeUInt32",value:function(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}},{key:"writeUInt64",value:function(t){this.offset=lr(this.buffer,t,this.offset)}},{key:"writeVarInt",value:function(t){var e=er(t,this.buffer,this.offset);this.offset+=e.bytes}},{key:"writeSlice",value:function(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}},{key:"writeVarSlice",value:function(t){this.writeVarInt(t.length),this.writeSlice(t)}},{key:"writeVector",value:function(t){var e=this;this.writeVarInt(t.length),t.forEach((function(t){return e.writeVarSlice(t)}))}},{key:"end",value:function(){if(this.buffer.length===this.offset)return this.buffer;throw new Error("buffer size ".concat(this.buffer.length,", offset ").concat(this.offset))}}],[{key:"withCapacity",value:function(e){return new t(ir.alloc(e))}}])}(),wr=function(){return sr((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;ur(this,t),this.buffer=e,this.offset=r,cr(Et(vt,It),[e,r])}),[{key:"readUInt8",value:function(){var t=this.buffer.readUInt8(this.offset);return this.offset++,t}},{key:"readInt32",value:function(){var t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt32",value:function(){var t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt64",value:function(){var t=pr(this.buffer,this.offset);return this.offset+=8,t}},{key:"readVarInt",value:function(){var t=rr(this.buffer,this.offset);return this.offset+=t.bytes,t.numberValue||0}},{key:"readSlice",value:function(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");var e=this.buffer.subarray(this.offset,this.offset+t);return this.offset+=t,e}},{key:"readVarSlice",value:function(){return this.readSlice(this.readVarInt())}},{key:"readVector",value:function(){for(var t=this.readVarInt(),e=[],r=0;r<t;r++)e.push(this.readVarSlice());return e}}])}();function vr(t){return function(t){if(Array.isArray(t))return mr(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return mr(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?mr(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function mr(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var br=192,Er=128,Sr=function(t){return"left"in t&&"right"in t};function Ir(t,e){if(t.length<33)throw new TypeError("The control-block length is too small. Got ".concat(t.length,", expected min 33."));for(var r=(t.length-33)/32,n=e,i=0;i<r;i++){var o=t.slice(33+32*i,65+32*i);n=n.compare(o)<0?Pr(n,o):Pr(o,n)}return n}function Tr(t){if(ht(t))return{hash:kr(t)};var e=[Tr(t[0]),Tr(t[1])];e.sort((function(t,e){return t.hash.compare(e.hash)}));var r=e[0],n=e[1];return{hash:Pr(r.hash,n.hash),left:r,right:n}}function _r(t,e){if(Sr(t)){var r=_r(t.left,e);if(void 0!==r)return[].concat(vr(r),[t.right.hash]);var n=_r(t.right,e);if(void 0!==n)return[].concat(vr(n),[t.left.hash])}else if(t.hash.equals(e))return[]}function kr(t){var e,r,n,i=t.version||br;return je("TapLeaf",rt.hp.concat([rt.hp.from([i]),(e=t.output,r=nr(e.length),n=rt.hp.allocUnsafe(r),er(e.length,n),rt.hp.concat([n,e]))]))}function Ar(t,e){return je("TapTweak",rt.hp.concat(e?[t,e]:[t]))}function Or(t,e){if(!rt.hp.isBuffer(t))return null;if(32!==t.length)return null;if(e&&32!==e.length)return null;var r=Ar(t,e),n=Ye().xOnlyPointAddTweak(t,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:rt.hp.from(n.xOnlyPubkey)}:null}function Pr(t,e){return je("TapBranch",rt.hp.concat([t,e]))}function Ur(t,e,r){Object.defineProperty(t,e,{configurable:!0,enumerable:!0,get:function(){var t=r.call(this);return this[e]=t,t},set:function(t){Object.defineProperty(this,e,{configurable:!0,enumerable:!0,value:t,writable:!0})}})}function Nr(t){var e;return function(){return void 0!==e?e:e=t()}}var xr=W;function Br(t,e){if(!t.data&&!t.output)throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),data:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network||p,n={name:Wi.Embed,network:r,data:[]};if(Ur(n,"output",(function(){if(t.data)return Gt([xr.OP_RETURN].concat(t.data))})),Ur(n,"data",(function(){if(t.output){var e=jt(t.output);if(null!=e)return e.slice(1)}})),e.validate&&t.output){var i=jt(t.output);if(i[0]!==xr.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(it.Buffer))throw new TypeError("Output is invalid");if(t.data&&!at(t.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,t)}var Cr=W,Hr=Cr.OP_RESERVED;function Rr(t,e){if(!(t.input||t.output||t.pubkeys&&void 0!==t.m||t.signatures))throw new TypeError("Not enough data");function r(t){return $t(t)||void 0!==(e.allowIncomplete&&t===Cr.OP_0)}e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),m:it.maybe(it.Number),n:it.maybe(it.Number),output:it.maybe(it.Buffer),pubkeys:it.maybe(it.arrayOf(st)),signatures:it.maybe(it.arrayOf(r)),input:it.maybe(it.Buffer)},t);var n={network:t.network||p,name:Wi.P2MS},i=[],o=!1;function u(t){o||(o=!0,i=jt(t),n.m=i[0]-Hr,n.n=i[i.length-2]-Hr,n.pubkeys=i.slice(1,-2))}if(Ur(n,"output",(function(){if(t.m&&n.n&&t.pubkeys)return Gt([].concat(Hr+t.m,t.pubkeys,Hr+n.n,Cr.OP_CHECKMULTISIG))})),Ur(n,"m",(function(){if(n.output)return u(n.output),n.m})),Ur(n,"n",(function(){if(n.pubkeys)return n.pubkeys.length})),Ur(n,"pubkeys",(function(){if(t.output)return u(t.output),n.pubkeys})),Ur(n,"signatures",(function(){if(t.input){var e=jt(t.input);if(null!=e)return e.slice(1)}})),Ur(n,"input",(function(){if(t.signatures)return Gt([Cr.OP_0].concat(t.signatures))})),Ur(n,"witness",(function(){if(n.input)return[]})),Ur(n,"name",(function(){if(n.m&&n.n)return"p2ms(".concat(n.m," of ").concat(n.n,")")})),e.validate){if(t.output){if(u(t.output),!it.Number(i[0]))throw new TypeError("Output is invalid");if(!it.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Cr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every((function(t){return st(t)})))throw new TypeError("Output is invalid");if(void 0!==t.m&&t.m!==n.m)throw new TypeError("m mismatch");if(void 0!==t.n&&t.n!==n.n)throw new TypeError("n mismatch");if(t.pubkeys&&!at(t.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(t.pubkeys){if(void 0!==t.n&&t.n!==t.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=t.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(t.signatures){if(t.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(t.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(t.input){if(t.input[0]!==Cr.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(t.signatures&&!at(t.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==t.m&&t.m!==t.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,t)}var Lr=W;function Vr(t,e){if(!(t.input||t.output||t.pubkey||t.input||t.signature))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Nr((function(){return jt(t.input)})),n=t.network||p,i={name:Wi.P2PK,network:n,pubkey:void 0};if(Ur(i,"output",(function(){if(t.pubkey)return Gt([t.pubkey,Lr.OP_CHECKSIG])})),Ur(i,"pubkey",(function(){if(t.output)return t.output.slice(1,-1)})),Ur(i,"signature",(function(){if(t.input)return r()[0]})),Ur(i,"input",(function(){if(t.signature)return Gt([t.signature])})),Ur(i,"witness",(function(){if(i.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Lr.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!st(i.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&!t.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&!t.input.equals(i.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!$t(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,t)}const Dr=2n**256n,Kr=Dr-0x1000003d1n,Mr=Dr-0x14551231950b75fc4402da1732fc9bebfn,Fr=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gr=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,jr={p:Kr,n:Mr,a:0n,b:7n,Gx:Fr,Gy:Gr},Wr=t=>tn(tn(t*t)*t+jr.b),qr=(t="")=>{throw new Error(t)},Xr=t=>"bigint"==typeof t,Yr=t=>"string"==typeof t,zr=t=>Xr(t)&&0n<t&&t<Kr,$r=t=>Xr(t)&&0n<t&&t<Mr,Jr=(t,e)=>!(t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?qr("Uint8Array expected"):t,Qr=t=>new Uint8Array(t),Zr=(t,e)=>Jr(Yr(t)?fn(t):Qr(Jr(t)),e),tn=(t,e=Kr)=>{const r=t%e;return r>=0n?r:e+r},en=t=>t instanceof rn?t:qr("Point expected");class rn{constructor(t,e,r){this.px=t,this.py=e,this.pz=r,Object.freeze(this)}static fromAffine(t){return 0n===t.x&&0n===t.y?on:new rn(t.x,t.y,1n)}static fromHex(t){let e;const r=(t=Zr(t))[0],n=t.subarray(1),i=hn(n,0,32),o=t.length;if(33===o&&[2,3].includes(r)){zr(i)||qr("Point hex invalid: x not FE");let t=gn(Wr(i));!(1&~r)!=(1n===(1n&t))&&(t=tn(-t)),e=new rn(i,t,1n)}return 65===o&&4===r&&(e=new rn(i,hn(n,32,64),1n)),e?e.ok():qr("Point invalid: not on curve")}static fromPrivateKey(t){return nn.mul(wn(t))}get x(){return this.aff().x}get y(){return this.aff().y}equals(t){const{px:e,py:r,pz:n}=this,{px:i,py:o,pz:u}=en(t),a=tn(e*u),s=tn(i*n),f=tn(r*u),c=tn(o*n);return a===s&&f===c}negate(){return new rn(this.px,tn(-this.py),this.pz)}double(){return this.add(this)}add(t){const{px:e,py:r,pz:n}=this,{px:i,py:o,pz:u}=en(t),{a,b:s}=jr;let f=0n,c=0n,h=0n;const p=tn(3n*s);let l=tn(e*i),d=tn(r*o),y=tn(n*u),g=tn(e+r),w=tn(i+o);g=tn(g*w),w=tn(l+d),g=tn(g-w),w=tn(e+n);let v=tn(i+u);return w=tn(w*v),v=tn(l+y),w=tn(w-v),v=tn(r+n),f=tn(o+u),v=tn(v*f),f=tn(d+y),v=tn(v-f),h=tn(a*w),f=tn(p*y),h=tn(f+h),f=tn(d-h),h=tn(d+h),c=tn(f*h),d=tn(l+l),d=tn(d+l),y=tn(a*y),w=tn(p*w),d=tn(d+y),y=tn(l-y),y=tn(a*y),w=tn(w+y),l=tn(d*w),c=tn(c+l),l=tn(v*w),f=tn(g*f),f=tn(f-l),l=tn(g*d),h=tn(v*h),h=tn(h+l),new rn(f,c,h)}mul(t,e=!0){if(!e&&0n===t)return on;if($r(t)||qr("scalar invalid"),this.equals(nn))return Sn(t).p;let r=on,n=nn;for(let i=this;t>0n;i=i.double(),t>>=1n)1n&t?r=r.add(i):e&&(n=n.add(i));return r}mulAddQUns(t,e,r){return this.mul(e,!1).add(t.mul(r,!1)).ok()}toAffine(){const{px:t,py:e,pz:r}=this;if(this.equals(on))return{x:0n,y:0n};if(1n===r)return{x:t,y:e};const n=yn(r,Kr);return 1n!==tn(r*n)&&qr("inverse invalid"),{x:tn(t*n),y:tn(e*n)}}assertValidity(){const{x:t,y:e}=this.aff();return zr(t)&&zr(e)||qr("Point invalid: x or y"),tn(e*e)===Wr(t)?this:qr("Point invalid: not on curve")}multiply(t){return this.mul(t)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(t=!0){const{x:e,y:r}=this.aff();return(t?0n===(1n&r)?"02":"03":"04")+ln(e)+(t?"":ln(r))}toRawBytes(t=!0){return fn(this.toHex(t))}}rn.BASE=new rn(Fr,Gr,1n),rn.ZERO=new rn(0n,1n,0n);const{BASE:nn,ZERO:on}=rn,un=(t,e)=>t.toString(16).padStart(e,"0"),an=t=>Array.from(Jr(t)).map((t=>un(t,2))).join(""),sn=t=>t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0,fn=t=>{const e="hex invalid";if(!Yr(t))return qr(e);const r=t.length,n=r/2;if(r%2)return qr(e);const i=Qr(n);for(let r=0,o=0;r<n;r++,o+=2){const n=sn(t.charCodeAt(o)),u=sn(t.charCodeAt(o+1));if(void 0===n||void 0===u)return qr(e);i[r]=16*n+u}return i},cn=t=>BigInt("0x"+(an(t)||"0")),hn=(t,e,r)=>cn(t.slice(e,r)),pn=t=>Xr(t)&&t>=0n&&t<Dr?fn(un(t,64)):qr("bigint expected"),ln=t=>an(pn(t)),dn=(...t)=>{const e=Qr(t.reduce(((t,e)=>t+Jr(e).length),0));let r=0;return t.forEach((t=>{e.set(t,r),r+=t.length})),e},yn=(t,e)=>{(0n===t||e<=0n)&&qr("no inverse n="+t+" mod="+e);let r=tn(t,e),n=e,i=0n,o=1n,u=1n,a=0n;for(;0n!==r;){const t=n/r,e=n%r,s=i-u*t,f=o-a*t;n=r,r=e,i=u,o=a,u=s,a=f}return 1n===n?tn(i,e):qr("no inverse")},gn=t=>{let e=1n;for(let r=t,n=(Kr+1n)/4n;n>0n;n>>=1n)1n&n&&(e=e*r%Kr),r=r*r%Kr;return tn(e*e)===t?e:qr("sqrt invalid")},wn=t=>(Xr(t)||(t=cn(Zr(t,32))),$r(t)?t:qr("private key invalid 3")),vn=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;let mn;const bn={hexToBytes:fn,bytesToHex:an,concatBytes:dn,bytesToNumberBE:cn,numberToBytesBE:pn,mod:tn,invert:yn,hmacSha256Async:async(t,...e)=>{const r=vn(),n=r&&r.subtle;if(!n)return qr("etc.hmacSha256Async or crypto.subtle must be defined");const i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Qr(await n.sign("HMAC",i,dn(...e)))},hmacSha256Sync:mn,hashToPrivateKey:t=>{((t=Zr(t)).length<40||t.length>1024)&&qr("expected 40-1024b");const e=tn(cn(t),Mr-1n);return pn(e+1n)},randomBytes:(t=32)=>{const e=vn();return e&&e.getRandomValues||qr("crypto.getRandomValues must be defined"),e.getRandomValues(Qr(t))}};let En;Object.defineProperties(bn,{hmacSha256Sync:{configurable:!1,get:()=>mn,set(t){mn||(mn=t)}}});const Sn=t=>{const e=En||(En=(()=>{const t=[];let e=nn,r=e;for(let n=0;n<33;n++){r=e,t.push(r);for(let n=1;n<128;n++)r=r.add(e),t.push(r);e=r.double()}return t})()),r=(t,e)=>{let r=e.negate();return t?r:e};let n=on,i=nn;const o=BigInt(255),u=BigInt(8);for(let a=0;a<33;a++){const s=128*a;let f=Number(t&o);t>>=u,f>128&&(f-=256,t+=1n);const c=s,h=s+Math.abs(f)-1,p=a%2!=0,l=f<0;0===f?i=i.add(r(p,e[c])):n=n.add(r(l,e[h]))}return{p:n,f:i}};var In=r(394),Tn=r(287).hp,_n=W;function kn(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(23)),redeem:it.maybe({network:it.maybe(it.Object),output:it.maybe(it.Buffer),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network;r||(r=t.redeem&&t.redeem.network||p);var n={network:r,name:Wi.P2SH},i=Nr((function(){var e=Tn.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),o=Nr((function(){return jt(t.input)})),u=Nr((function(){var e=o(),n=e[e.length-1];return{network:r,output:n===_n.OP_FALSE?Tn.from([]):n,input:Gt(e.slice(0,-1)),witness:t.witness||[]}}));if(Ur(n,"address",(function(){if(n.hash){var t=Tn.allocUnsafe(21);return t.writeUInt8(n.network.scriptHash,0),n.hash.copy(t,1),F.encode(t)}})),Ur(n,"hash",(function(){return t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?Ke(n.redeem.output):void 0})),Ur(n,"output",(function(){if(n.hash)return Gt([_n.OP_HASH160,n.hash,_n.OP_EQUAL])})),Ur(n,"redeem",(function(){if(t.input)return u()})),Ur(n,"input",(function(){if(t.redeem&&t.redeem.input&&t.redeem.output)return Gt([].concat(jt(t.redeem.input),t.redeem.output))})),Ur(n,"witness",(function(){return n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0})),Ur(n,"name",(function(){var t=["p2sh"];return void 0!==n.redeem&&void 0!==n.redeem.name&&t.push(n.redeem.name),t.join("-")})),e.validate){var a=Tn.from([]);if(t.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");a=i().hash}if(t.hash){if(a.length>0&&!a.equals(t.hash))throw new TypeError("Hash mismatch");a=t.hash}if(t.output){if(23!==t.output.length||t.output[0]!==_n.OP_HASH160||20!==t.output[1]||t.output[22]!==_n.OP_EQUAL)throw new TypeError("Output is invalid");var s=t.output.slice(2,22);if(a.length>0&&!a.equals(s))throw new TypeError("Hash mismatch");a=s}var f=function(t){if(t.output){var e=jt(t.output);if(!e||e.length<1)throw new TypeError("Redeem.output too short");if(t.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(Dt(e)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");var r=Ke(t.output);if(a.length>0&&!a.equals(r))throw new TypeError("Hash mismatch");a=r}if(t.input){var n=t.input.length>0,i=t.witness&&t.witness.length>0;if(!n&&!i)throw new TypeError("Empty input");if(n&&i)throw new TypeError("Input and witness provided");if(n&&!Vt(jt(t.input)))throw new TypeError("Non push-only scriptSig")}};if(t.input){var c=o();if(!c||c.length<1)throw new TypeError("Input too short");if(!Tn.isBuffer(u().output))throw new TypeError("Input is invalid");f(u())}if(t.redeem){if(t.redeem.network&&t.redeem.network!==r)throw new TypeError("Network mismatch");if(t.input){var h=u();if(t.redeem.output&&!t.redeem.output.equals(h.output))throw new TypeError("Redeem.output mismatch");if(t.redeem.input&&!t.redeem.input.equals(h.input))throw new TypeError("Redeem.input mismatch")}f(t.redeem)}if(t.witness&&t.redeem&&t.redeem.witness&&!at(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var An=W,On=1,Pn=80;function Un(t,e){if(!(t.address||t.output||t.pubkey||t.internalPubkey||t.witness&&t.witness.length>1))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(34)),internalPubkey:it.maybe(it.BufferN(32)),hash:it.maybe(it.BufferN(32)),pubkey:it.maybe(it.BufferN(32)),signature:it.maybe(it.anyOf(it.BufferN(64),it.BufferN(65))),witness:it.maybe(it.arrayOf(it.Buffer)),scriptTree:it.maybe(pt),redeem:it.maybe({output:it.maybe(it.Buffer),redeemVersion:it.maybe(it.Number),witness:it.maybe(it.arrayOf(it.Buffer))}),redeemVersion:it.maybe(it.Number)},t);var r=Nr((function(){return he(t.address)})),n=Nr((function(){if(t.witness&&t.witness.length)return t.witness.length>=2&&t.witness[t.witness.length-1][0]===Pn?t.witness.slice(0,-1):t.witness.slice()})),i=Nr((function(){return t.scriptTree?Tr(t.scriptTree):t.hash?{hash:t.hash}:void 0})),o=t.network||p,u={name:Wi.P2TR,network:o};if(Ur(u,"address",(function(){if(u.pubkey){var t=I.p2.toWords(u.pubkey);return t.unshift(On),I.p2.encode(o.bech32,t)}})),Ur(u,"hash",(function(){var t=i();if(t)return t.hash;var e=n();if(e&&e.length>1){var r=e[e.length-1],o=r[0]&ct;return Ir(r,kr({output:e[e.length-2],version:o}))}})),Ur(u,"output",(function(){if(u.pubkey)return Gt([An.OP_1,u.pubkey])})),Ur(u,"redeemVersion",(function(){return t.redeemVersion?t.redeemVersion:t.redeem&&void 0!==t.redeem.redeemVersion&&null!==t.redeem.redeemVersion?t.redeem.redeemVersion:br})),Ur(u,"redeem",(function(){var t=n();if(t&&!(t.length<2))return{output:t[t.length-2],witness:t.slice(0,-2),redeemVersion:t[t.length-1][0]&ct}})),Ur(u,"pubkey",(function(){if(t.pubkey)return t.pubkey;if(t.output)return t.output.slice(2);if(t.address)return r().data;if(u.internalPubkey){var e=Or(u.internalPubkey,u.hash);if(e)return e.x}})),Ur(u,"internalPubkey",(function(){if(t.internalPubkey)return t.internalPubkey;var e=n();return e&&e.length>1?e[e.length-1].slice(1,33):void 0})),Ur(u,"signature",(function(){if(t.signature)return t.signature;var e=n();return e&&1===e.length?e[0]:void 0})),Ur(u,"witness",(function(){if(t.witness)return t.witness;var e=i();if(e&&t.redeem&&t.redeem.output&&t.internalPubkey){var r=_r(e,kr({output:t.redeem.output,version:u.redeemVersion}));if(!r)return;var n=Or(t.internalPubkey,e.hash);if(!n)return;var o=rt.hp.concat([rt.hp.from([u.redeemVersion|n.parity]),t.internalPubkey].concat(r));return[t.redeem.output,o]}return t.signature?[t.signature]:void 0})),e.validate){var a=rt.hp.from([]);if(t.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==On)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");a=r().data}if(t.pubkey){if(a.length>0&&!a.equals(t.pubkey))throw new TypeError("Pubkey mismatch");a=t.pubkey}if(t.output){if(34!==t.output.length||t.output[0]!==An.OP_1||32!==t.output[1])throw new TypeError("Output is invalid");if(a.length>0&&!a.equals(t.output.slice(2)))throw new TypeError("Pubkey mismatch");a=t.output.slice(2)}if(t.internalPubkey){var s=Or(t.internalPubkey,u.hash);if(a.length>0&&!a.equals(s.x))throw new TypeError("Pubkey mismatch");a=s.x}var f=i();if(t.hash&&f&&!t.hash.equals(f.hash))throw new TypeError("Hash mismatch");if(t.redeem&&t.redeem.output&&f&&!_r(f,kr({output:t.redeem.output,version:u.redeemVersion})))throw new TypeError("Redeem script not in tree");var c=n();if(t.redeem&&u.redeem){if(t.redeem.redeemVersion&&t.redeem.redeemVersion!==u.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(t.redeem.output){if(0===jt(t.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(u.redeem.output&&!t.redeem.output.equals(u.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(t.redeem.witness&&u.redeem.witness&&!at(t.redeem.witness,u.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(c&&c.length)if(1===c.length){if(t.signature&&!t.signature.equals(c[0]))throw new TypeError("Signature mismatch")}else{var h=c[c.length-1];if(h.length<33)throw new TypeError("The control-block length is too small. Got ".concat(h.length,", expected min 33."));if((h.length-33)%32!=0)throw new TypeError("The control-block length of ".concat(h.length," is incorrect!"));var l=(h.length-33)/32;if(l>128)throw new TypeError("The script path is too long. Got ".concat(l,", expected max 128."));var d=h.slice(1,33);if(t.internalPubkey&&!t.internalPubkey.equals(d))throw new TypeError("Internal pubkey mismatch");if(!Ye().isXOnlyPoint(d))throw new TypeError("Invalid internalPubkey for p2tr witness");var y=h[0]&ct,g=Or(d,Ir(h,kr({output:c[c.length-2],version:y})));if(!g)throw new TypeError("Invalid outputKey for p2tr witness");if(a.length&&!a.equals(g.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(g.parity!==(1&h[0]))throw new Error("Incorrect parity")}}return Object.assign(u,t)}var Nn=r(287).hp,xn=W,Bn=Nn.alloc(0);function Cn(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(22)),pubkey:it.maybe(st),signature:it.maybe($t),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Nr((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Nn.from(n)}})),n=t.network||p,i={name:Wi.P2WPKH,network:n};if(Ur(i,"address",(function(){if(i.hash){var t=I.I.toWords(i.hash);return t.unshift(0),I.I.encode(n.bech32,t)}})),Ur(i,"hash",(function(){return t.output?t.output.slice(2,22):t.address?r().data:t.pubkey||i.pubkey?Ke(t.pubkey||i.pubkey):void 0})),Ur(i,"output",(function(){if(i.hash)return Gt([xn.OP_0,i.hash])})),Ur(i,"pubkey",(function(){return t.pubkey?t.pubkey:t.witness?t.witness[1]:void 0})),Ur(i,"signature",(function(){if(t.witness)return t.witness[0]})),Ur(i,"input",(function(){if(i.witness)return Bn})),Ur(i,"witness",(function(){if(t.pubkey&&t.signature)return[t.signature,t.pubkey]})),e.validate){var o=Nn.from([]);if(t.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");o=r().data}if(t.hash){if(o.length>0&&!o.equals(t.hash))throw new TypeError("Hash mismatch");o=t.hash}if(t.output){if(22!==t.output.length||t.output[0]!==xn.OP_0||20!==t.output[1])throw new TypeError("Output is invalid");if(o.length>0&&!o.equals(t.output.slice(2)))throw new TypeError("Hash mismatch");o=t.output.slice(2)}if(t.pubkey){var u=Ke(t.pubkey);if(o.length>0&&!o.equals(u))throw new TypeError("Hash mismatch");if(o=u,!st(t.pubkey)||33!==t.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(t.witness){if(2!==t.witness.length)throw new TypeError("Witness is invalid");if(!$t(t.witness[0]))throw new TypeError("Witness has invalid signature");if(!st(t.witness[1])||33!==t.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(t.signature&&!t.signature.equals(t.witness[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(t.witness[1]))throw new TypeError("Pubkey mismatch");var a=Ke(t.witness[1]);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(i,t)}var Hn=r(287).hp,Rn=W,Ln=Hn.alloc(0);function Vn(t){return!(!Hn.isBuffer(t)||65!==t.length||4!==t[0]||!st(t))}function Dn(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(32)),output:it.maybe(it.BufferN(34)),redeem:it.maybe({input:it.maybe(it.Buffer),network:it.maybe(it.Object),output:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.BufferN(0)),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Nr((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Hn.from(n)}})),n=Nr((function(){return jt(t.redeem.input)})),i=t.network;i||(i=t.redeem&&t.redeem.network||p);var o={network:i,name:Wi.P2WSH};if(Ur(o,"address",(function(){if(o.hash){var t=I.I.toWords(o.hash);return t.unshift(0),I.I.encode(i.bech32,t)}})),Ur(o,"hash",(function(){return t.output?t.output.slice(2):t.address?r().data:o.redeem&&o.redeem.output?De(o.redeem.output):void 0})),Ur(o,"output",(function(){if(o.hash)return Gt([Rn.OP_0,o.hash])})),Ur(o,"redeem",(function(){if(t.witness)return{output:t.witness[t.witness.length-1],input:Ln,witness:t.witness.slice(0,-1)}})),Ur(o,"input",(function(){if(o.witness)return Ln})),Ur(o,"witness",(function(){if(t.redeem&&t.redeem.input&&t.redeem.input.length>0&&t.redeem.output&&t.redeem.output.length>0){var e=Xt(n());return o.redeem=Object.assign({witness:e},t.redeem),o.redeem.input=Ln,[].concat(e,t.redeem.output)}if(t.redeem&&t.redeem.output&&t.redeem.witness)return[].concat(t.redeem.witness,t.redeem.output)})),Ur(o,"name",(function(){var t=["p2wsh"];return void 0!==o.redeem&&void 0!==o.redeem.name&&t.push(o.redeem.name),t.join("-")})),e.validate){var u=Hn.from([]);if(t.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");u=r().data}if(t.hash){if(u.length>0&&!u.equals(t.hash))throw new TypeError("Hash mismatch");u=t.hash}if(t.output){if(34!==t.output.length||t.output[0]!==Rn.OP_0||32!==t.output[1])throw new TypeError("Output is invalid");var a=t.output.slice(2);if(u.length>0&&!u.equals(a))throw new TypeError("Hash mismatch");u=a}if(t.redeem){if(t.redeem.network&&t.redeem.network!==i)throw new TypeError("Network mismatch");if(t.redeem.input&&t.redeem.input.length>0&&t.redeem.witness&&t.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(t.redeem.output){var s=jt(t.redeem.output);if(!s||s.length<1)throw new TypeError("Redeem.output is invalid");if(t.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Dt(s)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");var f=De(t.redeem.output);if(u.length>0&&!u.equals(f))throw new TypeError("Hash mismatch");u=f}if(t.redeem.input&&!Vt(n()))throw new TypeError("Non push-only scriptSig");if(t.witness&&t.redeem.witness&&!at(t.witness,t.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(t.redeem.input&&n().some(Vn)||t.redeem.output&&(jt(t.redeem.output)||[]).some(Vn))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(t.witness&&t.witness.length>0){var c=t.witness[t.witness.length-1];if(t.redeem&&t.redeem.output&&!t.redeem.output.equals(c))throw new TypeError("Witness and redeem.output mismatch");if(t.witness.some(Vn)||(jt(c)||[]).some(Vn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,t)}var Kn=r(287).hp;function Mn(t){return Mn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Mn(t)}function Fn(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,jn(n.key),n)}}function Gn(t,e,r){return(e=jn(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function jn(t){var e=function(t){if("object"!=Mn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Mn(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Mn(e)?e:e+""}var Wn=it;function qn(t){var e=t.length;return nr(e)+e}var Xn=Kn.allocUnsafe(0),Yn=[],zn=Kn.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),$n=Kn.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Jn=Kn.from("ffffffffffffffff","hex"),Qn={script:Xn,valueBuffer:Jn},Zn=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Gn(this,"version",1),Gn(this,"locktime",0),Gn(this,"ins",[]),Gn(this,"outs",[])}return e=t,r=[{key:"isCoinbase",value:function(){return 1===this.ins.length&&t.isCoinbaseHash(this.ins[0].hash)}},{key:"addInput",value:function(e,r,n,i){return Wn(Et(dt,It,bt(It),bt(vt)),arguments),kt(n)&&(n=t.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:r,script:i||Xn,sequence:n,witness:Yn})-1}},{key:"addOutput",value:function(t,e){return Wn(Et(vt,ft),arguments),this.outs.push({script:t,value:e})-1}},{key:"hasWitnesses",value:function(){return this.ins.some((function(t){return 0!==t.witness.length}))}},{key:"weight",value:function(){return 3*this.byteLength(!1)+this.byteLength(!0)}},{key:"virtualSize",value:function(){return Math.ceil(this.weight()/4)}},{key:"byteLength",value:function(){var t=(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&this.hasWitnesses();return(t?10:8)+nr(this.ins.length)+nr(this.outs.length)+this.ins.reduce((function(t,e){return t+40+qn(e.script)}),0)+this.outs.reduce((function(t,e){return t+8+qn(e.script)}),0)+(t?this.ins.reduce((function(t,e){return t+(nr((r=e.witness).length)+r.reduce((function(t,e){return t+qn(e)}),0));var r}),0):0)}},{key:"clone",value:function(){var e=new t;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map((function(t){return{hash:t.hash,index:t.index,script:t.script,sequence:t.sequence,witness:t.witness}})),e.outs=this.outs.map((function(t){return{script:t.script,value:t.value}})),e}},{key:"hashForSignature",value:function(e,r,n){if(Wn(Et(It,vt,yt),arguments),e>=this.ins.length)return $n;var i=Gt(jt(r).filter((function(t){return t!==W.OP_CODESEPARATOR}))),o=this.clone();if((31&n)===t.SIGHASH_NONE)o.outs=[],o.ins.forEach((function(t,r){r!==e&&(t.sequence=0)}));else if((31&n)===t.SIGHASH_SINGLE){if(e>=this.outs.length)return $n;o.outs.length=e+1;for(var u=0;u<e;u++)o.outs[u]=Qn;o.ins.forEach((function(t,r){r!==e&&(t.sequence=0)}))}n&t.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[e]],o.ins[0].script=i):(o.ins.forEach((function(t){t.script=Xn})),o.ins[e].script=i);var a=Kn.allocUnsafe(o.byteLength(!1)+4);return a.writeInt32LE(n,a.length-4),o.__toBuffer(a,0,!1),Me(a)}},{key:"hashForWitnessV1",value:function(e,r,n,i,o,u){if(Wn(Et(It,Wn.arrayOf(vt),Wn.arrayOf(ft),It),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");var a=i===t.SIGHASH_DEFAULT?t.SIGHASH_ALL:i&t.SIGHASH_OUTPUT_MASK,s=(i&t.SIGHASH_INPUT_MASK)===t.SIGHASH_ANYONECANPAY,f=a===t.SIGHASH_NONE,c=a===t.SIGHASH_SINGLE,h=Xn,p=Xn,l=Xn,d=Xn,y=Xn;if(!s){var g=gr.withCapacity(36*this.ins.length);this.ins.forEach((function(t){g.writeSlice(t.hash),g.writeUInt32(t.index)})),h=De(g.end()),g=gr.withCapacity(8*this.ins.length),n.forEach((function(t){return g.writeUInt64(t)})),p=De(g.end()),g=gr.withCapacity(r.map(qn).reduce((function(t,e){return t+e}))),r.forEach((function(t){return g.writeVarSlice(t)})),l=De(g.end()),g=gr.withCapacity(4*this.ins.length),this.ins.forEach((function(t){return g.writeUInt32(t.sequence)})),d=De(g.end())}if(f||c){if(c&&e<this.outs.length){var w=this.outs[e],v=gr.withCapacity(8+qn(w.script));v.writeUInt64(w.value),v.writeVarSlice(w.script),y=De(v.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");var m=this.outs.map((function(t){return 8+qn(t.script)})).reduce((function(t,e){return t+e})),b=gr.withCapacity(m);this.outs.forEach((function(t){b.writeUInt64(t.value),b.writeVarSlice(t.script)})),y=De(b.end())}var E=(o?2:0)+(u?1:0),S=174-(s?49:0)-(f?32:0)+(u?32:0)+(o?37:0),I=gr.withCapacity(S);if(I.writeUInt8(i),I.writeInt32(this.version),I.writeUInt32(this.locktime),I.writeSlice(h),I.writeSlice(p),I.writeSlice(l),I.writeSlice(d),f||c||I.writeSlice(y),I.writeUInt8(E),s){var T=this.ins[e];I.writeSlice(T.hash),I.writeUInt32(T.index),I.writeUInt64(n[e]),I.writeVarSlice(r[e]),I.writeUInt32(T.sequence)}else I.writeUInt32(e);if(u){var _=gr.withCapacity(qn(u));_.writeVarSlice(u),I.writeSlice(De(_.end()))}return c&&I.writeSlice(y),o&&(I.writeSlice(o),I.writeUInt8(0),I.writeUInt32(4294967295)),je("TapSighash",Kn.concat([Kn.from([0]),I.end()]))}},{key:"hashForWitnessV0",value:function(e,r,n,i){Wn(Et(It,vt,ft,It),arguments);var o,u=Kn.from([]),a=zn,s=zn,f=zn;if(i&t.SIGHASH_ANYONECANPAY||(u=Kn.allocUnsafe(36*this.ins.length),o=new gr(u,0),this.ins.forEach((function(t){o.writeSlice(t.hash),o.writeUInt32(t.index)})),s=Me(u)),i&t.SIGHASH_ANYONECANPAY||(31&i)===t.SIGHASH_SINGLE||(31&i)===t.SIGHASH_NONE||(u=Kn.allocUnsafe(4*this.ins.length),o=new gr(u,0),this.ins.forEach((function(t){o.writeUInt32(t.sequence)})),f=Me(u)),(31&i)!==t.SIGHASH_SINGLE&&(31&i)!==t.SIGHASH_NONE){var c=this.outs.reduce((function(t,e){return t+8+qn(e.script)}),0);u=Kn.allocUnsafe(c),o=new gr(u,0),this.outs.forEach((function(t){o.writeUInt64(t.value),o.writeVarSlice(t.script)})),a=Me(u)}else if((31&i)===t.SIGHASH_SINGLE&&e<this.outs.length){var h=this.outs[e];u=Kn.allocUnsafe(8+qn(h.script)),(o=new gr(u,0)).writeUInt64(h.value),o.writeVarSlice(h.script),a=Me(u)}u=Kn.allocUnsafe(156+qn(r)),o=new gr(u,0);var p=this.ins[e];return o.writeInt32(this.version),o.writeSlice(s),o.writeSlice(f),o.writeSlice(p.hash),o.writeUInt32(p.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(p.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Me(u)}},{key:"getHash",value:function(t){return t&&this.isCoinbase()?Kn.alloc(32,0):Me(this.__toBuffer(void 0,void 0,t))}},{key:"getId",value:function(){return dr(this.getHash(!1)).toString("hex")}},{key:"toBuffer",value:function(t,e){return this.__toBuffer(t,e,!0)}},{key:"toHex",value:function(){return this.toBuffer(void 0,void 0).toString("hex")}},{key:"setInputScript",value:function(t,e){Wn(Et(yt,vt),arguments),this.ins[t].script=e}},{key:"setWitness",value:function(t,e){Wn(Et(yt,[vt]),arguments),this.ins[t].witness=e}},{key:"__toBuffer",value:function(e,r){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];e||(e=Kn.allocUnsafe(this.byteLength(n)));var i=new gr(e,r||0);i.writeInt32(this.version);var o=n&&this.hasWitnesses();return o&&(i.writeUInt8(t.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(t.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach((function(t){i.writeSlice(t.hash),i.writeUInt32(t.index),i.writeVarSlice(t.script),i.writeUInt32(t.sequence)})),i.writeVarInt(this.outs.length),this.outs.forEach((function(t){void 0!==t.value?i.writeUInt64(t.value):i.writeSlice(t.valueBuffer),i.writeVarSlice(t.script)})),o&&this.ins.forEach((function(t){i.writeVector(t.witness)})),i.writeUInt32(this.locktime),void 0!==r?e.slice(r,i.offset):e}}],n=[{key:"fromBuffer",value:function(e,r){var n=new wr(e),i=new t;i.version=n.readInt32();var o=n.readUInt8(),u=n.readUInt8(),a=!1;o===t.ADVANCED_TRANSACTION_MARKER&&u===t.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;for(var s=n.readVarInt(),f=0;f<s;++f){var c=n.readSlice(32),h=n.readUInt32(),p=n.readVarSlice(),l=n.readUInt32();i.ins.push({hash:c,index:h,script:p,sequence:l,witness:Yn})}for(var d=n.readVarInt(),y=0;y<d;++y)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(var g=0;g<s;++g)i.ins[g].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==e.length)throw new Error("Transaction has unexpected data");return i}},{key:"fromHex",value:function(e){return t.fromBuffer(Kn.from(e,"hex"),!1)}},{key:"isCoinbaseHash",value:function(t){Wn(dt,t);for(var e=0;e<32;++e)if(0!==t[e])return!1;return!0}}],r&&Fn(e.prototype,r),n&&Fn(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();Gn(Zn,"DEFAULT_SEQUENCE",4294967295),Gn(Zn,"SIGHASH_DEFAULT",0),Gn(Zn,"SIGHASH_ALL",1),Gn(Zn,"SIGHASH_NONE",2),Gn(Zn,"SIGHASH_SINGLE",3),Gn(Zn,"SIGHASH_ANYONECANPAY",128),Gn(Zn,"SIGHASH_OUTPUT_MASK",3),Gn(Zn,"SIGHASH_INPUT_MASK",128),Gn(Zn,"ADVANCED_TRANSACTION_MARKER",0),Gn(Zn,"ADVANCED_TRANSACTION_FLAG",1);var ti=r(287).hp;function ei(t,e){if(t){if("string"==typeof t)return ri(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ri(t,e):void 0}}function ri(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ni=function(t){var e=32===t.length?t:t.slice(1,33);return ti.isBuffer(e)?e:ti.from(e)};function ii(t,e,r){var n=function(t,e,r){if(!t.tapScriptSig||!t.tapScriptSig.length)throw new Error("Can not finalize taproot input #".concat(e,". No tapleaf script signature provided."));var n=(t.tapLeafScript||[]).sort((function(t,e){return t.controlBlock.length-e.controlBlock.length})).find((function(e){return function(t,e,r){var n=kr({output:t.script,version:t.leafVersion});return(!r||r.equals(n))&&void 0!==e.find((function(t){return t.leafHash.equals(n)}))}(e,t.tapScriptSig,r)}));if(!n)throw new Error("Can not finalize taproot input #".concat(e,". Signature for tapleaf script not found."));return n}(e,t,r);try{var i=function(t,e){var r=kr({output:e.script,version:e.leafVersion});return(t.tapScriptSig||[]).filter((function(t){return t.leafHash.equals(r)})).map((function(t){return function(t,e){return Object.assign({positionInScript:Ki(e.pubkey,t)},e)}(e.script,t)})).sort((function(t,e){return e.positionInScript-t.positionInScript})).map((function(t){return t.signature}))}(e,n);return{finalScriptWitness:Ri(i.concat(n.script).concat(n.controlBlock))}}catch(e){throw new Error("Can not finalize taproot input #".concat(t,": ").concat(e))}}function oi(t,e){var r=e?ti.from([e]):ti.from([]);return ti.concat([t,r])}function ui(t){return t&&!!(t.tapInternalKey||t.tapMerkleRoot||t.tapLeafScript&&t.tapLeafScript.length||t.tapBip32Derivation&&t.tapBip32Derivation.length||t.witnessUtxo&&Ci(t.witnessUtxo.script))}function ai(t,e){return t&&!!(t.tapInternalKey||t.tapTree||t.tapBip32Derivation&&t.tapBip32Derivation.length||e&&Ci(e))}function si(t,e,r){!function(t,e,r){var n=ui(t)&&mi(e),i=mi(t)&&ui(e),o=t===e&&ui(e)&&mi(e);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}(t,e,r),function(t,e,r){if(e.tapMerkleRoot){var n=(e.tapLeafScript||[]).every((function(t){return vi(t,e.tapMerkleRoot)})),i=(t.tapLeafScript||[]).every((function(t){return vi(t,e.tapMerkleRoot)}));if(!n||!i)throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}else if(t.tapMerkleRoot&&!(e.tapLeafScript||[]).every((function(e){return vi(e,t.tapMerkleRoot)})))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}(t,e,r)}function fi(t,e,r){!function(t,e,r){var n=ai(t)&&mi(e),i=mi(t)&&ai(e),o=t===e&&ai(e)&&mi(e);if(n||i||o)throw new Error("Invalid arguments for Psbt.".concat(r,". ")+"Cannot use both taproot and non-taproot fields.")}(t,e,r),function(t,e){if(e.tapTree||e.tapInternalKey){var r=e.tapInternalKey||t.tapInternalKey,n=e.tapTree||t.tapTree;if(r){var i=t.script,o=function(t,e){return Un({internalPubkey:t,scriptTree:e&&pi(e.leaves)}).output}(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}}(t,e)}function ci(t,e){var r=e.tapInternalKey,n=r&&Or(r,e.tapMerkleRoot);if(!n)throw new Error("Cannot tweak tap internal key for input #".concat(t,". Public key: ").concat(r&&r.toString("hex")));return n.x}function hi(t){if(!pt(t))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return gi(t)}function pi(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 1===t.length&&0===t[0].depth?{output:t[0].script,version:t[0].leafVersion}:function(t){var e,r,n=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=ei(t))){e&&(t=e);var r=0,n=function(){};return{s:n,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,u=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return o=t.done,t},e:function(t){u=!0,i=t},f:function(){try{o||null==e.return||e.return()}finally{if(u)throw i}}}}(t);try{for(n.s();!(r=n.n()).done;)if(!(e=wi(r.value,e)))throw new Error("No room left to insert tapleaf in tree")}catch(t){n.e(t)}finally{n.f()}return e}(t)}function li(t,e){var r=function(t){var e,r=[];if(t.tapKeySig&&r.push(t.tapKeySig),t.tapScriptSig&&r.push.apply(r,function(t){if(Array.isArray(t))return ri(t)}(e=t.tapScriptSig.map((function(t){return t.signature})))||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||ei(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),!r.length){var n=yi(t.finalScriptWitness);n&&r.push(n)}return r}(t);return r.some((function(t){return Gi(t,di,e)}))}function di(t){return{signature:t.slice(0,64),hashType:t.slice(64)[0]||Zn.SIGHASH_DEFAULT}}function yi(t){if(t){var e=t.slice(2);return 64===e.length||65===e.length?e:void 0}}function gi(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>Er)throw new Error("Max taptree depth exceeded.");return t?ht(t)?(e.push({depth:r,leafVersion:t.version||br,script:t.output}),e):(t[0]&&gi(t[0],e,r+1),t[1]&&gi(t[1],e,r+1),e):[]}function wi(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>Er)throw new Error("Max taptree depth exceeded.");if(t.depth===r)return e?void 0:{output:t.script,version:t.leafVersion};if(!ht(e)){var n=wi(t,e&&e[0],r+1);if(n)return[n,e&&e[1]];var i=wi(t,e&&e[1],r+1);return i?[e&&e[0],i]:void 0}}function vi(t,e){if(!e)return!0;var r=kr({output:t.script,version:t.leafVersion});return Ir(t.controlBlock,r).equals(e)}function mi(t){return t&&!!(t.redeemScript||t.witnessScript||t.bip32Derivation&&t.bip32Derivation.length)}var bi=r(287).hp,Ei=W,Si=16,Ii=2,Ti=40;function _i(t,e){if(!(t.address||t.output||t.program||void 0!==t.deploymentVersion&&t.hash160))throw new TypeError("At least one of address, output or program must be provided");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),output:it.maybe(it.Buffer),program:it.maybe(it.Buffer),network:it.maybe(it.Object),deploymentVersion:it.maybe(it.Number),hash160:it.maybe(it.BufferN(20))},t);var r=function(){if(void 0!==t.deploymentVersion&&void 0!==t.hash160){if(20!==t.hash160.length)throw new TypeError("hash160 must be exactly 20 bytes");if(t.deploymentVersion<0||t.deploymentVersion>255)throw new TypeError("deploymentVersion must fit in one byte");return bi.concat([bi.of(t.deploymentVersion),t.hash160])}},n=Nr((function(){return he(t.address)})),i=t.network||p,o={name:Wi.P2OP,network:i,deploymentVersion:0};if(Ur(o,"program",(function(){if(t.program)return t.program;var e=r();if(e)return e;if(t.output){if(t.output[0]!==Ei.OP_16)throw new TypeError("Invalid P2OP script");var i,o=1;if(t.output[1]<76)i=t.output[1],o=2;else{if(76!==t.output[1])throw new TypeError("Unsupported push opcode in P2OP script");i=t.output[2],o=3}return t.output.slice(o,o+i)}return t.address?n().data:void 0})),Ur(o,"deploymentVersion",(function(){if(o.program)return o.program[0]})),Ur(o,"hash160",(function(){if(o.program)return o.program.slice(1)})),Ur(o,"output",(function(){if(o.program)return Gt([Ei.OP_16,o.program])})),Ur(o,"address",(function(){if(o.program){if(!i.bech32Opnet)throw new TypeError("Network does not support opnet");var t=I.p2.toWords(o.program);return t.unshift(Si),I.p2.encode(i.bech32Opnet,t)}})),e.validate){var u=rt.hp.alloc(0);if(t.address){var a=n();if(i.bech32Opnet!==a.prefix)throw new TypeError("Invalid prefix or network mismatch");if(a.version!==Si)throw new TypeError("Invalid witness version for p2op");if(a.data.length<Ii||a.data.length>Ti)throw new TypeError("Invalid witness program length");u=a.data}if(t.program){if(u.length&&!u.equals(t.program))throw new TypeError("Program mismatch");u=t.program}if(!u.length&&void 0!==t.deploymentVersion&&t.hash160&&(u=r()),t.output){var s=o.program;if(u.length&&!u.equals(s))throw new TypeError("Program mismatch (output vs other source)");u=s}if(u.length<Ii||u.length>Ti)throw new TypeError("Witness program must be 2–40 bytes. Was ".concat(u.length," bytes"));if(void 0!==t.deploymentVersion&&t.deploymentVersion!==u[0])throw new TypeError("deploymentVersion mismatch");if(t.hash160&&!t.hash160.equals(u.slice(1)))throw new TypeError("hash160 mismatch")}return Object.assign(o,t)}var ki=r(287).hp;function Ai(t){return function(e){try{return t({output:e}),!0}catch(t){return!1}}}var Oi=Ai(Rr),Pi=Ai(Vr),Ui=Ai(Yi),Ni=Ai(Cn),xi=Ai(Dn),Bi=Ai(kn),Ci=Ai(Un),Hi=Ai(_i);function Ri(t){var e,r=ki.allocUnsafe(0);function n(t){var e=r.length,n=In.encodingLength(t);r=ki.concat([r,ki.allocUnsafe(n)]),In.encode(t,r,e)}return n((e=t).length),e.forEach((function(t){n(t.length),function(t){r=ki.concat([r,ki.from(t)])}(t)})),r}function Li(t){if(32!==t.length){if([33,65].includes(t.length)){var e;try{e=rn.fromHex(t)}catch(t){throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}var r=Vi(e.x),n=Vi(e.y),i=e.y%2n===0n?6:7,o=ki.alloc(65);return o[0]=i,r.copy(o,1),n.copy(o,33),{hybrid:o,uncompressed:ki.concat([ki.from([4]),r,n])}}console.warn("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed)."))}}function Vi(t){var e=t.toString(16);return(e=e.padStart(64,"0")).length>64&&(e=e.slice(-64)),ki.from(e,"hex")}function Di(t,e){if(t.equals(e))return!0;if(65===t.length&&65===e.length){var r=ki.from(t),n=ki.from(e);return 6!==r[0]&&7!==r[0]||(r[0]=4),6!==n[0]&&7!==n[0]||(n[0]=4),r.equals(n)}return!1}function Ki(t,e){var r=jt(e);if(null===r)throw new Error("Unknown script error");var n=Ke(t),i=ni(t),o=Li(t),u=null!=o&&o.hybrid?Ke(o.hybrid):void 0,a=null!=o&&o.uncompressed?Ke(o.uncompressed):void 0;return r.findIndex((function(e){if("number"==typeof e)return!1;if(Di(e,t))return!0;if(Di(e,i))return!0;if(e.equals(n))return!0;if(o){if(Di(e,o.uncompressed))return!0;if(Di(e,o.hybrid))return!0;if(u&&e.equals(u)||a&&e.equals(a))return!0}}))}function Mi(t,e){return-1!==Ki(t,e)}function Fi(t,e){var r=function(t){var e=[];if(0===(t.partialSig||[]).length){if(!t.finalScriptSig&&!t.finalScriptWitness)return[];e=ji(t)}else e=t.partialSig;return e.map((function(t){return t.signature}))}(t);return r.some((function(t){return Gi(t,Qt.decode,e)}))}function Gi(t,e,r){var n=e(t).hashType,i=[];switch(n&Zn.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case Zn.SIGHASH_ALL:break;case Zn.SIGHASH_SINGLE:case Zn.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function ji(t){var e=t.finalScriptSig&&jt(t.finalScriptSig)||[],r=t.finalScriptWitness&&jt(t.finalScriptWitness)||[];return e.concat(r).filter((function(t){return ki.isBuffer(t)&&$t(t)})).map((function(t){return{signature:t}}))}var Wi,qi=r(287).hp,Xi=W;function Yi(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(25)),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Nr((function(){var e=qi.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),n=Nr((function(){return jt(t.input)})),i=t.network||p,o={name:Wi.P2PKH,network:i,hash:void 0};if(Ur(o,"address",(function(){if(o.hash){var t=qi.allocUnsafe(21);return t.writeUInt8(i.pubKeyHash,0),o.hash.copy(t,1),F.encode(t)}})),Ur(o,"hash",(function(){return t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?Ke(t.pubkey||o.pubkey):void 0})),Ur(o,"output",(function(){if(o.hash)return Gt([Xi.OP_DUP,Xi.OP_HASH160,o.hash,Xi.OP_EQUALVERIFY,Xi.OP_CHECKSIG])})),Ur(o,"pubkey",(function(){if(t.input)return n()[1]})),Ur(o,"signature",(function(){if(t.input)return n()[0]})),Ur(o,"input",(function(){if(t.pubkey&&t.signature){var e=t.pubkey;if(t.useHybrid||t.useUncompressed){var r=Li(t.pubkey);r&&(e=t.useUncompressed?r.uncompressed:r.hybrid)}return Gt([t.signature,e])}})),Ur(o,"witness",(function(){if(o.input)return[]})),e.validate){var u=qi.from([]);if(t.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");u=r().hash}if(t.hash){if(u.length>0&&!u.equals(t.hash))throw new TypeError("Hash mismatch");u=t.hash}if(t.output){if(25!==t.output.length||t.output[0]!==Xi.OP_DUP||t.output[1]!==Xi.OP_HASH160||20!==t.output[2]||t.output[23]!==Xi.OP_EQUALVERIFY||t.output[24]!==Xi.OP_CHECKSIG)throw new TypeError("Output is invalid");var a=t.output.slice(3,23);if(u.length>0&&!u.equals(a))throw new TypeError("Hash mismatch");u=a}if(t.pubkey){var s=Ke(t.pubkey),f=u.length>0&&!u.equals(s);if(f&&(33===t.pubkey.length&&(2===t.pubkey[0]||3===t.pubkey[0])||65===t.pubkey.length&&4===t.pubkey[0])){var c=Li(t.pubkey);if(c){var h=Ke(c.uncompressed);if(u.equals(h))f=!1,t.useUncompressed=!0;else{var l=Ke(c.hybrid);(f=!u.equals(l))||(t.useHybrid=!0)}}}if(f)throw new TypeError("Hash mismatch");u=s}if(t.input){var d=n();if(2!==d.length)throw new TypeError("Input is invalid");if(!$t(d[0]))throw new TypeError("Input has invalid signature");if(!st(d[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&!t.signature.equals(d[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(d[1]))throw new TypeError("Pubkey mismatch");var y=Ke(d[1]);if(u.length>0&&!u.equals(y))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,t)}!function(t){t.P2PK="p2pk",t.P2PKH="p2pkh",t.P2SH="p2sh",t.P2MS="p2ms",t.P2WPKH="p2wpkh",t.P2WSH="p2wsh",t.P2TR="p2tr",t.P2OP="p2op",t.Embed="embed",t.ScriptRedeem="scriptRedeem"}(Wi||(Wi={}));var zi=r(287).hp,$i=r(287).hp;function Ji(t){return Ji="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ji(t)}function Qi(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,to(n.key),n)}}function Zi(t,e,r){return(e=to(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function to(t){var e=function(t){if("object"!=Ji(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Ji(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ji(e)?e:e+""}var eo=it,ro=new TypeError("Cannot compute merkle root for zero transactions"),no=new TypeError("Cannot compute witness commit for non-segwit block"),io=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Zi(this,"version",1),Zi(this,"prevHash",void 0),Zi(this,"merkleRoot",void 0),Zi(this,"timestamp",0),Zi(this,"witnessCommit",void 0),Zi(this,"bits",0),Zi(this,"nonce",0),Zi(this,"transactions",void 0)}return e=t,r=[{key:"getWitnessCommit",value:function(){if(!oo(this.transactions))return null;var t=this.transactions[0].outs.filter((function(t){return t.script.slice(0,6).equals($i.from("6a24aa21a9ed","hex"))})).map((function(t){return t.script.slice(6,38)}));if(0===t.length)return null;var e=t[t.length-1];return e instanceof $i&&32===e.length?e:null}},{key:"hasWitnessCommit",value:function(){return this.witnessCommit instanceof $i&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}},{key:"hasWitness",value:function(){return(t=this.transactions)instanceof Array&&t.some((function(t){return"object"===Ji(t)&&t.ins instanceof Array&&t.ins.some((function(t){return"object"===Ji(t)&&t.witness instanceof Array&&t.witness.length>0}))}));var t}},{key:"weight",value:function(){return 3*this.byteLength(!1,!1)+this.byteLength(!1,!0)}},{key:"byteLength",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t||!this.transactions?80:80+nr(this.transactions.length)+this.transactions.reduce((function(t,r){return t+r.byteLength(e)}),0)}},{key:"getHash",value:function(){return Me(this.toBuffer(!0))}},{key:"getId",value:function(){return dr(this.getHash()).toString("hex")}},{key:"getUTCDate",value:function(){var t=new Date(0);return t.setUTCSeconds(this.timestamp),t}},{key:"toBuffer",value:function(t){var e=$i.allocUnsafe(this.byteLength(t)),r=new gr(e);if(r.writeInt32(this.version),r.writeSlice(this.prevHash),r.writeSlice(this.merkleRoot),r.writeUInt32(this.timestamp),r.writeUInt32(this.bits),r.writeUInt32(this.nonce),t||!this.transactions)return e;var n=er(this.transactions.length,e,r.offset);return r.offset+=n.bytes,this.transactions.forEach((function(t){var n=t.byteLength();t.toBuffer(e,r.offset),r.offset+=n})),e}},{key:"toHex",value:function(t){return this.toBuffer(t).toString("hex")}},{key:"checkTxRoots",value:function(){var t=this.hasWitnessCommit();return!(!t&&this.hasWitness())&&this.__checkMerkleRoot()&&(!t||this.__checkWitnessCommit())}},{key:"checkProofOfWork",value:function(){var e=dr(this.getHash()),r=t.calculateTarget(this.bits);return e.compare(r)<=0}},{key:"__checkMerkleRoot",value:function(){if(!this.transactions)throw ro;var e=t.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}},{key:"__checkWitnessCommit",value:function(){if(!this.transactions)throw ro;if(!this.hasWitnessCommit())throw no;var e=t.calculateMerkleRoot(this.transactions,!0);return 0===this.witnessCommit.compare(e)}}],n=[{key:"fromBuffer",value:function(e){if(e.length<80)throw new Error("Buffer too small (< 80 bytes)");var r=new wr(e),n=new t;if(n.version=r.readInt32(),n.prevHash=r.readSlice(32),n.merkleRoot=r.readSlice(32),n.timestamp=r.readUInt32(),n.bits=r.readUInt32(),n.nonce=r.readUInt32(),80===e.length)return n;var i=function(){var t=Zn.fromBuffer(r.buffer.slice(r.offset),!0);return r.offset+=t.byteLength(),t},o=r.readVarInt();n.transactions=[];for(var u=0;u<o;++u){var a=i();n.transactions.push(a)}var s=n.getWitnessCommit();return s&&(n.witnessCommit=s),n}},{key:"fromHex",value:function(e){return t.fromBuffer($i.from(e,"hex"))}},{key:"calculateTarget",value:function(t){var e=((4278190080&t)>>24)-3,r=8388607&t,n=$i.alloc(32,0);return n.writeUIntBE(r,29-e,3),n}},{key:"calculateMerkleRoot",value:function(t,e){if(eo([{getHash:Tt}],t),0===t.length)throw ro;if(e&&!oo(t))throw no;var r=function(t,e){if(!Array.isArray(t))throw TypeError("Expected values Array");if("function"!=typeof e)throw TypeError("Expected digest Function");for(var r=t.length,n=t.concat();r>1;){for(var i=0,o=0;o<r;o+=2,++i){var u=n[o],a=o+1===r?u:n[o+1],s=zi.concat([u,a]);n[i]=e(s)}r=i}return n[0]}(t.map((function(t){return t.getHash(e)})),Me);return e?Me($i.concat([r,t[0].ins[0].witness[0]])):r}}],r&&Qi(e.prototype,r),n&&Qi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function oo(t){return t instanceof Array&&t[0]&&t[0].ins&&t[0].ins instanceof Array&&t[0].ins[0]&&t[0].ins[0].witness&&t[0].ins[0].witness instanceof Array&&t[0].ins[0].witness.length>0}var uo=r(614),ao=r(699),so=r(287).hp;function fo(t){return fo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fo(t)}function co(){co=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function s(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(e,r,n,i){var o=r&&r.prototype instanceof p?r:p,u=Object.create(o.prototype);return s(u,"_invoke",function(e,r,n){var i=1;return function(o,u){if(3===i)throw Error("Generator is already running");if(4===i){if("throw"===o)throw u;return{value:t,done:!0}}for(n.method=o,n.arg=u;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===i)throw i=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=3;var f=c(e,r,n);if("normal"===f.type){if(i=n.done?4:2,f.arg===h)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(i=4,n.method="throw",n.arg=f.arg)}}}(e,n,new T(i||[])),!0),u}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h={};function p(){}function l(){}function d(){}var y={};s(y,o,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(_([])));w&&w!==r&&n.call(w,o)&&(y=w);var v=d.prototype=p.prototype=Object.create(y);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(i,o,u,a){var s=c(t[i],t,o);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==fo(h)&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(h).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,a)}))}a(s.arg)}var i;s(this,"_invoke",(function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}),!0)}function E(e,r){var n=r.method,i=e.i[n];if(i===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,E(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=c(i,e.i,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,h;var u=o.arg;return u?u.done?(r[e.r]=u.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,h):u:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function S(t){this.tryEntries.push(t)}function I(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function T(t){this.tryEntries=[[-1]],t.forEach(S,this),this.reset(!0)}function _(e){if(null!=e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,u=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return u.next=u}}throw new TypeError(fo(e)+" is not iterable")}return l.prototype=d,s(v,"constructor",d),s(d,"constructor",l),l.displayName=s(d,a,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,a,"GeneratorFunction")),t.prototype=Object.create(v),t},e.awrap=function(t){return{__await:t}},m(b.prototype),s(b.prototype,u,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new b(f(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},m(v),s(v,a,"Generator"),s(v,o,(function(){return this})),s(v,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},e.values=_,T.prototype={constructor:T,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){u.type="throw",u.arg=e,r.next=t}for(var i=r.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o[4],a=this.prev,s=o[1],f=o[2];if(-1===o[0])return n("end"),!1;if(!s&&!f)throw Error("try statement without catch or finally");if(null!=o[0]&&o[0]<=a){if(a<s)return this.method="next",this.arg=t,n(s),!0;if(a<f)return n(f),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var i=n;break}}i&&("break"===t||"continue"===t)&&i[0]<=e&&e<=i[2]&&(i=null);var o=i?i[4]:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i[2],h):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),I(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var i=n.arg;I(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:_(e),r,n},"next"===this.method&&(this.arg=t),h}},e}function ho(t,e,r,n,i,o,u){try{var a=t[o](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,i)}function po(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){ho(o,n,i,u,a,"next",t)}function a(t){ho(o,n,i,u,a,"throw",t)}u(void 0)}))}}function lo(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=go(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){a=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(a)throw o}}}}function yo(t){return function(t){if(Array.isArray(t))return wo(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||go(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function go(t,e){if(t){if("string"==typeof t)return wo(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wo(t,e):void 0}}function wo(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function vo(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function mo(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Eo(n.key),n)}}function bo(t,e,r){return e&&mo(t.prototype,e),r&&mo(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Eo(t){var e=function(t){if("object"!=fo(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=fo(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==fo(e)?e:e+""}var So={network:p,maximumFeeRate:5e3},Io=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new uo.i(new _o);vo(this,t),this.data=r,this.opts=Object.assign({},So,e),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},0===this.data.inputs.length&&this.setVersion(2);var n=function(t,e,r,n){Object.defineProperty(t,e,{enumerable:r,writable:n})};n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}return bo(t,[{key:"inputCount",get:function(){return this.data.inputs.length}},{key:"version",get:function(){return this.__CACHE.__TX.version},set:function(t){this.setVersion(t)}},{key:"locktime",get:function(){return this.__CACHE.__TX.locktime},set:function(t){this.setLocktime(t)}},{key:"txInputs",get:function(){return this.__CACHE.__TX.ins.map((function(t){return{hash:yr(t.hash),index:t.index,sequence:t.sequence}}))}},{key:"txOutputs",get:function(){var t=this;return this.__CACHE.__TX.outs.map((function(e){var r;try{r=de(e.script,t.opts.network)}catch(t){}return{script:yr(e.script),value:e.value,address:r}}))}},{key:"combine",value:function(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=this.data).combine.apply(t,yo(r.map((function(t){return t.data})))),this}},{key:"clone",value:function(){return t.fromBuffer(this.data.toBuffer(),JSON.parse(JSON.stringify(this.opts)))}},{key:"setMaximumFeeRate",value:function(t){Uo(t),this.opts.maximumFeeRate=t}},{key:"setVersion",value:function(t){Uo(t),No(this.data.inputs,"setVersion");var e=this.__CACHE;return e.__TX.version=t,e.__EXTRACTED_TX=void 0,this}},{key:"setLocktime",value:function(t){Uo(t),No(this.data.inputs,"setLocktime");var e=this.__CACHE;return e.__TX.locktime=t,e.__EXTRACTED_TX=void 0,this}},{key:"setInputSequence",value:function(t,e){Uo(e),No(this.data.inputs,"setInputSequence");var r=this.__CACHE;if(r.__TX.ins.length<=t)throw new Error("Input index too high");return r.__TX.ins[t].sequence=e,r.__EXTRACTED_TX=void 0,this}},{key:"addInputs",value:function(t){var e=this,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t.forEach((function(t){return e.addInput(t,r)})),this}},{key:"addInput",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!t||void 0===t.hash||void 0===t.index)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");si(t,t,"addInput"),e&&No(this.data.inputs,"addInput"),t.witnessScript&&eu(t.witnessScript);var r=this.__CACHE;this.data.addInput(t),Bo(r,r.__TX.ins[r.__TX.ins.length-1]);var n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&Yo(this.__CACHE,i,n),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}},{key:"addOutputs",value:function(t){var e=this;return t.forEach((function(t){return e.addOutput(t)})),this}},{key:"addOutput",value:function(t){if(arguments.length>1||!t||void 0===t.value||void 0===t.address&&void 0===t.script)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");No(this.data.inputs,"addOutput");var e=t.address;if("string"==typeof e){var r=ye(e,this.opts.network);t=Object.assign({},t,{script:r})}fi(t,t,"addOutput");var n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}},{key:"extractTransaction",value:function(t,e){if(e&&(this.data.inputs=this.data.inputs.filter((function(t){return!t.partialSig}))),!this.data.inputs.every(Oo))throw new Error("Not finalized");var r=this.__CACHE;if(t||function(t,e,r){var n=e.__FEE_RATE||t.getFeeRate(),i=e.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error("Warning: You are paying around ".concat((o/1e8).toFixed(8)," in ")+"fees, which is ".concat(n," satoshi per byte for a transaction ")+"with a VSize of ".concat(i," bytes (segwit counted as 0.25 byte per ")+"byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.")}(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;var n=r.__TX.clone();return zo(this.data.inputs,n,r,!0,e),n}},{key:"getFeeRate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Lo("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE,t)}},{key:"getFee",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Lo("__FEE","fee",this.data.inputs,this.__CACHE,t)}},{key:"finalizeAllInputs",value:function(){var t=this;return(0,ao.checkForInput)(this.data.inputs,0),nu(this.data.inputs.length).forEach((function(e){return t.finalizeInput(e)})),this}},{key:"finalizeInput",value:function(t,e,r){var n=(0,ao.checkForInput)(this.data.inputs,t);return ui(n)?this._finalizeTaprootInput(t,n,void 0,e):this._finalizeInput(t,n,e,null==r||r)}},{key:"finalizeTaprootInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ii,n=(0,ao.checkForInput)(this.data.inputs,t);if(ui(n))return this._finalizeTaprootInput(t,n,e,r);throw new Error("Cannot finalize input #".concat(t,". Not Taproot."))}},{key:"getInputType",value:function(t){var e=(0,ao.checkForInput)(this.data.inputs,t),r=tu(Jo(t,e,this.__CACHE),t,"input",e.redeemScript||function(t){if(t){var e=jt(t);if(e){var r=e[e.length-1];if(so.isBuffer(r)&&!Zo(r)&&!$t(r))if(jt(r))return r}}}(e.finalScriptSig),e.witnessScript||function(t){if(t){var e=Xo(t),r=e[e.length-1];if(!Zo(r)&&jt(r))return r}}(e.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+ru(r.meaningfulScript)}},{key:"inputHasPubkey",value:function(t,e){return function(t,e,r,n){return Mi(t,tu(Jo(r,e,n),r,"input",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,ao.checkForInput)(this.data.inputs,t),t,this.__CACHE)}},{key:"inputHasHDKey",value:function(t,e){var r=(0,ao.checkForInput)(this.data.inputs,t),n=Po(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"outputHasPubkey",value:function(t,e){return function(t,e,r,n){return Mi(t,tu(n.__TX.outs[r].script,r,"output",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,ao.checkForOutput)(this.data.outputs,t),t,this.__CACHE)}},{key:"outputHasHDKey",value:function(t,e){var r=(0,ao.checkForOutput)(this.data.outputs,t),n=Po(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"validateSignaturesOfAllInputs",value:function(t){var e=this;return(0,ao.checkForInput)(this.data.inputs,0),nu(this.data.inputs.length).map((function(r){return e.validateSignaturesOfInput(r,t)})).reduce((function(t,e){return!0===e&&t}),!0)}},{key:"validateSignaturesOfInput",value:function(t,e,r){return ui(this.data.inputs[t])?this.validateSignaturesOfTaprootInput(t,e,r):this._validateSignaturesOfInput(t,e,r)}},{key:"signAllInputsHD",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[Zn.SIGHASH_ALL];if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");var r,n=[],i=lo(nu(this.data.inputs.length));try{for(i.s();!(r=i.n()).done;){var o=r.value;try{this.signInputHD(o,t,e),n.push(!0)}catch(t){n.push(!1)}}}catch(t){i.e(t)}finally{i.f()}if(n.every((function(t){return!1===t})))throw new Error("No inputs were signed");return this}},{key:"signAllInputsHDAsync",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[Zn.SIGHASH_ALL];return new Promise((function(n,i){if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));var o,u=[],a=[],s=lo(nu(e.data.inputs.length));try{for(s.s();!(o=s.n()).done;){var f=o.value;a.push(e.signInputHDAsync(f,t,r).then((function(){u.push(!0)}),(function(){u.push(!1)})))}}catch(t){s.e(t)}finally{s.f()}return Promise.all(a).then((function(){if(u.every((function(t){return!1===t})))return i(new Error("No inputs were signed"));n()}))}))}},{key:"signInputHD",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL];if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");return qo(t,this.data.inputs,e).forEach((function(e){return r.signInput(t,e,n)})),this}},{key:"signInputHDAsync",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL];return new Promise((function(i,o){if(!e||!e.publicKey||!e.fingerprint)return o(new Error("Need HDSigner to sign input"));var u=qo(t,r.data.inputs,e).map((function(e){return r.signInputAsync(t,e,n)}));return Promise.all(u).then((function(){i()})).catch(o)}))}},{key:"signAllInputs",value:function(t,e){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");var r,n=[],i=lo(nu(this.data.inputs.length));try{for(i.s();!(r=i.n()).done;){var o=r.value;try{this.signInput(o,t,e),n.push(!0)}catch(t){n.push(!1)}}}catch(t){i.e(t)}finally{i.f()}if(n.every((function(t){return!1===t})))throw new Error("No inputs were signed");return this}},{key:"signAllInputsAsync",value:function(t,e){var r=this;return new Promise((function(n,i){if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));var o,u,a,s=[],f=[],c=lo(r.data.inputs.entries());try{for(c.s();!(o=c.n()).done;){var h=(u=o.value,a=1,function(t){if(Array.isArray(t))return t}(u)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,u,a=[],s=!0,f=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=o.call(r)).done)&&(a.push(n.value),a.length!==e);s=!0);}catch(t){f=!0,i=t}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(f)throw i}}return a}}(u,a)||go(u,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0];f.push(r.signInputAsync(h,t,e).then((function(){s.push(!0)}),(function(){s.push(!1)})))}}catch(t){c.e(t)}finally{c.f()}return Promise.all(f).then((function(){if(s.every((function(t){return!1===t})))return i(new Error("No inputs were signed"));n()}))}))}},{key:"signInput",value:function(t,e,r){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var n=(0,ao.checkForInput)(this.data.inputs,t);return ui(n)?this._signTaprootInput(t,n,e,void 0,r):this._signInput(t,e,r)}},{key:"signTaprootInput",value:function(t,e,r,n){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var i=(0,ao.checkForInput)(this.data.inputs,t);if(ui(i))return this._signTaprootInput(t,i,e,r,n);throw new Error("Input #".concat(t," is not of type Taproot."))}},{key:"signInputAsync",value:function(t,e,r){var n=this;return Promise.resolve().then((function(){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var i=(0,ao.checkForInput)(n.data.inputs,t);return ui(i)?n._signTaprootInputAsync(t,i,e,void 0,r):n._signInputAsync(t,e,r)}))}},{key:"signTaprootInputAsync",value:function(t,e,r,n){var i=this;return Promise.resolve().then((function(){if(!e||!e.publicKey)throw new Error("Need Signer to sign input");var o=(0,ao.checkForInput)(i.data.inputs,t);if(ui(o))return i._signTaprootInputAsync(t,o,e,r,n);throw new Error("Input #".concat(t," is not of type Taproot."))}))}},{key:"toBuffer",value:function(){return ko(this.__CACHE),this.data.toBuffer()}},{key:"toHex",value:function(){return ko(this.__CACHE),this.data.toHex()}},{key:"toBase64",value:function(){return ko(this.__CACHE),this.data.toBase64()}},{key:"updateGlobal",value:function(t){return this.data.updateGlobal(t),this}},{key:"updateInput",value:function(t,e){return e.witnessScript&&eu(e.witnessScript),si(this.data.inputs[t],e,"updateInput"),this.data.updateInput(t,e),e.nonWitnessUtxo&&Yo(this.__CACHE,this.data.inputs[t],t),this}},{key:"updateOutput",value:function(t,e){return fi(this.data.outputs[t],e,"updateOutput"),this.data.updateOutput(t,e),this}},{key:"addUnknownKeyValToGlobal",value:function(t){return this.data.addUnknownKeyValToGlobal(t),this}},{key:"addUnknownKeyValToInput",value:function(t,e){return this.data.addUnknownKeyValToInput(t,e),this}},{key:"addUnknownKeyValToOutput",value:function(t,e){return this.data.addUnknownKeyValToOutput(t,e),this}},{key:"clearFinalizedInput",value:function(t){return this.data.clearFinalizedInput(t),this}},{key:"checkTaprootHashesForSig",value:function(t,e,r,n,i){if("function"!=typeof r.signSchnorr)throw new Error("Need Schnorr Signer to sign taproot input #".concat(t,"."));var o=jo(t,e,this.data.inputs,r.publicKey,this.__CACHE,n,i);if(!o||!o.length)throw new Error("Can not sign for input #".concat(t," with the key ").concat(r.publicKey.toString("hex")));return o}},{key:"_finalizeInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Vo,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=function(t,e,r){var n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!e.redeemScript,i.isP2WSH=!!e.witnessScript,e.witnessScript)i.script=e.witnessScript;else if(e.redeemScript)i.script=e.redeemScript;else if(e.nonWitnessUtxo){var o=$o(r,e,t),u=n.ins[t].index;i.script=o.outs[u].script}else e.witnessUtxo&&(i.script=e.witnessUtxo.script);return(e.witnessScript||Ni(i.script))&&(i.isSegwit=!0),i}(t,e,this.__CACHE),o=i.script,u=i.isP2SH,a=i.isP2WSH,s=i.isSegwit;if(!o)throw new Error("No script found for input #".concat(t));!function(t){if(t.sighashType&&t.partialSig){var e=t.partialSig,r=t.sighashType;e.forEach((function(t){var e=Qt.decode(t.signature).hashType;if(r!==e)throw new Error("Signature sighash does not match input sighash type")}))}}(e);var f=r(t,e,o,s,u,a,n),c=f.finalScriptSig,h=f.finalScriptWitness;if(c&&this.data.updateInput(t,{finalScriptSig:c}),h&&this.data.updateInput(t,{finalScriptWitness:h}),!c&&!h)throw new Error("Unknown error finalizing input #".concat(t));return this.data.clearFinalizedInput(t),this}},{key:"_finalizeTaprootInput",value:function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ii;if(!e.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing witness utxo."));if(e.tapKeySig){var i=Ri(Un({output:e.witnessUtxo.script,signature:e.tapKeySig}).witness);this.data.updateInput(t,{finalScriptWitness:i})}else{var o=n(t,e,r).finalScriptWitness;this.data.updateInput(t,{finalScriptWitness:o})}return this.data.clearFinalizedInput(t),this}},{key:"_validateSignaturesOfInput",value:function(t,e,r){var n=this.data.inputs[t],i=(n||{}).partialSig;if(!n||!i||i.length<1)throw new Error("No signatures to validate");if("function"!=typeof e)throw new Error("Need validator function to validate signatures");var o=r?i.filter((function(t){return t.pubkey.equals(r)})):i;if(o.length<1)throw new Error("No signatures for this pubkey");var u,a,s,f,c=[],h=lo(o);try{for(h.s();!(f=h.n()).done;){var p=f.value,l=Qt.decode(p.signature),d=s!==l.hashType?Mo(t,Object.assign({},n,{sighashType:l.hashType}),this.__CACHE,!0):{hash:u,script:a},y=d.hash,g=d.script;s=l.hashType,u=y,a=g,xo(p.pubkey,g,"verify"),c.push(e(p.pubkey,y,l.signature))}}catch(t){h.e(t)}finally{h.f()}return c.every((function(t){return!0===t}))}},{key:"validateSignaturesOfTaprootInput",value:function(t,e,r){var n=this.data.inputs[t],i=(n||{}).tapKeySig,o=(n||{}).tapScriptSig;if(!n&&!i&&(!o||o.length))throw new Error("No signatures to validate");if("function"!=typeof e)throw new Error("Need validator function to validate signatures");var u=(r=r&&ni(r))?jo(t,n,this.data.inputs,r,this.__CACHE):function(t,e,r,n){var i=[];if(e.tapInternalKey){var o=Fo(t,e,n);o&&i.push(o)}if(e.tapScriptSig){var u=e.tapScriptSig.map((function(t){return t.pubkey}));i.push.apply(i,yo(u))}return i.map((function(i){return jo(t,e,r,i,n)})).flat()}(t,n,this.data.inputs,this.__CACHE);if(!u.length)throw new Error("No signatures for this pubkey");var a=u.find((function(t){return!t.leafHash})),s=0;if(i&&a){if(!e(a.pubkey,a.hash,Go(i)))return!1;s++}if(o){var f,c=lo(o);try{var h,p=function(){var t=f.value,r=u.find((function(e){return t.pubkey.equals(e.pubkey)}));if(r){if(!e(t.pubkey,r.hash,Go(t.signature)))return{v:!1};s++}};for(c.s();!(f=c.n()).done;)if(h=p())return h.v}catch(t){c.e(t)}finally{c.f()}}return s>0}},{key:"_signInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL],n=Ko(this.data.inputs,t,e.publicKey,this.__CACHE,r),i=n.hash,o=n.sighashType,u=[{pubkey:e.publicKey,signature:Qt.encode(e.sign(i),o)}];return this.data.updateInput(t,{partialSig:u}),this}},{key:"_signTaprootInput",value:function(t,e,r,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[Zn.SIGHASH_DEFAULT],o=this.checkTaprootHashesForSig(t,e,r,n,i),u=o.filter((function(t){return!t.leafHash})).map((function(t){return oi(r.signSchnorr(t.hash),e.sighashType)}))[0],a=o.filter((function(t){return!!t.leafHash})).map((function(t){return{pubkey:ni(r.publicKey),signature:oi(r.signSchnorr(t.hash),e.sighashType),leafHash:t.leafHash}}));return u&&this.data.updateInput(t,{tapKeySig:u}),a.length&&this.data.updateInput(t,{tapScriptSig:a}),this}},{key:"_signInputAsync",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[Zn.SIGHASH_ALL],i=Ko(this.data.inputs,t,e.publicKey,this.__CACHE,n),o=i.hash,u=i.sighashType;return Promise.resolve(e.sign(o)).then((function(n){var i=[{pubkey:e.publicKey,signature:Qt.encode(n,u)}];r.data.updateInput(t,{partialSig:i})}))}},{key:"_signTaprootInputAsync",value:(e=po(co().mark((function t(e,r,n,i){var o,u,a,s,f,c,h,p,l,d,y,g=arguments;return co().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=g.length>4&&void 0!==g[4]?g[4]:[Zn.SIGHASH_DEFAULT],u=this.checkTaprootHashesForSig(e,r,n,i,o),a=[],s=u.filter((function(t){return!t.leafHash}))[0],s&&(f=Promise.resolve(n.signSchnorr(s.hash)).then((function(t){return{tapKeySig:oi(t,r.sighashType)}})),a.push(f)),c=u.filter((function(t){return!!t.leafHash})),c.length&&(h=c.map(function(){var t=po(co().mark((function t(e){var i,o;return co().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.signSchnorr(e.hash);case 2:return i=t.sent,o=[{pubkey:ni(n.publicKey),signature:oi(i,r.sighashType),leafHash:e.leafHash}],t.abrupt("return",{tapScriptSig:o});case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),a.push.apply(a,yo(h))),t.next=9,Promise.all(a);case 9:p=t.sent,l=lo(p);try{for(l.s();!(d=l.n()).done;)y=d.value,this.data.updateInput(e,y)}catch(t){l.e(t)}finally{l.f()}case 12:case"end":return t.stop()}}),t,this)}))),function(t,r,n,i){return e.apply(this,arguments)})}],[{key:"fromBase64",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=so.from(t,"base64");return this.fromBuffer(r,e)}},{key:"fromHex",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=so.from(t,"hex");return this.fromBuffer(r,e)}},{key:"fromBuffer",value:function(e){var r,n,i=new t(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},uo.i.fromBuffer(e,To));return r=i.__CACHE.__TX,n=i.__CACHE,r.ins.forEach((function(t){Bo(n,t)})),i}}]);var e}(),To=function(t){return new _o(t)},_o=function(){return bo((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:so.from([2,0,0,0,0,0,0,0,0,0]);vo(this,t),this.tx=Zn.fromBuffer(e),function(t){if(!t.ins.every((function(t){return t.script&&0===t.script.length&&t.witness&&0===t.witness.length})))throw new Error("Format Error: Transaction ScriptSigs are not empty")}(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}),[{key:"getInputOutputCounts",value:function(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}},{key:"addInput",value:function(t){if(void 0===t.hash||void 0===t.index||!so.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");var e="string"==typeof t.hash?dr(so.from(t.hash,"hex")):t.hash;this.tx.addInput(e,t.index,t.sequence)}},{key:"addOutput",value:function(t){if(void 0===t.script||void 0===t.value||!so.isBuffer(t.script)||"number"!=typeof t.value)throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}},{key:"toBuffer",value:function(){return this.tx.toBuffer()}}])}();function ko(t){if(!1!==t.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function Ao(t,e,r){if(!e)return!1;var n;if((n=r?r.map((function(t){var r=function(t){if(65===t.length){var e=1&t[64],r=t.slice(0,33);return r[0]=2|e,r}return t.slice()}(t);return e.find((function(t){return t.pubkey.equals(r)}))})).filter((function(t){return!!t})):e).length>t)throw new Error("Too many signatures");return n.length===t}function Oo(t){return!!t.finalScriptSig||!!t.finalScriptWitness}function Po(t){return function(e){return!!e.masterFingerprint.equals(t.fingerprint)&&!!t.derivePath(e.path).publicKey.equals(e.pubkey)}}function Uo(t){if("number"!=typeof t||t!==Math.floor(t)||t>4294967295||t<0)throw new Error("Invalid 32 bit integer")}function No(t,e){t.forEach((function(t){if(ui(t)?li(t,e):Fi(t,e))throw new Error("Can not modify transaction, signatures exist.")}))}function xo(t,e,r){if(!Mi(t,e))throw new Error("Can not ".concat(r," for this input with the key ").concat(t.toString("hex")))}function Bo(t,e){var r=dr(so.from(e.hash)).toString("hex")+":"+e.index;if(t.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");t.__TX_IN_CACHE[r]=1}function Co(t,e){return function(r,n,i,o){var u=t({redeem:{output:i}}).output;if(!n.equals(u))throw new Error("".concat(e," for ").concat(o," #").concat(r," doesn't match the scriptPubKey in the prevout"))}}var Ho=Co(kn,"Redeem script"),Ro=Co(Dn,"Witness script");function Lo(t,e,r,n){var i,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!r.every(Oo))throw new Error("PSBT must be finalized to calculate ".concat(e));if("__FEE_RATE"===t&&n.__FEE_RATE)return n.__FEE_RATE;if("__FEE"===t&&n.__FEE)return n.__FEE;var u=!0;return n.__EXTRACTED_TX?(i=n.__EXTRACTED_TX,u=!1):i=n.__TX.clone(),zo(r,i,n,u,o),"__FEE_RATE"===t?n.__FEE_RATE:"__FEE"===t?n.__FEE:void 0}function Vo(t,e,r,n,i,o){var u=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],a=ru(r);if(!function(t,e,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return Ao(1,t.partialSig);case"multisig":var n=Rr({output:e});return Ao(n.m,t.partialSig,n.pubkeys);case"nonstandard":return!0;default:return!1}}(e,r,a)&&u)throw new Error("Can not finalize input #".concat(t));return Do(r,a,e.partialSig,n,i,o)}function Do(t,e,r,n,i,o){var u,a,s=function(t,e,r){var n;switch(e){case"multisig":var i=function(t,e){return Rr({output:t}).pubkeys.map((function(t){return(e.filter((function(e){return e.pubkey.equals(t)}))[0]||{}).signature})).filter((function(t){return!!t}))}(t,r);n=Rr({output:t,signatures:i});break;case"pubkey":n=Vr({output:t,signature:r[0].signature});break;case"pubkeyhash":n=Yi({output:t,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=Cn({output:t,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(t,e,r),f=o?Dn({redeem:s}):null,c=i?kn({redeem:f||s}):null;return n?(a=Ri(f?f.witness:s.witness),c&&(u=c.input)):u=c?c.input:s.input,{finalScriptSig:u,finalScriptWitness:a}}function Ko(t,e,r,n,i){var o=Mo(e,(0,ao.checkForInput)(t,e),n,!1,i),u=o.hash,a=o.sighashType;return xo(r,o.script,"sign"),{hash:u,sighashType:a}}function Mo(t,e,r,n,i){var o,u,a=r.__TX,s=e.sighashType||Zn.SIGHASH_ALL;if(Wo(s,i),e.nonWitnessUtxo){var f=$o(r,e,t),c=a.ins[t].hash,h=f.getHash();if(!c.equals(h))throw new Error("Non-witness UTXO hash for input #".concat(t," doesn't match the hash specified in the prevout"));var p=a.ins[t].index;u=f.outs[p]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}var l=tu(u.script,t,"input",e.redeemScript,e.witnessScript),d=l.meaningfulScript,y=l.type;if(["p2sh-p2wsh","p2wsh"].indexOf(y)>=0)o=a.hashForWitnessV0(t,d,u.value,s);else if(Ni(d)){var g=Yi({hash:d.slice(2)}).output;o=a.hashForWitnessV0(t,g,u.value,s)}else{if(void 0===e.nonWitnessUtxo&&!1===r.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Input #".concat(t," has witnessUtxo but non-segwit script: ")+"".concat(d.toString("hex")));n||!1===r.__UNSAFE_SIGN_NONSEGWIT||console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),o=a.hashForSignature(t,d,s)}return{script:d,sighashType:s,hash:o}}function Fo(t,e,r){var n=Qo(t,e,r).script;return Ci(n)?n.subarray(2,34):null}function Go(t){return 64===t.length?t:t.subarray(0,64)}function jo(t,e,r,n,i,o,u){var a=i.__TX,s=e.sighashType||Zn.SIGHASH_DEFAULT;Wo(s,u);var f=r.map((function(t,e){return Qo(e,t,i)})),c=f.map((function(t){return t.script})),h=f.map((function(t){return t.value})),p=[];if(e.tapInternalKey&&!o){var l=Fo(t,e,i)||so.from([]);if(ni(n).equals(l)){var d=a.hashForWitnessV1(t,c,h,s);p.push({pubkey:n,hash:d})}}var y=(e.tapLeafScript||[]).filter((function(t){return Mi(n,t.script)})).map((function(t){var e=kr({output:t.script,version:t.leafVersion});return Object.assign({hash:e},t)})).filter((function(t){return!o||o.equals(t.hash)})).map((function(e){var r=a.hashForWitnessV1(t,c,h,s,e.hash);return{pubkey:n,hash:r,leafHash:e.hash}}));return p.concat(y)}function Wo(t,e){if(e&&e.indexOf(t)<0){var r=function(t){var e=t&Zn.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&t){case Zn.SIGHASH_ALL:e+="SIGHASH_ALL";break;case Zn.SIGHASH_SINGLE:e+="SIGHASH_SINGLE";break;case Zn.SIGHASH_NONE:e+="SIGHASH_NONE"}return e}(t);throw new Error("Sighash type is not allowed. Retry the sign method passing the "+"sighashTypes array of whitelisted types. Sighash type: ".concat(r))}}function qo(t,e,r){var n=(0,ao.checkForInput)(e,t);if(!n.bip32Derivation||0===n.bip32Derivation.length)throw new Error("Need bip32Derivation to sign with HD");var i=n.bip32Derivation.map((function(t){return t.masterFingerprint.equals(r.fingerprint)?t:void 0})).filter((function(t){return!!t}));if(0===i.length)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map((function(t){var e=r.derivePath(t.path);if(!t.pubkey.equals(e.publicKey))throw new Error("pubkey did not match bip32Derivation");return e}))}function Xo(t){var e=0;function r(){var r=In.decode(t,e);return e+=In.decode.bytes,r}return function(){for(var n=r(),i=[],o=0;o<n;o++)i.push((u=void 0,u=r(),e+=u,t.slice(e-u,e)));var u;return i}()}function Yo(t,e,r){t.__NON_WITNESS_UTXO_BUF_CACHE[r]=e.nonWitnessUtxo,t.__NON_WITNESS_UTXO_TX_CACHE[r]=Zn.fromBuffer(e.nonWitnessUtxo);var n=t,i=r;delete e.nonWitnessUtxo,Object.defineProperty(e,"nonWitnessUtxo",{enumerable:!0,get:function(){var t=n.__NON_WITNESS_UTXO_BUF_CACHE[i],e=n.__NON_WITNESS_UTXO_TX_CACHE[i];if(void 0!==t)return t;var r=e.toBuffer();return n.__NON_WITNESS_UTXO_BUF_CACHE[i]=r,r},set:function(t){n.__NON_WITNESS_UTXO_BUF_CACHE[i]=t}})}function zo(t,e,r,n,i){var o=0;t.forEach((function(t,i){if(n&&t.finalScriptSig&&(e.ins[i].script=t.finalScriptSig),n&&t.finalScriptWitness&&(e.ins[i].witness=Xo(t.finalScriptWitness)),t.witnessUtxo)o+=t.witnessUtxo.value;else if(t.nonWitnessUtxo){var u=$o(r,t,i),a=e.ins[i].index,s=u.outs[a];o+=s.value}}));var u=e.outs.reduce((function(t,e){return t+e.value}),0),a=o-u;if(!i&&a<0)throw new Error("Outputs are spending more than Inputs");var s=e.virtualSize();r.__FEE=a,r.__EXTRACTED_TX=e,r.__FEE_RATE=Math.floor(a/s)}function $o(t,e,r){var n=t.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||Yo(t,e,r),n[r]}function Jo(t,e,r){return Qo(t,e,r).script}function Qo(t,e,r){if(void 0!==e.witnessUtxo)return{script:e.witnessUtxo.script,value:e.witnessUtxo.value};if(void 0!==e.nonWitnessUtxo){var n=$o(r,e,t).outs[r.__TX.ins[t].index];return{script:n.script,value:n.value}}throw new Error("Can't find pubkey in input without Utxo data")}function Zo(t){return 33===t.length&&Yt(t)}function tu(t,e,r,n,i){var o,u=Bi(t),a=u&&n&&xi(n),s=xi(t);if(u&&void 0===n)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((s||a)&&void 0===i)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");return a?(o=i,Ho(e,t,n,r),Ro(e,n,i,r),eu(o)):s?(o=i,Ro(e,t,i,r),eu(o)):u?(o=n,Ho(e,t,n,r)):o=t,{meaningfulScript:o,type:a?"p2sh-p2wsh":u?"p2sh":s?"p2wsh":"raw"}}function eu(t){if(Ni(t)||Bi(t))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function ru(t){return Ni(t)?"witnesspubkeyhash":Ui(t)?"pubkeyhash":Oi(t)?"multisig":Pi(t)?"pubkey":"nonstandard"}function nu(t){return yo(Array(t).keys())}const iu={networks:n,address:a,payments:h,script:u,crypto:s,Transaction:c};export{io as Block,wr as BufferReader,gr as BufferWriter,br as LEAF_VERSION_TAPSCRIPT,Er as MAX_TAPTREE_DEPTH,Wi as PaymentType,Io as Psbt,Ge as TAGGED_HASH_PREFIXES,Fe as TAGS,ct as TAPLEAF_VERSION_MASK,Zn as Transaction,a as address,Vi as bigIntTo32Bytes,Fi as checkInputForSig,si as checkTaprootInputFields,li as checkTaprootInputForSigs,fi as checkTaprootOutputFields,yr as cloneBuffer,s as crypto,Li as decompressPublicKey,iu as default,_r as findScriptPath,ce as fromBase58Check,he as fromBech32,de as fromOutputScript,Vo as getFinalScripts,ji as getPsigsFromInputFinalScripts,yi as getTapKeySigFromWitness,Ke as hash160,Me as hash256,Xe as initEccLib,Oi as isP2MS,Hi as isP2OP,Pi as isP2PK,Ui as isP2PKH,Bi as isP2SHScript,Ci as isP2TR,Ni as isP2WPKH,xi as isP2WSHScript,ui as isTaprootInput,ai as isTaprootOutput,n as networks,W as opcodes,h as payments,Do as prepareFinalScripts,Mi as pubkeyInScript,Ki as pubkeyPositionInScript,Di as pubkeysMatch,pr as readUInt64LE,dr as reverseBuffer,Le as ripemd160,Ir as rootHashFromPath,u as script,oi as serializeTaprootSignature,Ve as sha1,De as sha256,Gi as signatureBlocksAction,je as taggedHash,ii as tapScriptFinalizer,pi as tapTreeFromList,hi as tapTreeToList,Ar as tapTweakHash,kr as tapleafHash,pe as toBase58Check,le as toBech32,fe as toFutureOPNetAddress,Tr as toHashTree,ye as toOutputScript,ni as toXOnly,ci as tweakInternalPubKey,Or as tweakKey,f as varuint,Ri as witnessStackToScriptWitness,lr as writeUInt64LE};
|