@smartledger/bsv 9.11.1 → 9.11.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.
- package/CHANGELOG.md +31 -0
- package/README.md +19 -19
- package/bsv-gdaf.min.js +2 -2
- package/bsv-ltp.min.js +1 -1
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +2 -2
- package/bsv.min.js +2 -2
- package/docs/AUDIT_SCOPE.md +3 -3
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/audit-rfq/cure53.txt +1 -1
- package/docs/audit-rfq/ncc-group.txt +1 -1
- package/docs/audit-rfq/trail-of-bits.txt +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/lib/script/script.js +14 -2
- package/package.json +1 -1
- package/version.js +1 -1
package/bsv-ltp.min.js
CHANGED
|
@@ -66,7 +66,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
66
66
|
`))}throw n}};function m1(e,t,r,n,i){if(!bc(t))throw new Qo("regexp","RegExp",t);var o=i==="match";if(typeof e!="string"||_c(t,e)!==o){if(r instanceof Error)throw r;var s=!r;r=r||(typeof e!="string"?'The "string" argument must be of type string. Received type '+"".concat(Lr(e)," (").concat(vc(e),")"):(o?"The input did not match the regular expression ":"The input was expected to not match the regular expression ")+"".concat(vc(t),`. Input:
|
|
67
67
|
|
|
68
68
|
`).concat(vc(e),`
|
|
69
|
-
`));var a=new yi({actual:e,expected:t,message:r,operator:i,stackStartFn:n});throw a.generatedMessage=s,a}}Ye.match=function e(t,r,n){m1(t,r,n,e,"match")};Ye.doesNotMatch=function e(t,r,n){m1(t,r,n,e,"doesNotMatch")};function v1(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];c1.apply(void 0,[v1,t.length].concat(t))}Ye.strict=e6(v1,Ye,{equal:Ye.strictEqual,deepEqual:Ye.deepStrictEqual,notEqual:Ye.notStrictEqual,notDeepEqual:Ye.notDeepStrictEqual});Ye.strict.strict=Ye.strict});var Ma=B((O5,S1)=>{"use strict";p();var Na=ze(),_1=Le(),es=wr(),it=function e(t){if(!(this instanceof e))return new e(t);if(!Na.isUndefined(t))if(d.Buffer.isBuffer(t))this.set({buf:t});else if(Na.isString(t)){var r=d.Buffer.from(t,"hex");if(r.length*2!==t.length)throw new TypeError("Invalid hex string");this.set({buf:r})}else if(Na.isObject(t)){var n=t;this.set(n)}else throw new TypeError("Unrecognized argument for BufferReader")};it.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this};it.prototype.eof=function(){return this.pos>=this.buf.length};it.prototype.finished=it.prototype.eof;it.prototype.read=function(e){_1.checkArgument(!Na.isUndefined(e),"Must specify a length");var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,t};it.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e};it.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e};it.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e};it.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e};it.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e};it.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e};it.prototype.readInt32LE=function(){var e=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,e};it.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=es.fromBuffer(e);return this.pos=this.pos+8,t};it.prototype.readUInt64LEBN=function(){var e=this.buf.readUInt32LE(this.pos),t=this.buf.readUInt32LE(this.pos+4),r=t*4294967296+e,n;if(r<=9007199254740991)n=new es(r);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);n=new es(i,10,"le")}return this.pos=this.pos+8,n};it.prototype.readVarintNum=function(){var e=this.readUInt8();switch(e){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var t=this.readUInt64LEBN(),r=t.toNumber();if(r<=Math.pow(2,53))return r;throw new Error("number too large to retain precision - use readVarintBN");default:return e}};it.prototype.readVarLengthBuffer=function(){var e=this.readVarintNum(),t=this.read(e);return _1.checkState(t.length===e,"Invalid length while reading varlength buffer. Expected to read: "+e+" and read "+t.length),t};it.prototype.readVarintBuf=function(){var e=this.buf.readUInt8(this.pos);switch(e){case 253:return this.read(3);case 254:return this.read(5);case 255:return this.read(9);default:return this.read(1)}};it.prototype.readVarintBN=function(){var e=this.readUInt8();switch(e){case 253:return new es(this.readUInt16LE());case 254:return new es(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new es(e)}};it.prototype.reverse=function(){for(var e=d.Buffer.alloc(this.buf.length),t=0;t<e.length;t++)e[t]=this.buf[this.buf.length-1-t];return this.buf=e,this};it.prototype.readReverse=function(e){Na.isUndefined(e)&&(e=this.buf.length);var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,d.Buffer.from(t).reverse()};S1.exports=it});var hp=B((T5,w1)=>{"use strict";p();var ts=ze(),ka=Le(),r6=pr();function Ne(e){if(!(this instanceof Ne))return new Ne(e);var t;if(ts.isNumber(e))t=e;else if(ts.isString(e))t=Ne.map[e];else throw new TypeError('Unrecognized num type: "'+typeof e+'" for Opcode');return r6.defineImmutable(this,{num:t}),this}Ne.fromBuffer=function(e){return ka.checkArgument(d.Buffer.isBuffer(e)),new Ne(+("0x"+e.toString("hex")))};Ne.fromNumber=function(e){return ka.checkArgument(ts.isNumber(e)),new Ne(e)};Ne.fromString=function(e){ka.checkArgument(ts.isString(e));var t=Ne.map[e];if(typeof t>"u")throw new TypeError("Invalid opcodestr");return new Ne(t)};Ne.prototype.toHex=function(){return this.num.toString(16)};Ne.prototype.toBuffer=function(){return d.Buffer.from(this.toHex(),"hex")};Ne.prototype.toNumber=function(){return this.num};Ne.prototype.toString=function(){var e=Ne.reverseMap[this.num];if(typeof e>"u")throw new Error("Opcode does not have a string representation");return e};Ne.smallInt=function(e){return ka.checkArgument(ts.isNumber(e),"Invalid Argument: n should be number"),ka.checkArgument(e>=0&&e<=16,"Invalid Argument: n must be between 0 and 16"),e===0?Ne("OP_0"):new Ne(Ne.map.OP_1+e-1)};Ne.map={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_SPLIT:127,OP_NUM2BIN:128,OP_BIN2NUM: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_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_SUBSTR:179,OP_LEFT:180,OP_RIGHT:181,OP_LSHIFTNUM:182,OP_RSHIFTNUM:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Ne.reverseMap=[];for(lp in Ne.map)Ne.reverseMap[Ne.map[lp]]=lp;var lp;ts.extend(Ne,Ne.map);Ne.isSmallIntOp=function(e){return e instanceof Ne&&(e=e.toNumber()),e===Ne.map.OP_0||e>=Ne.map.OP_1&&e<=Ne.map.OP_16};Ne.prototype.inspect=function(){return"<Opcode: "+this.toString()+", hex: "+this.toHex()+", decimal: "+this.num+">"};w1.exports=Ne});var nr=B((B5,x1)=>{"use strict";p();var Qi=wr(),n6=ze(),rr=Le(),i6=pr(),Oe=function e(t,r){if(!(this instanceof e))return new e(t,r);if(t instanceof Qi)this.set({r:t,s:r});else if(t){var n=t;this.set(n)}};Oe.prototype.set=function(e){return this.r=e.r||this.r||void 0,this.s=e.s||this.s||void 0,this.i=typeof e.i<"u"?e.i:this.i,this.compressed=typeof e.compressed<"u"?e.compressed:this.compressed,this.nhashtype=e.nhashtype||this.nhashtype||void 0,this};Oe.fromCompact=function(e){rr.checkArgument(d.Buffer.isBuffer(e),"Argument is expected to be a Buffer");var t=new Oe,r=!0,n=e.slice(0,1)[0]-27-4;n<0&&(r=!1,n=n+4);var i=e.slice(1,33),o=e.slice(33,65);return rr.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),rr.checkArgument(i.length===32,new Error("r must be 32 bytes")),rr.checkArgument(o.length===32,new Error("s must be 32 bytes")),t.compressed=r,t.i=n,t.r=Qi.fromBuffer(i),t.s=Qi.fromBuffer(o),t};Oe.fromDER=Oe.fromBuffer=function(e,t){var r=Oe.parseDER(e,t),n=new Oe;return n.r=r.r,n.s=r.s,n};Oe.fromTxFormat=function(e){var t=e.readUInt8(e.length-1),r=e.slice(0,e.length-1),n=Oe.fromDER(r,!1);return n.nhashtype=t,n};Oe.fromString=function(e){var t=d.Buffer.from(e,"hex");return Oe.fromDER(t)};function E1(e,t){rr.checkArgument(t.length>0,new Error("Length of "+e+" is zero")),rr.checkArgument(!(t[0]&128),new Error("Value of "+e+" is negative")),rr.checkArgument(!(t.length>1&&t[0]===0&&!(t[1]&128)),new Error("Value of "+e+" is excessively padded"))}Oe.parseDER=function(e,t){rr.checkArgument(d.Buffer.isBuffer(e),new Error("DER formatted signature should be a buffer")),n6.isUndefined(t)&&(t=!0);var r=e[0];rr.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=e[1],i=e.slice(2).length;rr.checkArgument(!t||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=e[2];rr.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var s=e[3],a=e.slice(4,4+s),f=Qi.fromBuffer(a),l=e[4]===0;rr.checkArgument(s===a.length,new Error("Length of r incorrect"));var m=e[4+s+0];rr.checkArgument(m===2,new Error("Integer byte for s should be 0x02"));var g=e[4+s+1],v=e.slice(4+s+2,4+s+2+g),E=Qi.fromBuffer(v),T=e[4+s+2]===0;rr.checkArgument(g===v.length,new Error("Length of s incorrect"));var M=4+s+2+g;rr.checkArgument(n===M-2,new Error("Length of signature incorrect")),t&&(E1("r",a),E1("s",v));var U={header:r,length:n,rheader:o,rlength:s,rneg:l,rbuf:a,r:f,sheader:m,slength:g,sneg:T,sbuf:v,s:E};return U};Oe.prototype.toCompact=function(e,t){if(e=typeof e=="number"?e:this.i,t=typeof t=="boolean"?t:this.compressed,!(e===0||e===1||e===2||e===3))throw new Error("i must be equal to 0, 1, 2, or 3");var r=e+27+4;t===!1&&(r=r-4);var n=d.Buffer.from([r]),i=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return d.Buffer.concat([n,i,o])};Oe.prototype.toBuffer=Oe.prototype.toDER=function(){var e=this.r.toBuffer(),t=this.s.toBuffer(),r=!!(e[0]&128),n=!!(t[0]&128),i=r?d.Buffer.concat([d.Buffer.from([0]),e]):e,o=n?d.Buffer.concat([d.Buffer.from([0]),t]):t,s=i.length,a=o.length,f=2+s+2+a,l=2,m=2,g=48,v=d.Buffer.concat([d.Buffer.from([g,f,l,s]),i,d.Buffer.from([m,a]),o]);return v};Oe.prototype.toString=function(){var e=this.toDER();return e.toString("hex")};Oe.isTxDER=function(e){if(e.length<9||e.length>73||e[0]!==48||e[1]!==e.length-3)return!1;var t=e[3];if(5+t>=e.length)return!1;var r=e[5+t];if(t+r+7!==e.length)return!1;var n=e.slice(4);if(e[2]!==2||t===0||n[0]&128||t>1&&n[0]===0&&!(n[1]&128))return!1;var i=e.slice(6+t);return!(e[6+t-2]!==2||r===0||i[0]&128||r>1&&i[0]===0&&!(i[1]&128))};Oe.prototype.hasLowS=function(){return!(this.s.lt(new Qi(1))||this.s.gt(new Qi("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};Oe.prototype.hasDefinedHashtype=function(){if(!i6.isNaturalNumber(this.nhashtype))return!1;var e=this.nhashtype&31;return!(e<Oe.SIGHASH_ALL||e>Oe.SIGHASH_SINGLE)};Oe.prototype.toTxFormat=function(){var e=this.toDER(),t=d.Buffer.alloc(1);return t.writeUInt8(this.nhashtype,0),d.Buffer.concat([e,t])};Oe.SIGHASH_ALL=1;Oe.SIGHASH_NONE=2;Oe.SIGHASH_SINGLE=3;Oe.SIGHASH_CHRONICLE=32;Oe.SIGHASH_FORKID=64;Oe.SIGHASH_ANYONECANPAY=128;Oe.prototype.isCanonical=function(){var e=fi(),t=e.getN().shrn(1);return this.s.lte(t)};Oe.prototype.toCanonical=function(){if(this.isCanonical())return new Oe({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var e=fi(),t=e.getN(),r=t.sub(this.s);return new Oe({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};Oe.prototype.validate=function(){if(!this.r||!this.s)throw new Error("Signature missing r or s component");if(this.r.isZero())throw new Error("Signature r component is zero");if(this.s.isZero())throw new Error("Signature s component is zero");var e=fi(),t=e.getN();if(this.r.gte(t))throw new Error("Signature r component >= curve order");if(this.s.gte(t))throw new Error("Signature s component >= curve order");if(this.r.isNeg())throw new Error("Signature r component is negative");if(this.s.isNeg())throw new Error("Signature s component is negative");return!0};Oe.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};Oe.prototype.applySecurityPatches=function(){var e=fi(),t=e.getN(),r=t.shrn(1);if(this.r.isZero()||this.s.isZero())throw new Error("Invalid signature: zero r or s");if(this.r.gte(t)||this.s.gte(t))throw new Error("Invalid signature: out of range");if(this.s.gt(r))throw new Error("Invalid signature: non-canonical (high) s");return this};x1.exports=Oe});var gp=B((M5,R1)=>{"use strict";p();var o6=ba(),Ur=ro(),s6=Ma(),dp=Jt(),$=hp(),to=Ar(),eo=nr(),I1=ya(),Xe=Le(),Re=ze(),pp=Jn(),A1=Nt(),a6=pr(),q=function e(t){if(!(this instanceof e))return new e(t);if(this.chunks=[],d.Buffer.isBuffer(t))return e.fromBuffer(t);if(t instanceof Ur)return e.fromAddress(t);if(t instanceof e)return e.fromBuffer(t.toBuffer());if(Re.isString(t))return e.fromString(t);Re.isObject(t)&&Re.isArray(t.chunks)&&this.set(t)};q.prototype.set=function(e){return Xe.checkArgument(Re.isObject(e)),Xe.checkArgument(Re.isArray(e.chunks)),this.chunks=e.chunks,this};q.fromBuffer=function(e){var t=new q;t.chunks=[];for(var r=new s6(e);!r.finished();)try{var n=r.readUInt8(),i,o;n>0&&n<$.OP_PUSHDATA1?(i=n,t.chunks.push({buf:r.read(i),len:i,opcodenum:n})):n===$.OP_PUSHDATA1?(i=r.readUInt8(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===$.OP_PUSHDATA2?(i=r.readUInt16LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===$.OP_PUSHDATA4?(i=r.readUInt32LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):t.chunks.push({opcodenum:n})}catch(s){throw s instanceof RangeError?new pp.Script.InvalidBuffer(e.toString("hex")):s}return t};q.prototype.toBuffer=function(){var e=this.chunks,t=0,r,n,i;for(r=0;r<e.length;r++)n=e[r],i=n.opcodenum,t+=1,n.buf&&(i<$.OP_PUSHDATA1?t+=Ec(n.buf):i===$.OP_PUSHDATA1?t+=1+Ec(n.buf):i===$.OP_PUSHDATA2?t+=2+Ec(n.buf):i===$.OP_PUSHDATA4&&(t+=4+Ec(n.buf)));var o=d.Buffer.alloc(t),s=0;for(r=0;r<e.length;r++)n=e[r],i=n.opcodenum,s=o.writeUInt8(n.opcodenum,s),n.buf&&(i<$.OP_PUSHDATA1?s+=n.buf.copy(o,s):i===$.OP_PUSHDATA1?(s=o.writeUInt8(n.len,s),s+=n.buf.copy(o,s)):i===$.OP_PUSHDATA2?(s=o.writeUInt16LE(n.len,s),s+=n.buf.copy(o,s)):i===$.OP_PUSHDATA4&&(s=o.writeUInt32LE(n.len,s),s+=n.buf.copy(o,s)));return o};function Ec(e){if(!d.Buffer.isBuffer(e))throw new o6.AssertionError({message:"chunk data must be a Buffer",actual:e,expected:"Buffer",operator:"isBuffer"});return e.length}function O1(e){if(/^0x[0-9a-fA-F]{2}$/.test(e)){var t=parseInt(e.slice(2),16);return t>$.OP_PUSHDATA4?t:void 0}}q.fromASM=function(e){var t=new q;if(t.chunks=[],e==="")return t;for(var r=e.split(" "),n=0;n<r.length;){var i=r[n],o=$(i),s=o.toNumber(),a=O1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(i==="0")s=0,t.chunks.push({opcodenum:s}),n=n+1;else if(i==="-1")s=$.OP_1NEGATE,t.chunks.push({opcodenum:s}),n=n+1;else if(Re.isUndefined(s)){var f=d.Buffer.from(r[n],"hex");if(f.toString("hex")!==r[n])throw new Error("invalid hex string in script");var l=f.length;l>=0&&l<$.OP_PUSHDATA1?s=l:l<Math.pow(2,8)?s=$.OP_PUSHDATA1:l<Math.pow(2,16)?s=$.OP_PUSHDATA2:l<Math.pow(2,32)&&(s=$.OP_PUSHDATA4),t.chunks.push({buf:f,len:f.length,opcodenum:s}),n=n+1}else t.chunks.push({opcodenum:s}),n=n+1}return t};q.fromHex=function(e){return new q(A1.Buffer.from(e,"hex"))};q.fromString=function(e){if(a6.isHexa(e)||e.length===0)return new q(A1.Buffer.from(e,"hex"));var t=new q;t.chunks=[];for(var r=e.split(" "),n=0;n<r.length;){var i=r[n],o=$(i),s=o.toNumber(),a=O1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(Re.isUndefined(s))if(s=parseInt(i),s>0&&s<$.OP_PUSHDATA1)t.chunks.push({buf:d.Buffer.from(r[n+1].slice(2),"hex"),len:s,opcodenum:s}),n=n+2;else throw new Error("Invalid script: "+JSON.stringify(e));else if(s===$.OP_PUSHDATA1||s===$.OP_PUSHDATA2||s===$.OP_PUSHDATA4){if(r[n+2].slice(0,2)!=="0x")throw new Error("Pushdata data must start with 0x");t.chunks.push({buf:d.Buffer.from(r[n+2].slice(2),"hex"),len:parseInt(r[n+1]),opcodenum:s}),n=n+3}else t.chunks.push({opcodenum:s}),n=n+1}return t};q.prototype._chunkToString=function(e,t){var r=e.opcodenum,n=t==="asm",i="";if(e.buf)!n&&(r===$.OP_PUSHDATA1||r===$.OP_PUSHDATA2||r===$.OP_PUSHDATA4)&&(i=i+" "+$(r).toString()),e.len>0&&(n?i=i+" "+e.buf.toString("hex"):i=i+" "+e.len+" 0x"+e.buf.toString("hex"));else if(typeof $.reverseMap[r]<"u")n?r===0?i=i+" 0":r===79?i=i+" -1":i=i+" "+$(r).toString():i=i+" "+$(r).toString();else{var o=r.toString(16);o.length%2!==0&&(o="0"+o),i=i+" 0x"+o}return i};q.prototype.toASM=function(){for(var e="",t=0;t<this.chunks.length;t++){var r=this.chunks[t];e+=this._chunkToString(r,"asm")}return e.substr(1)};q.prototype.toString=function(){for(var e="",t=0;t<this.chunks.length;t++){var r=this.chunks[t];e+=this._chunkToString(r)}return e.substr(1)};q.prototype.toHex=function(){return this.toBuffer().toString("hex")};q.prototype.inspect=function(){return"<Script: "+this.toString()+">"};q.prototype.isPublicKeyHashOut=function(){return!!(this.chunks.length===5&&this.chunks[0].opcodenum===$.OP_DUP&&this.chunks[1].opcodenum===$.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===$.OP_EQUALVERIFY&&this.chunks[4].opcodenum===$.OP_CHECKSIG)};q.prototype.isPublicKeyHashOutPrefix=function(){return!!(this.chunks.length>=5&&this.chunks[0].opcodenum===$.OP_DUP&&this.chunks[1].opcodenum===$.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===$.OP_EQUALVERIFY&&this.chunks[4].opcodenum===$.OP_CHECKSIG)};q.prototype.isPublicKeyHashIn=function(){if(this.chunks.length===2){var e=this.chunks[0].buf,t=this.chunks[1].buf;if(e&&e.length&&e[0]===48&&t&&t.length){var r=t[0];if((r===4||r===6||r===7)&&t.length===65)return!0;if((r===3||r===2)&&t.length===33)return!0}}return!1};q.prototype.getPublicKey=function(){return Xe.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output"),this.chunks[0].buf};q.prototype.getPublicKeyHash=function(){return Xe.checkState(this.isPublicKeyHashOut(),"Can't retrieve PublicKeyHash from a non-PKH output"),this.chunks[2].buf};q.prototype.isPublicKeyOut=function(){if(this.chunks.length===2&&this.chunks[0].buf&&this.chunks[0].buf.length&&this.chunks[1].opcodenum===$.OP_CHECKSIG){var e=this.chunks[0].buf,t=e[0],r=!1;if(((t===4||t===6||t===7)&&e.length===65||(t===3||t===2)&&e.length===33)&&(r=!0),r)return to.isValid(e)}return!1};q.prototype.isPublicKeyIn=function(){if(this.chunks.length===1){var e=this.chunks[0].buf;if(e&&e.length&&e[0]===48)return!0}return!1};q.prototype.isScriptHashOut=function(){var e=this.toBuffer();return e.length===23&&e[0]===$.OP_HASH160&&e[1]===20&&e[e.length-1]===$.OP_EQUAL};q.prototype.isScriptHashIn=function(){if(this.chunks.length<=1)return!1;var e=this.chunks[this.chunks.length-1],t=e.buf;if(!t)return!1;var r;try{r=q.fromBuffer(t)}catch(i){if(i instanceof pp.Script.InvalidBuffer)return!1;throw i}var n=r.classify();return n!==q.types.UNKNOWN};q.prototype.isMultisigOut=function(){return this.chunks.length>3&&$.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)})&&$.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===$.OP_CHECKMULTISIG};q.prototype.isMultisigIn=function(){return this.chunks.length>=2&&this.chunks[0].opcodenum===0&&this.chunks.slice(1,this.chunks.length).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)&&eo.isTxDER(e.buf)})};q.prototype.isDataOut=function(){var e=this.chunks.length>=1&&this.chunks[0].opcodenum===$.OP_RETURN;if(!e)return!1;var t=this.chunks.slice(1),r=new q({chunks:t});return r.isPushOnly()};q.prototype.isSafeDataOut=function(){if(this.chunks.length<2||this.chunks[0].opcodenum!==$.OP_FALSE)return!1;var e=this.chunks.slice(1),t=new q({chunks:e});return t.isDataOut()};q.prototype.getData=function(){if(this.isSafeDataOut()){var e=this.chunks.slice(2),t=e.map(r=>r.buf);return t}if(this.isDataOut()||this.isScriptHashOut())return Re.isUndefined(this.chunks[1])?d.Buffer.alloc(0):d.Buffer.from(this.chunks[1].buf);if(this.isPublicKeyHashOut())return d.Buffer.from(this.chunks[2].buf);throw new Error("Unrecognized script type to get data from")};q.prototype.isPushOnly=function(){return Re.every(this.chunks,function(e){return e.opcodenum<=$.OP_16||e.opcodenum===$.OP_PUSHDATA1||e.opcodenum===$.OP_PUSHDATA2||e.opcodenum===$.OP_PUSHDATA4})};q.types={};q.types.UNKNOWN="Unknown";q.types.PUBKEY_OUT="Pay to public key";q.types.PUBKEY_IN="Spend from public key";q.types.PUBKEYHASH_OUT="Pay to public key hash";q.types.PUBKEYHASH_IN="Spend from public key hash";q.types.SCRIPTHASH_OUT="Pay to script hash";q.types.SCRIPTHASH_IN="Spend from script hash";q.types.MULTISIG_OUT="Pay to multisig";q.types.MULTISIG_IN="Spend from multisig";q.types.DATA_OUT="Data push";q.types.SAFE_DATA_OUT="Safe data push";q.OP_RETURN_STANDARD_SIZE=220;q.prototype.classify=function(){if(this._isInput)return this.classifyInput();if(this._isOutput)return this.classifyOutput();var e=this.classifyOutput();return e!==q.types.UNKNOWN?e:this.classifyInput()};q.outputIdentifiers={};q.outputIdentifiers.PUBKEY_OUT=q.prototype.isPublicKeyOut;q.outputIdentifiers.PUBKEYHASH_OUT=q.prototype.isPublicKeyHashOut;q.outputIdentifiers.MULTISIG_OUT=q.prototype.isMultisigOut;q.outputIdentifiers.SCRIPTHASH_OUT=q.prototype.isScriptHashOut;q.outputIdentifiers.DATA_OUT=q.prototype.isDataOut;q.outputIdentifiers.SAFE_DATA_OUT=q.prototype.isSafeDataOut;q.prototype.classifyOutput=function(){for(var e in q.outputIdentifiers)if(q.outputIdentifiers[e].bind(this)())return q.types[e];return q.types.UNKNOWN};q.inputIdentifiers={};q.inputIdentifiers.PUBKEY_IN=q.prototype.isPublicKeyIn;q.inputIdentifiers.PUBKEYHASH_IN=q.prototype.isPublicKeyHashIn;q.inputIdentifiers.MULTISIG_IN=q.prototype.isMultisigIn;q.inputIdentifiers.SCRIPTHASH_IN=q.prototype.isScriptHashIn;q.prototype.classifyInput=function(){for(var e in q.inputIdentifiers)if(q.inputIdentifiers[e].bind(this)())return q.types[e];return q.types.UNKNOWN};q.prototype.isStandard=function(){return this.classify()!==q.types.UNKNOWN};q.prototype.prepend=function(e){return this._addByType(e,!0),this};q.prototype.equals=function(e){if(Xe.checkState(e instanceof q,"Must provide another script"),this.chunks.length!==e.chunks.length)return!1;var t;for(t=0;t<this.chunks.length;t++){if(d.Buffer.isBuffer(this.chunks[t].buf)&&!d.Buffer.isBuffer(e.chunks[t].buf)||d.Buffer.isBuffer(this.chunks[t].buf)&&!this.chunks[t].buf.equals(e.chunks[t].buf))return!1;if(this.chunks[t].opcodenum!==e.chunks[t].opcodenum)return!1}return!0};q.prototype.add=function(e){return this._addByType(e,!1),this};q.prototype._addByType=function(e,t){if(typeof e=="string")this._addOpcode(e,t);else if(typeof e=="number")this._addOpcode(e,t);else if(e instanceof $)this._addOpcode(e,t);else if(d.Buffer.isBuffer(e))this._addBuffer(e,t);else if(e instanceof q)this.chunks=this.chunks.concat(e.chunks);else if(typeof e=="object")this._insertAtPosition(e,t);else throw new Error("Invalid script chunk")};q.prototype._insertAtPosition=function(e,t){t?this.chunks.unshift(e):this.chunks.push(e)};q.prototype._addOpcode=function(e,t){var r;return typeof e=="number"?r=e:e instanceof $?r=e.toNumber():r=$(e).toNumber(),this._insertAtPosition({opcodenum:r},t),this};q.prototype._addBuffer=function(e,t){var r,n=e.length;if(n>=0&&n<$.OP_PUSHDATA1)r=n;else if(n<Math.pow(2,8))r=$.OP_PUSHDATA1;else if(n<Math.pow(2,16))r=$.OP_PUSHDATA2;else if(n<Math.pow(2,32))r=$.OP_PUSHDATA4;else throw new Error("You can't push that much data");return this._insertAtPosition({buf:e,len:n,opcodenum:r},t),this};q.prototype.removeCodeseparators=function(){for(var e=[],t=0;t<this.chunks.length;t++)this.chunks[t].opcodenum!==$.OP_CODESEPARATOR&&e.push(this.chunks[t]);return this.chunks=e,this};q.buildMultisigOut=function(e,t,r){Xe.checkArgument(t<=e.length,"Number of required signatures must be less than or equal to the number of public keys"),r=r||{};var n=new q;n.add($.smallInt(t)),e=Re.map(e,to);var i=e;r.noSorting||(i=e.map(a=>a.toString("hex")).sort().map(a=>new to(a)));for(var o=0;o<i.length;o++){var s=i[o];n.add(s.toBuffer())}return n.add($.smallInt(e.length)),n.add($.OP_CHECKMULTISIG),n};q.buildMultisigIn=function(e,t,r,n){Xe.checkArgument(Re.isArray(e)),Xe.checkArgument(Re.isNumber(t)),Xe.checkArgument(Re.isArray(r)),n=n||{};var i=new q;return i.add($.OP_0),Re.each(r,function(o){Xe.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i};q.buildP2SHMultisigIn=function(e,t,r,n){Xe.checkArgument(Re.isArray(e)),Xe.checkArgument(Re.isNumber(t)),Xe.checkArgument(Re.isArray(r)),n=n||{};var i=new q;return i.add($.OP_0),Re.each(r,function(o){Xe.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i.add((n.cachedMultisig||q.buildMultisigOut(e,t,n)).toBuffer()),i};q.buildPublicKeyHashOut=function(e){Xe.checkArgument(!Re.isUndefined(e)),Xe.checkArgument(e instanceof to||e instanceof Ur||Re.isString(e)),e instanceof to?e=e.toAddress():Re.isString(e)&&(e=new Ur(e));var t=new q;return t.add($.OP_DUP).add($.OP_HASH160).add(e.hashBuffer).add($.OP_EQUALVERIFY).add($.OP_CHECKSIG),t._network=e.network,t};q.buildPublicKeyOut=function(e){Xe.checkArgument(e instanceof to);var t=new q;return t.add(e.toBuffer()).add($.OP_CHECKSIG),t};q.buildDataOut=function(e,t){Xe.checkArgument(Re.isUndefined(e)||Re.isString(e)||Re.isArray(e)||d.Buffer.isBuffer(e));var r=e;Re.isArray(r)||(r=[e]);var n=new q;n.add($.OP_RETURN);for(let i of r)Xe.checkArgument(Re.isUndefined(i)||Re.isString(i)||d.Buffer.isBuffer(i)),Re.isString(i)&&(i=d.Buffer.from(i,t)),Re.isUndefined(i)||n.add(i);return n};q.buildSafeDataOut=function(e,t){var r=q.buildDataOut(e,t),n=new q;return n.add($.OP_FALSE),n.add(r),n};q.buildScriptHashOut=function(e){Xe.checkArgument(e instanceof q||e instanceof Ur&&e.isPayToScriptHash());var t=new q;return t.add($.OP_HASH160).add(e instanceof Ur?e.hashBuffer:dp.sha256ripemd160(e.toBuffer())).add($.OP_EQUAL),t._network=e._network||e.network,t};q.buildPublicKeyIn=function(e,t){Xe.checkArgument(e instanceof eo||d.Buffer.isBuffer(e)),Xe.checkArgument(Re.isUndefined(t)||Re.isNumber(t)),e instanceof eo&&(e=e.toBuffer());var r=new q;return r.add(d.Buffer.concat([e,d.Buffer.from([(t||eo.SIGHASH_ALL)&255])])),r};q.buildPublicKeyHashIn=function(e,t,r){Xe.checkArgument(t instanceof eo||d.Buffer.isBuffer(t)),Xe.checkArgument(Re.isUndefined(r)||Re.isNumber(r)),t instanceof eo&&(t=t.toBuffer());var n=new q().add(d.Buffer.concat([t,d.Buffer.from([(r||eo.SIGHASH_ALL)&255])])).add(new to(e).toBuffer());return n};q.empty=function(){return new q};q.prototype.toScriptHashOut=function(){return q.buildScriptHashOut(this)};q.fromAddress=function(e){if(e=Ur(e),e.isPayToScriptHash())return q.buildScriptHashOut(e);if(e.isPayToPublicKeyHash())return q.buildPublicKeyHashOut(e);throw new pp.Script.UnrecognizedAddress(e)};q.prototype.getAddressInfo=function(e){if(this._isInput)return this._getInputAddressInfo();if(this._isOutput)return this._getOutputAddressInfo();var t=this._getOutputAddressInfo();return t||this._getInputAddressInfo()};q.prototype._getOutputAddressInfo=function(){var e={};if(this.isScriptHashOut())e.hashBuffer=this.getData(),e.type=Ur.PayToScriptHash;else if(this.isPublicKeyHashOut())e.hashBuffer=this.getData(),e.type=Ur.PayToPublicKeyHash;else return!1;return e};q.prototype._getInputAddressInfo=function(){var e={};if(this.isPublicKeyHashIn())e.hashBuffer=dp.sha256ripemd160(this.chunks[1].buf),e.type=Ur.PayToPublicKeyHash;else if(this.isScriptHashIn())e.hashBuffer=dp.sha256ripemd160(this.chunks[this.chunks.length-1].buf),e.type=Ur.PayToScriptHash;else return!1;return e};q.prototype.toAddress=function(e){var t=this.getAddressInfo();return t?(t.network=I1.get(e)||this._network||I1.defaultNetwork,new Ur(t)):!1};q.prototype.findAndDelete=function(e){for(var t=e.toBuffer(),r=t.length?t[0]:-1,n=0;n<this.chunks.length;n++){var i=this.chunks[n];if(!(i.opcodenum!==r&&u6(i))){var o=q({chunks:[i]}).toBuffer();t.equals(o)&&(this.chunks.splice(n,1),n--)}}return this};function u6(e){var t=e.opcodenum;if(typeof t!="number"||!Number.isInteger(t)||t<0||t>255)return!1;if(!e.buf||t>$.OP_PUSHDATA4)return!0;if(!d.Buffer.isBuffer(e.buf))return!1;var r=e.len;return t===$.OP_PUSHDATA1?Number.isInteger(r)&&r>=0&&r<=255:t===$.OP_PUSHDATA2?Number.isInteger(r)&&r>=0&&r<=65535:t===$.OP_PUSHDATA4?Number.isInteger(r)&&r>=0&&r<=4294967295:!0}q.prototype.checkMinimalPush=function(e){var t=this.chunks[e],r=t.buf,n=t.opcodenum;return r?r.length===0?n===$.OP_0:r.length===1&&r[0]>=1&&r[0]<=16?n===$.OP_1+(r[0]-1):r.length===1&&r[0]===129?n===$.OP_1NEGATE:r.length<=75?n===r.length:r.length<=255?n===$.OP_PUSHDATA1:r.length<=65535?n===$.OP_PUSHDATA2:!0:!0};q.prototype._decodeOP_N=function(e){if(e===$.OP_0)return 0;if(e>=$.OP_1&&e<=$.OP_16)return e-($.OP_1-1);throw new Error("Invalid opcode: "+JSON.stringify(e))};q.prototype.getSignatureOperationsCount=function(e){e=Re.isUndefined(e)?!0:e;var t=this,r=0,n=$.OP_INVALIDOPCODE;return Re.each(t.chunks,function(o){var s=o.opcodenum;s===$.OP_CHECKSIG||s===$.OP_CHECKSIGVERIFY?r++:(s===$.OP_CHECKMULTISIG||s===$.OP_CHECKMULTISIGVERIFY)&&(e&&n>=$.OP_1&&n<=$.OP_16?r+=t._decodeOP_N(n):r+=20),n=s}),r};R1.exports=q});var rs=B((C5,P1)=>{"use strict";p();var T1=ba(),ot=function e(t){if(!(this instanceof e))return new e(t);this.bufLen=0,t?this.set(t):this.bufs=[]};ot.prototype.set=function(e){return this.bufs=e.bufs||this.bufs||[],this.bufLen=this.bufs.reduce(function(t,r){return t+r.length},0),this};ot.prototype.toBuffer=function(){return this.concat()};ot.prototype.concat=function(){return d.Buffer.concat(this.bufs,this.bufLen)};ot.prototype.write=function(e){return T1(d.Buffer.isBuffer(e)),this.bufs.push(e),this.bufLen+=e.length,this};ot.prototype.writeReverse=function(e){return T1(d.Buffer.isBuffer(e)),this.bufs.push(d.Buffer.from(e).reverse()),this.bufLen+=e.length,this};ot.prototype.writeUInt8=function(e){var t=d.Buffer.alloc(1);return t.writeUInt8(e,0),this.write(t),this};ot.prototype.writeUInt16BE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16BE(e,0),this.write(t),this};ot.prototype.writeUInt16LE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16LE(e,0),this.write(t),this};ot.prototype.writeUInt32BE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32BE(e,0),this.write(t),this};ot.prototype.writeInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeInt32LE(e,0),this.write(t),this};ot.prototype.writeUInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32LE(e,0),this.write(t),this};ot.prototype.writeUInt64BEBN=function(e){var t=e.toBuffer({size:8});return this.write(t),this};ot.prototype.writeUInt64LEBN=function(e){var t=e.toBuffer({size:8});return this.writeReverse(t),this};ot.prototype.writeVarintNum=function(e){var t=ot.varintBufNum(e);return this.write(t),this};ot.prototype.writeVarintBN=function(e){var t=ot.varintBufBN(e);return this.write(t),this};ot.varintBufNum=function(e){var t;return e<253?(t=d.Buffer.alloc(1),t.writeUInt8(e,0)):e<65536?(t=d.Buffer.alloc(3),t.writeUInt8(253,0),t.writeUInt16LE(e,1)):e<4294967296?(t=d.Buffer.alloc(5),t.writeUInt8(254,0),t.writeUInt32LE(e,1)):(t=d.Buffer.alloc(9),t.writeUInt8(255,0),t.writeInt32LE(e&-1,1),t.writeUInt32LE(Math.floor(e/4294967296),5)),t};ot.varintBufBN=function(e){var t,r=e.toNumber();if(r<253)t=d.Buffer.alloc(1),t.writeUInt8(r,0);else if(r<65536)t=d.Buffer.alloc(3),t.writeUInt8(253,0),t.writeUInt16LE(r,1);else if(r<4294967296)t=d.Buffer.alloc(5),t.writeUInt8(254,0),t.writeUInt32LE(r,1);else{var n=new ot;n.writeUInt8(255),n.writeUInt64LEBN(e),t=n.concat()}return t};P1.exports=ot});var Ca=B((D5,M1)=>{"use strict";p();var B1=rs(),N1=Ma(),f6=wr(),Fr=function e(t){if(!(this instanceof e))return new e(t);if(d.Buffer.isBuffer(t))this.buf=t;else if(typeof t=="number"){var r=t;this.fromNumber(r)}else if(t instanceof f6){var n=t;this.fromBN(n)}else if(t){var i=t;this.set(i)}};Fr.prototype.set=function(e){return this.buf=e.buf||this.buf,this};Fr.prototype.fromString=function(e){return this.set({buf:d.Buffer.from(e,"hex")}),this};Fr.prototype.toString=function(){return this.buf.toString("hex")};Fr.prototype.fromBuffer=function(e){return this.buf=e,this};Fr.prototype.fromBufferReader=function(e){return this.buf=e.readVarintBuf(),this};Fr.prototype.fromBN=function(e){return this.buf=B1().writeVarintBN(e).concat(),this};Fr.prototype.fromNumber=function(e){return this.buf=B1().writeVarintNum(e).concat(),this};Fr.prototype.toBuffer=function(){return this.buf};Fr.prototype.toBN=function(){return N1(this.buf).readVarintBN()};Fr.prototype.toNumber=function(){return N1(this.buf).readVarintNum()};M1.exports=Fr});var Cn=B((F5,C1)=>{"use strict";p();var xc=ze(),yp=wr(),k1=Nt(),Ic=pr(),c6=rs(),l6=Ca(),mp=qr(),vp=Le(),h6=Jn(),d6=9007199254740991;function jt(e){if(!(this instanceof jt))return new jt(e);if(xc.isObject(e))if(this.satoshis=e.satoshis,d.Buffer.isBuffer(e.script))this._scriptBuffer=e.script;else{var t;xc.isString(e.script)&&Ic.isHexa(e.script)?t=k1.Buffer.from(e.script,"hex"):t=e.script,this.setScript(t)}else throw new TypeError("Unrecognized argument for Output")}Object.defineProperty(jt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this._script?this._script:(this.setScriptFromBuffer(this._scriptBuffer),this._script)}});Object.defineProperty(jt.prototype,"satoshis",{configurable:!1,enumerable:!0,get:function(){return this._satoshis},set:function(e){e instanceof yp?(this._satoshisBN=e,this._satoshis=e.toNumber()):xc.isString(e)?(this._satoshis=parseInt(e),this._satoshisBN=yp.fromNumber(this._satoshis)):(vp.checkArgument(Ic.isNaturalNumber(e),"Output satoshis is not a natural number"),this._satoshisBN=yp.fromNumber(e),this._satoshis=e),vp.checkState(Ic.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});jt.prototype.invalidSatoshis=function(){return this._satoshis>d6?"transaction txout satoshis greater than max safe integer":this._satoshis!==this._satoshisBN.toNumber()?"transaction txout satoshis has corrupted value":this._satoshis<0?"transaction txout negative":!1};Object.defineProperty(jt.prototype,"satoshisBN",{configurable:!1,enumerable:!0,get:function(){return this._satoshisBN},set:function(e){this._satoshisBN=e,this._satoshis=e.toNumber(),vp.checkState(Ic.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});jt.prototype.toObject=jt.prototype.toJSON=function(){var t={satoshis:this.satoshis};return t.script=this._scriptBuffer.toString("hex"),t};jt.fromObject=function(e){return new jt(e)};jt.prototype.setScriptFromBuffer=function(e){this._scriptBuffer=e;try{this._script=mp.fromBuffer(this._scriptBuffer),this._script._isOutput=!0}catch(t){if(t instanceof h6.Script.InvalidBuffer)this._script=null;else throw t}};jt.prototype.setScript=function(e){if(e instanceof mp)this._scriptBuffer=e.toBuffer(),this._script=e,this._script._isOutput=!0;else if(xc.isString(e))this._script=mp.fromString(e),this._scriptBuffer=this._script.toBuffer(),this._script._isOutput=!0;else if(d.Buffer.isBuffer(e))this.setScriptFromBuffer(e);else throw new TypeError("Invalid argument type: script");return this};jt.prototype.inspect=function(){var e;return this.script?e=this.script.inspect():e=this._scriptBuffer.toString("hex"),"<Output ("+this.satoshis+" sats) "+e+">"};jt.fromBufferReader=function(e){var t={};t.satoshis=e.readUInt64LEBN();var r=e.readVarintNum();return r!==0?t.script=e.read(r):t.script=k1.Buffer.from([]),new jt(t)};jt.prototype.toBufferWriter=function(e){e||(e=new c6),e.writeUInt64LEBN(this._satoshisBN);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e};jt.prototype.getSize=function(){var e=this.script.toBuffer().length,t=l6(e).toBuffer().length;return 8+t+e};C1.exports=jt});var La=B((H5,L1)=>{"use strict";p();var gr=wr(),cn=fi(),p6=nr(),g6=Ar(),y6=Qs(),mi=Jt(),m6=ze(),bp=Le(),Ke=function e(t){if(!(this instanceof e))return new e(t);t&&this.set(t)};Object.defineProperty(Ke.prototype,"k",{get:function(){return this._k},set:function(e){this._k=e,this._kFresh=!0},enumerable:!0,configurable:!0});Ke.prototype.set=function(e){if(this.hashbuf=e.hashbuf||this.hashbuf,this.endian=e.endian||this.endian,this.privkey=e.privkey||this.privkey,this.pubkey=e.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey),e.sig)if(d.Buffer.isBuffer(e.sig)){var t=nr();this.sig=t.fromDER(e.sig)}else this.sig=e.sig;else this.sig=this.sig;return e.k&&(this.k=e.k),this.verified=e.verified||this.verified,this};Ke.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()};Ke.prototype.calci=function(){for(var e=0;e<4;e++){this.sig.i=e;var t;try{t=this.toPublicKey()}catch(r){console.error(r);continue}if(t.point.eq(this.pubkey.point))return this.sig.compressed=this.pubkey.compressed,this}throw this.sig.i=void 0,new Error("Unable to find valid recovery factor")};Ke.fromString=function(e){var t=JSON.parse(e);return new Ke(t)};Ke.prototype.randomK=function(){var e=cn.getN(),t;do t=gr.fromBuffer(y6.getRandomBuffer(32));while(!(t.lt(e)&&t.gt(gr.Zero)));return this.k=t,this};Ke.prototype.deterministicK=function(e){m6.isUndefined(e)&&(e=0);var t=d.Buffer.alloc(32);t.fill(1);var r=d.Buffer.alloc(32);r.fill(0);var n=this.privkey.bn.toBuffer({size:32}),i=this.endian==="little"?d.Buffer.from(this.hashbuf).reverse():this.hashbuf;r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0]),n,i]),r),t=mi.sha256hmac(t,r),r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([1]),n,i]),r),t=mi.sha256hmac(t,r),t=mi.sha256hmac(t,r);for(var o=gr.fromBuffer(t),s=cn.getN(),a=0;a<e||!(o.lt(s)&&o.gt(gr.Zero));a++)r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0])]),r),t=mi.sha256hmac(t,r),t=mi.sha256hmac(t,r),o=gr.fromBuffer(t);return this.k=o,this};Ke.prototype.toPublicKey=function(){var e=this.sig.i;bp.checkArgument(e===0||e===1||e===2||e===3,new Error("i must be equal to 0, 1, 2, or 3"));var t=gr.fromBuffer(this.hashbuf),r=this.sig.r,n=this.sig.s,i=e&1,o=e>>1,s=cn.getN(),a=cn.getG(),f=o?r.add(s):r,l=cn.fromX(i,f),m=l.mul(s);if(!m.isInfinity())throw new Error("nR is not a valid curve point");var g=t.neg().umod(s),v=r.invm(s),E=l.mul(n).add(a.mul(g)).mul(v),T=g6.fromPoint(E,this.sig.compressed);return T};Ke.prototype.sigError=function(){if(!d.Buffer.isBuffer(this.hashbuf)||this.hashbuf.length!==32)return"hashbuf must be a 32 byte buffer";var e=this.sig.r,t=this.sig.s,r=cn.getN();try{if(e.lte(gr.Zero)||t.lte(gr.Zero)||e.gte(r)||t.gte(r))return"r and s not in range";var n=gr.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:void 0),i=t.invm(r),o=i.mul(n).umod(r),s=i.mul(e).umod(r),a=cn.getG().mulAdd(o,this.pubkey.point,s);return a.isInfinity()?"p is infinity":a.getX().umod(r).cmp(e)!==0?"Invalid signature":!1}catch(f){return"Signature security validation failed: "+f.message}};Ke.toLowS=function(e){return e.gt(gr.fromBuffer(d.Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=cn.getN().sub(e)),e};Ke.prototype._findSignature=function(e,t){var r=cn.getN(),n=cn.getG(),i=0,o,s,a,f;do(!this.k||!this._kFresh||i>0)&&this.deterministicK(i),i++,o=this.k,s=n.mul(o),a=s.x.umod(r),f=o.invm(r).mul(t.add(e.mul(a))).umod(r);while(a.cmp(gr.Zero)<=0||f.cmp(gr.Zero)<=0);return this._kFresh=!1,f=Ke.toLowS(f),{s:f,r:a}};Ke.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;bp.checkState(e&&t&&r,new Error("invalid parameters")),bp.checkState(d.Buffer.isBuffer(e)&&e.length===32,new Error("hashbuf must be a 32 byte buffer"));var n=gr.fromBuffer(e,this.endian?{endian:this.endian}:void 0),i=this._findSignature(r,n);return i.compressed=this.pubkey.compressed,this.sig=new p6(i),this};Ke.prototype.signRandomK=function(){return this.randomK(),this.sign()};Ke.prototype.toString=function(){var e={};return this.hashbuf&&(e.hashbuf=this.hashbuf.toString("hex")),this.privkey&&(e.privkey=this.privkey.toString()),this.pubkey&&(e.pubkey=this.pubkey.toString()),this.sig&&(e.sig=this.sig.toString()),this.k&&(e.k=this.k.toString()),JSON.stringify(e)};Ke.prototype.verify=function(){return this.verified=!this.sigError(),this.verified};Ke.prototype.verifyBool=function(){return this.verify()===!0};Ke.sign=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).sign().sig};Ke.signWithCalcI=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).sign().calci().sig};Ke.signRandomK=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).signRandomK().sig};Ke.verify=function(e,t,r,n){return Ke().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify()};L1.exports=Ke});var ns=B((K5,q1)=>{"use strict";p();var vi=ze(),v6=Le(),Da=Jn(),b6=rs(),_p=Nt(),U1=pr(),Ac=qr(),_6=bi(),D1=Cn(),Oc=4294967295,S6=Oc-2,F1=Oc,w6=Oc-1;function Ge(e){if(!(this instanceof Ge))return new Ge(e);if(e)return this._fromObject(e)}Ge.MAXINT=Oc;Ge.DEFAULT_SEQNUMBER=F1;Ge.DEFAULT_LOCKTIME_SEQNUMBER=w6;Ge.DEFAULT_RBF_SEQNUMBER=S6;Ge.BASE_SIZE=40;Object.defineProperty(Ge.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this.isNull()?null:(this._script||(this._script=new Ac(this._scriptBuffer),this._script._isInput=!0),this._script)}});Ge.fromObject=function(e){v6.checkArgument(vi.isObject(e));var t=new Ge;return t._fromObject(e)};Ge.prototype._fromObject=function(e){var t;if(vi.isString(e.prevTxId)&&U1.isHexa(e.prevTxId)?t=_p.Buffer.from(e.prevTxId,"hex"):t=e.prevTxId,this.output=e.output?e.output instanceof D1?e.output:new D1(e.output):void 0,this.prevTxId=t||e.txidbuf,this.outputIndex=vi.isUndefined(e.outputIndex)?e.txoutnum:e.outputIndex,this.sequenceNumber=vi.isUndefined(e.sequenceNumber)?vi.isUndefined(e.seqnum)?F1:e.seqnum:e.sequenceNumber,vi.isUndefined(e.script)&&vi.isUndefined(e.scriptBuffer))throw new Da.Transaction.Input.MissingScript;return this.setScript(e.scriptBuffer||e.script),this};Ge.prototype.toObject=Ge.prototype.toJSON=function(){var t={prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,sequenceNumber:this.sequenceNumber,script:this._scriptBuffer.toString("hex")};return this.script&&(t.scriptString=this.script.toString()),this.output&&(t.output=this.output.toObject()),t};Ge.fromBufferReader=function(e){var t=new Ge;return t.prevTxId=e.readReverse(32),t.outputIndex=e.readUInt32LE(),t._scriptBuffer=e.readVarLengthBuffer(),t.sequenceNumber=e.readUInt32LE(),t};Ge.prototype.toBufferWriter=function(e){e||(e=new b6),e.writeReverse(this.prevTxId),e.writeUInt32LE(this.outputIndex);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e.writeUInt32LE(this.sequenceNumber),e};Ge.prototype.setScript=function(e){if(this._script=null,e instanceof Ac)this._script=e,this._script._isInput=!0,this._scriptBuffer=e.toBuffer();else if(e===null)this._script=Ac.empty(),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(U1.isHexa(e))this._scriptBuffer=_p.Buffer.from(e,"hex");else if(vi.isString(e))this._script=new Ac(e),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(d.Buffer.isBuffer(e))this._scriptBuffer=_p.Buffer.from(e);else throw new TypeError("Invalid argument type: script");return this};Ge.prototype.getSignatures=function(){throw new Da.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: "+JSON.stringify(this))};Ge.prototype.isFullySigned=function(){throw new Da.AbstractMethodInvoked("Input#isFullySigned")};Ge.prototype.isFinal=function(){return this.sequenceNumber===Ge.MAXINT};Ge.prototype.addSignature=function(){throw new Da.AbstractMethodInvoked("Input#addSignature")};Ge.prototype.clearSignatures=function(){throw new Da.AbstractMethodInvoked("Input#clearSignatures")};Ge.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,_6.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ge.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};Ge.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};q1.exports=Ge});var is=B((V5,H1)=>{"use strict";p();H1.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}});var ss=B((z5,G1)=>{"use strict";p();var os=ze(),Or=Le(),E6=is(),j1=pr(),K1=Ar(),x6=Jn(),Ua=nr();function Hr(e){if(!(this instanceof Hr))return new Hr(e);if(e instanceof Hr)return e;if(os.isObject(e))return this._fromObject(e);throw new x6.InvalidArgument("TransactionSignatures must be instantiated from an object")}E6(Hr,Ua);Hr.prototype._fromObject=function(e){return this._checkObjectArgs(e),this.publicKey=new K1(e.publicKey),this.prevTxId=d.Buffer.isBuffer(e.prevTxId)?e.prevTxId:d.Buffer.from(e.prevTxId,"hex"),this.outputIndex=e.outputIndex,this.inputIndex=e.inputIndex,this.signature=e.signature instanceof Ua?e.signature:d.Buffer.isBuffer(e.signature)?Ua.fromBuffer(e.signature):Ua.fromString(e.signature),this.sigtype=e.sigtype,this};Hr.prototype._checkObjectArgs=function(e){Or.checkArgument(K1(e.publicKey),"publicKey"),Or.checkArgument(!os.isUndefined(e.inputIndex),"inputIndex"),Or.checkArgument(!os.isUndefined(e.outputIndex),"outputIndex"),Or.checkState(os.isNumber(e.inputIndex),"inputIndex must be a number"),Or.checkState(os.isNumber(e.outputIndex),"outputIndex must be a number"),Or.checkArgument(e.signature,"signature"),Or.checkArgument(e.prevTxId,"prevTxId"),Or.checkState(e.signature instanceof Ua||d.Buffer.isBuffer(e.signature)||j1.isHexa(e.signature),"signature must be a buffer or hexa value"),Or.checkState(d.Buffer.isBuffer(e.prevTxId)||j1.isHexa(e.prevTxId),"prevTxId must be a buffer or hexa value"),Or.checkArgument(e.sigtype,"sigtype"),Or.checkState(os.isNumber(e.sigtype),"sigtype must be a number")};Hr.prototype.toObject=Hr.prototype.toJSON=function(){return{publicKey:this.publicKey.toString(),prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,inputIndex:this.inputIndex,signature:this.signature.toString(),sigtype:this.sigtype}};Hr.fromObject=function(e){return Or.checkArgument(e),new Hr(e)};G1.exports=Hr});var $1=B(($5,Y1)=>{"use strict";p();var I6=is(),W1=Le(),Sp=ns(),A6=Cn(),O6=bi(),z1=qr(),V1=nr(),R6=ss();function Ln(){Sp.apply(this,arguments)}I6(Ln,Sp);Ln.prototype.getSignatures=function(e,t,r,n){W1.checkState(this.output instanceof A6),n=n||V1.SIGHASH_ALL|V1.SIGHASH_FORKID;var i=t.toPublicKey();return i.toString()===this.output.script.getPublicKey().toString("hex")?[new R6({publicKey:i,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:O6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Ln.prototype.addSignature=function(e,t){return W1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(z1.buildPublicKeyIn(t.signature.toDER(),t.sigtype)),this};Ln.prototype.clearSignatures=function(){return this.setScript(z1.empty()),this};Ln.prototype.isFullySigned=function(){return this.script.isPublicKeyIn()};Ln.SCRIPT_MAX_SIZE=74;Ln.prototype._estimateSize=function(){return Sp.BASE_SIZE+Ln.SCRIPT_MAX_SIZE};Y1.exports=Ln});var ex=B((X5,Q1)=>{"use strict";p();var T6=is(),X1=Le(),P6=Jt(),wp=ns(),B6=Cn(),N6=bi(),J1=qr(),Z1=nr(),M6=ss();function Dn(){wp.apply(this,arguments)}T6(Dn,wp);Dn.prototype.getSignatures=function(e,t,r,n,i){X1.checkState(this.output instanceof B6),i=i||P6.sha256ripemd160(t.publicKey.toBuffer()),n=n||Z1.SIGHASH_ALL|Z1.SIGHASH_FORKID;var o=this.output.script.chunks[2]&&this.output.script.chunks[2].buf;return o&&i.equals(o)?[new M6({publicKey:t.publicKey,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:N6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Dn.prototype.addSignature=function(e,t){return X1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(J1.buildPublicKeyHashIn(t.publicKey,t.signature.toDER(),t.sigtype)),this};Dn.prototype.clearSignatures=function(){return this.setScript(J1.empty()),this};Dn.prototype.isFullySigned=function(){return this.script.isPublicKeyHashIn()};Dn.SCRIPT_MAX_SIZE=108;Dn.prototype._estimateSize=function(){return wp.BASE_SIZE+Dn.SCRIPT_MAX_SIZE};Q1.exports=Dn});var nx=B((Q5,rx)=>{"use strict";p();var jr=ze(),k6=is(),Tc=ns(),C6=Cn(),Fa=Le(),tx=qr(),Rc=nr(),Ep=bi(),xp=ss(),L6=Ar(),D6=Ca();function Ct(e,t,r,n){Tc.apply(this,arguments);var i=this;t=t||e.publicKeys,r=r||e.threshold,n=n||e.signatures,this.publicKeys=t.map(o=>o.toString("hex")).sort().map(o=>new L6(o)),Fa.checkState(tx.buildMultisigOut(this.publicKeys,r).equals(this.output.script),"Provided public keys don't match to the provided output script"),this.publicKeyIndex={},jr.each(this.publicKeys,function(o,s){i.publicKeyIndex[o.toString()]=s}),this.threshold=r,this.signatures=n?this._deserializeSignatures(n):new Array(this.publicKeys.length)}k6(Ct,Tc);Ct.prototype.toObject=function(){var e=Tc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=jr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Ct.prototype._deserializeSignatures=function(e){return jr.map(e,function(t){if(t)return new xp(t)})};Ct.prototype._serializeSignatures=function(){return jr.map(this.signatures,function(e){if(e)return e.toObject()})};Ct.prototype.getSignatures=function(e,t,r,n){Fa.checkState(this.output instanceof C6),n=n||Rc.SIGHASH_ALL|Rc.SIGHASH_FORKID;var i=this,o=[];return jr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new xp({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:Ep.sign(e,t,n,r,i.output.script,i.output.satoshisBN),sigtype:n}))}),o};Ct.prototype.addSignature=function(e,t){return Fa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),Fa.checkArgument(!jr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),Fa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Ct.prototype._updateScript=function(){return this.setScript(tx.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures())),this};Ct.prototype._createSignatures=function(){return jr.map(jr.filter(this.signatures,function(e){return!jr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Ct.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Ct.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Ct.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Ct.prototype.countSignatures=function(){return jr.reduce(this.signatures,function(e,t){return e+!!t},0)};Ct.prototype.publicKeysWithoutSignature=function(){var e=this;return jr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Ct.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,Ep.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ct.normalizeSignatures=function(e,t,r,n,i){return i.map(function(o){var s=null;return n=n.filter(function(a){if(s)return!0;var f=new xp({signature:Rc.fromTxFormat(a),publicKey:o,prevTxId:t.prevTxId,outputIndex:t.outputIndex,inputIndex:r,sigtype:Rc.SIGHASH_ALL});f.signature.nhashtype=f.sigtype;var l=Ep.verify(e,f.signature,f.publicKey,f.inputIndex,t.output.script);return l?(s=f,!1):!0}),s||null})};Ct.SIGNATURE_SIZE=73;Ct.prototype._estimateSize=function(){var e=1+this.threshold*Ct.SIGNATURE_SIZE;return Tc.BASE_SIZE+D6(e).toBuffer().length+e};rx.exports=Ct});var ux=B((tq,ax)=>{"use strict";p();var Kr=ze(),U6=is(),Pc=ns(),F6=Cn(),qa=Le(),Ip=qr(),ix=nr(),ox=bi(),sx=ss(),q6=Ar(),H6=Ca();function Pt(e,t,r,n){Pc.apply(this,arguments);var i=this;t=t||e.publicKeys,r=r||e.threshold,n=n||e.signatures,this.publicKeys=t.map(o=>o.toString("hex")).sort().map(o=>new q6(o)),this.redeemScript=Ip.buildMultisigOut(this.publicKeys,r),qa.checkState(Ip.buildScriptHashOut(this.redeemScript).equals(this.output.script),"Provided public keys don't hash to the provided output"),this.publicKeyIndex={},Kr.each(this.publicKeys,function(o,s){i.publicKeyIndex[o.toString()]=s}),this.threshold=r,this.signatures=n?this._deserializeSignatures(n):new Array(this.publicKeys.length)}U6(Pt,Pc);Pt.prototype.toObject=function(){var e=Pc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=Kr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Pt.prototype._deserializeSignatures=function(e){return Kr.map(e,function(t){if(t)return new sx(t)})};Pt.prototype._serializeSignatures=function(){return Kr.map(this.signatures,function(e){if(e)return e.toObject()})};Pt.prototype.getSignatures=function(e,t,r,n){qa.checkState(this.output instanceof F6),n=n||ix.SIGHASH_ALL|ix.SIGHASH_FORKID;var i=this,o=[];return Kr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new sx({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:ox.sign(e,t,n,r,i.redeemScript,i.output.satoshisBN),sigtype:n}))}),o};Pt.prototype.addSignature=function(e,t){return qa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),qa.checkArgument(!Kr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),qa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Pt.prototype._updateScript=function(){return this.setScript(Ip.buildP2SHMultisigIn(this.publicKeys,this.threshold,this._createSignatures(),{cachedMultisig:this.redeemScript})),this};Pt.prototype._createSignatures=function(){return Kr.map(Kr.filter(this.signatures,function(e){return!Kr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Pt.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Pt.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Pt.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Pt.prototype.countSignatures=function(){return Kr.reduce(this.signatures,function(e,t){return e+!!t},0)};Pt.prototype.publicKeysWithoutSignature=function(){var e=this;return Kr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Pt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,ox.verify(e,t.signature,t.publicKey,t.inputIndex,this.redeemScript,this.output.satoshisBN)};Pt.SIGNATURE_SIZE=73;Pt.PUBKEY_SIZE=34;Pt.prototype._estimateSize=function(){var e=this.publicKeys.length*Pt.PUBKEY_SIZE,t=this.threshold*Pt.SIGNATURE_SIZE,r=3+e,n=r<=75?1:r<=255?2:3,i=t+1+n+r;return Pc.BASE_SIZE+H6(i).toBuffer().length+i};ax.exports=Pt});var Bc=B((nq,as)=>{p();as.exports=ns();as.exports.PublicKey=$1();as.exports.PublicKeyHash=ex();as.exports.MultiSig=nx();as.exports.MultiSigScriptHash=ux()});var bi=B((oq,dx)=>{"use strict";p();var j6=Nt(),fr=nr(),Ha=qr(),K6=Cn(),G6=Ma(),ja=rs(),fx=wr(),Nc=Jt(),cx=La(),Ap=Le(),Op=Mc(),_i=ze(),lx=d.Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),V6="ffffffffffffffff",W6=Op.SCRIPT_ENABLE_SIGHASH_FORKID,z6=function(e,t,r,n,i){var o=e.inputs[r];Ap.checkArgument(i instanceof fx,"For ForkId=0 signatures, satoshis or complete input must be provided");function s(U){var F=new ja;_i.each(U.inputs,function(G){F.writeReverse(G.prevTxId),F.writeUInt32LE(G.outputIndex)});var V=F.toBuffer(),z=Nc.sha256sha256(V);return z}function a(U){var F=new ja;_i.each(U.inputs,function(G){F.writeUInt32LE(G.sequenceNumber)});var V=F.toBuffer(),z=Nc.sha256sha256(V);return z}function f(U,F){var V=new ja;_i.isUndefined(F)?_i.each(U.outputs,function(ie){ie.toBufferWriter(V)}):U.outputs[F].toBufferWriter(V);var z=V.toBuffer(),G=Nc.sha256sha256(z);return G}var l=d.Buffer.alloc(32),m=d.Buffer.alloc(32),g=d.Buffer.alloc(32);t&fr.SIGHASH_ANYONECANPAY||(l=s(e)),!(t&fr.SIGHASH_ANYONECANPAY)&&(t&31)!==fr.SIGHASH_SINGLE&&(t&31)!==fr.SIGHASH_NONE&&(m=a(e)),(t&31)!==fr.SIGHASH_SINGLE&&(t&31)!==fr.SIGHASH_NONE?g=f(e):(t&31)===fr.SIGHASH_SINGLE&&r<e.outputs.length&&(g=f(e,r));var v=new ja;v.writeInt32LE(e.version),v.write(l),v.write(m),v.writeReverse(o.prevTxId),v.writeUInt32LE(o.outputIndex);var E=n.toBuffer();v.writeVarintNum(E.length),v.write(E),v.writeUInt64LEBN(i);var T=o.sequenceNumber;v.writeUInt32LE(T),v.write(g),v.writeUInt32LE(e.nLockTime),v.writeUInt32LE(t>>>0);var M=v.toBuffer();return M},hx=function(t,r,n,i,o,s){var a=Tp(),f=Bc();_i.isUndefined(s)&&(s=W6);var l=a.shallowCopy(t);if(i instanceof Ha||(i=new Ha(i)),s&Op.SCRIPT_ENABLE_REPLAY_PROTECTION){var m=r>>8,g=16711680|m^57005;r=g<<8|r&255}if(r&fr.SIGHASH_FORKID&&!(r&fr.SIGHASH_CHRONICLE)&&s&Op.SCRIPT_ENABLE_SIGHASH_FORKID)return z6(l,r,n,i,o);i=new Ha(i),i.removeCodeseparators();var v;for(v=0;v<l.inputs.length;v++)l.inputs[v]=new f(l.inputs[v]).setScript(Ha.empty());if(l.inputs[n]=new f(l.inputs[n]).setScript(i),(r&31)===fr.SIGHASH_NONE||(r&31)===fr.SIGHASH_SINGLE)for(v=0;v<l.inputs.length;v++)v!==n&&(l.inputs[v].sequenceNumber=0);if((r&31)===fr.SIGHASH_NONE)l.outputs=[];else if((r&31)===fr.SIGHASH_SINGLE){if(n>=l.outputs.length)return lx;for(l.outputs.length=n+1,v=0;v<n;v++)l.outputs[v]=new K6({satoshis:fx.fromBuffer(j6.Buffer.from(V6,"hex")),script:Ha.empty()})}r&fr.SIGHASH_ANYONECANPAY&&(l.inputs=[l.inputs[n]]);var E=new ja().write(l.toBuffer()).writeInt32LE(r).toBuffer();return E},Rp=function(t,r,n,i,o,s){var a=hx(t,r,n,i,o,s);if(a.compare(lx)===0)return a;var f=Nc.sha256sha256(a);return f=new G6(f).readReverse(),f};function Y6(e,t,r,n,i,o,s){var a=Rp(e,r,n,i,o,s),f=cx.sign(a,t,"little").set({nhashtype:r});return f}function $6(e,t,r,n,i,o,s){Ap.checkArgument(!_i.isUndefined(e)),Ap.checkArgument(!_i.isUndefined(t)&&!_i.isUndefined(t.nhashtype));var a=Rp(e,t.nhashtype,n,i,o,s);return cx.verify(a,t,r,"little")}dx.exports={sighashPreimage:hx,sighash:Rp,sign:Y6,verify:$6}});var Pp=B((aq,gx)=>{"use strict";p();var Un=ze(),kc=Le(),px=pr(),Z6=qr(),X6=ro();function Fn(e){if(!(this instanceof Fn))return new Fn(e);kc.checkArgument(Un.isObject(e),"Must provide an object from where to extract data");var t=e.address?new X6(e.address):void 0,r=e.txid?e.txid:e.txId;if(!r||!px.isHexaString(r)||r.length>64)throw new Error("Invalid TXID in object",e);var n=Un.isUndefined(e.vout)?e.outputIndex:e.vout;if(!Un.isNumber(n))throw new Error("Invalid outputIndex, received "+n);kc.checkArgument(!Un.isUndefined(e.scriptPubKey)||!Un.isUndefined(e.script),"Must provide the scriptPubKey for that output!");var i=new Z6(e.scriptPubKey||e.script);kc.checkArgument(!Un.isUndefined(e.amount)||!Un.isUndefined(e.satoshis),"Must provide an amount for the output");var o=Un.isUndefined(e.amount)?e.satoshis:Math.round(e.amount*1e8);kc.checkArgument(Un.isNumber(o),"Amount must be a number"),px.defineImmutable(this,{address:t,txId:r,outputIndex:n,script:i,satoshis:o})}Fn.prototype.inspect=function(){return"<UnspentOutput: "+this.txId+":"+this.outputIndex+", satoshis: "+this.satoshis+", address: "+this.address+">"};Fn.prototype.toString=function(){return this.txId+":"+this.outputIndex};Fn.fromObject=function(e){return new Fn(e)};Fn.prototype.toObject=Fn.prototype.toJSON=function(){return{address:this.address?this.address.toString():void 0,txid:this.txId,vout:this.outputIndex,scriptPubKey:this.script.toBuffer().toString("hex"),amount:Number.parseFloat((this.satoshis/1e8).toFixed(8))}};gx.exports=Fn});var Tp=B((fq,Ex)=>{"use strict";p();var ye=ze(),Kt=Le(),J6=Nt(),Dt=Jn(),mx=pr(),vx=Ma(),Q6=rs(),yx=Ca(),bx=Jt(),Lc=nr(),_x=bi(),eC=ro(),Sx=Pp(),Lt=Bc(),tC=Lt.PublicKeyHash,rC=Lt.PublicKey,nC=Lt.MultiSigScriptHash,iC=Lt.MultiSig,Gr=Cn(),ln=qr(),oC=no(),Cc=wr(),sC=Mc(),aC=sC.SCRIPT_ENABLE_SIGHASH_FORKID;function Y(e){if(!(this instanceof Y))return new Y(e);if(this.inputs=[],this.outputs=[],this._inputAmount=void 0,this._outputAmount=void 0,e){if(e instanceof Y)return Y.shallowCopy(e);if(mx.isHexa(e))this.fromString(e);else if(d.Buffer.isBuffer(e))this.fromBuffer(e);else if(ye.isObject(e))this.fromObject(e);else throw new Dt.InvalidArgument("Must provide an object or string to deserialize a transaction")}else this._newTransaction()}var uC=1,fC=0,cC=1e6;Y.DUST_AMOUNT=546;Y.FEE_SECURITY_MARGIN=150;Y.MAX_MONEY=21e6*1e8;Y.NLOCKTIME_BLOCKHEIGHT_LIMIT=5e8;Y.NLOCKTIME_MAX_VALUE=4294967295;Y.FEE_PER_KB=500;Y.CHANGE_OUTPUT_MAX_SIZE=62;Y.shallowCopy=function(e){var t=new Y(e.toBuffer());return t};var wx={configurable:!1,enumerable:!0,get:function(){return this._hash=new vx(this._getHash()).readReverse().toString("hex"),this._hash}};Object.defineProperty(Y.prototype,"hash",wx);Object.defineProperty(Y.prototype,"id",wx);var Bp={configurable:!1,enumerable:!0,get:function(){return this._getInputAmount()}};Object.defineProperty(Y.prototype,"inputAmount",Bp);Bp.get=function(){return this._getOutputAmount()};Object.defineProperty(Y.prototype,"outputAmount",Bp);Y.prototype._getHash=function(){return bx.sha256sha256(this.toBuffer())};Y.prototype.serialize=function(e){return e===!0||e&&e.disableAll?this.uncheckedSerialize():this.checkedSerialize(e)};Y.prototype.uncheckedSerialize=Y.prototype.toString=function(){return this.toBuffer().toString("hex")};Y.prototype.checkedSerialize=function(e){var t=this.getSerializationError(e);if(t)throw t.message+=" - For more information please see: https://bsv.io/api/lib/transaction#serialization-checks",t;return this.uncheckedSerialize()};Y.prototype.invalidSatoshis=function(){for(var e=!1,t=0;t<this.outputs.length;t++)this.outputs[t].invalidSatoshis()&&(e=!0);return e};Y.prototype.getSerializationError=function(e){if(e=e||{},this.invalidSatoshis())return new Dt.Transaction.InvalidSatoshis;var t=this._getUnspentValue(),r;return t<0?e.disableMoreOutputThanInput||(r=new Dt.Transaction.InvalidOutputAmountSum):r=this._hasFeeError(e,t),r||this._hasDustOutputs(e)||this._isMissingSignatures(e)};Y.prototype._hasFeeError=function(e,t){if(!ye.isUndefined(this._fee)&&this._fee!==t)return new Dt.Transaction.FeeError.Different("Unspent value is "+t+" but specified fee is "+this._fee);if(!e.disableLargeFees){var r=Math.floor(Y.FEE_SECURITY_MARGIN*this._estimateFee());if(t>r)return this._missingChange()?new Dt.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided"):new Dt.Transaction.FeeError.TooLarge("expected less than "+r+" but got "+t)}};Y.prototype._missingChange=function(){return!this._changeScript};Y.prototype._hasDustOutputs=function(e){if(!e.disableDustOutputs){var t,r;for(t in this.outputs)if(r=this.outputs[t],r.satoshis<Y.DUST_AMOUNT&&!r.script.isDataOut()&&!r.script.isSafeDataOut())return new Dt.Transaction.DustOutputs}};Y.prototype._isMissingSignatures=function(e){if(!e.disableIsFullySigned&&!this.isFullySigned())return new Dt.Transaction.MissingSignatures};Y.prototype.inspect=function(){return"<Transaction: "+this.uncheckedSerialize()+">"};Y.prototype.toBuffer=function(){var e=new Q6;return this.toBufferWriter(e).toBuffer()};Y.prototype.toBufferWriter=function(e){return e.writeInt32LE(this.version),e.writeVarintNum(this.inputs.length),ye.each(this.inputs,function(t){t.toBufferWriter(e)}),e.writeVarintNum(this.outputs.length),ye.each(this.outputs,function(t){t.toBufferWriter(e)}),e.writeUInt32LE(this.nLockTime),e};Y.prototype.fromBuffer=function(e){var t=new vx(e);return this.fromBufferReader(t)};Y.prototype.fromBufferReader=function(e){Kt.checkArgument(!e.finished(),"No transaction data received");var t,r,n;for(this.version=e.readInt32LE(),r=e.readVarintNum(),t=0;t<r;t++){var i=Lt.fromBufferReader(e);this.inputs.push(i)}for(n=e.readVarintNum(),t=0;t<n;t++)this.outputs.push(Gr.fromBufferReader(e));return this.nLockTime=e.readUInt32LE(),this};Y.prototype.toObject=Y.prototype.toJSON=function(){var t=[];this.inputs.forEach(function(i){t.push(i.toObject())});var r=[];this.outputs.forEach(function(i){r.push(i.toObject())});var n={hash:this.hash,version:this.version,inputs:t,outputs:r,nLockTime:this.nLockTime};return this._changeScript&&(n.changeScript=this._changeScript.toString()),ye.isUndefined(this._changeIndex)||(n.changeIndex=this._changeIndex),ye.isUndefined(this._fee)||(n.fee=this._fee),n};Y.prototype.fromObject=function(t){Kt.checkArgument(ye.isObject(t)||t instanceof Y);var r=this,n;return t instanceof Y?n=t.toObject():n=t,ye.each(n.inputs,function(i){if(!i.output||!i.output.script){r.uncheckedAddInput(new Lt(i));return}var o=new ln(i.output.script),s;if(o.isPublicKeyHashOut())s=new Lt.PublicKeyHash(i);else if(o.isScriptHashOut()&&i.publicKeys&&i.threshold)s=new Lt.MultiSigScriptHash(i,i.publicKeys,i.threshold,i.signatures);else if(o.isPublicKeyOut())s=new Lt.PublicKey(i);else throw new Dt.Transaction.Input.UnsupportedScript(i.output.script);r.addInput(s)}),ye.each(n.outputs,function(i){r.addOutput(new Gr(i))}),n.changeIndex&&(this._changeIndex=n.changeIndex),n.changeScript&&(this._changeScript=new ln(n.changeScript)),n.fee&&(this._fee=n.fee),this.nLockTime=n.nLockTime,this.version=n.version,this._checkConsistency(t),this};Y.prototype._checkConsistency=function(e){ye.isUndefined(this._changeIndex)||(Kt.checkState(this._changeScript,"Change script is expected."),Kt.checkState(this.outputs[this._changeIndex],"Change index points to undefined output."),Kt.checkState(this.outputs[this._changeIndex].script.toString()===this._changeScript.toString(),"Change output has an unexpected script.")),e&&e.hash&&Kt.checkState(e.hash===this.hash,"Hash in object does not match transaction hash.")};Y.prototype.lockUntilDate=function(e){if(Kt.checkArgument(e),ye.isNumber(e)&&e<Y.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Dt.Transaction.LockTimeTooEarly;ye.isDate(e)&&(e=e.getTime()/1e3);for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===Lt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=Lt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Y.prototype.lockUntilBlockHeight=function(e){if(Kt.checkArgument(ye.isNumber(e)),e>=Y.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Dt.Transaction.BlockHeightTooHigh;if(e<0)throw new Dt.Transaction.NLockTimeOutOfRange;for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===Lt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=Lt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Y.prototype.getLockTime=function(){return this.nLockTime?this.nLockTime<Y.NLOCKTIME_BLOCKHEIGHT_LIMIT?this.nLockTime:new Date(1e3*this.nLockTime):null};Y.prototype.fromString=function(e){this.fromBuffer(J6.Buffer.from(e,"hex"))};Y.prototype._newTransaction=function(){this.version=uC,this.nLockTime=fC};Y.prototype.from=function(e,t,r){if(ye.isArray(e)){var n=this;return ye.each(e,function(o){n.from(o,t,r)}),this}var i=ye.some(this.inputs,function(o){return o.prevTxId.toString("hex")===e.txId&&o.outputIndex===e.outputIndex});return i?this:(t&&r?this._fromMultisigUtxo(e,t,r):this._fromNonP2SH(e),this)};Y.prototype._fromNonP2SH=function(e){var t;e=new Sx(e),e.script.isPublicKeyHashOutPrefix()?t=tC:e.script.isPublicKeyOut()?t=rC:t=Lt,this.addInput(new t({output:new Gr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:ln.empty()}))};Y.prototype._fromMultisigUtxo=function(e,t,r){Kt.checkArgument(r<=t.length,"Number of required signatures must be greater than the number of public keys");var n;if(e=new Sx(e),e.script.isMultisigOut())n=iC;else if(e.script.isScriptHashOut())n=nC;else throw new Dt.Transaction.Input.UnsupportedScript(e.script.toString());this.addInput(new n({output:new Gr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:ln.empty()},t,r))};Y.prototype.addInput=function(e,t,r){if(Kt.checkArgumentType(e,Lt,"input"),!e.output&&(ye.isUndefined(t)||ye.isUndefined(r)))throw new Dt.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis");return!e.output&&t&&!ye.isUndefined(r)&&(t=t instanceof ln?t:new ln(t),Kt.checkArgumentType(r,"number","satoshis"),e.output=new Gr({script:t,satoshis:r})),this.uncheckedAddInput(e)};Y.prototype.uncheckedAddInput=function(e){return Kt.checkArgumentType(e,Lt,"input"),this.inputs.push(e),this._inputAmount=void 0,this._updateChangeOutput(),this};Y.prototype.hasAllUtxoInfo=function(){return ye.every(this.inputs.map(function(e){return!!e.output}))};Y.prototype.fee=function(e){return Kt.checkArgument(ye.isNumber(e),"amount must be a number"),this._fee=e,this._updateChangeOutput(),this};Y.prototype.feePerKb=function(e){return Kt.checkArgument(ye.isNumber(e),"amount must be a number"),this._feePerKb=e,this._updateChangeOutput(),this};Y.prototype.change=function(e){return Kt.checkArgument(e,"address is required"),this._changeScript=ln.fromAddress(e),this._updateChangeOutput(),this};Y.prototype.getChangeOutput=function(){return ye.isUndefined(this._changeIndex)?null:this.outputs[this._changeIndex]};Y.prototype.to=function(e,t){if(ye.isArray(e)){var r=this;return ye.each(e,function(n){r.to(n.address,n.satoshis)}),this}return Kt.checkArgument(mx.isNaturalNumber(t),"Amount is expected to be a positive integer"),this.addOutput(new Gr({script:ln(new eC(e)),satoshis:t})),this};Y.prototype.addData=function(e){return this.addOutput(new Gr({script:ln.buildDataOut(e),satoshis:0})),this};Y.prototype.addSafeData=function(e){return this.addOutput(new Gr({script:ln.buildSafeDataOut(e),satoshis:0})),this};Y.prototype.addOutput=function(e){return Kt.checkArgumentType(e,Gr,"output"),this._addOutput(e),this._updateChangeOutput(),this};Y.prototype.clearOutputs=function(){return this.outputs=[],this._clearSignatures(),this._outputAmount=void 0,this._changeIndex=void 0,this._updateChangeOutput(),this};Y.prototype._addOutput=function(e){this.outputs.push(e),this._outputAmount=void 0};Y.prototype._getOutputAmount=function(){if(ye.isUndefined(this._outputAmount)){var e=this;this._outputAmount=0,ye.each(this.outputs,function(t){e._outputAmount+=t.satoshis})}return this._outputAmount};Y.prototype._getInputAmount=function(){if(ye.isUndefined(this._inputAmount)){var e=this;this._inputAmount=0,ye.each(this.inputs,function(t){if(ye.isUndefined(t.output))throw new Dt.Transaction.Input.MissingPreviousOutput;e._inputAmount+=t.output.satoshis})}return this._inputAmount};Y.prototype._updateChangeOutput=function(){if(this._changeScript){this._clearSignatures(),ye.isUndefined(this._changeIndex)||this._removeOutput(this._changeIndex),this._changeIndex=this.outputs.length,this._addOutput(new Gr({script:this._changeScript,satoshis:0}));var e=this._getUnspentValue(),t=this.getFee(),r=e-t;this._removeOutput(this._changeIndex),this._changeIndex=void 0,r>=Y.DUST_AMOUNT&&(this._changeIndex=this.outputs.length,this._addOutput(new Gr({script:this._changeScript,satoshis:r})))}};Y.prototype.getFee=function(){return this.isCoinbase()?0:ye.isUndefined(this._fee)?this._changeScript?this._estimateFee():this._getUnspentValue():this._fee};Y.prototype._estimateFee=function(){var e=this._estimateSize();return Math.ceil(e/1e3*(this._feePerKb||Y.FEE_PER_KB))};Y.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Y.prototype._clearSignatures=function(){ye.each(this.inputs,function(e){e.clearSignatures!==Lt.prototype.clearSignatures&&e.clearSignatures()})};Y.prototype._estimateSize=function(){var e=8;return e+=yx(this.inputs.length).toBuffer().length,e+=yx(this.outputs.length).toBuffer().length,ye.each(this.inputs,function(t){e+=t._estimateSize()}),ye.each(this.outputs,function(t){e+=t.getSize()}),e};Y.prototype._removeOutput=function(e){var t=this.outputs[e];this.outputs=ye.without(this.outputs,t),this._outputAmount=void 0};Y.prototype.removeOutput=function(e){this._removeOutput(e),this._updateChangeOutput()};Y.prototype.sort=function(){return this.sortInputs(function(e){var t=Array.prototype.concat.apply([],e);return t.sort(function(r,n){return r.prevTxId.compare(n.prevTxId)||r.outputIndex-n.outputIndex}),t}),this.sortOutputs(function(e){var t=Array.prototype.concat.apply([],e);return t.sort(function(r,n){return r.satoshis-n.satoshis||r.script.toBuffer().compare(n.script.toBuffer())}),t}),this};Y.prototype.shuffleOutputs=function(){return this.sortOutputs(ye.shuffle)};Y.prototype.sortOutputs=function(e){var t=e(this.outputs);return this._newOutputOrder(t)};Y.prototype.sortInputs=function(e){return this.inputs=e(this.inputs),this._clearSignatures(),this};Y.prototype._newOutputOrder=function(e){var t=this.outputs.length!==e.length||ye.difference(this.outputs,e).length!==0;if(t)throw new Dt.Transaction.InvalidSorting;if(!ye.isUndefined(this._changeIndex)){var r=this.outputs[this._changeIndex];this._changeIndex=e.indexOf(r)}return this.outputs=e,this};Y.prototype.removeInput=function(e,t){var r;if(!t&&ye.isNumber(e)?r=e:r=ye.findIndex(this.inputs,function(i){return i.prevTxId.toString("hex")===e&&i.outputIndex===t}),r<0||r>=this.inputs.length)throw new Dt.Transaction.InvalidIndex(r,this.inputs.length);var n=this.inputs[r];this.inputs=ye.without(this.inputs,n),this._inputAmount=void 0,this._updateChangeOutput()};Y.prototype.sign=function(e,t){Kt.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var r=this;return ye.isArray(e)?(ye.each(e,function(n){r.sign(n,t)}),this):(ye.each(this.getSignatures(e,t),function(n){r.applySignature(n)}),this)};Y.prototype.getSignatures=function(e,t){e=new oC(e),t=t||Lc.SIGHASH_ALL|Lc.SIGHASH_FORKID;var r=this,n=[],i=bx.sha256ripemd160(e.publicKey.toBuffer());return ye.each(this.inputs,function(s,a){ye.each(s.getSignatures(r,e,a,t,i),function(f){n.push(f)})}),n};Y.prototype.applySignature=function(e){return this.inputs[e.inputIndex].addSignature(this,e),this};Y.prototype.isFullySigned=function(){return ye.each(this.inputs,function(e){if(e.isFullySigned===Lt.prototype.isFullySigned)throw new Dt.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction")}),ye.every(ye.map(this.inputs,function(e){return e.isFullySigned()}))};Y.prototype.isValidSignature=function(e){var t=this;if(this.inputs[e.inputIndex].isValidSignature===Lt.prototype.isValidSignature)throw new Dt.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction");return this.inputs[e.inputIndex].isValidSignature(t,e)};Y.prototype.verifySignature=function(e,t,r,n,i,o){return _x.verify(this,e,t,r,n,i,o)};Y.prototype.verify=function(){if(this.inputs.length===0)return"transaction txins empty";if(this.outputs.length===0)return"transaction txouts empty";for(var e=new Cc(0),t=0;t<this.outputs.length;t++){var r=this.outputs[t];if(r.invalidSatoshis())return"transaction txout "+t+" satoshis is invalid";if(r._satoshisBN.gt(new Cc(Y.MAX_MONEY,10)))return"transaction txout "+t+" greater than MAX_MONEY";if(e=e.add(r._satoshisBN),e.gt(new Cc(Y.MAX_MONEY)))return"transaction txout "+t+" total output greater than MAX_MONEY"}if(this.toBuffer().length>cC)return"transaction over the maximum block size";var n={};for(t=0;t<this.inputs.length;t++){var i=this.inputs[t],o=i.prevTxId+":"+i.outputIndex;if(!ye.isUndefined(n[o]))return"transaction input "+t+" duplicate input";n[o]=!0}var s=this.isCoinbase();if(s){var a=this.inputs[0]._scriptBuffer;if(a.length<2||a.length>100)return"coinbase transaction script size invalid"}else for(t=0;t<this.inputs.length;t++)if(this.inputs[t].isNull())return"transaction input "+t+" has null input";return!0};Y.prototype.isCoinbase=function(){return this.inputs.length===1&&this.inputs[0].isNull()};Y.prototype.sighash=function(e,t,r,n,i){t=t||Lc.SIGHASH_ALL|Lc.SIGHASH_FORKID;var o=this.inputs[e];if(!o)throw new Error("Input index "+e+" does not exist");return!r&&o.output&&(r=o.output.script),!n&&o.output&&(n=new Cc(o.output.satoshis)),i=i||aC,_x.sighash(this,t,e,r,n,i)};Ex.exports=Y});var Np=B((lq,io)=>{p();io.exports=Tp();io.exports.Input=Bc();io.exports.Output=Cn();io.exports.UnspentOutput=Pp();io.exports.Signature=ss();io.exports.Sighash=bi()});var Mc=B((dq,Ox)=>{"use strict";p();var Dc=ze(),Uc=gp(),N=hp(),he=wr(),Ka=Jt(),qn=nr(),Mp=Ar();function xx(e){return e.map(function(t){return d.Buffer.isBuffer(t)?d.Buffer.from(t):t})}var P=function e(t){if(!(this instanceof e))return new e(t);t?(this.initialize(),this.set(t)):this.initialize()};P.prototype._verifyCore=function(e,t,r,n,i,o){var s=Np();if(Dc.isUndefined(r)&&(r=new s),Dc.isUndefined(n)&&(n=0),Dc.isUndefined(i)&&(i=P.currentConsensusFlags(),o||(i&=~P.SCRIPT_ENABLE_SIGHASH_FORKID)),i&P.SCRIPT_ENABLE_SIGHASH_FORKID&&(i|=P.SCRIPT_VERIFY_STRICTENC,!o))throw new Error("internal error - need satoshisBN to verify FORKID transactions");this.set({script:e,tx:r,nin:n,flags:i,satoshisBN:o});var a;if((i&P.SCRIPT_VERIFY_SIGPUSHONLY)!==0&&!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1;if(!this.evaluate())return!1;var f=(i&P.SCRIPT_VERIFY_P2SH)!==0&&(i&P.SCRIPT_UTXO_AFTER_GENESIS)===0;f&&(a=this.stack.slice());var l=this.stack;if(this.initialize(),this.set({script:t,stack:l,tx:r,nin:n,flags:i,satoshisBN:o}),!this.evaluate())return!1;if(this.stack.length===0)return this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_RESULT",!1;var m=this.stack[this.stack.length-1];if(!P.castToBool(m))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK",!1;if(f&&t.isScriptHashOut()){if(!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1;if(a.length===0)throw new Error("internal error - stack copy empty");var g=a[a.length-1],v=Uc.fromBuffer(g);if(a.pop(),this.initialize(),this.set({script:v,stack:a,tx:r,nin:n,flags:i,satoshisBN:o}),!this.evaluate())return!1;if(a.length===0)return this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_P2SH_STACK",!1;if(!P.castToBool(a[a.length-1]))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK",!1}if((i&P.SCRIPT_VERIFY_CLEANSTACK)!==0){if((i&P.SCRIPT_VERIFY_P2SH)===0&&(i&P.SCRIPT_UTXO_AFTER_GENESIS)===0)throw new Error("internal error - CLEANSTACK without P2SH");if(this.stack.length!==1)return this.errstr="SCRIPT_ERR_CLEANSTACK",!1}return!0};Ox.exports=P;P.prototype.initialize=function(e){this.stack=[],this.altstack=[],this.pc=0,this.pbegincodehash=0,this.nOpCount=0,this.returned=!1,this.nonTopLevelReturnAfterGenesis=!1,this.vfExec=[],this.vfElse=[],this.errstr="",this.flags=0};P.prototype.set=function(e){this.script=e.script||this.script,this.tx=e.tx||this.tx,this.nin=typeof e.nin<"u"?e.nin:this.nin,this.satoshisBN=e.satoshisBN||this.satoshisBN,this.stack=e.stack||this.stack,this.altstack=e.altstack||this.altstack,this.pc=typeof e.pc<"u"?e.pc:this.pc,this.pbegincodehash=typeof e.pbegincodehash<"u"?e.pbegincodehash:this.pbegincodehash,this.nOpCount=typeof e.nOpCount<"u"?e.nOpCount:this.nOpCount,this.returned=typeof e.returned<"u"?e.returned:this.returned,this.nonTopLevelReturnAfterGenesis=typeof e.nonTopLevelReturnAfterGenesis<"u"?e.nonTopLevelReturnAfterGenesis:this.nonTopLevelReturnAfterGenesis,this.vfExec=e.vfExec||this.vfExec,this.vfElse=e.vfElse||this.vfElse,this.errstr=e.errstr||this.errstr,this.flags=typeof e.flags<"u"?e.flags:this.flags};P.true=d.Buffer.from([1]);P.false=d.Buffer.from([]);P.MAX_SCRIPT_ELEMENT_SIZE=520;P.MAXIMUM_ELEMENT_SIZE=4;P.MAX_OPS_PER_SCRIPT=500;P.MAX_SCRIPT_SIZE=1e4;P.UNLIMITED=Number.MAX_SAFE_INTEGER;P.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS=75e4;P.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE=32e6;P.MAX_PUBKEYS_PER_MULTISIG_AFTER_GENESIS=4294967295;P.MAX_STACK_SIZE=1e3;P.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS=P.UNLIMITED;P.STACK_MEMORY_USAGE_POLICY=100*1024*1024;P.STACK_ELEMENT_OVERHEAD=32;P.LOCKTIME_THRESHOLD=5e8;P.LOCKTIME_THRESHOLD_BN=new he(P.LOCKTIME_THRESHOLD);P.useGenesisLimits=function(e){return e=e||2147483647,P.MAX_SCRIPT_ELEMENT_SIZE=e,P.MAX_OPS_PER_SCRIPT=e,P.MAX_SCRIPT_SIZE=e,P};P.getLimits=function(){return{maxScriptElementSize:P.MAX_SCRIPT_ELEMENT_SIZE,maximumElementSize:P.MAXIMUM_ELEMENT_SIZE,maxOpsPerScript:P.MAX_OPS_PER_SCRIPT,maxScriptSize:P.MAX_SCRIPT_SIZE}};P.setLimits=function(e){return e=e||{},e.maxScriptElementSize!=null&&(P.MAX_SCRIPT_ELEMENT_SIZE=e.maxScriptElementSize),e.maximumElementSize!=null&&(P.MAXIMUM_ELEMENT_SIZE=e.maximumElementSize),e.maxOpsPerScript!=null&&(P.MAX_OPS_PER_SCRIPT=e.maxOpsPerScript),e.maxScriptSize!=null&&(P.MAX_SCRIPT_SIZE=e.maxScriptSize),P};P.SCRIPT_VERIFY_NONE=0;P.SCRIPT_VERIFY_P2SH=1;P.SCRIPT_VERIFY_STRICTENC=2;P.SCRIPT_VERIFY_DERSIG=4;P.SCRIPT_VERIFY_LOW_S=8;P.SCRIPT_VERIFY_NULLDUMMY=16;P.SCRIPT_VERIFY_SIGPUSHONLY=32;P.SCRIPT_VERIFY_MINIMALDATA=64;P.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=128;P.SCRIPT_VERIFY_CLEANSTACK=256;P.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=512;P.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1024;P.SCRIPT_VERIFY_MINIMALIF=8192;P.SCRIPT_VERIFY_NULLFAIL=16384;P.SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE=32768;P.SCRIPT_ENABLE_SIGHASH_FORKID=65536;P.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;P.SCRIPT_ENABLE_MONOLITH_OPCODES=2048;P.SCRIPT_ENABLE_MAGNETIC_OPCODES=4096;P.SCRIPT_GENESIS=1<<18;P.SCRIPT_UTXO_AFTER_GENESIS=1<<19;P.SCRIPT_ENABLE_CHRONICLE=1<<20;P.SCRIPT_CHRONICLE=P.SCRIPT_ENABLE_CHRONICLE;P.SCRIPT_UTXO_AFTER_CHRONICLE=1<<21;P.CHRONICLE_ACTIVATION_HEIGHT=943816;P.ERA_SENSITIVE_ERRORS={SCRIPT_ERR_PUSH_SIZE:{cap:"stack element size (capped at 520 bytes pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPT_SIZE:{cap:"total script size (capped at 10,000 bytes pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_OP_COUNT:{cap:"opcode count (capped at 201 pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPTNUM_OVERFLOW:{cap:"script number width (4 bytes pre-Genesis, 750,000 after Genesis, 32,000,000 after Chronicle)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS|P.SCRIPT_UTXO_AFTER_CHRONICLE}};P.ERA_FLAGS=P.SCRIPT_GENESIS|P.SCRIPT_UTXO_AFTER_GENESIS|P.SCRIPT_ENABLE_CHRONICLE|P.SCRIPT_UTXO_AFTER_CHRONICLE;P.eraDiagnostics=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_ERA_HINT==="1");var kp=!1;P.prototype._eraDiagnose=function(e){if(e!==void 0){var t=P.ERA_SENSITIVE_ERRORS[this.errstr];if(t&&(e&t.lifts)===0){var r=t.cap;this.eraHint=this.errstr+" was produced under PRE-GENESIS limits: "+r+`.
|
|
69
|
+
`));var a=new yi({actual:e,expected:t,message:r,operator:i,stackStartFn:n});throw a.generatedMessage=s,a}}Ye.match=function e(t,r,n){m1(t,r,n,e,"match")};Ye.doesNotMatch=function e(t,r,n){m1(t,r,n,e,"doesNotMatch")};function v1(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];c1.apply(void 0,[v1,t.length].concat(t))}Ye.strict=e6(v1,Ye,{equal:Ye.strictEqual,deepEqual:Ye.deepStrictEqual,notEqual:Ye.notStrictEqual,notDeepEqual:Ye.notDeepStrictEqual});Ye.strict.strict=Ye.strict});var Ma=B((O5,S1)=>{"use strict";p();var Na=ze(),_1=Le(),es=wr(),it=function e(t){if(!(this instanceof e))return new e(t);if(!Na.isUndefined(t))if(d.Buffer.isBuffer(t))this.set({buf:t});else if(Na.isString(t)){var r=d.Buffer.from(t,"hex");if(r.length*2!==t.length)throw new TypeError("Invalid hex string");this.set({buf:r})}else if(Na.isObject(t)){var n=t;this.set(n)}else throw new TypeError("Unrecognized argument for BufferReader")};it.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this};it.prototype.eof=function(){return this.pos>=this.buf.length};it.prototype.finished=it.prototype.eof;it.prototype.read=function(e){_1.checkArgument(!Na.isUndefined(e),"Must specify a length");var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,t};it.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e};it.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e};it.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e};it.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e};it.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e};it.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e};it.prototype.readInt32LE=function(){var e=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,e};it.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=es.fromBuffer(e);return this.pos=this.pos+8,t};it.prototype.readUInt64LEBN=function(){var e=this.buf.readUInt32LE(this.pos),t=this.buf.readUInt32LE(this.pos+4),r=t*4294967296+e,n;if(r<=9007199254740991)n=new es(r);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);n=new es(i,10,"le")}return this.pos=this.pos+8,n};it.prototype.readVarintNum=function(){var e=this.readUInt8();switch(e){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var t=this.readUInt64LEBN(),r=t.toNumber();if(r<=Math.pow(2,53))return r;throw new Error("number too large to retain precision - use readVarintBN");default:return e}};it.prototype.readVarLengthBuffer=function(){var e=this.readVarintNum(),t=this.read(e);return _1.checkState(t.length===e,"Invalid length while reading varlength buffer. Expected to read: "+e+" and read "+t.length),t};it.prototype.readVarintBuf=function(){var e=this.buf.readUInt8(this.pos);switch(e){case 253:return this.read(3);case 254:return this.read(5);case 255:return this.read(9);default:return this.read(1)}};it.prototype.readVarintBN=function(){var e=this.readUInt8();switch(e){case 253:return new es(this.readUInt16LE());case 254:return new es(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new es(e)}};it.prototype.reverse=function(){for(var e=d.Buffer.alloc(this.buf.length),t=0;t<e.length;t++)e[t]=this.buf[this.buf.length-1-t];return this.buf=e,this};it.prototype.readReverse=function(e){Na.isUndefined(e)&&(e=this.buf.length);var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,d.Buffer.from(t).reverse()};S1.exports=it});var hp=B((T5,w1)=>{"use strict";p();var ts=ze(),ka=Le(),r6=pr();function Ne(e){if(!(this instanceof Ne))return new Ne(e);var t;if(ts.isNumber(e))t=e;else if(ts.isString(e))t=Ne.map[e];else throw new TypeError('Unrecognized num type: "'+typeof e+'" for Opcode');return r6.defineImmutable(this,{num:t}),this}Ne.fromBuffer=function(e){return ka.checkArgument(d.Buffer.isBuffer(e)),new Ne(+("0x"+e.toString("hex")))};Ne.fromNumber=function(e){return ka.checkArgument(ts.isNumber(e)),new Ne(e)};Ne.fromString=function(e){ka.checkArgument(ts.isString(e));var t=Ne.map[e];if(typeof t>"u")throw new TypeError("Invalid opcodestr");return new Ne(t)};Ne.prototype.toHex=function(){return this.num.toString(16)};Ne.prototype.toBuffer=function(){return d.Buffer.from(this.toHex(),"hex")};Ne.prototype.toNumber=function(){return this.num};Ne.prototype.toString=function(){var e=Ne.reverseMap[this.num];if(typeof e>"u")throw new Error("Opcode does not have a string representation");return e};Ne.smallInt=function(e){return ka.checkArgument(ts.isNumber(e),"Invalid Argument: n should be number"),ka.checkArgument(e>=0&&e<=16,"Invalid Argument: n must be between 0 and 16"),e===0?Ne("OP_0"):new Ne(Ne.map.OP_1+e-1)};Ne.map={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_SPLIT:127,OP_NUM2BIN:128,OP_BIN2NUM: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_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_SUBSTR:179,OP_LEFT:180,OP_RIGHT:181,OP_LSHIFTNUM:182,OP_RSHIFTNUM:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Ne.reverseMap=[];for(lp in Ne.map)Ne.reverseMap[Ne.map[lp]]=lp;var lp;ts.extend(Ne,Ne.map);Ne.isSmallIntOp=function(e){return e instanceof Ne&&(e=e.toNumber()),e===Ne.map.OP_0||e>=Ne.map.OP_1&&e<=Ne.map.OP_16};Ne.prototype.inspect=function(){return"<Opcode: "+this.toString()+", hex: "+this.toHex()+", decimal: "+this.num+">"};w1.exports=Ne});var nr=B((B5,x1)=>{"use strict";p();var Qi=wr(),n6=ze(),rr=Le(),i6=pr(),Oe=function e(t,r){if(!(this instanceof e))return new e(t,r);if(t instanceof Qi)this.set({r:t,s:r});else if(t){var n=t;this.set(n)}};Oe.prototype.set=function(e){return this.r=e.r||this.r||void 0,this.s=e.s||this.s||void 0,this.i=typeof e.i<"u"?e.i:this.i,this.compressed=typeof e.compressed<"u"?e.compressed:this.compressed,this.nhashtype=e.nhashtype||this.nhashtype||void 0,this};Oe.fromCompact=function(e){rr.checkArgument(d.Buffer.isBuffer(e),"Argument is expected to be a Buffer");var t=new Oe,r=!0,n=e.slice(0,1)[0]-27-4;n<0&&(r=!1,n=n+4);var i=e.slice(1,33),o=e.slice(33,65);return rr.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),rr.checkArgument(i.length===32,new Error("r must be 32 bytes")),rr.checkArgument(o.length===32,new Error("s must be 32 bytes")),t.compressed=r,t.i=n,t.r=Qi.fromBuffer(i),t.s=Qi.fromBuffer(o),t};Oe.fromDER=Oe.fromBuffer=function(e,t){var r=Oe.parseDER(e,t),n=new Oe;return n.r=r.r,n.s=r.s,n};Oe.fromTxFormat=function(e){var t=e.readUInt8(e.length-1),r=e.slice(0,e.length-1),n=Oe.fromDER(r,!1);return n.nhashtype=t,n};Oe.fromString=function(e){var t=d.Buffer.from(e,"hex");return Oe.fromDER(t)};function E1(e,t){rr.checkArgument(t.length>0,new Error("Length of "+e+" is zero")),rr.checkArgument(!(t[0]&128),new Error("Value of "+e+" is negative")),rr.checkArgument(!(t.length>1&&t[0]===0&&!(t[1]&128)),new Error("Value of "+e+" is excessively padded"))}Oe.parseDER=function(e,t){rr.checkArgument(d.Buffer.isBuffer(e),new Error("DER formatted signature should be a buffer")),n6.isUndefined(t)&&(t=!0);var r=e[0];rr.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=e[1],i=e.slice(2).length;rr.checkArgument(!t||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=e[2];rr.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var s=e[3],a=e.slice(4,4+s),f=Qi.fromBuffer(a),l=e[4]===0;rr.checkArgument(s===a.length,new Error("Length of r incorrect"));var m=e[4+s+0];rr.checkArgument(m===2,new Error("Integer byte for s should be 0x02"));var g=e[4+s+1],v=e.slice(4+s+2,4+s+2+g),E=Qi.fromBuffer(v),T=e[4+s+2]===0;rr.checkArgument(g===v.length,new Error("Length of s incorrect"));var M=4+s+2+g;rr.checkArgument(n===M-2,new Error("Length of signature incorrect")),t&&(E1("r",a),E1("s",v));var U={header:r,length:n,rheader:o,rlength:s,rneg:l,rbuf:a,r:f,sheader:m,slength:g,sneg:T,sbuf:v,s:E};return U};Oe.prototype.toCompact=function(e,t){if(e=typeof e=="number"?e:this.i,t=typeof t=="boolean"?t:this.compressed,!(e===0||e===1||e===2||e===3))throw new Error("i must be equal to 0, 1, 2, or 3");var r=e+27+4;t===!1&&(r=r-4);var n=d.Buffer.from([r]),i=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return d.Buffer.concat([n,i,o])};Oe.prototype.toBuffer=Oe.prototype.toDER=function(){var e=this.r.toBuffer(),t=this.s.toBuffer(),r=!!(e[0]&128),n=!!(t[0]&128),i=r?d.Buffer.concat([d.Buffer.from([0]),e]):e,o=n?d.Buffer.concat([d.Buffer.from([0]),t]):t,s=i.length,a=o.length,f=2+s+2+a,l=2,m=2,g=48,v=d.Buffer.concat([d.Buffer.from([g,f,l,s]),i,d.Buffer.from([m,a]),o]);return v};Oe.prototype.toString=function(){var e=this.toDER();return e.toString("hex")};Oe.isTxDER=function(e){if(e.length<9||e.length>73||e[0]!==48||e[1]!==e.length-3)return!1;var t=e[3];if(5+t>=e.length)return!1;var r=e[5+t];if(t+r+7!==e.length)return!1;var n=e.slice(4);if(e[2]!==2||t===0||n[0]&128||t>1&&n[0]===0&&!(n[1]&128))return!1;var i=e.slice(6+t);return!(e[6+t-2]!==2||r===0||i[0]&128||r>1&&i[0]===0&&!(i[1]&128))};Oe.prototype.hasLowS=function(){return!(this.s.lt(new Qi(1))||this.s.gt(new Qi("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};Oe.prototype.hasDefinedHashtype=function(){if(!i6.isNaturalNumber(this.nhashtype))return!1;var e=this.nhashtype&31;return!(e<Oe.SIGHASH_ALL||e>Oe.SIGHASH_SINGLE)};Oe.prototype.toTxFormat=function(){var e=this.toDER(),t=d.Buffer.alloc(1);return t.writeUInt8(this.nhashtype,0),d.Buffer.concat([e,t])};Oe.SIGHASH_ALL=1;Oe.SIGHASH_NONE=2;Oe.SIGHASH_SINGLE=3;Oe.SIGHASH_CHRONICLE=32;Oe.SIGHASH_FORKID=64;Oe.SIGHASH_ANYONECANPAY=128;Oe.prototype.isCanonical=function(){var e=fi(),t=e.getN().shrn(1);return this.s.lte(t)};Oe.prototype.toCanonical=function(){if(this.isCanonical())return new Oe({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var e=fi(),t=e.getN(),r=t.sub(this.s);return new Oe({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};Oe.prototype.validate=function(){if(!this.r||!this.s)throw new Error("Signature missing r or s component");if(this.r.isZero())throw new Error("Signature r component is zero");if(this.s.isZero())throw new Error("Signature s component is zero");var e=fi(),t=e.getN();if(this.r.gte(t))throw new Error("Signature r component >= curve order");if(this.s.gte(t))throw new Error("Signature s component >= curve order");if(this.r.isNeg())throw new Error("Signature r component is negative");if(this.s.isNeg())throw new Error("Signature s component is negative");return!0};Oe.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};Oe.prototype.applySecurityPatches=function(){var e=fi(),t=e.getN(),r=t.shrn(1);if(this.r.isZero()||this.s.isZero())throw new Error("Invalid signature: zero r or s");if(this.r.gte(t)||this.s.gte(t))throw new Error("Invalid signature: out of range");if(this.s.gt(r))throw new Error("Invalid signature: non-canonical (high) s");return this};x1.exports=Oe});var gp=B((M5,R1)=>{"use strict";p();var o6=ba(),Ur=ro(),s6=Ma(),dp=Jt(),$=hp(),to=Ar(),eo=nr(),I1=ya(),Xe=Le(),Re=ze(),pp=Jn(),A1=Nt(),a6=pr(),q=function e(t){if(!(this instanceof e))return new e(t);if(this.chunks=[],d.Buffer.isBuffer(t))return e.fromBuffer(t);if(t instanceof Ur)return e.fromAddress(t);if(t instanceof e)return e.fromBuffer(t.toBuffer());if(Re.isString(t))return e.fromString(t);Re.isObject(t)&&Re.isArray(t.chunks)&&this.set(t)};q.prototype.set=function(e){return Xe.checkArgument(Re.isObject(e)),Xe.checkArgument(Re.isArray(e.chunks)),this.chunks=e.chunks,this};q.fromBuffer=function(e){var t=new q;t.chunks=[];for(var r=new s6(e);!r.finished();)try{var n=r.readUInt8(),i,o;n>0&&n<$.OP_PUSHDATA1?(i=n,t.chunks.push({buf:r.read(i),len:i,opcodenum:n})):n===$.OP_PUSHDATA1?(i=r.readUInt8(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===$.OP_PUSHDATA2?(i=r.readUInt16LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===$.OP_PUSHDATA4?(i=r.readUInt32LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):t.chunks.push({opcodenum:n})}catch(s){throw s instanceof RangeError?new pp.Script.InvalidBuffer(e.toString("hex")):s}return t};q.prototype.toBuffer=function(){var e=this.chunks,t=0,r,n,i;for(r=0;r<e.length;r++)n=e[r],i=n.opcodenum,t+=1,n.buf&&(i<$.OP_PUSHDATA1?t+=Ec(n.buf):i===$.OP_PUSHDATA1?t+=1+Ec(n.buf):i===$.OP_PUSHDATA2?t+=2+Ec(n.buf):i===$.OP_PUSHDATA4&&(t+=4+Ec(n.buf)));var o=d.Buffer.alloc(t),s=0;for(r=0;r<e.length;r++)n=e[r],i=n.opcodenum,s=o.writeUInt8(n.opcodenum,s),n.buf&&(i<$.OP_PUSHDATA1?s+=n.buf.copy(o,s):i===$.OP_PUSHDATA1?(s=o.writeUInt8(n.len,s),s+=n.buf.copy(o,s)):i===$.OP_PUSHDATA2?(s=o.writeUInt16LE(n.len,s),s+=n.buf.copy(o,s)):i===$.OP_PUSHDATA4&&(s=o.writeUInt32LE(n.len,s),s+=n.buf.copy(o,s)));return o};function Ec(e){if(!d.Buffer.isBuffer(e))throw new o6.AssertionError({message:"chunk data must be a Buffer",actual:e,expected:"Buffer",operator:"isBuffer"});return e.length}function O1(e){if(/^0x[0-9a-fA-F]{2}$/.test(e)){var t=parseInt(e.slice(2),16);return t>$.OP_PUSHDATA4?t:void 0}}q.fromASM=function(e){var t=new q;if(t.chunks=[],e==="")return t;for(var r=e.split(" "),n=0;n<r.length;){var i=r[n],o=$(i),s=o.toNumber(),a=O1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(i==="0")s=0,t.chunks.push({opcodenum:s}),n=n+1;else if(i==="-1")s=$.OP_1NEGATE,t.chunks.push({opcodenum:s}),n=n+1;else if(Re.isUndefined(s)){var f=d.Buffer.from(r[n],"hex");if(f.toString("hex")!==r[n])throw new Error("invalid hex string in script");var l=f.length;l>=0&&l<$.OP_PUSHDATA1?s=l:l<Math.pow(2,8)?s=$.OP_PUSHDATA1:l<Math.pow(2,16)?s=$.OP_PUSHDATA2:l<Math.pow(2,32)&&(s=$.OP_PUSHDATA4),t.chunks.push({buf:f,len:f.length,opcodenum:s}),n=n+1}else t.chunks.push({opcodenum:s}),n=n+1}return t};q.fromHex=function(e){return new q(A1.Buffer.from(e,"hex"))};q.fromString=function(e){if(a6.isHexa(e)||e.length===0)return new q(A1.Buffer.from(e,"hex"));var t=new q;t.chunks=[];for(var r=e.split(" "),n=0;n<r.length;){var i=r[n],o=$(i),s=o.toNumber(),a=O1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(Re.isUndefined(s))if(s=parseInt(i),s>0&&s<$.OP_PUSHDATA1)t.chunks.push({buf:d.Buffer.from(r[n+1].slice(2),"hex"),len:s,opcodenum:s}),n=n+2;else throw new Error("Invalid script: "+JSON.stringify(e));else if(s===$.OP_PUSHDATA1||s===$.OP_PUSHDATA2||s===$.OP_PUSHDATA4){if(r[n+2].slice(0,2)!=="0x")throw new Error("Pushdata data must start with 0x");t.chunks.push({buf:d.Buffer.from(r[n+2].slice(2),"hex"),len:parseInt(r[n+1]),opcodenum:s}),n=n+3}else t.chunks.push({opcodenum:s}),n=n+1}return t};q.prototype._chunkToString=function(e,t){var r=e.opcodenum,n=t==="asm",i="";if(e.buf){var s=r===$.OP_PUSHDATA1||r===$.OP_PUSHDATA2||r===$.OP_PUSHDATA4;!n&&s&&(i=i+" "+$(r).toString()),e.len>0?n?i=i+" "+e.buf.toString("hex"):i=i+" "+e.len+" 0x"+e.buf.toString("hex"):n?i=i+" 0":s?i=i+" 0 0x":i=i+" OP_0"}else if(typeof $.reverseMap[r]<"u")n?r===0?i=i+" 0":r===79?i=i+" -1":i=i+" "+$(r).toString():i=i+" "+$(r).toString();else{var o=r.toString(16);o.length%2!==0&&(o="0"+o),i=i+" 0x"+o}return i};q.prototype.toASM=function(){for(var e="",t=0;t<this.chunks.length;t++){var r=this.chunks[t];e+=this._chunkToString(r,"asm")}return e.substr(1)};q.prototype.toString=function(){for(var e="",t=0;t<this.chunks.length;t++){var r=this.chunks[t];e+=this._chunkToString(r)}return e.substr(1)};q.prototype.toHex=function(){return this.toBuffer().toString("hex")};q.prototype.inspect=function(){return"<Script: "+this.toString()+">"};q.prototype.isPublicKeyHashOut=function(){return!!(this.chunks.length===5&&this.chunks[0].opcodenum===$.OP_DUP&&this.chunks[1].opcodenum===$.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===$.OP_EQUALVERIFY&&this.chunks[4].opcodenum===$.OP_CHECKSIG)};q.prototype.isPublicKeyHashOutPrefix=function(){return!!(this.chunks.length>=5&&this.chunks[0].opcodenum===$.OP_DUP&&this.chunks[1].opcodenum===$.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===$.OP_EQUALVERIFY&&this.chunks[4].opcodenum===$.OP_CHECKSIG)};q.prototype.isPublicKeyHashIn=function(){if(this.chunks.length===2){var e=this.chunks[0].buf,t=this.chunks[1].buf;if(e&&e.length&&e[0]===48&&t&&t.length){var r=t[0];if((r===4||r===6||r===7)&&t.length===65)return!0;if((r===3||r===2)&&t.length===33)return!0}}return!1};q.prototype.getPublicKey=function(){return Xe.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output"),this.chunks[0].buf};q.prototype.getPublicKeyHash=function(){return Xe.checkState(this.isPublicKeyHashOut(),"Can't retrieve PublicKeyHash from a non-PKH output"),this.chunks[2].buf};q.prototype.isPublicKeyOut=function(){if(this.chunks.length===2&&this.chunks[0].buf&&this.chunks[0].buf.length&&this.chunks[1].opcodenum===$.OP_CHECKSIG){var e=this.chunks[0].buf,t=e[0],r=!1;if(((t===4||t===6||t===7)&&e.length===65||(t===3||t===2)&&e.length===33)&&(r=!0),r)return to.isValid(e)}return!1};q.prototype.isPublicKeyIn=function(){if(this.chunks.length===1){var e=this.chunks[0].buf;if(e&&e.length&&e[0]===48)return!0}return!1};q.prototype.isScriptHashOut=function(){var e=this.toBuffer();return e.length===23&&e[0]===$.OP_HASH160&&e[1]===20&&e[e.length-1]===$.OP_EQUAL};q.prototype.isScriptHashIn=function(){if(this.chunks.length<=1)return!1;var e=this.chunks[this.chunks.length-1],t=e.buf;if(!t)return!1;var r;try{r=q.fromBuffer(t)}catch(i){if(i instanceof pp.Script.InvalidBuffer)return!1;throw i}var n=r.classify();return n!==q.types.UNKNOWN};q.prototype.isMultisigOut=function(){return this.chunks.length>3&&$.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)})&&$.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===$.OP_CHECKMULTISIG};q.prototype.isMultisigIn=function(){return this.chunks.length>=2&&this.chunks[0].opcodenum===0&&this.chunks.slice(1,this.chunks.length).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)&&eo.isTxDER(e.buf)})};q.prototype.isDataOut=function(){var e=this.chunks.length>=1&&this.chunks[0].opcodenum===$.OP_RETURN;if(!e)return!1;var t=this.chunks.slice(1),r=new q({chunks:t});return r.isPushOnly()};q.prototype.isSafeDataOut=function(){if(this.chunks.length<2||this.chunks[0].opcodenum!==$.OP_FALSE)return!1;var e=this.chunks.slice(1),t=new q({chunks:e});return t.isDataOut()};q.prototype.getData=function(){if(this.isSafeDataOut()){var e=this.chunks.slice(2),t=e.map(r=>r.buf);return t}if(this.isDataOut()||this.isScriptHashOut())return Re.isUndefined(this.chunks[1])?d.Buffer.alloc(0):d.Buffer.from(this.chunks[1].buf);if(this.isPublicKeyHashOut())return d.Buffer.from(this.chunks[2].buf);throw new Error("Unrecognized script type to get data from")};q.prototype.isPushOnly=function(){return Re.every(this.chunks,function(e){return e.opcodenum<=$.OP_16||e.opcodenum===$.OP_PUSHDATA1||e.opcodenum===$.OP_PUSHDATA2||e.opcodenum===$.OP_PUSHDATA4})};q.types={};q.types.UNKNOWN="Unknown";q.types.PUBKEY_OUT="Pay to public key";q.types.PUBKEY_IN="Spend from public key";q.types.PUBKEYHASH_OUT="Pay to public key hash";q.types.PUBKEYHASH_IN="Spend from public key hash";q.types.SCRIPTHASH_OUT="Pay to script hash";q.types.SCRIPTHASH_IN="Spend from script hash";q.types.MULTISIG_OUT="Pay to multisig";q.types.MULTISIG_IN="Spend from multisig";q.types.DATA_OUT="Data push";q.types.SAFE_DATA_OUT="Safe data push";q.OP_RETURN_STANDARD_SIZE=220;q.prototype.classify=function(){if(this._isInput)return this.classifyInput();if(this._isOutput)return this.classifyOutput();var e=this.classifyOutput();return e!==q.types.UNKNOWN?e:this.classifyInput()};q.outputIdentifiers={};q.outputIdentifiers.PUBKEY_OUT=q.prototype.isPublicKeyOut;q.outputIdentifiers.PUBKEYHASH_OUT=q.prototype.isPublicKeyHashOut;q.outputIdentifiers.MULTISIG_OUT=q.prototype.isMultisigOut;q.outputIdentifiers.SCRIPTHASH_OUT=q.prototype.isScriptHashOut;q.outputIdentifiers.DATA_OUT=q.prototype.isDataOut;q.outputIdentifiers.SAFE_DATA_OUT=q.prototype.isSafeDataOut;q.prototype.classifyOutput=function(){for(var e in q.outputIdentifiers)if(q.outputIdentifiers[e].bind(this)())return q.types[e];return q.types.UNKNOWN};q.inputIdentifiers={};q.inputIdentifiers.PUBKEY_IN=q.prototype.isPublicKeyIn;q.inputIdentifiers.PUBKEYHASH_IN=q.prototype.isPublicKeyHashIn;q.inputIdentifiers.MULTISIG_IN=q.prototype.isMultisigIn;q.inputIdentifiers.SCRIPTHASH_IN=q.prototype.isScriptHashIn;q.prototype.classifyInput=function(){for(var e in q.inputIdentifiers)if(q.inputIdentifiers[e].bind(this)())return q.types[e];return q.types.UNKNOWN};q.prototype.isStandard=function(){return this.classify()!==q.types.UNKNOWN};q.prototype.prepend=function(e){return this._addByType(e,!0),this};q.prototype.equals=function(e){if(Xe.checkState(e instanceof q,"Must provide another script"),this.chunks.length!==e.chunks.length)return!1;var t;for(t=0;t<this.chunks.length;t++){if(d.Buffer.isBuffer(this.chunks[t].buf)&&!d.Buffer.isBuffer(e.chunks[t].buf)||d.Buffer.isBuffer(this.chunks[t].buf)&&!this.chunks[t].buf.equals(e.chunks[t].buf))return!1;if(this.chunks[t].opcodenum!==e.chunks[t].opcodenum)return!1}return!0};q.prototype.add=function(e){return this._addByType(e,!1),this};q.prototype._addByType=function(e,t){if(typeof e=="string")this._addOpcode(e,t);else if(typeof e=="number")this._addOpcode(e,t);else if(e instanceof $)this._addOpcode(e,t);else if(d.Buffer.isBuffer(e))this._addBuffer(e,t);else if(e instanceof q)this.chunks=this.chunks.concat(e.chunks);else if(typeof e=="object")this._insertAtPosition(e,t);else throw new Error("Invalid script chunk")};q.prototype._insertAtPosition=function(e,t){t?this.chunks.unshift(e):this.chunks.push(e)};q.prototype._addOpcode=function(e,t){var r;return typeof e=="number"?r=e:e instanceof $?r=e.toNumber():r=$(e).toNumber(),this._insertAtPosition({opcodenum:r},t),this};q.prototype._addBuffer=function(e,t){var r,n=e.length;if(n>=0&&n<$.OP_PUSHDATA1)r=n;else if(n<Math.pow(2,8))r=$.OP_PUSHDATA1;else if(n<Math.pow(2,16))r=$.OP_PUSHDATA2;else if(n<Math.pow(2,32))r=$.OP_PUSHDATA4;else throw new Error("You can't push that much data");return this._insertAtPosition({buf:e,len:n,opcodenum:r},t),this};q.prototype.removeCodeseparators=function(){for(var e=[],t=0;t<this.chunks.length;t++)this.chunks[t].opcodenum!==$.OP_CODESEPARATOR&&e.push(this.chunks[t]);return this.chunks=e,this};q.buildMultisigOut=function(e,t,r){Xe.checkArgument(t<=e.length,"Number of required signatures must be less than or equal to the number of public keys"),r=r||{};var n=new q;n.add($.smallInt(t)),e=Re.map(e,to);var i=e;r.noSorting||(i=e.map(a=>a.toString("hex")).sort().map(a=>new to(a)));for(var o=0;o<i.length;o++){var s=i[o];n.add(s.toBuffer())}return n.add($.smallInt(e.length)),n.add($.OP_CHECKMULTISIG),n};q.buildMultisigIn=function(e,t,r,n){Xe.checkArgument(Re.isArray(e)),Xe.checkArgument(Re.isNumber(t)),Xe.checkArgument(Re.isArray(r)),n=n||{};var i=new q;return i.add($.OP_0),Re.each(r,function(o){Xe.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i};q.buildP2SHMultisigIn=function(e,t,r,n){Xe.checkArgument(Re.isArray(e)),Xe.checkArgument(Re.isNumber(t)),Xe.checkArgument(Re.isArray(r)),n=n||{};var i=new q;return i.add($.OP_0),Re.each(r,function(o){Xe.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i.add((n.cachedMultisig||q.buildMultisigOut(e,t,n)).toBuffer()),i};q.buildPublicKeyHashOut=function(e){Xe.checkArgument(!Re.isUndefined(e)),Xe.checkArgument(e instanceof to||e instanceof Ur||Re.isString(e)),e instanceof to?e=e.toAddress():Re.isString(e)&&(e=new Ur(e));var t=new q;return t.add($.OP_DUP).add($.OP_HASH160).add(e.hashBuffer).add($.OP_EQUALVERIFY).add($.OP_CHECKSIG),t._network=e.network,t};q.buildPublicKeyOut=function(e){Xe.checkArgument(e instanceof to);var t=new q;return t.add(e.toBuffer()).add($.OP_CHECKSIG),t};q.buildDataOut=function(e,t){Xe.checkArgument(Re.isUndefined(e)||Re.isString(e)||Re.isArray(e)||d.Buffer.isBuffer(e));var r=e;Re.isArray(r)||(r=[e]);var n=new q;n.add($.OP_RETURN);for(let i of r)Xe.checkArgument(Re.isUndefined(i)||Re.isString(i)||d.Buffer.isBuffer(i)),Re.isString(i)&&(i=d.Buffer.from(i,t)),Re.isUndefined(i)||n.add(i);return n};q.buildSafeDataOut=function(e,t){var r=q.buildDataOut(e,t),n=new q;return n.add($.OP_FALSE),n.add(r),n};q.buildScriptHashOut=function(e){Xe.checkArgument(e instanceof q||e instanceof Ur&&e.isPayToScriptHash());var t=new q;return t.add($.OP_HASH160).add(e instanceof Ur?e.hashBuffer:dp.sha256ripemd160(e.toBuffer())).add($.OP_EQUAL),t._network=e._network||e.network,t};q.buildPublicKeyIn=function(e,t){Xe.checkArgument(e instanceof eo||d.Buffer.isBuffer(e)),Xe.checkArgument(Re.isUndefined(t)||Re.isNumber(t)),e instanceof eo&&(e=e.toBuffer());var r=new q;return r.add(d.Buffer.concat([e,d.Buffer.from([(t||eo.SIGHASH_ALL)&255])])),r};q.buildPublicKeyHashIn=function(e,t,r){Xe.checkArgument(t instanceof eo||d.Buffer.isBuffer(t)),Xe.checkArgument(Re.isUndefined(r)||Re.isNumber(r)),t instanceof eo&&(t=t.toBuffer());var n=new q().add(d.Buffer.concat([t,d.Buffer.from([(r||eo.SIGHASH_ALL)&255])])).add(new to(e).toBuffer());return n};q.empty=function(){return new q};q.prototype.toScriptHashOut=function(){return q.buildScriptHashOut(this)};q.fromAddress=function(e){if(e=Ur(e),e.isPayToScriptHash())return q.buildScriptHashOut(e);if(e.isPayToPublicKeyHash())return q.buildPublicKeyHashOut(e);throw new pp.Script.UnrecognizedAddress(e)};q.prototype.getAddressInfo=function(e){if(this._isInput)return this._getInputAddressInfo();if(this._isOutput)return this._getOutputAddressInfo();var t=this._getOutputAddressInfo();return t||this._getInputAddressInfo()};q.prototype._getOutputAddressInfo=function(){var e={};if(this.isScriptHashOut())e.hashBuffer=this.getData(),e.type=Ur.PayToScriptHash;else if(this.isPublicKeyHashOut())e.hashBuffer=this.getData(),e.type=Ur.PayToPublicKeyHash;else return!1;return e};q.prototype._getInputAddressInfo=function(){var e={};if(this.isPublicKeyHashIn())e.hashBuffer=dp.sha256ripemd160(this.chunks[1].buf),e.type=Ur.PayToPublicKeyHash;else if(this.isScriptHashIn())e.hashBuffer=dp.sha256ripemd160(this.chunks[this.chunks.length-1].buf),e.type=Ur.PayToScriptHash;else return!1;return e};q.prototype.toAddress=function(e){var t=this.getAddressInfo();return t?(t.network=I1.get(e)||this._network||I1.defaultNetwork,new Ur(t)):!1};q.prototype.findAndDelete=function(e){for(var t=e.toBuffer(),r=t.length?t[0]:-1,n=0;n<this.chunks.length;n++){var i=this.chunks[n];if(!(i.opcodenum!==r&&u6(i))){var o=q({chunks:[i]}).toBuffer();t.equals(o)&&(this.chunks.splice(n,1),n--)}}return this};function u6(e){var t=e.opcodenum;if(typeof t!="number"||!Number.isInteger(t)||t<0||t>255)return!1;if(!e.buf||t>$.OP_PUSHDATA4)return!0;if(!d.Buffer.isBuffer(e.buf))return!1;var r=e.len;return t===$.OP_PUSHDATA1?Number.isInteger(r)&&r>=0&&r<=255:t===$.OP_PUSHDATA2?Number.isInteger(r)&&r>=0&&r<=65535:t===$.OP_PUSHDATA4?Number.isInteger(r)&&r>=0&&r<=4294967295:!0}q.prototype.checkMinimalPush=function(e){var t=this.chunks[e],r=t.buf,n=t.opcodenum;return r?r.length===0?n===$.OP_0:r.length===1&&r[0]>=1&&r[0]<=16?n===$.OP_1+(r[0]-1):r.length===1&&r[0]===129?n===$.OP_1NEGATE:r.length<=75?n===r.length:r.length<=255?n===$.OP_PUSHDATA1:r.length<=65535?n===$.OP_PUSHDATA2:!0:!0};q.prototype._decodeOP_N=function(e){if(e===$.OP_0)return 0;if(e>=$.OP_1&&e<=$.OP_16)return e-($.OP_1-1);throw new Error("Invalid opcode: "+JSON.stringify(e))};q.prototype.getSignatureOperationsCount=function(e){e=Re.isUndefined(e)?!0:e;var t=this,r=0,n=$.OP_INVALIDOPCODE;return Re.each(t.chunks,function(o){var s=o.opcodenum;s===$.OP_CHECKSIG||s===$.OP_CHECKSIGVERIFY?r++:(s===$.OP_CHECKMULTISIG||s===$.OP_CHECKMULTISIGVERIFY)&&(e&&n>=$.OP_1&&n<=$.OP_16?r+=t._decodeOP_N(n):r+=20),n=s}),r};R1.exports=q});var rs=B((C5,P1)=>{"use strict";p();var T1=ba(),ot=function e(t){if(!(this instanceof e))return new e(t);this.bufLen=0,t?this.set(t):this.bufs=[]};ot.prototype.set=function(e){return this.bufs=e.bufs||this.bufs||[],this.bufLen=this.bufs.reduce(function(t,r){return t+r.length},0),this};ot.prototype.toBuffer=function(){return this.concat()};ot.prototype.concat=function(){return d.Buffer.concat(this.bufs,this.bufLen)};ot.prototype.write=function(e){return T1(d.Buffer.isBuffer(e)),this.bufs.push(e),this.bufLen+=e.length,this};ot.prototype.writeReverse=function(e){return T1(d.Buffer.isBuffer(e)),this.bufs.push(d.Buffer.from(e).reverse()),this.bufLen+=e.length,this};ot.prototype.writeUInt8=function(e){var t=d.Buffer.alloc(1);return t.writeUInt8(e,0),this.write(t),this};ot.prototype.writeUInt16BE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16BE(e,0),this.write(t),this};ot.prototype.writeUInt16LE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16LE(e,0),this.write(t),this};ot.prototype.writeUInt32BE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32BE(e,0),this.write(t),this};ot.prototype.writeInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeInt32LE(e,0),this.write(t),this};ot.prototype.writeUInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32LE(e,0),this.write(t),this};ot.prototype.writeUInt64BEBN=function(e){var t=e.toBuffer({size:8});return this.write(t),this};ot.prototype.writeUInt64LEBN=function(e){var t=e.toBuffer({size:8});return this.writeReverse(t),this};ot.prototype.writeVarintNum=function(e){var t=ot.varintBufNum(e);return this.write(t),this};ot.prototype.writeVarintBN=function(e){var t=ot.varintBufBN(e);return this.write(t),this};ot.varintBufNum=function(e){var t;return e<253?(t=d.Buffer.alloc(1),t.writeUInt8(e,0)):e<65536?(t=d.Buffer.alloc(3),t.writeUInt8(253,0),t.writeUInt16LE(e,1)):e<4294967296?(t=d.Buffer.alloc(5),t.writeUInt8(254,0),t.writeUInt32LE(e,1)):(t=d.Buffer.alloc(9),t.writeUInt8(255,0),t.writeInt32LE(e&-1,1),t.writeUInt32LE(Math.floor(e/4294967296),5)),t};ot.varintBufBN=function(e){var t,r=e.toNumber();if(r<253)t=d.Buffer.alloc(1),t.writeUInt8(r,0);else if(r<65536)t=d.Buffer.alloc(3),t.writeUInt8(253,0),t.writeUInt16LE(r,1);else if(r<4294967296)t=d.Buffer.alloc(5),t.writeUInt8(254,0),t.writeUInt32LE(r,1);else{var n=new ot;n.writeUInt8(255),n.writeUInt64LEBN(e),t=n.concat()}return t};P1.exports=ot});var Ca=B((D5,M1)=>{"use strict";p();var B1=rs(),N1=Ma(),f6=wr(),Fr=function e(t){if(!(this instanceof e))return new e(t);if(d.Buffer.isBuffer(t))this.buf=t;else if(typeof t=="number"){var r=t;this.fromNumber(r)}else if(t instanceof f6){var n=t;this.fromBN(n)}else if(t){var i=t;this.set(i)}};Fr.prototype.set=function(e){return this.buf=e.buf||this.buf,this};Fr.prototype.fromString=function(e){return this.set({buf:d.Buffer.from(e,"hex")}),this};Fr.prototype.toString=function(){return this.buf.toString("hex")};Fr.prototype.fromBuffer=function(e){return this.buf=e,this};Fr.prototype.fromBufferReader=function(e){return this.buf=e.readVarintBuf(),this};Fr.prototype.fromBN=function(e){return this.buf=B1().writeVarintBN(e).concat(),this};Fr.prototype.fromNumber=function(e){return this.buf=B1().writeVarintNum(e).concat(),this};Fr.prototype.toBuffer=function(){return this.buf};Fr.prototype.toBN=function(){return N1(this.buf).readVarintBN()};Fr.prototype.toNumber=function(){return N1(this.buf).readVarintNum()};M1.exports=Fr});var Cn=B((F5,C1)=>{"use strict";p();var xc=ze(),yp=wr(),k1=Nt(),Ic=pr(),c6=rs(),l6=Ca(),mp=qr(),vp=Le(),h6=Jn(),d6=9007199254740991;function jt(e){if(!(this instanceof jt))return new jt(e);if(xc.isObject(e))if(this.satoshis=e.satoshis,d.Buffer.isBuffer(e.script))this._scriptBuffer=e.script;else{var t;xc.isString(e.script)&&Ic.isHexa(e.script)?t=k1.Buffer.from(e.script,"hex"):t=e.script,this.setScript(t)}else throw new TypeError("Unrecognized argument for Output")}Object.defineProperty(jt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this._script?this._script:(this.setScriptFromBuffer(this._scriptBuffer),this._script)}});Object.defineProperty(jt.prototype,"satoshis",{configurable:!1,enumerable:!0,get:function(){return this._satoshis},set:function(e){e instanceof yp?(this._satoshisBN=e,this._satoshis=e.toNumber()):xc.isString(e)?(this._satoshis=parseInt(e),this._satoshisBN=yp.fromNumber(this._satoshis)):(vp.checkArgument(Ic.isNaturalNumber(e),"Output satoshis is not a natural number"),this._satoshisBN=yp.fromNumber(e),this._satoshis=e),vp.checkState(Ic.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});jt.prototype.invalidSatoshis=function(){return this._satoshis>d6?"transaction txout satoshis greater than max safe integer":this._satoshis!==this._satoshisBN.toNumber()?"transaction txout satoshis has corrupted value":this._satoshis<0?"transaction txout negative":!1};Object.defineProperty(jt.prototype,"satoshisBN",{configurable:!1,enumerable:!0,get:function(){return this._satoshisBN},set:function(e){this._satoshisBN=e,this._satoshis=e.toNumber(),vp.checkState(Ic.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});jt.prototype.toObject=jt.prototype.toJSON=function(){var t={satoshis:this.satoshis};return t.script=this._scriptBuffer.toString("hex"),t};jt.fromObject=function(e){return new jt(e)};jt.prototype.setScriptFromBuffer=function(e){this._scriptBuffer=e;try{this._script=mp.fromBuffer(this._scriptBuffer),this._script._isOutput=!0}catch(t){if(t instanceof h6.Script.InvalidBuffer)this._script=null;else throw t}};jt.prototype.setScript=function(e){if(e instanceof mp)this._scriptBuffer=e.toBuffer(),this._script=e,this._script._isOutput=!0;else if(xc.isString(e))this._script=mp.fromString(e),this._scriptBuffer=this._script.toBuffer(),this._script._isOutput=!0;else if(d.Buffer.isBuffer(e))this.setScriptFromBuffer(e);else throw new TypeError("Invalid argument type: script");return this};jt.prototype.inspect=function(){var e;return this.script?e=this.script.inspect():e=this._scriptBuffer.toString("hex"),"<Output ("+this.satoshis+" sats) "+e+">"};jt.fromBufferReader=function(e){var t={};t.satoshis=e.readUInt64LEBN();var r=e.readVarintNum();return r!==0?t.script=e.read(r):t.script=k1.Buffer.from([]),new jt(t)};jt.prototype.toBufferWriter=function(e){e||(e=new c6),e.writeUInt64LEBN(this._satoshisBN);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e};jt.prototype.getSize=function(){var e=this.script.toBuffer().length,t=l6(e).toBuffer().length;return 8+t+e};C1.exports=jt});var La=B((H5,L1)=>{"use strict";p();var gr=wr(),cn=fi(),p6=nr(),g6=Ar(),y6=Qs(),mi=Jt(),m6=ze(),bp=Le(),Ke=function e(t){if(!(this instanceof e))return new e(t);t&&this.set(t)};Object.defineProperty(Ke.prototype,"k",{get:function(){return this._k},set:function(e){this._k=e,this._kFresh=!0},enumerable:!0,configurable:!0});Ke.prototype.set=function(e){if(this.hashbuf=e.hashbuf||this.hashbuf,this.endian=e.endian||this.endian,this.privkey=e.privkey||this.privkey,this.pubkey=e.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey),e.sig)if(d.Buffer.isBuffer(e.sig)){var t=nr();this.sig=t.fromDER(e.sig)}else this.sig=e.sig;else this.sig=this.sig;return e.k&&(this.k=e.k),this.verified=e.verified||this.verified,this};Ke.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()};Ke.prototype.calci=function(){for(var e=0;e<4;e++){this.sig.i=e;var t;try{t=this.toPublicKey()}catch(r){console.error(r);continue}if(t.point.eq(this.pubkey.point))return this.sig.compressed=this.pubkey.compressed,this}throw this.sig.i=void 0,new Error("Unable to find valid recovery factor")};Ke.fromString=function(e){var t=JSON.parse(e);return new Ke(t)};Ke.prototype.randomK=function(){var e=cn.getN(),t;do t=gr.fromBuffer(y6.getRandomBuffer(32));while(!(t.lt(e)&&t.gt(gr.Zero)));return this.k=t,this};Ke.prototype.deterministicK=function(e){m6.isUndefined(e)&&(e=0);var t=d.Buffer.alloc(32);t.fill(1);var r=d.Buffer.alloc(32);r.fill(0);var n=this.privkey.bn.toBuffer({size:32}),i=this.endian==="little"?d.Buffer.from(this.hashbuf).reverse():this.hashbuf;r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0]),n,i]),r),t=mi.sha256hmac(t,r),r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([1]),n,i]),r),t=mi.sha256hmac(t,r),t=mi.sha256hmac(t,r);for(var o=gr.fromBuffer(t),s=cn.getN(),a=0;a<e||!(o.lt(s)&&o.gt(gr.Zero));a++)r=mi.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0])]),r),t=mi.sha256hmac(t,r),t=mi.sha256hmac(t,r),o=gr.fromBuffer(t);return this.k=o,this};Ke.prototype.toPublicKey=function(){var e=this.sig.i;bp.checkArgument(e===0||e===1||e===2||e===3,new Error("i must be equal to 0, 1, 2, or 3"));var t=gr.fromBuffer(this.hashbuf),r=this.sig.r,n=this.sig.s,i=e&1,o=e>>1,s=cn.getN(),a=cn.getG(),f=o?r.add(s):r,l=cn.fromX(i,f),m=l.mul(s);if(!m.isInfinity())throw new Error("nR is not a valid curve point");var g=t.neg().umod(s),v=r.invm(s),E=l.mul(n).add(a.mul(g)).mul(v),T=g6.fromPoint(E,this.sig.compressed);return T};Ke.prototype.sigError=function(){if(!d.Buffer.isBuffer(this.hashbuf)||this.hashbuf.length!==32)return"hashbuf must be a 32 byte buffer";var e=this.sig.r,t=this.sig.s,r=cn.getN();try{if(e.lte(gr.Zero)||t.lte(gr.Zero)||e.gte(r)||t.gte(r))return"r and s not in range";var n=gr.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:void 0),i=t.invm(r),o=i.mul(n).umod(r),s=i.mul(e).umod(r),a=cn.getG().mulAdd(o,this.pubkey.point,s);return a.isInfinity()?"p is infinity":a.getX().umod(r).cmp(e)!==0?"Invalid signature":!1}catch(f){return"Signature security validation failed: "+f.message}};Ke.toLowS=function(e){return e.gt(gr.fromBuffer(d.Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=cn.getN().sub(e)),e};Ke.prototype._findSignature=function(e,t){var r=cn.getN(),n=cn.getG(),i=0,o,s,a,f;do(!this.k||!this._kFresh||i>0)&&this.deterministicK(i),i++,o=this.k,s=n.mul(o),a=s.x.umod(r),f=o.invm(r).mul(t.add(e.mul(a))).umod(r);while(a.cmp(gr.Zero)<=0||f.cmp(gr.Zero)<=0);return this._kFresh=!1,f=Ke.toLowS(f),{s:f,r:a}};Ke.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;bp.checkState(e&&t&&r,new Error("invalid parameters")),bp.checkState(d.Buffer.isBuffer(e)&&e.length===32,new Error("hashbuf must be a 32 byte buffer"));var n=gr.fromBuffer(e,this.endian?{endian:this.endian}:void 0),i=this._findSignature(r,n);return i.compressed=this.pubkey.compressed,this.sig=new p6(i),this};Ke.prototype.signRandomK=function(){return this.randomK(),this.sign()};Ke.prototype.toString=function(){var e={};return this.hashbuf&&(e.hashbuf=this.hashbuf.toString("hex")),this.privkey&&(e.privkey=this.privkey.toString()),this.pubkey&&(e.pubkey=this.pubkey.toString()),this.sig&&(e.sig=this.sig.toString()),this.k&&(e.k=this.k.toString()),JSON.stringify(e)};Ke.prototype.verify=function(){return this.verified=!this.sigError(),this.verified};Ke.prototype.verifyBool=function(){return this.verify()===!0};Ke.sign=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).sign().sig};Ke.signWithCalcI=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).sign().calci().sig};Ke.signRandomK=function(e,t,r){return Ke().set({hashbuf:e,endian:r,privkey:t}).signRandomK().sig};Ke.verify=function(e,t,r,n){return Ke().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify()};L1.exports=Ke});var ns=B((K5,q1)=>{"use strict";p();var vi=ze(),v6=Le(),Da=Jn(),b6=rs(),_p=Nt(),U1=pr(),Ac=qr(),_6=bi(),D1=Cn(),Oc=4294967295,S6=Oc-2,F1=Oc,w6=Oc-1;function Ge(e){if(!(this instanceof Ge))return new Ge(e);if(e)return this._fromObject(e)}Ge.MAXINT=Oc;Ge.DEFAULT_SEQNUMBER=F1;Ge.DEFAULT_LOCKTIME_SEQNUMBER=w6;Ge.DEFAULT_RBF_SEQNUMBER=S6;Ge.BASE_SIZE=40;Object.defineProperty(Ge.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this.isNull()?null:(this._script||(this._script=new Ac(this._scriptBuffer),this._script._isInput=!0),this._script)}});Ge.fromObject=function(e){v6.checkArgument(vi.isObject(e));var t=new Ge;return t._fromObject(e)};Ge.prototype._fromObject=function(e){var t;if(vi.isString(e.prevTxId)&&U1.isHexa(e.prevTxId)?t=_p.Buffer.from(e.prevTxId,"hex"):t=e.prevTxId,this.output=e.output?e.output instanceof D1?e.output:new D1(e.output):void 0,this.prevTxId=t||e.txidbuf,this.outputIndex=vi.isUndefined(e.outputIndex)?e.txoutnum:e.outputIndex,this.sequenceNumber=vi.isUndefined(e.sequenceNumber)?vi.isUndefined(e.seqnum)?F1:e.seqnum:e.sequenceNumber,vi.isUndefined(e.script)&&vi.isUndefined(e.scriptBuffer))throw new Da.Transaction.Input.MissingScript;return this.setScript(e.scriptBuffer||e.script),this};Ge.prototype.toObject=Ge.prototype.toJSON=function(){var t={prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,sequenceNumber:this.sequenceNumber,script:this._scriptBuffer.toString("hex")};return this.script&&(t.scriptString=this.script.toString()),this.output&&(t.output=this.output.toObject()),t};Ge.fromBufferReader=function(e){var t=new Ge;return t.prevTxId=e.readReverse(32),t.outputIndex=e.readUInt32LE(),t._scriptBuffer=e.readVarLengthBuffer(),t.sequenceNumber=e.readUInt32LE(),t};Ge.prototype.toBufferWriter=function(e){e||(e=new b6),e.writeReverse(this.prevTxId),e.writeUInt32LE(this.outputIndex);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e.writeUInt32LE(this.sequenceNumber),e};Ge.prototype.setScript=function(e){if(this._script=null,e instanceof Ac)this._script=e,this._script._isInput=!0,this._scriptBuffer=e.toBuffer();else if(e===null)this._script=Ac.empty(),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(U1.isHexa(e))this._scriptBuffer=_p.Buffer.from(e,"hex");else if(vi.isString(e))this._script=new Ac(e),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(d.Buffer.isBuffer(e))this._scriptBuffer=_p.Buffer.from(e);else throw new TypeError("Invalid argument type: script");return this};Ge.prototype.getSignatures=function(){throw new Da.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: "+JSON.stringify(this))};Ge.prototype.isFullySigned=function(){throw new Da.AbstractMethodInvoked("Input#isFullySigned")};Ge.prototype.isFinal=function(){return this.sequenceNumber===Ge.MAXINT};Ge.prototype.addSignature=function(){throw new Da.AbstractMethodInvoked("Input#addSignature")};Ge.prototype.clearSignatures=function(){throw new Da.AbstractMethodInvoked("Input#clearSignatures")};Ge.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,_6.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ge.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};Ge.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};q1.exports=Ge});var is=B((V5,H1)=>{"use strict";p();H1.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}});var ss=B((z5,G1)=>{"use strict";p();var os=ze(),Or=Le(),E6=is(),j1=pr(),K1=Ar(),x6=Jn(),Ua=nr();function Hr(e){if(!(this instanceof Hr))return new Hr(e);if(e instanceof Hr)return e;if(os.isObject(e))return this._fromObject(e);throw new x6.InvalidArgument("TransactionSignatures must be instantiated from an object")}E6(Hr,Ua);Hr.prototype._fromObject=function(e){return this._checkObjectArgs(e),this.publicKey=new K1(e.publicKey),this.prevTxId=d.Buffer.isBuffer(e.prevTxId)?e.prevTxId:d.Buffer.from(e.prevTxId,"hex"),this.outputIndex=e.outputIndex,this.inputIndex=e.inputIndex,this.signature=e.signature instanceof Ua?e.signature:d.Buffer.isBuffer(e.signature)?Ua.fromBuffer(e.signature):Ua.fromString(e.signature),this.sigtype=e.sigtype,this};Hr.prototype._checkObjectArgs=function(e){Or.checkArgument(K1(e.publicKey),"publicKey"),Or.checkArgument(!os.isUndefined(e.inputIndex),"inputIndex"),Or.checkArgument(!os.isUndefined(e.outputIndex),"outputIndex"),Or.checkState(os.isNumber(e.inputIndex),"inputIndex must be a number"),Or.checkState(os.isNumber(e.outputIndex),"outputIndex must be a number"),Or.checkArgument(e.signature,"signature"),Or.checkArgument(e.prevTxId,"prevTxId"),Or.checkState(e.signature instanceof Ua||d.Buffer.isBuffer(e.signature)||j1.isHexa(e.signature),"signature must be a buffer or hexa value"),Or.checkState(d.Buffer.isBuffer(e.prevTxId)||j1.isHexa(e.prevTxId),"prevTxId must be a buffer or hexa value"),Or.checkArgument(e.sigtype,"sigtype"),Or.checkState(os.isNumber(e.sigtype),"sigtype must be a number")};Hr.prototype.toObject=Hr.prototype.toJSON=function(){return{publicKey:this.publicKey.toString(),prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,inputIndex:this.inputIndex,signature:this.signature.toString(),sigtype:this.sigtype}};Hr.fromObject=function(e){return Or.checkArgument(e),new Hr(e)};G1.exports=Hr});var $1=B(($5,Y1)=>{"use strict";p();var I6=is(),W1=Le(),Sp=ns(),A6=Cn(),O6=bi(),z1=qr(),V1=nr(),R6=ss();function Ln(){Sp.apply(this,arguments)}I6(Ln,Sp);Ln.prototype.getSignatures=function(e,t,r,n){W1.checkState(this.output instanceof A6),n=n||V1.SIGHASH_ALL|V1.SIGHASH_FORKID;var i=t.toPublicKey();return i.toString()===this.output.script.getPublicKey().toString("hex")?[new R6({publicKey:i,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:O6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Ln.prototype.addSignature=function(e,t){return W1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(z1.buildPublicKeyIn(t.signature.toDER(),t.sigtype)),this};Ln.prototype.clearSignatures=function(){return this.setScript(z1.empty()),this};Ln.prototype.isFullySigned=function(){return this.script.isPublicKeyIn()};Ln.SCRIPT_MAX_SIZE=74;Ln.prototype._estimateSize=function(){return Sp.BASE_SIZE+Ln.SCRIPT_MAX_SIZE};Y1.exports=Ln});var ex=B((X5,Q1)=>{"use strict";p();var T6=is(),X1=Le(),P6=Jt(),wp=ns(),B6=Cn(),N6=bi(),J1=qr(),Z1=nr(),M6=ss();function Dn(){wp.apply(this,arguments)}T6(Dn,wp);Dn.prototype.getSignatures=function(e,t,r,n,i){X1.checkState(this.output instanceof B6),i=i||P6.sha256ripemd160(t.publicKey.toBuffer()),n=n||Z1.SIGHASH_ALL|Z1.SIGHASH_FORKID;var o=this.output.script.chunks[2]&&this.output.script.chunks[2].buf;return o&&i.equals(o)?[new M6({publicKey:t.publicKey,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:N6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Dn.prototype.addSignature=function(e,t){return X1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(J1.buildPublicKeyHashIn(t.publicKey,t.signature.toDER(),t.sigtype)),this};Dn.prototype.clearSignatures=function(){return this.setScript(J1.empty()),this};Dn.prototype.isFullySigned=function(){return this.script.isPublicKeyHashIn()};Dn.SCRIPT_MAX_SIZE=108;Dn.prototype._estimateSize=function(){return wp.BASE_SIZE+Dn.SCRIPT_MAX_SIZE};Q1.exports=Dn});var nx=B((Q5,rx)=>{"use strict";p();var jr=ze(),k6=is(),Tc=ns(),C6=Cn(),Fa=Le(),tx=qr(),Rc=nr(),Ep=bi(),xp=ss(),L6=Ar(),D6=Ca();function Ct(e,t,r,n){Tc.apply(this,arguments);var i=this;t=t||e.publicKeys,r=r||e.threshold,n=n||e.signatures,this.publicKeys=t.map(o=>o.toString("hex")).sort().map(o=>new L6(o)),Fa.checkState(tx.buildMultisigOut(this.publicKeys,r).equals(this.output.script),"Provided public keys don't match to the provided output script"),this.publicKeyIndex={},jr.each(this.publicKeys,function(o,s){i.publicKeyIndex[o.toString()]=s}),this.threshold=r,this.signatures=n?this._deserializeSignatures(n):new Array(this.publicKeys.length)}k6(Ct,Tc);Ct.prototype.toObject=function(){var e=Tc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=jr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Ct.prototype._deserializeSignatures=function(e){return jr.map(e,function(t){if(t)return new xp(t)})};Ct.prototype._serializeSignatures=function(){return jr.map(this.signatures,function(e){if(e)return e.toObject()})};Ct.prototype.getSignatures=function(e,t,r,n){Fa.checkState(this.output instanceof C6),n=n||Rc.SIGHASH_ALL|Rc.SIGHASH_FORKID;var i=this,o=[];return jr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new xp({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:Ep.sign(e,t,n,r,i.output.script,i.output.satoshisBN),sigtype:n}))}),o};Ct.prototype.addSignature=function(e,t){return Fa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),Fa.checkArgument(!jr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),Fa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Ct.prototype._updateScript=function(){return this.setScript(tx.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures())),this};Ct.prototype._createSignatures=function(){return jr.map(jr.filter(this.signatures,function(e){return!jr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Ct.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Ct.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Ct.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Ct.prototype.countSignatures=function(){return jr.reduce(this.signatures,function(e,t){return e+!!t},0)};Ct.prototype.publicKeysWithoutSignature=function(){var e=this;return jr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Ct.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,Ep.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ct.normalizeSignatures=function(e,t,r,n,i){return i.map(function(o){var s=null;return n=n.filter(function(a){if(s)return!0;var f=new xp({signature:Rc.fromTxFormat(a),publicKey:o,prevTxId:t.prevTxId,outputIndex:t.outputIndex,inputIndex:r,sigtype:Rc.SIGHASH_ALL});f.signature.nhashtype=f.sigtype;var l=Ep.verify(e,f.signature,f.publicKey,f.inputIndex,t.output.script);return l?(s=f,!1):!0}),s||null})};Ct.SIGNATURE_SIZE=73;Ct.prototype._estimateSize=function(){var e=1+this.threshold*Ct.SIGNATURE_SIZE;return Tc.BASE_SIZE+D6(e).toBuffer().length+e};rx.exports=Ct});var ux=B((tq,ax)=>{"use strict";p();var Kr=ze(),U6=is(),Pc=ns(),F6=Cn(),qa=Le(),Ip=qr(),ix=nr(),ox=bi(),sx=ss(),q6=Ar(),H6=Ca();function Pt(e,t,r,n){Pc.apply(this,arguments);var i=this;t=t||e.publicKeys,r=r||e.threshold,n=n||e.signatures,this.publicKeys=t.map(o=>o.toString("hex")).sort().map(o=>new q6(o)),this.redeemScript=Ip.buildMultisigOut(this.publicKeys,r),qa.checkState(Ip.buildScriptHashOut(this.redeemScript).equals(this.output.script),"Provided public keys don't hash to the provided output"),this.publicKeyIndex={},Kr.each(this.publicKeys,function(o,s){i.publicKeyIndex[o.toString()]=s}),this.threshold=r,this.signatures=n?this._deserializeSignatures(n):new Array(this.publicKeys.length)}U6(Pt,Pc);Pt.prototype.toObject=function(){var e=Pc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=Kr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Pt.prototype._deserializeSignatures=function(e){return Kr.map(e,function(t){if(t)return new sx(t)})};Pt.prototype._serializeSignatures=function(){return Kr.map(this.signatures,function(e){if(e)return e.toObject()})};Pt.prototype.getSignatures=function(e,t,r,n){qa.checkState(this.output instanceof F6),n=n||ix.SIGHASH_ALL|ix.SIGHASH_FORKID;var i=this,o=[];return Kr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new sx({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:ox.sign(e,t,n,r,i.redeemScript,i.output.satoshisBN),sigtype:n}))}),o};Pt.prototype.addSignature=function(e,t){return qa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),qa.checkArgument(!Kr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),qa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Pt.prototype._updateScript=function(){return this.setScript(Ip.buildP2SHMultisigIn(this.publicKeys,this.threshold,this._createSignatures(),{cachedMultisig:this.redeemScript})),this};Pt.prototype._createSignatures=function(){return Kr.map(Kr.filter(this.signatures,function(e){return!Kr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Pt.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Pt.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Pt.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Pt.prototype.countSignatures=function(){return Kr.reduce(this.signatures,function(e,t){return e+!!t},0)};Pt.prototype.publicKeysWithoutSignature=function(){var e=this;return Kr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Pt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,ox.verify(e,t.signature,t.publicKey,t.inputIndex,this.redeemScript,this.output.satoshisBN)};Pt.SIGNATURE_SIZE=73;Pt.PUBKEY_SIZE=34;Pt.prototype._estimateSize=function(){var e=this.publicKeys.length*Pt.PUBKEY_SIZE,t=this.threshold*Pt.SIGNATURE_SIZE,r=3+e,n=r<=75?1:r<=255?2:3,i=t+1+n+r;return Pc.BASE_SIZE+H6(i).toBuffer().length+i};ax.exports=Pt});var Bc=B((nq,as)=>{p();as.exports=ns();as.exports.PublicKey=$1();as.exports.PublicKeyHash=ex();as.exports.MultiSig=nx();as.exports.MultiSigScriptHash=ux()});var bi=B((oq,dx)=>{"use strict";p();var j6=Nt(),fr=nr(),Ha=qr(),K6=Cn(),G6=Ma(),ja=rs(),fx=wr(),Nc=Jt(),cx=La(),Ap=Le(),Op=Mc(),_i=ze(),lx=d.Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),V6="ffffffffffffffff",W6=Op.SCRIPT_ENABLE_SIGHASH_FORKID,z6=function(e,t,r,n,i){var o=e.inputs[r];Ap.checkArgument(i instanceof fx,"For ForkId=0 signatures, satoshis or complete input must be provided");function s(U){var F=new ja;_i.each(U.inputs,function(G){F.writeReverse(G.prevTxId),F.writeUInt32LE(G.outputIndex)});var V=F.toBuffer(),z=Nc.sha256sha256(V);return z}function a(U){var F=new ja;_i.each(U.inputs,function(G){F.writeUInt32LE(G.sequenceNumber)});var V=F.toBuffer(),z=Nc.sha256sha256(V);return z}function f(U,F){var V=new ja;_i.isUndefined(F)?_i.each(U.outputs,function(ie){ie.toBufferWriter(V)}):U.outputs[F].toBufferWriter(V);var z=V.toBuffer(),G=Nc.sha256sha256(z);return G}var l=d.Buffer.alloc(32),m=d.Buffer.alloc(32),g=d.Buffer.alloc(32);t&fr.SIGHASH_ANYONECANPAY||(l=s(e)),!(t&fr.SIGHASH_ANYONECANPAY)&&(t&31)!==fr.SIGHASH_SINGLE&&(t&31)!==fr.SIGHASH_NONE&&(m=a(e)),(t&31)!==fr.SIGHASH_SINGLE&&(t&31)!==fr.SIGHASH_NONE?g=f(e):(t&31)===fr.SIGHASH_SINGLE&&r<e.outputs.length&&(g=f(e,r));var v=new ja;v.writeInt32LE(e.version),v.write(l),v.write(m),v.writeReverse(o.prevTxId),v.writeUInt32LE(o.outputIndex);var E=n.toBuffer();v.writeVarintNum(E.length),v.write(E),v.writeUInt64LEBN(i);var T=o.sequenceNumber;v.writeUInt32LE(T),v.write(g),v.writeUInt32LE(e.nLockTime),v.writeUInt32LE(t>>>0);var M=v.toBuffer();return M},hx=function(t,r,n,i,o,s){var a=Tp(),f=Bc();_i.isUndefined(s)&&(s=W6);var l=a.shallowCopy(t);if(i instanceof Ha||(i=new Ha(i)),s&Op.SCRIPT_ENABLE_REPLAY_PROTECTION){var m=r>>8,g=16711680|m^57005;r=g<<8|r&255}if(r&fr.SIGHASH_FORKID&&!(r&fr.SIGHASH_CHRONICLE)&&s&Op.SCRIPT_ENABLE_SIGHASH_FORKID)return z6(l,r,n,i,o);i=new Ha(i),i.removeCodeseparators();var v;for(v=0;v<l.inputs.length;v++)l.inputs[v]=new f(l.inputs[v]).setScript(Ha.empty());if(l.inputs[n]=new f(l.inputs[n]).setScript(i),(r&31)===fr.SIGHASH_NONE||(r&31)===fr.SIGHASH_SINGLE)for(v=0;v<l.inputs.length;v++)v!==n&&(l.inputs[v].sequenceNumber=0);if((r&31)===fr.SIGHASH_NONE)l.outputs=[];else if((r&31)===fr.SIGHASH_SINGLE){if(n>=l.outputs.length)return lx;for(l.outputs.length=n+1,v=0;v<n;v++)l.outputs[v]=new K6({satoshis:fx.fromBuffer(j6.Buffer.from(V6,"hex")),script:Ha.empty()})}r&fr.SIGHASH_ANYONECANPAY&&(l.inputs=[l.inputs[n]]);var E=new ja().write(l.toBuffer()).writeInt32LE(r).toBuffer();return E},Rp=function(t,r,n,i,o,s){var a=hx(t,r,n,i,o,s);if(a.compare(lx)===0)return a;var f=Nc.sha256sha256(a);return f=new G6(f).readReverse(),f};function Y6(e,t,r,n,i,o,s){var a=Rp(e,r,n,i,o,s),f=cx.sign(a,t,"little").set({nhashtype:r});return f}function $6(e,t,r,n,i,o,s){Ap.checkArgument(!_i.isUndefined(e)),Ap.checkArgument(!_i.isUndefined(t)&&!_i.isUndefined(t.nhashtype));var a=Rp(e,t.nhashtype,n,i,o,s);return cx.verify(a,t,r,"little")}dx.exports={sighashPreimage:hx,sighash:Rp,sign:Y6,verify:$6}});var Pp=B((aq,gx)=>{"use strict";p();var Un=ze(),kc=Le(),px=pr(),Z6=qr(),X6=ro();function Fn(e){if(!(this instanceof Fn))return new Fn(e);kc.checkArgument(Un.isObject(e),"Must provide an object from where to extract data");var t=e.address?new X6(e.address):void 0,r=e.txid?e.txid:e.txId;if(!r||!px.isHexaString(r)||r.length>64)throw new Error("Invalid TXID in object",e);var n=Un.isUndefined(e.vout)?e.outputIndex:e.vout;if(!Un.isNumber(n))throw new Error("Invalid outputIndex, received "+n);kc.checkArgument(!Un.isUndefined(e.scriptPubKey)||!Un.isUndefined(e.script),"Must provide the scriptPubKey for that output!");var i=new Z6(e.scriptPubKey||e.script);kc.checkArgument(!Un.isUndefined(e.amount)||!Un.isUndefined(e.satoshis),"Must provide an amount for the output");var o=Un.isUndefined(e.amount)?e.satoshis:Math.round(e.amount*1e8);kc.checkArgument(Un.isNumber(o),"Amount must be a number"),px.defineImmutable(this,{address:t,txId:r,outputIndex:n,script:i,satoshis:o})}Fn.prototype.inspect=function(){return"<UnspentOutput: "+this.txId+":"+this.outputIndex+", satoshis: "+this.satoshis+", address: "+this.address+">"};Fn.prototype.toString=function(){return this.txId+":"+this.outputIndex};Fn.fromObject=function(e){return new Fn(e)};Fn.prototype.toObject=Fn.prototype.toJSON=function(){return{address:this.address?this.address.toString():void 0,txid:this.txId,vout:this.outputIndex,scriptPubKey:this.script.toBuffer().toString("hex"),amount:Number.parseFloat((this.satoshis/1e8).toFixed(8))}};gx.exports=Fn});var Tp=B((fq,Ex)=>{"use strict";p();var ye=ze(),Kt=Le(),J6=Nt(),Dt=Jn(),mx=pr(),vx=Ma(),Q6=rs(),yx=Ca(),bx=Jt(),Lc=nr(),_x=bi(),eC=ro(),Sx=Pp(),Lt=Bc(),tC=Lt.PublicKeyHash,rC=Lt.PublicKey,nC=Lt.MultiSigScriptHash,iC=Lt.MultiSig,Gr=Cn(),ln=qr(),oC=no(),Cc=wr(),sC=Mc(),aC=sC.SCRIPT_ENABLE_SIGHASH_FORKID;function Y(e){if(!(this instanceof Y))return new Y(e);if(this.inputs=[],this.outputs=[],this._inputAmount=void 0,this._outputAmount=void 0,e){if(e instanceof Y)return Y.shallowCopy(e);if(mx.isHexa(e))this.fromString(e);else if(d.Buffer.isBuffer(e))this.fromBuffer(e);else if(ye.isObject(e))this.fromObject(e);else throw new Dt.InvalidArgument("Must provide an object or string to deserialize a transaction")}else this._newTransaction()}var uC=1,fC=0,cC=1e6;Y.DUST_AMOUNT=546;Y.FEE_SECURITY_MARGIN=150;Y.MAX_MONEY=21e6*1e8;Y.NLOCKTIME_BLOCKHEIGHT_LIMIT=5e8;Y.NLOCKTIME_MAX_VALUE=4294967295;Y.FEE_PER_KB=500;Y.CHANGE_OUTPUT_MAX_SIZE=62;Y.shallowCopy=function(e){var t=new Y(e.toBuffer());return t};var wx={configurable:!1,enumerable:!0,get:function(){return this._hash=new vx(this._getHash()).readReverse().toString("hex"),this._hash}};Object.defineProperty(Y.prototype,"hash",wx);Object.defineProperty(Y.prototype,"id",wx);var Bp={configurable:!1,enumerable:!0,get:function(){return this._getInputAmount()}};Object.defineProperty(Y.prototype,"inputAmount",Bp);Bp.get=function(){return this._getOutputAmount()};Object.defineProperty(Y.prototype,"outputAmount",Bp);Y.prototype._getHash=function(){return bx.sha256sha256(this.toBuffer())};Y.prototype.serialize=function(e){return e===!0||e&&e.disableAll?this.uncheckedSerialize():this.checkedSerialize(e)};Y.prototype.uncheckedSerialize=Y.prototype.toString=function(){return this.toBuffer().toString("hex")};Y.prototype.checkedSerialize=function(e){var t=this.getSerializationError(e);if(t)throw t.message+=" - For more information please see: https://bsv.io/api/lib/transaction#serialization-checks",t;return this.uncheckedSerialize()};Y.prototype.invalidSatoshis=function(){for(var e=!1,t=0;t<this.outputs.length;t++)this.outputs[t].invalidSatoshis()&&(e=!0);return e};Y.prototype.getSerializationError=function(e){if(e=e||{},this.invalidSatoshis())return new Dt.Transaction.InvalidSatoshis;var t=this._getUnspentValue(),r;return t<0?e.disableMoreOutputThanInput||(r=new Dt.Transaction.InvalidOutputAmountSum):r=this._hasFeeError(e,t),r||this._hasDustOutputs(e)||this._isMissingSignatures(e)};Y.prototype._hasFeeError=function(e,t){if(!ye.isUndefined(this._fee)&&this._fee!==t)return new Dt.Transaction.FeeError.Different("Unspent value is "+t+" but specified fee is "+this._fee);if(!e.disableLargeFees){var r=Math.floor(Y.FEE_SECURITY_MARGIN*this._estimateFee());if(t>r)return this._missingChange()?new Dt.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided"):new Dt.Transaction.FeeError.TooLarge("expected less than "+r+" but got "+t)}};Y.prototype._missingChange=function(){return!this._changeScript};Y.prototype._hasDustOutputs=function(e){if(!e.disableDustOutputs){var t,r;for(t in this.outputs)if(r=this.outputs[t],r.satoshis<Y.DUST_AMOUNT&&!r.script.isDataOut()&&!r.script.isSafeDataOut())return new Dt.Transaction.DustOutputs}};Y.prototype._isMissingSignatures=function(e){if(!e.disableIsFullySigned&&!this.isFullySigned())return new Dt.Transaction.MissingSignatures};Y.prototype.inspect=function(){return"<Transaction: "+this.uncheckedSerialize()+">"};Y.prototype.toBuffer=function(){var e=new Q6;return this.toBufferWriter(e).toBuffer()};Y.prototype.toBufferWriter=function(e){return e.writeInt32LE(this.version),e.writeVarintNum(this.inputs.length),ye.each(this.inputs,function(t){t.toBufferWriter(e)}),e.writeVarintNum(this.outputs.length),ye.each(this.outputs,function(t){t.toBufferWriter(e)}),e.writeUInt32LE(this.nLockTime),e};Y.prototype.fromBuffer=function(e){var t=new vx(e);return this.fromBufferReader(t)};Y.prototype.fromBufferReader=function(e){Kt.checkArgument(!e.finished(),"No transaction data received");var t,r,n;for(this.version=e.readInt32LE(),r=e.readVarintNum(),t=0;t<r;t++){var i=Lt.fromBufferReader(e);this.inputs.push(i)}for(n=e.readVarintNum(),t=0;t<n;t++)this.outputs.push(Gr.fromBufferReader(e));return this.nLockTime=e.readUInt32LE(),this};Y.prototype.toObject=Y.prototype.toJSON=function(){var t=[];this.inputs.forEach(function(i){t.push(i.toObject())});var r=[];this.outputs.forEach(function(i){r.push(i.toObject())});var n={hash:this.hash,version:this.version,inputs:t,outputs:r,nLockTime:this.nLockTime};return this._changeScript&&(n.changeScript=this._changeScript.toString()),ye.isUndefined(this._changeIndex)||(n.changeIndex=this._changeIndex),ye.isUndefined(this._fee)||(n.fee=this._fee),n};Y.prototype.fromObject=function(t){Kt.checkArgument(ye.isObject(t)||t instanceof Y);var r=this,n;return t instanceof Y?n=t.toObject():n=t,ye.each(n.inputs,function(i){if(!i.output||!i.output.script){r.uncheckedAddInput(new Lt(i));return}var o=new ln(i.output.script),s;if(o.isPublicKeyHashOut())s=new Lt.PublicKeyHash(i);else if(o.isScriptHashOut()&&i.publicKeys&&i.threshold)s=new Lt.MultiSigScriptHash(i,i.publicKeys,i.threshold,i.signatures);else if(o.isPublicKeyOut())s=new Lt.PublicKey(i);else throw new Dt.Transaction.Input.UnsupportedScript(i.output.script);r.addInput(s)}),ye.each(n.outputs,function(i){r.addOutput(new Gr(i))}),n.changeIndex&&(this._changeIndex=n.changeIndex),n.changeScript&&(this._changeScript=new ln(n.changeScript)),n.fee&&(this._fee=n.fee),this.nLockTime=n.nLockTime,this.version=n.version,this._checkConsistency(t),this};Y.prototype._checkConsistency=function(e){ye.isUndefined(this._changeIndex)||(Kt.checkState(this._changeScript,"Change script is expected."),Kt.checkState(this.outputs[this._changeIndex],"Change index points to undefined output."),Kt.checkState(this.outputs[this._changeIndex].script.toString()===this._changeScript.toString(),"Change output has an unexpected script.")),e&&e.hash&&Kt.checkState(e.hash===this.hash,"Hash in object does not match transaction hash.")};Y.prototype.lockUntilDate=function(e){if(Kt.checkArgument(e),ye.isNumber(e)&&e<Y.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Dt.Transaction.LockTimeTooEarly;ye.isDate(e)&&(e=e.getTime()/1e3);for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===Lt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=Lt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Y.prototype.lockUntilBlockHeight=function(e){if(Kt.checkArgument(ye.isNumber(e)),e>=Y.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Dt.Transaction.BlockHeightTooHigh;if(e<0)throw new Dt.Transaction.NLockTimeOutOfRange;for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===Lt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=Lt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Y.prototype.getLockTime=function(){return this.nLockTime?this.nLockTime<Y.NLOCKTIME_BLOCKHEIGHT_LIMIT?this.nLockTime:new Date(1e3*this.nLockTime):null};Y.prototype.fromString=function(e){this.fromBuffer(J6.Buffer.from(e,"hex"))};Y.prototype._newTransaction=function(){this.version=uC,this.nLockTime=fC};Y.prototype.from=function(e,t,r){if(ye.isArray(e)){var n=this;return ye.each(e,function(o){n.from(o,t,r)}),this}var i=ye.some(this.inputs,function(o){return o.prevTxId.toString("hex")===e.txId&&o.outputIndex===e.outputIndex});return i?this:(t&&r?this._fromMultisigUtxo(e,t,r):this._fromNonP2SH(e),this)};Y.prototype._fromNonP2SH=function(e){var t;e=new Sx(e),e.script.isPublicKeyHashOutPrefix()?t=tC:e.script.isPublicKeyOut()?t=rC:t=Lt,this.addInput(new t({output:new Gr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:ln.empty()}))};Y.prototype._fromMultisigUtxo=function(e,t,r){Kt.checkArgument(r<=t.length,"Number of required signatures must be greater than the number of public keys");var n;if(e=new Sx(e),e.script.isMultisigOut())n=iC;else if(e.script.isScriptHashOut())n=nC;else throw new Dt.Transaction.Input.UnsupportedScript(e.script.toString());this.addInput(new n({output:new Gr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:ln.empty()},t,r))};Y.prototype.addInput=function(e,t,r){if(Kt.checkArgumentType(e,Lt,"input"),!e.output&&(ye.isUndefined(t)||ye.isUndefined(r)))throw new Dt.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis");return!e.output&&t&&!ye.isUndefined(r)&&(t=t instanceof ln?t:new ln(t),Kt.checkArgumentType(r,"number","satoshis"),e.output=new Gr({script:t,satoshis:r})),this.uncheckedAddInput(e)};Y.prototype.uncheckedAddInput=function(e){return Kt.checkArgumentType(e,Lt,"input"),this.inputs.push(e),this._inputAmount=void 0,this._updateChangeOutput(),this};Y.prototype.hasAllUtxoInfo=function(){return ye.every(this.inputs.map(function(e){return!!e.output}))};Y.prototype.fee=function(e){return Kt.checkArgument(ye.isNumber(e),"amount must be a number"),this._fee=e,this._updateChangeOutput(),this};Y.prototype.feePerKb=function(e){return Kt.checkArgument(ye.isNumber(e),"amount must be a number"),this._feePerKb=e,this._updateChangeOutput(),this};Y.prototype.change=function(e){return Kt.checkArgument(e,"address is required"),this._changeScript=ln.fromAddress(e),this._updateChangeOutput(),this};Y.prototype.getChangeOutput=function(){return ye.isUndefined(this._changeIndex)?null:this.outputs[this._changeIndex]};Y.prototype.to=function(e,t){if(ye.isArray(e)){var r=this;return ye.each(e,function(n){r.to(n.address,n.satoshis)}),this}return Kt.checkArgument(mx.isNaturalNumber(t),"Amount is expected to be a positive integer"),this.addOutput(new Gr({script:ln(new eC(e)),satoshis:t})),this};Y.prototype.addData=function(e){return this.addOutput(new Gr({script:ln.buildDataOut(e),satoshis:0})),this};Y.prototype.addSafeData=function(e){return this.addOutput(new Gr({script:ln.buildSafeDataOut(e),satoshis:0})),this};Y.prototype.addOutput=function(e){return Kt.checkArgumentType(e,Gr,"output"),this._addOutput(e),this._updateChangeOutput(),this};Y.prototype.clearOutputs=function(){return this.outputs=[],this._clearSignatures(),this._outputAmount=void 0,this._changeIndex=void 0,this._updateChangeOutput(),this};Y.prototype._addOutput=function(e){this.outputs.push(e),this._outputAmount=void 0};Y.prototype._getOutputAmount=function(){if(ye.isUndefined(this._outputAmount)){var e=this;this._outputAmount=0,ye.each(this.outputs,function(t){e._outputAmount+=t.satoshis})}return this._outputAmount};Y.prototype._getInputAmount=function(){if(ye.isUndefined(this._inputAmount)){var e=this;this._inputAmount=0,ye.each(this.inputs,function(t){if(ye.isUndefined(t.output))throw new Dt.Transaction.Input.MissingPreviousOutput;e._inputAmount+=t.output.satoshis})}return this._inputAmount};Y.prototype._updateChangeOutput=function(){if(this._changeScript){this._clearSignatures(),ye.isUndefined(this._changeIndex)||this._removeOutput(this._changeIndex),this._changeIndex=this.outputs.length,this._addOutput(new Gr({script:this._changeScript,satoshis:0}));var e=this._getUnspentValue(),t=this.getFee(),r=e-t;this._removeOutput(this._changeIndex),this._changeIndex=void 0,r>=Y.DUST_AMOUNT&&(this._changeIndex=this.outputs.length,this._addOutput(new Gr({script:this._changeScript,satoshis:r})))}};Y.prototype.getFee=function(){return this.isCoinbase()?0:ye.isUndefined(this._fee)?this._changeScript?this._estimateFee():this._getUnspentValue():this._fee};Y.prototype._estimateFee=function(){var e=this._estimateSize();return Math.ceil(e/1e3*(this._feePerKb||Y.FEE_PER_KB))};Y.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Y.prototype._clearSignatures=function(){ye.each(this.inputs,function(e){e.clearSignatures!==Lt.prototype.clearSignatures&&e.clearSignatures()})};Y.prototype._estimateSize=function(){var e=8;return e+=yx(this.inputs.length).toBuffer().length,e+=yx(this.outputs.length).toBuffer().length,ye.each(this.inputs,function(t){e+=t._estimateSize()}),ye.each(this.outputs,function(t){e+=t.getSize()}),e};Y.prototype._removeOutput=function(e){var t=this.outputs[e];this.outputs=ye.without(this.outputs,t),this._outputAmount=void 0};Y.prototype.removeOutput=function(e){this._removeOutput(e),this._updateChangeOutput()};Y.prototype.sort=function(){return this.sortInputs(function(e){var t=Array.prototype.concat.apply([],e);return t.sort(function(r,n){return r.prevTxId.compare(n.prevTxId)||r.outputIndex-n.outputIndex}),t}),this.sortOutputs(function(e){var t=Array.prototype.concat.apply([],e);return t.sort(function(r,n){return r.satoshis-n.satoshis||r.script.toBuffer().compare(n.script.toBuffer())}),t}),this};Y.prototype.shuffleOutputs=function(){return this.sortOutputs(ye.shuffle)};Y.prototype.sortOutputs=function(e){var t=e(this.outputs);return this._newOutputOrder(t)};Y.prototype.sortInputs=function(e){return this.inputs=e(this.inputs),this._clearSignatures(),this};Y.prototype._newOutputOrder=function(e){var t=this.outputs.length!==e.length||ye.difference(this.outputs,e).length!==0;if(t)throw new Dt.Transaction.InvalidSorting;if(!ye.isUndefined(this._changeIndex)){var r=this.outputs[this._changeIndex];this._changeIndex=e.indexOf(r)}return this.outputs=e,this};Y.prototype.removeInput=function(e,t){var r;if(!t&&ye.isNumber(e)?r=e:r=ye.findIndex(this.inputs,function(i){return i.prevTxId.toString("hex")===e&&i.outputIndex===t}),r<0||r>=this.inputs.length)throw new Dt.Transaction.InvalidIndex(r,this.inputs.length);var n=this.inputs[r];this.inputs=ye.without(this.inputs,n),this._inputAmount=void 0,this._updateChangeOutput()};Y.prototype.sign=function(e,t){Kt.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var r=this;return ye.isArray(e)?(ye.each(e,function(n){r.sign(n,t)}),this):(ye.each(this.getSignatures(e,t),function(n){r.applySignature(n)}),this)};Y.prototype.getSignatures=function(e,t){e=new oC(e),t=t||Lc.SIGHASH_ALL|Lc.SIGHASH_FORKID;var r=this,n=[],i=bx.sha256ripemd160(e.publicKey.toBuffer());return ye.each(this.inputs,function(s,a){ye.each(s.getSignatures(r,e,a,t,i),function(f){n.push(f)})}),n};Y.prototype.applySignature=function(e){return this.inputs[e.inputIndex].addSignature(this,e),this};Y.prototype.isFullySigned=function(){return ye.each(this.inputs,function(e){if(e.isFullySigned===Lt.prototype.isFullySigned)throw new Dt.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction")}),ye.every(ye.map(this.inputs,function(e){return e.isFullySigned()}))};Y.prototype.isValidSignature=function(e){var t=this;if(this.inputs[e.inputIndex].isValidSignature===Lt.prototype.isValidSignature)throw new Dt.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction");return this.inputs[e.inputIndex].isValidSignature(t,e)};Y.prototype.verifySignature=function(e,t,r,n,i,o){return _x.verify(this,e,t,r,n,i,o)};Y.prototype.verify=function(){if(this.inputs.length===0)return"transaction txins empty";if(this.outputs.length===0)return"transaction txouts empty";for(var e=new Cc(0),t=0;t<this.outputs.length;t++){var r=this.outputs[t];if(r.invalidSatoshis())return"transaction txout "+t+" satoshis is invalid";if(r._satoshisBN.gt(new Cc(Y.MAX_MONEY,10)))return"transaction txout "+t+" greater than MAX_MONEY";if(e=e.add(r._satoshisBN),e.gt(new Cc(Y.MAX_MONEY)))return"transaction txout "+t+" total output greater than MAX_MONEY"}if(this.toBuffer().length>cC)return"transaction over the maximum block size";var n={};for(t=0;t<this.inputs.length;t++){var i=this.inputs[t],o=i.prevTxId+":"+i.outputIndex;if(!ye.isUndefined(n[o]))return"transaction input "+t+" duplicate input";n[o]=!0}var s=this.isCoinbase();if(s){var a=this.inputs[0]._scriptBuffer;if(a.length<2||a.length>100)return"coinbase transaction script size invalid"}else for(t=0;t<this.inputs.length;t++)if(this.inputs[t].isNull())return"transaction input "+t+" has null input";return!0};Y.prototype.isCoinbase=function(){return this.inputs.length===1&&this.inputs[0].isNull()};Y.prototype.sighash=function(e,t,r,n,i){t=t||Lc.SIGHASH_ALL|Lc.SIGHASH_FORKID;var o=this.inputs[e];if(!o)throw new Error("Input index "+e+" does not exist");return!r&&o.output&&(r=o.output.script),!n&&o.output&&(n=new Cc(o.output.satoshis)),i=i||aC,_x.sighash(this,t,e,r,n,i)};Ex.exports=Y});var Np=B((lq,io)=>{p();io.exports=Tp();io.exports.Input=Bc();io.exports.Output=Cn();io.exports.UnspentOutput=Pp();io.exports.Signature=ss();io.exports.Sighash=bi()});var Mc=B((dq,Ox)=>{"use strict";p();var Dc=ze(),Uc=gp(),N=hp(),he=wr(),Ka=Jt(),qn=nr(),Mp=Ar();function xx(e){return e.map(function(t){return d.Buffer.isBuffer(t)?d.Buffer.from(t):t})}var P=function e(t){if(!(this instanceof e))return new e(t);t?(this.initialize(),this.set(t)):this.initialize()};P.prototype._verifyCore=function(e,t,r,n,i,o){var s=Np();if(Dc.isUndefined(r)&&(r=new s),Dc.isUndefined(n)&&(n=0),Dc.isUndefined(i)&&(i=P.currentConsensusFlags(),o||(i&=~P.SCRIPT_ENABLE_SIGHASH_FORKID)),i&P.SCRIPT_ENABLE_SIGHASH_FORKID&&(i|=P.SCRIPT_VERIFY_STRICTENC,!o))throw new Error("internal error - need satoshisBN to verify FORKID transactions");this.set({script:e,tx:r,nin:n,flags:i,satoshisBN:o});var a;if((i&P.SCRIPT_VERIFY_SIGPUSHONLY)!==0&&!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1;if(!this.evaluate())return!1;var f=(i&P.SCRIPT_VERIFY_P2SH)!==0&&(i&P.SCRIPT_UTXO_AFTER_GENESIS)===0;f&&(a=this.stack.slice());var l=this.stack;if(this.initialize(),this.set({script:t,stack:l,tx:r,nin:n,flags:i,satoshisBN:o}),!this.evaluate())return!1;if(this.stack.length===0)return this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_RESULT",!1;var m=this.stack[this.stack.length-1];if(!P.castToBool(m))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK",!1;if(f&&t.isScriptHashOut()){if(!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1;if(a.length===0)throw new Error("internal error - stack copy empty");var g=a[a.length-1],v=Uc.fromBuffer(g);if(a.pop(),this.initialize(),this.set({script:v,stack:a,tx:r,nin:n,flags:i,satoshisBN:o}),!this.evaluate())return!1;if(a.length===0)return this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_P2SH_STACK",!1;if(!P.castToBool(a[a.length-1]))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK",!1}if((i&P.SCRIPT_VERIFY_CLEANSTACK)!==0){if((i&P.SCRIPT_VERIFY_P2SH)===0&&(i&P.SCRIPT_UTXO_AFTER_GENESIS)===0)throw new Error("internal error - CLEANSTACK without P2SH");if(this.stack.length!==1)return this.errstr="SCRIPT_ERR_CLEANSTACK",!1}return!0};Ox.exports=P;P.prototype.initialize=function(e){this.stack=[],this.altstack=[],this.pc=0,this.pbegincodehash=0,this.nOpCount=0,this.returned=!1,this.nonTopLevelReturnAfterGenesis=!1,this.vfExec=[],this.vfElse=[],this.errstr="",this.flags=0};P.prototype.set=function(e){this.script=e.script||this.script,this.tx=e.tx||this.tx,this.nin=typeof e.nin<"u"?e.nin:this.nin,this.satoshisBN=e.satoshisBN||this.satoshisBN,this.stack=e.stack||this.stack,this.altstack=e.altstack||this.altstack,this.pc=typeof e.pc<"u"?e.pc:this.pc,this.pbegincodehash=typeof e.pbegincodehash<"u"?e.pbegincodehash:this.pbegincodehash,this.nOpCount=typeof e.nOpCount<"u"?e.nOpCount:this.nOpCount,this.returned=typeof e.returned<"u"?e.returned:this.returned,this.nonTopLevelReturnAfterGenesis=typeof e.nonTopLevelReturnAfterGenesis<"u"?e.nonTopLevelReturnAfterGenesis:this.nonTopLevelReturnAfterGenesis,this.vfExec=e.vfExec||this.vfExec,this.vfElse=e.vfElse||this.vfElse,this.errstr=e.errstr||this.errstr,this.flags=typeof e.flags<"u"?e.flags:this.flags};P.true=d.Buffer.from([1]);P.false=d.Buffer.from([]);P.MAX_SCRIPT_ELEMENT_SIZE=520;P.MAXIMUM_ELEMENT_SIZE=4;P.MAX_OPS_PER_SCRIPT=500;P.MAX_SCRIPT_SIZE=1e4;P.UNLIMITED=Number.MAX_SAFE_INTEGER;P.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS=75e4;P.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE=32e6;P.MAX_PUBKEYS_PER_MULTISIG_AFTER_GENESIS=4294967295;P.MAX_STACK_SIZE=1e3;P.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS=P.UNLIMITED;P.STACK_MEMORY_USAGE_POLICY=100*1024*1024;P.STACK_ELEMENT_OVERHEAD=32;P.LOCKTIME_THRESHOLD=5e8;P.LOCKTIME_THRESHOLD_BN=new he(P.LOCKTIME_THRESHOLD);P.useGenesisLimits=function(e){return e=e||2147483647,P.MAX_SCRIPT_ELEMENT_SIZE=e,P.MAX_OPS_PER_SCRIPT=e,P.MAX_SCRIPT_SIZE=e,P};P.getLimits=function(){return{maxScriptElementSize:P.MAX_SCRIPT_ELEMENT_SIZE,maximumElementSize:P.MAXIMUM_ELEMENT_SIZE,maxOpsPerScript:P.MAX_OPS_PER_SCRIPT,maxScriptSize:P.MAX_SCRIPT_SIZE}};P.setLimits=function(e){return e=e||{},e.maxScriptElementSize!=null&&(P.MAX_SCRIPT_ELEMENT_SIZE=e.maxScriptElementSize),e.maximumElementSize!=null&&(P.MAXIMUM_ELEMENT_SIZE=e.maximumElementSize),e.maxOpsPerScript!=null&&(P.MAX_OPS_PER_SCRIPT=e.maxOpsPerScript),e.maxScriptSize!=null&&(P.MAX_SCRIPT_SIZE=e.maxScriptSize),P};P.SCRIPT_VERIFY_NONE=0;P.SCRIPT_VERIFY_P2SH=1;P.SCRIPT_VERIFY_STRICTENC=2;P.SCRIPT_VERIFY_DERSIG=4;P.SCRIPT_VERIFY_LOW_S=8;P.SCRIPT_VERIFY_NULLDUMMY=16;P.SCRIPT_VERIFY_SIGPUSHONLY=32;P.SCRIPT_VERIFY_MINIMALDATA=64;P.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=128;P.SCRIPT_VERIFY_CLEANSTACK=256;P.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=512;P.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1024;P.SCRIPT_VERIFY_MINIMALIF=8192;P.SCRIPT_VERIFY_NULLFAIL=16384;P.SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE=32768;P.SCRIPT_ENABLE_SIGHASH_FORKID=65536;P.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;P.SCRIPT_ENABLE_MONOLITH_OPCODES=2048;P.SCRIPT_ENABLE_MAGNETIC_OPCODES=4096;P.SCRIPT_GENESIS=1<<18;P.SCRIPT_UTXO_AFTER_GENESIS=1<<19;P.SCRIPT_ENABLE_CHRONICLE=1<<20;P.SCRIPT_CHRONICLE=P.SCRIPT_ENABLE_CHRONICLE;P.SCRIPT_UTXO_AFTER_CHRONICLE=1<<21;P.CHRONICLE_ACTIVATION_HEIGHT=943816;P.ERA_SENSITIVE_ERRORS={SCRIPT_ERR_PUSH_SIZE:{cap:"stack element size (capped at 520 bytes pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPT_SIZE:{cap:"total script size (capped at 10,000 bytes pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_OP_COUNT:{cap:"opcode count (capped at 201 pre-Genesis, unbounded after)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPTNUM_OVERFLOW:{cap:"script number width (4 bytes pre-Genesis, 750,000 after Genesis, 32,000,000 after Chronicle)",lifts:P.SCRIPT_UTXO_AFTER_GENESIS|P.SCRIPT_UTXO_AFTER_CHRONICLE}};P.ERA_FLAGS=P.SCRIPT_GENESIS|P.SCRIPT_UTXO_AFTER_GENESIS|P.SCRIPT_ENABLE_CHRONICLE|P.SCRIPT_UTXO_AFTER_CHRONICLE;P.eraDiagnostics=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_ERA_HINT==="1");var kp=!1;P.prototype._eraDiagnose=function(e){if(e!==void 0){var t=P.ERA_SENSITIVE_ERRORS[this.errstr];if(t&&(e&t.lifts)===0){var r=t.cap;this.eraHint=this.errstr+" was produced under PRE-GENESIS limits: "+r+`.
|
|
70
70
|
The flags passed to verify() (0x`+(e>>>0).toString(16)+`) carry no era bit, so those caps applied regardless of which feature opcodes were enabled.
|
|
71
71
|
To validate against BSV as it is today, omit the flags argument or pass Interpreter.mainnetFlags(). If you are deliberately testing pre-Genesis consensus this failure is correct \u2014 set Interpreter.eraDiagnostics = false (or BSV_NO_ERA_HINT=1) to silence this.`,P.eraDiagnostics&&!kp&&(kp=!0,console.warn(`
|
|
72
72
|
[@smartledger/bsv] `+this.eraHint+`
|
package/bsv-smartcontract.min.js
CHANGED
|
@@ -20,5 +20,5 @@ var bsvSmartContract=(()=>{var Xn=Object.create;var yr=Object.defineProperty;var
|
|
|
20
20
|
[${a+1}/${n.length}] Step (${c})`);try{if(typeof i.step=="function")i.step();else{console.log("\u26A0\uFE0F Step-by-step execution not supported in this BSV version"),console.log("\u{1F4A1} Consider using runFullEvaluation instead");break}console.log(`\u{1F9E9} Executed: ${c}`),Xt(i.stack,i.altstack)}catch(d){console.log(`\u26A0\uFE0F Error executing ${c}: ${d.message}`);break}}o&&o.close(),console.log(`
|
|
21
21
|
===========================================`),console.log("\u2705 Final Stack State:"),Xt(i.stack||[],i.altstack||[]),console.log("===========================================")}function Ji(e,t,r){console.log("==========================================="),console.log("\u{1F50D} SCRIPT INTERPRETER DEBUGGER (FULL RUN)"),console.log(`===========================================
|
|
22
22
|
`);let i=new ct,n=new Fa(1e5),o=i.verify(e,t,r,0,ct.SCRIPT_ENABLE_SIGHASH_FORKID,n);console.log("\u{1F510} Locking Script:",t.toASM()),console.log("\u{1F513} Unlocking Script:",e.toASM()),console.log("-------------------------------------------"),console.log("\u2705 Result:",o?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",i.stack.map(a=>a.toString("hex"))),console.log("AltStack:",i.altstack.map(a=>a.toString("hex"))),console.log("===========================================")}async function en(){if(typeof m.default>"u"||!m.default.argv){console.log("\u2699\uFE0F CLI mode not available in browser environment");return}let e=m.default.argv.slice(2),t=P=>{let x=e.indexOf(P);return x!==-1&&e[x+1]?e[x+1]:null},r=t("--unlocking"),i=t("--locking"),n=t("--combined"),o=e.includes("--step"),a=e.includes("--truth"),s,c,d;if(n)d=at(n);else{s=at(r),c=at(i);let P=u.Buffer.concat([s.toBuffer(),c.toBuffer()]);d=he.fromBuffer(P)}let g=new Ca,y=new La({prevTxId:"0".repeat(64),outputIndex:0,script:he.empty(),satoshis:1e5,output:new Qi({satoshis:1e5,script:he.empty()})});g.addInput(y),g.addOutput(new Qi({satoshis:1e5,script:he.empty()})),o?await Zi(d,g,!0):a?Ji(s||he.empty(),c||he.empty(),g):console.log("\u2699\uFE0F No mode specified. Use --step or --truth")}jt.exports={parseScript:at,printStack:Xt,stepThroughScript:Zi,runFullEvaluation:Ji,main:en};typeof L<"u"&&L.main===jt&&en()});var pe=O((uu,hn)=>{"use strict";f();var nn=b(),on=ge(),Wt=V(),Qt=D(),Ra=He(),an=$e(),sn=_e(),ut=M(),Ba=fe(),rn=Ee(),Zt=rn.SIGHASH_ALL|rn.SIGHASH_FORKID;function cn(){return on.mainnetFlags()}function Na(e,t,r){r=r||{};var i=new on,n=i.verify(e,t,r.tx||new Qt,r.inputIndex||0,r.flags||cn(),new ut(r.satoshis||0));return{ok:n,err:i.errstr||""}}function un(e,t,r,i,n){return sn.sighashPreimage(e,n||Zt,t,r,new ut(i))}function Ua(e,t,r,i,n){return Ba.sha256sha256(un(e,t,r,i,n))}function qa(e,t,r,i,n,o){o=o||Zt;var a=sn.sign(e,t,o,r,i,new ut(n));return u.Buffer.concat([a.toDER(),u.Buffer.from([o])])}function Da(e,t,r){r=r||{};var i=new Qt().addOutput(new an({script:e,satoshis:t})),n=new Qt;return n.addInput(new Ra({prevTxId:i.hash,outputIndex:0,script:nn.empty()}),e,t),r.outputs&&r.outputs.forEach(function(o){n.addOutput(o)}),{funding:i,spend:n}}function Ma(e,t){var r=e.toAddress?e.toAddress():e;return new an({script:nn.buildPublicKeyHashOut(r),satoshis:t})}function Ga(e){return e===0?Wt.OP_0:e===-1?Wt.OP_1NEGATE:e>=1&&e<=16?Wt["OP_"+e]:new ut(e).toScriptNumBuffer()}hn.exports={SIGHASH:Zt,flags:cn,verify:Na,rawPreimage:un,sighashDigest:Ua,signInput:qa,fundAndSpend:Da,p2pkhOutput:Ma,scriptNum:Ga}});var dn=O((pu,ln)=>{"use strict";f();var Va=fe(),Ka=pe(),qe=b(),Ue=V(),pn=Ka.signInput;function za(e){var t=Va.sha256(e),r=new qe().add(Ue.OP_SHA256).add(t).add(Ue.OP_EQUAL);return{lock:r,meta:{name:"hash-lock",digest:t.toString("hex")},unlock:function(i,n,o){return new qe().add(o||e)}}}function $a(e){var t=e.toPublicKey(),r=qe.buildPublicKeyHashOut(t.toAddress());return{lock:r,meta:{name:"p2pkh",address:t.toAddress().toString()},unlock:function(i,n){return new qe().add(pn(i,e,0,r,n)).add(t.toBuffer())}}}function Ya(e,t){var r=t.map(function(n){return n.toPublicKey()}),i=new qe().add(Ue["OP_"+e]);return r.forEach(function(n){i.add(n.toBuffer())}),i.add(Ue["OP_"+r.length]).add(Ue.OP_CHECKMULTISIG),{lock:i,meta:{name:e+"-of-"+r.length+"-multisig"},unlock:function(n,o,a){a=a||t.slice(0,e);var s=new qe().add(Ue.OP_0);return a.forEach(function(c){s.add(pn(n,c,0,i,o))}),s}}}ln.exports={hashLock:za,p2pkh:$a,multisig:Ya}});var je=O((du,xn)=>{"use strict";f();var fn=b(),_=V(),ee=Ee(),ht=M(),gn=fe(),er=pe(),tr=er.SIGHASH,pt=er.scriptNum,De=u.Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),rr=new ht("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",16),Xa=u.Buffer.concat([u.Buffer.from([2]),De]),mn=u.Buffer.from(De).reverse(),yn=u.Buffer.concat([u.Buffer.from(rr.toBuffer()).reverse(),u.Buffer.from([0])]),ja=u.Buffer.concat([u.Buffer.from([48,68,2,32]),De,u.Buffer.from([2,32])]);function Jt(e,t){var r;for(r=0;r<t-1;r++)e.add(_.OP_1).add(_.OP_SPLIT);for(r=0;r<t-1;r++)e.add(_.OP_SWAP).add(_.OP_CAT);return e}var Wa=ee.SIGHASH_ALL|ee.SIGHASH_FORKID,Qa=ee.SIGHASH_SINGLE|ee.SIGHASH_FORKID,Za=ee.SIGHASH_SINGLE|ee.SIGHASH_ANYONECANPAY|ee.SIGHASH_FORKID,Ja=ee.SIGHASH_ALL|ee.SIGHASH_ANYONECANPAY|ee.SIGHASH_FORKID;function ir(e,t){var r=t&&t.sighashType||tr;return e.add(_.OP_HASH256),Jt(e,32),e.add(mn).add(_.OP_ADD),e.add(yn).add(_.OP_MOD),e.add(pt(32)).add(_.OP_NUM2BIN),Jt(e,32),e.add(De).add(_.OP_DUP),e.add(_.OP_2).add(_.OP_SWAP).add(_.OP_CAT),e.add(_.OP_TOALTSTACK),e.add(u.Buffer.from([48,68,2,32])).add(_.OP_SWAP).add(_.OP_CAT),e.add(u.Buffer.from([2,32])).add(_.OP_CAT),e.add(_.OP_SWAP).add(_.OP_CAT),e.add(u.Buffer.from([r])).add(_.OP_CAT),e.add(_.OP_FROMALTSTACK).add(_.OP_CHECKSIG),e}function es(){return ir(new fn)}function Sn(e){return e.add(pt(40)).add(_.OP_RIGHT).add(pt(32)).add(_.OP_LEFT),e}function ts(e){return vn(e,tr)}function vn(e,t){var r=u.Buffer.from([t&255,0,0,0]);return e.add(_.OP_DUP).add(pt(4)).add(_.OP_RIGHT).add(r).add(_.OP_EQUALVERIFY),e}function rs(e){var t=u.Buffer.concat(e.map(function(r){return r.toBufferWriter().toBuffer()}));return gn.sha256sha256(t)}function is(e){var t=new fn().add(_.OP_DUP);return ir(t),t.add(_.OP_VERIFY),Sn(t),t.add(u.Buffer.from(e)).add(_.OP_EQUAL),t}var ns=new ht("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex");function On(e){var t=gn.sha256sha256(e);if(t[0]<1||t[0]>127)return null;var r=new ht(t).add(new ht(De)).mod(rr);if(r.gt(ns))return null;var i=r.toBuffer("be",32);return i[0]>=1?i:null}function os(e,t,r,i,n){typeof n=="number"&&(n={maxTries:n}),n=n||{};var o=n.maxTries||5e3,a=n.start||0,s=n.field||"nLockTime",c=n.sighashType||tr;if(s!=="nLockTime"&&s!=="sequence")throw new Error("grind field must be 'nLockTime' or 'sequence'");for(var d=e.inputs[t],g=0;g<o;g++){var y=a+g;s==="nLockTime"?e.nLockTime=y:d.sequenceNumber=4294967294-y;var P=er.rawPreimage(e,t,r,i,c);if(On(P))return{preimage:P,tries:g+1,field:s,nonce:y}}throw new Error("OP_PUSH_TX grind failed after "+o+" tries")}xn.exports={Gx:De,N:rr,PUBKEY:Xa,gxLe:mn,N_LE:yn,DER_PREFIX:ja,reverseBytes:Jt,pushTxCore:ir,authenticator:es,extractHashOutputs:Sn,assertSighashAll:ts,assertSighashType:vn,SIGHASH_ALL_FORKID:Wa,SIGHASH_SINGLE_FORKID:Qa,SIGHASH_SINGLE_ANYONECANPAY_FORKID:Za,SIGHASH_ALL_ANYONECANPAY_FORKID:Ja,hashOutputs:rs,valueCovenant:is,sFromPreimage:On,grind:os}});var or=O((gu,Pn)=>{"use strict";f();var nr=je(),as=pe(),ss=b(),A=V(),Me=as.scriptNum;function cs(e){var t=new ss;return t.add(A.OP_DUP),nr.pushTxCore(t),t.add(A.OP_VERIFY),nr.assertSighashAll(t),t.add(A.OP_DUP),t.add(Me(104)).add(A.OP_SPLIT).add(A.OP_NIP),t.add(A.OP_SIZE).add(Me(52)).add(A.OP_SUB).add(A.OP_SPLIT).add(A.OP_DROP),t.add(A.OP_OVER),t.add(Me(52)).add(A.OP_RIGHT).add(Me(8)).add(A.OP_LEFT),t.add(A.OP_BIN2NUM).add(Me(e)).add(A.OP_SUB),t.add(Me(8)).add(A.OP_NUM2BIN),t.add(A.OP_SWAP).add(A.OP_CAT),t.add(A.OP_HASH256),t.add(A.OP_SWAP),nr.extractHashOutputs(t),t.add(A.OP_EQUAL),t}Pn.exports={pelsCovenant:cs}});var En=O((yu,_n)=>{f();_n.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.PublicKey});var cr=O((vu,Tn)=>{"use strict";f();var us=ze(),hs=En(),ps=b(),wn=fe(),sr=pe(),E=V(),Ge=sr.scriptNum;function lt(e){return e instanceof us?e.toPublicKey().toBuffer():e instanceof hs?e.toBuffer():e}function ls(){return{name:"single-key",commit:function(e){return wn.sha256ripemd160(lt(e))},emit:function(e){return e.add(E.OP_OVER).add(E.OP_HASH160).add(E.OP_EQUALVERIFY),e.add(E.OP_CHECKSIGVERIFY),e},unlockArgs:function(e,t,r,i,n){var o=sr.signInput(e,n,t,r,i);return[o,n.toPublicKey().toBuffer()]}}}function ar(e,t){var r=t.length;if(e<1||e>r||r<1||r>16)throw new Error("multisig requires 1 <= m <= n <= 16");var i=new ps().add(E["OP_"+e]);return t.forEach(function(n){i.add(u.Buffer.from(n))}),i.add(E["OP_"+r]).add(E.OP_CHECKMULTISIG),i.toBuffer()}function ds(e,t){if(typeof t!="number"||!Number.isInteger(t))throw new Error("multisig(m, nKeys): nKeys is the NUMBER of keys, not the keys themselves"+(Array.isArray(t)?" \u2014 pass "+t.length+" instead of the array":""));if(typeof e!="number"||!Number.isInteger(e))throw new Error("multisig(m, nKeys): m must be an integer");if(e<1||e>t||t<1||t>16)throw new Error("multisig requires 1 <= m <= n <= 16");return{name:e+"-of-"+t+"-multisig",m:e,n:t,commit:function(r){if(r.length!==t)throw new Error("expected "+t+" public keys");return wn.sha256ripemd160(ar(e,r.map(lt)))},emit:function(r){r.add(E.OP_OVER).add(E.OP_HASH160).add(E.OP_EQUALVERIFY),r.add(Ge(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_SIZE).add(Ge(2)).add(E.OP_SUB).add(E.OP_SPLIT).add(E.OP_DROP);for(var i=0;i<this.n;i++)r.add(Ge(34)).add(E.OP_SPLIT),r.add(E.OP_SWAP).add(Ge(1)).add(E.OP_SPLIT).add(E.OP_NIP),r.add(E.OP_TOALTSTACK);for(r.add(E.OP_DROP),r.add(Ge(this.m)),i=0;i<this.n;i++)r.add(E.OP_FROMALTSTACK);return r.add(Ge(this.n)),r.add(E.OP_CHECKMULTISIGVERIFY),r},unlockArgs:function(r,i,n,o,a){var s=a.keys;if(s.length!==t)throw new Error("expected "+t+" public keys in signer.keys");var c=ar(e,s.map(lt)),d=s.map(lt).map(function(P){return P.toString("hex")}),g=a.signWith.map(function(P){var x=d.indexOf(P.toPublicKey().toBuffer().toString("hex"));if(x<0)throw new Error("signWith key is not in the committed key set");return{idx:x,priv:P}}).sort(function(P,x){return x.idx-P.idx}).slice(0,e);if(g.length<e)throw new Error("need at least "+e+" signing keys");var y=g.map(function(P){return sr.signInput(r,P.priv,i,n,o)});return[E.OP_0].concat(y).concat([c])}}}function fs(e){if(!e||typeof e.emit!="function"||typeof e.unlockArgs!="function"||typeof e.commit!="function")throw new Error("predicate authorizer needs { commit, emit, unlockArgs } functions");return{name:e.name||"predicate",commit:e.commit,emit:e.emit,unlockArgs:e.unlockArgs}}Tn.exports={singleKey:ls,multisig:ds,predicate:fs,redeemScript:ar}});var hr=O((xu,Ln)=>{"use strict";f();var gs=M(),We=je(),ur=pe(),Qe=cr(),dt=b(),v=V(),te=ur.scriptNum;function An(e,t){var r=u.Buffer.isBuffer(e)?e:t.commit(e);if(r.length!==20)throw new Error("owner commitment must be 20 bytes (HASH160)");return r}function In(e,t){return t.length?e.add(u.Buffer.from(t)):e.add(v.OP_0)}function bn(e,t){return e.add(v.OP_DUP),We.pushTxCore(e),e.add(v.OP_VERIFY),We.assertSighashAll(e),e.add(v.OP_DUP).add(te(52)).add(v.OP_RIGHT).add(te(8)).add(v.OP_LEFT).add(v.OP_TOALTSTACK),e.add(v.OP_DUP),We.extractHashOutputs(e),e.add(v.OP_TOALTSTACK),e.add(te(104)).add(v.OP_SPLIT).add(v.OP_NIP).add(v.OP_SIZE).add(te(52)).add(v.OP_SUB).add(v.OP_SPLIT).add(v.OP_DROP),e.add(v.OP_DUP).add(te(4)).add(te(20)).add(v.OP_SUBSTR),e.add(v.OP_SWAP).add(v.OP_TOALTSTACK),t.emit(e),e.add(v.OP_FROMALTSTACK),e}function kn(e){return e.add(te(4)).add(v.OP_SPLIT).add(te(20)).add(v.OP_SPLIT).add(v.OP_NIP),e.add(v.OP_TOALTSTACK),e.add(v.OP_SWAP).add(v.OP_CAT),e.add(v.OP_FROMALTSTACK).add(v.OP_CAT),e}function Hn(e){var t=e.toBuffer().length;if(t<=252||t>65535)throw new Error("token script length must use a 3-byte varint (253..65535); got "+t);return e}function ms(e,t,r){r=r||Qe.singleKey();var i=new dt;return i.add(An(t,r)),i.add(v.OP_DROP),bn(i,r),kn(i),i.add(v.OP_FROMALTSTACK),i.add(v.OP_SWAP),i.add(v.OP_FROMALTSTACK),i.add(v.OP_BIN2NUM).add(te(e)).add(v.OP_SUB).add(te(8)).add(v.OP_NUM2BIN),i.add(v.OP_SWAP).add(v.OP_CAT),i.add(v.OP_HASH256),i.add(v.OP_EQUAL),Hn(i)}function Fn(e,t){t=t||Qe.singleKey();var r=new dt;return r.add(An(e,t)),r.add(v.OP_DROP),bn(r,t),kn(r),r.add(v.OP_CAT),r.add(v.OP_SWAP).add(v.OP_CAT),r.add(v.OP_CAT),r.add(v.OP_FROMALTSTACK),r.add(v.OP_FROMALTSTACK).add(v.OP_DROP),r.add(v.OP_SWAP).add(v.OP_HASH256).add(v.OP_EQUAL),Hn(r)}function ys(e){return Qe.singleKey().commit(e)}function Ss(e,t,r,i,n,o){o=o||{};var a=o.auth||Qe.singleKey(),s=o.inputIndex||0;if(t.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(i<=1&&!o.allowLowValue)throw new Error("unlockTransfer: single-output token sets output = input - fee, which burns a "+i+"-sat UTXO (e.g. a 1-sat ordinal). Use Token.transferOrdinal / ownershipTokenMulti to preserve the satoshi.");We.grind(r,s,n,i,o.grind);var c=ur.rawPreimage(r,s,n,i),d=a.unlockArgs(r,s,n,i,e),g=new dt().add(u.Buffer.from(t));return d.forEach(function(y){g.add(y)}),g.add(u.Buffer.from(c)),g}function Cn(e,t,r,i,n,o,a){a=a||{};var s=a.auth||Qe.singleKey(),c=a.inputIndex||0;if(t.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(!o||o.tokenValue==null||o.tokenValue.length!==8)throw new Error("layout.tokenValue must be the 8-byte LE value of the token output");We.grind(r,c,n,i,a.grind);var d=ur.rawPreimage(r,c,n,i),g=s.unlockArgs(r,c,n,i,e),y=new dt;return In(y,o.before||u.Buffer.alloc(0)),In(y,o.after||u.Buffer.alloc(0)),y.add(u.Buffer.from(o.tokenValue)),y.add(u.Buffer.from(t)),g.forEach(function(P){y.add(P)}),y.add(u.Buffer.from(d)),y}function vs(e,t){return Fn(e,t)}function Os(e,t,r,i,n,o){o=o||{},i==null&&(i=1);var a=o.tokenIndex||0,s=r.outputs||[],c=s[a];if(!c)throw new Error("transferOrdinal: spend has no output at tokenIndex "+a);if(c.satoshis!==i)throw new Error("transferOrdinal: token output value ("+c.satoshis+" sat) must equal the ordinal value ("+i+" sat) to avoid burning the inscription");function d(x){return x.toBufferWriter().toBuffer()}var g=u.Buffer.concat(s.slice(0,a).map(d)),y=u.Buffer.concat(s.slice(a+1).map(d)),P=new gs(i).toBuffer({endian:"little",size:8});return Cn(e,t,r,i,n,{before:g,after:y,tokenValue:P},o)}Ln.exports={ownershipToken:ms,ownershipTokenMulti:Fn,ordinalLock:vs,ownerId:ys,unlockTransfer:Ss,unlockTransferMulti:Cn,transferOrdinal:Os}});var mr=O((_u,Rn)=>{"use strict";f();var ft=je(),xs=or(),Ps=hr(),fr=pe(),pr=b(),T=V(),lr=D(),Ve=fr.scriptNum,dr=5e8,_s=u.Buffer.from([255,255,255,255]),Es=u.Buffer.from([0]);function ws(e,t){return e instanceof lr.Output?e:e instanceof pr?new lr.Output({script:e,satoshis:t}):fr.p2pkhOutput(e,t)}function Ts(e,t,r,i,n,o){o=o||5e4;for(var a=0;a<o;a++){e.nLockTime=n+a;var s=fr.rawPreimage(e,t,r,i);if(ft.sFromPreimage(s))return s}throw new Error("covenant grind failed after "+o+" tries")}function le(){if(!(this instanceof le))return new le;this._outputs=[],this._minLockTime=null}le.prototype.payTo=function(e,t){return this._outputs.push(ws(e,t)),this};le.prototype.lockUntil=function(e){if(!Number.isInteger(e)||e<1||e>4294967295)throw new Error("lockUntil: expected an integer in 1..4294967295, got "+e+' (nLockTime 0 means "no lock" \u2014 consensus treats such a transaction as final)');return this._minLockTime=e,this};le.prototype.outputs=function(){return this._outputs.map(function(e){return new lr.Output(e.toObject())})};le.prototype.describe=function(){var e=[];if(this._outputs.forEach(function(r,i){e.push("output["+i+"] = "+r.satoshis+" sat to "+r.script.toASM().slice(0,24)+"...")}),this._minLockTime!==null){var t=this._minLockTime<dr?"block height":"unix time";e.push("nLockTime >= "+this._minLockTime+" as a "+t),e.push("this input is non-final (nSequence != 0xffffffff)")}return"spend allowed iff: "+e.join(" AND ")};le.prototype.compile=function(){if(this._outputs.length===0&&this._minLockTime===null)throw new Error("empty policy: add at least one constraint (payTo / lockUntil)");var e=this,t=new pr().add(T.OP_DUP);if(ft.pushTxCore(t),t.add(T.OP_VERIFY),this._outputs.length){var r=ft.hashOutputs(this._outputs);t.add(T.OP_DUP),ft.extractHashOutputs(t),t.add(u.Buffer.from(r)).add(T.OP_EQUALVERIFY)}return this._minLockTime!==null&&(t.add(T.OP_DUP),t.add(Ve(44)).add(T.OP_RIGHT).add(Ve(4)).add(T.OP_LEFT),t.add(_s).add(T.OP_EQUAL).add(T.OP_NOT).add(T.OP_VERIFY),t.add(T.OP_DUP),t.add(Ve(8)).add(T.OP_RIGHT).add(Ve(4)).add(T.OP_LEFT),t.add(Es).add(T.OP_CAT).add(T.OP_BIN2NUM),this._minLockTime<dr&&t.add(T.OP_DUP).add(Ve(dr)).add(T.OP_LESSTHAN).add(T.OP_VERIFY),t.add(Ve(this._minLockTime)).add(T.OP_GREATERTHANOREQUAL).add(T.OP_VERIFY)),t.add(T.OP_DROP).add(T.OP_1),{lock:t,outputs:e.outputs(),describe:function(){return e.describe()},unlock:function(i,n,o){o=o||0;var a=e._minLockTime===null?0:e._minLockTime;return e._minLockTime!==null&&(i.inputs[o].sequenceNumber=4294967294),new pr().add(Ts(i,o,t,n,a))}}};function gr(){return new le}gr.perpetual=function(e){return xs.pelsCovenant(e)};gr.token=function(e,t){return Ps.ownershipToken(e,t)};Rn.exports={policy:gr,Policy:le}});var Dn=O((wu,qn)=>{"use strict";f();var Is=ge(),As=M(),bs=D(),ks=V(),Hs=pe();function Nn(e){if(e===0)return"OP_0";if(e>=1&&e<=75)return"PUSH("+e+")";if(e===76)return"OP_PUSHDATA1";if(e===77)return"OP_PUSHDATA2";if(e===78)return"OP_PUSHDATA4";try{return ks.fromNumber(e).toString()}catch{return"0x"+e.toString(16)}}function Bn(e,t){t=t||16;var r=u.Buffer.from(e).toString("hex");return r.length<=t*2?r||"0":r.slice(0,t*2)+"...("+e.length+"B)"}function Fs(e,t,r){r=r||{};var i=new Is,n=[];i.stepListener=function(a,s,c){n.push({phase:i.script===t?"lock":"unlock",op:Nn(a.opcode&&typeof a.opcode.toNumber=="function"?a.opcode.toNumber():a.opcode.num),stack:s.map(function(d){return Bn(d)}),altstack:c.map(function(d){return Bn(d)})})};var o=i.verify(e,t,r.tx||new bs,r.inputIndex||0,typeof r.flags=="number"?r.flags:Hs.flags(),new As(r.satoshis||0));return{ok:o,err:i.errstr||"",steps:n}}function Un(e){var t=[],r=null;return e.steps.forEach(function(i,n){i.phase!==r&&(t.push("-- "+i.phase+" script --"),r=i.phase);var o=i.stack.length?i.stack.join(" | "):"(empty)",a=i.altstack.length?" alt:["+i.altstack.join(" | ")+"]":"";t.push(String(n).padStart(3)+" "+i.op.padEnd(16)+" -> ["+o+"]"+a)}),t.push((e.ok?"VALID":"INVALID")+(e.err?" ("+e.err+")":"")),t.join(`
|
|
23
|
-
`)}function Cs(e){return console.log(Un(e)),e}qn.exports={trace:Fs,format:Un,print:Cs,opLabel:Nn}});var Gn=O((Iu,Mn)=>{"use strict";f();Mn.exports="9.11.
|
|
23
|
+
`)}function Cs(e){return console.log(Un(e)),e}qn.exports={trace:Fs,format:Un,print:Cs,opLabel:Nn}});var Gn=O((Iu,Mn)=>{"use strict";f();Mn.exports="9.11.2"});var zn=O((bu,Kn)=>{"use strict";f();var Ls=fe(),Vn=D(),Rs=It(),Bs=b(),p={Covenant:ai(),Preimage:J(),SIGHASH:li(),Builder:vi(),UTXOGenerator:Bi(),ScriptTester:Mi(),CovenantBuilder:Vt().CovenantBuilder,CovenantTemplates:Vt().CovenantTemplates,OpcodeMap:Dt(),ScriptUtils:Xi(),StackExaminer:Wi(),ScriptInterpreter:tn(),CovenantHelpers:pe(),Locks:dn(),PushTx:je(),PELS:or(),Token:hr(),Authorizers:cr(),DSL:mr(),Policy:mr().Policy,Debugger:Dn()};p.policy=p.DSL.policy;p.trace=function(e,t,r){return p.Debugger.trace(e,t,r)};p.verifyScript=function(e,t,r){return p.CovenantHelpers.verify(e,t,r)};p.perpetualCovenant=function(e){return p.PELS.pelsCovenant(e)};p.ownershipToken=function(e,t,r){return p.Token.ownershipToken(e,t,r)};p.valueCovenant=function(e){return p.PushTx.valueCovenant(e)};p.ordinalLock=function(e,t){return p.Token.ordinalLock(e,t)};p.transferOrdinal=function(e,t,r,i,n,o){return p.Token.transferOrdinal(e,t,r,i,n,o)};p.createCovenant=function(e,t){return new p.Covenant(e,t)};p.extractPreimage=function(e,t){return new p.Preimage(e,t)};p.analyzeSIGHASH=function(e){return new p.SIGHASH(e)};p.buildCovenant=function(e,t){return new p.Builder(e,t)};p.createUTXOGenerator=function(e){return new p.UTXOGenerator(e)};p.createTestEnvironment=function(e){return p.UTXOGenerator.createTestEnvironment(e)};p.testScript=function(e,t,r){return p.ScriptTester.test(e,t,r)};p.testCovenant=function(e,t,r){return p.ScriptTester.testCovenant(e,t,r)};p.testFieldExtraction=function(e,t,r){return p.ScriptTester.testFieldExtraction(e,t,r)};p.debugScript=function(e,t){var r=new p.ScriptTester(t);return r.debug(e)};p.explainZeroHashes=function(){return p.SIGHASH.explainZeroMystery()};p.getAllSIGHASHTypes=function(){return p.SIGHASH.getAllTypes()};p.demonstrateAllSIGHASH=function(){return p.SIGHASH.generateAllDemonstrations()};p.createCovenantBuilder=function(){return new p.CovenantBuilder};p.createValueLockCovenant=function(e){return p.CovenantTemplates.valueLock(e)};p.createHashLockCovenant=function(e){return p.CovenantTemplates.hashLock(e)};p.createComplexValidationCovenant=function(e){return p.CovenantTemplates.complexValidation(e)};p.getOpcodeMap=function(){return p.OpcodeMap.opcodeMap};p.simulateScript=function(e,t){return p.OpcodeMap.utils.simulate(e,t)};p.createASMFromJS=function(e){return p.OpcodeMap.utils.createASM(e)};p.scriptToASM=function(e){return p.ScriptUtils.scriptToASM(e)};p.asmToScript=function(e){return p.ScriptUtils.asmToScript(e)};p.asmToHex=function(e){return p.ScriptUtils.asmToHex(e)};p.hexToASM=function(e){return p.ScriptUtils.hexToASM(e)};p.scriptToHex=function(e){return p.ScriptUtils.scriptToHex(e)};p.validateASM=function(e){return p.ScriptUtils.validateASM(e)};p.validateScript=function(e){return p.ScriptUtils.validateScript(e)};p.estimateScriptSize=function(e){return p.ScriptUtils.estimateScriptSize(e)};p.optimizeScript=function(e){return p.ScriptUtils.optimizeScript(e)};p.compareScripts=function(e,t){return p.ScriptUtils.compareScripts(e,t)};p.explainScript=function(e){return p.ScriptUtils.explainScript(e)};p.scriptMetrics=function(e){return p.ScriptUtils.scriptMetrics(e)};p.analyzeComplexity=function(e){return p.ScriptUtils.analyzeComplexity(e)};p.findOptimizations=function(e){return p.ScriptUtils.findOptimizations(e)};p.covenantToEnglish=function(e){return p.ScriptUtils.covenantToEnglish(e)};p.batchTestScripts=function(e,t){return p.ScriptUtils.batchTestScripts(e,t)};p.examineStack=function(e,t){return p.StackExaminer.runScript(e,t)};p.debugScriptExecution=function(e,t,r){return r=r||{},r.stepMode?p.ScriptInterpreter.stepThroughScript(p.ScriptInterpreter.parseScript(e+" "+t),new Vn,!0):p.ScriptInterpreter.runFullEvaluation(p.ScriptInterpreter.parseScript(e),p.ScriptInterpreter.parseScript(t),new Vn)};p.parseScript=function(e){return p.ScriptInterpreter.parseScript(e)};p.printStack=function(e,t){return p.ScriptInterpreter.printStack(e,t)};p.createQuickCovenant=function(e,t){let r=p.createCovenantBuilder();switch(e){case"value_lock":return r.comment(`Value lock: minimum ${t.value} satoshis`).extractField("value").push(t.value).greaterThanOrEqual().verify().build();case"hash_lock":return r.comment(`Hash lock: requires preimage of ${t.hash}`).push("secret_placeholder").sha256().push(t.hash).equalVerify().build();case"time_lock":return r.comment(`Time lock: requires nLockTime > ${t.timestamp}`).extractField("nLockTime").push(t.timestamp).greaterThan().verify().build();case"multi_condition":let i=r.comment("Multi-condition covenant");return t.conditions.forEach(n=>{switch(n.type){case"value":i=i.extractField("value").push(n.value).greaterThanOrEqual().verify();break;case"hash":i=i.push("secret_placeholder").sha256().push(n.hash).equalVerify();break;case"time":i=i.extractField("nLockTime").push(n.timestamp).greaterThan().verify();break}}),i.build();default:throw new Error(`Unknown covenant type: ${e}`)}};p.completeCovenantFlow=function(e,t,r){var i=new p.Covenant(e);return i.completeFlow(t,r)};p.getEducationalResources=function(){return{zeroHashMystery:p.SIGHASH.explainZeroMystery(),sighashTypes:p.SIGHASH.getAllTypes(),exampleDemonstrations:p.SIGHASH.generateAllDemonstrations()}};p.utils={};p.utils.reconstructP2pkhScript=function(e){return Bs.buildPublicKeyHashOut(e).toHex()};p.utils.createCovenantAddress=function(e){var t=Ls.sha256ripemd160(e.toBuffer());return Rs.fromScriptHash(t)};p.utils.decodeCompactSize=function(e,t){return p.Preimage.decodeCompactSize(e,t)};p.version=Gn();p.description="Smart Contract Framework for Bitcoin SV";p.features={BIP143_PREIMAGE:!0,COMPACT_SIZE_VARINT:!0,BIDIRECTIONAL_EXTRACTION:!0,SIGHASH_DETECTION:!0,ZERO_HASH_WARNINGS:!0,MULTI_FIELD_VALIDATION:!0,REAL_UTXO_GENERATION:!0,SCRIPT_TESTING:!0,LOCAL_VERIFICATION:!0,JAVASCRIPT_TO_SCRIPT:!0,OPCODE_MAPPING:!0,COVENANT_BUILDER:!0,SCRIPT_ANALYSIS:!0,SCRIPT_OPTIMIZATION:!0,SCRIPT_CONVERSION:!0,BATCH_TESTING:!0,QUICK_COVENANTS:!0,SCRIPT_EXPLANATIONS:!0,STACK_EXAMINATION:!0,SCRIPT_DEBUGGING:!0,STEP_BY_STEP_EXECUTION:!0,INTERACTIVE_DEBUGGING:!0};p.interpretScript=p.debugScriptExecution;p.getScriptMetrics=p.scriptMetrics;Kn.exports=p});var Ns=O((Hu,$n)=>{f();$n.exports=zn()});return Ns();})();
|
|
24
24
|
if(typeof module!=="undefined"&&module.exports){module.exports=bsvSmartContract}else if(typeof define==="function"&&define.amd){define([],function(){return bsvSmartContract})}
|