@btc-vision/bitcoin 6.4.11 → 6.5.2

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.
Files changed (105) hide show
  1. package/browser/chunks/crypto-0PweVewC.js +2033 -0
  2. package/browser/chunks/payments-CgasufRS.js +1047 -0
  3. package/browser/chunks/psbt-BIwOrKer.js +4096 -0
  4. package/browser/chunks/script-CROJPzz_.js +318 -0
  5. package/browser/chunks/transaction-DchBu35N.js +432 -0
  6. package/browser/chunks/utils-CO5kmxe9.js +761 -0
  7. package/browser/crypto/crypto.d.ts +1 -1
  8. package/browser/crypto.d.ts +1 -1
  9. package/browser/hooks/HookedSigner.d.ts +1 -1
  10. package/browser/index.d.ts +6 -4
  11. package/browser/index.js +92 -2
  12. package/browser/payments/index.d.ts +2 -2
  13. package/browser/payments/lazy.d.ts +1 -1
  14. package/browser/psbt/bip371.d.ts +5 -1
  15. package/browser/psbt.d.ts +1 -1
  16. package/browser/typeforce.d.ts +38 -0
  17. package/browser/types.d.ts +22 -20
  18. package/build/address.js +2 -2
  19. package/build/bip66.js +2 -2
  20. package/build/block.js +2 -2
  21. package/build/crypto.d.ts +1 -1
  22. package/build/crypto.js +2 -3
  23. package/build/hooks/HookedSigner.d.ts +1 -1
  24. package/build/index.d.ts +6 -4
  25. package/build/index.js +2 -2
  26. package/build/payments/bip341.js +1 -1
  27. package/build/payments/index.d.ts +2 -2
  28. package/build/payments/lazy.d.ts +1 -1
  29. package/build/payments/p2op.js +3 -3
  30. package/build/payments/p2pk.js +1 -1
  31. package/build/payments/p2pkh.js +3 -3
  32. package/build/payments/p2sh.js +3 -3
  33. package/build/payments/p2tr.js +9 -5
  34. package/build/payments/p2wpkh.js +3 -3
  35. package/build/payments/p2wsh.js +2 -2
  36. package/build/psbt/bip371.d.ts +5 -1
  37. package/build/psbt/bip371.js +10 -7
  38. package/build/psbt/psbtutils.js +5 -4
  39. package/build/psbt.d.ts +1 -1
  40. package/build/psbt.js +78 -45
  41. package/build/script.js +2 -2
  42. package/build/script_signature.js +7 -7
  43. package/build/transaction.js +22 -10
  44. package/build/tsconfig.tsbuildinfo +1 -0
  45. package/build/types.d.ts +22 -20
  46. package/build/types.js +10 -9
  47. package/package.json +37 -63
  48. package/src/address.ts +2 -2
  49. package/src/bip66.ts +2 -2
  50. package/src/block.ts +8 -5
  51. package/src/crypto.ts +3 -4
  52. package/src/ecc_lib.ts +1 -1
  53. package/src/hooks/HookedSigner.ts +1 -1
  54. package/src/index.ts +6 -6
  55. package/src/payments/bip341.ts +1 -1
  56. package/src/payments/embed.ts +1 -2
  57. package/src/payments/index.ts +4 -4
  58. package/src/payments/lazy.ts +3 -3
  59. package/src/payments/p2op.ts +4 -3
  60. package/src/payments/p2pk.ts +1 -1
  61. package/src/payments/p2pkh.ts +3 -3
  62. package/src/payments/p2sh.ts +13 -5
  63. package/src/payments/p2tr.ts +8 -9
  64. package/src/payments/p2wpkh.ts +3 -3
  65. package/src/payments/p2wsh.ts +4 -4
  66. package/src/psbt/bip371.ts +22 -13
  67. package/src/psbt/psbtutils.ts +8 -5
  68. package/src/psbt.ts +127 -80
  69. package/src/script.ts +4 -4
  70. package/src/script_signature.ts +7 -7
  71. package/src/transaction.ts +31 -18
  72. package/src/typeforce.d.ts +38 -0
  73. package/src/types.ts +34 -29
  74. package/test/address.spec.ts +12 -4
  75. package/test/bitcoin.core.spec.ts +1 -1
  76. package/test/block.spec.ts +1 -1
  77. package/test/bufferutils.spec.ts +1 -1
  78. package/test/crypto.spec.ts +3 -2
  79. package/test/fixtures/address.json +1 -1
  80. package/test/integration/addresses.spec.ts +1 -1
  81. package/test/integration/bip32.spec.ts +2 -2
  82. package/test/integration/blocks.spec.ts +1 -1
  83. package/test/integration/cltv.spec.ts +3 -3
  84. package/test/integration/csv.spec.ts +3 -3
  85. package/test/integration/payments.spec.ts +1 -1
  86. package/test/integration/taproot.spec.ts +8 -7
  87. package/test/integration/transactions.spec.ts +2 -2
  88. package/test/payments.spec.ts +4 -3
  89. package/test/psbt.spec.ts +106 -74
  90. package/test/script.spec.ts +73 -7
  91. package/test/script_number.spec.ts +1 -1
  92. package/test/script_signature.spec.ts +1 -1
  93. package/test/transaction.spec.ts +1 -1
  94. package/test/tsconfig.json +1 -1
  95. package/test/types.spec.ts +1 -1
  96. package/vite.config.browser.ts +93 -0
  97. package/vitest.config.ts +16 -0
  98. package/.babelrc +0 -4
  99. package/.mocharc.json +0 -13
  100. package/browser/index.js.LICENSE.txt +0 -14
  101. package/cjs/package.json +0 -3
  102. package/gulpfile.js +0 -42
  103. package/src/crypto/crypto-browser.js +0 -75
  104. package/test/ts-node-register.js +0 -7
  105. package/webpack.config.js +0 -79
