@btc-vision/bitcoin 6.3.4 → 6.3.6
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/browser/psbt/psbtutils.d.ts +1 -1
- package/build/psbt/psbtutils.js +1 -0
- package/package.json +2 -2
- package/src/psbt/psbtutils.ts +4 -0
- package/src/psbt.ts +2187 -2187
package/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
var t={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},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 l=[];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||l.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:l}}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")},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})}},834:(t,e,r)=>{var n=r(287).Buffer;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)}},213:(t,e,r)=>{var n=r(287).Buffer;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()}}},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),l=r(760),p=r(695),y=r(454),d=r(34),g=r(926),w=r(851),v=r(545),m=r(412),b=r(307),E=r(636),S=r(223),T=r(578),I={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=I;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:T.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:l,tapScriptSig:d,tapLeafScript:p,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:S.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:y};e.inputs=_;const k={bip32Derivation:v.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:T.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},605:(t,e,r)=>{var n=r(287).Buffer;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}},795:(t,e,r)=>{var n=r(287).Buffer;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}},431:(t,e,r)=>{var n=r(287).Buffer;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}},907:(t,e,r)=>{var n=r(287).Buffer;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)}},949:(t,e,r)=>{var n=r(287).Buffer;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}},344:(t,e,r)=>{var n=r(287).Buffer;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}},760:(t,e,r)=>{var n=r(287).Buffer;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}},695:(t,e,r)=>{var n=r(287).Buffer;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)}},454:(t,e,r)=>{var n=r(287).Buffer;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}},34:(t,e,r)=>{var n=r(287).Buffer;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)}},926:(t,e,r)=>{var n=r(287).Buffer;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}},851:(t,e,r)=>{var n=r(287).Buffer;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}},545:(t,e,r)=>{var n=r(287).Buffer;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)}}}},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}}},307:(t,e,r)=>{var n=r(287).Buffer;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}}}},636:(t,e,r)=>{var n=r(287).Buffer;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}}},223:(t,e,r)=>{var n=r(287).Buffer;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}}}},578:(t,e,r)=>{var n=r(287).Buffer;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}}}},133:(t,e,r)=>{var n=r(287).Buffer;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}},394:(t,e,r)=>{var n=r(287).Buffer;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},263:(t,e,r)=>{var n=r(287).Buffer;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,l=[],p=[];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)}l.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)}p.push(e)}return{globalMap:u,inputs:l,outputs:p}}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 l=c.filter((t=>t.key[0]===a.GlobalTypes.UNSIGNED_TX));if(1!==l.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const p=e(l[0].value),{inputCount:y,outputCount:d}=p.getInputOutputCounts(),g=[],w=[];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 input: input index "+t+" key "+o);e[o]=1,r.push(n)}g.push(r)}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 output: output index "+t+" key "+o);e[o]=1,r.push(n)}w.push(r)}return f(p,{globalMapKeyVals:c,inputKeyVals:g,outputKeyVals:w})},e.checkKeyBuffer=s,e.psbtFromKeyVals=f},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))},238:(t,e,r)=>{var n=r(287).Buffer;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),l=c(a),p=n.allocUnsafe(5);return p.writeUIntBE(482972169471,0,5),n.concat([p,f].concat(h,l))};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},614:(t,e,r)=>{var n=r(287).Buffer;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()}}},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"]},699:(t,e,r)=>{var n=r(287).Buffer;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}},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.Buffer=s,e.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},e.INSPECT_MAX_BYTES=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|d(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(Y(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return l(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(Y(t,ArrayBuffer)||t&&Y(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(Y(t,SharedArrayBuffer)||t&&Y(t.buffer,SharedArrayBuffer)))return p(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|y(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):l(t):"Buffer"===t.type&&Array.isArray(t.data)?l(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|y(t))}function l(t){const e=t.length<0?0:0|y(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(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 y(t){if(t>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return 0|t}function d(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Y(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 X(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(t).length;default:if(i)return n?-1:X(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 B(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 U(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 z(X(e,t.length-r),t,r,n)}function S(t,e,r,n){return z(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 T(t,e,r,n){return z(q(e),t,r,n)}function I(t,e,r,n){return z(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)}e.kMaxLength=u,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(Y(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),Y(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(Y(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=d,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.INSPECT_MAX_BYTES;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(Y(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 T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(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 B(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 U(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 N(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 x(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 L(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 H(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 R(t,e,r,n,o){return e=+e,r>>>=0,o||H(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||H(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||N(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||N(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||N(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||N(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||N(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||N(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||N(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=Q((function(t){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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||N(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||N(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||N(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||N(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||N(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||N(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||N(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=Q((function(t){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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||N(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||N(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||N(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||N(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||x(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||x(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||x(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||x(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||x(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||x(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||x(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 L(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);x(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);x(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||x(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||x(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||x(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||x(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||x(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 L(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return R(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return R(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 K={};function M(t,e,r){K[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 V(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 K.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,r){j(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||G(e,t.length-(r+1))}(n,i,o)}function j(t,e){if("number"!=typeof t)throw new K.ERR_INVALID_ARG_TYPE(e,"number",t)}function G(t,e,r){if(Math.floor(t)!==t)throw j(t,r),new K.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new K.ERR_BUFFER_OUT_OF_BOUNDS;throw new K.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}M("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),M("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),M("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=V(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=V(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function X(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 q(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 z(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 Y(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")}},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,l=r?-1:1,p=t[e+h];for(h+=l,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+t[e+h],h+=l,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=l,c-=8);if(0===o)o=1-f;else{if(o===s)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),o-=f}return(p?-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,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,d=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?l/s:l*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+p]=255&a,p+=y,a/=256,i-=8);for(u=u<<i|a,f+=i;f>0;t[r+p]=255&u,p+=y,u/=256,f-=8);t[r+p-y]|=128*d}},861:(t,e,r)=>{var n=r(287),i=n.Buffer;function o(t,e){for(var r in t)e[r]=t[r]}function u(t,e,r){return i(t,e,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?t.exports=n:(o(n,e),e.Buffer=u),u.prototype=Object.create(i.prototype),o(i,u),u.from=function(t,e,r){if("number"==typeof t)throw new TypeError("Argument must not be a number");return i(t,e,r)},u.alloc=function(t,e,r){if("number"!=typeof t)throw new TypeError("Argument must be a number");var n=i(t);return void 0!==e?"string"==typeof r?n.fill(e,r):n.fill(e):n.fill(0),n},u.allocUnsafe=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return i(t)},u.allocUnsafeSlow=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return n.SlowBuffer(t)}},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}},542:(t,e,r)=>{var n=r(287).Buffer,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),l=s.bind(null,i.String),p=Math.pow(2,53)-1,y={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>=-p&&t<=p&&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:l,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<=p&&Math.floor(t)===t}};for(var d in y)y[d].toJSON=function(t){return t}.bind(null,d);t.exports=y},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 l(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&&l(e,o,n)}catch(t){throw s(t,o,"key")}try{var u=r[o];l(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)l(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 l(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 l(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 l(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 l(t,e,r,n){if(i.Function(t)){if(t(e,r))return!0;throw new u(n||t,e)}return l(h(t),e,r)}for(var p in c.oneOf=c.anyOf,i)l[p]=i[p];for(p in c)l[p]=c[p];var y=r(542);for(p in y)l[p]=y[p];l.compile=h,l.TfTypeError=u,l.TfPropertyTypeError=a,t.exports=l},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},469:(t,e,r)=>{var n=r(861).Buffer;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}t.exports={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),t.bytes=1):e<=65535?(r.writeUInt8(253,u),r.writeUInt16LE(e,u+1),t.bytes=3):e<=4294967295?(r.writeUInt8(254,u),r.writeUInt32LE(e,u+1),t.bytes=5):(r.writeUInt8(255,u),r.writeUInt32LE(e>>>0,u+1),r.writeUInt32LE(e/4294967296|0,u+5),t.bytes=9),r},decode:function t(e,r){if(!n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");r||(r=0);var o=e.readUInt8(r);if(o<253)return t.bytes=1,o;if(253===o)return t.bytes=3,e.readUInt16LE(r+1);if(254===o)return t.bytes=5,e.readUInt32LE(r+1);t.bytes=9;var u=e.readUInt32LE(r+1),a=4294967296*e.readUInt32LE(r+5)+u;return i(a),a},encodingLength:o}}},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.d(n,{eB:()=>Hi,Oo:()=>ir,ac:()=>nr,ri:()=>ar,RY:()=>sr,iL:()=>yo,PW:()=>Le,gp:()=>Ce,gM:()=>ft,ZX:()=>Kn,hl:()=>s,p2:()=>wi,XL:()=>Ei,R0:()=>zn,vJ:()=>Zn,em:()=>Yn,Eb:()=>rr,Et:()=>f,m$:()=>gi,Ay:()=>$o,CB:()=>lr,VL:()=>oe,ow:()=>ue,hP:()=>fe,Dk:()=>Bo,Ln:()=>Ti,BL:()=>ei,A0:()=>Ne,CX:()=>xe,f0:()=>Ke,Bh:()=>si,Q2:()=>fi,C5:()=>ci,n0:()=>pi,NI:()=>yi,fQ:()=>hi,mG:()=>li,AM:()=>Xn,Zh:()=>qn,o8:()=>i,Ez:()=>G,KT:()=>h,KS:()=>Uo,AI:()=>bi,k1:()=>mi,pM:()=>vi,Qf:()=>Ze,Fl:()=>er,HE:()=>Pe,WH:()=>cr,K$:()=>a,C2:()=>Wn,e8:()=>Be,sc:()=>Ue,XN:()=>Si,VQ:()=>He,LE:()=>Gn,_T:()=>Qn,zm:()=>Jn,qR:()=>yr,o4:()=>pr,Og:()=>ae,FT:()=>se,uu:()=>hr,I:()=>ce,gU:()=>jn,wn:()=>$n,Kn:()=>dr,Uu:()=>Ge,du:()=>di,tO:()=>tr});var i={};r.r(i),r.d(i,{bitcoin:()=>l,bitcoinCash:()=>m,bitcoinCashTestnet:()=>b,dash:()=>E,dashTestnet:()=>S,dogecoin:()=>d,dogecoinTestnet:()=>g,litecoin:()=>w,litecoinTestnet:()=>v,regtest:()=>p,testnet:()=>y});var o={};r.r(o),r.d(o,{decode:()=>Z,encode:()=>tt});var u={};r.r(u),r.d(u,{decode:()=>Ut,encode:()=>Nt});var a={};r.r(a),r.d(a,{OPS:()=>G,compile:()=>Ft,countNonPushOnlyOPs:()=>Dt,decompile:()=>jt,fromASM:()=>Wt,isCanonicalPubKey:()=>qt,isCanonicalScriptSignature:()=>Yt,isDefinedHashType:()=>zt,isPushOnly:()=>Rt,number:()=>$t,signature:()=>Jt,toASM:()=>Gt,toStack:()=>Xt});var s={};r.r(s),r.d(s,{fromBase58Check:()=>oe,fromBech32:()=>ue,fromOutputScript:()=>fe,toBase58Check:()=>ae,toBech32:()=>se,toOutputScript:()=>ce});var f={};r.r(f),r.d(f,{TAGGED_HASH_PREFIXES:()=>Le,TAGS:()=>Ce,hash160:()=>Ne,hash256:()=>xe,ripemd160:()=>Pe,sha1:()=>Be,sha256:()=>Ue,taggedHash:()=>He});var c={};r.r(c),r.d(c,{Transaction:()=>Kn});var h={};r.r(h),r.d(h,{LEAF_VERSION_TAPSCRIPT:()=>ar,MAX_TAPTREE_DEPTH:()=>sr,findScriptPath:()=>lr,p2data:()=>br,p2ms:()=>Tr,p2pk:()=>_r,p2pkh:()=>ki,p2sh:()=>ln,p2tr:()=>gn,p2wpkh:()=>bn,p2wsh:()=>_n,prop:()=>wr,rootHashFromPath:()=>cr,tapTweakHash:()=>yr,tapleafHash:()=>pr,toHashTree:()=>hr,tweakKey:()=>dr,value:()=>vr});var l={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},p={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},y={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},d={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},g={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},w={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},v={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},m={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},b={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},E={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},S={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},T=r(343);function I(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")}const k=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),A=(t,e)=>t<<32-e|t>>>e,O=(t,e)=>t<<e|t>>>32-e>>>0;function P(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),I(t),t}class B{clone(){return this._cloneInto()}}function U(t){const e=e=>t().update(P(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}const N=(t,e,r)=>t&e^~t&r,x=(t,e,r)=>t&e^t&r^e&r;class C extends B{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=k(this.buffer)}update(t){_(this);const{view:e,buffer:r,blockLen:n}=this,i=(t=P(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=k(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){I(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,this.buffer.subarray(o).fill(0),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=k(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.length=n,t.pos=u,t.finished=i,t.destroyed=o,n%e&&t.buffer.set(r),t}}const L=new Uint32Array([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]),H=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),R=new Uint32Array(64);class D extends C{constructor(){super(64,32,8,!1),this.A=0|H[0],this.B=0|H[1],this.C=0|H[2],this.D=0|H[3],this.E=0|H[4],this.F=0|H[5],this.G=0|H[6],this.H=0|H[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)R[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=R[t-15],r=R[t-2],n=A(e,7)^A(e,18)^e>>>3,i=A(r,17)^A(r,19)^r>>>10;R[t]=i+R[t-7]+n+R[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+(A(u,6)^A(u,11)^A(u,25))+N(u,a,s)+L[t]+R[t]|0,c=(A(r,2)^A(r,13)^A(r,22))+x(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(){R.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const K=U((()=>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 l=u;for(;c!==s;)h[l++]=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 l=n.repeat(i);for(;h<f;++h)l+=t.charAt(c[h]);return l},decodeUnsafe:u,decode:function(t){const e=u(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),V=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 F=r(287).Buffer;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=F.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 G={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},W={},X=0,q=Object.keys(G);X<q.length;X++){var z=q[X],Y=G[z];W[Y]=z}function $(t){return t<G.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function J(t,e){var r,n,i=t.readUInt8(e);if(i<G.OP_PUSHDATA1)r=i,n=1;else if(i===G.OP_PUSHDATA1){if(e+2>t.length)return null;r=t.readUInt8(e+1),n=2}else if(i===G.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!==G.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=t.readUInt32LE(e+1),n=5}return{opcode:i,number:r,size:n}}var Q=r(287).Buffer;function Z(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 tt(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=Q.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 et=r(287),rt=r(676),nt=r.n(rt)(),it=et.Buffer.alloc(32,0),ot=et.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function ut(t,e){return t.length===e.length&&t.every((function(t,r){return t.equals(e[r])}))}function at(t){if(!et.Buffer.isBuffer(t))return!1;if(t.length<33)return!1;var e=t[0],r=t.slice(1,33);if(0===r.compare(it))return!1;if(r.compare(ot)>=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(it)||n.compare(ot)>=0||4!==e&&6!==e&&7!==e)}function st(t){return nt.UInt53(t)&&t<=21e14}var ft=254;function ct(t){return!(!t||!("output"in t)||!et.Buffer.isBuffer(t.output)||void 0!==t.version&&(t.version&ft)!==t.version)}function ht(t){return dt(t)?2===t.length&&t.every((function(t){return ht(t)})):ct(t)}nt.BufferN(32);var lt=nt.BufferN(20),pt=nt.BufferN(32),yt=nt.Number,dt=nt.Array,gt=(nt.Boolean,nt.String),wt=nt.Buffer,vt=nt.Hex,mt=nt.maybe,bt=nt.tuple,Et=nt.UInt8,St=nt.UInt32,Tt=nt.Function,It=nt.BufferN,_t=nt.Null,kt=(nt.oneOf,r(287).Buffer),At=nt,Ot=kt.alloc(1,0);function Pt(t){for(var e=0;0===t[e];)++e;return e===t.length?Ot:128&(t=t.slice(e))[0]?kt.concat([Ot,t],1+t.length):t}function Bt(t){0===t[0]&&(t=t.slice(1));var e=kt.alloc(32,0),r=Math.max(0,32-t.length);return t.copy(e,r),e}function Ut(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=Bt(r.r),i=Bt(r.s);return{signature:kt.concat([n,i],64),hashType:e}}function Nt(t,e){if(At({signature:It(64),hashType:Et},{signature:t,hashType:e}),!zt(e))throw new Error("Invalid hashType "+e);var r=kt.allocUnsafe(1);r.writeUInt8(e,0);var n=Pt(t.slice(0,32)),i=Pt(t.slice(32,64));return kt.concat([j(n,i),r])}var xt=r(287).Buffer,Ct=nt,Lt=G.OP_RESERVED;function Ht(t){return wt(t)||function(t){return yt(t)&&(t===G.OP_0||t>=G.OP_1&&t<=G.OP_16||t===G.OP_1NEGATE)}(t)}function Rt(t){return dt(t)&&t.every(Ht)}function Dt(t){return t.length-t.filter(Ht).length}function Kt(t){return 0===t.length?G.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Lt+t[0]:129===t[0]?G.OP_1NEGATE:void 0:void 0}function Mt(t){return xt.isBuffer(t)}function Vt(t){return xt.isBuffer(t)}function Ft(t){if(Mt(t))return t;Ct(dt,t);var e=t.reduce((function(t,e){return Vt(e)?1===e.length&&void 0!==Kt(e)?t+1:t+$(e.length)+e.length:t+1}),0),r=xt.allocUnsafe(e),n=0;if(t.forEach((function(t){if(Vt(t)){var e=Kt(t);if(void 0!==e)return r.writeUInt8(e,n),void(n+=1);n+=function(t,e,r){var n=$(e);return 1===n?t.writeUInt8(e,r):2===n?(t.writeUInt8(G.OP_PUSHDATA1,r),t.writeUInt8(e,r+1)):3===n?(t.writeUInt8(G.OP_PUSHDATA2,r),t.writeUInt16LE(e,r+1)):(t.writeUInt8(G.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(dt(t))return t;Ct(wt,t);for(var e=[],r=0;r<t.length;){var n=t[r];if(n>G.OP_0&&n<=G.OP_PUSHDATA4){var i=J(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 Gt(t){if(Mt(t)&&(t=jt(t)),!t)throw new Error("Could not convert invalid chunks to ASM");return t.map((function(t){if(Vt(t)){var e=Kt(t);if(void 0===e)return t.toString("hex");t=e}return W[t]})).join(" ")}function Wt(t){return Ct(gt,t),Ft(t.split(" ").map((function(t){return void 0!==G[t]?G[t]:(Ct(vt,t),xt.from(t,"hex"))})))}function Xt(t){return t=jt(t),Ct(Rt,t),t.map((function(t){return Vt(t)?t:t===G.OP_0?xt.allocUnsafe(0):tt(t-Lt)}))}function qt(t){return at(t)}function zt(t){var e=-129&t;return e>0&&e<4}function Yt(t){return!!xt.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 $t=o,Jt=u,Qt=r(287).Buffer,Zt=40,te=2,ee=16,re=2,ne=80,ie="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 oe(t){var e=Qt.from(V.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.slice(1)}}function ue(t){var e,r;try{e=T.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=T.p2.decode(t)).words[0]))throw new TypeError(t+" uses wrong encoding");var n=T.I.fromWords(e.words.slice(1));return{version:r,prefix:e.prefix,data:Qt.from(n)}}function ae(t,e){nt(bt(lt,Et),arguments);var r=Qt.allocUnsafe(21);return r.writeUInt8(e,0),t.copy(r,1),V.encode(r)}function se(t,e,r){var n=T.I.toWords(t);return n.unshift(e),0===e?T.I.encode(r,n):T.p2.encode(r,n)}function fe(t,e){e=e||l;try{return ki({output:t,network:e}).address}catch(t){}try{return ln({output:t,network:e}).address}catch(t){}try{return bn({output:t,network:e}).address}catch(t){}try{return _n({output:t,network:e}).address}catch(t){}try{return gn({output:t,network:e}).address}catch(t){}try{return function(t,e){var r=t.slice(2);if(r.length<te||r.length>Zt)throw new TypeError("Invalid program length for segwit address");var n=t[0]-ne;if(n<re||n>ee)throw new TypeError("Invalid version for segwit address");if(t[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(ie),se(r,n,e.bech32)}(t,e)}catch(t){}throw new Error(Gt(t)+" has no matching Address")}function ce(t,e){var r,n;e=e||l;try{r=oe(t)}catch(t){}if(r){if(r.version===e.pubKeyHash)return ki({hash:r.hash}).output;if(r.version===e.scriptHash)return ln({hash:r.hash}).output}else{try{n=ue(t)}catch(t){}if(n){if(n.prefix!==e.bech32)throw new Error(t+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return bn({hash:n.data}).output;if(32===n.data.length)return _n({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return gn({pubkey:n.data}).output}else if(n.version>=re&&n.version<=ee&&n.data.length>=te&&n.data.length<=Zt)return console.warn(ie),Ft([n.version+ne,n.data])}}return Qt.from(t,"hex")}const he=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),le=new Uint8Array(new Array(16).fill(0).map(((t,e)=>e)));let pe=[le],ye=[le.map((t=>(9*t+5)%16))];for(let t=0;t<4;t++)for(let e of[pe,ye])e.push(e[t].map((t=>he[t])));const de=[[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=>new Uint8Array(t))),ge=pe.map(((t,e)=>t.map((t=>de[e][t])))),we=ye.map(((t,e)=>t.map((t=>de[e][t])))),ve=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),me=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function be(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 Ee=new Uint32Array(16);class Se extends C{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)Ee[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,l=ve[t],p=me[t],y=pe[t],d=ye[t],g=ge[t],w=we[t];for(let e=0;e<16;e++){const n=O(r+be(t,i,u,s)+Ee[y[e]]+l,g[e])+c|0;r=c,c=s,s=0|O(u,10),u=i,i=n}for(let t=0;t<16;t++){const r=O(n+be(e,o,a,f)+Ee[d[t]]+p,w[t])+h|0;n=h,h=f,f=0|O(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(){Ee.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const Te=U((()=>new Se)),Ie=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),_e=new Uint32Array(80);class ke extends C{constructor(){super(64,20,8,!1),this.A=0|Ie[0],this.B=0|Ie[1],this.C=0|Ie[2],this.D=0|Ie[3],this.E=0|Ie[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)_e[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)_e[t]=O(_e[t-3]^_e[t-8]^_e[t-14]^_e[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=N(n,i,o),a=1518500249):t<40?(e=n^i^o,a=1859775393):t<60?(e=x(n,i,o),a=2400959708):(e=n^i^o,a=3395469782);const s=O(r,5)+e+u+a+_e[t]|0;u=o,o=i,i=O(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(){_e.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}const Ae=U((()=>new ke));var Oe=r(287).Buffer;function Pe(t){return Oe.from(Te(Uint8Array.from(t)))}function Be(t){return Oe.from(Ae(Uint8Array.from(t)))}function Ue(t){return Oe.from(K(Uint8Array.from(t)))}function Ne(t){return Oe.from(Te(K(Uint8Array.from(t))))}function xe(t){return Oe.from(K(K(Uint8Array.from(t))))}var Ce=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],Le={"BIP0340/challenge":Oe.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":Oe.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":Oe.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:Oe.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:Oe.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:Oe.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:Oe.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":Oe.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":Oe.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 He(t,e){return Ue(Oe.concat([Le[t],e]))}var Re=r(287).Buffer,De={};function Ke(t){var e;t?t!==De.eccLib&&(Fe("function"==typeof(e=t).isXOnlyPoint),Fe(e.isXOnlyPoint(Ve("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Fe(e.isXOnlyPoint(Ve("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Fe(e.isXOnlyPoint(Ve("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Fe(e.isXOnlyPoint(Ve("0000000000000000000000000000000000000000000000000000000000000001"))),Fe(!e.isXOnlyPoint(Ve("0000000000000000000000000000000000000000000000000000000000000000"))),Fe(!e.isXOnlyPoint(Ve("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Fe("function"==typeof e.xOnlyPointAddTweak),je.forEach((function(t){var r=e.xOnlyPointAddTweak(Ve(t.pubkey),Ve(t.tweak));null===t.result?Fe(null===r):(Fe(null!==r),Fe(r.parity===t.parity),Fe(Re.from(r.xOnlyPubkey).equals(Ve(t.result))))})),De.eccLib=t):De.eccLib=t}function Me(){if(!De.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return De.eccLib}var Ve=function(t){return Re.from(t,"hex")};function Fe(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"}],Ge=r(469),We=r(287).Buffer;function Xe(t){return Xe="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},Xe(t)}function qe(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ze(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,$e(n.key),n)}}function Ye(t,e,r){return e&&ze(t.prototype,e),r&&ze(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function $e(t){var e=function(t){if("object"!=Xe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Xe(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Xe(e)?e:e+""}var Je=nt;function Qe(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 Ze(t,e){var r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return Qe((n*=4294967296)+r,9007199254740991),n+r}function tr(t,e,r){return Qe(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}function er(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 rr(t){var e=We.allocUnsafe(t.length);return t.copy(e),e}var nr=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;qe(this,t),this.buffer=e,this.offset=r,Je(bt(wt,St),[e,r])}return Ye(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=tr(this.buffer,t,this.offset)}},{key:"writeVarInt",value:function(t){Ge.encode(t,this.buffer,this.offset),this.offset+=Ge.encode.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(We.alloc(e))}}])}(),ir=function(){return Ye((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;qe(this,t),this.buffer=e,this.offset=r,Je(bt(wt,St),[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=Ze(this.buffer,this.offset);return this.offset+=8,t}},{key:"readVarInt",value:function(){var t=Ge.decode(this.buffer,this.offset);return this.offset+=Ge.decode.bytes,t}},{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.slice(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 or(t){return function(t){if(Array.isArray(t))return ur(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 ur(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)?ur(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 ur(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 ar=192,sr=128,fr=function(t){return"left"in t&&"right"in t};function cr(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?gr(n,o):gr(o,n)}return n}function hr(t){if(ct(t))return{hash:pr(t)};var e=[hr(t[0]),hr(t[1])];e.sort((function(t,e){return t.hash.compare(e.hash)}));var r=e[0],n=e[1];return{hash:gr(r.hash,n.hash),left:r,right:n}}function lr(t,e){if(fr(t)){var r=lr(t.left,e);if(void 0!==r)return[].concat(or(r),[t.right.hash]);var n=lr(t.right,e);if(void 0!==n)return[].concat(or(n),[t.left.hash])}else if(t.hash.equals(e))return[]}function pr(t){var e,r,n,i=t.version||ar;return He("TapLeaf",et.Buffer.concat([et.Buffer.from([i]),(e=t.output,r=Ge.encodingLength(e.length),n=et.Buffer.allocUnsafe(r),Ge.encode(e.length,n),et.Buffer.concat([n,e]))]))}function yr(t,e){return He("TapTweak",et.Buffer.concat(e?[t,e]:[t]))}function dr(t,e){if(!et.Buffer.isBuffer(t))return null;if(32!==t.length)return null;if(e&&32!==e.length)return null;var r=yr(t,e),n=Me().xOnlyPointAddTweak(t,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:et.Buffer.from(n.xOnlyPubkey)}:null}function gr(t,e){return He("TapBranch",et.Buffer.concat([t,e]))}function wr(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 vr(t){var e;return function(){return void 0!==e?e:e=t()}}var mr=G;function br(t,e){if(!t.data&&!t.output)throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),nt({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),data:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r={name:"embed",network:t.network||l};if(wr(r,"output",(function(){if(t.data)return Ft([mr.OP_RETURN].concat(t.data))})),wr(r,"data",(function(){if(t.output)return jt(t.output).slice(1)})),e.validate&&t.output){var n=jt(t.output);if(n[0]!==mr.OP_RETURN)throw new TypeError("Output is invalid");if(!n.slice(1).every(nt.Buffer))throw new TypeError("Output is invalid");if(t.data&&!ut(t.data,r.data))throw new TypeError("Data mismatch")}return Object.assign(r,t)}var Er=G,Sr=Er.OP_RESERVED;function Tr(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 Yt(t)||void 0!==(e.allowIncomplete&&t===Er.OP_0)}e=Object.assign({validate:!0},e||{}),nt({network:nt.maybe(nt.Object),m:nt.maybe(nt.Number),n:nt.maybe(nt.Number),output:nt.maybe(nt.Buffer),pubkeys:nt.maybe(nt.arrayOf(at)),signatures:nt.maybe(nt.arrayOf(r)),input:nt.maybe(nt.Buffer)},t);var n={network:t.network||l},i=[],o=!1;function u(t){o||(o=!0,i=jt(t),n.m=i[0]-Sr,n.n=i[i.length-2]-Sr,n.pubkeys=i.slice(1,-2))}if(wr(n,"output",(function(){if(t.m&&n.n&&t.pubkeys)return Ft([].concat(Sr+t.m,t.pubkeys,Sr+n.n,Er.OP_CHECKMULTISIG))})),wr(n,"m",(function(){if(n.output)return u(n.output),n.m})),wr(n,"n",(function(){if(n.pubkeys)return n.pubkeys.length})),wr(n,"pubkeys",(function(){if(t.output)return u(t.output),n.pubkeys})),wr(n,"signatures",(function(){if(t.input)return jt(t.input).slice(1)})),wr(n,"input",(function(){if(t.signatures)return Ft([Er.OP_0].concat(t.signatures))})),wr(n,"witness",(function(){if(n.input)return[]})),wr(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),!nt.Number(i[0]))throw new TypeError("Output is invalid");if(!nt.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Er.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 at(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&&!ut(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]!==Er.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&&!ut(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 Ir=G;function _r(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||{}),nt({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),pubkey:nt.maybe(at),signature:nt.maybe(Yt),input:nt.maybe(nt.Buffer)},t);var r=vr((function(){return jt(t.input)})),n={name:"p2pk",network:t.network||l};if(wr(n,"output",(function(){if(t.pubkey)return Ft([t.pubkey,Ir.OP_CHECKSIG])})),wr(n,"pubkey",(function(){if(t.output)return t.output.slice(1,-1)})),wr(n,"signature",(function(){if(t.input)return r()[0]})),wr(n,"input",(function(){if(t.signature)return Ft([t.signature])})),wr(n,"witness",(function(){if(n.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Ir.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!at(n.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&!t.pubkey.equals(n.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&!t.input.equals(n.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!Yt(n.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(n,t)}const kr=2n**256n,Ar=kr-0x1000003d1n,Or=kr-0x14551231950b75fc4402da1732fc9bebfn,Pr=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Br=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,Ur={p:Ar,n:Or,a:0n,b:7n,Gx:Pr,Gy:Br},Nr=t=>Vr(Vr(t*t)*t+Ur.b),xr=(t="")=>{throw new Error(t)},Cr=t=>"bigint"==typeof t,Lr=t=>"string"==typeof t,Hr=t=>Cr(t)&&0n<t&&t<Ar,Rr=t=>Cr(t)&&0n<t&&t<Or,Dr=(t,e)=>!(t=>t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?xr("Uint8Array expected"):t,Kr=t=>new Uint8Array(t),Mr=(t,e)=>Dr(Lr(t)?zr(t):Kr(Dr(t)),e),Vr=(t,e=Ar)=>{let r=t%e;return r>=0n?r:e+r},Fr=t=>t instanceof jr?t:xr("Point expected");class jr{constructor(t,e,r){this.px=t,this.py=e,this.pz=r}static fromAffine(t){return 0n===t.x&&0n===t.y?jr.ZERO:new jr(t.x,t.y,1n)}static fromHex(t){let e;const r=(t=Mr(t))[0],n=t.subarray(1),i=$r(n,0,32),o=t.length;if(33===o&&[2,3].includes(r)){Hr(i)||xr("Point hex invalid: x not FE");let t=en(Nr(i));!(1&~r)!=(1n===(1n&t))&&(t=Vr(-t)),e=new jr(i,t,1n)}return 65===o&&4===r&&(e=new jr(i,$r(n,32,64),1n)),e?e.ok():xr("Point is not on curve")}static fromPrivateKey(t){return Gr.mul(rn(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}=Fr(t),a=Vr(e*u),s=Vr(i*n),f=Vr(r*u),c=Vr(o*n);return a===s&&f===c}negate(){return new jr(this.px,Vr(-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}=Fr(t),{a,b:s}=Ur;let f=0n,c=0n,h=0n;const l=Vr(3n*s);let p=Vr(e*i),y=Vr(r*o),d=Vr(n*u),g=Vr(e+r),w=Vr(i+o);g=Vr(g*w),w=Vr(p+y),g=Vr(g-w),w=Vr(e+n);let v=Vr(i+u);return w=Vr(w*v),v=Vr(p+d),w=Vr(w-v),v=Vr(r+n),f=Vr(o+u),v=Vr(v*f),f=Vr(y+d),v=Vr(v-f),h=Vr(a*w),f=Vr(l*d),h=Vr(f+h),f=Vr(y-h),h=Vr(y+h),c=Vr(f*h),y=Vr(p+p),y=Vr(y+p),d=Vr(a*d),w=Vr(l*w),y=Vr(y+d),d=Vr(p-d),d=Vr(a*d),w=Vr(w+d),p=Vr(y*w),c=Vr(c+p),p=Vr(v*w),f=Vr(g*f),f=Vr(f-p),p=Vr(g*y),h=Vr(v*h),h=Vr(h+p),new jr(f,c,h)}mul(t,e=!0){if(!e&&0n===t)return Wr;if(Rr(t)||xr("invalid scalar"),this.equals(Gr))return sn(t).p;let r=Wr,n=Gr;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(Wr))return{x:0n,y:0n};if(1n===r)return{x:t,y:e};const n=tn(r);return 1n!==Vr(r*n)&&xr("invalid inverse"),{x:Vr(t*n),y:Vr(e*n)}}assertValidity(){const{x:t,y:e}=this.aff();return Hr(t)&&Hr(e)||xr("Point invalid: x or y"),Vr(e*e)===Nr(t)?this:xr("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")+Qr(e)+(t?"":Qr(r))}toRawBytes(t=!0){return zr(this.toHex(t))}}jr.BASE=new jr(Pr,Br,1n),jr.ZERO=new jr(0n,1n,0n);const{BASE:Gr,ZERO:Wr}=jr,Xr=(t,e)=>t.toString(16).padStart(e,"0"),qr=t=>Array.from(t).map((t=>Xr(t,2))).join(""),zr=t=>{const e=t.length;(!Lr(t)||e%2)&&xr("hex invalid 1");const r=Kr(e/2);for(let e=0;e<r.length;e++){const n=2*e,i=t.slice(n,n+2),o=Number.parseInt(i,16);(Number.isNaN(o)||o<0)&&xr("hex invalid 2"),r[e]=o}return r},Yr=t=>BigInt("0x"+(qr(t)||"0")),$r=(t,e,r)=>Yr(t.slice(e,r)),Jr=t=>Cr(t)&&t>=0n&&t<kr?zr(Xr(t,64)):xr("bigint expected"),Qr=t=>qr(Jr(t)),Zr=(...t)=>{const e=Kr(t.reduce(((t,e)=>t+Dr(e).length),0));let r=0;return t.forEach((t=>{e.set(t,r),r+=t.length})),e},tn=(t,e=Ar)=>{(0n===t||e<=0n)&&xr("no inverse n="+t+" mod="+e);let r=Vr(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?Vr(i,e):xr("no inverse")},en=t=>{let e=1n;for(let r=t,n=(Ar+1n)/4n;n>0n;n>>=1n)1n&n&&(e=e*r%Ar),r=r*r%Ar;return Vr(e*e)===t?e:xr("sqrt invalid")},rn=t=>(Cr(t)||(t=Yr(Mr(t,32))),Rr(t)?t:xr("private key out of range")),nn=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;let on;const un={hexToBytes:zr,bytesToHex:qr,concatBytes:Zr,bytesToNumberBE:Yr,numberToBytesBE:Jr,mod:Vr,invert:tn,hmacSha256Async:async(t,...e)=>{const r=nn(),n=r&&r.subtle;if(!n)return xr("etc.hmacSha256Async not set");const i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Kr(await n.sign("HMAC",i,Zr(...e)))},hmacSha256Sync:on,hashToPrivateKey:t=>{((t=Mr(t)).length<40||t.length>1024)&&xr("expected proper params");const e=Vr(Yr(t),Or-1n)+1n;return Jr(e)},randomBytes:(t=32)=>{const e=nn();return e&&e.getRandomValues||xr("crypto.getRandomValues must be defined"),e.getRandomValues(Kr(t))}};let an;Object.defineProperties(un,{hmacSha256Sync:{configurable:!1,get:()=>on,set(t){on||(on=t)}}});const sn=t=>{const e=an||(an=(()=>{const t=[];let e=Gr,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=Wr,i=Gr;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,l=a%2!=0,p=f<0;0===f?i=i.add(r(l,e[c])):n=n.add(r(p,e[h]))}return{p:n,f:i}};var fn=r(394),cn=r(287).Buffer,hn=G;function ln(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),output:nt.maybe(nt.BufferN(23)),redeem:nt.maybe({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),input:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),input:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=t.network;r||(r=t.redeem&&t.redeem.network||l);var n={network:r},i=vr((function(){var e=cn.from(V.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),o=vr((function(){return jt(t.input)})),u=vr((function(){var e=o(),n=e[e.length-1];return{network:r,output:n===hn.OP_FALSE?cn.from([]):n,input:Ft(e.slice(0,-1)),witness:t.witness||[]}}));if(wr(n,"address",(function(){if(n.hash){var t=cn.allocUnsafe(21);return t.writeUInt8(n.network.scriptHash,0),n.hash.copy(t,1),V.encode(t)}})),wr(n,"hash",(function(){return t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?Ne(n.redeem.output):void 0})),wr(n,"output",(function(){if(n.hash)return Ft([hn.OP_HASH160,n.hash,hn.OP_EQUAL])})),wr(n,"redeem",(function(){if(t.input)return u()})),wr(n,"input",(function(){if(t.redeem&&t.redeem.input&&t.redeem.output)return Ft([].concat(jt(t.redeem.input),t.redeem.output))})),wr(n,"witness",(function(){return n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0})),wr(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=cn.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]!==hn.OP_HASH160||20!==t.output[1]||t.output[22]!==hn.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=Ne(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&&!Rt(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(!cn.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&&!ut(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var pn=G,yn=1,dn=80;function gn(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||{}),nt({address:nt.maybe(nt.String),input:nt.maybe(nt.BufferN(0)),network:nt.maybe(nt.Object),output:nt.maybe(nt.BufferN(34)),internalPubkey:nt.maybe(nt.BufferN(32)),hash:nt.maybe(nt.BufferN(32)),pubkey:nt.maybe(nt.BufferN(32)),signature:nt.maybe(nt.anyOf(nt.BufferN(64),nt.BufferN(65))),witness:nt.maybe(nt.arrayOf(nt.Buffer)),scriptTree:nt.maybe(ht),redeem:nt.maybe({output:nt.maybe(nt.Buffer),redeemVersion:nt.maybe(nt.Number),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),redeemVersion:nt.maybe(nt.Number)},t);var r=vr((function(){return ue(t.address)})),n=vr((function(){if(t.witness&&t.witness.length)return t.witness.length>=2&&t.witness[t.witness.length-1][0]===dn?t.witness.slice(0,-1):t.witness.slice()})),i=vr((function(){return t.scriptTree?hr(t.scriptTree):t.hash?{hash:t.hash}:void 0})),o=t.network||l,u={name:"p2tr",network:o};if(wr(u,"address",(function(){if(u.pubkey){var t=T.p2.toWords(u.pubkey);return t.unshift(yn),T.p2.encode(o.bech32,t)}})),wr(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]&ft;return cr(r,pr({output:e[e.length-2],version:o}))}return null})),wr(u,"output",(function(){if(u.pubkey)return Ft([pn.OP_1,u.pubkey])})),wr(u,"redeemVersion",(function(){return t.redeemVersion?t.redeemVersion:t.redeem&&void 0!==t.redeem.redeemVersion&&null!==t.redeem.redeemVersion?t.redeem.redeemVersion:ar})),wr(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]&ft}})),wr(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=dr(u.internalPubkey,u.hash);if(e)return e.x}})),wr(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})),wr(u,"signature",(function(){if(t.signature)return t.signature;var e=n();return e&&1===e.length?e[0]:void 0})),wr(u,"witness",(function(){if(t.witness)return t.witness;var e=i();if(e&&t.redeem&&t.redeem.output&&t.internalPubkey){var r=lr(e,pr({output:t.redeem.output,version:u.redeemVersion}));if(!r)return;var n=dr(t.internalPubkey,e.hash);if(!n)return;var o=et.Buffer.concat([et.Buffer.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=et.Buffer.from([]);if(t.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==yn)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]!==pn.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=dr(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&&!lr(f,pr({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&&!ut(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 p=(h.length-33)/32;if(p>128)throw new TypeError("The script path is too long. Got ".concat(p,", expected max 128."));var y=h.slice(1,33);if(t.internalPubkey&&!t.internalPubkey.equals(y))throw new TypeError("Internal pubkey mismatch");if(!Me().isXOnlyPoint(y))throw new TypeError("Invalid internalPubkey for p2tr witness");var d=h[0]&ft,g=dr(y,cr(h,pr({output:c[c.length-2],version:d})));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 wn=r(287).Buffer,vn=G,mn=wn.alloc(0);function bn(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||{}),nt({address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),input:nt.maybe(nt.BufferN(0)),network:nt.maybe(nt.Object),output:nt.maybe(nt.BufferN(22)),pubkey:nt.maybe(at),signature:nt.maybe(Yt),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=vr((function(){var e=T.I.decode(t.address),r=e.words.shift(),n=T.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:wn.from(n)}})),n=t.network||l,i={name:"p2wpkh",network:n};if(wr(i,"address",(function(){if(i.hash){var t=T.I.toWords(i.hash);return t.unshift(0),T.I.encode(n.bech32,t)}})),wr(i,"hash",(function(){return t.output?t.output.slice(2,22):t.address?r().data:t.pubkey||i.pubkey?Ne(t.pubkey||i.pubkey):void 0})),wr(i,"output",(function(){if(i.hash)return Ft([vn.OP_0,i.hash])})),wr(i,"pubkey",(function(){return t.pubkey?t.pubkey:t.witness?t.witness[1]:void 0})),wr(i,"signature",(function(){if(t.witness)return t.witness[0]})),wr(i,"input",(function(){if(i.witness)return mn})),wr(i,"witness",(function(){if(t.pubkey&&t.signature)return[t.signature,t.pubkey]})),e.validate){var o=wn.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]!==vn.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=Ne(t.pubkey);if(o.length>0&&!o.equals(u))throw new TypeError("Hash mismatch");if(o=u,!at(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(!Yt(t.witness[0]))throw new TypeError("Witness has invalid signature");if(!at(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=Ne(t.witness[1]);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(i,t)}var En=r(287).Buffer,Sn=G,Tn=En.alloc(0);function In(t){return!(!En.isBuffer(t)||65!==t.length||4!==t[0]||!at(t))}function _n(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(32)),output:nt.maybe(nt.BufferN(34)),redeem:nt.maybe({input:nt.maybe(nt.Buffer),network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),input:nt.maybe(nt.BufferN(0)),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=vr((function(){var e=T.I.decode(t.address),r=e.words.shift(),n=T.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:En.from(n)}})),n=vr((function(){return jt(t.redeem.input)})),i=t.network;i||(i=t.redeem&&t.redeem.network||l);var o={network:i};if(wr(o,"address",(function(){if(o.hash){var t=T.I.toWords(o.hash);return t.unshift(0),T.I.encode(i.bech32,t)}})),wr(o,"hash",(function(){return t.output?t.output.slice(2):t.address?r().data:o.redeem&&o.redeem.output?Ue(o.redeem.output):void 0})),wr(o,"output",(function(){if(o.hash)return Ft([Sn.OP_0,o.hash])})),wr(o,"redeem",(function(){if(t.witness)return{output:t.witness[t.witness.length-1],input:Tn,witness:t.witness.slice(0,-1)}})),wr(o,"input",(function(){if(o.witness)return Tn})),wr(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=Tn,[].concat(e,t.redeem.output)}if(t.redeem&&t.redeem.output&&t.redeem.witness)return[].concat(t.redeem.witness,t.redeem.output)})),wr(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=En.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]!==Sn.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=Ue(t.redeem.output);if(u.length>0&&!u.equals(f))throw new TypeError("Hash mismatch");u=f}if(t.redeem.input&&!Rt(n()))throw new TypeError("Non push-only scriptSig");if(t.witness&&t.redeem.witness&&!ut(t.witness,t.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(t.redeem.input&&n().some(In)||t.redeem.output&&(jt(t.redeem.output)||[]).some(In))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(In)||(jt(c)||[]).some(In))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,t)}var kn=r(287).Buffer;function An(t){return An="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},An(t)}function On(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,Bn(n.key),n)}}function Pn(t,e,r){return(e=Bn(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Bn(t){var e=function(t){if("object"!=An(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=An(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==An(e)?e:e+""}var Un=nt;function Nn(t){var e=t.length;return Ge.encodingLength(e)+e}var xn=kn.allocUnsafe(0),Cn=[],Ln=kn.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Hn=kn.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Rn=kn.from("ffffffffffffffff","hex"),Dn={script:xn,valueBuffer:Rn},Kn=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Pn(this,"version",1),Pn(this,"locktime",0),Pn(this,"ins",[]),Pn(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 Un(bt(pt,St,mt(St),mt(wt)),arguments),_t(n)&&(n=t.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:r,script:i||xn,sequence:n,witness:Cn})-1}},{key:"addOutput",value:function(t,e){return Un(bt(wt,st),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)+Ge.encodingLength(this.ins.length)+Ge.encodingLength(this.outs.length)+this.ins.reduce((function(t,e){return t+40+Nn(e.script)}),0)+this.outs.reduce((function(t,e){return t+8+Nn(e.script)}),0)+(t?this.ins.reduce((function(t,e){return t+(n=(r=e.witness).length,Ge.encodingLength(n)+r.reduce((function(t,e){return t+Nn(e)}),0));var r,n}),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(Un(bt(St,wt,yt),arguments),e>=this.ins.length)return Hn;var i=Ft(jt(r).filter((function(t){return t!==G.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 Hn;o.outs.length=e+1;for(var u=0;u<e;u++)o.outs[u]=Dn;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),xe(a)}},{key:"hashForWitnessV1",value:function(e,r,n,i,o,u){if(Un(bt(St,Un.arrayOf(wt),Un.arrayOf(st),St),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,l=xn,p=xn,y=xn,d=xn;if(!s){var g=nr.withCapacity(36*this.ins.length);this.ins.forEach((function(t){g.writeSlice(t.hash),g.writeUInt32(t.index)})),h=Ue(g.end()),g=nr.withCapacity(8*this.ins.length),n.forEach((function(t){return g.writeUInt64(t)})),l=Ue(g.end()),g=nr.withCapacity(r.map(Nn).reduce((function(t,e){return t+e}))),r.forEach((function(t){return g.writeVarSlice(t)})),p=Ue(g.end()),g=nr.withCapacity(4*this.ins.length),this.ins.forEach((function(t){return g.writeUInt32(t.sequence)})),y=Ue(g.end())}if(f||c){if(c&&e<this.outs.length){var w=this.outs[e],v=nr.withCapacity(8+Nn(w.script));v.writeUInt64(w.value),v.writeVarSlice(w.script),d=Ue(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+Nn(t.script)})).reduce((function(t,e){return t+e})),b=nr.withCapacity(m);this.outs.forEach((function(t){b.writeUInt64(t.value),b.writeVarSlice(t.script)})),d=Ue(b.end())}var E=(o?2:0)+(u?1:0),S=174-(s?49:0)-(f?32:0)+(u?32:0)+(o?37:0),T=nr.withCapacity(S);if(T.writeUInt8(i),T.writeInt32(this.version),T.writeUInt32(this.locktime),T.writeSlice(h),T.writeSlice(l),T.writeSlice(p),T.writeSlice(y),f||c||T.writeSlice(d),T.writeUInt8(E),s){var I=this.ins[e];T.writeSlice(I.hash),T.writeUInt32(I.index),T.writeUInt64(n[e]),T.writeVarSlice(r[e]),T.writeUInt32(I.sequence)}else T.writeUInt32(e);if(u){var _=nr.withCapacity(Nn(u));_.writeVarSlice(u),T.writeSlice(Ue(_.end()))}return c&&T.writeSlice(d),o&&(T.writeSlice(o),T.writeUInt8(0),T.writeUInt32(4294967295)),He("TapSighash",kn.concat([kn.from([0]),T.end()]))}},{key:"hashForWitnessV0",value:function(e,r,n,i){Un(bt(St,wt,st,St),arguments);var o,u=kn.from([]),a=Ln,s=Ln,f=Ln;if(i&t.SIGHASH_ANYONECANPAY||(u=kn.allocUnsafe(36*this.ins.length),o=new nr(u,0),this.ins.forEach((function(t){o.writeSlice(t.hash),o.writeUInt32(t.index)})),s=xe(u)),i&t.SIGHASH_ANYONECANPAY||(31&i)===t.SIGHASH_SINGLE||(31&i)===t.SIGHASH_NONE||(u=kn.allocUnsafe(4*this.ins.length),o=new nr(u,0),this.ins.forEach((function(t){o.writeUInt32(t.sequence)})),f=xe(u)),(31&i)!==t.SIGHASH_SINGLE&&(31&i)!==t.SIGHASH_NONE){var c=this.outs.reduce((function(t,e){return t+8+Nn(e.script)}),0);u=kn.allocUnsafe(c),o=new nr(u,0),this.outs.forEach((function(t){o.writeUInt64(t.value),o.writeVarSlice(t.script)})),a=xe(u)}else if((31&i)===t.SIGHASH_SINGLE&&e<this.outs.length){var h=this.outs[e];u=kn.allocUnsafe(8+Nn(h.script)),(o=new nr(u,0)).writeUInt64(h.value),o.writeVarSlice(h.script),a=xe(u)}u=kn.allocUnsafe(156+Nn(r)),o=new nr(u,0);var l=this.ins[e];return o.writeInt32(this.version),o.writeSlice(s),o.writeSlice(f),o.writeSlice(l.hash),o.writeUInt32(l.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(l.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),xe(u)}},{key:"getHash",value:function(t){return t&&this.isCoinbase()?kn.alloc(32,0):xe(this.__toBuffer(void 0,void 0,t))}},{key:"getId",value:function(){return er(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){Un(bt(yt,wt),arguments),this.ins[t].script=e}},{key:"setWitness",value:function(t,e){Un(bt(yt,[wt]),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 nr(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 ir(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(),l=n.readVarSlice(),p=n.readUInt32();i.ins.push({hash:c,index:h,script:l,sequence:p,witness:Cn})}for(var y=n.readVarInt(),d=0;d<y;++d)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){Un(pt,t);for(var e=0;e<32;++e)if(0!==t[e])return!1;return!0}}],r&&On(e.prototype,r),n&&On(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();Pn(Kn,"DEFAULT_SEQUENCE",4294967295),Pn(Kn,"SIGHASH_DEFAULT",0),Pn(Kn,"SIGHASH_ALL",1),Pn(Kn,"SIGHASH_NONE",2),Pn(Kn,"SIGHASH_SINGLE",3),Pn(Kn,"SIGHASH_ANYONECANPAY",128),Pn(Kn,"SIGHASH_OUTPUT_MASK",3),Pn(Kn,"SIGHASH_INPUT_MASK",128),Pn(Kn,"ADVANCED_TRANSACTION_MARKER",0),Pn(Kn,"ADVANCED_TRANSACTION_FLAG",1);var Mn=r(287).Buffer;function Vn(t,e){if(t){if("string"==typeof t)return Fn(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)?Fn(t,e):void 0}}function Fn(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 jn=function(t){var e=32===t.length?t:t.slice(1,33);return Mn.isBuffer(e)?e:Mn.from(e)};function Gn(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=pr({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=pr({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:mi(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:di(i.concat(n.script).concat(n.controlBlock))}}catch(e){throw new Error("Can not finalize taproot input #".concat(t,": ").concat(e))}}function Wn(t,e){var r=e?Mn.from([e]):Mn.from([]);return Mn.concat([t,r])}function Xn(t){return t&&!!(t.tapInternalKey||t.tapMerkleRoot||t.tapLeafScript&&t.tapLeafScript.length||t.tapBip32Derivation&&t.tapBip32Derivation.length||t.witnessUtxo&&yi(t.witnessUtxo.script))}function qn(t,e){return t&&!!(t.tapInternalKey||t.tapTree||t.tapBip32Derivation&&t.tapBip32Derivation.length||e&&yi(e))}function zn(t,e,r){!function(t,e,r){var n=Xn(t)&&oi(e),i=oi(t)&&Xn(e),o=t===e&&Xn(e)&&oi(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 ii(t,e.tapMerkleRoot)})),i=(t.tapLeafScript||[]).every((function(t){return ii(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 ii(e,t.tapMerkleRoot)})))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}(t,e,r)}function Yn(t,e,r){!function(t,e,r){var n=qn(t)&&oi(e),i=oi(t)&&qn(e),o=t===e&&qn(e)&&oi(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 gn({internalPubkey:t,scriptTree:e&&Qn(e.leaves)}).output}(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}}(t,e)}function $n(t,e){var r=e.tapInternalKey,n=r&&dr(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 Jn(t){if(!ht(t))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ri(t)}function Qn(){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=Vn(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=ni(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 Zn(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 Fn(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)||Vn(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=ei(t.finalScriptWitness);n&&r.push(n)}return r}(t);return r.some((function(t){return Si(t,ti,e)}))}function ti(t){return{signature:t.slice(0,64),hashType:t.slice(64)[0]||Kn.SIGHASH_DEFAULT}}function ei(t){if(t){var e=t.slice(2);return 64===e.length||65===e.length?e:void 0}}function ri(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>sr)throw new Error("Max taptree depth exceeded.");return t?ct(t)?(e.push({depth:r,leafVersion:t.version||ar,script:t.output}),e):(t[0]&&ri(t[0],e,r+1),t[1]&&ri(t[1],e,r+1),e):[]}function ni(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>sr)throw new Error("Max taptree depth exceeded.");if(t.depth===r)return e?void 0:{output:t.script,version:t.leafVersion};if(!ct(e)){var n=ni(t,e&&e[0],r+1);if(n)return[n,e&&e[1]];var i=ni(t,e&&e[1],r+1);return i?[e&&e[0],i]:void 0}}function ii(t,e){if(!e)return!0;var r=pr({output:t.script,version:t.leafVersion});return cr(t.controlBlock,r).equals(e)}function oi(t){return t&&!!(t.redeemScript||t.witnessScript||t.bip32Derivation&&t.bip32Derivation.length)}var ui=r(287).Buffer;function ai(t){return function(e){try{return t({output:e}),!0}catch(t){return!1}}}var si=ai(Tr),fi=ai(_r),ci=ai(ki),hi=ai(bn),li=ai(_n),pi=ai(ln),yi=ai(gn);function di(t){var e,r=ui.allocUnsafe(0);function n(t){var e=r.length,n=fn.encodingLength(t);r=ui.concat([r,ui.allocUnsafe(n)]),fn.encode(t,r,e)}return n((e=t).length),e.forEach((function(t){n(t.length),function(t){r=ui.concat([r,ui.from(t)])}(t)})),r}function gi(t){if(![33,65].includes(t.length))throw new Error("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed)."));var e;try{e=jr.fromHex(t)}catch(t){throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}var r=wi(e.x),n=wi(e.y),i=e.y%2n===0n?6:7,o=ui.alloc(65);return o[0]=i,r.copy(o,1),n.copy(o,33),{hybrid:o,uncompressed:ui.concat([ui.from([4]),r,n])}}function wi(t){var e=t.toString(16);return(e=e.padStart(64,"0")).length>64&&(e=e.slice(-64)),ui.from(e,"hex")}function vi(t,e){if(t.equals(e))return!0;if(65===t.length&&65===e.length){var r=ui.from(t),n=ui.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 mi(t,e){var r=jt(e);if(null===r)throw new Error("Unknown script error");var n=Ne(t),i=jn(t),o=gi(t),u=Ne(o.hybrid),a=Ne(o.uncompressed);return r.findIndex((function(e){return"number"!=typeof e&&(!!vi(e,t)||!!vi(e,i)||!!e.equals(n)||!!vi(e,o.uncompressed)||!!vi(e,o.hybrid)||!(!e.equals(u)&&!e.equals(a))||void 0)}))}function bi(t,e){return-1!==mi(t,e)}function Ei(t,e){var r=function(t){var e=[];if(0===(t.partialSig||[]).length){if(!t.finalScriptSig&&!t.finalScriptWitness)return[];e=Ti(t)}else e=t.partialSig;return e.map((function(t){return t.signature}))}(t);return r.some((function(t){return Si(t,Jt.decode,e)}))}function Si(t,e,r){var n=e(t).hashType,i=[];switch(n&Kn.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case Kn.SIGHASH_ALL:break;case Kn.SIGHASH_SINGLE:case Kn.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function Ti(t){var e=t.finalScriptSig&&jt(t.finalScriptSig)||[],r=t.finalScriptWitness&&jt(t.finalScriptWitness)||[];return e.concat(r).filter((function(t){return ui.isBuffer(t)&&Yt(t)})).map((function(t){return{signature:t}}))}var Ii=r(287).Buffer,_i=G;function ki(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),output:nt.maybe(nt.BufferN(25)),pubkey:nt.maybe(at),signature:nt.maybe(Yt),input:nt.maybe(nt.Buffer)},t);var r=vr((function(){var e=Ii.from(V.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),n=vr((function(){return jt(t.input)})),i=t.network||l,o={name:"p2pkh",network:i};if(wr(o,"address",(function(){if(o.hash){var t=Ii.allocUnsafe(21);return t.writeUInt8(i.pubKeyHash,0),o.hash.copy(t,1),V.encode(t)}})),wr(o,"hash",(function(){return t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?Ne(t.pubkey||o.pubkey):void 0})),wr(o,"output",(function(){if(o.hash)return Ft([_i.OP_DUP,_i.OP_HASH160,o.hash,_i.OP_EQUALVERIFY,_i.OP_CHECKSIG])})),wr(o,"pubkey",(function(){if(t.input)return n()[1]})),wr(o,"signature",(function(){if(t.input)return n()[0]})),wr(o,"input",(function(){if(t.pubkey&&t.signature){var e=t.pubkey;if(t.useHybrid||t.useUncompressed){var r=gi(t.pubkey);e=t.useUncompressed?r.uncompressed:r.hybrid}return Ft([t.signature,e])}})),wr(o,"witness",(function(){if(o.input)return[]})),e.validate){var u=Ii.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]!==_i.OP_DUP||t.output[1]!==_i.OP_HASH160||20!==t.output[2]||t.output[23]!==_i.OP_EQUALVERIFY||t.output[24]!==_i.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=Ne(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=gi(t.pubkey),h=Ne(c.uncompressed);if(u.equals(h))f=!1,t.useUncompressed=!0;else{var p=Ne(c.hybrid);(f=!u.equals(p))||(t.useHybrid=!0)}}if(f)throw new TypeError("Hash mismatch");u=s}if(t.input){var y=n();if(2!==y.length)throw new TypeError("Input is invalid");if(!Yt(y[0]))throw new TypeError("Input has invalid signature");if(!at(y[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&!t.signature.equals(y[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(y[1]))throw new TypeError("Pubkey mismatch");var d=Ne(y[1]);if(u.length>0&&!u.equals(d))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,t)}var Ai=r(287).Buffer,Oi=r(287).Buffer;function Pi(t){return Pi="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},Pi(t)}function Bi(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,Ni(n.key),n)}}function Ui(t,e,r){return(e=Ni(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Ni(t){var e=function(t){if("object"!=Pi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Pi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pi(e)?e:e+""}var xi=nt,Ci=new TypeError("Cannot compute merkle root for zero transactions"),Li=new TypeError("Cannot compute witness commit for non-segwit block"),Hi=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Ui(this,"version",1),Ui(this,"prevHash",void 0),Ui(this,"merkleRoot",void 0),Ui(this,"timestamp",0),Ui(this,"witnessCommit",void 0),Ui(this,"bits",0),Ui(this,"nonce",0),Ui(this,"transactions",void 0)}return e=t,r=[{key:"getWitnessCommit",value:function(){if(!Ri(this.transactions))return null;var t=this.transactions[0].outs.filter((function(t){return t.script.slice(0,6).equals(Oi.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 Oi&&32===e.length?e:null}},{key:"hasWitnessCommit",value:function(){return this.witnessCommit instanceof Oi&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}},{key:"hasWitness",value:function(){return(t=this.transactions)instanceof Array&&t.some((function(t){return"object"===Pi(t)&&t.ins instanceof Array&&t.ins.some((function(t){return"object"===Pi(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+Ge.encodingLength(this.transactions.length)+this.transactions.reduce((function(t,r){return t+r.byteLength(e)}),0)}},{key:"getHash",value:function(){return xe(this.toBuffer(!0))}},{key:"getId",value:function(){return er(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=Oi.allocUnsafe(this.byteLength(t)),r=new nr(e);return 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||(Ge.encode(this.transactions.length,e,r.offset),r.offset+=Ge.encode.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=er(this.getHash()),r=t.calculateTarget(this.bits);return e.compare(r)<=0}},{key:"__checkMerkleRoot",value:function(){if(!this.transactions)throw Ci;var e=t.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}},{key:"__checkWitnessCommit",value:function(){if(!this.transactions)throw Ci;if(!this.hasWitnessCommit())throw Li;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 ir(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=Kn.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(Oi.from(e,"hex"))}},{key:"calculateTarget",value:function(t){var e=((4278190080&t)>>24)-3,r=8388607&t,n=Oi.alloc(32,0);return n.writeUIntBE(r,29-e,3),n}},{key:"calculateMerkleRoot",value:function(t,e){if(xi([{getHash:Tt}],t),0===t.length)throw Ci;if(e&&!Ri(t))throw Li;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=Ai.concat([u,a]);n[i]=e(s)}r=i}return n[0]}(t.map((function(t){return t.getHash(e)})),xe);return e?xe(Oi.concat([r,t[0].ins[0].witness[0]])):r}}],r&&Bi(e.prototype,r),n&&Bi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function Ri(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 Di=r(614),Ki=r(699);function Mi(t){return Mi="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},Mi(t)}function Vi(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 Fi(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,ji(n.key),n)}}function ji(t){var e=function(t){if("object"!=Mi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Mi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Mi(e)?e:e+""}var Gi=function(){return t=function t(){var e,r,n,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e=this,r="cacheByLength",n=new Map,(r=ji(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,this.registry=new FinalizationRegistry((function(t){var e=i.cacheByLength.get(t.length);e&&(e.delete(t),0===e.size&&i.cacheByLength.delete(t.length))}))},e=[{key:"addSignature",value:function(t,e){var r=t.length,n={length:r,dataRef:new WeakRef(t),signature:e};return this.cacheByLength.has(r)||this.cacheByLength.set(r,new Set),this.cacheByLength.get(r).add(n),this.registry.register(t,n),e}},{key:"getSignature",value:function(t){var e=t.length,r=this.cacheByLength.get(e);if(r){var n,i=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Vi(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)?Vi(t,e):void 0}}(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}}}}(r);try{for(i.s();!(n=i.n()).done;){var o=n.value,u=o.dataRef.deref();if(u&&u.equals(t))return o.signature}}catch(t){i.e(t)}finally{i.f()}}}},{key:"clearCache",value:function(){this.cacheByLength.clear()}}],e&&Fi(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Wi(t){return Wi="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},Wi(t)}function Xi(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 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,zi(n.key),n)}}function zi(t){var e=function(t){if("object"!=Wi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Wi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Wi(e)?e:e+""}var Yi=function(){function t(){var e,r,n,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e=this,r="cacheBySigner",n=new Map,(r=zi(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,this.registry=new FinalizationRegistry((function(t){var e=i.cacheBySigner.get(t.pubKey);e&&(e.delete(t),0===e.size&&i.cacheBySigner.delete(t.pubKey))}))}return e=t,r=[{key:"addSignature",value:function(t,e,r){var n={pubKey:t,dataRef:new WeakRef(e),signature:r};return this.cacheBySigner.has(t)||this.cacheBySigner.set(t,new Set),this.cacheBySigner.get(t).add(n),this.registry.register(e,n),r}},{key:"getSignature",value:function(t,e){var r=this.cacheBySigner.get(t);if(r){var n,i=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Xi(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)?Xi(t,e):void 0}}(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}}}}(r);try{for(i.s();!(n=i.n()).done;){var o=n.value,u=o.dataRef.deref();if(u&&u.equals(e))return o.signature}}catch(t){i.e(t)}finally{i.f()}}}},{key:"clearCache",value:function(){this.cacheBySigner.clear()}},{key:"clearCacheForSigner",value:function(t){this.cacheBySigner.delete(t)}}],n=[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}],r&&qi(e.prototype,r),n&&qi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}(),$i=r(287).Buffer,Ji=Yi.getInstance();function Qi(t){if(t.publicKey&&$i.isBuffer(t.publicKey))return t.publicKey.toString("hex")}function Zi(t){var e=t;e.hasHook||(e.hasHook=!0,e.signatureManager=new Gi,function(t){var e=t.sign;e&&(t.sign=new Proxy(e,{apply:function(e,r,n){var i=Qi(t),o=n[0];if(i){var u=Ji.getSignature(i,o);return u||(u=Ji.addSignature(i,o,Reflect.apply(e,r,n))),u}var a=t.signatureManager.getSignature(o);return a||(a=t.signatureManager.addSignature(o,Reflect.apply(e,r,n))),a}}));var r=t.signSchnorr;r&&(t.signSchnorr=new Proxy(r,{apply:function(e,r,n){var i=Qi(t),o=n[0];if(i){var u=Ji.getSignature(i,o);return u||(u=Ji.addSignature(i,o,Reflect.apply(e,r,n))),u}var a=t.signatureManager.getSignature(o);return a||(a=t.signatureManager.addSignature(o,Reflect.apply(e,r,n))),a}}))}(e))}var to=r(287).Buffer;function eo(t){return eo="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},eo(t)}function ro(){ro=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,u=Object.create(o.prototype),a=new B(n||[]);return i(u,"_invoke",{value:k(t,r,a)}),u}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var l="suspendedStart",p="suspendedYield",y="executing",d="completed",g={};function w(){}function v(){}function m(){}var b={};f(b,u,(function(){return this}));var E=Object.getPrototypeOf,S=E&&E(E(U([])));S&&S!==r&&n.call(S,u)&&(b=S);var T=m.prototype=w.prototype=Object.create(b);function I(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,e){function r(i,o,u,a){var s=h(t[i],t,o);if("throw"!==s.type){var f=s.arg,c=f.value;return c&&"object"==eo(c)&&n.call(c,"__await")?e.resolve(c.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(c).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,a)}))}a(s.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,i){r(t,n,e,i)}))}return o=o?o.then(i,i):i()}})}function k(e,r,n){var i=l;return function(o,u){if(i===y)throw Error("Generator is already running");if(i===d){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=A(a,n);if(s){if(s===g)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===l)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var f=h(e,r,n);if("normal"===f.type){if(i=n.done?d:p,f.arg===g)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(i=d,n.method="throw",n.arg=f.arg)}}}function A(e,r){var n=r.method,i=e.iterator[n];if(i===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,A(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var o=h(i,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,g;var u=o.arg;return u?u.done?(r[e.resultName]=u.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):u:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function B(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function U(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=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 o.next=o}}throw new TypeError(eo(e)+" is not iterable")}return v.prototype=m,i(T,"constructor",{value:m,configurable:!0}),i(m,"constructor",{value:v,configurable:!0}),v.displayName=f(m,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,f(t,s,"GeneratorFunction")),t.prototype=Object.create(T),t},e.awrap=function(t){return{__await:t}},I(_.prototype),f(_.prototype,a,(function(){return this})),e.AsyncIterator=_,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new _(c(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},I(T),f(T,s,"Generator"),f(T,u,(function(){return this})),f(T,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=U,B.prototype={constructor:B,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!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].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function i(n,i){return a.type="throw",a.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],a=u.completion;if("root"===u.tryLoc)return i("end");if(u.tryLoc<=this.prev){var s=n.call(u,"catchLoc"),f=n.call(u,"finallyLoc");if(s&&f){if(this.prev<u.catchLoc)return i(u.catchLoc,!0);if(this.prev<u.finallyLoc)return i(u.finallyLoc)}else if(s){if(this.prev<u.catchLoc)return i(u.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return i(u.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(u)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:U(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function no(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 io(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){no(o,n,i,u,a,"next",t)}function a(t){no(o,n,i,u,a,"throw",t)}u(void 0)}))}}function oo(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=ao(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 uo(t){return function(t){if(Array.isArray(t))return so(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||ao(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 ao(t,e){if(t){if("string"==typeof t)return so(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)?so(t,e):void 0}}function so(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 fo(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function co(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,lo(n.key),n)}}function ho(t,e,r){return e&&co(t.prototype,e),r&&co(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function lo(t){var e=function(t){if("object"!=eo(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=eo(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==eo(e)?e:e+""}var po={network:l,maximumFeeRate:5e3},yo=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 Di.i(new wo);fo(this,t),this.data=r,this.opts=Object.assign({},po,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 ho(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:rr(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=fe(e.script,t.opts.network)}catch(t){}return{script:rr(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,uo(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){So(t),this.opts.maximumFeeRate=t}},{key:"setVersion",value:function(t){So(t),To(this.data.inputs,"setVersion");var e=this.__CACHE;return e.__TX.version=t,e.__EXTRACTED_TX=void 0,this}},{key:"setLocktime",value:function(t){So(t),To(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){So(e),To(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]");zn(t,t,"addInput"),e&&To(this.data.inputs,"addInput"),t.witnessScript&&qo(t.witnessScript);var r=this.__CACHE;this.data.addInput(t),_o(r,r.__TX.ins[r.__TX.ins.length-1]);var n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&Mo(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]");To(this.data.inputs,"addOutput");var e=t.address;if("string"==typeof e){var r=ce(e,this.opts.network);t=Object.assign({},t,{script:r})}Yn(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(bo))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 Vo(this.data.inputs,n,r,!0,e),n}},{key:"getFeeRate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Po("__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 Po("__FEE","fee",this.data.inputs,this.__CACHE,t)}},{key:"finalizeAllInputs",value:function(){var t=this;return(0,Ki.checkForInput)(this.data.inputs,0),Yo(this.data.inputs.length).forEach((function(e){return t.finalizeInput(e)})),this}},{key:"finalizeInput",value:function(t,e,r){var n=(0,Ki.checkForInput)(this.data.inputs,t);return Xn(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]:Gn,n=(0,Ki.checkForInput)(this.data.inputs,t);if(Xn(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,Ki.checkForInput)(this.data.inputs,t),r=Xo(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(to.isBuffer(r)&&!Wo(r)&&!Yt(r))if(jt(r))return r}}}(e.finalScriptSig),e.witnessScript||function(t){if(t){var e=Ko(t),r=e[e.length-1];if(!Wo(r)&&jt(r))return r}}(e.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+zo(r.meaningfulScript)}},{key:"inputHasPubkey",value:function(t,e){return function(t,e,r,n){return bi(t,Xo(jo(r,e,n),r,"input",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,Ki.checkForInput)(this.data.inputs,t),t,this.__CACHE)}},{key:"inputHasHDKey",value:function(t,e){var r=(0,Ki.checkForInput)(this.data.inputs,t),n=Eo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"outputHasPubkey",value:function(t,e){return function(t,e,r,n){return bi(t,Xo(n.__TX.outs[r].script,r,"output",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,Ki.checkForOutput)(this.data.outputs,t),t,this.__CACHE)}},{key:"outputHasHDKey",value:function(t,e){var r=(0,Ki.checkForOutput)(this.data.outputs,t),n=Eo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"validateSignaturesOfAllInputs",value:function(t){var e=this;return(0,Ki.checkForInput)(this.data.inputs,0),Yo(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 Xn(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]:[Kn.SIGHASH_ALL];if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");var r,n=[],i=oo(Yo(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]:[Kn.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=oo(Yo(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]:[Kn.SIGHASH_ALL];if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");return Do(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]:[Kn.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=Do(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=oo(Yo(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=oo(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)||ao(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,Ki.checkForInput)(this.data.inputs,t);return Xn(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,Ki.checkForInput)(this.data.inputs,t);if(Xn(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,Ki.checkForInput)(n.data.inputs,t);return Xn(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,Ki.checkForInput)(i.data.inputs,t);if(Xn(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 vo(this.__CACHE),this.data.toBuffer()}},{key:"toHex",value:function(){return vo(this.__CACHE),this.data.toHex()}},{key:"toBase64",value:function(){return vo(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&&qo(e.witnessScript),zn(this.data.inputs[t],e,"updateInput"),this.data.updateInput(t,e),e.nonWitnessUtxo&&Mo(this.__CACHE,this.data.inputs[t],t),this}},{key:"updateOutput",value:function(t,e){return Yn(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=Ho(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]:Bo,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=Fo(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||hi(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=Jt.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]:Gn;if(!e.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing witness utxo."));if(e.tapKeySig){var i=di(gn({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=oo(o);try{for(h.s();!(f=h.n()).done;){var l=f.value,p=Jt.decode(l.signature),y=s!==p.hashType?xo(t,Object.assign({},n,{sighashType:p.hashType}),this.__CACHE,!0):{hash:u,script:a},d=y.hash,g=y.script;s=p.hashType,u=d,a=g,Io(l.pubkey,g,"verify"),c.push(e(l.pubkey,d,p.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&&jn(r))?Ho(t,n,this.data.inputs,r,this.__CACHE):function(t,e,r,n){var i=[];if(e.tapInternalKey){var o=Co(t,e,n);o&&i.push(o)}if(e.tapScriptSig){var u=e.tapScriptSig.map((function(t){return t.pubkey}));i.push.apply(i,uo(u))}return i.map((function(i){return Ho(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,Lo(i)))return!1;s++}if(o){var f,c=oo(o);try{var h,l=function(){var t=f.value,r=u.find((function(e){return t.pubkey.equals(e.pubkey)}));if(r){if(!e(t.pubkey,r.hash,Lo(t.signature)))return{v:!1};s++}};for(c.s();!(f=c.n()).done;)if(h=l())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]:[Kn.SIGHASH_ALL];Zi(e);var n=No(this.data.inputs,t,e.publicKey,this.__CACHE,r),i=n.hash,o=n.sighashType,u=[{pubkey:e.publicKey,signature:Jt.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]:[Kn.SIGHASH_DEFAULT];Zi(r);var o=this.checkTaprootHashesForSig(t,e,r,n,i),u=o.filter((function(t){return!t.leafHash})).map((function(t){return Wn(r.signSchnorr(t.hash),e.sighashType)}))[0],a=o.filter((function(t){return!!t.leafHash})).map((function(t){return{pubkey:jn(r.publicKey),signature:Wn(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]:[Kn.SIGHASH_ALL];Zi(e);var i=No(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:Jt.encode(n,u)}];r.data.updateInput(t,{partialSig:i})}))}},{key:"_signTaprootInputAsync",value:(e=io(ro().mark((function t(e,r,n,i){var o,u,a,s,f,c,h,l,p,y,d,g=arguments;return ro().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=g.length>4&&void 0!==g[4]?g[4]:[Kn.SIGHASH_DEFAULT],Zi(n),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:Wn(t,r.sighashType)}})),a.push(f)),c=u.filter((function(t){return!!t.leafHash})),c.length&&(h=c.map(function(){var t=io(ro().mark((function t(e){var i,o;return ro().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:jn(n.publicKey),signature:Wn(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,uo(h))),t.next=10,Promise.all(a);case 10:l=t.sent,p=oo(l);try{for(p.s();!(y=p.n()).done;)d=y.value,this.data.updateInput(e,d)}catch(t){p.e(t)}finally{p.f()}case 13: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=to.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=to.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]:{},Di.i.fromBuffer(e,go));return r=i.__CACHE.__TX,n=i.__CACHE,r.ins.forEach((function(t){_o(n,t)})),i}}]);var e}(),go=function(t){return new wo(t)},wo=function(){return ho((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:to.from([2,0,0,0,0,0,0,0,0,0]);fo(this,t),this.tx=Kn.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||!to.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");var e="string"==typeof t.hash?er(to.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||!to.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 vo(t){if(!1!==t.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function mo(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 bo(t){return!!t.finalScriptSig||!!t.finalScriptWitness}function Eo(t){return function(e){return!!e.masterFingerprint.equals(t.fingerprint)&&!!t.derivePath(e.path).publicKey.equals(e.pubkey)}}function So(t){if("number"!=typeof t||t!==Math.floor(t)||t>4294967295||t<0)throw new Error("Invalid 32 bit integer")}function To(t,e){t.forEach((function(t){if(Xn(t)?Zn(t,e):Ei(t,e))throw new Error("Can not modify transaction, signatures exist.")}))}function Io(t,e,r){if(!bi(t,e))throw new Error("Can not ".concat(r," for this input with the key ").concat(t.toString("hex")))}function _o(t,e){var r=er(to.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 ko(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 Ao=ko(ln,"Redeem script"),Oo=ko(_n,"Witness script");function Po(t,e,r,n){var i,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!r.every(bo))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(),Vo(r,i,n,u,o),"__FEE_RATE"===t?n.__FEE_RATE:"__FEE"===t?n.__FEE:void 0}function Bo(t,e,r,n,i,o){var u=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],a=zo(r);if(!function(t,e,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return mo(1,t.partialSig);case"multisig":var n=Tr({output:e});return mo(n.m,t.partialSig,n.pubkeys);default:return!1}}(e,r,a)&&u)throw new Error("Can not finalize input #".concat(t));return Uo(r,a,e.partialSig,n,i,o)}function Uo(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 Tr({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=Tr({output:t,signatures:i});break;case"pubkey":n=_r({output:t,signature:r[0].signature});break;case"pubkeyhash":n=ki({output:t,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=bn({output:t,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(t,e,r),f=o?_n({redeem:s}):null,c=i?ln({redeem:f||s}):null;return n?(a=di(f?f.witness:s.witness),c&&(u=c.input)):u=c?c.input:s.input,{finalScriptSig:u,finalScriptWitness:a}}function No(t,e,r,n,i){var o=xo(e,(0,Ki.checkForInput)(t,e),n,!1,i),u=o.hash,a=o.sighashType;return Io(r,o.script,"sign"),{hash:u,sighashType:a}}function xo(t,e,r,n,i){var o,u,a=r.__TX,s=e.sighashType||Kn.SIGHASH_ALL;if(Ro(s,i),e.nonWitnessUtxo){var f=Fo(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 l=a.ins[t].index;u=f.outs[l]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}var p=Xo(u.script,t,"input",e.redeemScript,e.witnessScript),y=p.meaningfulScript,d=p.type;if(["p2sh-p2wsh","p2wsh"].indexOf(d)>=0)o=a.hashForWitnessV0(t,y,u.value,s);else if(hi(y)){var g=ki({hash:y.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(y.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,y,s)}return{script:y,sighashType:s,hash:o}}function Co(t,e,r){var n=Go(t,e,r).script;return yi(n)?n.subarray(2,34):null}function Lo(t){return 64===t.length?t:t.subarray(0,64)}function Ho(t,e,r,n,i,o,u){var a=i.__TX,s=e.sighashType||Kn.SIGHASH_DEFAULT;Ro(s,u);var f=r.map((function(t,e){return Go(e,t,i)})),c=f.map((function(t){return t.script})),h=f.map((function(t){return t.value})),l=[];if(e.tapInternalKey&&!o){var p=Co(t,e,i)||to.from([]);if(jn(n).equals(p)){var y=a.hashForWitnessV1(t,c,h,s);l.push({pubkey:n,hash:y})}}var d=(e.tapLeafScript||[]).filter((function(t){return bi(n,t.script)})).map((function(t){var e=pr({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 l.concat(d)}function Ro(t,e){if(e&&e.indexOf(t)<0){var r=function(t){var e=t&Kn.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&t){case Kn.SIGHASH_ALL:e+="SIGHASH_ALL";break;case Kn.SIGHASH_SINGLE:e+="SIGHASH_SINGLE";break;case Kn.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 Do(t,e,r){var n=(0,Ki.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 Ko(t){var e=0;function r(){var r=fn.decode(t,e);return e+=fn.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 Mo(t,e,r){t.__NON_WITNESS_UTXO_BUF_CACHE[r]=e.nonWitnessUtxo,t.__NON_WITNESS_UTXO_TX_CACHE[r]=Kn.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 Vo(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=Ko(t.finalScriptWitness)),t.witnessUtxo)o+=t.witnessUtxo.value;else if(t.nonWitnessUtxo){var u=Fo(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 Fo(t,e,r){var n=t.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||Mo(t,e,r),n[r]}function jo(t,e,r){return Go(t,e,r).script}function Go(t,e,r){if(void 0!==e.witnessUtxo)return{script:e.witnessUtxo.script,value:e.witnessUtxo.value};if(void 0!==e.nonWitnessUtxo){var n=Fo(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 Wo(t){return 33===t.length&&qt(t)}function Xo(t,e,r,n,i){var o,u=pi(t),a=u&&n&&li(n),s=li(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,Ao(e,t,n,r),Oo(e,n,i,r),qo(o)):s?(o=i,Oo(e,t,i,r),qo(o)):u?(o=n,Ao(e,t,n,r)):o=t,{meaningfulScript:o,type:a?"p2sh-p2wsh":u?"p2sh":s?"p2wsh":"raw"}}function qo(t){if(hi(t)||pi(t))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function zo(t){return hi(t)?"witnesspubkeyhash":ci(t)?"pubkeyhash":si(t)?"multisig":fi(t)?"pubkey":"nonstandard"}function Yo(t){return uo(Array(t).keys())}const $o={networks:i,address:s,payments:h,script:a,crypto:f,Transaction:c};var Jo=n.eB,Qo=n.Oo,Zo=n.ac,tu=n.ri,eu=n.RY,ru=n.iL,nu=n.PW,iu=n.gp,ou=n.gM,uu=n.ZX,au=n.hl,su=n.p2,fu=n.XL,cu=n.R0,hu=n.vJ,lu=n.em,pu=n.Eb,yu=n.Et,du=n.m$,gu=n.Ay,wu=n.CB,vu=n.VL,mu=n.ow,bu=n.hP,Eu=n.Dk,Su=n.Ln,Tu=n.BL,Iu=n.A0,_u=n.CX,ku=n.f0,Au=n.Bh,Ou=n.Q2,Pu=n.C5,Bu=n.n0,Uu=n.NI,Nu=n.fQ,xu=n.mG,Cu=n.AM,Lu=n.Zh,Hu=n.o8,Ru=n.Ez,Du=n.KT,Ku=n.KS,Mu=n.AI,Vu=n.k1,Fu=n.pM,ju=n.Qf,Gu=n.Fl,Wu=n.HE,Xu=n.WH,qu=n.K$,zu=n.C2,Yu=n.e8,$u=n.sc,Ju=n.XN,Qu=n.VQ,Zu=n.LE,ta=n._T,ea=n.zm,ra=n.qR,na=n.o4,ia=n.Og,oa=n.FT,ua=n.uu,aa=n.I,sa=n.gU,fa=n.wn,ca=n.Kn,ha=n.Uu,la=n.du,pa=n.tO;export{Jo as Block,Qo as BufferReader,Zo as BufferWriter,tu as LEAF_VERSION_TAPSCRIPT,eu as MAX_TAPTREE_DEPTH,ru as Psbt,nu as TAGGED_HASH_PREFIXES,iu as TAGS,ou as TAPLEAF_VERSION_MASK,uu as Transaction,au as address,su as bigIntTo32Bytes,fu as checkInputForSig,cu as checkTaprootInputFields,hu as checkTaprootInputForSigs,lu as checkTaprootOutputFields,pu as cloneBuffer,yu as crypto,du as decompressPublicKey,gu as default,wu as findScriptPath,vu as fromBase58Check,mu as fromBech32,bu as fromOutputScript,Eu as getFinalScripts,Su as getPsigsFromInputFinalScripts,Tu as getTapKeySigFromWitness,Iu as hash160,_u as hash256,ku as initEccLib,Au as isP2MS,Ou as isP2PK,Pu as isP2PKH,Bu as isP2SHScript,Uu as isP2TR,Nu as isP2WPKH,xu as isP2WSHScript,Cu as isTaprootInput,Lu as isTaprootOutput,Hu as networks,Ru as opcodes,Du as payments,Ku as prepareFinalScripts,Mu as pubkeyInScript,Vu as pubkeyPositionInScript,Fu as pubkeysMatch,ju as readUInt64LE,Gu as reverseBuffer,Wu as ripemd160,Xu as rootHashFromPath,qu as script,zu as serializeTaprootSignature,Yu as sha1,$u as sha256,Ju as signatureBlocksAction,Qu as taggedHash,Zu as tapScriptFinalizer,ta as tapTreeFromList,ea as tapTreeToList,ra as tapTweakHash,na as tapleafHash,ia as toBase58Check,oa as toBech32,ua as toHashTree,aa as toOutputScript,sa as toXOnly,fa as tweakInternalPubKey,ca as tweakKey,ha as varuint,la as witnessStackToScriptWitness,pa as writeUInt64LE};
|
|
2
|
+
var t={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},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 l=[];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||l.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:l}}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")},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})}},834:(t,e,r)=>{var n=r(287).Buffer;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)}},213:(t,e,r)=>{var n=r(287).Buffer;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()}}},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),l=r(760),p=r(695),y=r(454),d=r(34),g=r(926),w=r(851),v=r(545),m=r(412),b=r(307),E=r(636),S=r(223),T=r(578),I={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=I;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:T.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:l,tapScriptSig:d,tapLeafScript:p,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:S.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:y};e.inputs=_;const k={bip32Derivation:v.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:T.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},605:(t,e,r)=>{var n=r(287).Buffer;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}},795:(t,e,r)=>{var n=r(287).Buffer;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}},431:(t,e,r)=>{var n=r(287).Buffer;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}},907:(t,e,r)=>{var n=r(287).Buffer;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)}},949:(t,e,r)=>{var n=r(287).Buffer;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}},344:(t,e,r)=>{var n=r(287).Buffer;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}},760:(t,e,r)=>{var n=r(287).Buffer;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}},695:(t,e,r)=>{var n=r(287).Buffer;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)}},454:(t,e,r)=>{var n=r(287).Buffer;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}},34:(t,e,r)=>{var n=r(287).Buffer;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)}},926:(t,e,r)=>{var n=r(287).Buffer;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}},851:(t,e,r)=>{var n=r(287).Buffer;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}},545:(t,e,r)=>{var n=r(287).Buffer;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)}}}},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}}},307:(t,e,r)=>{var n=r(287).Buffer;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}}}},636:(t,e,r)=>{var n=r(287).Buffer;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}}},223:(t,e,r)=>{var n=r(287).Buffer;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}}}},578:(t,e,r)=>{var n=r(287).Buffer;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}}}},133:(t,e,r)=>{var n=r(287).Buffer;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}},394:(t,e,r)=>{var n=r(287).Buffer;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},263:(t,e,r)=>{var n=r(287).Buffer;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,l=[],p=[];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)}l.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)}p.push(e)}return{globalMap:u,inputs:l,outputs:p}}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 l=c.filter((t=>t.key[0]===a.GlobalTypes.UNSIGNED_TX));if(1!==l.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const p=e(l[0].value),{inputCount:y,outputCount:d}=p.getInputOutputCounts(),g=[],w=[];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 input: input index "+t+" key "+o);e[o]=1,r.push(n)}g.push(r)}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 output: output index "+t+" key "+o);e[o]=1,r.push(n)}w.push(r)}return f(p,{globalMapKeyVals:c,inputKeyVals:g,outputKeyVals:w})},e.checkKeyBuffer=s,e.psbtFromKeyVals=f},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))},238:(t,e,r)=>{var n=r(287).Buffer;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),l=c(a),p=n.allocUnsafe(5);return p.writeUIntBE(482972169471,0,5),n.concat([p,f].concat(h,l))};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},614:(t,e,r)=>{var n=r(287).Buffer;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()}}},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"]},699:(t,e,r)=>{var n=r(287).Buffer;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}},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.Buffer=s,e.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},e.INSPECT_MAX_BYTES=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|d(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(Y(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return l(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(Y(t,ArrayBuffer)||t&&Y(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(Y(t,SharedArrayBuffer)||t&&Y(t.buffer,SharedArrayBuffer)))return p(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|y(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):l(t):"Buffer"===t.type&&Array.isArray(t.data)?l(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|y(t))}function l(t){const e=t.length<0?0:0|y(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(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 y(t){if(t>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return 0|t}function d(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Y(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 X(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(t).length;default:if(i)return n?-1:X(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 B(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 U(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 z(X(e,t.length-r),t,r,n)}function S(t,e,r,n){return z(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 T(t,e,r,n){return z(q(e),t,r,n)}function I(t,e,r,n){return z(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)}e.kMaxLength=u,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(Y(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),Y(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(Y(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=d,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.INSPECT_MAX_BYTES;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(Y(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 T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(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 B(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 U(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 N(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 x(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 L(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 H(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 R(t,e,r,n,o){return e=+e,r>>>=0,o||H(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||H(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||N(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||N(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||N(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||N(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||N(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||N(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||N(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=Q((function(t){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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||N(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||N(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||N(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||N(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||N(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||N(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||N(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=Q((function(t){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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){j(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(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||N(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||N(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||N(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||N(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||x(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||x(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||x(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||x(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||x(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||x(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||x(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 L(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);x(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);x(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||x(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||x(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||x(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||x(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||x(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 L(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return R(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return R(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 K={};function M(t,e,r){K[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 V(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 K.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,r){j(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||G(e,t.length-(r+1))}(n,i,o)}function j(t,e){if("number"!=typeof t)throw new K.ERR_INVALID_ARG_TYPE(e,"number",t)}function G(t,e,r){if(Math.floor(t)!==t)throw j(t,r),new K.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new K.ERR_BUFFER_OUT_OF_BOUNDS;throw new K.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}M("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),M("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),M("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=V(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=V(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function X(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 q(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 z(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 Y(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")}},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,l=r?-1:1,p=t[e+h];for(h+=l,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+t[e+h],h+=l,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=l,c-=8);if(0===o)o=1-f;else{if(o===s)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),o-=f}return(p?-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,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,d=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?l/s:l*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+p]=255&a,p+=y,a/=256,i-=8);for(u=u<<i|a,f+=i;f>0;t[r+p]=255&u,p+=y,u/=256,f-=8);t[r+p-y]|=128*d}},861:(t,e,r)=>{var n=r(287),i=n.Buffer;function o(t,e){for(var r in t)e[r]=t[r]}function u(t,e,r){return i(t,e,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?t.exports=n:(o(n,e),e.Buffer=u),u.prototype=Object.create(i.prototype),o(i,u),u.from=function(t,e,r){if("number"==typeof t)throw new TypeError("Argument must not be a number");return i(t,e,r)},u.alloc=function(t,e,r){if("number"!=typeof t)throw new TypeError("Argument must be a number");var n=i(t);return void 0!==e?"string"==typeof r?n.fill(e,r):n.fill(e):n.fill(0),n},u.allocUnsafe=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return i(t)},u.allocUnsafeSlow=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return n.SlowBuffer(t)}},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}},542:(t,e,r)=>{var n=r(287).Buffer,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),l=s.bind(null,i.String),p=Math.pow(2,53)-1,y={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>=-p&&t<=p&&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:l,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<=p&&Math.floor(t)===t}};for(var d in y)y[d].toJSON=function(t){return t}.bind(null,d);t.exports=y},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 l(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&&l(e,o,n)}catch(t){throw s(t,o,"key")}try{var u=r[o];l(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)l(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 l(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 l(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 l(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 l(t,e,r,n){if(i.Function(t)){if(t(e,r))return!0;throw new u(n||t,e)}return l(h(t),e,r)}for(var p in c.oneOf=c.anyOf,i)l[p]=i[p];for(p in c)l[p]=c[p];var y=r(542);for(p in y)l[p]=y[p];l.compile=h,l.TfTypeError=u,l.TfPropertyTypeError=a,t.exports=l},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},469:(t,e,r)=>{var n=r(861).Buffer;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}t.exports={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),t.bytes=1):e<=65535?(r.writeUInt8(253,u),r.writeUInt16LE(e,u+1),t.bytes=3):e<=4294967295?(r.writeUInt8(254,u),r.writeUInt32LE(e,u+1),t.bytes=5):(r.writeUInt8(255,u),r.writeUInt32LE(e>>>0,u+1),r.writeUInt32LE(e/4294967296|0,u+5),t.bytes=9),r},decode:function t(e,r){if(!n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");r||(r=0);var o=e.readUInt8(r);if(o<253)return t.bytes=1,o;if(253===o)return t.bytes=3,e.readUInt16LE(r+1);if(254===o)return t.bytes=5,e.readUInt32LE(r+1);t.bytes=9;var u=e.readUInt32LE(r+1),a=4294967296*e.readUInt32LE(r+5)+u;return i(a),a},encodingLength:o}}},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.d(n,{eB:()=>Hi,Oo:()=>ir,ac:()=>nr,ri:()=>ar,RY:()=>sr,iL:()=>yo,PW:()=>Le,gp:()=>Ce,gM:()=>ft,ZX:()=>Kn,hl:()=>s,p2:()=>wi,XL:()=>Ei,R0:()=>zn,vJ:()=>Zn,em:()=>Yn,Eb:()=>rr,Et:()=>f,m$:()=>gi,Ay:()=>$o,CB:()=>lr,VL:()=>oe,ow:()=>ue,hP:()=>fe,Dk:()=>Bo,Ln:()=>Ti,BL:()=>ei,A0:()=>Ne,CX:()=>xe,f0:()=>Ke,Bh:()=>si,Q2:()=>fi,C5:()=>ci,n0:()=>pi,NI:()=>yi,fQ:()=>hi,mG:()=>li,AM:()=>Xn,Zh:()=>qn,o8:()=>i,Ez:()=>G,KT:()=>h,KS:()=>Uo,AI:()=>bi,k1:()=>mi,pM:()=>vi,Qf:()=>Ze,Fl:()=>er,HE:()=>Pe,WH:()=>cr,K$:()=>a,C2:()=>Wn,e8:()=>Be,sc:()=>Ue,XN:()=>Si,VQ:()=>He,LE:()=>Gn,_T:()=>Qn,zm:()=>Jn,qR:()=>yr,o4:()=>pr,Og:()=>ae,FT:()=>se,uu:()=>hr,I:()=>ce,gU:()=>jn,wn:()=>$n,Kn:()=>dr,Uu:()=>Ge,du:()=>di,tO:()=>tr});var i={};r.r(i),r.d(i,{bitcoin:()=>l,bitcoinCash:()=>m,bitcoinCashTestnet:()=>b,dash:()=>E,dashTestnet:()=>S,dogecoin:()=>d,dogecoinTestnet:()=>g,litecoin:()=>w,litecoinTestnet:()=>v,regtest:()=>p,testnet:()=>y});var o={};r.r(o),r.d(o,{decode:()=>Z,encode:()=>tt});var u={};r.r(u),r.d(u,{decode:()=>Ut,encode:()=>Nt});var a={};r.r(a),r.d(a,{OPS:()=>G,compile:()=>Ft,countNonPushOnlyOPs:()=>Dt,decompile:()=>jt,fromASM:()=>Wt,isCanonicalPubKey:()=>qt,isCanonicalScriptSignature:()=>Yt,isDefinedHashType:()=>zt,isPushOnly:()=>Rt,number:()=>$t,signature:()=>Jt,toASM:()=>Gt,toStack:()=>Xt});var s={};r.r(s),r.d(s,{fromBase58Check:()=>oe,fromBech32:()=>ue,fromOutputScript:()=>fe,toBase58Check:()=>ae,toBech32:()=>se,toOutputScript:()=>ce});var f={};r.r(f),r.d(f,{TAGGED_HASH_PREFIXES:()=>Le,TAGS:()=>Ce,hash160:()=>Ne,hash256:()=>xe,ripemd160:()=>Pe,sha1:()=>Be,sha256:()=>Ue,taggedHash:()=>He});var c={};r.r(c),r.d(c,{Transaction:()=>Kn});var h={};r.r(h),r.d(h,{LEAF_VERSION_TAPSCRIPT:()=>ar,MAX_TAPTREE_DEPTH:()=>sr,findScriptPath:()=>lr,p2data:()=>br,p2ms:()=>Tr,p2pk:()=>_r,p2pkh:()=>ki,p2sh:()=>ln,p2tr:()=>gn,p2wpkh:()=>bn,p2wsh:()=>_n,prop:()=>wr,rootHashFromPath:()=>cr,tapTweakHash:()=>yr,tapleafHash:()=>pr,toHashTree:()=>hr,tweakKey:()=>dr,value:()=>vr});var l={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},p={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},y={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},d={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},g={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},w={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},v={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},m={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},b={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},E={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},S={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},T=r(343);function I(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")}const k=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),A=(t,e)=>t<<32-e|t>>>e,O=(t,e)=>t<<e|t>>>32-e>>>0;function P(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),I(t),t}class B{clone(){return this._cloneInto()}}function U(t){const e=e=>t().update(P(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}const N=(t,e,r)=>t&e^~t&r,x=(t,e,r)=>t&e^t&r^e&r;class C extends B{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=k(this.buffer)}update(t){_(this);const{view:e,buffer:r,blockLen:n}=this,i=(t=P(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=k(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){I(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,this.buffer.subarray(o).fill(0),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=k(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.length=n,t.pos=u,t.finished=i,t.destroyed=o,n%e&&t.buffer.set(r),t}}const L=new Uint32Array([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]),H=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),R=new Uint32Array(64);class D extends C{constructor(){super(64,32,8,!1),this.A=0|H[0],this.B=0|H[1],this.C=0|H[2],this.D=0|H[3],this.E=0|H[4],this.F=0|H[5],this.G=0|H[6],this.H=0|H[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)R[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=R[t-15],r=R[t-2],n=A(e,7)^A(e,18)^e>>>3,i=A(r,17)^A(r,19)^r>>>10;R[t]=i+R[t-7]+n+R[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+(A(u,6)^A(u,11)^A(u,25))+N(u,a,s)+L[t]+R[t]|0,c=(A(r,2)^A(r,13)^A(r,22))+x(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(){R.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const K=U((()=>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 l=u;for(;c!==s;)h[l++]=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 l=n.repeat(i);for(;h<f;++h)l+=t.charAt(c[h]);return l},decodeUnsafe:u,decode:function(t){const e=u(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),V=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 F=r(287).Buffer;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=F.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 G={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},W={},X=0,q=Object.keys(G);X<q.length;X++){var z=q[X],Y=G[z];W[Y]=z}function $(t){return t<G.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function J(t,e){var r,n,i=t.readUInt8(e);if(i<G.OP_PUSHDATA1)r=i,n=1;else if(i===G.OP_PUSHDATA1){if(e+2>t.length)return null;r=t.readUInt8(e+1),n=2}else if(i===G.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!==G.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=t.readUInt32LE(e+1),n=5}return{opcode:i,number:r,size:n}}var Q=r(287).Buffer;function Z(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 tt(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=Q.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 et=r(287),rt=r(676),nt=r.n(rt)(),it=et.Buffer.alloc(32,0),ot=et.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function ut(t,e){return t.length===e.length&&t.every((function(t,r){return t.equals(e[r])}))}function at(t){if(!et.Buffer.isBuffer(t))return!1;if(t.length<33)return!1;var e=t[0],r=t.slice(1,33);if(0===r.compare(it))return!1;if(r.compare(ot)>=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(it)||n.compare(ot)>=0||4!==e&&6!==e&&7!==e)}function st(t){return nt.UInt53(t)&&t<=21e14}var ft=254;function ct(t){return!(!t||!("output"in t)||!et.Buffer.isBuffer(t.output)||void 0!==t.version&&(t.version&ft)!==t.version)}function ht(t){return dt(t)?2===t.length&&t.every((function(t){return ht(t)})):ct(t)}nt.BufferN(32);var lt=nt.BufferN(20),pt=nt.BufferN(32),yt=nt.Number,dt=nt.Array,gt=(nt.Boolean,nt.String),wt=nt.Buffer,vt=nt.Hex,mt=nt.maybe,bt=nt.tuple,Et=nt.UInt8,St=nt.UInt32,Tt=nt.Function,It=nt.BufferN,_t=nt.Null,kt=(nt.oneOf,r(287).Buffer),At=nt,Ot=kt.alloc(1,0);function Pt(t){for(var e=0;0===t[e];)++e;return e===t.length?Ot:128&(t=t.slice(e))[0]?kt.concat([Ot,t],1+t.length):t}function Bt(t){0===t[0]&&(t=t.slice(1));var e=kt.alloc(32,0),r=Math.max(0,32-t.length);return t.copy(e,r),e}function Ut(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=Bt(r.r),i=Bt(r.s);return{signature:kt.concat([n,i],64),hashType:e}}function Nt(t,e){if(At({signature:It(64),hashType:Et},{signature:t,hashType:e}),!zt(e))throw new Error("Invalid hashType "+e);var r=kt.allocUnsafe(1);r.writeUInt8(e,0);var n=Pt(t.slice(0,32)),i=Pt(t.slice(32,64));return kt.concat([j(n,i),r])}var xt=r(287).Buffer,Ct=nt,Lt=G.OP_RESERVED;function Ht(t){return wt(t)||function(t){return yt(t)&&(t===G.OP_0||t>=G.OP_1&&t<=G.OP_16||t===G.OP_1NEGATE)}(t)}function Rt(t){return dt(t)&&t.every(Ht)}function Dt(t){return t.length-t.filter(Ht).length}function Kt(t){return 0===t.length?G.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Lt+t[0]:129===t[0]?G.OP_1NEGATE:void 0:void 0}function Mt(t){return xt.isBuffer(t)}function Vt(t){return xt.isBuffer(t)}function Ft(t){if(Mt(t))return t;Ct(dt,t);var e=t.reduce((function(t,e){return Vt(e)?1===e.length&&void 0!==Kt(e)?t+1:t+$(e.length)+e.length:t+1}),0),r=xt.allocUnsafe(e),n=0;if(t.forEach((function(t){if(Vt(t)){var e=Kt(t);if(void 0!==e)return r.writeUInt8(e,n),void(n+=1);n+=function(t,e,r){var n=$(e);return 1===n?t.writeUInt8(e,r):2===n?(t.writeUInt8(G.OP_PUSHDATA1,r),t.writeUInt8(e,r+1)):3===n?(t.writeUInt8(G.OP_PUSHDATA2,r),t.writeUInt16LE(e,r+1)):(t.writeUInt8(G.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(dt(t))return t;Ct(wt,t);for(var e=[],r=0;r<t.length;){var n=t[r];if(n>G.OP_0&&n<=G.OP_PUSHDATA4){var i=J(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 Gt(t){if(Mt(t)&&(t=jt(t)),!t)throw new Error("Could not convert invalid chunks to ASM");return t.map((function(t){if(Vt(t)){var e=Kt(t);if(void 0===e)return t.toString("hex");t=e}return W[t]})).join(" ")}function Wt(t){return Ct(gt,t),Ft(t.split(" ").map((function(t){return void 0!==G[t]?G[t]:(Ct(vt,t),xt.from(t,"hex"))})))}function Xt(t){return t=jt(t),Ct(Rt,t),t.map((function(t){return Vt(t)?t:t===G.OP_0?xt.allocUnsafe(0):tt(t-Lt)}))}function qt(t){return at(t)}function zt(t){var e=-129&t;return e>0&&e<4}function Yt(t){return!!xt.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 $t=o,Jt=u,Qt=r(287).Buffer,Zt=40,te=2,ee=16,re=2,ne=80,ie="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 oe(t){var e=Qt.from(V.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.slice(1)}}function ue(t){var e,r;try{e=T.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=T.p2.decode(t)).words[0]))throw new TypeError(t+" uses wrong encoding");var n=T.I.fromWords(e.words.slice(1));return{version:r,prefix:e.prefix,data:Qt.from(n)}}function ae(t,e){nt(bt(lt,Et),arguments);var r=Qt.allocUnsafe(21);return r.writeUInt8(e,0),t.copy(r,1),V.encode(r)}function se(t,e,r){var n=T.I.toWords(t);return n.unshift(e),0===e?T.I.encode(r,n):T.p2.encode(r,n)}function fe(t,e){e=e||l;try{return ki({output:t,network:e}).address}catch(t){}try{return ln({output:t,network:e}).address}catch(t){}try{return bn({output:t,network:e}).address}catch(t){}try{return _n({output:t,network:e}).address}catch(t){}try{return gn({output:t,network:e}).address}catch(t){}try{return function(t,e){var r=t.slice(2);if(r.length<te||r.length>Zt)throw new TypeError("Invalid program length for segwit address");var n=t[0]-ne;if(n<re||n>ee)throw new TypeError("Invalid version for segwit address");if(t[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(ie),se(r,n,e.bech32)}(t,e)}catch(t){}throw new Error(Gt(t)+" has no matching Address")}function ce(t,e){var r,n;e=e||l;try{r=oe(t)}catch(t){}if(r){if(r.version===e.pubKeyHash)return ki({hash:r.hash}).output;if(r.version===e.scriptHash)return ln({hash:r.hash}).output}else{try{n=ue(t)}catch(t){}if(n){if(n.prefix!==e.bech32)throw new Error(t+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return bn({hash:n.data}).output;if(32===n.data.length)return _n({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return gn({pubkey:n.data}).output}else if(n.version>=re&&n.version<=ee&&n.data.length>=te&&n.data.length<=Zt)return console.warn(ie),Ft([n.version+ne,n.data])}}return Qt.from(t,"hex")}const he=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),le=new Uint8Array(new Array(16).fill(0).map(((t,e)=>e)));let pe=[le],ye=[le.map((t=>(9*t+5)%16))];for(let t=0;t<4;t++)for(let e of[pe,ye])e.push(e[t].map((t=>he[t])));const de=[[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=>new Uint8Array(t))),ge=pe.map(((t,e)=>t.map((t=>de[e][t])))),we=ye.map(((t,e)=>t.map((t=>de[e][t])))),ve=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),me=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function be(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 Ee=new Uint32Array(16);class Se extends C{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)Ee[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,l=ve[t],p=me[t],y=pe[t],d=ye[t],g=ge[t],w=we[t];for(let e=0;e<16;e++){const n=O(r+be(t,i,u,s)+Ee[y[e]]+l,g[e])+c|0;r=c,c=s,s=0|O(u,10),u=i,i=n}for(let t=0;t<16;t++){const r=O(n+be(e,o,a,f)+Ee[d[t]]+p,w[t])+h|0;n=h,h=f,f=0|O(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(){Ee.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const Te=U((()=>new Se)),Ie=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),_e=new Uint32Array(80);class ke extends C{constructor(){super(64,20,8,!1),this.A=0|Ie[0],this.B=0|Ie[1],this.C=0|Ie[2],this.D=0|Ie[3],this.E=0|Ie[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)_e[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)_e[t]=O(_e[t-3]^_e[t-8]^_e[t-14]^_e[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=N(n,i,o),a=1518500249):t<40?(e=n^i^o,a=1859775393):t<60?(e=x(n,i,o),a=2400959708):(e=n^i^o,a=3395469782);const s=O(r,5)+e+u+a+_e[t]|0;u=o,o=i,i=O(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(){_e.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}const Ae=U((()=>new ke));var Oe=r(287).Buffer;function Pe(t){return Oe.from(Te(Uint8Array.from(t)))}function Be(t){return Oe.from(Ae(Uint8Array.from(t)))}function Ue(t){return Oe.from(K(Uint8Array.from(t)))}function Ne(t){return Oe.from(Te(K(Uint8Array.from(t))))}function xe(t){return Oe.from(K(K(Uint8Array.from(t))))}var Ce=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],Le={"BIP0340/challenge":Oe.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":Oe.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":Oe.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:Oe.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:Oe.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:Oe.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:Oe.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":Oe.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":Oe.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 He(t,e){return Ue(Oe.concat([Le[t],e]))}var Re=r(287).Buffer,De={};function Ke(t){var e;t?t!==De.eccLib&&(Fe("function"==typeof(e=t).isXOnlyPoint),Fe(e.isXOnlyPoint(Ve("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Fe(e.isXOnlyPoint(Ve("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Fe(e.isXOnlyPoint(Ve("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Fe(e.isXOnlyPoint(Ve("0000000000000000000000000000000000000000000000000000000000000001"))),Fe(!e.isXOnlyPoint(Ve("0000000000000000000000000000000000000000000000000000000000000000"))),Fe(!e.isXOnlyPoint(Ve("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Fe("function"==typeof e.xOnlyPointAddTweak),je.forEach((function(t){var r=e.xOnlyPointAddTweak(Ve(t.pubkey),Ve(t.tweak));null===t.result?Fe(null===r):(Fe(null!==r),Fe(r.parity===t.parity),Fe(Re.from(r.xOnlyPubkey).equals(Ve(t.result))))})),De.eccLib=t):De.eccLib=t}function Me(){if(!De.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return De.eccLib}var Ve=function(t){return Re.from(t,"hex")};function Fe(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"}],Ge=r(469),We=r(287).Buffer;function Xe(t){return Xe="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},Xe(t)}function qe(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ze(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,$e(n.key),n)}}function Ye(t,e,r){return e&&ze(t.prototype,e),r&&ze(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function $e(t){var e=function(t){if("object"!=Xe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Xe(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Xe(e)?e:e+""}var Je=nt;function Qe(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 Ze(t,e){var r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return Qe((n*=4294967296)+r,9007199254740991),n+r}function tr(t,e,r){return Qe(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}function er(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 rr(t){var e=We.allocUnsafe(t.length);return t.copy(e),e}var nr=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;qe(this,t),this.buffer=e,this.offset=r,Je(bt(wt,St),[e,r])}return Ye(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=tr(this.buffer,t,this.offset)}},{key:"writeVarInt",value:function(t){Ge.encode(t,this.buffer,this.offset),this.offset+=Ge.encode.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(We.alloc(e))}}])}(),ir=function(){return Ye((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;qe(this,t),this.buffer=e,this.offset=r,Je(bt(wt,St),[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=Ze(this.buffer,this.offset);return this.offset+=8,t}},{key:"readVarInt",value:function(){var t=Ge.decode(this.buffer,this.offset);return this.offset+=Ge.decode.bytes,t}},{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.slice(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 or(t){return function(t){if(Array.isArray(t))return ur(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 ur(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)?ur(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 ur(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 ar=192,sr=128,fr=function(t){return"left"in t&&"right"in t};function cr(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?gr(n,o):gr(o,n)}return n}function hr(t){if(ct(t))return{hash:pr(t)};var e=[hr(t[0]),hr(t[1])];e.sort((function(t,e){return t.hash.compare(e.hash)}));var r=e[0],n=e[1];return{hash:gr(r.hash,n.hash),left:r,right:n}}function lr(t,e){if(fr(t)){var r=lr(t.left,e);if(void 0!==r)return[].concat(or(r),[t.right.hash]);var n=lr(t.right,e);if(void 0!==n)return[].concat(or(n),[t.left.hash])}else if(t.hash.equals(e))return[]}function pr(t){var e,r,n,i=t.version||ar;return He("TapLeaf",et.Buffer.concat([et.Buffer.from([i]),(e=t.output,r=Ge.encodingLength(e.length),n=et.Buffer.allocUnsafe(r),Ge.encode(e.length,n),et.Buffer.concat([n,e]))]))}function yr(t,e){return He("TapTweak",et.Buffer.concat(e?[t,e]:[t]))}function dr(t,e){if(!et.Buffer.isBuffer(t))return null;if(32!==t.length)return null;if(e&&32!==e.length)return null;var r=yr(t,e),n=Me().xOnlyPointAddTweak(t,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:et.Buffer.from(n.xOnlyPubkey)}:null}function gr(t,e){return He("TapBranch",et.Buffer.concat([t,e]))}function wr(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 vr(t){var e;return function(){return void 0!==e?e:e=t()}}var mr=G;function br(t,e){if(!t.data&&!t.output)throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),nt({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),data:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r={name:"embed",network:t.network||l};if(wr(r,"output",(function(){if(t.data)return Ft([mr.OP_RETURN].concat(t.data))})),wr(r,"data",(function(){if(t.output)return jt(t.output).slice(1)})),e.validate&&t.output){var n=jt(t.output);if(n[0]!==mr.OP_RETURN)throw new TypeError("Output is invalid");if(!n.slice(1).every(nt.Buffer))throw new TypeError("Output is invalid");if(t.data&&!ut(t.data,r.data))throw new TypeError("Data mismatch")}return Object.assign(r,t)}var Er=G,Sr=Er.OP_RESERVED;function Tr(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 Yt(t)||void 0!==(e.allowIncomplete&&t===Er.OP_0)}e=Object.assign({validate:!0},e||{}),nt({network:nt.maybe(nt.Object),m:nt.maybe(nt.Number),n:nt.maybe(nt.Number),output:nt.maybe(nt.Buffer),pubkeys:nt.maybe(nt.arrayOf(at)),signatures:nt.maybe(nt.arrayOf(r)),input:nt.maybe(nt.Buffer)},t);var n={network:t.network||l},i=[],o=!1;function u(t){o||(o=!0,i=jt(t),n.m=i[0]-Sr,n.n=i[i.length-2]-Sr,n.pubkeys=i.slice(1,-2))}if(wr(n,"output",(function(){if(t.m&&n.n&&t.pubkeys)return Ft([].concat(Sr+t.m,t.pubkeys,Sr+n.n,Er.OP_CHECKMULTISIG))})),wr(n,"m",(function(){if(n.output)return u(n.output),n.m})),wr(n,"n",(function(){if(n.pubkeys)return n.pubkeys.length})),wr(n,"pubkeys",(function(){if(t.output)return u(t.output),n.pubkeys})),wr(n,"signatures",(function(){if(t.input)return jt(t.input).slice(1)})),wr(n,"input",(function(){if(t.signatures)return Ft([Er.OP_0].concat(t.signatures))})),wr(n,"witness",(function(){if(n.input)return[]})),wr(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),!nt.Number(i[0]))throw new TypeError("Output is invalid");if(!nt.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Er.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 at(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&&!ut(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]!==Er.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&&!ut(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 Ir=G;function _r(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||{}),nt({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),pubkey:nt.maybe(at),signature:nt.maybe(Yt),input:nt.maybe(nt.Buffer)},t);var r=vr((function(){return jt(t.input)})),n={name:"p2pk",network:t.network||l};if(wr(n,"output",(function(){if(t.pubkey)return Ft([t.pubkey,Ir.OP_CHECKSIG])})),wr(n,"pubkey",(function(){if(t.output)return t.output.slice(1,-1)})),wr(n,"signature",(function(){if(t.input)return r()[0]})),wr(n,"input",(function(){if(t.signature)return Ft([t.signature])})),wr(n,"witness",(function(){if(n.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Ir.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!at(n.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&!t.pubkey.equals(n.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&!t.input.equals(n.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!Yt(n.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(n,t)}const kr=2n**256n,Ar=kr-0x1000003d1n,Or=kr-0x14551231950b75fc4402da1732fc9bebfn,Pr=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Br=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,Ur={p:Ar,n:Or,a:0n,b:7n,Gx:Pr,Gy:Br},Nr=t=>Vr(Vr(t*t)*t+Ur.b),xr=(t="")=>{throw new Error(t)},Cr=t=>"bigint"==typeof t,Lr=t=>"string"==typeof t,Hr=t=>Cr(t)&&0n<t&&t<Ar,Rr=t=>Cr(t)&&0n<t&&t<Or,Dr=(t,e)=>!(t=>t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?xr("Uint8Array expected"):t,Kr=t=>new Uint8Array(t),Mr=(t,e)=>Dr(Lr(t)?zr(t):Kr(Dr(t)),e),Vr=(t,e=Ar)=>{let r=t%e;return r>=0n?r:e+r},Fr=t=>t instanceof jr?t:xr("Point expected");class jr{constructor(t,e,r){this.px=t,this.py=e,this.pz=r}static fromAffine(t){return 0n===t.x&&0n===t.y?jr.ZERO:new jr(t.x,t.y,1n)}static fromHex(t){let e;const r=(t=Mr(t))[0],n=t.subarray(1),i=$r(n,0,32),o=t.length;if(33===o&&[2,3].includes(r)){Hr(i)||xr("Point hex invalid: x not FE");let t=en(Nr(i));!(1&~r)!=(1n===(1n&t))&&(t=Vr(-t)),e=new jr(i,t,1n)}return 65===o&&4===r&&(e=new jr(i,$r(n,32,64),1n)),e?e.ok():xr("Point is not on curve")}static fromPrivateKey(t){return Gr.mul(rn(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}=Fr(t),a=Vr(e*u),s=Vr(i*n),f=Vr(r*u),c=Vr(o*n);return a===s&&f===c}negate(){return new jr(this.px,Vr(-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}=Fr(t),{a,b:s}=Ur;let f=0n,c=0n,h=0n;const l=Vr(3n*s);let p=Vr(e*i),y=Vr(r*o),d=Vr(n*u),g=Vr(e+r),w=Vr(i+o);g=Vr(g*w),w=Vr(p+y),g=Vr(g-w),w=Vr(e+n);let v=Vr(i+u);return w=Vr(w*v),v=Vr(p+d),w=Vr(w-v),v=Vr(r+n),f=Vr(o+u),v=Vr(v*f),f=Vr(y+d),v=Vr(v-f),h=Vr(a*w),f=Vr(l*d),h=Vr(f+h),f=Vr(y-h),h=Vr(y+h),c=Vr(f*h),y=Vr(p+p),y=Vr(y+p),d=Vr(a*d),w=Vr(l*w),y=Vr(y+d),d=Vr(p-d),d=Vr(a*d),w=Vr(w+d),p=Vr(y*w),c=Vr(c+p),p=Vr(v*w),f=Vr(g*f),f=Vr(f-p),p=Vr(g*y),h=Vr(v*h),h=Vr(h+p),new jr(f,c,h)}mul(t,e=!0){if(!e&&0n===t)return Wr;if(Rr(t)||xr("invalid scalar"),this.equals(Gr))return sn(t).p;let r=Wr,n=Gr;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(Wr))return{x:0n,y:0n};if(1n===r)return{x:t,y:e};const n=tn(r);return 1n!==Vr(r*n)&&xr("invalid inverse"),{x:Vr(t*n),y:Vr(e*n)}}assertValidity(){const{x:t,y:e}=this.aff();return Hr(t)&&Hr(e)||xr("Point invalid: x or y"),Vr(e*e)===Nr(t)?this:xr("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")+Qr(e)+(t?"":Qr(r))}toRawBytes(t=!0){return zr(this.toHex(t))}}jr.BASE=new jr(Pr,Br,1n),jr.ZERO=new jr(0n,1n,0n);const{BASE:Gr,ZERO:Wr}=jr,Xr=(t,e)=>t.toString(16).padStart(e,"0"),qr=t=>Array.from(t).map((t=>Xr(t,2))).join(""),zr=t=>{const e=t.length;(!Lr(t)||e%2)&&xr("hex invalid 1");const r=Kr(e/2);for(let e=0;e<r.length;e++){const n=2*e,i=t.slice(n,n+2),o=Number.parseInt(i,16);(Number.isNaN(o)||o<0)&&xr("hex invalid 2"),r[e]=o}return r},Yr=t=>BigInt("0x"+(qr(t)||"0")),$r=(t,e,r)=>Yr(t.slice(e,r)),Jr=t=>Cr(t)&&t>=0n&&t<kr?zr(Xr(t,64)):xr("bigint expected"),Qr=t=>qr(Jr(t)),Zr=(...t)=>{const e=Kr(t.reduce(((t,e)=>t+Dr(e).length),0));let r=0;return t.forEach((t=>{e.set(t,r),r+=t.length})),e},tn=(t,e=Ar)=>{(0n===t||e<=0n)&&xr("no inverse n="+t+" mod="+e);let r=Vr(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?Vr(i,e):xr("no inverse")},en=t=>{let e=1n;for(let r=t,n=(Ar+1n)/4n;n>0n;n>>=1n)1n&n&&(e=e*r%Ar),r=r*r%Ar;return Vr(e*e)===t?e:xr("sqrt invalid")},rn=t=>(Cr(t)||(t=Yr(Mr(t,32))),Rr(t)?t:xr("private key out of range")),nn=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;let on;const un={hexToBytes:zr,bytesToHex:qr,concatBytes:Zr,bytesToNumberBE:Yr,numberToBytesBE:Jr,mod:Vr,invert:tn,hmacSha256Async:async(t,...e)=>{const r=nn(),n=r&&r.subtle;if(!n)return xr("etc.hmacSha256Async not set");const i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Kr(await n.sign("HMAC",i,Zr(...e)))},hmacSha256Sync:on,hashToPrivateKey:t=>{((t=Mr(t)).length<40||t.length>1024)&&xr("expected proper params");const e=Vr(Yr(t),Or-1n)+1n;return Jr(e)},randomBytes:(t=32)=>{const e=nn();return e&&e.getRandomValues||xr("crypto.getRandomValues must be defined"),e.getRandomValues(Kr(t))}};let an;Object.defineProperties(un,{hmacSha256Sync:{configurable:!1,get:()=>on,set(t){on||(on=t)}}});const sn=t=>{const e=an||(an=(()=>{const t=[];let e=Gr,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=Wr,i=Gr;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,l=a%2!=0,p=f<0;0===f?i=i.add(r(l,e[c])):n=n.add(r(p,e[h]))}return{p:n,f:i}};var fn=r(394),cn=r(287).Buffer,hn=G;function ln(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),output:nt.maybe(nt.BufferN(23)),redeem:nt.maybe({network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),input:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),input:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=t.network;r||(r=t.redeem&&t.redeem.network||l);var n={network:r},i=vr((function(){var e=cn.from(V.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),o=vr((function(){return jt(t.input)})),u=vr((function(){var e=o(),n=e[e.length-1];return{network:r,output:n===hn.OP_FALSE?cn.from([]):n,input:Ft(e.slice(0,-1)),witness:t.witness||[]}}));if(wr(n,"address",(function(){if(n.hash){var t=cn.allocUnsafe(21);return t.writeUInt8(n.network.scriptHash,0),n.hash.copy(t,1),V.encode(t)}})),wr(n,"hash",(function(){return t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?Ne(n.redeem.output):void 0})),wr(n,"output",(function(){if(n.hash)return Ft([hn.OP_HASH160,n.hash,hn.OP_EQUAL])})),wr(n,"redeem",(function(){if(t.input)return u()})),wr(n,"input",(function(){if(t.redeem&&t.redeem.input&&t.redeem.output)return Ft([].concat(jt(t.redeem.input),t.redeem.output))})),wr(n,"witness",(function(){return n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0})),wr(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=cn.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]!==hn.OP_HASH160||20!==t.output[1]||t.output[22]!==hn.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=Ne(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&&!Rt(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(!cn.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&&!ut(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var pn=G,yn=1,dn=80;function gn(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||{}),nt({address:nt.maybe(nt.String),input:nt.maybe(nt.BufferN(0)),network:nt.maybe(nt.Object),output:nt.maybe(nt.BufferN(34)),internalPubkey:nt.maybe(nt.BufferN(32)),hash:nt.maybe(nt.BufferN(32)),pubkey:nt.maybe(nt.BufferN(32)),signature:nt.maybe(nt.anyOf(nt.BufferN(64),nt.BufferN(65))),witness:nt.maybe(nt.arrayOf(nt.Buffer)),scriptTree:nt.maybe(ht),redeem:nt.maybe({output:nt.maybe(nt.Buffer),redeemVersion:nt.maybe(nt.Number),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),redeemVersion:nt.maybe(nt.Number)},t);var r=vr((function(){return ue(t.address)})),n=vr((function(){if(t.witness&&t.witness.length)return t.witness.length>=2&&t.witness[t.witness.length-1][0]===dn?t.witness.slice(0,-1):t.witness.slice()})),i=vr((function(){return t.scriptTree?hr(t.scriptTree):t.hash?{hash:t.hash}:void 0})),o=t.network||l,u={name:"p2tr",network:o};if(wr(u,"address",(function(){if(u.pubkey){var t=T.p2.toWords(u.pubkey);return t.unshift(yn),T.p2.encode(o.bech32,t)}})),wr(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]&ft;return cr(r,pr({output:e[e.length-2],version:o}))}return null})),wr(u,"output",(function(){if(u.pubkey)return Ft([pn.OP_1,u.pubkey])})),wr(u,"redeemVersion",(function(){return t.redeemVersion?t.redeemVersion:t.redeem&&void 0!==t.redeem.redeemVersion&&null!==t.redeem.redeemVersion?t.redeem.redeemVersion:ar})),wr(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]&ft}})),wr(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=dr(u.internalPubkey,u.hash);if(e)return e.x}})),wr(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})),wr(u,"signature",(function(){if(t.signature)return t.signature;var e=n();return e&&1===e.length?e[0]:void 0})),wr(u,"witness",(function(){if(t.witness)return t.witness;var e=i();if(e&&t.redeem&&t.redeem.output&&t.internalPubkey){var r=lr(e,pr({output:t.redeem.output,version:u.redeemVersion}));if(!r)return;var n=dr(t.internalPubkey,e.hash);if(!n)return;var o=et.Buffer.concat([et.Buffer.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=et.Buffer.from([]);if(t.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==yn)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]!==pn.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=dr(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&&!lr(f,pr({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&&!ut(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 p=(h.length-33)/32;if(p>128)throw new TypeError("The script path is too long. Got ".concat(p,", expected max 128."));var y=h.slice(1,33);if(t.internalPubkey&&!t.internalPubkey.equals(y))throw new TypeError("Internal pubkey mismatch");if(!Me().isXOnlyPoint(y))throw new TypeError("Invalid internalPubkey for p2tr witness");var d=h[0]&ft,g=dr(y,cr(h,pr({output:c[c.length-2],version:d})));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 wn=r(287).Buffer,vn=G,mn=wn.alloc(0);function bn(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||{}),nt({address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),input:nt.maybe(nt.BufferN(0)),network:nt.maybe(nt.Object),output:nt.maybe(nt.BufferN(22)),pubkey:nt.maybe(at),signature:nt.maybe(Yt),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=vr((function(){var e=T.I.decode(t.address),r=e.words.shift(),n=T.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:wn.from(n)}})),n=t.network||l,i={name:"p2wpkh",network:n};if(wr(i,"address",(function(){if(i.hash){var t=T.I.toWords(i.hash);return t.unshift(0),T.I.encode(n.bech32,t)}})),wr(i,"hash",(function(){return t.output?t.output.slice(2,22):t.address?r().data:t.pubkey||i.pubkey?Ne(t.pubkey||i.pubkey):void 0})),wr(i,"output",(function(){if(i.hash)return Ft([vn.OP_0,i.hash])})),wr(i,"pubkey",(function(){return t.pubkey?t.pubkey:t.witness?t.witness[1]:void 0})),wr(i,"signature",(function(){if(t.witness)return t.witness[0]})),wr(i,"input",(function(){if(i.witness)return mn})),wr(i,"witness",(function(){if(t.pubkey&&t.signature)return[t.signature,t.pubkey]})),e.validate){var o=wn.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]!==vn.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=Ne(t.pubkey);if(o.length>0&&!o.equals(u))throw new TypeError("Hash mismatch");if(o=u,!at(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(!Yt(t.witness[0]))throw new TypeError("Witness has invalid signature");if(!at(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=Ne(t.witness[1]);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(i,t)}var En=r(287).Buffer,Sn=G,Tn=En.alloc(0);function In(t){return!(!En.isBuffer(t)||65!==t.length||4!==t[0]||!at(t))}function _n(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(32)),output:nt.maybe(nt.BufferN(34)),redeem:nt.maybe({input:nt.maybe(nt.Buffer),network:nt.maybe(nt.Object),output:nt.maybe(nt.Buffer),witness:nt.maybe(nt.arrayOf(nt.Buffer))}),input:nt.maybe(nt.BufferN(0)),witness:nt.maybe(nt.arrayOf(nt.Buffer))},t);var r=vr((function(){var e=T.I.decode(t.address),r=e.words.shift(),n=T.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:En.from(n)}})),n=vr((function(){return jt(t.redeem.input)})),i=t.network;i||(i=t.redeem&&t.redeem.network||l);var o={network:i};if(wr(o,"address",(function(){if(o.hash){var t=T.I.toWords(o.hash);return t.unshift(0),T.I.encode(i.bech32,t)}})),wr(o,"hash",(function(){return t.output?t.output.slice(2):t.address?r().data:o.redeem&&o.redeem.output?Ue(o.redeem.output):void 0})),wr(o,"output",(function(){if(o.hash)return Ft([Sn.OP_0,o.hash])})),wr(o,"redeem",(function(){if(t.witness)return{output:t.witness[t.witness.length-1],input:Tn,witness:t.witness.slice(0,-1)}})),wr(o,"input",(function(){if(o.witness)return Tn})),wr(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=Tn,[].concat(e,t.redeem.output)}if(t.redeem&&t.redeem.output&&t.redeem.witness)return[].concat(t.redeem.witness,t.redeem.output)})),wr(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=En.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]!==Sn.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=Ue(t.redeem.output);if(u.length>0&&!u.equals(f))throw new TypeError("Hash mismatch");u=f}if(t.redeem.input&&!Rt(n()))throw new TypeError("Non push-only scriptSig");if(t.witness&&t.redeem.witness&&!ut(t.witness,t.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(t.redeem.input&&n().some(In)||t.redeem.output&&(jt(t.redeem.output)||[]).some(In))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(In)||(jt(c)||[]).some(In))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,t)}var kn=r(287).Buffer;function An(t){return An="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},An(t)}function On(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,Bn(n.key),n)}}function Pn(t,e,r){return(e=Bn(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Bn(t){var e=function(t){if("object"!=An(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=An(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==An(e)?e:e+""}var Un=nt;function Nn(t){var e=t.length;return Ge.encodingLength(e)+e}var xn=kn.allocUnsafe(0),Cn=[],Ln=kn.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Hn=kn.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Rn=kn.from("ffffffffffffffff","hex"),Dn={script:xn,valueBuffer:Rn},Kn=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Pn(this,"version",1),Pn(this,"locktime",0),Pn(this,"ins",[]),Pn(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 Un(bt(pt,St,mt(St),mt(wt)),arguments),_t(n)&&(n=t.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:r,script:i||xn,sequence:n,witness:Cn})-1}},{key:"addOutput",value:function(t,e){return Un(bt(wt,st),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)+Ge.encodingLength(this.ins.length)+Ge.encodingLength(this.outs.length)+this.ins.reduce((function(t,e){return t+40+Nn(e.script)}),0)+this.outs.reduce((function(t,e){return t+8+Nn(e.script)}),0)+(t?this.ins.reduce((function(t,e){return t+(n=(r=e.witness).length,Ge.encodingLength(n)+r.reduce((function(t,e){return t+Nn(e)}),0));var r,n}),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(Un(bt(St,wt,yt),arguments),e>=this.ins.length)return Hn;var i=Ft(jt(r).filter((function(t){return t!==G.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 Hn;o.outs.length=e+1;for(var u=0;u<e;u++)o.outs[u]=Dn;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),xe(a)}},{key:"hashForWitnessV1",value:function(e,r,n,i,o,u){if(Un(bt(St,Un.arrayOf(wt),Un.arrayOf(st),St),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,l=xn,p=xn,y=xn,d=xn;if(!s){var g=nr.withCapacity(36*this.ins.length);this.ins.forEach((function(t){g.writeSlice(t.hash),g.writeUInt32(t.index)})),h=Ue(g.end()),g=nr.withCapacity(8*this.ins.length),n.forEach((function(t){return g.writeUInt64(t)})),l=Ue(g.end()),g=nr.withCapacity(r.map(Nn).reduce((function(t,e){return t+e}))),r.forEach((function(t){return g.writeVarSlice(t)})),p=Ue(g.end()),g=nr.withCapacity(4*this.ins.length),this.ins.forEach((function(t){return g.writeUInt32(t.sequence)})),y=Ue(g.end())}if(f||c){if(c&&e<this.outs.length){var w=this.outs[e],v=nr.withCapacity(8+Nn(w.script));v.writeUInt64(w.value),v.writeVarSlice(w.script),d=Ue(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+Nn(t.script)})).reduce((function(t,e){return t+e})),b=nr.withCapacity(m);this.outs.forEach((function(t){b.writeUInt64(t.value),b.writeVarSlice(t.script)})),d=Ue(b.end())}var E=(o?2:0)+(u?1:0),S=174-(s?49:0)-(f?32:0)+(u?32:0)+(o?37:0),T=nr.withCapacity(S);if(T.writeUInt8(i),T.writeInt32(this.version),T.writeUInt32(this.locktime),T.writeSlice(h),T.writeSlice(l),T.writeSlice(p),T.writeSlice(y),f||c||T.writeSlice(d),T.writeUInt8(E),s){var I=this.ins[e];T.writeSlice(I.hash),T.writeUInt32(I.index),T.writeUInt64(n[e]),T.writeVarSlice(r[e]),T.writeUInt32(I.sequence)}else T.writeUInt32(e);if(u){var _=nr.withCapacity(Nn(u));_.writeVarSlice(u),T.writeSlice(Ue(_.end()))}return c&&T.writeSlice(d),o&&(T.writeSlice(o),T.writeUInt8(0),T.writeUInt32(4294967295)),He("TapSighash",kn.concat([kn.from([0]),T.end()]))}},{key:"hashForWitnessV0",value:function(e,r,n,i){Un(bt(St,wt,st,St),arguments);var o,u=kn.from([]),a=Ln,s=Ln,f=Ln;if(i&t.SIGHASH_ANYONECANPAY||(u=kn.allocUnsafe(36*this.ins.length),o=new nr(u,0),this.ins.forEach((function(t){o.writeSlice(t.hash),o.writeUInt32(t.index)})),s=xe(u)),i&t.SIGHASH_ANYONECANPAY||(31&i)===t.SIGHASH_SINGLE||(31&i)===t.SIGHASH_NONE||(u=kn.allocUnsafe(4*this.ins.length),o=new nr(u,0),this.ins.forEach((function(t){o.writeUInt32(t.sequence)})),f=xe(u)),(31&i)!==t.SIGHASH_SINGLE&&(31&i)!==t.SIGHASH_NONE){var c=this.outs.reduce((function(t,e){return t+8+Nn(e.script)}),0);u=kn.allocUnsafe(c),o=new nr(u,0),this.outs.forEach((function(t){o.writeUInt64(t.value),o.writeVarSlice(t.script)})),a=xe(u)}else if((31&i)===t.SIGHASH_SINGLE&&e<this.outs.length){var h=this.outs[e];u=kn.allocUnsafe(8+Nn(h.script)),(o=new nr(u,0)).writeUInt64(h.value),o.writeVarSlice(h.script),a=xe(u)}u=kn.allocUnsafe(156+Nn(r)),o=new nr(u,0);var l=this.ins[e];return o.writeInt32(this.version),o.writeSlice(s),o.writeSlice(f),o.writeSlice(l.hash),o.writeUInt32(l.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(l.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),xe(u)}},{key:"getHash",value:function(t){return t&&this.isCoinbase()?kn.alloc(32,0):xe(this.__toBuffer(void 0,void 0,t))}},{key:"getId",value:function(){return er(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){Un(bt(yt,wt),arguments),this.ins[t].script=e}},{key:"setWitness",value:function(t,e){Un(bt(yt,[wt]),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 nr(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 ir(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(),l=n.readVarSlice(),p=n.readUInt32();i.ins.push({hash:c,index:h,script:l,sequence:p,witness:Cn})}for(var y=n.readVarInt(),d=0;d<y;++d)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){Un(pt,t);for(var e=0;e<32;++e)if(0!==t[e])return!1;return!0}}],r&&On(e.prototype,r),n&&On(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();Pn(Kn,"DEFAULT_SEQUENCE",4294967295),Pn(Kn,"SIGHASH_DEFAULT",0),Pn(Kn,"SIGHASH_ALL",1),Pn(Kn,"SIGHASH_NONE",2),Pn(Kn,"SIGHASH_SINGLE",3),Pn(Kn,"SIGHASH_ANYONECANPAY",128),Pn(Kn,"SIGHASH_OUTPUT_MASK",3),Pn(Kn,"SIGHASH_INPUT_MASK",128),Pn(Kn,"ADVANCED_TRANSACTION_MARKER",0),Pn(Kn,"ADVANCED_TRANSACTION_FLAG",1);var Mn=r(287).Buffer;function Vn(t,e){if(t){if("string"==typeof t)return Fn(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)?Fn(t,e):void 0}}function Fn(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 jn=function(t){var e=32===t.length?t:t.slice(1,33);return Mn.isBuffer(e)?e:Mn.from(e)};function Gn(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=pr({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=pr({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:mi(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:di(i.concat(n.script).concat(n.controlBlock))}}catch(e){throw new Error("Can not finalize taproot input #".concat(t,": ").concat(e))}}function Wn(t,e){var r=e?Mn.from([e]):Mn.from([]);return Mn.concat([t,r])}function Xn(t){return t&&!!(t.tapInternalKey||t.tapMerkleRoot||t.tapLeafScript&&t.tapLeafScript.length||t.tapBip32Derivation&&t.tapBip32Derivation.length||t.witnessUtxo&&yi(t.witnessUtxo.script))}function qn(t,e){return t&&!!(t.tapInternalKey||t.tapTree||t.tapBip32Derivation&&t.tapBip32Derivation.length||e&&yi(e))}function zn(t,e,r){!function(t,e,r){var n=Xn(t)&&oi(e),i=oi(t)&&Xn(e),o=t===e&&Xn(e)&&oi(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 ii(t,e.tapMerkleRoot)})),i=(t.tapLeafScript||[]).every((function(t){return ii(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 ii(e,t.tapMerkleRoot)})))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}(t,e,r)}function Yn(t,e,r){!function(t,e,r){var n=qn(t)&&oi(e),i=oi(t)&&qn(e),o=t===e&&qn(e)&&oi(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 gn({internalPubkey:t,scriptTree:e&&Qn(e.leaves)}).output}(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}}(t,e)}function $n(t,e){var r=e.tapInternalKey,n=r&&dr(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 Jn(t){if(!ht(t))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ri(t)}function Qn(){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=Vn(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=ni(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 Zn(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 Fn(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)||Vn(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=ei(t.finalScriptWitness);n&&r.push(n)}return r}(t);return r.some((function(t){return Si(t,ti,e)}))}function ti(t){return{signature:t.slice(0,64),hashType:t.slice(64)[0]||Kn.SIGHASH_DEFAULT}}function ei(t){if(t){var e=t.slice(2);return 64===e.length||65===e.length?e:void 0}}function ri(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>sr)throw new Error("Max taptree depth exceeded.");return t?ct(t)?(e.push({depth:r,leafVersion:t.version||ar,script:t.output}),e):(t[0]&&ri(t[0],e,r+1),t[1]&&ri(t[1],e,r+1),e):[]}function ni(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>sr)throw new Error("Max taptree depth exceeded.");if(t.depth===r)return e?void 0:{output:t.script,version:t.leafVersion};if(!ct(e)){var n=ni(t,e&&e[0],r+1);if(n)return[n,e&&e[1]];var i=ni(t,e&&e[1],r+1);return i?[e&&e[0],i]:void 0}}function ii(t,e){if(!e)return!0;var r=pr({output:t.script,version:t.leafVersion});return cr(t.controlBlock,r).equals(e)}function oi(t){return t&&!!(t.redeemScript||t.witnessScript||t.bip32Derivation&&t.bip32Derivation.length)}var ui=r(287).Buffer;function ai(t){return function(e){try{return t({output:e}),!0}catch(t){return!1}}}var si=ai(Tr),fi=ai(_r),ci=ai(ki),hi=ai(bn),li=ai(_n),pi=ai(ln),yi=ai(gn);function di(t){var e,r=ui.allocUnsafe(0);function n(t){var e=r.length,n=fn.encodingLength(t);r=ui.concat([r,ui.allocUnsafe(n)]),fn.encode(t,r,e)}return n((e=t).length),e.forEach((function(t){n(t.length),function(t){r=ui.concat([r,ui.from(t)])}(t)})),r}function gi(t){if(32!==t.length){if(![33,65].includes(t.length))throw console.trace("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed).")),new Error("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed)."));var e;try{e=jr.fromHex(t)}catch(t){throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}var r=wi(e.x),n=wi(e.y),i=e.y%2n===0n?6:7,o=ui.alloc(65);return o[0]=i,r.copy(o,1),n.copy(o,33),{hybrid:o,uncompressed:ui.concat([ui.from([4]),r,n])}}}function wi(t){var e=t.toString(16);return(e=e.padStart(64,"0")).length>64&&(e=e.slice(-64)),ui.from(e,"hex")}function vi(t,e){if(t.equals(e))return!0;if(65===t.length&&65===e.length){var r=ui.from(t),n=ui.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 mi(t,e){var r=jt(e);if(null===r)throw new Error("Unknown script error");var n=Ne(t),i=jn(t),o=gi(t),u=null!=o&&o.hybrid?Ne(o.hybrid):void 0,a=null!=o&&o.uncompressed?Ne(o.uncompressed):void 0;return r.findIndex((function(e){if("number"==typeof e)return!1;if(vi(e,t))return!0;if(vi(e,i))return!0;if(e.equals(n))return!0;if(o){if(vi(e,o.uncompressed))return!0;if(vi(e,o.hybrid))return!0;if(u&&e.equals(u)||a&&e.equals(a))return!0}}))}function bi(t,e){return-1!==mi(t,e)}function Ei(t,e){var r=function(t){var e=[];if(0===(t.partialSig||[]).length){if(!t.finalScriptSig&&!t.finalScriptWitness)return[];e=Ti(t)}else e=t.partialSig;return e.map((function(t){return t.signature}))}(t);return r.some((function(t){return Si(t,Jt.decode,e)}))}function Si(t,e,r){var n=e(t).hashType,i=[];switch(n&Kn.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case Kn.SIGHASH_ALL:break;case Kn.SIGHASH_SINGLE:case Kn.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function Ti(t){var e=t.finalScriptSig&&jt(t.finalScriptSig)||[],r=t.finalScriptWitness&&jt(t.finalScriptWitness)||[];return e.concat(r).filter((function(t){return ui.isBuffer(t)&&Yt(t)})).map((function(t){return{signature:t}}))}var Ii=r(287).Buffer,_i=G;function ki(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||{}),nt({network:nt.maybe(nt.Object),address:nt.maybe(nt.String),hash:nt.maybe(nt.BufferN(20)),output:nt.maybe(nt.BufferN(25)),pubkey:nt.maybe(at),signature:nt.maybe(Yt),input:nt.maybe(nt.Buffer)},t);var r=vr((function(){var e=Ii.from(V.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),n=vr((function(){return jt(t.input)})),i=t.network||l,o={name:"p2pkh",network:i};if(wr(o,"address",(function(){if(o.hash){var t=Ii.allocUnsafe(21);return t.writeUInt8(i.pubKeyHash,0),o.hash.copy(t,1),V.encode(t)}})),wr(o,"hash",(function(){return t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?Ne(t.pubkey||o.pubkey):void 0})),wr(o,"output",(function(){if(o.hash)return Ft([_i.OP_DUP,_i.OP_HASH160,o.hash,_i.OP_EQUALVERIFY,_i.OP_CHECKSIG])})),wr(o,"pubkey",(function(){if(t.input)return n()[1]})),wr(o,"signature",(function(){if(t.input)return n()[0]})),wr(o,"input",(function(){if(t.pubkey&&t.signature){var e=t.pubkey;if(t.useHybrid||t.useUncompressed){var r=gi(t.pubkey);r&&(e=t.useUncompressed?r.uncompressed:r.hybrid)}return Ft([t.signature,e])}})),wr(o,"witness",(function(){if(o.input)return[]})),e.validate){var u=Ii.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]!==_i.OP_DUP||t.output[1]!==_i.OP_HASH160||20!==t.output[2]||t.output[23]!==_i.OP_EQUALVERIFY||t.output[24]!==_i.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=Ne(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=gi(t.pubkey);if(c){var h=Ne(c.uncompressed);if(u.equals(h))f=!1,t.useUncompressed=!0;else{var p=Ne(c.hybrid);(f=!u.equals(p))||(t.useHybrid=!0)}}}if(f)throw new TypeError("Hash mismatch");u=s}if(t.input){var y=n();if(2!==y.length)throw new TypeError("Input is invalid");if(!Yt(y[0]))throw new TypeError("Input has invalid signature");if(!at(y[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&!t.signature.equals(y[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(y[1]))throw new TypeError("Pubkey mismatch");var d=Ne(y[1]);if(u.length>0&&!u.equals(d))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,t)}var Ai=r(287).Buffer,Oi=r(287).Buffer;function Pi(t){return Pi="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},Pi(t)}function Bi(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,Ni(n.key),n)}}function Ui(t,e,r){return(e=Ni(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Ni(t){var e=function(t){if("object"!=Pi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Pi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pi(e)?e:e+""}var xi=nt,Ci=new TypeError("Cannot compute merkle root for zero transactions"),Li=new TypeError("Cannot compute witness commit for non-segwit block"),Hi=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Ui(this,"version",1),Ui(this,"prevHash",void 0),Ui(this,"merkleRoot",void 0),Ui(this,"timestamp",0),Ui(this,"witnessCommit",void 0),Ui(this,"bits",0),Ui(this,"nonce",0),Ui(this,"transactions",void 0)}return e=t,r=[{key:"getWitnessCommit",value:function(){if(!Ri(this.transactions))return null;var t=this.transactions[0].outs.filter((function(t){return t.script.slice(0,6).equals(Oi.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 Oi&&32===e.length?e:null}},{key:"hasWitnessCommit",value:function(){return this.witnessCommit instanceof Oi&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}},{key:"hasWitness",value:function(){return(t=this.transactions)instanceof Array&&t.some((function(t){return"object"===Pi(t)&&t.ins instanceof Array&&t.ins.some((function(t){return"object"===Pi(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+Ge.encodingLength(this.transactions.length)+this.transactions.reduce((function(t,r){return t+r.byteLength(e)}),0)}},{key:"getHash",value:function(){return xe(this.toBuffer(!0))}},{key:"getId",value:function(){return er(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=Oi.allocUnsafe(this.byteLength(t)),r=new nr(e);return 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||(Ge.encode(this.transactions.length,e,r.offset),r.offset+=Ge.encode.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=er(this.getHash()),r=t.calculateTarget(this.bits);return e.compare(r)<=0}},{key:"__checkMerkleRoot",value:function(){if(!this.transactions)throw Ci;var e=t.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}},{key:"__checkWitnessCommit",value:function(){if(!this.transactions)throw Ci;if(!this.hasWitnessCommit())throw Li;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 ir(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=Kn.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(Oi.from(e,"hex"))}},{key:"calculateTarget",value:function(t){var e=((4278190080&t)>>24)-3,r=8388607&t,n=Oi.alloc(32,0);return n.writeUIntBE(r,29-e,3),n}},{key:"calculateMerkleRoot",value:function(t,e){if(xi([{getHash:Tt}],t),0===t.length)throw Ci;if(e&&!Ri(t))throw Li;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=Ai.concat([u,a]);n[i]=e(s)}r=i}return n[0]}(t.map((function(t){return t.getHash(e)})),xe);return e?xe(Oi.concat([r,t[0].ins[0].witness[0]])):r}}],r&&Bi(e.prototype,r),n&&Bi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function Ri(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 Di=r(614),Ki=r(699);function Mi(t){return Mi="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},Mi(t)}function Vi(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 Fi(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,ji(n.key),n)}}function ji(t){var e=function(t){if("object"!=Mi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Mi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Mi(e)?e:e+""}var Gi=function(){return t=function t(){var e,r,n,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e=this,r="cacheByLength",n=new Map,(r=ji(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,this.registry=new FinalizationRegistry((function(t){var e=i.cacheByLength.get(t.length);e&&(e.delete(t),0===e.size&&i.cacheByLength.delete(t.length))}))},e=[{key:"addSignature",value:function(t,e){var r=t.length,n={length:r,dataRef:new WeakRef(t),signature:e};return this.cacheByLength.has(r)||this.cacheByLength.set(r,new Set),this.cacheByLength.get(r).add(n),this.registry.register(t,n),e}},{key:"getSignature",value:function(t){var e=t.length,r=this.cacheByLength.get(e);if(r){var n,i=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Vi(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)?Vi(t,e):void 0}}(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}}}}(r);try{for(i.s();!(n=i.n()).done;){var o=n.value,u=o.dataRef.deref();if(u&&u.equals(t))return o.signature}}catch(t){i.e(t)}finally{i.f()}}}},{key:"clearCache",value:function(){this.cacheByLength.clear()}}],e&&Fi(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Wi(t){return Wi="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},Wi(t)}function Xi(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 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,zi(n.key),n)}}function zi(t){var e=function(t){if("object"!=Wi(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Wi(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Wi(e)?e:e+""}var Yi=function(){function t(){var e,r,n,i=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e=this,r="cacheBySigner",n=new Map,(r=zi(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,this.registry=new FinalizationRegistry((function(t){var e=i.cacheBySigner.get(t.pubKey);e&&(e.delete(t),0===e.size&&i.cacheBySigner.delete(t.pubKey))}))}return e=t,r=[{key:"addSignature",value:function(t,e,r){var n={pubKey:t,dataRef:new WeakRef(e),signature:r};return this.cacheBySigner.has(t)||this.cacheBySigner.set(t,new Set),this.cacheBySigner.get(t).add(n),this.registry.register(e,n),r}},{key:"getSignature",value:function(t,e){var r=this.cacheBySigner.get(t);if(r){var n,i=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Xi(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)?Xi(t,e):void 0}}(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}}}}(r);try{for(i.s();!(n=i.n()).done;){var o=n.value,u=o.dataRef.deref();if(u&&u.equals(e))return o.signature}}catch(t){i.e(t)}finally{i.f()}}}},{key:"clearCache",value:function(){this.cacheBySigner.clear()}},{key:"clearCacheForSigner",value:function(t){this.cacheBySigner.delete(t)}}],n=[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}],r&&qi(e.prototype,r),n&&qi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}(),$i=r(287).Buffer,Ji=Yi.getInstance();function Qi(t){if(t.publicKey&&$i.isBuffer(t.publicKey))return t.publicKey.toString("hex")}function Zi(t){var e=t;e.hasHook||(e.hasHook=!0,e.signatureManager=new Gi,function(t){var e=t.sign;e&&(t.sign=new Proxy(e,{apply:function(e,r,n){var i=Qi(t),o=n[0];if(i){var u=Ji.getSignature(i,o);return u||(u=Ji.addSignature(i,o,Reflect.apply(e,r,n))),u}var a=t.signatureManager.getSignature(o);return a||(a=t.signatureManager.addSignature(o,Reflect.apply(e,r,n))),a}}));var r=t.signSchnorr;r&&(t.signSchnorr=new Proxy(r,{apply:function(e,r,n){var i=Qi(t),o=n[0];if(i){var u=Ji.getSignature(i,o);return u||(u=Ji.addSignature(i,o,Reflect.apply(e,r,n))),u}var a=t.signatureManager.getSignature(o);return a||(a=t.signatureManager.addSignature(o,Reflect.apply(e,r,n))),a}}))}(e))}var to=r(287).Buffer;function eo(t){return eo="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},eo(t)}function ro(){ro=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,u=Object.create(o.prototype),a=new B(n||[]);return i(u,"_invoke",{value:k(t,r,a)}),u}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var l="suspendedStart",p="suspendedYield",y="executing",d="completed",g={};function w(){}function v(){}function m(){}var b={};f(b,u,(function(){return this}));var E=Object.getPrototypeOf,S=E&&E(E(U([])));S&&S!==r&&n.call(S,u)&&(b=S);var T=m.prototype=w.prototype=Object.create(b);function I(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,e){function r(i,o,u,a){var s=h(t[i],t,o);if("throw"!==s.type){var f=s.arg,c=f.value;return c&&"object"==eo(c)&&n.call(c,"__await")?e.resolve(c.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(c).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,a)}))}a(s.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,i){r(t,n,e,i)}))}return o=o?o.then(i,i):i()}})}function k(e,r,n){var i=l;return function(o,u){if(i===y)throw Error("Generator is already running");if(i===d){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=A(a,n);if(s){if(s===g)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===l)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var f=h(e,r,n);if("normal"===f.type){if(i=n.done?d:p,f.arg===g)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(i=d,n.method="throw",n.arg=f.arg)}}}function A(e,r){var n=r.method,i=e.iterator[n];if(i===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,A(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var o=h(i,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,g;var u=o.arg;return u?u.done?(r[e.resultName]=u.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):u:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function B(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function U(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=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 o.next=o}}throw new TypeError(eo(e)+" is not iterable")}return v.prototype=m,i(T,"constructor",{value:m,configurable:!0}),i(m,"constructor",{value:v,configurable:!0}),v.displayName=f(m,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,f(t,s,"GeneratorFunction")),t.prototype=Object.create(T),t},e.awrap=function(t){return{__await:t}},I(_.prototype),f(_.prototype,a,(function(){return this})),e.AsyncIterator=_,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new _(c(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},I(T),f(T,s,"Generator"),f(T,u,(function(){return this})),f(T,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=U,B.prototype={constructor:B,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!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].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function i(n,i){return a.type="throw",a.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],a=u.completion;if("root"===u.tryLoc)return i("end");if(u.tryLoc<=this.prev){var s=n.call(u,"catchLoc"),f=n.call(u,"finallyLoc");if(s&&f){if(this.prev<u.catchLoc)return i(u.catchLoc,!0);if(this.prev<u.finallyLoc)return i(u.finallyLoc)}else if(s){if(this.prev<u.catchLoc)return i(u.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return i(u.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(u)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:U(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function no(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 io(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){no(o,n,i,u,a,"next",t)}function a(t){no(o,n,i,u,a,"throw",t)}u(void 0)}))}}function oo(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=ao(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 uo(t){return function(t){if(Array.isArray(t))return so(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||ao(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 ao(t,e){if(t){if("string"==typeof t)return so(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)?so(t,e):void 0}}function so(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 fo(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function co(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,lo(n.key),n)}}function ho(t,e,r){return e&&co(t.prototype,e),r&&co(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function lo(t){var e=function(t){if("object"!=eo(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=eo(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==eo(e)?e:e+""}var po={network:l,maximumFeeRate:5e3},yo=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 Di.i(new wo);fo(this,t),this.data=r,this.opts=Object.assign({},po,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 ho(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:rr(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=fe(e.script,t.opts.network)}catch(t){}return{script:rr(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,uo(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){So(t),this.opts.maximumFeeRate=t}},{key:"setVersion",value:function(t){So(t),To(this.data.inputs,"setVersion");var e=this.__CACHE;return e.__TX.version=t,e.__EXTRACTED_TX=void 0,this}},{key:"setLocktime",value:function(t){So(t),To(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){So(e),To(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]");zn(t,t,"addInput"),e&&To(this.data.inputs,"addInput"),t.witnessScript&&qo(t.witnessScript);var r=this.__CACHE;this.data.addInput(t),_o(r,r.__TX.ins[r.__TX.ins.length-1]);var n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&Mo(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]");To(this.data.inputs,"addOutput");var e=t.address;if("string"==typeof e){var r=ce(e,this.opts.network);t=Object.assign({},t,{script:r})}Yn(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(bo))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 Vo(this.data.inputs,n,r,!0,e),n}},{key:"getFeeRate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Po("__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 Po("__FEE","fee",this.data.inputs,this.__CACHE,t)}},{key:"finalizeAllInputs",value:function(){var t=this;return(0,Ki.checkForInput)(this.data.inputs,0),Yo(this.data.inputs.length).forEach((function(e){return t.finalizeInput(e)})),this}},{key:"finalizeInput",value:function(t,e,r){var n=(0,Ki.checkForInput)(this.data.inputs,t);return Xn(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]:Gn,n=(0,Ki.checkForInput)(this.data.inputs,t);if(Xn(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,Ki.checkForInput)(this.data.inputs,t),r=Xo(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(to.isBuffer(r)&&!Wo(r)&&!Yt(r))if(jt(r))return r}}}(e.finalScriptSig),e.witnessScript||function(t){if(t){var e=Ko(t),r=e[e.length-1];if(!Wo(r)&&jt(r))return r}}(e.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+zo(r.meaningfulScript)}},{key:"inputHasPubkey",value:function(t,e){return function(t,e,r,n){return bi(t,Xo(jo(r,e,n),r,"input",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,Ki.checkForInput)(this.data.inputs,t),t,this.__CACHE)}},{key:"inputHasHDKey",value:function(t,e){var r=(0,Ki.checkForInput)(this.data.inputs,t),n=Eo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"outputHasPubkey",value:function(t,e){return function(t,e,r,n){return bi(t,Xo(n.__TX.outs[r].script,r,"output",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,Ki.checkForOutput)(this.data.outputs,t),t,this.__CACHE)}},{key:"outputHasHDKey",value:function(t,e){var r=(0,Ki.checkForOutput)(this.data.outputs,t),n=Eo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"validateSignaturesOfAllInputs",value:function(t){var e=this;return(0,Ki.checkForInput)(this.data.inputs,0),Yo(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 Xn(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]:[Kn.SIGHASH_ALL];if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");var r,n=[],i=oo(Yo(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]:[Kn.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=oo(Yo(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]:[Kn.SIGHASH_ALL];if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");return Do(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]:[Kn.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=Do(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=oo(Yo(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=oo(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)||ao(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,Ki.checkForInput)(this.data.inputs,t);return Xn(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,Ki.checkForInput)(this.data.inputs,t);if(Xn(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,Ki.checkForInput)(n.data.inputs,t);return Xn(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,Ki.checkForInput)(i.data.inputs,t);if(Xn(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 vo(this.__CACHE),this.data.toBuffer()}},{key:"toHex",value:function(){return vo(this.__CACHE),this.data.toHex()}},{key:"toBase64",value:function(){return vo(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&&qo(e.witnessScript),zn(this.data.inputs[t],e,"updateInput"),this.data.updateInput(t,e),e.nonWitnessUtxo&&Mo(this.__CACHE,this.data.inputs[t],t),this}},{key:"updateOutput",value:function(t,e){return Yn(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=Ho(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]:Bo,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=Fo(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||hi(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=Jt.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]:Gn;if(!e.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing witness utxo."));if(e.tapKeySig){var i=di(gn({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=oo(o);try{for(h.s();!(f=h.n()).done;){var l=f.value,p=Jt.decode(l.signature),y=s!==p.hashType?xo(t,Object.assign({},n,{sighashType:p.hashType}),this.__CACHE,!0):{hash:u,script:a},d=y.hash,g=y.script;s=p.hashType,u=d,a=g,Io(l.pubkey,g,"verify"),c.push(e(l.pubkey,d,p.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&&jn(r))?Ho(t,n,this.data.inputs,r,this.__CACHE):function(t,e,r,n){var i=[];if(e.tapInternalKey){var o=Co(t,e,n);o&&i.push(o)}if(e.tapScriptSig){var u=e.tapScriptSig.map((function(t){return t.pubkey}));i.push.apply(i,uo(u))}return i.map((function(i){return Ho(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,Lo(i)))return!1;s++}if(o){var f,c=oo(o);try{var h,l=function(){var t=f.value,r=u.find((function(e){return t.pubkey.equals(e.pubkey)}));if(r){if(!e(t.pubkey,r.hash,Lo(t.signature)))return{v:!1};s++}};for(c.s();!(f=c.n()).done;)if(h=l())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]:[Kn.SIGHASH_ALL];Zi(e);var n=No(this.data.inputs,t,e.publicKey,this.__CACHE,r),i=n.hash,o=n.sighashType,u=[{pubkey:e.publicKey,signature:Jt.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]:[Kn.SIGHASH_DEFAULT];Zi(r);var o=this.checkTaprootHashesForSig(t,e,r,n,i),u=o.filter((function(t){return!t.leafHash})).map((function(t){return Wn(r.signSchnorr(t.hash),e.sighashType)}))[0],a=o.filter((function(t){return!!t.leafHash})).map((function(t){return{pubkey:jn(r.publicKey),signature:Wn(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]:[Kn.SIGHASH_ALL];Zi(e);var i=No(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:Jt.encode(n,u)}];r.data.updateInput(t,{partialSig:i})}))}},{key:"_signTaprootInputAsync",value:(e=io(ro().mark((function t(e,r,n,i){var o,u,a,s,f,c,h,l,p,y,d,g=arguments;return ro().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=g.length>4&&void 0!==g[4]?g[4]:[Kn.SIGHASH_DEFAULT],Zi(n),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:Wn(t,r.sighashType)}})),a.push(f)),c=u.filter((function(t){return!!t.leafHash})),c.length&&(h=c.map(function(){var t=io(ro().mark((function t(e){var i,o;return ro().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:jn(n.publicKey),signature:Wn(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,uo(h))),t.next=10,Promise.all(a);case 10:l=t.sent,p=oo(l);try{for(p.s();!(y=p.n()).done;)d=y.value,this.data.updateInput(e,d)}catch(t){p.e(t)}finally{p.f()}case 13: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=to.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=to.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]:{},Di.i.fromBuffer(e,go));return r=i.__CACHE.__TX,n=i.__CACHE,r.ins.forEach((function(t){_o(n,t)})),i}}]);var e}(),go=function(t){return new wo(t)},wo=function(){return ho((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:to.from([2,0,0,0,0,0,0,0,0,0]);fo(this,t),this.tx=Kn.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||!to.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");var e="string"==typeof t.hash?er(to.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||!to.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 vo(t){if(!1!==t.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function mo(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 bo(t){return!!t.finalScriptSig||!!t.finalScriptWitness}function Eo(t){return function(e){return!!e.masterFingerprint.equals(t.fingerprint)&&!!t.derivePath(e.path).publicKey.equals(e.pubkey)}}function So(t){if("number"!=typeof t||t!==Math.floor(t)||t>4294967295||t<0)throw new Error("Invalid 32 bit integer")}function To(t,e){t.forEach((function(t){if(Xn(t)?Zn(t,e):Ei(t,e))throw new Error("Can not modify transaction, signatures exist.")}))}function Io(t,e,r){if(!bi(t,e))throw new Error("Can not ".concat(r," for this input with the key ").concat(t.toString("hex")))}function _o(t,e){var r=er(to.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 ko(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 Ao=ko(ln,"Redeem script"),Oo=ko(_n,"Witness script");function Po(t,e,r,n){var i,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!r.every(bo))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(),Vo(r,i,n,u,o),"__FEE_RATE"===t?n.__FEE_RATE:"__FEE"===t?n.__FEE:void 0}function Bo(t,e,r,n,i,o){var u=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],a=zo(r);if(!function(t,e,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return mo(1,t.partialSig);case"multisig":var n=Tr({output:e});return mo(n.m,t.partialSig,n.pubkeys);default:return!1}}(e,r,a)&&u)throw new Error("Can not finalize input #".concat(t));return Uo(r,a,e.partialSig,n,i,o)}function Uo(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 Tr({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=Tr({output:t,signatures:i});break;case"pubkey":n=_r({output:t,signature:r[0].signature});break;case"pubkeyhash":n=ki({output:t,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=bn({output:t,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(t,e,r),f=o?_n({redeem:s}):null,c=i?ln({redeem:f||s}):null;return n?(a=di(f?f.witness:s.witness),c&&(u=c.input)):u=c?c.input:s.input,{finalScriptSig:u,finalScriptWitness:a}}function No(t,e,r,n,i){var o=xo(e,(0,Ki.checkForInput)(t,e),n,!1,i),u=o.hash,a=o.sighashType;return Io(r,o.script,"sign"),{hash:u,sighashType:a}}function xo(t,e,r,n,i){var o,u,a=r.__TX,s=e.sighashType||Kn.SIGHASH_ALL;if(Ro(s,i),e.nonWitnessUtxo){var f=Fo(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 l=a.ins[t].index;u=f.outs[l]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}var p=Xo(u.script,t,"input",e.redeemScript,e.witnessScript),y=p.meaningfulScript,d=p.type;if(["p2sh-p2wsh","p2wsh"].indexOf(d)>=0)o=a.hashForWitnessV0(t,y,u.value,s);else if(hi(y)){var g=ki({hash:y.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(y.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,y,s)}return{script:y,sighashType:s,hash:o}}function Co(t,e,r){var n=Go(t,e,r).script;return yi(n)?n.subarray(2,34):null}function Lo(t){return 64===t.length?t:t.subarray(0,64)}function Ho(t,e,r,n,i,o,u){var a=i.__TX,s=e.sighashType||Kn.SIGHASH_DEFAULT;Ro(s,u);var f=r.map((function(t,e){return Go(e,t,i)})),c=f.map((function(t){return t.script})),h=f.map((function(t){return t.value})),l=[];if(e.tapInternalKey&&!o){var p=Co(t,e,i)||to.from([]);if(jn(n).equals(p)){var y=a.hashForWitnessV1(t,c,h,s);l.push({pubkey:n,hash:y})}}var d=(e.tapLeafScript||[]).filter((function(t){return bi(n,t.script)})).map((function(t){var e=pr({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 l.concat(d)}function Ro(t,e){if(e&&e.indexOf(t)<0){var r=function(t){var e=t&Kn.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&t){case Kn.SIGHASH_ALL:e+="SIGHASH_ALL";break;case Kn.SIGHASH_SINGLE:e+="SIGHASH_SINGLE";break;case Kn.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 Do(t,e,r){var n=(0,Ki.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 Ko(t){var e=0;function r(){var r=fn.decode(t,e);return e+=fn.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 Mo(t,e,r){t.__NON_WITNESS_UTXO_BUF_CACHE[r]=e.nonWitnessUtxo,t.__NON_WITNESS_UTXO_TX_CACHE[r]=Kn.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 Vo(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=Ko(t.finalScriptWitness)),t.witnessUtxo)o+=t.witnessUtxo.value;else if(t.nonWitnessUtxo){var u=Fo(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 Fo(t,e,r){var n=t.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||Mo(t,e,r),n[r]}function jo(t,e,r){return Go(t,e,r).script}function Go(t,e,r){if(void 0!==e.witnessUtxo)return{script:e.witnessUtxo.script,value:e.witnessUtxo.value};if(void 0!==e.nonWitnessUtxo){var n=Fo(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 Wo(t){return 33===t.length&&qt(t)}function Xo(t,e,r,n,i){var o,u=pi(t),a=u&&n&&li(n),s=li(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,Ao(e,t,n,r),Oo(e,n,i,r),qo(o)):s?(o=i,Oo(e,t,i,r),qo(o)):u?(o=n,Ao(e,t,n,r)):o=t,{meaningfulScript:o,type:a?"p2sh-p2wsh":u?"p2sh":s?"p2wsh":"raw"}}function qo(t){if(hi(t)||pi(t))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function zo(t){return hi(t)?"witnesspubkeyhash":ci(t)?"pubkeyhash":si(t)?"multisig":fi(t)?"pubkey":"nonstandard"}function Yo(t){return uo(Array(t).keys())}const $o={networks:i,address:s,payments:h,script:a,crypto:f,Transaction:c};var Jo=n.eB,Qo=n.Oo,Zo=n.ac,tu=n.ri,eu=n.RY,ru=n.iL,nu=n.PW,iu=n.gp,ou=n.gM,uu=n.ZX,au=n.hl,su=n.p2,fu=n.XL,cu=n.R0,hu=n.vJ,lu=n.em,pu=n.Eb,yu=n.Et,du=n.m$,gu=n.Ay,wu=n.CB,vu=n.VL,mu=n.ow,bu=n.hP,Eu=n.Dk,Su=n.Ln,Tu=n.BL,Iu=n.A0,_u=n.CX,ku=n.f0,Au=n.Bh,Ou=n.Q2,Pu=n.C5,Bu=n.n0,Uu=n.NI,Nu=n.fQ,xu=n.mG,Cu=n.AM,Lu=n.Zh,Hu=n.o8,Ru=n.Ez,Du=n.KT,Ku=n.KS,Mu=n.AI,Vu=n.k1,Fu=n.pM,ju=n.Qf,Gu=n.Fl,Wu=n.HE,Xu=n.WH,qu=n.K$,zu=n.C2,Yu=n.e8,$u=n.sc,Ju=n.XN,Qu=n.VQ,Zu=n.LE,ta=n._T,ea=n.zm,ra=n.qR,na=n.o4,ia=n.Og,oa=n.FT,ua=n.uu,aa=n.I,sa=n.gU,fa=n.wn,ca=n.Kn,ha=n.Uu,la=n.du,pa=n.tO;export{Jo as Block,Qo as BufferReader,Zo as BufferWriter,tu as LEAF_VERSION_TAPSCRIPT,eu as MAX_TAPTREE_DEPTH,ru as Psbt,nu as TAGGED_HASH_PREFIXES,iu as TAGS,ou as TAPLEAF_VERSION_MASK,uu as Transaction,au as address,su as bigIntTo32Bytes,fu as checkInputForSig,cu as checkTaprootInputFields,hu as checkTaprootInputForSigs,lu as checkTaprootOutputFields,pu as cloneBuffer,yu as crypto,du as decompressPublicKey,gu as default,wu as findScriptPath,vu as fromBase58Check,mu as fromBech32,bu as fromOutputScript,Eu as getFinalScripts,Su as getPsigsFromInputFinalScripts,Tu as getTapKeySigFromWitness,Iu as hash160,_u as hash256,ku as initEccLib,Au as isP2MS,Ou as isP2PK,Pu as isP2PKH,Bu as isP2SHScript,Uu as isP2TR,Nu as isP2WPKH,xu as isP2WSHScript,Cu as isTaprootInput,Lu as isTaprootOutput,Hu as networks,Ru as opcodes,Du as payments,Ku as prepareFinalScripts,Mu as pubkeyInScript,Vu as pubkeyPositionInScript,Fu as pubkeysMatch,ju as readUInt64LE,Gu as reverseBuffer,Wu as ripemd160,Xu as rootHashFromPath,qu as script,zu as serializeTaprootSignature,Yu as sha1,$u as sha256,Ju as signatureBlocksAction,Qu as taggedHash,Zu as tapScriptFinalizer,ta as tapTreeFromList,ea as tapTreeToList,ra as tapTweakHash,na as tapleafHash,ia as toBase58Check,oa as toBech32,ua as toHashTree,aa as toOutputScript,sa as toXOnly,fa as tweakInternalPubKey,ca as tweakKey,ha as varuint,la as witnessStackToScriptWitness,pa as writeUInt64LE};
|