package/browser/index.js CHANGED
@@ -1,2 +1,92 @@
1
- /*! For license information please see index.js.LICENSE.txt */
2
- var t={34:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+t.key.toString("hex"));if(65!==t.key.length)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+t.key.toString("hex"));if(64!==t.value.length&&65!==t.value.length)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1,33),leafHash:t.key.slice(33),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_SCRIPT_SIG]);return{key:n.concat([e,t.pubkey,t.leafHash]),value:t.signature}},e.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.leafHash)&&n.isBuffer(t.signature)&&32===t.pubkey.length&&32===t.leafHash.length&&(64===t.signature.length||65===t.signature.length)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex")+e.leafHash.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey)&&t.leafHash.equals(e.leafHash))).length)}},61:(t,e,r)=>{var n=r(113);function i(t){return t.name||t.toString().match(/function (.*?)\s*\(/)[1]}function o(t){return n.Nil(t)?"":i(t.constructor)}function u(t,e){Error.captureStackTrace&&Error.captureStackTrace(t,e)}function a(t){return n.Function(t)?t.toJSON?t.toJSON():i(t):n.Array(t)?"Array":t&&n.Object(t)?"Object":void 0!==t?t:""}function s(t,e,r){var i=function(t){return n.Function(t)?"":n.String(t)?JSON.stringify(t):t&&n.Object(t)?"":t}(e);return"Expected "+a(t)+", got"+(""!==r?" "+r:"")+(""!==i?" "+i:"")}function f(t,e,r){r=r||o(e),this.message=s(t,e,r),u(this,f),this.__type=t,this.__value=e,this.__valueTypeName=r}function c(t,e,r,n,i){t?(i=i||o(n),this.message=function(t,e,r,n,i){var o='" of type ';return"key"===e&&(o='" with key type '),s('property "'+a(r)+o+a(t),n,i)}(t,r,e,n,i)):this.message='Unexpected property "'+e+'"',u(this,f),this.__label=r,this.__property=e,this.__type=t,this.__value=n,this.__valueTypeName=i}f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,c.prototype=Object.create(Error.prototype),c.prototype.constructor=f,t.exports={TfTypeError:f,TfPropertyTypeError:c,tfCustomError:function(t,e){return new f(t,{},e)},tfSubError:function(t,e,r){return t instanceof c?(e=e+"."+t.__property,t=new c(t.__type,e,t.__label,t.__value,t.__valueTypeName)):t instanceof f&&(t=new c(t.__type,e,r,t.__value,t.__valueTypeName)),u(t),t},tfJSON:a,getValueTypeName:o}},80:(t,e)=>{var r,n,i;Object.defineProperty(e,"__esModule",{value:!0}),(i=e.GlobalTypes||(e.GlobalTypes={}))[i.UNSIGNED_TX=0]="UNSIGNED_TX",i[i.GLOBAL_XPUB=1]="GLOBAL_XPUB",e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(n=e.InputTypes||(e.InputTypes={}))[n.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",n[n.WITNESS_UTXO=1]="WITNESS_UTXO",n[n.PARTIAL_SIG=2]="PARTIAL_SIG",n[n.SIGHASH_TYPE=3]="SIGHASH_TYPE",n[n.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",n[n.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",n[n.BIP32_DERIVATION=6]="BIP32_DERIVATION",n[n.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",n[n.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",n[n.POR_COMMITMENT=9]="POR_COMMITMENT",n[n.TAP_KEY_SIG=19]="TAP_KEY_SIG",n[n.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",n[n.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",n[n.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",n[n.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",n[n.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT",e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(r=e.OutputTypes||(e.OutputTypes={}))[r.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",r[r.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",r[r.BIP32_DERIVATION=2]="BIP32_DERIVATION",r[r.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",r[r.TAP_TREE=6]="TAP_TREE",r[r.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION",e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]},113:t=>{var e={Array:function(t){return null!=t&&t.constructor===Array},Boolean:function(t){return"boolean"==typeof t},Function:function(t){return"function"==typeof t},Nil:function(t){return null==t},Number:function(t){return"number"==typeof t},Object:function(t){return"object"==typeof t},String:function(t){return"string"==typeof t},"":function(){return!0}};for(var r in e.Null=e.Nil,e)e[r].toJSON=function(t){return t}.bind(null,r);t.exports=e},133:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394);function o(t){const e=t.key.length,r=t.value.length,o=i.encodingLength(e),u=i.encodingLength(r),a=n.allocUnsafe(o+e+u+r);return i.encode(e,a,0),t.key.copy(a,o),i.encode(r,a,o+e),t.value.copy(a,o+e+u),a}function u(t,e){if("number"!=typeof t)throw new Error("cannot write a non-number as a number");if(t<0)throw new Error("specified a negative value for writing an unsigned value");if(t>e)throw new Error("RangeError: value out of range");if(Math.floor(t)!==t)throw new Error("value has a fractional component")}e.range=t=>[...Array(t).keys()],e.reverseBuffer=function(t){if(t.length<1)return t;let e=t.length-1,r=0;for(let n=0;n<t.length/2;n++)r=t[n],t[n]=t[e],t[e]=r,e--;return t},e.keyValsToBuffer=function(t){const e=t.map(o);return e.push(n.from([0])),n.concat(e)},e.keyValToBuffer=o,e.readUInt64LE=function(t,e){const r=t.readUInt32LE(e);let n=t.readUInt32LE(e+4);return n*=4294967296,u(n+r,9007199254740991),n+r},e.writeUInt64LE=function(t,e,r){return u(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}},213:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.encode=function(t){return{key:n.from([i.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}}},223:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t||1!==e.key.length)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+e.key.toString("hex"));if(32!==e.value.length)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)&&32===t.length},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.tapInternalKey}}}},238:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133);e.psbtToBuffer=function({globalMap:t,inputs:e,outputs:r}){const{globalKeyVals:i,inputKeyVals:u,outputKeyVals:a}=s({globalMap:t,inputs:e,outputs:r}),f=o.keyValsToBuffer(i),c=t=>0===t.length?[n.from([0])]:t.map(o.keyValsToBuffer),h=c(u),p=c(a),l=n.allocUnsafe(5);return l.writeUIntBE(482972169471,0,5),n.concat([l,f].concat(h,p))};const u=(t,e)=>t.key.compare(e.key);function a(t,e){const r=new Set,n=Object.entries(t).reduce(((t,[n,i])=>{if("unknownKeyVals"===n)return t;const o=e[n];if(void 0===o)return t;const u=(Array.isArray(i)?i:[i]).map(o.encode);return u.map((t=>t.key.toString("hex"))).forEach((t=>{if(r.has(t))throw new Error("Serialize Error: Duplicate key: "+t);r.add(t)})),t.concat(u)}),[]),i=t.unknownKeyVals?t.unknownKeyVals.filter((t=>!r.has(t.key.toString("hex")))):[];return n.concat(i).sort(u)}function s({globalMap:t,inputs:e,outputs:r}){return{globalKeyVals:a(t,i.globals),inputKeyVals:e.map((t=>a(t,i.inputs))),outputKeyVals:r.map((t=>a(t,i.outputs)))}}e.psbtToKeyVals=s},251:(t,e)=>{e.read=function(t,e,r,n,i){var o,u,a=8*i-n-1,s=(1<<a)-1,f=s>>1,c=-7,h=r?i-1:0,p=r?-1:1,l=t[e+h];for(h+=p,o=l&(1<<-c)-1,l>>=-c,c+=a;c>0;o=256*o+t[e+h],h+=p,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=p,c-=8);if(0===o)o=1-f;else{if(o===s)return u?NaN:1/0*(l?-1:1);u+=Math.pow(2,n),o-=f}return(l?-1:1)*u*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var u,a,s,f=8*o-i-1,c=(1<<f)-1,h=c>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,u=c):(u=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-u))<1&&(u--,s*=2),(e+=u+h>=1?p/s:p*Math.pow(2,1-h))*s>=2&&(u++,s/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(e*s-1)*Math.pow(2,i),u+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),u=0));i>=8;t[r+l]=255&a,l+=d,a/=256,i-=8);for(u=u<<i|a,f+=i;f>0;t[r+l]=255&u,l+=d,u/=256,f-=8);t[r+l-d]|=128*y}},263:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706),o=r(133),u=r(394),a=r(80);function s(t,e,r){if(!e.equals(n.from([r])))throw new Error(`Format Error: Invalid ${t} key: ${e.toString("hex")}`)}function f(t,{globalMapKeyVals:e,inputKeyVals:r,outputKeyVals:n}){const u={unsignedTx:t};let f=0;for(const t of e)switch(t.key[0]){case a.GlobalTypes.UNSIGNED_TX:if(s("global",t.key,a.GlobalTypes.UNSIGNED_TX),f>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");f++;break;case a.GlobalTypes.GLOBAL_XPUB:void 0===u.globalXpub&&(u.globalXpub=[]),u.globalXpub.push(i.globals.globalXpub.decode(t));break;default:u.unknownKeyVals||(u.unknownKeyVals=[]),u.unknownKeyVals.push(t)}const c=r.length,h=n.length,p=[],l=[];for(const t of o.range(c)){const e={};for(const n of r[t])switch(i.inputs.checkPubkey(n),n.key[0]){case a.InputTypes.NON_WITNESS_UTXO:if(s("input",n.key,a.InputTypes.NON_WITNESS_UTXO),void 0!==e.nonWitnessUtxo)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");e.nonWitnessUtxo=i.inputs.nonWitnessUtxo.decode(n);break;case a.InputTypes.WITNESS_UTXO:if(s("input",n.key,a.InputTypes.WITNESS_UTXO),void 0!==e.witnessUtxo)throw new Error("Format Error: Input has multiple WITNESS_UTXO");e.witnessUtxo=i.inputs.witnessUtxo.decode(n);break;case a.InputTypes.PARTIAL_SIG:void 0===e.partialSig&&(e.partialSig=[]),e.partialSig.push(i.inputs.partialSig.decode(n));break;case a.InputTypes.SIGHASH_TYPE:if(s("input",n.key,a.InputTypes.SIGHASH_TYPE),void 0!==e.sighashType)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");e.sighashType=i.inputs.sighashType.decode(n);break;case a.InputTypes.REDEEM_SCRIPT:if(s("input",n.key,a.InputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");e.redeemScript=i.inputs.redeemScript.decode(n);break;case a.InputTypes.WITNESS_SCRIPT:if(s("input",n.key,a.InputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");e.witnessScript=i.inputs.witnessScript.decode(n);break;case a.InputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.inputs.bip32Derivation.decode(n));break;case a.InputTypes.FINAL_SCRIPTSIG:s("input",n.key,a.InputTypes.FINAL_SCRIPTSIG),e.finalScriptSig=i.inputs.finalScriptSig.decode(n);break;case a.InputTypes.FINAL_SCRIPTWITNESS:s("input",n.key,a.InputTypes.FINAL_SCRIPTWITNESS),e.finalScriptWitness=i.inputs.finalScriptWitness.decode(n);break;case a.InputTypes.POR_COMMITMENT:s("input",n.key,a.InputTypes.POR_COMMITMENT),e.porCommitment=i.inputs.porCommitment.decode(n);break;case a.InputTypes.TAP_KEY_SIG:s("input",n.key,a.InputTypes.TAP_KEY_SIG),e.tapKeySig=i.inputs.tapKeySig.decode(n);break;case a.InputTypes.TAP_SCRIPT_SIG:void 0===e.tapScriptSig&&(e.tapScriptSig=[]),e.tapScriptSig.push(i.inputs.tapScriptSig.decode(n));break;case a.InputTypes.TAP_LEAF_SCRIPT:void 0===e.tapLeafScript&&(e.tapLeafScript=[]),e.tapLeafScript.push(i.inputs.tapLeafScript.decode(n));break;case a.InputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.inputs.tapBip32Derivation.decode(n));break;case a.InputTypes.TAP_INTERNAL_KEY:s("input",n.key,a.InputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.inputs.tapInternalKey.decode(n);break;case a.InputTypes.TAP_MERKLE_ROOT:s("input",n.key,a.InputTypes.TAP_MERKLE_ROOT),e.tapMerkleRoot=i.inputs.tapMerkleRoot.decode(n);break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(n)}p.push(e)}for(const t of o.range(h)){const e={};for(const r of n[t])switch(i.outputs.checkPubkey(r),r.key[0]){case a.OutputTypes.REDEEM_SCRIPT:if(s("output",r.key,a.OutputTypes.REDEEM_SCRIPT),void 0!==e.redeemScript)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");e.redeemScript=i.outputs.redeemScript.decode(r);break;case a.OutputTypes.WITNESS_SCRIPT:if(s("output",r.key,a.OutputTypes.WITNESS_SCRIPT),void 0!==e.witnessScript)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");e.witnessScript=i.outputs.witnessScript.decode(r);break;case a.OutputTypes.BIP32_DERIVATION:void 0===e.bip32Derivation&&(e.bip32Derivation=[]),e.bip32Derivation.push(i.outputs.bip32Derivation.decode(r));break;case a.OutputTypes.TAP_INTERNAL_KEY:s("output",r.key,a.OutputTypes.TAP_INTERNAL_KEY),e.tapInternalKey=i.outputs.tapInternalKey.decode(r);break;case a.OutputTypes.TAP_TREE:s("output",r.key,a.OutputTypes.TAP_TREE),e.tapTree=i.outputs.tapTree.decode(r);break;case a.OutputTypes.TAP_BIP32_DERIVATION:void 0===e.tapBip32Derivation&&(e.tapBip32Derivation=[]),e.tapBip32Derivation.push(i.outputs.tapBip32Derivation.decode(r));break;default:e.unknownKeyVals||(e.unknownKeyVals=[]),e.unknownKeyVals.push(r)}l.push(e)}return{globalMap:u,inputs:p,outputs:l}}e.psbtFromBuffer=function(t,e){let r=0;function n(){const e=u.decode(t,r);r+=u.encodingLength(e);const n=t.slice(r,r+e);return r+=e,n}function i(){return{key:n(),value:n()}}function s(){if(r>=t.length)throw new Error("Format Error: Unexpected End of PSBT");const e=0===t.readUInt8(r);return e&&r++,e}if(1886610036!==function(){const e=t.readUInt32BE(r);return r+=4,e}())throw new Error("Format Error: Invalid Magic Number");if(255!==function(){const e=t.readUInt8(r);return r+=1,e}())throw new Error("Format Error: Magic Number must be followed by 0xff separator");const c=[],h={};for(;!s();){const t=i(),e=t.key.toString("hex");if(h[e])throw new Error("Format Error: Keys must be unique for global keymap: key "+e);h[e]=1,c.push(t)}const p=c.filter((t=>t.key[0]===a.GlobalTypes.UNSIGNED_TX));if(1!==p.length)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const l=e(p[0].value),{inputCount:d,outputCount:y}=l.getInputOutputCounts(),g=[],w=[];for(const t of o.range(d)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each input: input index "+t+" key "+o);e[o]=1,r.push(n)}g.push(r)}for(const t of o.range(y)){const e={},r=[];for(;!s();){const n=i(),o=n.key.toString("hex");if(e[o])throw new Error("Format Error: Keys must be unique for each output: output index "+t+" key "+o);e[o]=1,r.push(n)}w.push(r)}return f(l,{globalMapKeyVals:c,inputKeyVals:g,outputKeyVals:w})},e.checkKeyBuffer=s,e.psbtFromKeyVals=f},287:(t,e,r)=>{const n=r(526),i=r(251),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=s,e.IS=50;const u=2147483647;function a(t){if(t>u)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return h(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|y(t,e);let n=a(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(z(t,Uint8Array)){const e=new Uint8Array(t);return l(e.buffer,e.byteOffset,e.byteLength)}return p(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(z(t,ArrayBuffer)||t&&z(t.buffer,ArrayBuffer))return l(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(z(t,SharedArrayBuffer)||t&&z(t.buffer,SharedArrayBuffer)))return l(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);const i=function(t){if(s.isBuffer(t)){const e=0|d(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||$(t.length)?a(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t){return c(t),a(t<0?0:0|d(t))}function p(t){const e=t.length<0?0:0|d(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function d(t){if(t>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return 0|t}function y(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||z(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return 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 U(this,e,r);case"utf8":case"utf-8":return k(this,e,r);case"ascii":return O(this,e,r);case"latin1":case"binary":return P(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function v(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),$(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let o,u=1,a=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;u=2,a/=2,s/=2,r/=2}function f(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}if(i){let n=-1;for(o=r;o<a;o++)if(f(t,o)===f(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===s)return n*u}else-1!==n&&(o-=o-n),n=-1}else for(r+s>a&&(r=a-s),o=r;o>=0;o--){let r=!0;for(let n=0;n<s;n++)if(f(t,o+n)!==f(e,n)){r=!1;break}if(r)return o}return-1}function b(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let u;for(n>o/2&&(n=o/2),u=0;u<n;++u){const n=parseInt(e.substr(2*u,2),16);if($(n))return u;t[r+u]=n}return u}function E(t,e,r,n){return Y(X(e,t.length-r),t,r,n)}function S(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function I(t,e,r,n){return Y(q(e),t,r,n)}function T(t,e,r,n){return Y(function(t,e){let r,n,i;const o=[];for(let u=0;u<t.length&&!((e-=2)<0);++u)r=t.charCodeAt(u),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function _(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function k(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,u=e>239?4:e>223?3:e>191?2:1;if(i+u<=r){let r,n,a,s;switch(u){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(s=(31&e)<<6|63&r,s>127&&(o=s));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(s=(15&e)<<12|(63&r)<<6|63&n,s>2047&&(s<55296||s>57343)&&(o=s));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(s=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,s>65535&&s<1114112&&(o=s))}}null===o?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=u}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=A));return r}(n)}s.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return c(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},s.allocUnsafe=function(t){return h(t)},s.allocUnsafeSlow=function(t){return h(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=s.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(z(e,Uint8Array))i+e.length>n.length?(s.isBuffer(e)||(e=s.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!s.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},s.byteLength=y,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)w(this,e,e+1);return this},s.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)w(this,e,e+3),w(this,e+1,e+2);return this},s.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)w(this,e,e+7),w(this,e+1,e+6),w(this,e+2,e+5),w(this,e+3,e+4);return this},s.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?k(this,0,t):g.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},o&&(s.prototype[o]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,i){if(z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),u=(r>>>=0)-(e>>>=0);const a=Math.min(o,u),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<a;++t)if(f[t]!==c[t]){o=f[t],u=c[t];break}return o<u?-1:u<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return v(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return v(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return S(this,t,e,r);case"base64":return I(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function O(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function P(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function U(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=J[t[n]];return i}function N(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function x(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i){F(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,u>>=8,t[r++]=u,r}function R(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 L(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 V(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||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readBigUInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),s.prototype.readBigUInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readBigInt64LE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),s.prototype.readBigInt64BE=Q((function(t){G(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),s.prototype.readFloatLE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||B(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigUInt64LE=Q((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=Q((function(t,e=0){return R(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=0,o=1,u=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);B(this,t,e,r,n-1,-n)}let i=r-1,o=1,u=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/o|0)-u&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeBigInt64LE=Q((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=Q((function(t,e=0){return R(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return V(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return V(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=s.isBuffer(t)?t:s.from(t,n),u=o.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%u]}return this};const D={};function K(t,e,r){D[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function M(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,n,i,o){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=o>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** ${8*(o+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new D.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,r){G(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||j(e,t.length-(r+1))}(n,i,o)}function G(t,e){if("number"!=typeof t)throw new D.ERR_INVALID_ARG_TYPE(e,"number",t)}function j(t,e,r){if(Math.floor(t)!==t)throw G(t,r),new D.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new D.ERR_BUFFER_OUT_OF_BOUNDS;throw new D.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}K("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),K("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),K("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=M(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=M(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function 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 Y(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function z(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function $(t){return t!=t}const J=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function Q(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}},307:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.redeemScript}}}},343:(t,e)=>{e.p2=e.I=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<32;t++){const e=r.charAt(t);n[e]=t}function i(t){const e=t>>25;return(33554431&t)<<5^996825010&-(1&e)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=i(e)^n>>5}e=i(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=i(e)^31&n}return e}function u(t,e,r,n){let i=0,o=0;const u=(1<<r)-1,a=[];for(let n=0;n<t.length;++n)for(i=i<<e|t[n],o+=e;o>=r;)o-=r,a.push(i>>o&u);if(n)o>0&&a.push(i<<r-o&u);else{if(o>=e)return"Excess padding";if(i<<r-o&u)return"Non-zero padding"}return a}function a(t){return u(t,8,5,!0)}function s(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e}function f(t){const e=u(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function c(t){let e;function u(t,r){if(r=r||90,t.length<8)return t+" too short";if(t.length>r)return"Exceeds length limit";const u=t.toLowerCase(),a=t.toUpperCase();if(t!==u&&t!==a)return"Mixed-case string "+t;const s=(t=u).lastIndexOf("1");if(-1===s)return"No separator character for "+t;if(0===s)return"Missing prefix for "+t;const f=t.slice(0,s),c=t.slice(s+1);if(c.length<6)return"Data too short";let h=o(f);if("string"==typeof h)return h;const p=[];for(let t=0;t<c.length;++t){const e=c.charAt(t),r=n[e];if(void 0===r)return"Unknown character "+e;h=i(h)^r,t+6>=c.length||p.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:p}}return e="bech32"===t?1:734539939,{decodeUnsafe:function(t,e){const r=u(t,e);if("object"==typeof r)return r},decode:function(t,e){const r=u(t,e);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,n,u){if(u=u||90,t.length+7+n.length>u)throw new TypeError("Exceeds length limit");let a=o(t=t.toLowerCase());if("string"==typeof a)throw new Error(a);let s=t+"1";for(let t=0;t<n.length;++t){const e=n[t];if(e>>5)throw new Error("Non 5-bit word");a=i(a)^e,s+=r.charAt(e)}for(let t=0;t<6;++t)a=i(a);a^=e;for(let t=0;t<6;++t)s+=r.charAt(a>>5*(5-t)&31);return s},toWords:a,fromWordsUnsafe:s,fromWords:f}}e.I=c("bech32"),e.p2=c("bech32m")},344:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+t.key.toString("hex"));return t.value.readUInt32LE(0)},e.encode=function(t){const e=n.from([i.InputTypes.SIGHASH_TYPE]),r=n.allocUnsafe(4);return r.writeUInt32LE(t,0),{key:e,value:r}},e.expected="number",e.check=function(t){return"number"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.sighashType}},394:(t,e,r)=>{var n=r(287).hp;function i(t){if(t<0||t>9007199254740991||t%1!=0)throw new RangeError("value out of range")}function o(t){return i(t),t<253?1:t<=65535?3:t<=4294967295?5:9}Object.defineProperty(e,"__esModule",{value:!0}),e.encode=function t(e,r,u){if(i(e),r||(r=n.allocUnsafe(o(e))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return u||(u=0),e<253?(r.writeUInt8(e,u),Object.assign(t,{bytes:1})):e<=65535?(r.writeUInt8(253,u),r.writeUInt16LE(e,u+1),Object.assign(t,{bytes:3})):e<=4294967295?(r.writeUInt8(254,u),r.writeUInt32LE(e,u+1),Object.assign(t,{bytes:5})):(r.writeUInt8(255,u),r.writeUInt32LE(e>>>0,u+1),r.writeUInt32LE(e/4294967296|0,u+5),Object.assign(t,{bytes:9})),r},e.decode=function t(e,r){if(!n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");r||(r=0);const o=e.readUInt8(r);if(o<253)return Object.assign(t,{bytes:1}),o;if(253===o)return Object.assign(t,{bytes:3}),e.readUInt16LE(r+1);if(254===o)return Object.assign(t,{bytes:5}),e.readUInt32LE(r+1);{Object.assign(t,{bytes:9});const n=e.readUInt32LE(r+1),o=4294967296*e.readUInt32LE(r+5)+n;return i(o),o}},e.encodingLength=o},412:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.makeChecker=function(t){return function(e){let r;if(t.includes(e.key[0])&&(r=e.key.slice(1),33!==r.length&&65!==r.length||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+e.key.toString("hex"));return r}}},431:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.NON_WITNESS_UTXO]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.nonWitnessUtxo}},454:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&32===t.length}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_MERKLE_ROOT||1!==t.key.length)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_MERKLE_ROOT]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapMerkleRoot}},457:(t,e,r)=>{function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),n(r(263)),n(r(238))},526:(t,e)=>{e.byteLength=function(t){var e=a(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=a(t),u=o[0],s=o[1],f=new i(function(t,e,r){return 3*(e+r)/4-r}(0,u,s)),c=0,h=s>0?u-4:u;for(r=0;r<h;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],f[c++]=e>>16&255,f[c++]=e>>8&255,f[c++]=255&e;return 2===s&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,f[c++]=255&e),1===s&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,f[c++]=e>>8&255,f[c++]=255&e),f},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],u=16383,a=0,f=n-i;a<f;a+=u)o.push(s(t,a,a+u>f?f:a+u));return 1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0;u<64;++u)r[u]=o[u],n[o.charCodeAt(u)]=u;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function s(t,e,n){for(var i,o,u=[],a=e;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),u.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return u.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},542:(t,e,r)=>{var n=r(287).hp,i=r(113),o=r(61);function u(t){return n.isBuffer(t)}function a(t){return"string"==typeof t&&/^([0-9a-f]{2})+$/i.test(t)}function s(t,e){var r=t.toJSON();function n(n){if(!t(n))return!1;if(n.length===e)return!0;throw o.tfCustomError(r+"(Length: "+e+")",r+"(Length: "+n.length+")")}return n.toJSON=function(){return r},n}var f=s.bind(null,i.Array),c=s.bind(null,u),h=s.bind(null,a),p=s.bind(null,i.String),l=Math.pow(2,53)-1,d={ArrayN:f,Buffer:u,BufferN:c,Finite:function(t){return"number"==typeof t&&isFinite(t)},Hex:a,HexN:h,Int8:function(t){return t<<24>>24===t},Int16:function(t){return t<<16>>16===t},Int32:function(t){return(0|t)===t},Int53:function(t){return"number"==typeof t&&t>=-l&&t<=l&&Math.floor(t)===t},Range:function(t,e,r){function n(n,i){return r(n,i)&&n>t&&n<e}return r=r||i.Number,n.toJSON=function(){return`${r.toJSON()} between [${t}, ${e}]`},n},StringN:p,UInt8:function(t){return(255&t)===t},UInt16:function(t){return(65535&t)===t},UInt32:function(t){return t>>>0===t},UInt53:function(t){return"number"==typeof t&&t>=0&&t<=l&&Math.floor(t)===t}};for(var y in d)d[y].toJSON=function(t){return t}.bind(null,y);t.exports=d},545:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=t=>33===t.length&&[2,3].includes(t[0])||65===t.length&&4===t[0];e.makeConverter=function(t,e=i){return{decode:function(r){if(r.key[0]!==t)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+r.key.toString("hex"));const n=r.key.slice(1);if(!e(n))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+r.key.toString("hex"));if(r.value.length/4%1!=0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const i={masterFingerprint:r.value.slice(0,4),pubkey:n,path:"m"};for(const t of(o=r.value.length/4-1,[...Array(o).keys()])){const e=r.value.readUInt32LE(4*t+4),n=!!(2147483648&e),o=2147483647&e;i.path+="/"+o.toString(10)+(n?"'":"")}var o;return i},encode:function(e){const r=n.from([t]),i=n.concat([r,e.pubkey]),o=e.path.split("/"),u=n.allocUnsafe(4*o.length);e.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:i,value:u}},check:function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.masterFingerprint)&&"string"==typeof t.path&&e(t.pubkey)&&4===t.masterFingerprint.length},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }",canAddToArray:function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}}}},578:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0}),e.makeConverter=function(t){return{decode:function(e){if(e.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+e.key.toString("hex"));return e.value},encode:function(e){return{key:n.from([t]),value:e}},check:function(t){return n.isBuffer(t)},expected:"Buffer",canAdd:function(t,e){return!!t&&!!e&&void 0===t.witnessScript}}}},605:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTSIG]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptSig}},614:(t,e,r)=>{var n=r(287).hp;const i=r(863),o=r(457),u=r(80),a=r(699);e.i=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,e){const r=n.from(t,"base64");return this.fromBuffer(r,e)}static fromHex(t,e){const r=n.from(t,"hex");return this.fromBuffer(r,e)}static fromBuffer(t,e){const r=o.psbtFromBuffer(t,e),n=new this(r.globalMap.unsignedTx);return Object.assign(n,r),n}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return o.psbtToBuffer(this)}updateGlobal(t){return a.updateGlobal(t,this.globalMap),this}updateInput(t,e){const r=a.checkForInput(this.inputs,t);return a.updateInput(e,r),this}updateOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.updateOutput(e,r),this}addUnknownKeyValToGlobal(t){return a.checkHasKey(t,this.globalMap.unknownKeyVals,a.getEnumLength(u.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,e){const r=a.checkForInput(this.inputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.InputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addUnknownKeyValToOutput(t,e){const r=a.checkForOutput(this.outputs,t);return a.checkHasKey(e,r.unknownKeyVals,a.getEnumLength(u.OutputTypes)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(e),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToInput(r,t))),a.addInputAttributes(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const e=t.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(e))throw new Error("unknownKeyVals must be an Array");return e.forEach((t=>this.addUnknownKeyValToOutput(r,t))),a.addOutputAttributes(this.outputs,t),this}clearFinalizedInput(t){const e=a.checkForInput(this.inputs,t);a.inputCheckUncleanFinalized(t,e);for(const t of Object.keys(e))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(t)||delete e[t];return this}combine(...t){const e=i.combine([this].concat(t));return Object.assign(this,e),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}},636:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(394),o=r(545),u=t=>32===t.length;e.makeConverter=function(t){const e=o.makeConverter(t,u);return{decode:function(t){const r=i.decode(t.value),n=i.encodingLength(r),o=e.decode({key:t.key,value:t.value.slice(n+32*r)}),u=new Array(r);for(let e=0,i=n;e<r;e++,i+=32)u[e]=t.value.slice(i,i+32);return Object.assign({},o,{leafHashes:u})},encode:function(t){const r=e.encode(t),o=i.encodingLength(t.leafHashes.length),u=n.allocUnsafe(o);i.encode(t.leafHashes.length,u);const a=n.concat([u,...t.leafHashes,r.value]);return Object.assign({},r,{value:a})},check:function(t){return Array.isArray(t.leafHashes)&&t.leafHashes.every((t=>n.isBuffer(t)&&32===t.length))&&e.check(t)},expected:"{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }",canAddToArray:e.canAddToArray}}},676:(t,e,r)=>{var n=r(61),i=r(113),o=n.tfJSON,u=n.TfTypeError,a=n.TfPropertyTypeError,s=n.tfSubError,f=n.getValueTypeName,c={arrayOf:function(t,e){function r(r,n){return!!i.Array(r)&&!i.Nil(r)&&!(void 0!==e.minLength&&r.length<e.minLength)&&!(void 0!==e.maxLength&&r.length>e.maxLength)&&(void 0===e.length||r.length===e.length)&&r.every((function(e,r){try{return p(t,e,n)}catch(t){throw s(t,r)}}))}return t=h(t),e=e||{},r.toJSON=function(){var r="["+o(t)+"]";return void 0!==e.length?r+="{"+e.length+"}":void 0===e.minLength&&void 0===e.maxLength||(r+="{"+(void 0===e.minLength?0:e.minLength)+","+(void 0===e.maxLength?1/0:e.maxLength)+"}"),r},r},maybe:function t(e){function r(r,n){return i.Nil(r)||e(r,n,t)}return e=h(e),r.toJSON=function(){return"?"+o(e)},r},map:function(t,e){function r(r,n){if(!i.Object(r))return!1;if(i.Nil(r))return!1;for(var o in r){try{e&&p(e,o,n)}catch(t){throw s(t,o,"key")}try{var u=r[o];p(t,u,n)}catch(t){throw s(t,o)}}return!0}return t=h(t),e&&(e=h(e)),r.toJSON=e?function(){return"{"+o(e)+": "+o(t)+"}"}:function(){return"{"+o(t)+"}"},r},object:function(t){var e={};for(var r in t)e[r]=h(t[r]);function n(t,r){if(!i.Object(t))return!1;if(i.Nil(t))return!1;var n;try{for(n in e)p(e[n],t[n],r)}catch(t){throw s(t,n)}if(r)for(n in t)if(!e[n])throw new a(void 0,n);return!0}return n.toJSON=function(){return o(e)},n},anyOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.some((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join("|")},e},allOf:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return t.every((function(t){try{return p(t,e,r)}catch(t){return!1}}))}return e.toJSON=function(){return t.map(o).join(" & ")},e},quacksLike:function(t){function e(e){return t===f(e)}return e.toJSON=function(){return t},e},tuple:function(){var t=[].slice.call(arguments).map(h);function e(e,r){return!i.Nil(e)&&!i.Nil(e.length)&&(!r||e.length===t.length)&&t.every((function(t,n){try{return p(t,e[n],r)}catch(t){throw s(t,n)}}))}return e.toJSON=function(){return"("+t.map(o).join(", ")+")"},e},value:function(t){function e(e){return e===t}return e.toJSON=function(){return t},e}};function h(t){if(i.String(t))return"?"===t[0]?c.maybe(t.slice(1)):i[t]||c.quacksLike(t);if(t&&i.Object(t)){if(i.Array(t)){if(1!==t.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(t[0])}return c.object(t)}return i.Function(t)?t:c.value(t)}function p(t,e,r,n){if(i.Function(t)){if(t(e,r))return!0;throw new u(n||t,e)}return p(h(t),e,r)}for(var l in c.oneOf=c.anyOf,i)p[l]=i[l];for(l in c)p[l]=c[l];var d=r(542);for(l in d)p[l]=d[l];p.compile=h,p.TfTypeError=u,p.TfPropertyTypeError=a,t.exports=p},695:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+t.key.toString("hex"));if((t.key.length-2)%32!=0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+t.key.toString("hex"));const e=t.value[t.value.length-1];if((254&t.key[1])!==e)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+t.key.toString("hex"));const r=t.value.slice(0,-1);return{controlBlock:t.key.slice(1),script:r,leafVersion:e}},e.encode=function(t){const e=n.from([i.InputTypes.TAP_LEAF_SCRIPT]),r=n.from([t.leafVersion]);return{key:n.concat([e,t.controlBlock]),value:n.concat([t.script,r])}},e.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }",e.check=function(t){return n.isBuffer(t.controlBlock)&&(t.controlBlock.length-1)%32==0&&(254&t.controlBlock[0])===t.leafVersion&&n.isBuffer(t.script)},e.canAddToArray=function(t,e,r){const n=e.controlBlock.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.controlBlock.equals(e.controlBlock))).length)}},699:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(706);function o(t,e){const r=t[e];if(void 0===r)throw new Error(`No input #${e}`);return r}function u(t,e){const r=t[e];if(void 0===r)throw new Error(`No output #${e}`);return r}function a(t,e,r,n){throw new Error(`Data for ${t} key ${e} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function s(t){return(e,r)=>{for(const n of Object.keys(e)){const o=e[n],{canAdd:u,canAddToArray:s,check:f,expected:c}=i[t+"s"][n]||{};if(f)if(s){if(!Array.isArray(o)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);o.every(f)||a(t,n,c,o);const e=r[n]||[],i=new Set;if(!o.every((t=>s(e,t,i))))throw new Error("Can not add duplicate data to array");r[n]=e.concat(o)}else{if(f(o)||a(t,n,c,o),!u(r,o))throw new Error(`Can not add duplicate data to ${t}`);r[n]=o}}}}e.checkForInput=o,e.checkForOutput=u,e.checkHasKey=function(t,e,r){if(t.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(e&&0!==e.filter((e=>e.key.equals(t.key))).length)throw new Error(`Duplicate Key: ${t.key.toString("hex")}`)},e.getEnumLength=function(t){let e=0;return Object.keys(t).forEach((t=>{Number(isNaN(Number(t)))&&e++})),e},e.inputCheckUncleanFinalized=function(t,e){let r=!1;if(e.nonWitnessUtxo||e.witnessUtxo){const t=!!e.redeemScript,n=!!e.witnessScript,i=!t||!!e.finalScriptSig,o=!n||!!e.finalScriptWitness,u=!!e.finalScriptSig||!!e.finalScriptWitness;r=i&&o&&u}if(!1===r)throw new Error(`Input #${t} has too much or too little data to clean`)},e.updateGlobal=s("global"),e.updateInput=s("input"),e.updateOutput=s("output"),e.addInputAttributes=function(t,r){const n=o(t,t.length-1);e.updateInput(r,n)},e.addOutputAttributes=function(t,r){const n=u(t,t.length-1);e.updateOutput(r,n)},e.defaultVersionSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Version: Invalid Transaction");return e.writeUInt32LE(t,0),e},e.defaultLocktimeSetter=function(t,e){if(!n.isBuffer(e)||e.length<4)throw new Error("Set Locktime: Invalid Transaction");return e.writeUInt32LE(t,e.length-4),e}},706:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(80),i=r(834),o=r(213),u=r(605),a=r(795),s=r(431),f=r(907),c=r(949),h=r(344),p=r(760),l=r(695),d=r(454),y=r(34),g=r(926),w=r(851),v=r(545),m=r(412),b=r(307),E=r(636),S=r(223),I=r(578),T={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=T;const _={nonWitnessUtxo:s,partialSig:f,sighashType:h,finalScriptSig:u,finalScriptWitness:a,porCommitment:c,witnessUtxo:g,bip32Derivation:v.makeConverter(n.InputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.InputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:p,tapScriptSig:y,tapLeafScript:l,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:S.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:d};e.inputs=_;const k={bip32Derivation:v.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:b.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:I.makeConverter(n.OutputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:E.makeConverter(n.OutputTypes.TAP_BIP32_DERIVATION),tapTree:w,tapInternalKey:S.makeConverter(n.OutputTypes.TAP_INTERNAL_KEY)};e.outputs=k},760:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);function o(t){return n.isBuffer(t)&&(64===t.length||65===t.length)}e.decode=function(t){if(t.key[0]!==i.InputTypes.TAP_KEY_SIG||1!==t.key.length)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+t.key.toString("hex"));if(!o(t.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.TAP_KEY_SIG]),value:t}},e.expected="Buffer",e.check=o,e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapKeySig}},795:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptWitness}},834:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const e=t.key.slice(1),r={masterFingerprint:t.value.slice(0,4),extendedPubkey:e,path:"m"};for(const e of(n=t.value.length/4-1,[...Array(n).keys()])){const n=t.value.readUInt32LE(4*e+4),i=!!(2147483648&n),o=2147483647&n;r.path+="/"+o.toString(10)+(i?"'":"")}var n;return r},e.encode=function(t){const e=n.from([i.GlobalTypes.GLOBAL_XPUB]),r=n.concat([e,t.extendedPubkey]),o=t.path.split("/"),u=n.allocUnsafe(4*o.length);t.masterFingerprint.copy(u,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),u.writeUInt32LE(r,a),a+=4})),{key:r,value:u}},e.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",e.check=function(t){const e=t.extendedPubkey,r=t.masterFingerprint,i=t.path;return n.isBuffer(e)&&78===e.length&&[2,3].indexOf(e[45])>-1&&n.isBuffer(r)&&4===r.length&&"string"==typeof i&&!!i.match(/^m(\/\d+'?)*$/)},e.canAddToArray=function(t,e,r){const n=e.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.extendedPubkey.equals(e.extendedPubkey))).length)}},851:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(394);e.decode=function(t){if(t.key[0]!==i.OutputTypes.TAP_TREE||1!==t.key.length)throw new Error("Decode Error: could not decode tapTree with key 0x"+t.key.toString("hex"));let e=0;const r=[];for(;e<t.value.length;){const n=t.value[e++],i=t.value[e++],u=o.decode(t.value,e);e+=o.encodingLength(u),r.push({depth:n,leafVersion:i,script:t.value.slice(e,e+u)}),e+=u}return{leaves:r}},e.encode=function(t){const e=n.from([i.OutputTypes.TAP_TREE]),r=[].concat(...t.leaves.map((t=>[n.of(t.depth,t.leafVersion),o.encode(t.script.length),t.script])));return{key:e,value:n.concat(r)}},e.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }",e.check=function(t){return Array.isArray(t.leaves)&&t.leaves.every((t=>t.depth>=0&&t.depth<=128&&(254&t.leafVersion)===t.leafVersion&&n.isBuffer(t.script)))},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.tapTree}},863:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=r(457);function i(t,e,r){return n=>{if(t.has(n))return;const i=r.filter((t=>t.key.toString("hex")===n))[0];e.push(i),t.add(n)}}function o(t){return t.globalMap.unsignedTx}function u(t){const e=new Set;return t.forEach((t=>{const r=t.key.toString("hex");if(e.has(r))throw new Error("Combine: KeyValue Map keys should be unique");e.add(r)})),e}e.combine=function(t){const e=t[0],r=n.psbtToKeyVals(e),a=t.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const s=o(e);if(void 0===s)throw new Error("Combine: Self missing transaction");const f=u(r.globalKeyVals),c=r.inputKeyVals.map(u),h=r.outputKeyVals.map(u);for(const t of a){const e=o(t);if(void 0===e||!e.toBuffer().equals(s.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const a=n.psbtToKeyVals(t);u(a.globalKeyVals).forEach(i(f,r.globalKeyVals,a.globalKeyVals)),a.inputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(c[e],r.inputKeyVals[e],a.inputKeyVals[e])))),a.outputKeyVals.map(u).forEach(((t,e)=>t.forEach(i(h[e],r.outputKeyVals[e],a.outputKeyVals[e]))))}return n.psbtFromKeyVals(s,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}},907:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+t.key.toString("hex"));if(34!==t.key.length&&66!==t.key.length||![2,3,4].includes(t.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+t.key.toString("hex"));return{pubkey:t.key.slice(1),signature:t.value}},e.encode=function(t){const e=n.from([i.InputTypes.PARTIAL_SIG]);return{key:n.concat([e,t.pubkey]),value:t.signature}},e.expected="{ pubkey: Buffer; signature: Buffer; }",e.check=function(t){return n.isBuffer(t.pubkey)&&n.isBuffer(t.signature)&&[33,65].includes(t.pubkey.length)&&[2,3,4].includes(t.pubkey[0])&&function(t){if(!n.isBuffer(t)||t.length<9)return!1;if(48!==t[0])return!1;if(t.length!==t[1]+3)return!1;if(2!==t[2])return!1;const e=t[3];if(e>33||e<1)return!1;if(2!==t[3+e+1])return!1;const r=t[3+e+2];return!(r>33||r<1)&&t.length===3+e+2+r+2}(t.signature)},e.canAddToArray=function(t,e,r){const n=e.pubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.pubkey.equals(e.pubkey))).length)}},926:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80),o=r(133),u=r(394);e.decode=function(t){if(t.key[0]!==i.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+t.key.toString("hex"));const e=o.readUInt64LE(t.value,0);let r=8;const n=u.decode(t.value,r);r+=u.encodingLength(n);const a=t.value.slice(r);if(a.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:a,value:e}},e.encode=function(t){const{script:e,value:r}=t,a=u.encodingLength(e.length),s=n.allocUnsafe(8+a+e.length);return o.writeUInt64LE(s,r,0),u.encode(e.length,s,8),e.copy(s,8+a),{key:n.from([i.InputTypes.WITNESS_UTXO]),value:s}},e.expected="{ script: Buffer; value: number; }",e.check=function(t){return n.isBuffer(t.script)&&"number"==typeof t.value},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.witnessUtxo}},949:(t,e,r)=>{var n=r(287).hp;Object.defineProperty(e,"__esModule",{value:!0});const i=r(80);e.decode=function(t){if(t.key[0]!==i.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+t.key.toString("hex"));return t.value.toString("utf8")},e.encode=function(t){return{key:n.from([i.InputTypes.POR_COMMITMENT]),value:n.from(t,"utf8")}},e.expected="string",e.check=function(t){return"string"==typeof t},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.porCommitment}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{bitcoin:()=>p,bitcoinCash:()=>m,bitcoinCashTestnet:()=>b,dash:()=>E,dashTestnet:()=>S,dogecoin:()=>y,dogecoinTestnet:()=>g,litecoin:()=>w,litecoinTestnet:()=>v,regtest:()=>l,testnet:()=>d});var i={};r.r(i),r.d(i,{decode:()=>tt,encode:()=>et});var o={};r.r(o),r.d(o,{decode:()=>xt,encode:()=>Bt});var u={};r.r(u),r.d(u,{compile:()=>Gt,countNonPushOnlyOPs:()=>Dt,decompile:()=>jt,fromASM:()=>Xt,isCanonicalPubKey:()=>Yt,isCanonicalScriptSignature:()=>$t,isDefinedHashType:()=>zt,isPushOnly:()=>Vt,number:()=>Jt,opcodes:()=>W,signature:()=>Qt,toASM:()=>Wt,toStack:()=>qt});var a={};r.r(a),r.d(a,{FUTURE_MAX_VERSION:()=>ie,FUTURE_OPNET_VERSION:()=>oe,FUTURE_SEGWIT_MAX_SIZE:()=>ee,FUTURE_SEGWIT_MAX_VERSION:()=>ne,FUTURE_SEGWIT_MIN_SIZE:()=>re,FUTURE_SEGWIT_MIN_VERSION:()=>ue,FUTURE_SEGWIT_VERSION_DIFF:()=>ae,_toFutureSegwitAddress:()=>he,fromBase58Check:()=>pe,fromBech32:()=>le,fromOutputScript:()=>ge,isUnknownSegwitVersion:()=>fe,toBase58Check:()=>de,toBech32:()=>ye,toFutureOPNetAddress:()=>ce,toOutputScript:()=>we});var s={};r.r(s),r.d(s,{TAGGED_HASH_PREFIXES:()=>We,TAGS:()=>je,hash160:()=>Fe,hash256:()=>Ge,ripemd160:()=>De,sha1:()=>Ke,sha256:()=>Me,taggedHash:()=>Xe});var f={};r.r(f),r.d(f,{decode:()=>ir,encode:()=>nr,encodingLength:()=>or});var c={};r.r(c),r.d(c,{Transaction:()=>ei});var h={};r.r(h),r.d(h,{LEAF_VERSION_TAPSCRIPT:()=>Sr,MAX_TAPTREE_DEPTH:()=>Ir,PaymentType:()=>Yi,findScriptPath:()=>Ar,p2data:()=>Rr,p2ms:()=>Vr,p2op:()=>Ai,p2pk:()=>Kr,p2pkh:()=>Ji,p2sh:()=>On,p2tr:()=>xn,p2wpkh:()=>Hn,p2wsh:()=>Mn,prop:()=>xr,rootHashFromPath:()=>_r,tapTweakHash:()=>Pr,tapleafHash:()=>Or,toHashTree:()=>kr,tweakKey:()=>Ur,value:()=>Br});var p={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bech32Opnet:"op",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},l={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bech32Opnet:"opr",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},d={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bech32Opnet:"opt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},y={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:49990397,private:49988504},pubKeyHash:30,scriptHash:22,wif:158},g={messagePrefix:"Dogecoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:70429096,private:70427203},pubKeyHash:113,scriptHash:196,wif:241},w={messagePrefix:"Litecoin Signed Message:\n",bech32:"ltc",bech32Opnet:"opl",bip32:{public:27108450,private:27106558},pubKeyHash:48,scriptHash:50,wif:176},v={messagePrefix:"Litecoin Signed Message:\n",bech32:"tltc",bech32Opnet:"oplt",bip32:{public:70709117,private:70711009},pubKeyHash:111,scriptHash:58,wif:239},m={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bitcoincash",bech32Opnet:"opbch",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},b={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bchtest",bech32Opnet:"opbcht",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},E={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:50221772,private:50221816},pubKeyHash:76,scriptHash:16,wif:204},S={messagePrefix:"DarkCoin Signed Message:\n",bech32:"",bech32Opnet:"",bip32:{public:981492128,private:981489719},pubKeyHash:140,scriptHash:19,wif:239},I=r(343);function T(t,...e){if(!((r=t)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function _(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function k(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function A(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function O(t,e){return t<<32-e|t>>>e}function P(t,e){return t<<e|t>>>32-e>>>0}function U(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),T(t),t}class N{}function x(t){const e=e=>t().update(U(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function B(t,e,r){return t&e^~t&r}function C(t,e,r){return t&e^t&r^e&r}class R extends N{constructor(t,e,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(t),this.view=A(this.buffer)}update(t){_(this),T(t=U(t));const{view:e,buffer:r,blockLen:n}=this,i=t.length;for(let o=0;o<i;){const u=Math.min(n-this.pos,i-o);if(u!==n)r.set(t.subarray(o,o+u),this.pos),this.pos+=u,o+=u,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=A(t);for(;n<=i-o;o+=n)this.process(e,o)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){_(this),function(t,e){T(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;e[o++]=128,k(this.buffer.subarray(o)),this.padOffset>n-o&&(this.process(r,0),o=0);for(let t=o;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),u=Number(r>>i&o),a=Number(r&o),s=n?4:0,f=n?0:4;t.setUint32(e+s,u,n),t.setUint32(e+f,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const u=A(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const s=a/4,f=this.get();if(s>f.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<s;t++)u.setUint32(4*t,f[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:u}=this;return t.destroyed=o,t.finished=i,t.length=n,t.pos=u,n%e&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const H=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),L=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),V=new Uint32Array(64);class D extends R{constructor(t=32){super(64,t,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)V[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=V[t-15],r=V[t-2],n=O(e,7)^O(e,18)^e>>>3,i=O(r,17)^O(r,19)^r>>>10;V[t]=i+V[t-7]+n+V[t-16]|0}let{A:r,B:n,C:i,D:o,E:u,F:a,G:s,H:f}=this;for(let t=0;t<64;t++){const e=f+(O(u,6)^O(u,11)^O(u,25))+B(u,a,s)+L[t]+V[t]|0,c=(O(r,2)^O(r,13)^O(r,22))+C(r,n,i)|0;f=s,s=a,a=u,u=o+e|0,o=i,i=n,n=r,r=e+c|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,a=a+this.F|0,s=s+this.G|0,f=f+this.H|0,this.set(r,n,i,o,u,a,s,f)}roundClean(){k(V)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}const K=x((()=>new D)),M=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let t=0;t<e.length;t++)e[t]=255;for(let r=0;r<t.length;r++){const n=t.charAt(r),i=n.charCodeAt(0);if(255!==e[i])throw new TypeError(n+" is ambiguous");e[i]=r}const r=t.length,n=t.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function u(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;let o=0,u=0,a=0;for(;t[o]===n;)u++,o++;const s=(t.length-o)*i+1>>>0,f=new Uint8Array(s);for(;t[o];){let n=e[t.charCodeAt(o)];if(255===n)return;let i=0;for(let t=s-1;(0!==n||i<a)&&-1!==t;t--,i++)n+=r*f[t]>>>0,f[t]=n%256>>>0,n=n/256>>>0;if(0!==n)throw new Error("Non-zero carry");a=i,o++}let c=s-a;for(;c!==s&&0===f[c];)c++;const h=new Uint8Array(u+(s-c));let p=u;for(;c!==s;)h[p++]=f[c++];return h}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";let i=0,u=0,a=0;const s=e.length;for(;a!==s&&0===e[a];)a++,i++;const f=(s-a)*o+1>>>0,c=new Uint8Array(f);for(;a!==s;){let t=e[a],n=0;for(let e=f-1;(0!==t||n<u)&&-1!==e;e--,n++)t+=256*c[e]>>>0,c[e]=t%r>>>0,t=t/r>>>0;if(0!==t)throw new Error("Non-zero carry");u=n,a++}let h=f-u;for(;h!==f&&0===c[h];)h++;let p=n.repeat(i);for(;h<f;++h)p+=t.charAt(c[h]);return p},decodeUnsafe:u,decode:function(t){const e=u(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),F=function(t){function e(e){var r=e.slice(0,-4),n=e.slice(-4),i=t(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(e){var r=Uint8Array.from(e),n=t(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),M.encode(o)},decode:function(t){var r=e(M.decode(t));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(t){var r=M.decodeUnsafe(t);if(null!=r)return e(r)}}}((function(t){return K(K(t))}));var G=r(287).hp;function j(t,e){var r=t.length,n=e.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&t[0])throw new Error("R value is negative");if(128&e[0])throw new Error("S value is negative");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("R value excessively padded");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("S value excessively padded");var i=G.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=t.length,t.copy(i,4),i[4+r]=2,i[5+r]=e.length,e.copy(i,6+r),i}for(var W={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},X={},q=0,Y=Object.keys(W);q<Y.length;q++){var z=Y[q],$=W[z];X[$]=z}function J(t){return t<W.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function Q(t,e){var r,n,i=t.readUInt8(e);if(i<W.OP_PUSHDATA1)r=i,n=1;else if(i===W.OP_PUSHDATA1){if(e+2>t.length)return null;r=t.readUInt8(e+1),n=2}else if(i===W.OP_PUSHDATA2){if(e+3>t.length)return null;r=t.readUInt16LE(e+1),n=3}else{if(e+5>t.length)return null;if(i!==W.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=t.readUInt32LE(e+1),n=5}return{opcode:i,number:r,size:n}}var Z=r(287).hp;function tt(t,e,r){e=e||4,r=void 0===r||r;var n=t.length;if(0===n)return 0;if(n>e)throw new TypeError("Script number overflow");if(r&&!(127&t[n-1]||!(n<=1)&&128&t[n-2]))throw new Error("Non-minimally encoded script number");if(5===n){var i=t.readUInt32LE(0),o=t.readUInt8(4);return 128&o?-(4294967296*(-129&o)+i):4294967296*o+i}for(var u=0,a=0;a<n;++a)u|=t[a]<<8*a;return 128&t[n-1]?-(u&~(128<<8*(n-1))):u}function et(t){for(var e=Math.abs(t),r=function(t){return t>2147483647?5:t>8388607?4:t>32767?3:t>127?2:t>0?1:0}(e),n=Z.allocUnsafe(r),i=t<0,o=0;o<r;++o)n.writeUInt8(255&e,o),e>>=8;return 128&n[r-1]?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}var rt=r(287),nt=r(676),it=r.n(nt)(),ot=rt.hp.alloc(32,0),ut=rt.hp.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function at(t,e){return t.length===e.length&&t.every((function(t,r){return t.equals(e[r])}))}function st(t){if(!rt.hp.isBuffer(t))return!1;if(t.length<33)return!1;var e=t[0],r=t.slice(1,33);if(0===r.compare(ot))return!1;if(r.compare(ut)>=0)return!1;if((2===e||3===e)&&33===t.length)return!0;if(65!==t.length)return!1;var n=t.slice(33);return!(0===n.compare(ot)||n.compare(ut)>=0||4!==e&&6!==e&&7!==e)}function ft(t){return it.UInt53(t)&&t<=21e14}var ct=254;function ht(t){return!(!t||!("output"in t)||!rt.hp.isBuffer(t.output)||void 0!==t.version&&(t.version&ct)!==t.version)}function pt(t){return gt(t)?2===t.length&&t.every((function(t){return pt(t)})):ht(t)}it.BufferN(32);var lt=it.BufferN(20),dt=it.BufferN(32),yt=it.Number,gt=it.Array,wt=(it.Boolean,it.String),vt=it.Buffer,mt=it.Hex,bt=it.maybe,Et=it.tuple,St=it.UInt8,It=it.UInt32,Tt=it.Function,_t=it.BufferN,kt=it.Null,At=(it.oneOf,r(287).hp),Ot=it,Pt=At.alloc(1,0);function Ut(t){for(var e=0;0===t[e];)++e;return e===t.length?Pt:128&(t=t.slice(e))[0]?At.concat([Pt,t],1+t.length):t}function Nt(t){0===t[0]&&(t=t.slice(1));var e=At.alloc(32,0),r=Math.max(0,32-t.length);return t.copy(e,r),e}function xt(t){var e=t.readUInt8(t.length-1);if(!zt(e))throw new Error("Invalid hashType "+e);var r=function(t){if(t.length<8)throw new Error("DER sequence length is too short");if(t.length>72)throw new Error("DER sequence length is too long");if(48!==t[0])throw new Error("Expected DER sequence");if(t[1]!==t.length-2)throw new Error("DER sequence length is invalid");if(2!==t[2])throw new Error("Expected DER integer");var e=t[3];if(0===e)throw new Error("R length is zero");if(5+e>=t.length)throw new Error("R length is too long");if(2!==t[4+e])throw new Error("Expected DER integer (2)");var r=t[5+e];if(0===r)throw new Error("S length is zero");if(6+e+r!==t.length)throw new Error("S length is invalid");if(128&t[4])throw new Error("R value is negative");if(e>1&&0===t[4]&&!(128&t[5]))throw new Error("R value excessively padded");if(128&t[e+6])throw new Error("S value is negative");if(r>1&&0===t[e+6]&&!(128&t[e+7]))throw new Error("S value excessively padded");return{r:t.slice(4,4+e),s:t.slice(6+e)}}(t.slice(0,-1)),n=Nt(r.r),i=Nt(r.s);return{signature:At.concat([n,i],64),hashType:e}}function Bt(t,e){if(Ot({signature:_t(64),hashType:St},{signature:t,hashType:e}),!zt(e))throw new Error("Invalid hashType "+e);var r=At.allocUnsafe(1);r.writeUInt8(e,0);var n=Ut(t.slice(0,32)),i=Ut(t.slice(32,64));return At.concat([j(n,i),r])}var Ct=r(287).hp,Rt=it,Ht=W.OP_RESERVED;function Lt(t){return vt(t)||function(t){return yt(t)&&(t===W.OP_0||t>=W.OP_1&&t<=W.OP_16||t===W.OP_1NEGATE)}(t)}function Vt(t){return gt(t)&&t.every(Lt)}function Dt(t){return t.length-t.filter(Lt).length}function Kt(t){return 0===t.length?W.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Ht+t[0]:129===t[0]?W.OP_1NEGATE:void 0:void 0}function Mt(t){return Ct.isBuffer(t)}function Ft(t){return Ct.isBuffer(t)}function Gt(t){if(Mt(t))return t;Rt(gt,t);var e=t.reduce((function(t,e){return Ft(e)?1===e.length&&void 0!==Kt(e)?t+1:t+J(e.length)+e.length:t+1}),0),r=Ct.allocUnsafe(e),n=0;if(t.forEach((function(t){if(Ft(t)){var e=Kt(t);if(void 0!==e)return r.writeUInt8(e,n),void(n+=1);n+=function(t,e,r){var n=J(e);return 1===n?t.writeUInt8(e,r):2===n?(t.writeUInt8(W.OP_PUSHDATA1,r),t.writeUInt8(e,r+1)):3===n?(t.writeUInt8(W.OP_PUSHDATA2,r),t.writeUInt16LE(e,r+1)):(t.writeUInt8(W.OP_PUSHDATA4,r),t.writeUInt32LE(e,r+1)),n}(r,t.length,n),t.copy(r,n),n+=t.length}else r.writeUInt8(t,n),n+=1})),n!==r.length)throw new Error("Could not decode chunks");return r}function jt(t){if(gt(t))return t;Rt(vt,t);for(var e=[],r=0;r<t.length;){var n=t[r];if(n>W.OP_0&&n<=W.OP_PUSHDATA4){var i=Q(t,r);if(null===i)return null;if((r+=i.size)+i.number>t.length)return null;var o=t.slice(r,r+i.number);r+=i.number;var u=Kt(o);void 0!==u?e.push(u):e.push(o)}else e.push(n),r+=1}return e}function Wt(t){if(Mt(t)&&(t=jt(t)),!t)throw new Error("Could not convert invalid chunks to ASM");return t.map((function(t){if(Ft(t)){var e=Kt(t);if(void 0===e)return t.toString("hex");t=e}return X[t]})).join(" ")}function Xt(t){return Rt(wt,t),Gt(t.split(" ").map((function(t){return void 0!==W[t]?W[t]:(Rt(mt,t),Ct.from(t,"hex"))})))}function qt(t){return t=jt(t),Rt(Vt,t),t.map((function(t){return Ft(t)?t:t===W.OP_0?Ct.allocUnsafe(0):et(t-Ht)}))}function Yt(t){return st(t)}function zt(t){var e=-129&t;return e>0&&e<4}function $t(t){return!!Ct.isBuffer(t)&&!!zt(t[t.length-1])&&function(t){if(t.length<8)return!1;if(t.length>72)return!1;if(48!==t[0])return!1;if(t[1]!==t.length-2)return!1;if(2!==t[2])return!1;var e=t[3];if(0===e)return!1;if(5+e>=t.length)return!1;if(2!==t[4+e])return!1;var r=t[5+e];return!(0===r||6+e+r!==t.length||128&t[4]||e>1&&0===t[4]&&!(128&t[5])||128&t[e+6]||r>1&&0===t[e+6]&&!(128&t[e+7]))}(t.slice(0,-1))}var Jt=i,Qt=o,Zt=r(287).hp;function te(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ee=40,re=2,ne=15,ie=16,oe=16,ue=2,ae=80,se="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.",fe=function(t){try{var e=Zt.from(t.subarray(2));if(e.length<re||e.length>ee)throw new TypeError("Invalid program length for segwit address");var r=t[0]-ae;if(r<ue||r>ne+1)throw new TypeError("Invalid version for segwit address");if(1===r)throw new TypeError("taproot");return!0}catch(t){}return!1};function ce(t,e){if(!Zt.isBuffer(t))throw new TypeError("output must be a Buffer");if(!e.bech32Opnet)throw new Error("Network does not support opnet");var r,n=t[0],i=1;if(t[1]<76)r=t[1],i=2;else{if(76!==t[1])throw new TypeError("Unsupported push opcode in script");r=t[2],i=3}var o=Zt.from(t.subarray(i,i+r));if(o.length<re||o.length>ee)throw new TypeError("Invalid program length for segwit address");var u=n===W.OP_0?0:n>=W.OP_1&&n<=W.OP_16?n-(W.OP_1-1):-1;if(u<ne||u>ie)throw new TypeError("Invalid segwit version ".concat(u));var a,s=[u].concat(function(t){if(Array.isArray(t))return te(t)}(a=I.p2.toWords(o))||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(a)||function(t,e){if(t){if("string"==typeof t)return te(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?te(t,e):void 0}}(a)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());return I.p2.encode(e.bech32Opnet,s)}function he(t,e){var r=Zt.from(t.subarray(2));if(r.length<re||r.length>ee)throw new TypeError("Invalid program length for segwit address");var n=t[0]-ae;if(n<ue||n>ne)throw new TypeError("Invalid version for segwit address");if(t[1]!==r.length)throw new TypeError("Invalid script for segwit address ".concat(t[1]," !== ").concat(r.length));return ye(r,n,e.bech32,e.bech32Opnet)}function pe(t){var e=Zt.from(F.decode(t));if(e.length<21)throw new TypeError(t+" is too short");if(e.length>21)throw new TypeError(t+" is too long");return{version:e.readUInt8(0),hash:Zt.from(e.subarray(1))}}function le(t){var e,r;try{e=I.I.decode(t)}catch(t){}if(e){if(0!==(r=e.words[0]))throw new TypeError(t+" uses wrong encoding")}else if(0===(r=(e=I.p2.decode(t)).words[0]))throw new TypeError(t+" uses wrong encoding");var n=I.I.fromWords(e.words.slice(1));return{version:r,prefix:e.prefix,data:Zt.from(n)}}function de(t,e){it(Et(lt,St),arguments);var r=Zt.allocUnsafe(21);return r.writeUInt8(e,0),t.copy(r,1),F.encode(r)}function ye(t,e,r,n){var i=I.I.toWords(t);return i.unshift(e),e===oe&&n?I.p2.encode(n,i):0===e?I.I.encode(r,i):I.p2.encode(r,i)}function ge(t,e){e=e||p;try{return Ji({output:t,network:e}).address}catch(t){}try{return On({output:t,network:e}).address}catch(t){}try{return Hn({output:t,network:e}).address}catch(t){}try{return Mn({output:t,network:e}).address}catch(t){}try{return xn({output:t,network:e}).address}catch(t){}try{return ce(t,e)}catch(t){}try{return he(t,e)}catch(t){}throw new Error(Wt(t)+" has no matching Address")}function we(t,e){var r,n;e=e||p;try{r=pe(t)}catch(t){}if(r){if(r.version===e.pubKeyHash)return Ji({hash:r.hash}).output;if(r.version===e.scriptHash)return On({hash:r.hash}).output}else{try{n=le(t)}catch(t){}if(n){if(n.prefix!==e.bech32&&e.bech32Opnet&&n.prefix!==e.bech32Opnet)throw new Error(t+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return Hn({hash:n.data}).output;if(32===n.data.length)return Mn({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return xn({pubkey:n.data}).output}else{if(n.version===oe){if(!e.bech32Opnet)throw new Error(t+" has an invalid prefix");return Ai({program:n.data,network:e}).output}if(n.version>=ue&&n.version<=ne&&n.data.length>=re&&n.data.length<=ee)return n.version!==oe&&console.warn(se),Gt([n.version+ae,n.data])}}}return Zt.from(t,"hex")}const ve=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),me=new Uint32Array(80);class be extends R{constructor(){super(64,20,8,!1),this.A=0|ve[0],this.B=0|ve[1],this.C=0|ve[2],this.D=0|ve[3],this.E=0|ve[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)me[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)me[t]=P(me[t-3]^me[t-8]^me[t-14]^me[t-16],1);let{A:r,B:n,C:i,D:o,E:u}=this;for(let t=0;t<80;t++){let e,a;t<20?(e=B(n,i,o),a=1518500249):t<40?(e=n^i^o,a=1859775393):t<60?(e=C(n,i,o),a=2400959708):(e=n^i^o,a=3395469782);const s=P(r,5)+e+u+a+me[t]|0;u=o,o=i,i=P(n,30),n=r,r=s}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,u=u+this.E|0,this.set(r,n,i,o,u)}roundClean(){k(me)}destroy(){this.set(0,0,0,0,0),k(this.buffer)}}const Ee=x((()=>new be)),Se=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ie=(()=>Uint8Array.from(new Array(16).fill(0).map(((t,e)=>e))))(),Te=(()=>Ie.map((t=>(9*t+5)%16)))(),_e=(()=>{const t=[[Ie],[Te]];for(let e=0;e<4;e++)for(let r of t)r.push(r[e].map((t=>Se[t])));return t})(),ke=(()=>_e[0])(),Ae=(()=>_e[1])(),Oe=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((t=>Uint8Array.from(t))),Pe=ke.map(((t,e)=>t.map((t=>Oe[e][t])))),Ue=Ae.map(((t,e)=>t.map((t=>Oe[e][t])))),Ne=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),xe=Uint32Array.from([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 Ce=new Uint32Array(16);class Re extends R{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)Ce[r]=t.getUint32(e,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,u=0|this.h2,a=u,s=0|this.h3,f=s,c=0|this.h4,h=c;for(let t=0;t<5;t++){const e=4-t,p=Ne[t],l=xe[t],d=ke[t],y=Ae[t],g=Pe[t],w=Ue[t];for(let e=0;e<16;e++){const n=P(r+Be(t,i,u,s)+Ce[d[e]]+p,g[e])+c|0;r=c,c=s,s=0|P(u,10),u=i,i=n}for(let t=0;t<16;t++){const r=P(n+Be(e,o,a,f)+Ce[y[t]]+l,w[t])+h|0;n=h,h=f,f=0|P(a,10),a=o,o=r}}this.set(this.h1+u+f|0,this.h2+s+h|0,this.h3+c+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){k(Ce)}destroy(){this.destroyed=!0,k(this.buffer),this.set(0,0,0,0,0)}}const He=x((()=>new Re)),Le=Ee;var Ve=r(287).hp;function De(t){return Ve.from(He(Uint8Array.from(t)))}function Ke(t){return Ve.from(Le(Uint8Array.from(t)))}function Me(t){return Ve.from(K(Uint8Array.from(t)))}function Fe(t){return Ve.from(He(K(Uint8Array.from(t))))}function Ge(t){return Ve.from(K(K(Uint8Array.from(t))))}var je=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],We={"BIP0340/challenge":Ve.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":Ve.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":Ve.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:Ve.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:Ve.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:Ve.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:Ve.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":Ve.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":Ve.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 Xe(t,e){return Me(Ve.concat([We[t],e]))}var qe=r(287).hp,Ye={};function ze(t){var e;t?t!==Ye.eccLib&&(Qe("function"==typeof(e=t).isXOnlyPoint),Qe(e.isXOnlyPoint(Je("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Qe(e.isXOnlyPoint(Je("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Qe(e.isXOnlyPoint(Je("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Qe(e.isXOnlyPoint(Je("0000000000000000000000000000000000000000000000000000000000000001"))),Qe(!e.isXOnlyPoint(Je("0000000000000000000000000000000000000000000000000000000000000000"))),Qe(!e.isXOnlyPoint(Je("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Qe("function"==typeof e.xOnlyPointAddTweak),Ze.forEach((function(t){var r=e.xOnlyPointAddTweak(Je(t.pubkey),Je(t.tweak));null===t.result?Qe(null===r):(Qe(null!==r),Qe(r.parity===t.parity),Qe(qe.from(r.xOnlyPubkey).equals(Je(t.result))))})),Ye.eccLib=t):Ye.eccLib=t}function $e(){if(!Ye.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Ye.eccLib}var Je=function(t){return qe.from(t,"hex")};function Qe(t){if(!t)throw new Error("ecc library invalid")}var Ze=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];const tr="0123456789abcdefABCDEF";tr.split("").map((t=>t.codePointAt(0))),Array(256).fill(!0).map(((t,e)=>{const r=String.fromCodePoint(e),n=tr.indexOf(r);return n<0?void 0:n<16?n:n-6})),new TextEncoder,new TextDecoder;const er=t=>{if(t<0||t>0xffffffffffffffffn)throw new RangeError("value out of range")};function rr(t){"number"==typeof t?function(t){if(t<0||t>Number.MAX_SAFE_INTEGER||t%1!=0)throw new RangeError("value out of range")}(t):er(t)}function nr(t,e,r){rr(t),void 0===r&&(r=0),void 0===e&&(e=new Uint8Array(or(t)));let n=0;return t<253?(e.set([Number(t)],r),n=1):t<=65535?(e.set([253],r),function(t,e,r,n){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255):(t[e]=r>>8&255,t[e+1]=255&r)}(e,r+1,Number(t),"LE"),n=3):t<=4294967295?(e.set([254],r),function(t,e,r,n){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255):(t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r)}(e,r+1,Number(t),"LE"),n=5):(e.set([255],r),function(t,e,r,n){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 18446744073709551615. Received ${r}`);"LE"===n?(t[e]=Number(0xffn&r),t[e+1]=Number(r>>8n&0xffn),t[e+2]=Number(r>>16n&0xffn),t[e+3]=Number(r>>24n&0xffn),t[e+4]=Number(r>>32n&0xffn),t[e+5]=Number(r>>40n&0xffn),t[e+6]=Number(r>>48n&0xffn),t[e+7]=Number(r>>56n&0xffn)):(t[e]=Number(r>>56n&0xffn),t[e+1]=Number(r>>48n&0xffn),t[e+2]=Number(r>>40n&0xffn),t[e+3]=Number(r>>32n&0xffn),t[e+4]=Number(r>>24n&0xffn),t[e+5]=Number(r>>16n&0xffn),t[e+6]=Number(r>>8n&0xffn),t[e+7]=Number(0xffn&r))}(e,r+1,BigInt(t),"LE"),n=9),{buffer:e,bytes:n}}function ir(t,e){void 0===e&&(e=0);const r=t.at(e);if(void 0===r)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(253===r){const r=function(t,e,r){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+1],r=(r<<8)+t[e],r}{let r=0;return r=(r<<8)+t[e],r=(r<<8)+t[e+1],r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}if(254===r){const r=function(t,e,r){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+3]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e]>>>0,r}{let r=0;return r=(r<<8)+t[e]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+3]>>>0,r}}(t,e+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}{const r=function(t,e,r){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0n;return r=(r<<8n)+BigInt(t[e+7]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e]),r}{let r=0n;return r=(r<<8n)+BigInt(t[e]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+7]),r}}(t,e+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function or(t){return rr(t),t<253?1:t<=65535?3:t<=4294967295?5:9}var ur=r(287).hp;function ar(t){return ar="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},ar(t)}function sr(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function fr(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,hr(n.key),n)}}function cr(t,e,r){return e&&fr(t.prototype,e),r&&fr(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function hr(t){var e=function(t){if("object"!=ar(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=ar(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ar(e)?e:e+""}var pr=it;function lr(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 dr(t,e){var r=t.readUInt32LE(e),n=t.readUInt32LE(e+4);return lr((n*=4294967296)+r,9007199254740991),n+r}function yr(t,e,r){return lr(e,9007199254740991),t.writeInt32LE(-1&e,r),t.writeUInt32LE(Math.floor(e/4294967296),r+4),r+8}function gr(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 wr(t){var e=ur.allocUnsafe(t.length);return t.copy(e),e}var vr=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;sr(this,t),this.buffer=e,this.offset=r,pr(Et(vt,It),[e,r])}return cr(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=yr(this.buffer,t,this.offset)}},{key:"writeVarInt",value:function(t){var e=nr(t,this.buffer,this.offset);this.offset+=e.bytes}},{key:"writeSlice",value:function(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}},{key:"writeVarSlice",value:function(t){this.writeVarInt(t.length),this.writeSlice(t)}},{key:"writeVector",value:function(t){var e=this;this.writeVarInt(t.length),t.forEach((function(t){return e.writeVarSlice(t)}))}},{key:"end",value:function(){if(this.buffer.length===this.offset)return this.buffer;throw new Error("buffer size ".concat(this.buffer.length,", offset ").concat(this.offset))}}],[{key:"withCapacity",value:function(e){return new t(ur.alloc(e))}}])}(),mr=function(){return cr((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;sr(this,t),this.buffer=e,this.offset=r,pr(Et(vt,It),[e,r])}),[{key:"readUInt8",value:function(){var t=this.buffer.readUInt8(this.offset);return this.offset++,t}},{key:"readInt32",value:function(){var t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt32",value:function(){var t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}},{key:"readUInt64",value:function(){var t=dr(this.buffer,this.offset);return this.offset+=8,t}},{key:"readVarInt",value:function(){var t=ir(this.buffer,this.offset);return this.offset+=t.bytes,t.numberValue||0}},{key:"readSlice",value:function(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");var e=ur.from(this.buffer.subarray(this.offset,this.offset+t));return this.offset+=t,e}},{key:"readVarSlice",value:function(){return this.readSlice(this.readVarInt())}},{key:"readVector",value:function(){for(var t=this.readVarInt(),e=[],r=0;r<t;r++)e.push(this.readVarSlice());return e}}])}();function br(t){return function(t){if(Array.isArray(t))return Er(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 Er(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)?Er(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 Er(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 Sr=192,Ir=128,Tr=function(t){return"left"in t&&"right"in t};function _r(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?Nr(n,o):Nr(o,n)}return n}function kr(t){if(ht(t))return{hash:Or(t)};var e=[kr(t[0]),kr(t[1])];e.sort((function(t,e){return t.hash.compare(e.hash)}));var r=e[0],n=e[1];return{hash:Nr(r.hash,n.hash),left:r,right:n}}function Ar(t,e){if(Tr(t)){var r=Ar(t.left,e);if(void 0!==r)return[].concat(br(r),[t.right.hash]);var n=Ar(t.right,e);if(void 0!==n)return[].concat(br(n),[t.left.hash])}else if(t.hash.equals(e))return[]}function Or(t){var e,r,n,i=t.version||Sr;return Xe("TapLeaf",rt.hp.concat([rt.hp.from([i]),(e=t.output,r=or(e.length),n=rt.hp.allocUnsafe(r),nr(e.length,n),rt.hp.concat([n,e]))]))}function Pr(t,e){return Xe("TapTweak",rt.hp.concat(e?[t,e]:[t]))}function Ur(t,e){if(!rt.hp.isBuffer(t))return null;if(32!==t.length)return null;if(e&&32!==e.length)return null;var r=Pr(t,e),n=$e().xOnlyPointAddTweak(t,r);return n&&null!==n.xOnlyPubkey?{parity:n.parity,x:rt.hp.from(n.xOnlyPubkey)}:null}function Nr(t,e){return Xe("TapBranch",rt.hp.concat([t,e]))}function xr(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 Br(t){var e;return function(){return void 0!==e?e:e=t()}}var Cr=W;function Rr(t,e){if(!t.data&&!t.output)throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),data:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network||p,n={name:Yi.Embed,network:r,data:[]};if(xr(n,"output",(function(){if(t.data)return Gt([Cr.OP_RETURN].concat(t.data))})),xr(n,"data",(function(){if(t.output){var e=jt(t.output);if(null!=e)return e.slice(1)}})),e.validate&&t.output){var i=jt(t.output);if(i[0]!==Cr.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(it.Buffer))throw new TypeError("Output is invalid");if(t.data&&!at(t.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,t)}var Hr=W,Lr=Hr.OP_RESERVED;function Vr(t,e){if(!(t.input||t.output||t.pubkeys&&void 0!==t.m||t.signatures))throw new TypeError("Not enough data");function r(t){return $t(t)||void 0!==(e.allowIncomplete&&t===Hr.OP_0)}e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),m:it.maybe(it.Number),n:it.maybe(it.Number),output:it.maybe(it.Buffer),pubkeys:it.maybe(it.arrayOf(st)),signatures:it.maybe(it.arrayOf(r)),input:it.maybe(it.Buffer)},t);var n={network:t.network||p,name:Yi.P2MS},i=[],o=!1;function u(t){o||(o=!0,i=jt(t),n.m=i[0]-Lr,n.n=i[i.length-2]-Lr,n.pubkeys=i.slice(1,-2))}if(xr(n,"output",(function(){if(t.m&&n.n&&t.pubkeys)return Gt([].concat(Lr+t.m,t.pubkeys,Lr+n.n,Hr.OP_CHECKMULTISIG))})),xr(n,"m",(function(){if(n.output)return u(n.output),n.m})),xr(n,"n",(function(){if(n.pubkeys)return n.pubkeys.length})),xr(n,"pubkeys",(function(){if(t.output)return u(t.output),n.pubkeys})),xr(n,"signatures",(function(){if(t.input){var e=jt(t.input);if(null!=e)return e.slice(1)}})),xr(n,"input",(function(){if(t.signatures)return Gt([Hr.OP_0].concat(t.signatures))})),xr(n,"witness",(function(){if(n.input)return[]})),xr(n,"name",(function(){if(n.m&&n.n)return"p2ms(".concat(n.m," of ").concat(n.n,")")})),e.validate){if(t.output){if(u(t.output),!it.Number(i[0]))throw new TypeError("Output is invalid");if(!it.Number(i[i.length-2]))throw new TypeError("Output is invalid");if(i[i.length-1]!==Hr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every((function(t){return st(t)})))throw new TypeError("Output is invalid");if(void 0!==t.m&&t.m!==n.m)throw new TypeError("m mismatch");if(void 0!==t.n&&t.n!==n.n)throw new TypeError("n mismatch");if(t.pubkeys&&!at(t.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(t.pubkeys){if(void 0!==t.n&&t.n!==t.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=t.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(t.signatures){if(t.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(t.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(t.input){if(t.input[0]!==Hr.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(t.signatures&&!at(t.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==t.m&&t.m!==t.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,t)}var Dr=W;function Kr(t,e){if(!(t.input||t.output||t.pubkey||t.input||t.signature))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),output:it.maybe(it.Buffer),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Br((function(){return jt(t.input)})),n=t.network||p,i={name:Yi.P2PK,network:n,pubkey:void 0};if(xr(i,"output",(function(){if(t.pubkey)return Gt([t.pubkey,Dr.OP_CHECKSIG])})),xr(i,"pubkey",(function(){if(t.output)return t.output.slice(1,-1)})),xr(i,"signature",(function(){if(t.input)return r()[0]})),xr(i,"input",(function(){if(t.signature)return Gt([t.signature])})),xr(i,"witness",(function(){if(i.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Dr.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!st(i.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&!t.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&!t.input.equals(i.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!$t(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,t)}const Mr=2n**256n,Fr=Mr-0x1000003d1n,Gr=Mr-0x14551231950b75fc4402da1732fc9bebfn,jr=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Wr=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,Xr={p:Fr,n:Gr,a:0n,b:7n,Gx:jr,Gy:Wr},qr=t=>rn(rn(t*t)*t+Xr.b),Yr=(t="")=>{throw new Error(t)},zr=t=>"bigint"==typeof t,$r=t=>"string"==typeof t,Jr=t=>zr(t)&&0n<t&&t<Fr,Qr=t=>zr(t)&&0n<t&&t<Gr,Zr=(t,e)=>!(t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?Yr("Uint8Array expected"):t,tn=t=>new Uint8Array(t),en=(t,e)=>Zr($r(t)?hn(t):tn(Zr(t)),e),rn=(t,e=Fr)=>{const r=t%e;return r>=0n?r:e+r},nn=t=>t instanceof on?t:Yr("Point expected");class on{constructor(t,e,r){this.px=t,this.py=e,this.pz=r,Object.freeze(this)}static fromAffine(t){return 0n===t.x&&0n===t.y?an:new on(t.x,t.y,1n)}static fromHex(t){let e;const r=(t=en(t))[0],n=t.subarray(1),i=ln(n,0,32),o=t.length;if(33===o&&[2,3].includes(r)){Jr(i)||Yr("Point hex invalid: x not FE");let t=vn(qr(i));!(1&~r)!=(1n===(1n&t))&&(t=rn(-t)),e=new on(i,t,1n)}return 65===o&&4===r&&(e=new on(i,ln(n,32,64),1n)),e?e.ok():Yr("Point invalid: not on curve")}static fromPrivateKey(t){return un.mul(mn(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}=nn(t),a=rn(e*u),s=rn(i*n),f=rn(r*u),c=rn(o*n);return a===s&&f===c}negate(){return new on(this.px,rn(-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}=nn(t),{a,b:s}=Xr;let f=0n,c=0n,h=0n;const p=rn(3n*s);let l=rn(e*i),d=rn(r*o),y=rn(n*u),g=rn(e+r),w=rn(i+o);g=rn(g*w),w=rn(l+d),g=rn(g-w),w=rn(e+n);let v=rn(i+u);return w=rn(w*v),v=rn(l+y),w=rn(w-v),v=rn(r+n),f=rn(o+u),v=rn(v*f),f=rn(d+y),v=rn(v-f),h=rn(a*w),f=rn(p*y),h=rn(f+h),f=rn(d-h),h=rn(d+h),c=rn(f*h),d=rn(l+l),d=rn(d+l),y=rn(a*y),w=rn(p*w),d=rn(d+y),y=rn(l-y),y=rn(a*y),w=rn(w+y),l=rn(d*w),c=rn(c+l),l=rn(v*w),f=rn(g*f),f=rn(f-l),l=rn(g*d),h=rn(v*h),h=rn(h+l),new on(f,c,h)}mul(t,e=!0){if(!e&&0n===t)return an;if(Qr(t)||Yr("scalar invalid"),this.equals(un))return Tn(t).p;let r=an,n=un;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(an))return{x:0n,y:0n};if(1n===r)return{x:t,y:e};const n=wn(r,Fr);return 1n!==rn(r*n)&&Yr("inverse invalid"),{x:rn(t*n),y:rn(e*n)}}assertValidity(){const{x:t,y:e}=this.aff();return Jr(t)&&Jr(e)||Yr("Point invalid: x or y"),rn(e*e)===qr(t)?this:Yr("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")+yn(e)+(t?"":yn(r))}toRawBytes(t=!0){return hn(this.toHex(t))}}on.BASE=new on(jr,Wr,1n),on.ZERO=new on(0n,1n,0n);const{BASE:un,ZERO:an}=on,sn=(t,e)=>t.toString(16).padStart(e,"0"),fn=t=>Array.from(Zr(t)).map((t=>sn(t,2))).join(""),cn=t=>t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0,hn=t=>{const e="hex invalid";if(!$r(t))return Yr(e);const r=t.length,n=r/2;if(r%2)return Yr(e);const i=tn(n);for(let r=0,o=0;r<n;r++,o+=2){const n=cn(t.charCodeAt(o)),u=cn(t.charCodeAt(o+1));if(void 0===n||void 0===u)return Yr(e);i[r]=16*n+u}return i},pn=t=>BigInt("0x"+(fn(t)||"0")),ln=(t,e,r)=>pn(t.slice(e,r)),dn=t=>zr(t)&&t>=0n&&t<Mr?hn(sn(t,64)):Yr("bigint expected"),yn=t=>fn(dn(t)),gn=(...t)=>{const e=tn(t.reduce(((t,e)=>t+Zr(e).length),0));let r=0;return t.forEach((t=>{e.set(t,r),r+=t.length})),e},wn=(t,e)=>{(0n===t||e<=0n)&&Yr("no inverse n="+t+" mod="+e);let r=rn(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?rn(i,e):Yr("no inverse")},vn=t=>{let e=1n;for(let r=t,n=(Fr+1n)/4n;n>0n;n>>=1n)1n&n&&(e=e*r%Fr),r=r*r%Fr;return rn(e*e)===t?e:Yr("sqrt invalid")},mn=t=>(zr(t)||(t=pn(en(t,32))),Qr(t)?t:Yr("private key invalid 3")),bn=()=>"object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;let En;const Sn={hexToBytes:hn,bytesToHex:fn,concatBytes:gn,bytesToNumberBE:pn,numberToBytesBE:dn,mod:rn,invert:wn,hmacSha256Async:async(t,...e)=>{const r=bn(),n=r&&r.subtle;if(!n)return Yr("etc.hmacSha256Async or crypto.subtle must be defined");const i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return tn(await n.sign("HMAC",i,gn(...e)))},hmacSha256Sync:En,hashToPrivateKey:t=>{((t=en(t)).length<40||t.length>1024)&&Yr("expected 40-1024b");const e=rn(pn(t),Gr-1n);return dn(e+1n)},randomBytes:(t=32)=>{const e=bn();return e&&e.getRandomValues||Yr("crypto.getRandomValues must be defined"),e.getRandomValues(tn(t))}};let In;Object.defineProperties(Sn,{hmacSha256Sync:{configurable:!1,get:()=>En,set(t){En||(En=t)}}});const Tn=t=>{const e=In||(In=(()=>{const t=[];let e=un,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=an,i=un;const o=BigInt(255),u=BigInt(8);for(let a=0;a<33;a++){const s=128*a;let f=Number(t&o);t>>=u,f>128&&(f-=256,t+=1n);const c=s,h=s+Math.abs(f)-1,p=a%2!=0,l=f<0;0===f?i=i.add(r(p,e[c])):n=n.add(r(l,e[h]))}return{p:n,f:i}};var _n=r(394),kn=r(287).hp,An=W;function On(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(23)),redeem:it.maybe({network:it.maybe(it.Object),output:it.maybe(it.Buffer),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=t.network;r||(r=t.redeem&&t.redeem.network||p);var n={network:r,name:Yi.P2SH},i=Br((function(){var e=kn.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),o=Br((function(){return jt(t.input)})),u=Br((function(){var e=o(),n=e[e.length-1];return{network:r,output:n===An.OP_FALSE?kn.from([]):n,input:Gt(e.slice(0,-1)),witness:t.witness||[]}}));if(xr(n,"address",(function(){if(n.hash){var t=kn.allocUnsafe(21);return t.writeUInt8(n.network.scriptHash,0),n.hash.copy(t,1),F.encode(t)}})),xr(n,"hash",(function(){return t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?Fe(n.redeem.output):void 0})),xr(n,"output",(function(){if(n.hash)return Gt([An.OP_HASH160,n.hash,An.OP_EQUAL])})),xr(n,"redeem",(function(){if(t.input)return u()})),xr(n,"input",(function(){if(t.redeem&&t.redeem.input&&t.redeem.output)return Gt([].concat(jt(t.redeem.input),t.redeem.output))})),xr(n,"witness",(function(){return n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0})),xr(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=kn.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]!==An.OP_HASH160||20!==t.output[1]||t.output[22]!==An.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=Fe(t.output);if(a.length>0&&!a.equals(r))throw new TypeError("Hash mismatch");a=r}if(t.input){var n=t.input.length>0,i=t.witness&&t.witness.length>0;if(!n&&!i)throw new TypeError("Empty input");if(n&&i)throw new TypeError("Input and witness provided");if(n&&!Vt(jt(t.input)))throw new TypeError("Non push-only scriptSig")}};if(t.input){var c=o();if(!c||c.length<1)throw new TypeError("Input too short");if(!kn.isBuffer(u().output))throw new TypeError("Input is invalid");f(u())}if(t.redeem){if(t.redeem.network&&t.redeem.network!==r)throw new TypeError("Network mismatch");if(t.input){var h=u();if(t.redeem.output&&!t.redeem.output.equals(h.output))throw new TypeError("Redeem.output mismatch");if(t.redeem.input&&!t.redeem.input.equals(h.input))throw new TypeError("Redeem.input mismatch")}f(t.redeem)}if(t.witness&&t.redeem&&t.redeem.witness&&!at(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var Pn=W,Un=1,Nn=80;function xn(t,e){if(!(t.address||t.output||t.pubkey||t.internalPubkey||t.witness&&t.witness.length>1))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(34)),internalPubkey:it.maybe(it.BufferN(32)),hash:it.maybe(it.BufferN(32)),pubkey:it.maybe(it.BufferN(32)),signature:it.maybe(it.anyOf(it.BufferN(64),it.BufferN(65))),witness:it.maybe(it.arrayOf(it.Buffer)),scriptTree:it.maybe(pt),redeem:it.maybe({output:it.maybe(it.Buffer),redeemVersion:it.maybe(it.Number),witness:it.maybe(it.arrayOf(it.Buffer))}),redeemVersion:it.maybe(it.Number)},t);var r=Br((function(){return le(t.address)})),n=Br((function(){if(t.witness&&t.witness.length)return t.witness.length>=2&&t.witness[t.witness.length-1][0]===Nn?t.witness.slice(0,-1):t.witness.slice()})),i=Br((function(){return t.scriptTree?kr(t.scriptTree):t.hash?{hash:t.hash}:void 0})),o=t.network||p,u={name:Yi.P2TR,network:o};if(xr(u,"address",(function(){if(u.pubkey){var t=I.p2.toWords(u.pubkey);return t.unshift(Un),I.p2.encode(o.bech32,t)}})),xr(u,"hash",(function(){var t=i();if(t)return t.hash;var e=n();if(e&&e.length>1){var r=e[e.length-1],o=r[0]&ct;return _r(r,Or({output:e[e.length-2],version:o}))}})),xr(u,"output",(function(){if(u.pubkey)return Gt([Pn.OP_1,u.pubkey])})),xr(u,"redeemVersion",(function(){return t.redeemVersion?t.redeemVersion:t.redeem&&void 0!==t.redeem.redeemVersion&&null!==t.redeem.redeemVersion?t.redeem.redeemVersion:Sr})),xr(u,"redeem",(function(){var t=n();if(t&&!(t.length<2))return{output:t[t.length-2],witness:t.slice(0,-2),redeemVersion:t[t.length-1][0]&ct}})),xr(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=Ur(u.internalPubkey,u.hash);if(e)return e.x}})),xr(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})),xr(u,"signature",(function(){if(t.signature)return t.signature;var e=n();return e&&1===e.length?e[0]:void 0})),xr(u,"witness",(function(){if(t.witness)return t.witness;var e=i();if(e&&t.redeem&&t.redeem.output&&t.internalPubkey){var r=Ar(e,Or({output:t.redeem.output,version:u.redeemVersion}));if(!r)return;var n=Ur(t.internalPubkey,e.hash);if(!n)return;var o=rt.hp.concat([rt.hp.from([u.redeemVersion|n.parity]),t.internalPubkey].concat(r));return[t.redeem.output,o]}return t.signature?[t.signature]:void 0})),e.validate){var a=rt.hp.from([]);if(t.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==Un)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=Ur(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&&!Ar(f,Or({output:t.redeem.output,version:u.redeemVersion})))throw new TypeError("Redeem script not in tree");var c=n();if(t.redeem&&u.redeem){if(t.redeem.redeemVersion&&t.redeem.redeemVersion!==u.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(t.redeem.output){if(0===jt(t.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(u.redeem.output&&!t.redeem.output.equals(u.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(t.redeem.witness&&u.redeem.witness&&!at(t.redeem.witness,u.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(c&&c.length)if(1===c.length){if(t.signature&&!t.signature.equals(c[0]))throw new TypeError("Signature mismatch")}else{var h=c[c.length-1];if(h.length<33)throw new TypeError("The control-block length is too small. Got ".concat(h.length,", expected min 33."));if((h.length-33)%32!=0)throw new TypeError("The control-block length of ".concat(h.length," is incorrect!"));var l=(h.length-33)/32;if(l>128)throw new TypeError("The script path is too long. Got ".concat(l,", expected max 128."));var d=h.slice(1,33);if(t.internalPubkey&&!t.internalPubkey.equals(d))throw new TypeError("Internal pubkey mismatch");if(!$e().isXOnlyPoint(d))throw new TypeError("Invalid internalPubkey for p2tr witness");var y=h[0]&ct,g=Ur(d,_r(h,Or({output:c[c.length-2],version:y})));if(!g)throw new TypeError("Invalid outputKey for p2tr witness");if(a.length&&!a.equals(g.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(g.parity!==(1&h[0]))throw new Error("Incorrect parity")}}return Object.assign(u,t)}var Bn=r(287).hp,Cn=W,Rn=Bn.alloc(0);function Hn(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),input:it.maybe(it.BufferN(0)),network:it.maybe(it.Object),output:it.maybe(it.BufferN(22)),pubkey:it.maybe(st),signature:it.maybe($t),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Br((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Bn.from(n)}})),n=t.network||p,i={name:Yi.P2WPKH,network:n};if(xr(i,"address",(function(){if(i.hash){var t=I.I.toWords(i.hash);return t.unshift(0),I.I.encode(n.bech32,t)}})),xr(i,"hash",(function(){return t.output?t.output.slice(2,22):t.address?r().data:t.pubkey||i.pubkey?Fe(t.pubkey||i.pubkey):void 0})),xr(i,"output",(function(){if(i.hash)return Gt([Cn.OP_0,i.hash])})),xr(i,"pubkey",(function(){return t.pubkey?t.pubkey:t.witness?t.witness[1]:void 0})),xr(i,"signature",(function(){if(t.witness)return t.witness[0]})),xr(i,"input",(function(){if(i.witness)return Rn})),xr(i,"witness",(function(){if(t.pubkey&&t.signature)return[t.signature,t.pubkey]})),e.validate){var o=Bn.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]!==Cn.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=Fe(t.pubkey);if(o.length>0&&!o.equals(u))throw new TypeError("Hash mismatch");if(o=u,!st(t.pubkey)||33!==t.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(t.witness){if(2!==t.witness.length)throw new TypeError("Witness is invalid");if(!$t(t.witness[0]))throw new TypeError("Witness has invalid signature");if(!st(t.witness[1])||33!==t.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(t.signature&&!t.signature.equals(t.witness[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(t.witness[1]))throw new TypeError("Pubkey mismatch");var a=Fe(t.witness[1]);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(i,t)}var Ln=r(287).hp,Vn=W,Dn=Ln.alloc(0);function Kn(t){return!(!Ln.isBuffer(t)||65!==t.length||4!==t[0]||!st(t))}function Mn(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.witness))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(32)),output:it.maybe(it.BufferN(34)),redeem:it.maybe({input:it.maybe(it.Buffer),network:it.maybe(it.Object),output:it.maybe(it.Buffer),witness:it.maybe(it.arrayOf(it.Buffer))}),input:it.maybe(it.BufferN(0)),witness:it.maybe(it.arrayOf(it.Buffer))},t);var r=Br((function(){var e=I.I.decode(t.address),r=e.words.shift(),n=I.I.fromWords(e.words);return{version:r,prefix:e.prefix,data:Ln.from(n)}})),n=Br((function(){return jt(t.redeem.input)})),i=t.network;i||(i=t.redeem&&t.redeem.network||p);var o={network:i,name:Yi.P2WSH};if(xr(o,"address",(function(){if(o.hash){var t=I.I.toWords(o.hash);return t.unshift(0),I.I.encode(i.bech32,t)}})),xr(o,"hash",(function(){return t.output?t.output.slice(2):t.address?r().data:o.redeem&&o.redeem.output?Me(o.redeem.output):void 0})),xr(o,"output",(function(){if(o.hash)return Gt([Vn.OP_0,o.hash])})),xr(o,"redeem",(function(){if(t.witness)return{output:t.witness[t.witness.length-1],input:Dn,witness:t.witness.slice(0,-1)}})),xr(o,"input",(function(){if(o.witness)return Dn})),xr(o,"witness",(function(){if(t.redeem&&t.redeem.input&&t.redeem.input.length>0&&t.redeem.output&&t.redeem.output.length>0){var e=qt(n());return o.redeem=Object.assign({witness:e},t.redeem),o.redeem.input=Dn,[].concat(e,t.redeem.output)}if(t.redeem&&t.redeem.output&&t.redeem.witness)return[].concat(t.redeem.witness,t.redeem.output)})),xr(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=Ln.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]!==Vn.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=Me(t.redeem.output);if(u.length>0&&!u.equals(f))throw new TypeError("Hash mismatch");u=f}if(t.redeem.input&&!Vt(n()))throw new TypeError("Non push-only scriptSig");if(t.witness&&t.redeem.witness&&!at(t.witness,t.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(t.redeem.input&&n().some(Kn)||t.redeem.output&&(jt(t.redeem.output)||[]).some(Kn))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(Kn)||(jt(c)||[]).some(Kn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,t)}var Fn=r(287).hp;function Gn(t){return Gn="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},Gn(t)}function jn(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,Xn(n.key),n)}}function Wn(t,e,r){return(e=Xn(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Xn(t){var e=function(t){if("object"!=Gn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=Gn(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Gn(e)?e:e+""}var qn=it;function Yn(t){var e=t.length;return or(e)+e}var zn=Fn.allocUnsafe(0),$n=[],Jn=Fn.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Qn=Fn.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Zn=Fn.from("ffffffffffffffff","hex"),ti={script:zn,valueBuffer:Zn},ei=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Wn(this,"version",1),Wn(this,"locktime",0),Wn(this,"ins",[]),Wn(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 qn(Et(dt,It,bt(It),bt(vt)),arguments),kt(n)&&(n=t.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:r,script:i||zn,sequence:n,witness:$n})-1}},{key:"addOutput",value:function(t,e){return qn(Et(vt,ft),arguments),this.outs.push({script:t,value:e})-1}},{key:"hasWitnesses",value:function(){return this.ins.some((function(t){return 0!==t.witness.length}))}},{key:"weight",value:function(){return 3*this.byteLength(!1)+this.byteLength(!0)}},{key:"virtualSize",value:function(){return Math.ceil(this.weight()/4)}},{key:"byteLength",value:function(){var t=(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&this.hasWitnesses();return(t?10:8)+or(this.ins.length)+or(this.outs.length)+this.ins.reduce((function(t,e){return t+40+Yn(e.script)}),0)+this.outs.reduce((function(t,e){return t+8+Yn(e.script)}),0)+(t?this.ins.reduce((function(t,e){return t+(or((r=e.witness).length)+r.reduce((function(t,e){return t+Yn(e)}),0));var r}),0):0)}},{key:"clone",value:function(){var e=new t;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map((function(t){return{hash:t.hash,index:t.index,script:t.script,sequence:t.sequence,witness:t.witness}})),e.outs=this.outs.map((function(t){return{script:t.script,value:t.value}})),e}},{key:"hashForSignature",value:function(e,r,n){if(qn(Et(It,vt,yt),arguments),e>=this.ins.length)return Qn;var i=Gt(jt(r).filter((function(t){return t!==W.OP_CODESEPARATOR}))),o=this.clone();if((31&n)===t.SIGHASH_NONE)o.outs=[],o.ins.forEach((function(t,r){r!==e&&(t.sequence=0)}));else if((31&n)===t.SIGHASH_SINGLE){if(e>=this.outs.length)return Qn;o.outs.length=e+1;for(var u=0;u<e;u++)o.outs[u]=ti;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=zn})),o.ins[e].script=i);var a=Fn.allocUnsafe(o.byteLength(!1)+4);return a.writeInt32LE(n,a.length-4),o.__toBuffer(a,0,!1),Ge(a)}},{key:"hashForWitnessV1",value:function(e,r,n,i,o,u){if(qn(Et(It,qn.arrayOf(vt),qn.arrayOf(ft),It),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");var a=i===t.SIGHASH_DEFAULT?t.SIGHASH_ALL:i&t.SIGHASH_OUTPUT_MASK,s=(i&t.SIGHASH_INPUT_MASK)===t.SIGHASH_ANYONECANPAY,f=a===t.SIGHASH_NONE,c=a===t.SIGHASH_SINGLE,h=zn,p=zn,l=zn,d=zn,y=zn;if(!s){var g=vr.withCapacity(36*this.ins.length);this.ins.forEach((function(t){g.writeSlice(t.hash),g.writeUInt32(t.index)})),h=Me(g.end()),g=vr.withCapacity(8*this.ins.length),n.forEach((function(t){return g.writeUInt64(t)})),p=Me(g.end()),g=vr.withCapacity(r.map(Yn).reduce((function(t,e){return t+e}))),r.forEach((function(t){return g.writeVarSlice(t)})),l=Me(g.end()),g=vr.withCapacity(4*this.ins.length),this.ins.forEach((function(t){return g.writeUInt32(t.sequence)})),d=Me(g.end())}if(f||c){if(c&&e<this.outs.length){var w=this.outs[e],v=vr.withCapacity(8+Yn(w.script));v.writeUInt64(w.value),v.writeVarSlice(w.script),y=Me(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+Yn(t.script)})).reduce((function(t,e){return t+e})),b=vr.withCapacity(m);this.outs.forEach((function(t){b.writeUInt64(t.value),b.writeVarSlice(t.script)})),y=Me(b.end())}var E=(o?2:0)+(u?1:0),S=174-(s?49:0)-(f?32:0)+(u?32:0)+(o?37:0),I=vr.withCapacity(S);if(I.writeUInt8(i),I.writeInt32(this.version),I.writeUInt32(this.locktime),I.writeSlice(h),I.writeSlice(p),I.writeSlice(l),I.writeSlice(d),f||c||I.writeSlice(y),I.writeUInt8(E),s){var T=this.ins[e];I.writeSlice(T.hash),I.writeUInt32(T.index),I.writeUInt64(n[e]),I.writeVarSlice(r[e]),I.writeUInt32(T.sequence)}else I.writeUInt32(e);if(u){var _=vr.withCapacity(Yn(u));_.writeVarSlice(u),I.writeSlice(Me(_.end()))}return c&&I.writeSlice(y),o&&(I.writeSlice(o),I.writeUInt8(0),I.writeUInt32(4294967295)),Xe("TapSighash",Fn.concat([Fn.from([0]),I.end()]))}},{key:"hashForWitnessV0",value:function(e,r,n,i){qn(Et(It,vt,ft,It),arguments);var o,u=Fn.from([]),a=Jn,s=Jn,f=Jn;if(i&t.SIGHASH_ANYONECANPAY||(u=Fn.allocUnsafe(36*this.ins.length),o=new vr(u,0),this.ins.forEach((function(t){o.writeSlice(t.hash),o.writeUInt32(t.index)})),s=Ge(u)),i&t.SIGHASH_ANYONECANPAY||(31&i)===t.SIGHASH_SINGLE||(31&i)===t.SIGHASH_NONE||(u=Fn.allocUnsafe(4*this.ins.length),o=new vr(u,0),this.ins.forEach((function(t){o.writeUInt32(t.sequence)})),f=Ge(u)),(31&i)!==t.SIGHASH_SINGLE&&(31&i)!==t.SIGHASH_NONE){var c=this.outs.reduce((function(t,e){return t+8+Yn(e.script)}),0);u=Fn.allocUnsafe(c),o=new vr(u,0),this.outs.forEach((function(t){o.writeUInt64(t.value),o.writeVarSlice(t.script)})),a=Ge(u)}else if((31&i)===t.SIGHASH_SINGLE&&e<this.outs.length){var h=this.outs[e];u=Fn.allocUnsafe(8+Yn(h.script)),(o=new vr(u,0)).writeUInt64(h.value),o.writeVarSlice(h.script),a=Ge(u)}u=Fn.allocUnsafe(156+Yn(r)),o=new vr(u,0);var p=this.ins[e];return o.writeInt32(this.version),o.writeSlice(s),o.writeSlice(f),o.writeSlice(p.hash),o.writeUInt32(p.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(p.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),Ge(u)}},{key:"getHash",value:function(t){return t&&this.isCoinbase()?Fn.alloc(32,0):Ge(this.__toBuffer(void 0,void 0,t))}},{key:"getId",value:function(){return gr(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){qn(Et(yt,vt),arguments),this.ins[t].script=e}},{key:"setWitness",value:function(t,e){qn(Et(yt,[vt]),arguments),this.ins[t].witness=e}},{key:"__toBuffer",value:function(e,r){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];e||(e=Fn.allocUnsafe(this.byteLength(n)));var i=new vr(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 mr(e),i=new t;i.version=n.readInt32();var o=n.readUInt8(),u=n.readUInt8(),a=!1;o===t.ADVANCED_TRANSACTION_MARKER&&u===t.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;for(var s=n.readVarInt(),f=0;f<s;++f){var c=n.readSlice(32),h=n.readUInt32(),p=n.readVarSlice(),l=n.readUInt32();i.ins.push({hash:c,index:h,script:p,sequence:l,witness:$n})}for(var d=n.readVarInt(),y=0;y<d;++y)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(var g=0;g<s;++g)i.ins[g].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==e.length)throw new Error("Transaction has unexpected data");return i}},{key:"fromHex",value:function(e){return t.fromBuffer(Fn.from(e,"hex"),!1)}},{key:"isCoinbaseHash",value:function(t){qn(dt,t);for(var e=0;e<32;++e)if(0!==t[e])return!1;return!0}}],r&&jn(e.prototype,r),n&&jn(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();Wn(ei,"DEFAULT_SEQUENCE",4294967295),Wn(ei,"SIGHASH_DEFAULT",0),Wn(ei,"SIGHASH_ALL",1),Wn(ei,"SIGHASH_NONE",2),Wn(ei,"SIGHASH_SINGLE",3),Wn(ei,"SIGHASH_ANYONECANPAY",128),Wn(ei,"SIGHASH_OUTPUT_MASK",3),Wn(ei,"SIGHASH_INPUT_MASK",128),Wn(ei,"ADVANCED_TRANSACTION_MARKER",0),Wn(ei,"ADVANCED_TRANSACTION_FLAG",1),Wn(ei,"TRUC_VERSION",3),Wn(ei,"TRUC_MAX_VSIZE",1e4),Wn(ei,"TRUC_CHILD_MAX_VSIZE",1e3);var ri=r(287).hp;function ni(t,e){if(t){if("string"==typeof t)return ii(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)?ii(t,e):void 0}}function ii(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 oi=function(t){var e=32===t.length?t:t.slice(1,33);return ri.isBuffer(e)?e:ri.from(e)};function ui(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=Or({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=Or({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:Gi(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 ai(t,e){var r=e?ri.from([e]):ri.from([]);return ri.concat([t,r])}function si(t){return t&&!!(t.tapInternalKey||t.tapMerkleRoot||t.tapLeafScript&&t.tapLeafScript.length||t.tapBip32Derivation&&t.tapBip32Derivation.length||t.witnessUtxo&&Hi(t.witnessUtxo.script))}function fi(t,e){return t&&!!(t.tapInternalKey||t.tapTree||t.tapBip32Derivation&&t.tapBip32Derivation.length||e&&Hi(e))}function ci(t,e,r){!function(t,e,r){var n=si(t)&&Ei(e),i=Ei(t)&&si(e),o=t===e&&si(e)&&Ei(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 bi(t,e.tapMerkleRoot)})),i=(t.tapLeafScript||[]).every((function(t){return bi(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 bi(e,t.tapMerkleRoot)})))throw new Error("Invalid arguments for Psbt.".concat(r,". Tapleaf not part of taptree."))}(t,e,r)}function hi(t,e,r){!function(t,e,r){var n=fi(t)&&Ei(e),i=Ei(t)&&fi(e),o=t===e&&fi(e)&&Ei(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 xn({internalPubkey:t,scriptTree:e&&di(e.leaves)}).output}(r,n);if(i&&!i.equals(o))throw new Error("Error adding output. Script or address missmatch.")}}}(t,e)}function pi(t,e){var r=e.tapInternalKey,n=r&&Ur(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 li(t){if(!pt(t))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return vi(t)}function di(){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=ni(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=mi(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 yi(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 ii(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)||ni(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=wi(t.finalScriptWitness);n&&r.push(n)}return r}(t);return r.some((function(t){return Xi(t,gi,e)}))}function gi(t){return{signature:t.slice(0,64),hashType:t.slice(64)[0]||ei.SIGHASH_DEFAULT}}function wi(t){if(t){var e=t.slice(2);return 64===e.length||65===e.length?e:void 0}}function vi(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>Ir)throw new Error("Max taptree depth exceeded.");return t?ht(t)?(e.push({depth:r,leafVersion:t.version||Sr,script:t.output}),e):(t[0]&&vi(t[0],e,r+1),t[1]&&vi(t[1],e,r+1),e):[]}function mi(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r>Ir)throw new Error("Max taptree depth exceeded.");if(t.depth===r)return e?void 0:{output:t.script,version:t.leafVersion};if(!ht(e)){var n=mi(t,e&&e[0],r+1);if(n)return[n,e&&e[1]];var i=mi(t,e&&e[1],r+1);return i?[e&&e[0],i]:void 0}}function bi(t,e){if(!e)return!0;var r=Or({output:t.script,version:t.leafVersion});return _r(t.controlBlock,r).equals(e)}function Ei(t){return t&&!!(t.redeemScript||t.witnessScript||t.bip32Derivation&&t.bip32Derivation.length)}var Si=r(287).hp,Ii=W,Ti=16,_i=2,ki=40;function Ai(t,e){if(!(t.address||t.output||t.program||void 0!==t.deploymentVersion&&t.hash160))throw new TypeError("At least one of address, output or program must be provided");e=Object.assign({validate:!0},e||{}),it({address:it.maybe(it.String),output:it.maybe(it.Buffer),program:it.maybe(it.Buffer),network:it.maybe(it.Object),deploymentVersion:it.maybe(it.Number),hash160:it.maybe(it.BufferN(20))},t);var r=function(){if(void 0!==t.deploymentVersion&&void 0!==t.hash160){if(20!==t.hash160.length)throw new TypeError("hash160 must be exactly 20 bytes");if(t.deploymentVersion<0||t.deploymentVersion>255)throw new TypeError("deploymentVersion must fit in one byte");return Si.concat([Si.of(t.deploymentVersion),t.hash160])}},n=Br((function(){return le(t.address)})),i=t.network||p,o={name:Yi.P2OP,network:i,deploymentVersion:0};if(xr(o,"program",(function(){if(t.program)return t.program;var e=r();if(e)return e;if(t.output){if(t.output[0]!==Ii.OP_16)throw new TypeError("Invalid P2OP script");var i,o=1;if(t.output[1]<76)i=t.output[1],o=2;else{if(76!==t.output[1])throw new TypeError("Unsupported push opcode in P2OP script");i=t.output[2],o=3}return t.output.slice(o,o+i)}return t.address?n().data:void 0})),xr(o,"deploymentVersion",(function(){if(o.program)return o.program[0]})),xr(o,"hash160",(function(){if(o.program)return o.program.slice(1)})),xr(o,"output",(function(){if(o.program)return Gt([Ii.OP_16,o.program])})),xr(o,"address",(function(){if(o.program){if(!i.bech32Opnet)throw new TypeError("Network does not support opnet");var t=I.p2.toWords(o.program);return t.unshift(Ti),I.p2.encode(i.bech32Opnet,t)}})),e.validate){var u=rt.hp.alloc(0);if(t.address){var a=n();if(i.bech32Opnet!==a.prefix)throw new TypeError("Invalid prefix or network mismatch");if(a.version!==Ti)throw new TypeError("Invalid witness version for p2op");if(a.data.length<_i||a.data.length>ki)throw new TypeError("Invalid witness program length");u=a.data}if(t.program){if(u.length&&!u.equals(t.program))throw new TypeError("Program mismatch");u=t.program}if(!u.length&&void 0!==t.deploymentVersion&&t.hash160&&(u=r()),t.output){var s=o.program;if(u.length&&!u.equals(s))throw new TypeError("Program mismatch (output vs other source)");u=s}if(u.length<_i||u.length>ki)throw new TypeError("Witness program must be 2–40 bytes. Was ".concat(u.length," bytes"));if(void 0!==t.deploymentVersion&&t.deploymentVersion!==u[0])throw new TypeError("deploymentVersion mismatch");if(t.hash160&&!t.hash160.equals(u.slice(1)))throw new TypeError("hash160 mismatch")}return Object.assign(o,t)}var Oi=r(287).hp;function Pi(t){return function(e){try{return t({output:e}),!0}catch(t){return!1}}}var Ui=Pi(Vr),Ni=Pi(Kr),xi=Pi(Ji),Bi=Pi(Hn),Ci=Pi(Mn),Ri=Pi(On),Hi=Pi(xn),Li=Pi(Ai),Vi=function(t){return 4===t.length&&81===t[0]&&2===t[1]&&78===t[2]&&115===t[3]};function Di(t){var e,r=Oi.allocUnsafe(0);function n(t){var e=r.length,n=_n.encodingLength(t);r=Oi.concat([r,Oi.allocUnsafe(n)]),_n.encode(t,r,e)}return n((e=t).length),e.forEach((function(t){n(t.length),function(t){r=Oi.concat([r,Oi.from(t)])}(t)})),r}function Ki(t){if(32!==t.length){if([33,65].includes(t.length)){var e;try{e=on.fromHex(t)}catch(t){throw new Error("Invalid secp256k1 public key bytes. Cannot parse.")}var r=Mi(e.x),n=Mi(e.y),i=e.y%2n===0n?6:7,o=Oi.alloc(65);return o[0]=i,r.copy(o,1),n.copy(o,33),{hybrid:o,uncompressed:Oi.concat([Oi.from([4]),r,n])}}console.warn("Unsupported key length=".concat(t.length,". Must be 33 (compressed) or 65 (uncompressed)."))}}function Mi(t){var e=t.toString(16);return(e=e.padStart(64,"0")).length>64&&(e=e.slice(-64)),Oi.from(e,"hex")}function Fi(t,e){if(t.equals(e))return!0;if(65===t.length&&65===e.length){var r=Oi.from(t),n=Oi.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 Gi(t,e){var r=jt(e);if(null===r)throw new Error("Unknown script error");var n=Fe(t),i=oi(t),o=Ki(t),u=null!=o&&o.hybrid?Fe(o.hybrid):void 0,a=null!=o&&o.uncompressed?Fe(o.uncompressed):void 0;return r.findIndex((function(e){if("number"==typeof e)return!1;if(Fi(e,t))return!0;if(Fi(e,i))return!0;if(e.equals(n))return!0;if(o){if(Fi(e,o.uncompressed))return!0;if(Fi(e,o.hybrid))return!0;if(u&&e.equals(u)||a&&e.equals(a))return!0}}))}function ji(t,e){return-1!==Gi(t,e)}function Wi(t,e){var r=function(t){var e=[];if(0===(t.partialSig||[]).length){if(!t.finalScriptSig&&!t.finalScriptWitness)return[];e=qi(t)}else e=t.partialSig;return e.map((function(t){return t.signature}))}(t);return r.some((function(t){return Xi(t,Qt.decode,e)}))}function Xi(t,e,r){var n=e(t).hashType,i=[];switch(n&ei.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case ei.SIGHASH_ALL:break;case ei.SIGHASH_SINGLE:case ei.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}function qi(t){var e=t.finalScriptSig&&jt(t.finalScriptSig)||[],r=t.finalScriptWitness&&jt(t.finalScriptWitness)||[];return e.concat(r).filter((function(t){return Oi.isBuffer(t)&&$t(t)})).map((function(t){return{signature:t}}))}var Yi,zi=r(287).hp,$i=W;function Ji(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it({network:it.maybe(it.Object),address:it.maybe(it.String),hash:it.maybe(it.BufferN(20)),output:it.maybe(it.BufferN(25)),pubkey:it.maybe(st),signature:it.maybe($t),input:it.maybe(it.Buffer)},t);var r=Br((function(){var e=zi.from(F.decode(t.address));return{version:e.readUInt8(0),hash:e.slice(1)}})),n=Br((function(){return jt(t.input)})),i=t.network||p,o={name:Yi.P2PKH,network:i,hash:void 0};if(xr(o,"address",(function(){if(o.hash){var t=zi.allocUnsafe(21);return t.writeUInt8(i.pubKeyHash,0),o.hash.copy(t,1),F.encode(t)}})),xr(o,"hash",(function(){return t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?Fe(t.pubkey||o.pubkey):void 0})),xr(o,"output",(function(){if(o.hash)return Gt([$i.OP_DUP,$i.OP_HASH160,o.hash,$i.OP_EQUALVERIFY,$i.OP_CHECKSIG])})),xr(o,"pubkey",(function(){if(t.input)return n()[1]})),xr(o,"signature",(function(){if(t.input)return n()[0]})),xr(o,"input",(function(){if(t.pubkey&&t.signature){var e=t.pubkey;if(t.useHybrid||t.useUncompressed){var r=Ki(t.pubkey);r&&(e=t.useUncompressed?r.uncompressed:r.hybrid)}return Gt([t.signature,e])}})),xr(o,"witness",(function(){if(o.input)return[]})),e.validate){var u=zi.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=Fe(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=Ki(t.pubkey);if(c){var h=Fe(c.uncompressed);if(u.equals(h))f=!1,t.useUncompressed=!0;else{var l=Fe(c.hybrid);(f=!u.equals(l))||(t.useHybrid=!0)}}}if(f)throw new TypeError("Hash mismatch");u=s}if(t.input){var d=n();if(2!==d.length)throw new TypeError("Input is invalid");if(!$t(d[0]))throw new TypeError("Input has invalid signature");if(!st(d[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&!t.signature.equals(d[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&!t.pubkey.equals(d[1]))throw new TypeError("Pubkey mismatch");var y=Fe(d[1]);if(u.length>0&&!u.equals(y))throw new TypeError("Hash mismatch (input)")}}return Object.assign(o,t)}!function(t){t.P2PK="p2pk",t.P2PKH="p2pkh",t.P2SH="p2sh",t.P2MS="p2ms",t.P2WPKH="p2wpkh",t.P2WSH="p2wsh",t.P2TR="p2tr",t.P2OP="p2op",t.Embed="embed",t.ScriptRedeem="scriptRedeem"}(Yi||(Yi={}));var Qi=r(287).hp,Zi=r(287).hp;function to(t){return to="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},to(t)}function eo(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,no(n.key),n)}}function ro(t,e,r){return(e=no(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function no(t){var e=function(t){if("object"!=to(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=to(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==to(e)?e:e+""}var io=it,oo=new TypeError("Cannot compute merkle root for zero transactions"),uo=new TypeError("Cannot compute witness commit for non-segwit block"),ao=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),ro(this,"version",1),ro(this,"prevHash",void 0),ro(this,"merkleRoot",void 0),ro(this,"timestamp",0),ro(this,"witnessCommit",void 0),ro(this,"bits",0),ro(this,"nonce",0),ro(this,"transactions",void 0)}return e=t,r=[{key:"getWitnessCommit",value:function(){if(!so(this.transactions))return null;var t=this.transactions[0].outs.filter((function(t){return t.script.slice(0,6).equals(Zi.from("6a24aa21a9ed","hex"))})).map((function(t){return t.script.slice(6,38)}));if(0===t.length)return null;var e=t[t.length-1];return e instanceof Zi&&32===e.length?e:null}},{key:"hasWitnessCommit",value:function(){return this.witnessCommit instanceof Zi&&32===this.witnessCommit.length||null!==this.getWitnessCommit()}},{key:"hasWitness",value:function(){return(t=this.transactions)instanceof Array&&t.some((function(t){return"object"===to(t)&&t.ins instanceof Array&&t.ins.some((function(t){return"object"===to(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+or(this.transactions.length)+this.transactions.reduce((function(t,r){return t+r.byteLength(e)}),0)}},{key:"getHash",value:function(){return Ge(this.toBuffer(!0))}},{key:"getId",value:function(){return gr(this.getHash()).toString("hex")}},{key:"getUTCDate",value:function(){var t=new Date(0);return t.setUTCSeconds(this.timestamp),t}},{key:"toBuffer",value:function(t){var e=Zi.allocUnsafe(this.byteLength(t)),r=new vr(e);if(r.writeInt32(this.version),r.writeSlice(this.prevHash),r.writeSlice(this.merkleRoot),r.writeUInt32(this.timestamp),r.writeUInt32(this.bits),r.writeUInt32(this.nonce),t||!this.transactions)return e;var n=nr(this.transactions.length,e,r.offset);return r.offset+=n.bytes,this.transactions.forEach((function(t){var n=t.byteLength();t.toBuffer(e,r.offset),r.offset+=n})),e}},{key:"toHex",value:function(t){return this.toBuffer(t).toString("hex")}},{key:"checkTxRoots",value:function(){var t=this.hasWitnessCommit();return!(!t&&this.hasWitness())&&this.__checkMerkleRoot()&&(!t||this.__checkWitnessCommit())}},{key:"checkProofOfWork",value:function(){var e=gr(this.getHash()),r=t.calculateTarget(this.bits);return e.compare(r)<=0}},{key:"__checkMerkleRoot",value:function(){if(!this.transactions)throw oo;var e=t.calculateMerkleRoot(this.transactions);return 0===this.merkleRoot.compare(e)}},{key:"__checkWitnessCommit",value:function(){if(!this.transactions)throw oo;if(!this.hasWitnessCommit())throw uo;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 mr(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=ei.fromBuffer(r.buffer.slice(r.offset),!0);return r.offset+=t.byteLength(),t},o=r.readVarInt();n.transactions=[];for(var u=0;u<o;++u){var a=i();n.transactions.push(a)}var s=n.getWitnessCommit();return s&&(n.witnessCommit=s),n}},{key:"fromHex",value:function(e){return t.fromBuffer(Zi.from(e,"hex"))}},{key:"calculateTarget",value:function(t){var e=((4278190080&t)>>24)-3,r=8388607&t,n=Zi.alloc(32,0);return n.writeUIntBE(r,29-e,3),n}},{key:"calculateMerkleRoot",value:function(t,e){if(io([{getHash:Tt}],t),0===t.length)throw oo;if(e&&!so(t))throw uo;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=Qi.concat([u,a]);n[i]=e(s)}r=i}return n[0]}(t.map((function(t){return t.getHash(e)})),Ge);return e?Ge(Zi.concat([r,t[0].ins[0].witness[0]])):r}}],r&&eo(e.prototype,r),n&&eo(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}();function so(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 fo=r(614),co=r(699),ho=r(287).hp;function po(t){return po="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},po(t)}function lo(){lo=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function s(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(e,r,n,i){var o=r&&r.prototype instanceof p?r:p,u=Object.create(o.prototype);return s(u,"_invoke",function(e,r,n){var i=1;return function(o,u){if(3===i)throw Error("Generator is already running");if(4===i){if("throw"===o)throw u;return{value:t,done:!0}}for(n.method=o,n.arg=u;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===i)throw i=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=3;var f=c(e,r,n);if("normal"===f.type){if(i=n.done?4:2,f.arg===h)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(i=4,n.method="throw",n.arg=f.arg)}}}(e,n,new T(i||[])),!0),u}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h={};function p(){}function l(){}function d(){}var y={};s(y,o,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(_([])));w&&w!==r&&n.call(w,o)&&(y=w);var v=d.prototype=p.prototype=Object.create(y);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(i,o,u,a){var s=c(t[i],t,o);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==po(h)&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(h).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,a)}))}a(s.arg)}var i;s(this,"_invoke",(function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}),!0)}function E(e,r){var n=r.method,i=e.i[n];if(i===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,E(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=c(i,e.i,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,h;var u=o.arg;return u?u.done?(r[e.r]=u.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,h):u:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function S(t){this.tryEntries.push(t)}function I(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function T(t){this.tryEntries=[[-1]],t.forEach(S,this),this.reset(!0)}function _(e){if(null!=e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,u=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return u.next=u}}throw new TypeError(po(e)+" is not iterable")}return l.prototype=d,s(v,"constructor",d),s(d,"constructor",l),l.displayName=s(d,a,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,a,"GeneratorFunction")),t.prototype=Object.create(v),t},e.awrap=function(t){return{__await:t}},m(b.prototype),s(b.prototype,u,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new b(f(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},m(v),s(v,a,"Generator"),s(v,o,(function(){return this})),s(v,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},e.values=_,T.prototype={constructor:T,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){u.type="throw",u.arg=e,r.next=t}for(var i=r.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o[4],a=this.prev,s=o[1],f=o[2];if(-1===o[0])return n("end"),!1;if(!s&&!f)throw Error("try statement without catch or finally");if(null!=o[0]&&o[0]<=a){if(a<s)return this.method="next",this.arg=t,n(s),!0;if(a<f)return n(f),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var i=n;break}}i&&("break"===t||"continue"===t)&&i[0]<=e&&e<=i[2]&&(i=null);var o=i?i[4]:{};return o.type=t,o.arg=e,i?(this.method="next",this.next=i[2],h):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),I(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var i=n.arg;I(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:_(e),r,n},"next"===this.method&&(this.arg=t),h}},e}function yo(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 go(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function u(t){yo(o,n,i,u,a,"next",t)}function a(t){yo(o,n,i,u,a,"throw",t)}u(void 0)}))}}function wo(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=mo(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 vo(t){return function(t){if(Array.isArray(t))return bo(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||mo(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 mo(t,e){if(t){if("string"==typeof t)return bo(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)?bo(t,e):void 0}}function bo(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 Eo(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function So(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,To(n.key),n)}}function Io(t,e,r){return e&&So(t.prototype,e),r&&So(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function To(t){var e=function(t){if("object"!=po(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=po(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==po(e)?e:e+""}var _o={network:p,maximumFeeRate:5e3},ko=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 fo.i(new Oo);Eo(this,t),this.data=r,this.opts=Object.assign({},_o,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},3===e.version?this.setVersionTRUC():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 Io(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:wr(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=ge(e.script,t.opts.network)}catch(t){}return{script:wr(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,vo(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){Bo(t),this.opts.maximumFeeRate=t}},{key:"setVersion",value:function(t){Bo(t),Co(this.data.inputs,"setVersion");var e=this.__CACHE;return e.__TX.version=t,e.__EXTRACTED_TX=void 0,this}},{key:"setVersionTRUC",value:function(){return this.setVersion(ei.TRUC_VERSION)}},{key:"setLocktime",value:function(t){Bo(t),Co(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){Bo(e),Co(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]");ci(t,t,"addInput"),e&&Co(this.data.inputs,"addInput"),t.witnessScript&&iu(t.witnessScript);var r=this.__CACHE;this.data.addInput(t),Ho(r,r.__TX.ins[r.__TX.ins.length-1]);var n=this.data.inputs.length-1,i=this.data.inputs[n];return i.nonWitnessUtxo&&Jo(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]");Co(this.data.inputs,"addOutput");var e=t.address;if("string"==typeof e){var r=we(e,this.opts.network);t=Object.assign({},t,{script:r})}hi(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(No))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 Qo(this.data.inputs,n,r,!0,e),n}},{key:"getFeeRate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Ko("__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 Ko("__FEE","fee",this.data.inputs,this.__CACHE,t)}},{key:"finalizeAllInputs",value:function(){var t=this;return(0,co.checkForInput)(this.data.inputs,0),uu(this.data.inputs.length).forEach((function(e){return t.finalizeInput(e)})),this}},{key:"finalizeInput",value:function(t,e,r){var n=(0,co.checkForInput)(this.data.inputs,t);return si(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]:ui,n=(0,co.checkForInput)(this.data.inputs,t);if(si(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,co.checkForInput)(this.data.inputs,t),r=nu(tu(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(ho.isBuffer(r)&&!ru(r)&&!$t(r))if(jt(r))return r}}}(e.finalScriptSig),e.witnessScript||function(t){if(t){var e=$o(t),r=e[e.length-1];if(!ru(r)&&jt(r))return r}}(e.finalScriptWitness));return("raw"===r.type?"":r.type+"-")+ou(r.meaningfulScript)}},{key:"inputHasPubkey",value:function(t,e){return function(t,e,r,n){return ji(t,nu(tu(r,e,n),r,"input",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,co.checkForInput)(this.data.inputs,t),t,this.__CACHE)}},{key:"inputHasHDKey",value:function(t,e){var r=(0,co.checkForInput)(this.data.inputs,t),n=xo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"outputHasPubkey",value:function(t,e){return function(t,e,r,n){return ji(t,nu(n.__TX.outs[r].script,r,"output",e.redeemScript,e.witnessScript).meaningfulScript)}(e,(0,co.checkForOutput)(this.data.outputs,t),t,this.__CACHE)}},{key:"outputHasHDKey",value:function(t,e){var r=(0,co.checkForOutput)(this.data.outputs,t),n=xo(e);return!!r.bip32Derivation&&r.bip32Derivation.some(n)}},{key:"validateSignaturesOfAllInputs",value:function(t){var e=this;return(0,co.checkForInput)(this.data.inputs,0),uu(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 si(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]:[ei.SIGHASH_ALL];if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");var r,n=[],i=wo(uu(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]:[ei.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=wo(uu(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]:[ei.SIGHASH_ALL];if(!e||!e.publicKey||!e.fingerprint)throw new Error("Need HDSigner to sign input");return zo(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]:[ei.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=zo(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=wo(uu(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=wo(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)||mo(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,co.checkForInput)(this.data.inputs,t);return si(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,co.checkForInput)(this.data.inputs,t);if(si(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,co.checkForInput)(n.data.inputs,t);return si(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,co.checkForInput)(i.data.inputs,t);if(si(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 Po(this.__CACHE),this.data.toBuffer()}},{key:"toHex",value:function(){return Po(this.__CACHE),this.data.toHex()}},{key:"toBase64",value:function(){return Po(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&&iu(e.witnessScript),ci(this.data.inputs[t],e,"updateInput"),this.data.updateInput(t,e),e.nonWitnessUtxo&&Jo(this.__CACHE,this.data.inputs[t],t),this}},{key:"updateOutput",value:function(t,e){return hi(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=qo(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]:Mo,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=function(t,e,r){var n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!e.redeemScript,i.isP2WSH=!!e.witnessScript,e.witnessScript)i.script=e.witnessScript;else if(e.redeemScript)i.script=e.redeemScript;else if(e.nonWitnessUtxo){var o=Zo(r,e,t),u=n.ins[t].index;i.script=o.outs[u].script}else e.witnessUtxo&&(i.script=e.witnessUtxo.script);if(e.witnessScript||Bi(i.script))i.isSegwit=!0;else try{var a=i.script;if(!a)throw new TypeError("Invalid script for segwit address");i.isSegwit=fe(a)}catch(t){}return i}(t,e,this.__CACHE),o=i.script,u=i.isP2SH,a=i.isP2WSH,s=i.isSegwit;if(!o)throw new Error("No script found for input #".concat(t));!function(t){if(t.sighashType&&t.partialSig){var e=t.partialSig,r=t.sighashType;e.forEach((function(t){var e=Qt.decode(t.signature).hashType;if(r!==e)throw new Error("Signature sighash does not match input sighash type")}))}}(e);var f=r(t,e,o,s,u,a,n),c=f.finalScriptSig,h=f.finalScriptWitness;if(c&&this.data.updateInput(t,{finalScriptSig:c}),h&&this.data.updateInput(t,{finalScriptWitness:h}),!c&&!h)throw new Error("Unknown error finalizing input #".concat(t));return this.data.clearFinalizedInput(t),this}},{key:"_finalizeTaprootInput",value:function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ui;if(!e.witnessUtxo)throw new Error("Cannot finalize input #".concat(t,". Missing witness utxo."));if(e.tapKeySig){var i=Di(xn({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=wo(o);try{for(h.s();!(f=h.n()).done;){var p=f.value,l=Qt.decode(p.signature),d=s!==l.hashType?jo(t,Object.assign({},n,{sighashType:l.hashType}),this.__CACHE,!0):{hash:u,script:a},y=d.hash,g=d.script;s=l.hashType,u=y,a=g,Ro(p.pubkey,g,"verify"),c.push(e(p.pubkey,y,l.signature))}}catch(t){h.e(t)}finally{h.f()}return c.every((function(t){return!0===t}))}},{key:"validateSignaturesOfTaprootInput",value:function(t,e,r){var n=this.data.inputs[t],i=(n||{}).tapKeySig,o=(n||{}).tapScriptSig;if(!n&&!i&&(!o||o.length))throw new Error("No signatures to validate");if("function"!=typeof e)throw new Error("Need validator function to validate signatures");var u=(r=r&&oi(r))?qo(t,n,this.data.inputs,r,this.__CACHE):function(t,e,r,n){var i=[];if(e.tapInternalKey){var o=Wo(t,e,n);o&&i.push(o)}if(e.tapScriptSig){var u=e.tapScriptSig.map((function(t){return t.pubkey}));i.push.apply(i,vo(u))}return i.map((function(i){return qo(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,Xo(i)))return!1;s++}if(o){var f,c=wo(o);try{var h,p=function(){var t=f.value,r=u.find((function(e){return t.pubkey.equals(e.pubkey)}));if(r){if(!e(t.pubkey,r.hash,Xo(t.signature)))return{v:!1};s++}};for(c.s();!(f=c.n()).done;)if(h=p())return h.v}catch(t){c.e(t)}finally{c.f()}}return s>0}},{key:"_signInput",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[ei.SIGHASH_ALL],n=Go(this.data.inputs,t,e.publicKey,this.__CACHE,r),i=n.hash,o=n.sighashType,u=[{pubkey:e.publicKey,signature:Qt.encode(e.sign(i),o)}];return this.data.updateInput(t,{partialSig:u}),this}},{key:"_signTaprootInput",value:function(t,e,r,n){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[ei.SIGHASH_DEFAULT],o=this.checkTaprootHashesForSig(t,e,r,n,i),u=o.filter((function(t){return!t.leafHash})).map((function(t){return ai(r.signSchnorr(t.hash),e.sighashType)}))[0],a=o.filter((function(t){return!!t.leafHash})).map((function(t){return{pubkey:oi(r.publicKey),signature:ai(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]:[ei.SIGHASH_ALL],i=Go(this.data.inputs,t,e.publicKey,this.__CACHE,n),o=i.hash,u=i.sighashType;return Promise.resolve(e.sign(o)).then((function(n){var i=[{pubkey:e.publicKey,signature:Qt.encode(n,u)}];r.data.updateInput(t,{partialSig:i})}))}},{key:"_signTaprootInputAsync",value:(e=go(lo().mark((function t(e,r,n,i){var o,u,a,s,f,c,h,p,l,d,y,g=arguments;return lo().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=g.length>4&&void 0!==g[4]?g[4]:[ei.SIGHASH_DEFAULT],u=this.checkTaprootHashesForSig(e,r,n,i,o),a=[],s=u.filter((function(t){return!t.leafHash}))[0],s&&(f=Promise.resolve(n.signSchnorr(s.hash)).then((function(t){return{tapKeySig:ai(t,r.sighashType)}})),a.push(f)),c=u.filter((function(t){return!!t.leafHash})),c.length&&(h=c.map(function(){var t=go(lo().mark((function t(e){var i,o;return lo().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:oi(n.publicKey),signature:ai(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,vo(h))),t.next=9,Promise.all(a);case 9:p=t.sent,l=wo(p);try{for(l.s();!(d=l.n()).done;)y=d.value,this.data.updateInput(e,y)}catch(t){l.e(t)}finally{l.f()}case 12:case"end":return t.stop()}}),t,this)}))),function(t,r,n,i){return e.apply(this,arguments)})}],[{key:"fromBase64",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=ho.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=ho.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]:{},fo.i.fromBuffer(e,Ao));return r=i.__CACHE.__TX,n=i.__CACHE,r.ins.forEach((function(t){Ho(n,t)})),i}}]);var e}(),Ao=function(t){return new Oo(t)},Oo=function(){return Io((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ho.from([2,0,0,0,0,0,0,0,0,0]);Eo(this,t),this.tx=ei.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||!ho.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");var e="string"==typeof t.hash?gr(ho.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||!ho.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 Po(t){if(!1!==t.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Not BIP174 compliant, can not export")}function Uo(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 No(t){return!!t.finalScriptSig||!!t.finalScriptWitness}function xo(t){return function(e){return!!e.masterFingerprint.equals(t.fingerprint)&&!!t.derivePath(e.path).publicKey.equals(e.pubkey)}}function Bo(t){if("number"!=typeof t||t!==Math.floor(t)||t>4294967295||t<0)throw new Error("Invalid 32 bit integer")}function Co(t,e){t.forEach((function(t){if(si(t)?yi(t,e):Wi(t,e))throw new Error("Can not modify transaction, signatures exist.")}))}function Ro(t,e,r){if(!ji(t,e))throw new Error("Can not ".concat(r," for this input with the key ").concat(t.toString("hex")))}function Ho(t,e){var r=gr(ho.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 Lo(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 Vo=Lo(On,"Redeem script"),Do=Lo(Mn,"Witness script");function Ko(t,e,r,n){var i,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!r.every(No))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(),Qo(r,i,n,u,o),"__FEE_RATE"===t?n.__FEE_RATE:"__FEE"===t?n.__FEE:void 0}function Mo(t,e,r,n,i,o){var u=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],a=arguments.length>7?arguments[7]:void 0,s=ou(r);if(!function(t,e,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return Uo(1,t.partialSig);case"multisig":var n=Vr({output:e});return Uo(n.m,t.partialSig,n.pubkeys);case"nonstandard":return!0;default:return!1}}(e,r,s)&&u)throw new Error("Can not finalize input #".concat(t));return Fo(r,s,e.partialSig,n,i,o,a)}function Fo(t,e,r,n,i,o,u){var a,s,f=function(t,e,r){var n;switch(e){case"multisig":var i=function(t,e){return Vr({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=Vr({output:t,signatures:i});break;case"pubkey":n=Kr({output:t,signature:r[0].signature});break;case"pubkeyhash":n=Ji({output:t,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=Hn({output:t,pubkey:r[0].pubkey,signature:r[0].signature})}return n}(t,e,r),c=o?Mn({redeem:f}):null,h=i?On({redeem:c||f}):null;return n?(s=Di(c?c.witness:f?f.witness:null!=u?u:[ho.from([0])]),h&&(a=null==h?void 0:h.input)):a=h?null==h?void 0:h.input:f?f.input:Array.isArray(u)&&u[0]?u[0]:ho.from([1]),{finalScriptSig:a,finalScriptWitness:s}}function Go(t,e,r,n,i){var o=jo(e,(0,co.checkForInput)(t,e),n,!1,i),u=o.hash,a=o.sighashType;return Ro(r,o.script,"sign"),{hash:u,sighashType:a}}function jo(t,e,r,n,i){var o,u,a=r.__TX,s=e.sighashType||ei.SIGHASH_ALL;if(Yo(s,i),e.nonWitnessUtxo){var f=Zo(r,e,t),c=a.ins[t].hash,h=f.getHash();if(!c.equals(h))throw new Error("Non-witness UTXO hash for input #".concat(t," doesn't match the hash specified in the prevout"));var p=a.ins[t].index;u=f.outs[p]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}var l=nu(u.script,t,"input",e.redeemScript,e.witnessScript),d=l.meaningfulScript,y=l.type;if(["p2sh-p2wsh","p2wsh"].indexOf(y)>=0)o=a.hashForWitnessV0(t,d,u.value,s);else if(Bi(d)){var g=Ji({hash:d.slice(2)}).output;o=a.hashForWitnessV0(t,g,u.value,s)}else{if(void 0===e.nonWitnessUtxo&&!1===r.__UNSAFE_SIGN_NONSEGWIT)throw new Error("Input #".concat(t," has witnessUtxo but non-segwit script: ")+"".concat(d.toString("hex")));n||!1===r.__UNSAFE_SIGN_NONSEGWIT||console.warn("Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n*********************"),o=a.hashForSignature(t,d,s)}return{script:d,sighashType:s,hash:o}}function Wo(t,e,r){var n=eu(t,e,r).script;return Hi(n)?ho.from(n.subarray(2,34)):null}function Xo(t){return 64===t.length?t:ho.from(t.subarray(0,64))}function qo(t,e,r,n,i,o,u){var a=i.__TX,s=e.sighashType||ei.SIGHASH_DEFAULT;Yo(s,u);var f=r.map((function(t,e){return eu(e,t,i)})),c=f.map((function(t){return t.script})),h=f.map((function(t){return t.value})),p=[];if(e.tapInternalKey&&!o){var l=Wo(t,e,i)||ho.from([]);if(oi(n).equals(l)){var d=a.hashForWitnessV1(t,c,h,s);p.push({pubkey:n,hash:d})}}var y=(e.tapLeafScript||[]).filter((function(t){return ji(n,t.script)})).map((function(t){var e=Or({output:t.script,version:t.leafVersion});return Object.assign({hash:e},t)})).filter((function(t){return!o||o.equals(t.hash)})).map((function(e){var r=a.hashForWitnessV1(t,c,h,s,e.hash);return{pubkey:n,hash:r,leafHash:e.hash}}));return p.concat(y)}function Yo(t,e){if(e&&e.indexOf(t)<0){var r=function(t){var e=t&ei.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(31&t){case ei.SIGHASH_ALL:e+="SIGHASH_ALL";break;case ei.SIGHASH_SINGLE:e+="SIGHASH_SINGLE";break;case ei.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 zo(t,e,r){var n=(0,co.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 $o(t){var e=0;function r(){var r=_n.decode(t,e);return e+=_n.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 Jo(t,e,r){t.__NON_WITNESS_UTXO_BUF_CACHE[r]=e.nonWitnessUtxo,t.__NON_WITNESS_UTXO_TX_CACHE[r]=ei.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 Qo(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=$o(t.finalScriptWitness)),t.witnessUtxo)o+=t.witnessUtxo.value;else if(t.nonWitnessUtxo){var u=Zo(r,t,i),a=e.ins[i].index,s=u.outs[a];o+=s.value}}));var u=e.outs.reduce((function(t,e){return t+e.value}),0),a=o-u;if(!i&&a<0)throw new Error("Outputs are spending more than Inputs ".concat(o," < ").concat(u));var s=e.virtualSize();r.__FEE=a,r.__EXTRACTED_TX=e,r.__FEE_RATE=Math.floor(a/s)}function Zo(t,e,r){var n=t.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||Jo(t,e,r),n[r]}function tu(t,e,r){return eu(t,e,r).script}function eu(t,e,r){if(void 0!==e.witnessUtxo)return{script:e.witnessUtxo.script,value:e.witnessUtxo.value};if(void 0!==e.nonWitnessUtxo){var n=Zo(r,e,t).outs[r.__TX.ins[t].index];return{script:n.script,value:n.value}}throw new Error("Can't find pubkey in input without Utxo data")}function ru(t){return 33===t.length&&Yt(t)}function nu(t,e,r,n,i){var o,u=Ri(t),a=u&&n&&Ci(n),s=Ci(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,Vo(e,t,n,r),Do(e,n,i,r),iu(o)):s?(o=i,Do(e,t,i,r),iu(o)):u?(o=n,Vo(e,t,n,r)):o=t,{meaningfulScript:o,type:a?"p2sh-p2wsh":u?"p2sh":s?"p2wsh":"raw"}}function iu(t){if(Bi(t)||Ri(t))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function ou(t){return Bi(t)?"witnesspubkeyhash":xi(t)?"pubkeyhash":Ui(t)?"multisig":Ni(t)?"pubkey":"nonstandard"}function uu(t){return vo(Array(t).keys())}const au={networks:n,address:a,payments:h,script:u,crypto:s,Transaction:c};export{ao as Block,mr as BufferReader,vr as BufferWriter,ie as FUTURE_MAX_VERSION,oe as FUTURE_OPNET_VERSION,ee as FUTURE_SEGWIT_MAX_SIZE,ne as FUTURE_SEGWIT_MAX_VERSION,re as FUTURE_SEGWIT_MIN_SIZE,ue as FUTURE_SEGWIT_MIN_VERSION,ae as FUTURE_SEGWIT_VERSION_DIFF,Sr as LEAF_VERSION_TAPSCRIPT,Ir as MAX_TAPTREE_DEPTH,Yi as PaymentType,ko as Psbt,We as TAGGED_HASH_PREFIXES,je as TAGS,ct as TAPLEAF_VERSION_MASK,ei as Transaction,he as _toFutureSegwitAddress,a as address,Mi as bigIntTo32Bytes,Wi as checkInputForSig,ci as checkTaprootInputFields,yi as checkTaprootInputForSigs,hi as checkTaprootOutputFields,wr as cloneBuffer,s as crypto,Ki as decompressPublicKey,au as default,Ar as findScriptPath,pe as fromBase58Check,le as fromBech32,ge as fromOutputScript,Mo as getFinalScripts,qi as getPsigsFromInputFinalScripts,wi as getTapKeySigFromWitness,Fe as hash160,Ge as hash256,ze as initEccLib,Vi as isP2A,Ui as isP2MS,Li as isP2OP,Ni as isP2PK,xi as isP2PKH,Ri as isP2SHScript,Hi as isP2TR,Bi as isP2WPKH,Ci as isP2WSHScript,si as isTaprootInput,fi as isTaprootOutput,fe as isUnknownSegwitVersion,n as networks,W as opcodes,h as payments,Fo as prepareFinalScripts,ji as pubkeyInScript,Gi as pubkeyPositionInScript,Fi as pubkeysMatch,dr as readUInt64LE,gr as reverseBuffer,De as ripemd160,_r as rootHashFromPath,u as script,ai as serializeTaprootSignature,Ke as sha1,Me as sha256,Xi as signatureBlocksAction,Xe as taggedHash,ui as tapScriptFinalizer,di as tapTreeFromList,li as tapTreeToList,Pr as tapTweakHash,Or as tapleafHash,de as toBase58Check,ye as toBech32,ce as toFutureOPNetAddress,kr as toHashTree,we as toOutputScript,oi as toXOnly,pi as tweakInternalPubKey,Ur as tweakKey,f as varuint,Di as witnessStackToScriptWitness,yr as writeUInt64LE};
1
+ import { A as t, B as e, F as r, z as i, y as o, C as p, D as S, P as T, _ as c, e as n, X as E, a0 as u, o as I, w as P, q as _, a as F, c as h, H as f, f as R, K as k, j as d, a2 as m, x as A, h as U, V as l, M as O, U as g, N as y, O as B, S as H, T as N, Q as w, R as M, l as W, m as b, E as G, n as K, p as L, $ as V, Z as x, Y as X, s as C, a1 as D, k as v, v as z, u as Z, I as j, J as q, G as J, L as Q, t as Y, r as $, W as ss } from "./chunks/psbt-BIwOrKer.js";
2
+ import { L as ts, M as es, P as rs, k as is, i as os, r as ps, l as Ss, f as Ts, j as cs, t as ns } from "./chunks/payments-CgasufRS.js";
3
+ import { o as us, b as Is } from "./chunks/script-CROJPzz_.js";
4
+ import { d as _s, T as Fs, c as hs, h as fs, b as Rs, r as ks, s as ds, a as ms, t as As } from "./chunks/crypto-0PweVewC.js";
5
+ import { B as ls, T as Os } from "./chunks/transaction-DchBu35N.js";
6
+ import { f as ys, B as Bs, T as Hs, c as Ns, e as ws, r as Ms, d as Ws, w as bs } from "./chunks/utils-CO5kmxe9.js";
7
+ export {
8
+ ls as Block,
9
+ ys as BufferReader,
10
+ Bs as BufferWriter,
11
+ t as FUTURE_MAX_VERSION,
12
+ e as FUTURE_OPNET_VERSION,
13
+ r as FUTURE_SEGWIT_MAX_SIZE,
14
+ i as FUTURE_SEGWIT_MAX_VERSION,
15
+ o as FUTURE_SEGWIT_MIN_SIZE,
16
+ p as FUTURE_SEGWIT_MIN_VERSION,
17
+ S as FUTURE_SEGWIT_VERSION_DIFF,
18
+ ts as LEAF_VERSION_TAPSCRIPT,
19
+ es as MAX_TAPTREE_DEPTH,
20
+ rs as PaymentType,
21
+ T as Psbt,
22
+ _s as TAGGED_HASH_PREFIXES,
23
+ Fs as TAGS,
24
+ Hs as TAPLEAF_VERSION_MASK,
25
+ Os as Transaction,
26
+ c as _toFutureSegwitAddress,
27
+ n as address,
28
+ E as bigIntTo32Bytes,
29
+ u as checkInputForSig,
30
+ I as checkTaprootInputFields,
31
+ P as checkTaprootInputForSigs,
32
+ _ as checkTaprootOutputFields,
33
+ Ns as cloneBuffer,
34
+ hs as crypto,
35
+ F as decompressPublicKey,
36
+ h as default,
37
+ is as findScriptPath,
38
+ f as fromBase58Check,
39
+ R as fromBech32,
40
+ k as fromOutputScript,
41
+ d as getFinalScripts,
42
+ m as getPsigsFromInputFinalScripts,
43
+ A as getTapKeySigFromWitness,
44
+ fs as hash160,
45
+ Rs as hash256,
46
+ U as initEccLib,
47
+ l as isP2A,
48
+ O as isP2MS,
49
+ g as isP2OP,
50
+ y as isP2PK,
51
+ B as isP2PKH,
52
+ H as isP2SHScript,
53
+ N as isP2TR,
54
+ w as isP2WPKH,
55
+ M as isP2WSHScript,
56
+ W as isTaprootInput,
57
+ b as isTaprootOutput,
58
+ G as isUnknownSegwitVersion,
59
+ K as networks,
60
+ us as opcodes,
61
+ os as payments,
62
+ L as prepareFinalScripts,
63
+ V as pubkeyInScript,
64
+ x as pubkeyPositionInScript,
65
+ X as pubkeysMatch,
66
+ ws as readUInt64LE,
67
+ Ms as reverseBuffer,
68
+ ks as ripemd160,
69
+ ps as rootHashFromPath,
70
+ Is as script,
71
+ C as serializeTaprootSignature,
72
+ ds as sha1,
73
+ ms as sha256,
74
+ D as signatureBlocksAction,
75
+ As as taggedHash,
76
+ v as tapScriptFinalizer,
77
+ z as tapTreeFromList,
78
+ Z as tapTreeToList,
79
+ Ss as tapTweakHash,
80
+ Ts as tapleafHash,
81
+ j as toBase58Check,
82
+ q as toBech32,
83
+ J as toFutureOPNetAddress,
84
+ cs as toHashTree,
85
+ Q as toOutputScript,
86
+ Y as toXOnly,
87
+ $ as tweakInternalPubKey,
88
+ ns as tweakKey,
89
+ Ws as varuint,
90
+ ss as witnessStackToScriptWitness,
91
+ bs as writeUInt64LE
92
+ };