@smartledger/bsv 9.26.1 → 9.26.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 +63 -0
- package/README.md +19 -19
- package/bsv-ecies.min.js +4 -1
- package/bsv-gdaf.min.js +36 -33
- package/bsv-ltp.min.js +1 -1
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +36 -33
- package/bsv.min.js +36 -33
- package/docs/AUDIT_SCOPE.md +9 -9
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/audit-rfq/cure53.txt +2 -2
- package/docs/audit-rfq/ncc-group.txt +2 -2
- package/docs/audit-rfq/trail-of-bits.txt +2 -2
- 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/crypto/ecdsa.js +6 -3
- package/lib/ecies/electrum-ecies.js +17 -1
- 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 b1(e,t,r,n,i){if(!Ic(t))throw new ss("regexp","RegExp",t);var o=i==="match";if(typeof e!="string"||Ac(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(qr(e)," (").concat(xc(e),")"):(o?"The input did not match the regular expression ":"The input was expected to not match the regular expression ")+"".concat(xc(t),`. Input:
|
|
67
67
|
|
|
68
68
|
`).concat(xc(e),`
|
|
69
|
-
`));var a=new wi({actual:e,expected:t,message:r,operator:i,stackStartFn:n});throw a.generatedMessage=s,a}}ut.match=function e(t,r,n){b1(t,r,n,e,"match")};ut.doesNotMatch=function e(t,r,n){b1(t,r,n,e,"doesNotMatch")};function _1(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];h1.apply(void 0,[_1,t.length].concat(t))}ut.strict=n6(_1,ut,{equal:ut.strictEqual,deepEqual:ut.deepStrictEqual,notEqual:ut.notStrictEqual,notDeepEqual:ut.notDeepStrictEqual});ut.strict.strict=ut.strict});var qa=B((B5,E1)=>{"use strict";g();var Fa=at(),w1=We(),as=Ar(),vt=function e(t){if(!(this instanceof e))return new e(t);if(!Fa.isUndefined(t))if(d.Buffer.isBuffer(t))this.set({buf:t});else if(Fa.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(Fa.isObject(t)){var n=t;this.set(n)}else throw new TypeError("Unrecognized argument for BufferReader")};vt.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this};vt.prototype.eof=function(){return this.pos>=this.buf.length};vt.prototype.finished=vt.prototype.eof;vt.prototype.read=function(e){w1.checkArgument(!Fa.isUndefined(e),"Must specify a length");var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,t};vt.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e};vt.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e};vt.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e};vt.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e};vt.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readInt32LE=function(){var e=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=as.fromBuffer(e);return this.pos=this.pos+8,t};vt.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 as(r);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);n=new as(i,10,"le")}return this.pos=this.pos+8,n};vt.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}};vt.prototype.readVarLengthBuffer=function(){var e=this.readVarintNum(),t=this.read(e);return w1.checkState(t.length===e,"Invalid length while reading varlength buffer. Expected to read: "+e+" and read "+t.length),t};vt.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)}};vt.prototype.readVarintBN=function(){var e=this.readUInt8();switch(e){case 253:return new as(this.readUInt16LE());case 254:return new as(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new as(e)}};vt.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};vt.prototype.readReverse=function(e){Fa.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()};E1.exports=vt});var vp=B((M5,x1)=>{"use strict";g();var us=at(),Ha=We(),o6=vr();function Fe(e){if(!(this instanceof Fe))return new Fe(e);var t;if(us.isNumber(e))t=e;else if(us.isString(e))t=Fe.map[e];else throw new TypeError('Unrecognized num type: "'+typeof e+'" for Opcode');return o6.defineImmutable(this,{num:t}),this}Fe.fromBuffer=function(e){return Ha.checkArgument(d.Buffer.isBuffer(e)),new Fe(+("0x"+e.toString("hex")))};Fe.fromNumber=function(e){return Ha.checkArgument(us.isNumber(e)),new Fe(e)};Fe.fromString=function(e){Ha.checkArgument(us.isString(e));var t=Fe.map[e];if(typeof t>"u")throw new TypeError("Invalid opcodestr");return new Fe(t)};Fe.prototype.toHex=function(){return this.num.toString(16)};Fe.prototype.toBuffer=function(){return d.Buffer.from(this.toHex(),"hex")};Fe.prototype.toNumber=function(){return this.num};Fe.prototype.toString=function(){var e=Fe.reverseMap[this.num];if(typeof e>"u")throw new Error("Opcode does not have a string representation");return e};Fe.smallInt=function(e){return Ha.checkArgument(us.isNumber(e),"Invalid Argument: n should be number"),Ha.checkArgument(e>=0&&e<=16,"Invalid Argument: n must be between 0 and 16"),e===0?Fe("OP_0"):new Fe(Fe.map.OP_1+e-1)};Fe.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};Fe.reverseMap=[];for(mp in Fe.map)Fe.reverseMap[Fe.map[mp]]=mp;var mp;us.extend(Fe,Fe.map);Fe.isSmallIntOp=function(e){return e instanceof Fe&&(e=e.toNumber()),e===Fe.map.OP_0||e>=Fe.map.OP_1&&e<=Fe.map.OP_16};Fe.prototype.inspect=function(){return"<Opcode: "+this.toString()+", hex: "+this.toHex()+", decimal: "+this.num+">"};x1.exports=Fe});var fr=B((C5,A1)=>{"use strict";g();var oo=Ar(),s6=at(),ur=We(),a6=vr(),Ce=function e(t,r){if(!(this instanceof e))return new e(t,r);if(t instanceof oo)this.set({r:t,s:r});else if(t){var n=t;this.set(n)}};Ce.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};Ce.fromCompact=function(e){ur.checkArgument(d.Buffer.isBuffer(e),"Argument is expected to be a Buffer");var t=new Ce,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 ur.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),ur.checkArgument(i.length===32,new Error("r must be 32 bytes")),ur.checkArgument(o.length===32,new Error("s must be 32 bytes")),t.compressed=r,t.i=n,t.r=oo.fromBuffer(i),t.s=oo.fromBuffer(o),t};Ce.fromDER=Ce.fromBuffer=function(e,t){var r=Ce.parseDER(e,t),n=new Ce;return n.r=r.r,n.s=r.s,n};Ce.fromTxFormat=function(e){var t=e.readUInt8(e.length-1),r=e.slice(0,e.length-1),n=Ce.fromDER(r,!1);return n.nhashtype=t,n};Ce.fromString=function(e){var t=d.Buffer.from(e,"hex");return Ce.fromDER(t)};function I1(e,t){ur.checkArgument(t.length>0,new Error("Length of "+e+" is zero")),ur.checkArgument(!(t[0]&128),new Error("Value of "+e+" is negative")),ur.checkArgument(!(t.length>1&&t[0]===0&&!(t[1]&128)),new Error("Value of "+e+" is excessively padded"))}Ce.parseDER=function(e,t){ur.checkArgument(d.Buffer.isBuffer(e),new Error("DER formatted signature should be a buffer")),s6.isUndefined(t)&&(t=!0);var r=e[0];ur.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=e[1],i=e.slice(2).length;ur.checkArgument(!t||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=e[2];ur.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var s=e[3],a=e.slice(4,4+s),f=oo.fromBuffer(a),l=e[4]===0;ur.checkArgument(s===a.length,new Error("Length of r incorrect"));var m=e[4+s+0];ur.checkArgument(m===2,new Error("Integer byte for s should be 0x02"));var y=e[4+s+1],p=e.slice(4+s+2,4+s+2+y),S=oo.fromBuffer(p),O=e[4+s+2]===0;ur.checkArgument(y===p.length,new Error("Length of s incorrect"));var M=4+s+2+y;ur.checkArgument(n===M-2,new Error("Length of signature incorrect")),t&&(I1("r",a),I1("s",p));var U={header:r,length:n,rheader:o,rlength:s,rneg:l,rbuf:a,r:f,sheader:m,slength:y,sneg:O,sbuf:p,s:S};return U};Ce.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])};Ce.prototype.toBuffer=Ce.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,y=48,p=d.Buffer.concat([d.Buffer.from([y,f,l,s]),i,d.Buffer.from([m,a]),o]);return p};Ce.prototype.toString=function(){var e=this.toDER();return e.toString("hex")};Ce.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))};Ce.prototype.hasLowS=function(){return!(this.s.lt(new oo(1))||this.s.gt(new oo("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};Ce.prototype.hasDefinedHashtype=function(){if(!a6.isNaturalNumber(this.nhashtype))return!1;var e=this.nhashtype&31;return!(e<Ce.SIGHASH_ALL||e>Ce.SIGHASH_SINGLE)};Ce.prototype.toTxFormat=function(){var e=this.toDER(),t=d.Buffer.alloc(1);return t.writeUInt8(this.nhashtype,0),d.Buffer.concat([e,t])};Ce.SIGHASH_ALL=1;Ce.SIGHASH_NONE=2;Ce.SIGHASH_SINGLE=3;Ce.SIGHASH_CHRONICLE=32;Ce.SIGHASH_FORKID=64;Ce.SIGHASH_ANYONECANPAY=128;Ce.prototype.isCanonical=function(){var e=gi(),t=e.getN().shrn(1);return this.s.lte(t)};Ce.prototype.toCanonical=function(){if(this.isCanonical())return new Ce({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var e=gi(),t=e.getN(),r=t.sub(this.s);return new Ce({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};Ce.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=gi(),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};Ce.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};Ce.prototype.applySecurityPatches=function(){var e=gi(),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};A1.exports=Ce});var wp=B((D5,R1)=>{"use strict";g();var bp=Object.create(null),_p=[],Sp=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_DEPRECATION_WARNINGS==="1");function O1(e,t){if(!e||typeof e.what!="string"||e.what==="")throw new TypeError(t+"() requires { what: string }")}function u6(e){var t="[@smartledger/bsv] "+e.what+" is deprecated";return e.since&&(t+=" since "+e.since),t+=".",e.why&&(t+=" "+e.why.charAt(0).toUpperCase()+e.why.slice(1)+"."),e.use&&(t+=" Use "+e.use+" instead."),t+=e.removeIn?" It will be removed in "+e.removeIn+".":" A removal version has not been set; it will not be removed in a 9.x release.",t}function Hn(e){if(!e||!e.what)throw new TypeError("deprecate() requires { what }");if(bp[e.what])return!1;bp[e.what]=!0;var t=u6(e);return _p.push({what:e.what,since:e.since||null,removeIn:e.removeIn||null,use:e.use||null,message:t}),Sp&&console.warn(t),!0}Hn.fn=function(e,t){if(typeof e!="function")throw new TypeError("deprecate.fn() requires a function");O1(t,"deprecate.fn");var r=function(){return Hn(t),e.apply(this,arguments)};return Object.defineProperty(r,"name",{value:e.name,configurable:!0}),Object.defineProperty(r,"length",{value:e.length,configurable:!0}),r.__wrapped=e,r.__deprecation=t,r};Hn.property=function(e,t,r,n){O1(n,"deprecate.property");var i,o=!1;return Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get:function(){return Hn(n),o||(i=r(),o=!0),i}}),e};Hn.fired=function(){return _p.slice()};Hn.setEnabled=function(e){Sp=!!e};Hn.isEnabled=function(){return Sp};Hn.reset=function(){bp=Object.create(null),_p.length=0};R1.exports=Hn});var Ip=B((F5,N1)=>{"use strict";g();var f6=Aa(),jr=uo(),c6=qa(),Ep=nr(),X=vp(),ao=Pr(),so=fr(),T1=Ea(),lt=We(),Le=at(),xp=ii(),l6=wp(),P1=Lt(),h6=vr(),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 jr)return e.fromAddress(t);if(t instanceof e)return e.fromBuffer(t.toBuffer());if(Le.isString(t))return e.fromString(t);Le.isObject(t)&&Le.isArray(t.chunks)&&this.set(t)};q.prototype.set=function(e){return lt.checkArgument(Le.isObject(e)),lt.checkArgument(Le.isArray(e.chunks)),this.chunks=e.chunks,this};q.fromBuffer=function(e){var t=new q;t.chunks=[];for(var r=new c6(e);!r.finished();)try{var n=r.readUInt8(),i,o;n>0&&n<X.OP_PUSHDATA1?(i=n,t.chunks.push({buf:r.read(i),len:i,opcodenum:n})):n===X.OP_PUSHDATA1?(i=r.readUInt8(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===X.OP_PUSHDATA2?(i=r.readUInt16LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===X.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 xp.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<X.OP_PUSHDATA1?t+=Tc(n.buf):i===X.OP_PUSHDATA1?t+=1+Tc(n.buf):i===X.OP_PUSHDATA2?t+=2+Tc(n.buf):i===X.OP_PUSHDATA4&&(t+=4+Tc(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<X.OP_PUSHDATA1?s+=n.buf.copy(o,s):i===X.OP_PUSHDATA1?(s=o.writeUInt8(n.len,s),s+=n.buf.copy(o,s)):i===X.OP_PUSHDATA2?(s=o.writeUInt16LE(n.len,s),s+=n.buf.copy(o,s)):i===X.OP_PUSHDATA4&&(s=o.writeUInt32LE(n.len,s),s+=n.buf.copy(o,s)));return o};function Tc(e){if(!d.Buffer.isBuffer(e))throw new f6.AssertionError({message:"chunk data must be a Buffer",actual:e,expected:"Buffer",operator:"isBuffer"});return e.length}function B1(e){if(/^0x[0-9a-fA-F]{2}$/.test(e)){var t=parseInt(e.slice(2),16);return t>X.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=X(i),s=o.toNumber(),a=B1(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=X.OP_1NEGATE,t.chunks.push({opcodenum:s}),n=n+1;else if(Le.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<X.OP_PUSHDATA1?s=l:l<Math.pow(2,8)?s=X.OP_PUSHDATA1:l<Math.pow(2,16)?s=X.OP_PUSHDATA2:l<Math.pow(2,32)&&(s=X.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};var d6=/^(?:[0-9a-fA-F]{2})*$/;q.fromHex=function(e){return typeof e=="string"&&!d6.test(e)&&l6({what:"Script.fromHex() with a string that is not whole hex",since:"9.17.0",removeIn:"10.0.0",why:"Buffer.from() stops at the first character it cannot decode, so the script is silently truncated",use:"a round-trip check, Script.fromHex(h).toHex() === h.toLowerCase()"}),new q(P1.Buffer.from(e,"hex"))};q.fromString=function(e){if(h6.isHexa(e)||e.length===0)return new q(P1.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=X(i),s=o.toNumber(),a=B1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(Le.isUndefined(s))if(s=parseInt(i),s>0&&s<X.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===X.OP_PUSHDATA1||s===X.OP_PUSHDATA2||s===X.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===X.OP_PUSHDATA1||r===X.OP_PUSHDATA2||r===X.OP_PUSHDATA4;!n&&s&&(i=i+" "+X(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 X.reverseMap[r]<"u")n?r===0?i=i+" 0":r===79?i=i+" -1":i=i+" "+X(r).toString():i=i+" "+X(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===X.OP_DUP&&this.chunks[1].opcodenum===X.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===X.OP_EQUALVERIFY&&this.chunks[4].opcodenum===X.OP_CHECKSIG)};q.prototype.isPublicKeyHashOutPrefix=function(){return!!(this.chunks.length>=5&&this.chunks[0].opcodenum===X.OP_DUP&&this.chunks[1].opcodenum===X.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===X.OP_EQUALVERIFY&&this.chunks[4].opcodenum===X.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 lt.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output"),this.chunks[0].buf};q.prototype.getPublicKeyHash=function(){return lt.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===X.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 ao.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]===X.OP_HASH160&&e[1]===20&&e[e.length-1]===X.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 xp.Script.InvalidBuffer)return!1;throw i}var n=r.classify();return n!==q.types.UNKNOWN};q.prototype.isMultisigOut=function(){return this.chunks.length>3&&X.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)})&&X.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===X.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)&&so.isTxDER(e.buf)})};q.prototype.isDataOut=function(){var e=this.chunks.length>=1&&this.chunks[0].opcodenum===X.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!==X.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 Le.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 Le.every(this.chunks,function(e){return e.opcodenum<=X.OP_16||e.opcodenum===X.OP_PUSHDATA1||e.opcodenum===X.OP_PUSHDATA2||e.opcodenum===X.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(lt.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 X)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 X?r=e.toNumber():r=X(e).toNumber(),this._insertAtPosition({opcodenum:r},t),this};q.prototype._addBuffer=function(e,t){var r,n=e.length;if(n>=0&&n<X.OP_PUSHDATA1)r=n;else if(n<Math.pow(2,8))r=X.OP_PUSHDATA1;else if(n<Math.pow(2,16))r=X.OP_PUSHDATA2;else if(n<Math.pow(2,32))r=X.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!==X.OP_CODESEPARATOR&&e.push(this.chunks[t]);return this.chunks=e,this};q.buildMultisigOut=function(e,t,r){lt.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(X.smallInt(t)),e=Le.map(e,ao);var i=e;r.noSorting||(i=e.map(a=>a.toString("hex")).sort().map(a=>new ao(a)));for(var o=0;o<i.length;o++){var s=i[o];n.add(s.toBuffer())}return n.add(X.smallInt(e.length)),n.add(X.OP_CHECKMULTISIG),n};q.buildMultisigIn=function(e,t,r,n){lt.checkArgument(Le.isArray(e)),lt.checkArgument(Le.isNumber(t)),lt.checkArgument(Le.isArray(r)),n=n||{};var i=new q;return i.add(X.OP_0),Le.each(r,function(o){lt.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i};q.buildP2SHMultisigIn=function(e,t,r,n){lt.checkArgument(Le.isArray(e)),lt.checkArgument(Le.isNumber(t)),lt.checkArgument(Le.isArray(r)),n=n||{};var i=new q;return i.add(X.OP_0),Le.each(r,function(o){lt.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){lt.checkArgument(!Le.isUndefined(e)),lt.checkArgument(e instanceof ao||e instanceof jr||Le.isString(e)),e instanceof ao?e=e.toAddress():Le.isString(e)&&(e=new jr(e));var t=new q;return t.add(X.OP_DUP).add(X.OP_HASH160).add(e.hashBuffer).add(X.OP_EQUALVERIFY).add(X.OP_CHECKSIG),t._network=e.network,t};q.buildPublicKeyOut=function(e){lt.checkArgument(e instanceof ao);var t=new q;return t.add(e.toBuffer()).add(X.OP_CHECKSIG),t};q.buildDataOut=function(e,t){lt.checkArgument(Le.isUndefined(e)||Le.isString(e)||Le.isArray(e)||d.Buffer.isBuffer(e));var r=e;Le.isArray(r)||(r=[e]);var n=new q;n.add(X.OP_RETURN);for(let i of r)lt.checkArgument(Le.isUndefined(i)||Le.isString(i)||d.Buffer.isBuffer(i)),Le.isString(i)&&(i=d.Buffer.from(i,t)),Le.isUndefined(i)||n.add(i);return n};q.buildSafeDataOut=function(e,t){var r=q.buildDataOut(e,t),n=new q;return n.add(X.OP_FALSE),n.add(r),n};q.buildScriptHashOut=function(e){lt.checkArgument(e instanceof q||e instanceof jr&&e.isPayToScriptHash());var t=new q;return t.add(X.OP_HASH160).add(e instanceof jr?e.hashBuffer:Ep.sha256ripemd160(e.toBuffer())).add(X.OP_EQUAL),t._network=e._network||e.network,t};q.buildPublicKeyIn=function(e,t){lt.checkArgument(e instanceof so||d.Buffer.isBuffer(e)),lt.checkArgument(Le.isUndefined(t)||Le.isNumber(t)),e instanceof so&&(e=e.toBuffer());var r=new q;return r.add(d.Buffer.concat([e,d.Buffer.from([(t||so.SIGHASH_ALL)&255])])),r};q.buildPublicKeyHashIn=function(e,t,r){lt.checkArgument(t instanceof so||d.Buffer.isBuffer(t)),lt.checkArgument(Le.isUndefined(r)||Le.isNumber(r)),t instanceof so&&(t=t.toBuffer());var n=new q().add(d.Buffer.concat([t,d.Buffer.from([(r||so.SIGHASH_ALL)&255])])).add(new ao(e).toBuffer());return n};q.empty=function(){return new q};q.prototype.toScriptHashOut=function(){return q.buildScriptHashOut(this)};q.fromAddress=function(e){if(e=jr(e),e.isPayToScriptHash())return q.buildScriptHashOut(e);if(e.isPayToPublicKeyHash())return q.buildPublicKeyHashOut(e);throw new xp.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=jr.PayToScriptHash;else if(this.isPublicKeyHashOut())e.hashBuffer=this.getData(),e.type=jr.PayToPublicKeyHash;else return!1;return e};q.prototype._getInputAddressInfo=function(){var e={};if(this.isPublicKeyHashIn())e.hashBuffer=Ep.sha256ripemd160(this.chunks[1].buf),e.type=jr.PayToPublicKeyHash;else if(this.isScriptHashIn())e.hashBuffer=Ep.sha256ripemd160(this.chunks[this.chunks.length-1].buf),e.type=jr.PayToScriptHash;else return!1;return e};q.prototype.toAddress=function(e){var t=this.getAddressInfo();return t?(t.network=T1.get(e)||this._network||T1.defaultNetwork,new jr(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&&p6(i))){var o=q({chunks:[i]}).toBuffer();t.equals(o)&&(this.chunks.splice(n,1),n--)}}return this};function p6(e){var t=e.opcodenum;if(typeof t!="number"||!Number.isInteger(t)||t<0||t>255)return!1;if(!e.buf||t>X.OP_PUSHDATA4)return!0;if(!d.Buffer.isBuffer(e.buf))return!1;var r=e.len;return t===X.OP_PUSHDATA1?Number.isInteger(r)&&r>=0&&r<=255:t===X.OP_PUSHDATA2?Number.isInteger(r)&&r>=0&&r<=65535:t===X.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===X.OP_0:r.length===1&&r[0]>=1&&r[0]<=16?n===X.OP_1+(r[0]-1):r.length===1&&r[0]===129?n===X.OP_1NEGATE:r.length<=75?n===r.length:r.length<=255?n===X.OP_PUSHDATA1:r.length<=65535?n===X.OP_PUSHDATA2:!0:!0};q.prototype._decodeOP_N=function(e){if(e===X.OP_0)return 0;if(e>=X.OP_1&&e<=X.OP_16)return e-(X.OP_1-1);throw new Error("Invalid opcode: "+JSON.stringify(e))};q.prototype.getSignatureOperationsCount=function(e){e=Le.isUndefined(e)?!0:e;var t=this,r=0,n=X.OP_INVALIDOPCODE;return Le.each(t.chunks,function(o){var s=o.opcodenum;s===X.OP_CHECKSIG||s===X.OP_CHECKSIGVERIFY?r++:(s===X.OP_CHECKMULTISIG||s===X.OP_CHECKMULTISIGVERIFY)&&(e&&n>=X.OP_1&&n<=X.OP_16?r+=t._decodeOP_N(n):r+=20),n=s}),r};N1.exports=q});var fs=B((H5,k1)=>{"use strict";g();var M1=Aa(),bt=function e(t){if(!(this instanceof e))return new e(t);this.bufLen=0,t?this.set(t):this.bufs=[]};bt.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};bt.prototype.toBuffer=function(){return this.concat()};bt.prototype.concat=function(){return d.Buffer.concat(this.bufs,this.bufLen)};bt.prototype.write=function(e){return M1(d.Buffer.isBuffer(e)),this.bufs.push(e),this.bufLen+=e.length,this};bt.prototype.writeReverse=function(e){return M1(d.Buffer.isBuffer(e)),this.bufs.push(d.Buffer.from(e).reverse()),this.bufLen+=e.length,this};bt.prototype.writeUInt8=function(e){var t=d.Buffer.alloc(1);return t.writeUInt8(e,0),this.write(t),this};bt.prototype.writeUInt16BE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16BE(e,0),this.write(t),this};bt.prototype.writeUInt16LE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16LE(e,0),this.write(t),this};bt.prototype.writeUInt32BE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32BE(e,0),this.write(t),this};bt.prototype.writeInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeInt32LE(e,0),this.write(t),this};bt.prototype.writeUInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32LE(e,0),this.write(t),this};bt.prototype.writeUInt64BEBN=function(e){var t=e.toBuffer({size:8});return this.write(t),this};bt.prototype.writeUInt64LEBN=function(e){var t=e.toBuffer({size:8});return this.writeReverse(t),this};bt.prototype.writeVarintNum=function(e){var t=bt.varintBufNum(e);return this.write(t),this};bt.prototype.writeVarintBN=function(e){var t=bt.varintBufBN(e);return this.write(t),this};bt.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};bt.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 bt;n.writeUInt8(255),n.writeUInt64LEBN(e),t=n.concat()}return t};k1.exports=bt});var ja=B((K5,D1)=>{"use strict";g();var C1=fs(),L1=qa(),g6=Ar(),Kr=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 g6){var n=t;this.fromBN(n)}else if(t){var i=t;this.set(i)}};Kr.prototype.set=function(e){return this.buf=e.buf||this.buf,this};Kr.prototype.fromString=function(e){return this.set({buf:d.Buffer.from(e,"hex")}),this};Kr.prototype.toString=function(){return this.buf.toString("hex")};Kr.prototype.fromBuffer=function(e){return this.buf=e,this};Kr.prototype.fromBufferReader=function(e){return this.buf=e.readVarintBuf(),this};Kr.prototype.fromBN=function(e){return this.buf=C1().writeVarintBN(e).concat(),this};Kr.prototype.fromNumber=function(e){return this.buf=C1().writeVarintNum(e).concat(),this};Kr.prototype.toBuffer=function(){return this.buf};Kr.prototype.toBN=function(){return L1(this.buf).readVarintBN()};Kr.prototype.toNumber=function(){return L1(this.buf).readVarintNum()};D1.exports=Kr});var jn=B((V5,F1)=>{"use strict";g();var Pc=at(),Ap=Ar(),U1=Lt(),Bc=vr(),y6=fs(),m6=ja(),Op=Gr(),Rp=We(),v6=ii(),b6=9007199254740991;function Wt(e){if(!(this instanceof Wt))return new Wt(e);if(Pc.isObject(e))if(this.satoshis=e.satoshis,d.Buffer.isBuffer(e.script))this._scriptBuffer=e.script;else{var t;Pc.isString(e.script)&&Bc.isHexa(e.script)?t=U1.Buffer.from(e.script,"hex"):t=e.script,this.setScript(t)}else throw new TypeError("Unrecognized argument for Output")}Object.defineProperty(Wt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this._script?this._script:(this.setScriptFromBuffer(this._scriptBuffer),this._script)}});Object.defineProperty(Wt.prototype,"satoshis",{configurable:!1,enumerable:!0,get:function(){return this._satoshis},set:function(e){e instanceof Ap?(this._satoshisBN=e,this._satoshis=e.toNumber()):Pc.isString(e)?(this._satoshis=parseInt(e),this._satoshisBN=Ap.fromNumber(this._satoshis)):(Rp.checkArgument(Bc.isNaturalNumber(e),"Output satoshis is not a natural number"),this._satoshisBN=Ap.fromNumber(e),this._satoshis=e),Rp.checkState(Bc.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});Wt.prototype.invalidSatoshis=function(){return this._satoshis>b6?"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(Wt.prototype,"satoshisBN",{configurable:!1,enumerable:!0,get:function(){return this._satoshisBN},set:function(e){this._satoshisBN=e,this._satoshis=e.toNumber(),Rp.checkState(Bc.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});Wt.prototype.toObject=Wt.prototype.toJSON=function(){var t={satoshis:this.satoshis};return t.script=this._scriptBuffer.toString("hex"),t};Wt.fromObject=function(e){return new Wt(e)};Wt.prototype.setScriptFromBuffer=function(e){this._scriptBuffer=e;try{this._script=Op.fromBuffer(this._scriptBuffer),this._script._isOutput=!0}catch(t){if(t instanceof v6.Script.InvalidBuffer)this._script=null;else throw t}};Wt.prototype.setScript=function(e){if(e instanceof Op)this._scriptBuffer=e.toBuffer(),this._script=e,this._script._isOutput=!0;else if(Pc.isString(e))this._script=Op.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};Wt.prototype.inspect=function(){var e;return this.script?e=this.script.inspect():e=this._scriptBuffer.toString("hex"),"<Output ("+this.satoshis+" sats) "+e+">"};Wt.fromBufferReader=function(e){var t={};t.satoshis=e.readUInt64LEBN();var r=e.readVarintNum();return r!==0?t.script=e.read(r):t.script=U1.Buffer.from([]),new Wt(t)};Wt.prototype.toBufferWriter=function(e){e||(e=new y6),e.writeUInt64LEBN(this._satoshisBN);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e};Wt.prototype.getSize=function(){var e=this.script.toBuffer().length,t=m6(e).toBuffer().length;return 8+t+e};F1.exports=Wt});var Ka=B((z5,q1)=>{"use strict";g();var br=Ar(),gn=gi(),_6=fr(),S6=Pr(),w6=sa(),Ei=nr(),E6=at(),Tp=We(),tt=function e(t){if(!(this instanceof e))return new e(t);t&&this.set(t)};Object.defineProperty(tt.prototype,"k",{get:function(){return this._k},set:function(e){this._k=e,this._kFresh=!0},enumerable:!0,configurable:!0});tt.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=fr();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};tt.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()};tt.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")};tt.fromString=function(e){var t=JSON.parse(e);return new tt(t)};tt.prototype.randomK=function(){var e=gn.getN(),t;do t=br.fromBuffer(w6.getRandomBuffer(32));while(!(t.lt(e)&&t.gt(br.Zero)));return this.k=t,this};tt.prototype.deterministicK=function(e){E6.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=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0]),n,i]),r),t=Ei.sha256hmac(t,r),r=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([1]),n,i]),r),t=Ei.sha256hmac(t,r),t=Ei.sha256hmac(t,r);for(var o=br.fromBuffer(t),s=gn.getN(),a=0;a<e||!(o.lt(s)&&o.gt(br.Zero));a++)r=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0])]),r),t=Ei.sha256hmac(t,r),t=Ei.sha256hmac(t,r),o=br.fromBuffer(t);return this.k=o,this};tt.prototype.toPublicKey=function(){var e=this.sig.i;Tp.checkArgument(e===0||e===1||e===2||e===3,new Error("i must be equal to 0, 1, 2, or 3"));var t=br.fromBuffer(this.hashbuf),r=this.sig.r,n=this.sig.s,i=e&1,o=e>>1,s=gn.getN(),a=gn.getG(),f=o?r.add(s):r,l=gn.fromX(i,f),m=l.mul(s);if(!m.isInfinity())throw new Error("nR is not a valid curve point");var y=t.neg().umod(s),p=r.invm(s),S=l.mul(n).add(a.mul(y)).mul(p),O=S6.fromPoint(S,this.sig.compressed);return O};tt.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=gn.getN();try{if(e.lte(br.Zero)||t.lte(br.Zero)||e.gte(r)||t.gte(r))return"r and s not in range";var n=br.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=gn.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}};tt.toLowS=function(e){return e.gt(br.fromBuffer(d.Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=gn.getN().sub(e)),e};tt.prototype._findSignature=function(e,t){var r=gn.getN(),n=gn.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(br.Zero)<=0||f.cmp(br.Zero)<=0);return this._kFresh=!1,f=tt.toLowS(f),{s:f,r:a}};tt.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;Tp.checkState(e&&t&&r,new Error("invalid parameters")),Tp.checkState(d.Buffer.isBuffer(e)&&e.length===32,new Error("hashbuf must be a 32 byte buffer"));var n=br.fromBuffer(e,this.endian?{endian:this.endian}:void 0),i=this._findSignature(r,n);return i.compressed=this.pubkey.compressed,this.sig=new _6(i),this};tt.prototype.signRandomK=function(){return this.randomK(),this.sign()};tt.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)};tt.prototype.verify=function(){return this.verified=!this.sigError(),this.verified};tt.prototype.verifyBool=function(){return this.verify()===!0};tt.sign=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).sign().sig};tt.signWithCalcI=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).sign().calci().sig};tt.signRandomK=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).signRandomK().sig};tt.verify=function(e,t,r,n){return tt().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify()};q1.exports=tt});var cs=B(($5,G1)=>{"use strict";g();var xi=at(),x6=We(),Ga=ii(),I6=fs(),Pp=Lt(),j1=vr(),Nc=Gr(),A6=Ii(),H1=jn(),Mc=4294967295,O6=Mc-2,K1=Mc,R6=Mc-1;function rt(e){if(!(this instanceof rt))return new rt(e);if(e)return this._fromObject(e)}rt.MAXINT=Mc;rt.DEFAULT_SEQNUMBER=K1;rt.DEFAULT_LOCKTIME_SEQNUMBER=R6;rt.DEFAULT_RBF_SEQNUMBER=O6;rt.BASE_SIZE=40;Object.defineProperty(rt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this.isNull()?null:(this._script||(this._script=new Nc(this._scriptBuffer),this._script._isInput=!0),this._script)}});rt.fromObject=function(e){x6.checkArgument(xi.isObject(e));var t=new rt;return t._fromObject(e)};rt.prototype._fromObject=function(e){var t;if(xi.isString(e.prevTxId)&&j1.isHexa(e.prevTxId)?t=Pp.Buffer.from(e.prevTxId,"hex"):t=e.prevTxId,this.output=e.output?e.output instanceof H1?e.output:new H1(e.output):void 0,this.prevTxId=t||e.txidbuf,this.outputIndex=xi.isUndefined(e.outputIndex)?e.txoutnum:e.outputIndex,this.sequenceNumber=xi.isUndefined(e.sequenceNumber)?xi.isUndefined(e.seqnum)?K1:e.seqnum:e.sequenceNumber,xi.isUndefined(e.script)&&xi.isUndefined(e.scriptBuffer))throw new Ga.Transaction.Input.MissingScript;return this.setScript(e.scriptBuffer||e.script),this};rt.prototype.toObject=rt.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};rt.fromBufferReader=function(e){var t=new rt;return t.prevTxId=e.readReverse(32),t.outputIndex=e.readUInt32LE(),t._scriptBuffer=e.readVarLengthBuffer(),t.sequenceNumber=e.readUInt32LE(),t};rt.prototype.toBufferWriter=function(e){e||(e=new I6),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};rt.prototype.setScript=function(e){if(this._script=null,e instanceof Nc)this._script=e,this._script._isInput=!0,this._scriptBuffer=e.toBuffer();else if(e===null)this._script=Nc.empty(),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(j1.isHexa(e))this._scriptBuffer=Pp.Buffer.from(e,"hex");else if(xi.isString(e))this._script=new Nc(e),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(d.Buffer.isBuffer(e))this._scriptBuffer=Pp.Buffer.from(e);else throw new TypeError("Invalid argument type: script");return this};rt.prototype.getSignatures=function(){throw new Ga.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: "+JSON.stringify(this))};rt.prototype.isFullySigned=function(){throw new Ga.AbstractMethodInvoked("Input#isFullySigned")};rt.prototype.isFinal=function(){return this.sequenceNumber===rt.MAXINT};rt.prototype.addSignature=function(){throw new Ga.AbstractMethodInvoked("Input#addSignature")};rt.prototype.clearSignatures=function(){throw new Ga.AbstractMethodInvoked("Input#clearSignatures")};rt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,A6.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};rt.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};rt.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};G1.exports=rt});var ls=B((X5,V1)=>{"use strict";g();V1.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}});var ds=B((Q5,Y1)=>{"use strict";g();var hs=at(),Br=We(),T6=ls(),W1=vr(),z1=Pr(),P6=ii(),Va=fr();function Vr(e){if(!(this instanceof Vr))return new Vr(e);if(e instanceof Vr)return e;if(hs.isObject(e))return this._fromObject(e);throw new P6.InvalidArgument("TransactionSignatures must be instantiated from an object")}T6(Vr,Va);Vr.prototype._fromObject=function(e){return this._checkObjectArgs(e),this.publicKey=new z1(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 Va?e.signature:d.Buffer.isBuffer(e.signature)?Va.fromBuffer(e.signature):Va.fromString(e.signature),this.sigtype=e.sigtype,this};Vr.prototype._checkObjectArgs=function(e){Br.checkArgument(z1(e.publicKey),"publicKey"),Br.checkArgument(!hs.isUndefined(e.inputIndex),"inputIndex"),Br.checkArgument(!hs.isUndefined(e.outputIndex),"outputIndex"),Br.checkState(hs.isNumber(e.inputIndex),"inputIndex must be a number"),Br.checkState(hs.isNumber(e.outputIndex),"outputIndex must be a number"),Br.checkArgument(e.signature,"signature"),Br.checkArgument(e.prevTxId,"prevTxId"),Br.checkState(e.signature instanceof Va||d.Buffer.isBuffer(e.signature)||W1.isHexa(e.signature),"signature must be a buffer or hexa value"),Br.checkState(d.Buffer.isBuffer(e.prevTxId)||W1.isHexa(e.prevTxId),"prevTxId must be a buffer or hexa value"),Br.checkArgument(e.sigtype,"sigtype"),Br.checkState(hs.isNumber(e.sigtype),"sigtype must be a number")};Vr.prototype.toObject=Vr.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}};Vr.fromObject=function(e){return Br.checkArgument(e),new Vr(e)};Y1.exports=Vr});var Q1=B((tq,J1)=>{"use strict";g();var B6=ls(),Z1=We(),Bp=cs(),N6=jn(),M6=Ii(),X1=Gr(),$1=fr(),k6=ds();function Kn(){Bp.apply(this,arguments)}B6(Kn,Bp);Kn.prototype.getSignatures=function(e,t,r,n){Z1.checkState(this.output instanceof N6),n=n||$1.SIGHASH_ALL|$1.SIGHASH_FORKID;var i=t.toPublicKey();return i.toString()===this.output.script.getPublicKey().toString("hex")?[new k6({publicKey:i,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:M6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Kn.prototype.addSignature=function(e,t){return Z1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(X1.buildPublicKeyIn(t.signature.toDER(),t.sigtype)),this};Kn.prototype.clearSignatures=function(){return this.setScript(X1.empty()),this};Kn.prototype.isFullySigned=function(){return this.script.isPublicKeyIn()};Kn.SCRIPT_MAX_SIZE=74;Kn.prototype._estimateSize=function(){return Bp.BASE_SIZE+Kn.SCRIPT_MAX_SIZE};J1.exports=Kn});var ix=B((nq,nx)=>{"use strict";g();var C6=ls(),tx=We(),L6=nr(),Np=cs(),D6=jn(),U6=Ii(),rx=Gr(),ex=fr(),F6=ds();function Gn(){Np.apply(this,arguments)}C6(Gn,Np);Gn.prototype.getSignatures=function(e,t,r,n,i){tx.checkState(this.output instanceof D6),i=i||L6.sha256ripemd160(t.publicKey.toBuffer()),n=n||ex.SIGHASH_ALL|ex.SIGHASH_FORKID;var o=this.output.script.chunks[2]&&this.output.script.chunks[2].buf;return o&&i.equals(o)?[new F6({publicKey:t.publicKey,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:U6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Gn.prototype.addSignature=function(e,t){return tx.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(rx.buildPublicKeyHashIn(t.publicKey,t.signature.toDER(),t.sigtype)),this};Gn.prototype.clearSignatures=function(){return this.setScript(rx.empty()),this};Gn.prototype.isFullySigned=function(){return this.script.isPublicKeyHashIn()};Gn.SCRIPT_MAX_SIZE=108;Gn.prototype._estimateSize=function(){return Np.BASE_SIZE+Gn.SCRIPT_MAX_SIZE};nx.exports=Gn});var ax=B((oq,sx)=>{"use strict";g();var Wr=at(),q6=ls(),Cc=cs(),H6=jn(),Wa=We(),ox=Gr(),kc=fr(),Mp=Ii(),kp=ds(),j6=Pr(),K6=ja();function Ft(e,t,r,n){Cc.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 j6(o)),Wa.checkState(ox.buildMultisigOut(this.publicKeys,r).equals(this.output.script),"Provided public keys don't match to the provided output script"),this.publicKeyIndex={},Wr.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)}q6(Ft,Cc);Ft.prototype.toObject=function(){var e=Cc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=Wr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Ft.prototype._deserializeSignatures=function(e){return Wr.map(e,function(t){if(t)return new kp(t)})};Ft.prototype._serializeSignatures=function(){return Wr.map(this.signatures,function(e){if(e)return e.toObject()})};Ft.prototype.getSignatures=function(e,t,r,n){Wa.checkState(this.output instanceof H6),n=n||kc.SIGHASH_ALL|kc.SIGHASH_FORKID;var i=this,o=[];return Wr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new kp({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:Mp.sign(e,t,n,r,i.output.script,i.output.satoshisBN),sigtype:n}))}),o};Ft.prototype.addSignature=function(e,t){return Wa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),Wa.checkArgument(!Wr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),Wa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Ft.prototype._updateScript=function(){return this.setScript(ox.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures())),this};Ft.prototype._createSignatures=function(){return Wr.map(Wr.filter(this.signatures,function(e){return!Wr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Ft.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Ft.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Ft.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Ft.prototype.countSignatures=function(){return Wr.reduce(this.signatures,function(e,t){return e+!!t},0)};Ft.prototype.publicKeysWithoutSignature=function(){var e=this;return Wr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Ft.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,Mp.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ft.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 kp({signature:kc.fromTxFormat(a),publicKey:o,prevTxId:t.prevTxId,outputIndex:t.outputIndex,inputIndex:r,sigtype:kc.SIGHASH_ALL});f.signature.nhashtype=f.sigtype;var l=Mp.verify(e,f.signature,f.publicKey,f.inputIndex,t.output.script);return l?(s=f,!1):!0}),s||null})};Ft.SIGNATURE_SIZE=73;Ft.prototype._estimateSize=function(){var e=1+this.threshold*Ft.SIGNATURE_SIZE;return Cc.BASE_SIZE+K6(e).toBuffer().length+e};sx.exports=Ft});var hx=B((aq,lx)=>{"use strict";g();var zr=at(),G6=ls(),Lc=cs(),V6=jn(),za=We(),Cp=Gr(),ux=fr(),fx=Ii(),cx=ds(),W6=Pr(),z6=ja();function kt(e,t,r,n){Lc.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 W6(o)),this.redeemScript=Cp.buildMultisigOut(this.publicKeys,r),za.checkState(Cp.buildScriptHashOut(this.redeemScript).equals(this.output.script),"Provided public keys don't hash to the provided output"),this.publicKeyIndex={},zr.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)}G6(kt,Lc);kt.prototype.toObject=function(){var e=Lc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=zr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};kt.prototype._deserializeSignatures=function(e){return zr.map(e,function(t){if(t)return new cx(t)})};kt.prototype._serializeSignatures=function(){return zr.map(this.signatures,function(e){if(e)return e.toObject()})};kt.prototype.getSignatures=function(e,t,r,n){za.checkState(this.output instanceof V6),n=n||ux.SIGHASH_ALL|ux.SIGHASH_FORKID;var i=this,o=[];return zr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new cx({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:fx.sign(e,t,n,r,i.redeemScript,i.output.satoshisBN),sigtype:n}))}),o};kt.prototype.addSignature=function(e,t){return za.checkState(!this.isFullySigned(),"All needed signatures have already been added"),za.checkArgument(!zr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),za.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};kt.prototype._updateScript=function(){return this.setScript(Cp.buildP2SHMultisigIn(this.publicKeys,this.threshold,this._createSignatures(),{cachedMultisig:this.redeemScript})),this};kt.prototype._createSignatures=function(){return zr.map(zr.filter(this.signatures,function(e){return!zr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};kt.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};kt.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};kt.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};kt.prototype.countSignatures=function(){return zr.reduce(this.signatures,function(e,t){return e+!!t},0)};kt.prototype.publicKeysWithoutSignature=function(){var e=this;return zr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};kt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,fx.verify(e,t.signature,t.publicKey,t.inputIndex,this.redeemScript,this.output.satoshisBN)};kt.SIGNATURE_SIZE=73;kt.PUBKEY_SIZE=34;kt.prototype._estimateSize=function(){var e=this.publicKeys.length*kt.PUBKEY_SIZE,t=this.threshold*kt.SIGNATURE_SIZE,r=3+e,n=r<=75?1:r<=255?2:3,i=t+1+n+r;return Lc.BASE_SIZE+z6(i).toBuffer().length+i};lx.exports=kt});var Dc=B((fq,ps)=>{g();ps.exports=cs();ps.exports.PublicKey=Q1();ps.exports.PublicKeyHash=ix();ps.exports.MultiSig=ax();ps.exports.MultiSigScriptHash=hx()});var Ii=B((lq,mx)=>{"use strict";g();var Y6=Lt(),dr=fr(),Ya=Gr(),$6=jn(),Z6=qa(),$a=fs(),dx=Ar(),Uc=nr(),px=Ka(),Lp=We(),Dp=Fc(),Ai=at(),gx=d.Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),X6="ffffffffffffffff",J6=Dp.SCRIPT_ENABLE_SIGHASH_FORKID,Q6=function(e,t,r,n,i){var o=e.inputs[r];Lp.checkArgument(i instanceof dx,"For ForkId=0 signatures, satoshis or complete input must be provided");function s(F){var V=new $a;Ai.each(F.inputs,function(ue){V.writeReverse(ue.prevTxId),V.writeUInt32LE(ue.outputIndex)});var z=V.toBuffer(),Q=Uc.sha256sha256(z);return Q}function a(F){var V=new $a;Ai.each(F.inputs,function(ue){V.writeUInt32LE(ue.sequenceNumber)});var z=V.toBuffer(),Q=Uc.sha256sha256(z);return Q}function f(F,V){var z=new $a;Ai.isUndefined(V)?Ai.each(F.outputs,function(ee){ee.toBufferWriter(z)}):F.outputs[V].toBufferWriter(z);var Q=z.toBuffer(),ue=Uc.sha256sha256(Q);return ue}var l=d.Buffer.alloc(32),m=d.Buffer.alloc(32),y=d.Buffer.alloc(32),p=e&&e._sighashMidstates;t&dr.SIGHASH_ANYONECANPAY||(p?(p.prevouts||(p.prevouts=s(e)),l=p.prevouts):l=s(e)),!(t&dr.SIGHASH_ANYONECANPAY)&&(t&31)!==dr.SIGHASH_SINGLE&&(t&31)!==dr.SIGHASH_NONE&&(p?(p.sequence||(p.sequence=a(e)),m=p.sequence):m=a(e)),(t&31)!==dr.SIGHASH_SINGLE&&(t&31)!==dr.SIGHASH_NONE?p?(p.outputsAll||(p.outputsAll=f(e)),y=p.outputsAll):y=f(e):(t&31)===dr.SIGHASH_SINGLE&&r<e.outputs.length&&(y=f(e,r));var S=new $a;S.writeInt32LE(e.version),S.write(l),S.write(m),S.writeReverse(o.prevTxId),S.writeUInt32LE(o.outputIndex);var O=n.toBuffer();S.writeVarintNum(O.length),S.write(O),S.writeUInt64LEBN(i);var M=o.sequenceNumber;S.writeUInt32LE(M),S.write(y),S.writeUInt32LE(e.nLockTime),S.writeUInt32LE(t>>>0);var U=S.toBuffer();return U},yx=function(t,r,n,i,o,s){var a=Fp(),f=Dc();Ai.isUndefined(s)&&(s=J6);var l=a.shallowCopy(t);if(i instanceof Ya||(i=new Ya(i)),s&Dp.SCRIPT_ENABLE_REPLAY_PROTECTION){var m=r>>8,y=16711680|m^57005;r=y<<8|r&255}if(r&dr.SIGHASH_FORKID&&!(r&dr.SIGHASH_CHRONICLE)&&s&Dp.SCRIPT_ENABLE_SIGHASH_FORKID)return Q6(l,r,n,i,o);i=new Ya(i),i.removeCodeseparators();var p;for(p=0;p<l.inputs.length;p++)l.inputs[p]=new f(l.inputs[p]).setScript(Ya.empty());if(l.inputs[n]=new f(l.inputs[n]).setScript(i),(r&31)===dr.SIGHASH_NONE||(r&31)===dr.SIGHASH_SINGLE)for(p=0;p<l.inputs.length;p++)p!==n&&(l.inputs[p].sequenceNumber=0);if((r&31)===dr.SIGHASH_NONE)l.outputs=[];else if((r&31)===dr.SIGHASH_SINGLE){if(n>=l.outputs.length)return gx;for(l.outputs.length=n+1,p=0;p<n;p++)l.outputs[p]=new $6({satoshis:dx.fromBuffer(Y6.Buffer.from(X6,"hex")),script:Ya.empty()})}r&dr.SIGHASH_ANYONECANPAY&&(l.inputs=[l.inputs[n]]);var S=new $a().write(l.toBuffer()).writeInt32LE(r).toBuffer();return S},Up=function(t,r,n,i,o,s){var a=yx(t,r,n,i,o,s);if(a.compare(gx)===0)return a;var f=Uc.sha256sha256(a);return f=new Z6(f).readReverse(),f};function eC(e,t,r,n,i,o,s){var a=Up(e,r,n,i,o,s),f=px.sign(a,t,"little").set({nhashtype:r});return f}function tC(e,t,r,n,i,o,s){Lp.checkArgument(!Ai.isUndefined(e)),Lp.checkArgument(!Ai.isUndefined(t)&&!Ai.isUndefined(t.nhashtype));var a=Up(e,t.nhashtype,n,i,o,s);return px.verify(a,t,r,"little")}mx.exports={sighashPreimage:yx,sighash:Up,sign:eC,verify:tC}});var qp=B((dq,bx)=>{"use strict";g();var Vn=at(),qc=We(),vx=vr(),rC=Gr(),nC=uo();function Wn(e){if(!(this instanceof Wn))return new Wn(e);qc.checkArgument(Vn.isObject(e),"Must provide an object from where to extract data");var t=e.address?new nC(e.address):void 0,r=e.txid?e.txid:e.txId;if(!r||!vx.isHexaString(r)||r.length>64)throw new Error("Invalid TXID in object",e);var n=Vn.isUndefined(e.vout)?e.outputIndex:e.vout;if(!Vn.isNumber(n))throw new Error("Invalid outputIndex, received "+n);qc.checkArgument(!Vn.isUndefined(e.scriptPubKey)||!Vn.isUndefined(e.script),"Must provide the scriptPubKey for that output!");var i=new rC(e.scriptPubKey||e.script);qc.checkArgument(!Vn.isUndefined(e.amount)||!Vn.isUndefined(e.satoshis),"Must provide an amount for the output");var o=Vn.isUndefined(e.amount)?e.satoshis:Math.round(e.amount*1e8);qc.checkArgument(Vn.isNumber(o),"Amount must be a number"),vx.defineImmutable(this,{address:t,txId:r,outputIndex:n,script:i,satoshis:o})}Wn.prototype.inspect=function(){return"<UnspentOutput: "+this.txId+":"+this.outputIndex+", satoshis: "+this.satoshis+", address: "+this.address+">"};Wn.prototype.toString=function(){return this.txId+":"+this.outputIndex};Wn.fromObject=function(e){return new Wn(e)};Wn.prototype.toObject=Wn.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))}};bx.exports=Wn});var Fp=B((gq,Ox)=>{"use strict";g();var me=at(),zt=We(),iC=Lt(),Ht=ii(),Sx=vr(),wx=qa(),oC=fs(),_x=ja(),Ex=nr(),jc=fr(),xx=Ii(),sC=uo(),Ix=qp(),qt=Dc(),aC=qt.PublicKeyHash,uC=qt.PublicKey,fC=qt.MultiSigScriptHash,cC=qt.MultiSig,Yr=jn(),yn=Gr(),lC=fo(),Hc=Ar(),hC=Fc(),dC=hC.SCRIPT_ENABLE_SIGHASH_FORKID;function Z(e){if(!(this instanceof Z))return new Z(e);if(this.inputs=[],this.outputs=[],this._inputAmount=void 0,this._outputAmount=void 0,e){if(e instanceof Z)return Z.shallowCopy(e);if(Sx.isHexa(e))this.fromString(e);else if(d.Buffer.isBuffer(e))this.fromBuffer(e);else if(me.isObject(e))this.fromObject(e);else throw new Ht.InvalidArgument("Must provide an object or string to deserialize a transaction")}else this._newTransaction()}var pC=1,gC=0,yC=1e6;Z.DUST_AMOUNT=546;Z.FEE_SECURITY_MARGIN=150;Z.MAX_MONEY=21e6*1e8;Z.NLOCKTIME_BLOCKHEIGHT_LIMIT=5e8;Z.NLOCKTIME_MAX_VALUE=4294967295;Z.FEE_PER_KB=500;Z.CHANGE_OUTPUT_MAX_SIZE=62;Z.shallowCopy=function(e){var t=new Z(e.toBuffer());return t};var Ax={configurable:!1,enumerable:!0,get:function(){return this._hash=new wx(this._getHash()).readReverse().toString("hex"),this._hash}};Object.defineProperty(Z.prototype,"hash",Ax);Object.defineProperty(Z.prototype,"id",Ax);var Hp={configurable:!1,enumerable:!0,get:function(){return this._getInputAmount()}};Object.defineProperty(Z.prototype,"inputAmount",Hp);Hp.get=function(){return this._getOutputAmount()};Object.defineProperty(Z.prototype,"outputAmount",Hp);Z.prototype._getHash=function(){return Ex.sha256sha256(this.toBuffer())};Z.prototype.serialize=function(e){return e===!0||e&&e.disableAll?this.uncheckedSerialize():this.checkedSerialize(e)};Z.prototype.uncheckedSerialize=Z.prototype.toString=function(){return this.toBuffer().toString("hex")};Z.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()};Z.prototype.invalidSatoshis=function(){for(var e=!1,t=0;t<this.outputs.length;t++)this.outputs[t].invalidSatoshis()&&(e=!0);return e};Z.prototype.getSerializationError=function(e){if(e=e||{},this.invalidSatoshis())return new Ht.Transaction.InvalidSatoshis;var t=this._getUnspentValue(),r;return t<0?e.disableMoreOutputThanInput||(r=new Ht.Transaction.InvalidOutputAmountSum):r=this._hasFeeError(e,t),r||this._hasDustOutputs(e)||this._isMissingSignatures(e)};Z.prototype._hasFeeError=function(e,t){if(!me.isUndefined(this._fee)&&this._fee!==t)return new Ht.Transaction.FeeError.Different("Unspent value is "+t+" but specified fee is "+this._fee);if(!e.disableLargeFees){var r=Math.floor(Z.FEE_SECURITY_MARGIN*this._estimateFee());if(t>r)return this._missingChange()?new Ht.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided"):new Ht.Transaction.FeeError.TooLarge("expected less than "+r+" but got "+t)}};Z.prototype._missingChange=function(){return!this._changeScript};Z.prototype._hasDustOutputs=function(e){if(!e.disableDustOutputs){var t,r;for(t in this.outputs)if(r=this.outputs[t],r.satoshis<Z.DUST_AMOUNT&&!r.script.isDataOut()&&!r.script.isSafeDataOut())return new Ht.Transaction.DustOutputs}};Z.prototype._isMissingSignatures=function(e){if(!e.disableIsFullySigned&&!this.isFullySigned())return new Ht.Transaction.MissingSignatures};Z.prototype.inspect=function(){return"<Transaction: "+this.uncheckedSerialize()+">"};Z.prototype.toBuffer=function(){var e=new oC;return this.toBufferWriter(e).toBuffer()};Z.prototype.toBufferWriter=function(e){return e.writeInt32LE(this.version),e.writeVarintNum(this.inputs.length),me.each(this.inputs,function(t){t.toBufferWriter(e)}),e.writeVarintNum(this.outputs.length),me.each(this.outputs,function(t){t.toBufferWriter(e)}),e.writeUInt32LE(this.nLockTime),e};Z.prototype.fromBuffer=function(e){var t=new wx(e);return this.fromBufferReader(t)};Z.prototype.fromBufferReader=function(e){zt.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=qt.fromBufferReader(e);this.inputs.push(i)}for(n=e.readVarintNum(),t=0;t<n;t++)this.outputs.push(Yr.fromBufferReader(e));return this.nLockTime=e.readUInt32LE(),this};Z.prototype.toObject=Z.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()),me.isUndefined(this._changeIndex)||(n.changeIndex=this._changeIndex),me.isUndefined(this._fee)||(n.fee=this._fee),n};Z.prototype.fromObject=function(t){zt.checkArgument(me.isObject(t)||t instanceof Z);var r=this,n;return t instanceof Z?n=t.toObject():n=t,me.each(n.inputs,function(i){if(!i.output||!i.output.script){r.uncheckedAddInput(new qt(i));return}var o=new yn(i.output.script),s;if(o.isPublicKeyHashOut())s=new qt.PublicKeyHash(i);else if(o.isScriptHashOut()&&i.publicKeys&&i.threshold)s=new qt.MultiSigScriptHash(i,i.publicKeys,i.threshold,i.signatures);else if(o.isPublicKeyOut())s=new qt.PublicKey(i);else throw new Ht.Transaction.Input.UnsupportedScript(i.output.script);r.addInput(s)}),me.each(n.outputs,function(i){r.addOutput(new Yr(i))}),n.changeIndex&&(this._changeIndex=n.changeIndex),n.changeScript&&(this._changeScript=new yn(n.changeScript)),n.fee&&(this._fee=n.fee),this.nLockTime=n.nLockTime,this.version=n.version,this._checkConsistency(t),this};Z.prototype._checkConsistency=function(e){me.isUndefined(this._changeIndex)||(zt.checkState(this._changeScript,"Change script is expected."),zt.checkState(this.outputs[this._changeIndex],"Change index points to undefined output."),zt.checkState(this.outputs[this._changeIndex].script.toString()===this._changeScript.toString(),"Change output has an unexpected script.")),e&&e.hash&&zt.checkState(e.hash===this.hash,"Hash in object does not match transaction hash.")};Z.prototype.lockUntilDate=function(e){if(zt.checkArgument(e),me.isNumber(e)&&e<Z.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Ht.Transaction.LockTimeTooEarly;me.isDate(e)&&(e=e.getTime()/1e3);for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===qt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=qt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Z.prototype.lockUntilBlockHeight=function(e){if(zt.checkArgument(me.isNumber(e)),e>=Z.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Ht.Transaction.BlockHeightTooHigh;if(e<0)throw new Ht.Transaction.NLockTimeOutOfRange;for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===qt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=qt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Z.prototype.getLockTime=function(){return this.nLockTime?this.nLockTime<Z.NLOCKTIME_BLOCKHEIGHT_LIMIT?this.nLockTime:new Date(1e3*this.nLockTime):null};Z.prototype.fromString=function(e){this.fromBuffer(iC.Buffer.from(e,"hex"))};Z.prototype._newTransaction=function(){this.version=pC,this.nLockTime=gC};Z.prototype.from=function(e,t,r){if(me.isArray(e)){var n=this;return me.each(e,function(o){n.from(o,t,r)}),this}var i=me.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)};Z.prototype._fromNonP2SH=function(e){var t;e=new Ix(e),e.script.isPublicKeyHashOutPrefix()?t=aC:e.script.isPublicKeyOut()?t=uC:t=qt,this.addInput(new t({output:new Yr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:yn.empty()}))};Z.prototype._fromMultisigUtxo=function(e,t,r){zt.checkArgument(r<=t.length,"Number of required signatures must be greater than the number of public keys");var n;if(e=new Ix(e),e.script.isMultisigOut())n=cC;else if(e.script.isScriptHashOut())n=fC;else throw new Ht.Transaction.Input.UnsupportedScript(e.script.toString());this.addInput(new n({output:new Yr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:yn.empty()},t,r))};Z.prototype.addInput=function(e,t,r){if(zt.checkArgumentType(e,qt,"input"),!e.output&&(me.isUndefined(t)||me.isUndefined(r)))throw new Ht.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis");return!e.output&&t&&!me.isUndefined(r)&&(t=t instanceof yn?t:new yn(t),zt.checkArgumentType(r,"number","satoshis"),e.output=new Yr({script:t,satoshis:r})),this.uncheckedAddInput(e)};Z.prototype.uncheckedAddInput=function(e){return zt.checkArgumentType(e,qt,"input"),this.inputs.push(e),this._inputAmount=void 0,this._updateChangeOutput(),this};Z.prototype.hasAllUtxoInfo=function(){return me.every(this.inputs.map(function(e){return!!e.output}))};Z.prototype.fee=function(e){return zt.checkArgument(me.isNumber(e),"amount must be a number"),this._fee=e,this._updateChangeOutput(),this};Z.prototype.feePerKb=function(e){return zt.checkArgument(me.isNumber(e),"amount must be a number"),this._feePerKb=e,this._updateChangeOutput(),this};Z.prototype.change=function(e){return zt.checkArgument(e,"address is required"),this._changeScript=yn.fromAddress(e),this._updateChangeOutput(),this};Z.prototype.getChangeOutput=function(){return me.isUndefined(this._changeIndex)?null:this.outputs[this._changeIndex]};Z.prototype.to=function(e,t){if(me.isArray(e)){var r=this;return me.each(e,function(n){r.to(n.address,n.satoshis)}),this}return zt.checkArgument(Sx.isNaturalNumber(t),"Amount is expected to be a positive integer"),this.addOutput(new Yr({script:yn(new sC(e)),satoshis:t})),this};Z.prototype.addData=function(e){return this.addOutput(new Yr({script:yn.buildDataOut(e),satoshis:0})),this};Z.prototype.addSafeData=function(e){return this.addOutput(new Yr({script:yn.buildSafeDataOut(e),satoshis:0})),this};Z.prototype.addOutput=function(e){return zt.checkArgumentType(e,Yr,"output"),this._addOutput(e),this._updateChangeOutput(),this};Z.prototype.clearOutputs=function(){return this.outputs=[],this._clearSignatures(),this._outputAmount=void 0,this._changeIndex=void 0,this._updateChangeOutput(),this};Z.prototype._addOutput=function(e){this.outputs.push(e),this._outputAmount=void 0};Z.prototype._getOutputAmount=function(){if(me.isUndefined(this._outputAmount)){var e=this;this._outputAmount=0,me.each(this.outputs,function(t){e._outputAmount+=t.satoshis})}return this._outputAmount};Z.prototype._getInputAmount=function(){if(me.isUndefined(this._inputAmount)){var e=this;this._inputAmount=0,me.each(this.inputs,function(t){if(me.isUndefined(t.output))throw new Ht.Transaction.Input.MissingPreviousOutput;e._inputAmount+=t.output.satoshis})}return this._inputAmount};Z.prototype._updateChangeOutput=function(){if(this._changeScript){this._clearSignatures(),me.isUndefined(this._changeIndex)||this._removeOutput(this._changeIndex),this._changeIndex=this.outputs.length,this._addOutput(new Yr({script:this._changeScript,satoshis:0}));var e=this._getUnspentValue(),t=this.getFee(),r=e-t;this._removeOutput(this._changeIndex),this._changeIndex=void 0,r>=Z.DUST_AMOUNT&&(this._changeIndex=this.outputs.length,this._addOutput(new Yr({script:this._changeScript,satoshis:r})))}};Z.prototype.getFee=function(){return this.isCoinbase()?0:me.isUndefined(this._fee)?this._changeScript?this._estimateFee():this._getUnspentValue():this._fee};Z.prototype._estimateFee=function(){var e=this._estimateSize();return Math.ceil(e/1e3*(this._feePerKb||Z.FEE_PER_KB))};Z.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Z.prototype._clearSignatures=function(){me.each(this.inputs,function(e){e.clearSignatures!==qt.prototype.clearSignatures&&e.clearSignatures()})};Z.prototype._estimateSize=function(){var e=8;return e+=_x(this.inputs.length).toBuffer().length,e+=_x(this.outputs.length).toBuffer().length,me.each(this.inputs,function(t){e+=t._estimateSize()}),me.each(this.outputs,function(t){e+=t.getSize()}),e};Z.prototype._removeOutput=function(e){var t=this.outputs[e];this.outputs=me.without(this.outputs,t),this._outputAmount=void 0};Z.prototype.removeOutput=function(e){this._removeOutput(e),this._updateChangeOutput()};Z.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};Z.prototype.shuffleOutputs=function(){return this.sortOutputs(me.shuffle)};Z.prototype.sortOutputs=function(e){var t=e(this.outputs);return this._newOutputOrder(t)};Z.prototype.sortInputs=function(e){return this.inputs=e(this.inputs),this._clearSignatures(),this};Z.prototype._newOutputOrder=function(e){var t=this.outputs.length!==e.length||me.difference(this.outputs,e).length!==0;if(t)throw new Ht.Transaction.InvalidSorting;if(!me.isUndefined(this._changeIndex)){var r=this.outputs[this._changeIndex];this._changeIndex=e.indexOf(r)}return this.outputs=e,this};Z.prototype.removeInput=function(e,t){var r;if(!t&&me.isNumber(e)?r=e:r=me.findIndex(this.inputs,function(i){return i.prevTxId.toString("hex")===e&&i.outputIndex===t}),r<0||r>=this.inputs.length)throw new Ht.Transaction.InvalidIndex(r,this.inputs.length);var n=this.inputs[r];this.inputs=me.without(this.inputs,n),this._inputAmount=void 0,this._updateChangeOutput()};Z.prototype.sign=function(e,t){zt.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var r=this;if(me.isArray(e))return me.each(e,function(i){r.sign(i,t)}),this;var n=!this._sighashMidstates;n&&(this._sighashMidstates={});try{me.each(this.getSignatures(e,t),function(i){r.applySignature(i)})}finally{n&&delete this._sighashMidstates}return this};Z.prototype.getSignatures=function(e,t){e=new lC(e),t=t||jc.SIGHASH_ALL|jc.SIGHASH_FORKID;var r=this,n=[],i=Ex.sha256ripemd160(e.publicKey.toBuffer()),o=!this._sighashMidstates;o&&(this._sighashMidstates={});try{me.each(this.inputs,function(a,f){me.each(a.getSignatures(r,e,f,t,i),function(l){n.push(l)})})}finally{o&&delete this._sighashMidstates}return n};Z.prototype.applySignature=function(e){return this.inputs[e.inputIndex].addSignature(this,e),this};Z.prototype.isFullySigned=function(){return me.each(this.inputs,function(e){if(e.isFullySigned===qt.prototype.isFullySigned)throw new Ht.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction")}),me.every(me.map(this.inputs,function(e){return e.isFullySigned()}))};Z.prototype.isValidSignature=function(e){var t=this;if(this.inputs[e.inputIndex].isValidSignature===qt.prototype.isValidSignature)throw new Ht.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)};Z.prototype.verifySignature=function(e,t,r,n,i,o){return xx.verify(this,e,t,r,n,i,o)};Z.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 Hc(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 Hc(Z.MAX_MONEY,10)))return"transaction txout "+t+" greater than MAX_MONEY";if(e=e.add(r._satoshisBN),e.gt(new Hc(Z.MAX_MONEY)))return"transaction txout "+t+" total output greater than MAX_MONEY"}if(this.toBuffer().length>yC)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(!me.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};Z.prototype.isCoinbase=function(){return this.inputs.length===1&&this.inputs[0].isNull()};Z.prototype.sighash=function(e,t,r,n,i){t=t||jc.SIGHASH_ALL|jc.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 Hc(o.output.satoshis)),i=i||dC,xx.sighash(this,t,e,r,n,i)};Ox.exports=Z});var jp=B((mq,co)=>{g();co.exports=Fp();co.exports.Input=Dc();co.exports.Output=jn();co.exports.UnspentOutput=qp();co.exports.Signature=ds();co.exports.Sighash=Ii()});var Fc=B((bq,Nx)=>{"use strict";g();var Kc=at(),Gc=Ip(),k=vp(),le=Ar(),Za=nr(),zn=fr(),Kp=Pr();function Rx(e){return e.map(function(t){return d.Buffer.isBuffer(t)?d.Buffer.from(t):t})}var R=function e(t){if(!(this instanceof e))return new e(t);t?(this.initialize(),this.set(t)):this.initialize()};R.prototype._verifyCore=function(e,t,r,n,i,o){var s=jp();if(Kc.isUndefined(r)&&(r=new s),Kc.isUndefined(n)&&(n=0),Kc.isUndefined(i)&&(i=R.currentConsensusFlags(),o||(i&=~R.SCRIPT_ENABLE_SIGHASH_FORKID)),i&R.SCRIPT_ENABLE_SIGHASH_FORKID&&(i|=R.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&R.SCRIPT_UTXO_AFTER_CHRONICLE)!==0&&(i&R.SCRIPT_UTXO_AFTER_GENESIS)===0)return this.errstr="SCRIPT_ERR_INVALID_FLAGS",!1;if((i&R.SCRIPT_VERIFY_SIGPUSHONLY)!==0){var f=(i&R.SCRIPT_CHRONICLE)!==0,l=(i&R.SCRIPT_GENESIS)!==0&&!f||f&&Bx(i,r);if(l&&!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1}if(!this.evaluate())return!1;var m=(i&R.SCRIPT_VERIFY_P2SH)!==0&&(i&R.SCRIPT_UTXO_AFTER_GENESIS)===0;m&&(a=this.stack.slice());var y=this.stack;if(this.initialize(),this.set({script:t,stack:y,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 p=this.stack[this.stack.length-1];if(!R.castToBool(p))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK",!1;if(m&&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 S=a[a.length-1],O=Gc.fromBuffer(S);if(a.pop(),this.initialize(),this.set({script:O,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(!R.castToBool(a[a.length-1]))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK",!1}if((i&R.SCRIPT_VERIFY_CLEANSTACK)!==0){if((i&R.SCRIPT_VERIFY_P2SH)===0)return this.errstr="SCRIPT_ERR_INVALID_FLAGS",!1;if(this.enforceNonMalleability()&&this.stack.length!==1)return this.errstr="SCRIPT_ERR_CLEANSTACK",!1}return!0};Nx.exports=R;R.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};R.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};R.true=d.Buffer.from([1]);R.false=d.Buffer.from([]);R.MAX_SCRIPT_ELEMENT_SIZE=520;R.MAXIMUM_ELEMENT_SIZE=4;R.MAX_OPS_PER_SCRIPT=500;R.MAX_SCRIPT_SIZE=1e4;R.UNLIMITED=Number.MAX_SAFE_INTEGER;R.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS=75e4;R.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE=32e6;R.MAX_PUBKEYS_PER_MULTISIG_AFTER_GENESIS=4294967295;R.MAX_STACK_SIZE=1e3;R.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS=R.UNLIMITED;R.STACK_MEMORY_USAGE_POLICY=100*1024*1024;R.STACK_ELEMENT_OVERHEAD=32;R.LOCKTIME_THRESHOLD=5e8;R.LOCKTIME_THRESHOLD_BN=new le(R.LOCKTIME_THRESHOLD);R.useGenesisLimits=function(e){return e=e||2147483647,R.MAX_SCRIPT_ELEMENT_SIZE=e,R.MAX_OPS_PER_SCRIPT=e,R.MAX_SCRIPT_SIZE=e,R};R.getLimits=function(){return{maxScriptElementSize:R.MAX_SCRIPT_ELEMENT_SIZE,maximumElementSize:R.MAXIMUM_ELEMENT_SIZE,maxOpsPerScript:R.MAX_OPS_PER_SCRIPT,maxScriptSize:R.MAX_SCRIPT_SIZE}};R.setLimits=function(e){return e=e||{},e.maxScriptElementSize!=null&&(R.MAX_SCRIPT_ELEMENT_SIZE=e.maxScriptElementSize),e.maximumElementSize!=null&&(R.MAXIMUM_ELEMENT_SIZE=e.maximumElementSize),e.maxOpsPerScript!=null&&(R.MAX_OPS_PER_SCRIPT=e.maxOpsPerScript),e.maxScriptSize!=null&&(R.MAX_SCRIPT_SIZE=e.maxScriptSize),R};R.SCRIPT_VERIFY_NONE=0;R.SCRIPT_VERIFY_P2SH=1;R.SCRIPT_VERIFY_STRICTENC=2;R.SCRIPT_VERIFY_DERSIG=4;R.SCRIPT_VERIFY_LOW_S=8;R.SCRIPT_VERIFY_NULLDUMMY=16;R.SCRIPT_VERIFY_SIGPUSHONLY=32;R.SCRIPT_VERIFY_MINIMALDATA=64;R.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=128;R.SCRIPT_VERIFY_CLEANSTACK=256;R.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=512;R.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1024;R.SCRIPT_VERIFY_MINIMALIF=8192;R.SCRIPT_VERIFY_NULLFAIL=16384;R.SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE=32768;R.SCRIPT_ENABLE_SIGHASH_FORKID=65536;R.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;R.SCRIPT_ENABLE_MONOLITH_OPCODES=2048;R.SCRIPT_ENABLE_MAGNETIC_OPCODES=4096;R.SCRIPT_GENESIS=1<<18;R.SCRIPT_UTXO_AFTER_GENESIS=1<<19;R.SCRIPT_ENABLE_CHRONICLE=1<<20;R.SCRIPT_CHRONICLE=R.SCRIPT_ENABLE_CHRONICLE;R.SCRIPT_UTXO_AFTER_CHRONICLE=1<<21;R.CHRONICLE_ACTIVATION_HEIGHT=943816;R.ERA_SENSITIVE_ERRORS={SCRIPT_ERR_PUSH_SIZE:{cap:"stack element size (capped at 520 bytes pre-Genesis, unbounded after)",lifts:R.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPT_SIZE:{cap:"total script size (capped at 10,000 bytes pre-Genesis, unbounded after)",lifts:R.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_OP_COUNT:{cap:"opcode count (capped at 201 pre-Genesis, unbounded after)",lifts:R.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:R.SCRIPT_UTXO_AFTER_GENESIS|R.SCRIPT_UTXO_AFTER_CHRONICLE}};R.ERA_FLAGS=R.SCRIPT_GENESIS|R.SCRIPT_UTXO_AFTER_GENESIS|R.SCRIPT_ENABLE_CHRONICLE|R.SCRIPT_UTXO_AFTER_CHRONICLE;R.eraDiagnostics=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_ERA_HINT==="1");var Gp=!1;R.prototype._eraDiagnose=function(e){if(e!==void 0){var t=R.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 wi({actual:e,expected:t,message:r,operator:i,stackStartFn:n});throw a.generatedMessage=s,a}}ut.match=function e(t,r,n){b1(t,r,n,e,"match")};ut.doesNotMatch=function e(t,r,n){b1(t,r,n,e,"doesNotMatch")};function _1(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];h1.apply(void 0,[_1,t.length].concat(t))}ut.strict=n6(_1,ut,{equal:ut.strictEqual,deepEqual:ut.deepStrictEqual,notEqual:ut.notStrictEqual,notDeepEqual:ut.notDeepStrictEqual});ut.strict.strict=ut.strict});var qa=B((B5,E1)=>{"use strict";g();var Fa=at(),w1=We(),as=Ar(),vt=function e(t){if(!(this instanceof e))return new e(t);if(!Fa.isUndefined(t))if(d.Buffer.isBuffer(t))this.set({buf:t});else if(Fa.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(Fa.isObject(t)){var n=t;this.set(n)}else throw new TypeError("Unrecognized argument for BufferReader")};vt.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this};vt.prototype.eof=function(){return this.pos>=this.buf.length};vt.prototype.finished=vt.prototype.eof;vt.prototype.read=function(e){w1.checkArgument(!Fa.isUndefined(e),"Must specify a length");var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,t};vt.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e};vt.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e};vt.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e};vt.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e};vt.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readInt32LE=function(){var e=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,e};vt.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=as.fromBuffer(e);return this.pos=this.pos+8,t};vt.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 as(r);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);n=new as(i,10,"le")}return this.pos=this.pos+8,n};vt.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}};vt.prototype.readVarLengthBuffer=function(){var e=this.readVarintNum(),t=this.read(e);return w1.checkState(t.length===e,"Invalid length while reading varlength buffer. Expected to read: "+e+" and read "+t.length),t};vt.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)}};vt.prototype.readVarintBN=function(){var e=this.readUInt8();switch(e){case 253:return new as(this.readUInt16LE());case 254:return new as(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new as(e)}};vt.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};vt.prototype.readReverse=function(e){Fa.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()};E1.exports=vt});var vp=B((M5,x1)=>{"use strict";g();var us=at(),Ha=We(),o6=vr();function Fe(e){if(!(this instanceof Fe))return new Fe(e);var t;if(us.isNumber(e))t=e;else if(us.isString(e))t=Fe.map[e];else throw new TypeError('Unrecognized num type: "'+typeof e+'" for Opcode');return o6.defineImmutable(this,{num:t}),this}Fe.fromBuffer=function(e){return Ha.checkArgument(d.Buffer.isBuffer(e)),new Fe(+("0x"+e.toString("hex")))};Fe.fromNumber=function(e){return Ha.checkArgument(us.isNumber(e)),new Fe(e)};Fe.fromString=function(e){Ha.checkArgument(us.isString(e));var t=Fe.map[e];if(typeof t>"u")throw new TypeError("Invalid opcodestr");return new Fe(t)};Fe.prototype.toHex=function(){return this.num.toString(16)};Fe.prototype.toBuffer=function(){return d.Buffer.from(this.toHex(),"hex")};Fe.prototype.toNumber=function(){return this.num};Fe.prototype.toString=function(){var e=Fe.reverseMap[this.num];if(typeof e>"u")throw new Error("Opcode does not have a string representation");return e};Fe.smallInt=function(e){return Ha.checkArgument(us.isNumber(e),"Invalid Argument: n should be number"),Ha.checkArgument(e>=0&&e<=16,"Invalid Argument: n must be between 0 and 16"),e===0?Fe("OP_0"):new Fe(Fe.map.OP_1+e-1)};Fe.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};Fe.reverseMap=[];for(mp in Fe.map)Fe.reverseMap[Fe.map[mp]]=mp;var mp;us.extend(Fe,Fe.map);Fe.isSmallIntOp=function(e){return e instanceof Fe&&(e=e.toNumber()),e===Fe.map.OP_0||e>=Fe.map.OP_1&&e<=Fe.map.OP_16};Fe.prototype.inspect=function(){return"<Opcode: "+this.toString()+", hex: "+this.toHex()+", decimal: "+this.num+">"};x1.exports=Fe});var fr=B((C5,A1)=>{"use strict";g();var oo=Ar(),s6=at(),ur=We(),a6=vr(),Ce=function e(t,r){if(!(this instanceof e))return new e(t,r);if(t instanceof oo)this.set({r:t,s:r});else if(t){var n=t;this.set(n)}};Ce.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};Ce.fromCompact=function(e){ur.checkArgument(d.Buffer.isBuffer(e),"Argument is expected to be a Buffer");var t=new Ce,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 ur.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),ur.checkArgument(i.length===32,new Error("r must be 32 bytes")),ur.checkArgument(o.length===32,new Error("s must be 32 bytes")),t.compressed=r,t.i=n,t.r=oo.fromBuffer(i),t.s=oo.fromBuffer(o),t};Ce.fromDER=Ce.fromBuffer=function(e,t){var r=Ce.parseDER(e,t),n=new Ce;return n.r=r.r,n.s=r.s,n};Ce.fromTxFormat=function(e){var t=e.readUInt8(e.length-1),r=e.slice(0,e.length-1),n=Ce.fromDER(r,!1);return n.nhashtype=t,n};Ce.fromString=function(e){var t=d.Buffer.from(e,"hex");return Ce.fromDER(t)};function I1(e,t){ur.checkArgument(t.length>0,new Error("Length of "+e+" is zero")),ur.checkArgument(!(t[0]&128),new Error("Value of "+e+" is negative")),ur.checkArgument(!(t.length>1&&t[0]===0&&!(t[1]&128)),new Error("Value of "+e+" is excessively padded"))}Ce.parseDER=function(e,t){ur.checkArgument(d.Buffer.isBuffer(e),new Error("DER formatted signature should be a buffer")),s6.isUndefined(t)&&(t=!0);var r=e[0];ur.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=e[1],i=e.slice(2).length;ur.checkArgument(!t||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=e[2];ur.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var s=e[3],a=e.slice(4,4+s),f=oo.fromBuffer(a),l=e[4]===0;ur.checkArgument(s===a.length,new Error("Length of r incorrect"));var m=e[4+s+0];ur.checkArgument(m===2,new Error("Integer byte for s should be 0x02"));var y=e[4+s+1],p=e.slice(4+s+2,4+s+2+y),S=oo.fromBuffer(p),O=e[4+s+2]===0;ur.checkArgument(y===p.length,new Error("Length of s incorrect"));var M=4+s+2+y;ur.checkArgument(n===M-2,new Error("Length of signature incorrect")),t&&(I1("r",a),I1("s",p));var U={header:r,length:n,rheader:o,rlength:s,rneg:l,rbuf:a,r:f,sheader:m,slength:y,sneg:O,sbuf:p,s:S};return U};Ce.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])};Ce.prototype.toBuffer=Ce.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,y=48,p=d.Buffer.concat([d.Buffer.from([y,f,l,s]),i,d.Buffer.from([m,a]),o]);return p};Ce.prototype.toString=function(){var e=this.toDER();return e.toString("hex")};Ce.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))};Ce.prototype.hasLowS=function(){return!(this.s.lt(new oo(1))||this.s.gt(new oo("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};Ce.prototype.hasDefinedHashtype=function(){if(!a6.isNaturalNumber(this.nhashtype))return!1;var e=this.nhashtype&31;return!(e<Ce.SIGHASH_ALL||e>Ce.SIGHASH_SINGLE)};Ce.prototype.toTxFormat=function(){var e=this.toDER(),t=d.Buffer.alloc(1);return t.writeUInt8(this.nhashtype,0),d.Buffer.concat([e,t])};Ce.SIGHASH_ALL=1;Ce.SIGHASH_NONE=2;Ce.SIGHASH_SINGLE=3;Ce.SIGHASH_CHRONICLE=32;Ce.SIGHASH_FORKID=64;Ce.SIGHASH_ANYONECANPAY=128;Ce.prototype.isCanonical=function(){var e=gi(),t=e.getN().shrn(1);return this.s.lte(t)};Ce.prototype.toCanonical=function(){if(this.isCanonical())return new Ce({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var e=gi(),t=e.getN(),r=t.sub(this.s);return new Ce({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};Ce.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=gi(),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};Ce.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};Ce.prototype.applySecurityPatches=function(){var e=gi(),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};A1.exports=Ce});var wp=B((D5,R1)=>{"use strict";g();var bp=Object.create(null),_p=[],Sp=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_DEPRECATION_WARNINGS==="1");function O1(e,t){if(!e||typeof e.what!="string"||e.what==="")throw new TypeError(t+"() requires { what: string }")}function u6(e){var t="[@smartledger/bsv] "+e.what+" is deprecated";return e.since&&(t+=" since "+e.since),t+=".",e.why&&(t+=" "+e.why.charAt(0).toUpperCase()+e.why.slice(1)+"."),e.use&&(t+=" Use "+e.use+" instead."),t+=e.removeIn?" It will be removed in "+e.removeIn+".":" A removal version has not been set; it will not be removed in a 9.x release.",t}function Hn(e){if(!e||!e.what)throw new TypeError("deprecate() requires { what }");if(bp[e.what])return!1;bp[e.what]=!0;var t=u6(e);return _p.push({what:e.what,since:e.since||null,removeIn:e.removeIn||null,use:e.use||null,message:t}),Sp&&console.warn(t),!0}Hn.fn=function(e,t){if(typeof e!="function")throw new TypeError("deprecate.fn() requires a function");O1(t,"deprecate.fn");var r=function(){return Hn(t),e.apply(this,arguments)};return Object.defineProperty(r,"name",{value:e.name,configurable:!0}),Object.defineProperty(r,"length",{value:e.length,configurable:!0}),r.__wrapped=e,r.__deprecation=t,r};Hn.property=function(e,t,r,n){O1(n,"deprecate.property");var i,o=!1;return Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get:function(){return Hn(n),o||(i=r(),o=!0),i}}),e};Hn.fired=function(){return _p.slice()};Hn.setEnabled=function(e){Sp=!!e};Hn.isEnabled=function(){return Sp};Hn.reset=function(){bp=Object.create(null),_p.length=0};R1.exports=Hn});var Ip=B((F5,N1)=>{"use strict";g();var f6=Aa(),jr=uo(),c6=qa(),Ep=nr(),X=vp(),ao=Pr(),so=fr(),T1=Ea(),lt=We(),Le=at(),xp=ii(),l6=wp(),P1=Lt(),h6=vr(),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 jr)return e.fromAddress(t);if(t instanceof e)return e.fromBuffer(t.toBuffer());if(Le.isString(t))return e.fromString(t);Le.isObject(t)&&Le.isArray(t.chunks)&&this.set(t)};q.prototype.set=function(e){return lt.checkArgument(Le.isObject(e)),lt.checkArgument(Le.isArray(e.chunks)),this.chunks=e.chunks,this};q.fromBuffer=function(e){var t=new q;t.chunks=[];for(var r=new c6(e);!r.finished();)try{var n=r.readUInt8(),i,o;n>0&&n<X.OP_PUSHDATA1?(i=n,t.chunks.push({buf:r.read(i),len:i,opcodenum:n})):n===X.OP_PUSHDATA1?(i=r.readUInt8(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===X.OP_PUSHDATA2?(i=r.readUInt16LE(),o=r.read(i),t.chunks.push({buf:o,len:i,opcodenum:n})):n===X.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 xp.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<X.OP_PUSHDATA1?t+=Tc(n.buf):i===X.OP_PUSHDATA1?t+=1+Tc(n.buf):i===X.OP_PUSHDATA2?t+=2+Tc(n.buf):i===X.OP_PUSHDATA4&&(t+=4+Tc(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<X.OP_PUSHDATA1?s+=n.buf.copy(o,s):i===X.OP_PUSHDATA1?(s=o.writeUInt8(n.len,s),s+=n.buf.copy(o,s)):i===X.OP_PUSHDATA2?(s=o.writeUInt16LE(n.len,s),s+=n.buf.copy(o,s)):i===X.OP_PUSHDATA4&&(s=o.writeUInt32LE(n.len,s),s+=n.buf.copy(o,s)));return o};function Tc(e){if(!d.Buffer.isBuffer(e))throw new f6.AssertionError({message:"chunk data must be a Buffer",actual:e,expected:"Buffer",operator:"isBuffer"});return e.length}function B1(e){if(/^0x[0-9a-fA-F]{2}$/.test(e)){var t=parseInt(e.slice(2),16);return t>X.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=X(i),s=o.toNumber(),a=B1(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=X.OP_1NEGATE,t.chunks.push({opcodenum:s}),n=n+1;else if(Le.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<X.OP_PUSHDATA1?s=l:l<Math.pow(2,8)?s=X.OP_PUSHDATA1:l<Math.pow(2,16)?s=X.OP_PUSHDATA2:l<Math.pow(2,32)&&(s=X.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};var d6=/^(?:[0-9a-fA-F]{2})*$/;q.fromHex=function(e){return typeof e=="string"&&!d6.test(e)&&l6({what:"Script.fromHex() with a string that is not whole hex",since:"9.17.0",removeIn:"10.0.0",why:"Buffer.from() stops at the first character it cannot decode, so the script is silently truncated",use:"a round-trip check, Script.fromHex(h).toHex() === h.toLowerCase()"}),new q(P1.Buffer.from(e,"hex"))};q.fromString=function(e){if(h6.isHexa(e)||e.length===0)return new q(P1.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=X(i),s=o.toNumber(),a=B1(i);if(a!==void 0)t.chunks.push({opcodenum:a}),n=n+1;else if(Le.isUndefined(s))if(s=parseInt(i),s>0&&s<X.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===X.OP_PUSHDATA1||s===X.OP_PUSHDATA2||s===X.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===X.OP_PUSHDATA1||r===X.OP_PUSHDATA2||r===X.OP_PUSHDATA4;!n&&s&&(i=i+" "+X(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 X.reverseMap[r]<"u")n?r===0?i=i+" 0":r===79?i=i+" -1":i=i+" "+X(r).toString():i=i+" "+X(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===X.OP_DUP&&this.chunks[1].opcodenum===X.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===X.OP_EQUALVERIFY&&this.chunks[4].opcodenum===X.OP_CHECKSIG)};q.prototype.isPublicKeyHashOutPrefix=function(){return!!(this.chunks.length>=5&&this.chunks[0].opcodenum===X.OP_DUP&&this.chunks[1].opcodenum===X.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===X.OP_EQUALVERIFY&&this.chunks[4].opcodenum===X.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 lt.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output"),this.chunks[0].buf};q.prototype.getPublicKeyHash=function(){return lt.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===X.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 ao.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]===X.OP_HASH160&&e[1]===20&&e[e.length-1]===X.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 xp.Script.InvalidBuffer)return!1;throw i}var n=r.classify();return n!==q.types.UNKNOWN};q.prototype.isMultisigOut=function(){return this.chunks.length>3&&X.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return e.buf&&d.Buffer.isBuffer(e.buf)})&&X.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===X.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)&&so.isTxDER(e.buf)})};q.prototype.isDataOut=function(){var e=this.chunks.length>=1&&this.chunks[0].opcodenum===X.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!==X.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 Le.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 Le.every(this.chunks,function(e){return e.opcodenum<=X.OP_16||e.opcodenum===X.OP_PUSHDATA1||e.opcodenum===X.OP_PUSHDATA2||e.opcodenum===X.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(lt.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 X)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 X?r=e.toNumber():r=X(e).toNumber(),this._insertAtPosition({opcodenum:r},t),this};q.prototype._addBuffer=function(e,t){var r,n=e.length;if(n>=0&&n<X.OP_PUSHDATA1)r=n;else if(n<Math.pow(2,8))r=X.OP_PUSHDATA1;else if(n<Math.pow(2,16))r=X.OP_PUSHDATA2;else if(n<Math.pow(2,32))r=X.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!==X.OP_CODESEPARATOR&&e.push(this.chunks[t]);return this.chunks=e,this};q.buildMultisigOut=function(e,t,r){lt.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(X.smallInt(t)),e=Le.map(e,ao);var i=e;r.noSorting||(i=e.map(a=>a.toString("hex")).sort().map(a=>new ao(a)));for(var o=0;o<i.length;o++){var s=i[o];n.add(s.toBuffer())}return n.add(X.smallInt(e.length)),n.add(X.OP_CHECKMULTISIG),n};q.buildMultisigIn=function(e,t,r,n){lt.checkArgument(Le.isArray(e)),lt.checkArgument(Le.isNumber(t)),lt.checkArgument(Le.isArray(r)),n=n||{};var i=new q;return i.add(X.OP_0),Le.each(r,function(o){lt.checkArgument(d.Buffer.isBuffer(o),"Signatures must be an array of Buffers"),i.add(o)}),i};q.buildP2SHMultisigIn=function(e,t,r,n){lt.checkArgument(Le.isArray(e)),lt.checkArgument(Le.isNumber(t)),lt.checkArgument(Le.isArray(r)),n=n||{};var i=new q;return i.add(X.OP_0),Le.each(r,function(o){lt.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){lt.checkArgument(!Le.isUndefined(e)),lt.checkArgument(e instanceof ao||e instanceof jr||Le.isString(e)),e instanceof ao?e=e.toAddress():Le.isString(e)&&(e=new jr(e));var t=new q;return t.add(X.OP_DUP).add(X.OP_HASH160).add(e.hashBuffer).add(X.OP_EQUALVERIFY).add(X.OP_CHECKSIG),t._network=e.network,t};q.buildPublicKeyOut=function(e){lt.checkArgument(e instanceof ao);var t=new q;return t.add(e.toBuffer()).add(X.OP_CHECKSIG),t};q.buildDataOut=function(e,t){lt.checkArgument(Le.isUndefined(e)||Le.isString(e)||Le.isArray(e)||d.Buffer.isBuffer(e));var r=e;Le.isArray(r)||(r=[e]);var n=new q;n.add(X.OP_RETURN);for(let i of r)lt.checkArgument(Le.isUndefined(i)||Le.isString(i)||d.Buffer.isBuffer(i)),Le.isString(i)&&(i=d.Buffer.from(i,t)),Le.isUndefined(i)||n.add(i);return n};q.buildSafeDataOut=function(e,t){var r=q.buildDataOut(e,t),n=new q;return n.add(X.OP_FALSE),n.add(r),n};q.buildScriptHashOut=function(e){lt.checkArgument(e instanceof q||e instanceof jr&&e.isPayToScriptHash());var t=new q;return t.add(X.OP_HASH160).add(e instanceof jr?e.hashBuffer:Ep.sha256ripemd160(e.toBuffer())).add(X.OP_EQUAL),t._network=e._network||e.network,t};q.buildPublicKeyIn=function(e,t){lt.checkArgument(e instanceof so||d.Buffer.isBuffer(e)),lt.checkArgument(Le.isUndefined(t)||Le.isNumber(t)),e instanceof so&&(e=e.toBuffer());var r=new q;return r.add(d.Buffer.concat([e,d.Buffer.from([(t||so.SIGHASH_ALL)&255])])),r};q.buildPublicKeyHashIn=function(e,t,r){lt.checkArgument(t instanceof so||d.Buffer.isBuffer(t)),lt.checkArgument(Le.isUndefined(r)||Le.isNumber(r)),t instanceof so&&(t=t.toBuffer());var n=new q().add(d.Buffer.concat([t,d.Buffer.from([(r||so.SIGHASH_ALL)&255])])).add(new ao(e).toBuffer());return n};q.empty=function(){return new q};q.prototype.toScriptHashOut=function(){return q.buildScriptHashOut(this)};q.fromAddress=function(e){if(e=jr(e),e.isPayToScriptHash())return q.buildScriptHashOut(e);if(e.isPayToPublicKeyHash())return q.buildPublicKeyHashOut(e);throw new xp.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=jr.PayToScriptHash;else if(this.isPublicKeyHashOut())e.hashBuffer=this.getData(),e.type=jr.PayToPublicKeyHash;else return!1;return e};q.prototype._getInputAddressInfo=function(){var e={};if(this.isPublicKeyHashIn())e.hashBuffer=Ep.sha256ripemd160(this.chunks[1].buf),e.type=jr.PayToPublicKeyHash;else if(this.isScriptHashIn())e.hashBuffer=Ep.sha256ripemd160(this.chunks[this.chunks.length-1].buf),e.type=jr.PayToScriptHash;else return!1;return e};q.prototype.toAddress=function(e){var t=this.getAddressInfo();return t?(t.network=T1.get(e)||this._network||T1.defaultNetwork,new jr(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&&p6(i))){var o=q({chunks:[i]}).toBuffer();t.equals(o)&&(this.chunks.splice(n,1),n--)}}return this};function p6(e){var t=e.opcodenum;if(typeof t!="number"||!Number.isInteger(t)||t<0||t>255)return!1;if(!e.buf||t>X.OP_PUSHDATA4)return!0;if(!d.Buffer.isBuffer(e.buf))return!1;var r=e.len;return t===X.OP_PUSHDATA1?Number.isInteger(r)&&r>=0&&r<=255:t===X.OP_PUSHDATA2?Number.isInteger(r)&&r>=0&&r<=65535:t===X.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===X.OP_0:r.length===1&&r[0]>=1&&r[0]<=16?n===X.OP_1+(r[0]-1):r.length===1&&r[0]===129?n===X.OP_1NEGATE:r.length<=75?n===r.length:r.length<=255?n===X.OP_PUSHDATA1:r.length<=65535?n===X.OP_PUSHDATA2:!0:!0};q.prototype._decodeOP_N=function(e){if(e===X.OP_0)return 0;if(e>=X.OP_1&&e<=X.OP_16)return e-(X.OP_1-1);throw new Error("Invalid opcode: "+JSON.stringify(e))};q.prototype.getSignatureOperationsCount=function(e){e=Le.isUndefined(e)?!0:e;var t=this,r=0,n=X.OP_INVALIDOPCODE;return Le.each(t.chunks,function(o){var s=o.opcodenum;s===X.OP_CHECKSIG||s===X.OP_CHECKSIGVERIFY?r++:(s===X.OP_CHECKMULTISIG||s===X.OP_CHECKMULTISIGVERIFY)&&(e&&n>=X.OP_1&&n<=X.OP_16?r+=t._decodeOP_N(n):r+=20),n=s}),r};N1.exports=q});var fs=B((H5,k1)=>{"use strict";g();var M1=Aa(),bt=function e(t){if(!(this instanceof e))return new e(t);this.bufLen=0,t?this.set(t):this.bufs=[]};bt.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};bt.prototype.toBuffer=function(){return this.concat()};bt.prototype.concat=function(){return d.Buffer.concat(this.bufs,this.bufLen)};bt.prototype.write=function(e){return M1(d.Buffer.isBuffer(e)),this.bufs.push(e),this.bufLen+=e.length,this};bt.prototype.writeReverse=function(e){return M1(d.Buffer.isBuffer(e)),this.bufs.push(d.Buffer.from(e).reverse()),this.bufLen+=e.length,this};bt.prototype.writeUInt8=function(e){var t=d.Buffer.alloc(1);return t.writeUInt8(e,0),this.write(t),this};bt.prototype.writeUInt16BE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16BE(e,0),this.write(t),this};bt.prototype.writeUInt16LE=function(e){var t=d.Buffer.alloc(2);return t.writeUInt16LE(e,0),this.write(t),this};bt.prototype.writeUInt32BE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32BE(e,0),this.write(t),this};bt.prototype.writeInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeInt32LE(e,0),this.write(t),this};bt.prototype.writeUInt32LE=function(e){var t=d.Buffer.alloc(4);return t.writeUInt32LE(e,0),this.write(t),this};bt.prototype.writeUInt64BEBN=function(e){var t=e.toBuffer({size:8});return this.write(t),this};bt.prototype.writeUInt64LEBN=function(e){var t=e.toBuffer({size:8});return this.writeReverse(t),this};bt.prototype.writeVarintNum=function(e){var t=bt.varintBufNum(e);return this.write(t),this};bt.prototype.writeVarintBN=function(e){var t=bt.varintBufBN(e);return this.write(t),this};bt.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};bt.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 bt;n.writeUInt8(255),n.writeUInt64LEBN(e),t=n.concat()}return t};k1.exports=bt});var ja=B((K5,D1)=>{"use strict";g();var C1=fs(),L1=qa(),g6=Ar(),Kr=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 g6){var n=t;this.fromBN(n)}else if(t){var i=t;this.set(i)}};Kr.prototype.set=function(e){return this.buf=e.buf||this.buf,this};Kr.prototype.fromString=function(e){return this.set({buf:d.Buffer.from(e,"hex")}),this};Kr.prototype.toString=function(){return this.buf.toString("hex")};Kr.prototype.fromBuffer=function(e){return this.buf=e,this};Kr.prototype.fromBufferReader=function(e){return this.buf=e.readVarintBuf(),this};Kr.prototype.fromBN=function(e){return this.buf=C1().writeVarintBN(e).concat(),this};Kr.prototype.fromNumber=function(e){return this.buf=C1().writeVarintNum(e).concat(),this};Kr.prototype.toBuffer=function(){return this.buf};Kr.prototype.toBN=function(){return L1(this.buf).readVarintBN()};Kr.prototype.toNumber=function(){return L1(this.buf).readVarintNum()};D1.exports=Kr});var jn=B((V5,F1)=>{"use strict";g();var Pc=at(),Ap=Ar(),U1=Lt(),Bc=vr(),y6=fs(),m6=ja(),Op=Gr(),Rp=We(),v6=ii(),b6=9007199254740991;function Wt(e){if(!(this instanceof Wt))return new Wt(e);if(Pc.isObject(e))if(this.satoshis=e.satoshis,d.Buffer.isBuffer(e.script))this._scriptBuffer=e.script;else{var t;Pc.isString(e.script)&&Bc.isHexa(e.script)?t=U1.Buffer.from(e.script,"hex"):t=e.script,this.setScript(t)}else throw new TypeError("Unrecognized argument for Output")}Object.defineProperty(Wt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this._script?this._script:(this.setScriptFromBuffer(this._scriptBuffer),this._script)}});Object.defineProperty(Wt.prototype,"satoshis",{configurable:!1,enumerable:!0,get:function(){return this._satoshis},set:function(e){e instanceof Ap?(this._satoshisBN=e,this._satoshis=e.toNumber()):Pc.isString(e)?(this._satoshis=parseInt(e),this._satoshisBN=Ap.fromNumber(this._satoshis)):(Rp.checkArgument(Bc.isNaturalNumber(e),"Output satoshis is not a natural number"),this._satoshisBN=Ap.fromNumber(e),this._satoshis=e),Rp.checkState(Bc.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});Wt.prototype.invalidSatoshis=function(){return this._satoshis>b6?"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(Wt.prototype,"satoshisBN",{configurable:!1,enumerable:!0,get:function(){return this._satoshisBN},set:function(e){this._satoshisBN=e,this._satoshis=e.toNumber(),Rp.checkState(Bc.isNaturalNumber(this._satoshis),"Output satoshis is not a natural number")}});Wt.prototype.toObject=Wt.prototype.toJSON=function(){var t={satoshis:this.satoshis};return t.script=this._scriptBuffer.toString("hex"),t};Wt.fromObject=function(e){return new Wt(e)};Wt.prototype.setScriptFromBuffer=function(e){this._scriptBuffer=e;try{this._script=Op.fromBuffer(this._scriptBuffer),this._script._isOutput=!0}catch(t){if(t instanceof v6.Script.InvalidBuffer)this._script=null;else throw t}};Wt.prototype.setScript=function(e){if(e instanceof Op)this._scriptBuffer=e.toBuffer(),this._script=e,this._script._isOutput=!0;else if(Pc.isString(e))this._script=Op.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};Wt.prototype.inspect=function(){var e;return this.script?e=this.script.inspect():e=this._scriptBuffer.toString("hex"),"<Output ("+this.satoshis+" sats) "+e+">"};Wt.fromBufferReader=function(e){var t={};t.satoshis=e.readUInt64LEBN();var r=e.readVarintNum();return r!==0?t.script=e.read(r):t.script=U1.Buffer.from([]),new Wt(t)};Wt.prototype.toBufferWriter=function(e){e||(e=new y6),e.writeUInt64LEBN(this._satoshisBN);var t=this._scriptBuffer;return e.writeVarintNum(t.length),e.write(t),e};Wt.prototype.getSize=function(){var e=this.script.toBuffer().length,t=m6(e).toBuffer().length;return 8+t+e};F1.exports=Wt});var Ka=B((z5,q1)=>{"use strict";g();var br=Ar(),gn=gi(),_6=fr(),S6=Pr(),w6=sa(),Ei=nr(),E6=at(),Tp=We(),tt=function e(t){if(!(this instanceof e))return new e(t);t&&this.set(t)};Object.defineProperty(tt.prototype,"k",{get:function(){return this._k},set:function(e){this._k=e,this._kFresh=!0},enumerable:!0,configurable:!0});tt.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=fr();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};tt.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()};tt.prototype.calci=function(){for(var e=0;e<4;e++){this.sig.i=e;var t;try{t=this.toPublicKey()}catch{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")};tt.fromString=function(e){var t=JSON.parse(e);return new tt(t)};tt.prototype.randomK=function(){var e=gn.getN(),t;do t=br.fromBuffer(w6.getRandomBuffer(32));while(!(t.lt(e)&&t.gt(br.Zero)));return this.k=t,this};tt.prototype.deterministicK=function(e){E6.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=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0]),n,i]),r),t=Ei.sha256hmac(t,r),r=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([1]),n,i]),r),t=Ei.sha256hmac(t,r),t=Ei.sha256hmac(t,r);for(var o=br.fromBuffer(t),s=gn.getN(),a=0;a<e||!(o.lt(s)&&o.gt(br.Zero));a++)r=Ei.sha256hmac(d.Buffer.concat([t,d.Buffer.from([0])]),r),t=Ei.sha256hmac(t,r),t=Ei.sha256hmac(t,r),o=br.fromBuffer(t);return this.k=o,this};tt.prototype.toPublicKey=function(){var e=this.sig.i;Tp.checkArgument(e===0||e===1||e===2||e===3,new Error("i must be equal to 0, 1, 2, or 3"));var t=br.fromBuffer(this.hashbuf),r=this.sig.r,n=this.sig.s,i=e&1,o=e>>1,s=gn.getN(),a=gn.getG(),f=o?r.add(s):r,l=gn.fromX(i,f),m=l.mul(s);if(!m.isInfinity())throw new Error("nR is not a valid curve point");var y=t.neg().umod(s),p=r.invm(s),S=l.mul(n).add(a.mul(y)).mul(p),O=S6.fromPoint(S,this.sig.compressed);return O};tt.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=gn.getN();try{if(e.lte(br.Zero)||t.lte(br.Zero)||e.gte(r)||t.gte(r))return"r and s not in range";var n=br.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=gn.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}};tt.toLowS=function(e){return e.gt(br.fromBuffer(d.Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=gn.getN().sub(e)),e};tt.prototype._findSignature=function(e,t){var r=gn.getN(),n=gn.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(br.Zero)<=0||f.cmp(br.Zero)<=0);return this._kFresh=!1,f=tt.toLowS(f),{s:f,r:a}};tt.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;Tp.checkState(e&&t&&r,new Error("invalid parameters")),Tp.checkState(d.Buffer.isBuffer(e)&&e.length===32,new Error("hashbuf must be a 32 byte buffer"));var n=br.fromBuffer(e,this.endian?{endian:this.endian}:void 0),i=this._findSignature(r,n);return i.compressed=this.pubkey.compressed,this.sig=new _6(i),this};tt.prototype.signRandomK=function(){return this.randomK(),this.sign()};tt.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)};tt.prototype.verify=function(){return this.verified=!this.sigError(),this.verified};tt.prototype.verifyBool=function(){return this.verify()===!0};tt.sign=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).sign().sig};tt.signWithCalcI=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).sign().calci().sig};tt.signRandomK=function(e,t,r){return tt().set({hashbuf:e,endian:r,privkey:t}).signRandomK().sig};tt.verify=function(e,t,r,n){return tt().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify()};q1.exports=tt});var cs=B(($5,G1)=>{"use strict";g();var xi=at(),x6=We(),Ga=ii(),I6=fs(),Pp=Lt(),j1=vr(),Nc=Gr(),A6=Ii(),H1=jn(),Mc=4294967295,O6=Mc-2,K1=Mc,R6=Mc-1;function rt(e){if(!(this instanceof rt))return new rt(e);if(e)return this._fromObject(e)}rt.MAXINT=Mc;rt.DEFAULT_SEQNUMBER=K1;rt.DEFAULT_LOCKTIME_SEQNUMBER=R6;rt.DEFAULT_RBF_SEQNUMBER=O6;rt.BASE_SIZE=40;Object.defineProperty(rt.prototype,"script",{configurable:!1,enumerable:!0,get:function(){return this.isNull()?null:(this._script||(this._script=new Nc(this._scriptBuffer),this._script._isInput=!0),this._script)}});rt.fromObject=function(e){x6.checkArgument(xi.isObject(e));var t=new rt;return t._fromObject(e)};rt.prototype._fromObject=function(e){var t;if(xi.isString(e.prevTxId)&&j1.isHexa(e.prevTxId)?t=Pp.Buffer.from(e.prevTxId,"hex"):t=e.prevTxId,this.output=e.output?e.output instanceof H1?e.output:new H1(e.output):void 0,this.prevTxId=t||e.txidbuf,this.outputIndex=xi.isUndefined(e.outputIndex)?e.txoutnum:e.outputIndex,this.sequenceNumber=xi.isUndefined(e.sequenceNumber)?xi.isUndefined(e.seqnum)?K1:e.seqnum:e.sequenceNumber,xi.isUndefined(e.script)&&xi.isUndefined(e.scriptBuffer))throw new Ga.Transaction.Input.MissingScript;return this.setScript(e.scriptBuffer||e.script),this};rt.prototype.toObject=rt.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};rt.fromBufferReader=function(e){var t=new rt;return t.prevTxId=e.readReverse(32),t.outputIndex=e.readUInt32LE(),t._scriptBuffer=e.readVarLengthBuffer(),t.sequenceNumber=e.readUInt32LE(),t};rt.prototype.toBufferWriter=function(e){e||(e=new I6),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};rt.prototype.setScript=function(e){if(this._script=null,e instanceof Nc)this._script=e,this._script._isInput=!0,this._scriptBuffer=e.toBuffer();else if(e===null)this._script=Nc.empty(),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(j1.isHexa(e))this._scriptBuffer=Pp.Buffer.from(e,"hex");else if(xi.isString(e))this._script=new Nc(e),this._script._isInput=!0,this._scriptBuffer=this._script.toBuffer();else if(d.Buffer.isBuffer(e))this._scriptBuffer=Pp.Buffer.from(e);else throw new TypeError("Invalid argument type: script");return this};rt.prototype.getSignatures=function(){throw new Ga.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: "+JSON.stringify(this))};rt.prototype.isFullySigned=function(){throw new Ga.AbstractMethodInvoked("Input#isFullySigned")};rt.prototype.isFinal=function(){return this.sequenceNumber===rt.MAXINT};rt.prototype.addSignature=function(){throw new Ga.AbstractMethodInvoked("Input#addSignature")};rt.prototype.clearSignatures=function(){throw new Ga.AbstractMethodInvoked("Input#clearSignatures")};rt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,A6.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};rt.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};rt.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};G1.exports=rt});var ls=B((X5,V1)=>{"use strict";g();V1.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}});var ds=B((Q5,Y1)=>{"use strict";g();var hs=at(),Br=We(),T6=ls(),W1=vr(),z1=Pr(),P6=ii(),Va=fr();function Vr(e){if(!(this instanceof Vr))return new Vr(e);if(e instanceof Vr)return e;if(hs.isObject(e))return this._fromObject(e);throw new P6.InvalidArgument("TransactionSignatures must be instantiated from an object")}T6(Vr,Va);Vr.prototype._fromObject=function(e){return this._checkObjectArgs(e),this.publicKey=new z1(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 Va?e.signature:d.Buffer.isBuffer(e.signature)?Va.fromBuffer(e.signature):Va.fromString(e.signature),this.sigtype=e.sigtype,this};Vr.prototype._checkObjectArgs=function(e){Br.checkArgument(z1(e.publicKey),"publicKey"),Br.checkArgument(!hs.isUndefined(e.inputIndex),"inputIndex"),Br.checkArgument(!hs.isUndefined(e.outputIndex),"outputIndex"),Br.checkState(hs.isNumber(e.inputIndex),"inputIndex must be a number"),Br.checkState(hs.isNumber(e.outputIndex),"outputIndex must be a number"),Br.checkArgument(e.signature,"signature"),Br.checkArgument(e.prevTxId,"prevTxId"),Br.checkState(e.signature instanceof Va||d.Buffer.isBuffer(e.signature)||W1.isHexa(e.signature),"signature must be a buffer or hexa value"),Br.checkState(d.Buffer.isBuffer(e.prevTxId)||W1.isHexa(e.prevTxId),"prevTxId must be a buffer or hexa value"),Br.checkArgument(e.sigtype,"sigtype"),Br.checkState(hs.isNumber(e.sigtype),"sigtype must be a number")};Vr.prototype.toObject=Vr.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}};Vr.fromObject=function(e){return Br.checkArgument(e),new Vr(e)};Y1.exports=Vr});var Q1=B((tq,J1)=>{"use strict";g();var B6=ls(),Z1=We(),Bp=cs(),N6=jn(),M6=Ii(),X1=Gr(),$1=fr(),k6=ds();function Kn(){Bp.apply(this,arguments)}B6(Kn,Bp);Kn.prototype.getSignatures=function(e,t,r,n){Z1.checkState(this.output instanceof N6),n=n||$1.SIGHASH_ALL|$1.SIGHASH_FORKID;var i=t.toPublicKey();return i.toString()===this.output.script.getPublicKey().toString("hex")?[new k6({publicKey:i,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:M6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Kn.prototype.addSignature=function(e,t){return Z1.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(X1.buildPublicKeyIn(t.signature.toDER(),t.sigtype)),this};Kn.prototype.clearSignatures=function(){return this.setScript(X1.empty()),this};Kn.prototype.isFullySigned=function(){return this.script.isPublicKeyIn()};Kn.SCRIPT_MAX_SIZE=74;Kn.prototype._estimateSize=function(){return Bp.BASE_SIZE+Kn.SCRIPT_MAX_SIZE};J1.exports=Kn});var ix=B((nq,nx)=>{"use strict";g();var C6=ls(),tx=We(),L6=nr(),Np=cs(),D6=jn(),U6=Ii(),rx=Gr(),ex=fr(),F6=ds();function Gn(){Np.apply(this,arguments)}C6(Gn,Np);Gn.prototype.getSignatures=function(e,t,r,n,i){tx.checkState(this.output instanceof D6),i=i||L6.sha256ripemd160(t.publicKey.toBuffer()),n=n||ex.SIGHASH_ALL|ex.SIGHASH_FORKID;var o=this.output.script.chunks[2]&&this.output.script.chunks[2].buf;return o&&i.equals(o)?[new F6({publicKey:t.publicKey,prevTxId:this.prevTxId,outputIndex:this.outputIndex,inputIndex:r,signature:U6.sign(e,t,n,r,this.output.script,this.output.satoshisBN),sigtype:n})]:[]};Gn.prototype.addSignature=function(e,t){return tx.checkState(this.isValidSignature(e,t),"Signature is invalid"),this.setScript(rx.buildPublicKeyHashIn(t.publicKey,t.signature.toDER(),t.sigtype)),this};Gn.prototype.clearSignatures=function(){return this.setScript(rx.empty()),this};Gn.prototype.isFullySigned=function(){return this.script.isPublicKeyHashIn()};Gn.SCRIPT_MAX_SIZE=108;Gn.prototype._estimateSize=function(){return Np.BASE_SIZE+Gn.SCRIPT_MAX_SIZE};nx.exports=Gn});var ax=B((oq,sx)=>{"use strict";g();var Wr=at(),q6=ls(),Cc=cs(),H6=jn(),Wa=We(),ox=Gr(),kc=fr(),Mp=Ii(),kp=ds(),j6=Pr(),K6=ja();function Ft(e,t,r,n){Cc.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 j6(o)),Wa.checkState(ox.buildMultisigOut(this.publicKeys,r).equals(this.output.script),"Provided public keys don't match to the provided output script"),this.publicKeyIndex={},Wr.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)}q6(Ft,Cc);Ft.prototype.toObject=function(){var e=Cc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=Wr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};Ft.prototype._deserializeSignatures=function(e){return Wr.map(e,function(t){if(t)return new kp(t)})};Ft.prototype._serializeSignatures=function(){return Wr.map(this.signatures,function(e){if(e)return e.toObject()})};Ft.prototype.getSignatures=function(e,t,r,n){Wa.checkState(this.output instanceof H6),n=n||kc.SIGHASH_ALL|kc.SIGHASH_FORKID;var i=this,o=[];return Wr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new kp({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:Mp.sign(e,t,n,r,i.output.script,i.output.satoshisBN),sigtype:n}))}),o};Ft.prototype.addSignature=function(e,t){return Wa.checkState(!this.isFullySigned(),"All needed signatures have already been added"),Wa.checkArgument(!Wr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),Wa.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};Ft.prototype._updateScript=function(){return this.setScript(ox.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures())),this};Ft.prototype._createSignatures=function(){return Wr.map(Wr.filter(this.signatures,function(e){return!Wr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};Ft.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};Ft.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};Ft.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};Ft.prototype.countSignatures=function(){return Wr.reduce(this.signatures,function(e,t){return e+!!t},0)};Ft.prototype.publicKeysWithoutSignature=function(){var e=this;return Wr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};Ft.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,Mp.verify(e,t.signature,t.publicKey,t.inputIndex,this.output.script,this.output.satoshisBN)};Ft.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 kp({signature:kc.fromTxFormat(a),publicKey:o,prevTxId:t.prevTxId,outputIndex:t.outputIndex,inputIndex:r,sigtype:kc.SIGHASH_ALL});f.signature.nhashtype=f.sigtype;var l=Mp.verify(e,f.signature,f.publicKey,f.inputIndex,t.output.script);return l?(s=f,!1):!0}),s||null})};Ft.SIGNATURE_SIZE=73;Ft.prototype._estimateSize=function(){var e=1+this.threshold*Ft.SIGNATURE_SIZE;return Cc.BASE_SIZE+K6(e).toBuffer().length+e};sx.exports=Ft});var hx=B((aq,lx)=>{"use strict";g();var zr=at(),G6=ls(),Lc=cs(),V6=jn(),za=We(),Cp=Gr(),ux=fr(),fx=Ii(),cx=ds(),W6=Pr(),z6=ja();function kt(e,t,r,n){Lc.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 W6(o)),this.redeemScript=Cp.buildMultisigOut(this.publicKeys,r),za.checkState(Cp.buildScriptHashOut(this.redeemScript).equals(this.output.script),"Provided public keys don't hash to the provided output"),this.publicKeyIndex={},zr.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)}G6(kt,Lc);kt.prototype.toObject=function(){var e=Lc.prototype.toObject.apply(this,arguments);return e.threshold=this.threshold,e.publicKeys=zr.map(this.publicKeys,function(t){return t.toString()}),e.signatures=this._serializeSignatures(),e};kt.prototype._deserializeSignatures=function(e){return zr.map(e,function(t){if(t)return new cx(t)})};kt.prototype._serializeSignatures=function(){return zr.map(this.signatures,function(e){if(e)return e.toObject()})};kt.prototype.getSignatures=function(e,t,r,n){za.checkState(this.output instanceof V6),n=n||ux.SIGHASH_ALL|ux.SIGHASH_FORKID;var i=this,o=[];return zr.each(this.publicKeys,function(s){s.toString()===t.publicKey.toString()&&o.push(new cx({publicKey:t.publicKey,prevTxId:i.prevTxId,outputIndex:i.outputIndex,inputIndex:r,signature:fx.sign(e,t,n,r,i.redeemScript,i.output.satoshisBN),sigtype:n}))}),o};kt.prototype.addSignature=function(e,t){return za.checkState(!this.isFullySigned(),"All needed signatures have already been added"),za.checkArgument(!zr.isUndefined(this.publicKeyIndex[t.publicKey.toString()]),"Signature has no matching public key"),za.checkState(this.isValidSignature(e,t)),this.signatures[this.publicKeyIndex[t.publicKey.toString()]]=t,this._updateScript(),this};kt.prototype._updateScript=function(){return this.setScript(Cp.buildP2SHMultisigIn(this.publicKeys,this.threshold,this._createSignatures(),{cachedMultisig:this.redeemScript})),this};kt.prototype._createSignatures=function(){return zr.map(zr.filter(this.signatures,function(e){return!zr.isUndefined(e)}),function(e){return d.Buffer.concat([e.signature.toDER(),d.Buffer.from([e.sigtype&255])])})};kt.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length),this._updateScript()};kt.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};kt.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};kt.prototype.countSignatures=function(){return zr.reduce(this.signatures,function(e,t){return e+!!t},0)};kt.prototype.publicKeysWithoutSignature=function(){var e=this;return zr.filter(this.publicKeys,function(t){return!e.signatures[e.publicKeyIndex[t.toString()]]})};kt.prototype.isValidSignature=function(e,t){return t.signature.nhashtype=t.sigtype,fx.verify(e,t.signature,t.publicKey,t.inputIndex,this.redeemScript,this.output.satoshisBN)};kt.SIGNATURE_SIZE=73;kt.PUBKEY_SIZE=34;kt.prototype._estimateSize=function(){var e=this.publicKeys.length*kt.PUBKEY_SIZE,t=this.threshold*kt.SIGNATURE_SIZE,r=3+e,n=r<=75?1:r<=255?2:3,i=t+1+n+r;return Lc.BASE_SIZE+z6(i).toBuffer().length+i};lx.exports=kt});var Dc=B((fq,ps)=>{g();ps.exports=cs();ps.exports.PublicKey=Q1();ps.exports.PublicKeyHash=ix();ps.exports.MultiSig=ax();ps.exports.MultiSigScriptHash=hx()});var Ii=B((lq,mx)=>{"use strict";g();var Y6=Lt(),dr=fr(),Ya=Gr(),$6=jn(),Z6=qa(),$a=fs(),dx=Ar(),Uc=nr(),px=Ka(),Lp=We(),Dp=Fc(),Ai=at(),gx=d.Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),X6="ffffffffffffffff",J6=Dp.SCRIPT_ENABLE_SIGHASH_FORKID,Q6=function(e,t,r,n,i){var o=e.inputs[r];Lp.checkArgument(i instanceof dx,"For ForkId=0 signatures, satoshis or complete input must be provided");function s(F){var V=new $a;Ai.each(F.inputs,function(ue){V.writeReverse(ue.prevTxId),V.writeUInt32LE(ue.outputIndex)});var z=V.toBuffer(),Q=Uc.sha256sha256(z);return Q}function a(F){var V=new $a;Ai.each(F.inputs,function(ue){V.writeUInt32LE(ue.sequenceNumber)});var z=V.toBuffer(),Q=Uc.sha256sha256(z);return Q}function f(F,V){var z=new $a;Ai.isUndefined(V)?Ai.each(F.outputs,function(ee){ee.toBufferWriter(z)}):F.outputs[V].toBufferWriter(z);var Q=z.toBuffer(),ue=Uc.sha256sha256(Q);return ue}var l=d.Buffer.alloc(32),m=d.Buffer.alloc(32),y=d.Buffer.alloc(32),p=e&&e._sighashMidstates;t&dr.SIGHASH_ANYONECANPAY||(p?(p.prevouts||(p.prevouts=s(e)),l=p.prevouts):l=s(e)),!(t&dr.SIGHASH_ANYONECANPAY)&&(t&31)!==dr.SIGHASH_SINGLE&&(t&31)!==dr.SIGHASH_NONE&&(p?(p.sequence||(p.sequence=a(e)),m=p.sequence):m=a(e)),(t&31)!==dr.SIGHASH_SINGLE&&(t&31)!==dr.SIGHASH_NONE?p?(p.outputsAll||(p.outputsAll=f(e)),y=p.outputsAll):y=f(e):(t&31)===dr.SIGHASH_SINGLE&&r<e.outputs.length&&(y=f(e,r));var S=new $a;S.writeInt32LE(e.version),S.write(l),S.write(m),S.writeReverse(o.prevTxId),S.writeUInt32LE(o.outputIndex);var O=n.toBuffer();S.writeVarintNum(O.length),S.write(O),S.writeUInt64LEBN(i);var M=o.sequenceNumber;S.writeUInt32LE(M),S.write(y),S.writeUInt32LE(e.nLockTime),S.writeUInt32LE(t>>>0);var U=S.toBuffer();return U},yx=function(t,r,n,i,o,s){var a=Fp(),f=Dc();Ai.isUndefined(s)&&(s=J6);var l=a.shallowCopy(t);if(i instanceof Ya||(i=new Ya(i)),s&Dp.SCRIPT_ENABLE_REPLAY_PROTECTION){var m=r>>8,y=16711680|m^57005;r=y<<8|r&255}if(r&dr.SIGHASH_FORKID&&!(r&dr.SIGHASH_CHRONICLE)&&s&Dp.SCRIPT_ENABLE_SIGHASH_FORKID)return Q6(l,r,n,i,o);i=new Ya(i),i.removeCodeseparators();var p;for(p=0;p<l.inputs.length;p++)l.inputs[p]=new f(l.inputs[p]).setScript(Ya.empty());if(l.inputs[n]=new f(l.inputs[n]).setScript(i),(r&31)===dr.SIGHASH_NONE||(r&31)===dr.SIGHASH_SINGLE)for(p=0;p<l.inputs.length;p++)p!==n&&(l.inputs[p].sequenceNumber=0);if((r&31)===dr.SIGHASH_NONE)l.outputs=[];else if((r&31)===dr.SIGHASH_SINGLE){if(n>=l.outputs.length)return gx;for(l.outputs.length=n+1,p=0;p<n;p++)l.outputs[p]=new $6({satoshis:dx.fromBuffer(Y6.Buffer.from(X6,"hex")),script:Ya.empty()})}r&dr.SIGHASH_ANYONECANPAY&&(l.inputs=[l.inputs[n]]);var S=new $a().write(l.toBuffer()).writeInt32LE(r).toBuffer();return S},Up=function(t,r,n,i,o,s){var a=yx(t,r,n,i,o,s);if(a.compare(gx)===0)return a;var f=Uc.sha256sha256(a);return f=new Z6(f).readReverse(),f};function eC(e,t,r,n,i,o,s){var a=Up(e,r,n,i,o,s),f=px.sign(a,t,"little").set({nhashtype:r});return f}function tC(e,t,r,n,i,o,s){Lp.checkArgument(!Ai.isUndefined(e)),Lp.checkArgument(!Ai.isUndefined(t)&&!Ai.isUndefined(t.nhashtype));var a=Up(e,t.nhashtype,n,i,o,s);return px.verify(a,t,r,"little")}mx.exports={sighashPreimage:yx,sighash:Up,sign:eC,verify:tC}});var qp=B((dq,bx)=>{"use strict";g();var Vn=at(),qc=We(),vx=vr(),rC=Gr(),nC=uo();function Wn(e){if(!(this instanceof Wn))return new Wn(e);qc.checkArgument(Vn.isObject(e),"Must provide an object from where to extract data");var t=e.address?new nC(e.address):void 0,r=e.txid?e.txid:e.txId;if(!r||!vx.isHexaString(r)||r.length>64)throw new Error("Invalid TXID in object",e);var n=Vn.isUndefined(e.vout)?e.outputIndex:e.vout;if(!Vn.isNumber(n))throw new Error("Invalid outputIndex, received "+n);qc.checkArgument(!Vn.isUndefined(e.scriptPubKey)||!Vn.isUndefined(e.script),"Must provide the scriptPubKey for that output!");var i=new rC(e.scriptPubKey||e.script);qc.checkArgument(!Vn.isUndefined(e.amount)||!Vn.isUndefined(e.satoshis),"Must provide an amount for the output");var o=Vn.isUndefined(e.amount)?e.satoshis:Math.round(e.amount*1e8);qc.checkArgument(Vn.isNumber(o),"Amount must be a number"),vx.defineImmutable(this,{address:t,txId:r,outputIndex:n,script:i,satoshis:o})}Wn.prototype.inspect=function(){return"<UnspentOutput: "+this.txId+":"+this.outputIndex+", satoshis: "+this.satoshis+", address: "+this.address+">"};Wn.prototype.toString=function(){return this.txId+":"+this.outputIndex};Wn.fromObject=function(e){return new Wn(e)};Wn.prototype.toObject=Wn.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))}};bx.exports=Wn});var Fp=B((gq,Ox)=>{"use strict";g();var me=at(),zt=We(),iC=Lt(),Ht=ii(),Sx=vr(),wx=qa(),oC=fs(),_x=ja(),Ex=nr(),jc=fr(),xx=Ii(),sC=uo(),Ix=qp(),qt=Dc(),aC=qt.PublicKeyHash,uC=qt.PublicKey,fC=qt.MultiSigScriptHash,cC=qt.MultiSig,Yr=jn(),yn=Gr(),lC=fo(),Hc=Ar(),hC=Fc(),dC=hC.SCRIPT_ENABLE_SIGHASH_FORKID;function Z(e){if(!(this instanceof Z))return new Z(e);if(this.inputs=[],this.outputs=[],this._inputAmount=void 0,this._outputAmount=void 0,e){if(e instanceof Z)return Z.shallowCopy(e);if(Sx.isHexa(e))this.fromString(e);else if(d.Buffer.isBuffer(e))this.fromBuffer(e);else if(me.isObject(e))this.fromObject(e);else throw new Ht.InvalidArgument("Must provide an object or string to deserialize a transaction")}else this._newTransaction()}var pC=1,gC=0,yC=1e6;Z.DUST_AMOUNT=546;Z.FEE_SECURITY_MARGIN=150;Z.MAX_MONEY=21e6*1e8;Z.NLOCKTIME_BLOCKHEIGHT_LIMIT=5e8;Z.NLOCKTIME_MAX_VALUE=4294967295;Z.FEE_PER_KB=500;Z.CHANGE_OUTPUT_MAX_SIZE=62;Z.shallowCopy=function(e){var t=new Z(e.toBuffer());return t};var Ax={configurable:!1,enumerable:!0,get:function(){return this._hash=new wx(this._getHash()).readReverse().toString("hex"),this._hash}};Object.defineProperty(Z.prototype,"hash",Ax);Object.defineProperty(Z.prototype,"id",Ax);var Hp={configurable:!1,enumerable:!0,get:function(){return this._getInputAmount()}};Object.defineProperty(Z.prototype,"inputAmount",Hp);Hp.get=function(){return this._getOutputAmount()};Object.defineProperty(Z.prototype,"outputAmount",Hp);Z.prototype._getHash=function(){return Ex.sha256sha256(this.toBuffer())};Z.prototype.serialize=function(e){return e===!0||e&&e.disableAll?this.uncheckedSerialize():this.checkedSerialize(e)};Z.prototype.uncheckedSerialize=Z.prototype.toString=function(){return this.toBuffer().toString("hex")};Z.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()};Z.prototype.invalidSatoshis=function(){for(var e=!1,t=0;t<this.outputs.length;t++)this.outputs[t].invalidSatoshis()&&(e=!0);return e};Z.prototype.getSerializationError=function(e){if(e=e||{},this.invalidSatoshis())return new Ht.Transaction.InvalidSatoshis;var t=this._getUnspentValue(),r;return t<0?e.disableMoreOutputThanInput||(r=new Ht.Transaction.InvalidOutputAmountSum):r=this._hasFeeError(e,t),r||this._hasDustOutputs(e)||this._isMissingSignatures(e)};Z.prototype._hasFeeError=function(e,t){if(!me.isUndefined(this._fee)&&this._fee!==t)return new Ht.Transaction.FeeError.Different("Unspent value is "+t+" but specified fee is "+this._fee);if(!e.disableLargeFees){var r=Math.floor(Z.FEE_SECURITY_MARGIN*this._estimateFee());if(t>r)return this._missingChange()?new Ht.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided"):new Ht.Transaction.FeeError.TooLarge("expected less than "+r+" but got "+t)}};Z.prototype._missingChange=function(){return!this._changeScript};Z.prototype._hasDustOutputs=function(e){if(!e.disableDustOutputs){var t,r;for(t in this.outputs)if(r=this.outputs[t],r.satoshis<Z.DUST_AMOUNT&&!r.script.isDataOut()&&!r.script.isSafeDataOut())return new Ht.Transaction.DustOutputs}};Z.prototype._isMissingSignatures=function(e){if(!e.disableIsFullySigned&&!this.isFullySigned())return new Ht.Transaction.MissingSignatures};Z.prototype.inspect=function(){return"<Transaction: "+this.uncheckedSerialize()+">"};Z.prototype.toBuffer=function(){var e=new oC;return this.toBufferWriter(e).toBuffer()};Z.prototype.toBufferWriter=function(e){return e.writeInt32LE(this.version),e.writeVarintNum(this.inputs.length),me.each(this.inputs,function(t){t.toBufferWriter(e)}),e.writeVarintNum(this.outputs.length),me.each(this.outputs,function(t){t.toBufferWriter(e)}),e.writeUInt32LE(this.nLockTime),e};Z.prototype.fromBuffer=function(e){var t=new wx(e);return this.fromBufferReader(t)};Z.prototype.fromBufferReader=function(e){zt.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=qt.fromBufferReader(e);this.inputs.push(i)}for(n=e.readVarintNum(),t=0;t<n;t++)this.outputs.push(Yr.fromBufferReader(e));return this.nLockTime=e.readUInt32LE(),this};Z.prototype.toObject=Z.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()),me.isUndefined(this._changeIndex)||(n.changeIndex=this._changeIndex),me.isUndefined(this._fee)||(n.fee=this._fee),n};Z.prototype.fromObject=function(t){zt.checkArgument(me.isObject(t)||t instanceof Z);var r=this,n;return t instanceof Z?n=t.toObject():n=t,me.each(n.inputs,function(i){if(!i.output||!i.output.script){r.uncheckedAddInput(new qt(i));return}var o=new yn(i.output.script),s;if(o.isPublicKeyHashOut())s=new qt.PublicKeyHash(i);else if(o.isScriptHashOut()&&i.publicKeys&&i.threshold)s=new qt.MultiSigScriptHash(i,i.publicKeys,i.threshold,i.signatures);else if(o.isPublicKeyOut())s=new qt.PublicKey(i);else throw new Ht.Transaction.Input.UnsupportedScript(i.output.script);r.addInput(s)}),me.each(n.outputs,function(i){r.addOutput(new Yr(i))}),n.changeIndex&&(this._changeIndex=n.changeIndex),n.changeScript&&(this._changeScript=new yn(n.changeScript)),n.fee&&(this._fee=n.fee),this.nLockTime=n.nLockTime,this.version=n.version,this._checkConsistency(t),this};Z.prototype._checkConsistency=function(e){me.isUndefined(this._changeIndex)||(zt.checkState(this._changeScript,"Change script is expected."),zt.checkState(this.outputs[this._changeIndex],"Change index points to undefined output."),zt.checkState(this.outputs[this._changeIndex].script.toString()===this._changeScript.toString(),"Change output has an unexpected script.")),e&&e.hash&&zt.checkState(e.hash===this.hash,"Hash in object does not match transaction hash.")};Z.prototype.lockUntilDate=function(e){if(zt.checkArgument(e),me.isNumber(e)&&e<Z.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Ht.Transaction.LockTimeTooEarly;me.isDate(e)&&(e=e.getTime()/1e3);for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===qt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=qt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Z.prototype.lockUntilBlockHeight=function(e){if(zt.checkArgument(me.isNumber(e)),e>=Z.NLOCKTIME_BLOCKHEIGHT_LIMIT)throw new Ht.Transaction.BlockHeightTooHigh;if(e<0)throw new Ht.Transaction.NLockTimeOutOfRange;for(var t=0;t<this.inputs.length;t++)this.inputs[t].sequenceNumber===qt.DEFAULT_SEQNUMBER&&(this.inputs[t].sequenceNumber=qt.DEFAULT_LOCKTIME_SEQNUMBER);return this.nLockTime=e,this};Z.prototype.getLockTime=function(){return this.nLockTime?this.nLockTime<Z.NLOCKTIME_BLOCKHEIGHT_LIMIT?this.nLockTime:new Date(1e3*this.nLockTime):null};Z.prototype.fromString=function(e){this.fromBuffer(iC.Buffer.from(e,"hex"))};Z.prototype._newTransaction=function(){this.version=pC,this.nLockTime=gC};Z.prototype.from=function(e,t,r){if(me.isArray(e)){var n=this;return me.each(e,function(o){n.from(o,t,r)}),this}var i=me.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)};Z.prototype._fromNonP2SH=function(e){var t;e=new Ix(e),e.script.isPublicKeyHashOutPrefix()?t=aC:e.script.isPublicKeyOut()?t=uC:t=qt,this.addInput(new t({output:new Yr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:yn.empty()}))};Z.prototype._fromMultisigUtxo=function(e,t,r){zt.checkArgument(r<=t.length,"Number of required signatures must be greater than the number of public keys");var n;if(e=new Ix(e),e.script.isMultisigOut())n=cC;else if(e.script.isScriptHashOut())n=fC;else throw new Ht.Transaction.Input.UnsupportedScript(e.script.toString());this.addInput(new n({output:new Yr({script:e.script,satoshis:e.satoshis}),prevTxId:e.txId,outputIndex:e.outputIndex,script:yn.empty()},t,r))};Z.prototype.addInput=function(e,t,r){if(zt.checkArgumentType(e,qt,"input"),!e.output&&(me.isUndefined(t)||me.isUndefined(r)))throw new Ht.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis");return!e.output&&t&&!me.isUndefined(r)&&(t=t instanceof yn?t:new yn(t),zt.checkArgumentType(r,"number","satoshis"),e.output=new Yr({script:t,satoshis:r})),this.uncheckedAddInput(e)};Z.prototype.uncheckedAddInput=function(e){return zt.checkArgumentType(e,qt,"input"),this.inputs.push(e),this._inputAmount=void 0,this._updateChangeOutput(),this};Z.prototype.hasAllUtxoInfo=function(){return me.every(this.inputs.map(function(e){return!!e.output}))};Z.prototype.fee=function(e){return zt.checkArgument(me.isNumber(e),"amount must be a number"),this._fee=e,this._updateChangeOutput(),this};Z.prototype.feePerKb=function(e){return zt.checkArgument(me.isNumber(e),"amount must be a number"),this._feePerKb=e,this._updateChangeOutput(),this};Z.prototype.change=function(e){return zt.checkArgument(e,"address is required"),this._changeScript=yn.fromAddress(e),this._updateChangeOutput(),this};Z.prototype.getChangeOutput=function(){return me.isUndefined(this._changeIndex)?null:this.outputs[this._changeIndex]};Z.prototype.to=function(e,t){if(me.isArray(e)){var r=this;return me.each(e,function(n){r.to(n.address,n.satoshis)}),this}return zt.checkArgument(Sx.isNaturalNumber(t),"Amount is expected to be a positive integer"),this.addOutput(new Yr({script:yn(new sC(e)),satoshis:t})),this};Z.prototype.addData=function(e){return this.addOutput(new Yr({script:yn.buildDataOut(e),satoshis:0})),this};Z.prototype.addSafeData=function(e){return this.addOutput(new Yr({script:yn.buildSafeDataOut(e),satoshis:0})),this};Z.prototype.addOutput=function(e){return zt.checkArgumentType(e,Yr,"output"),this._addOutput(e),this._updateChangeOutput(),this};Z.prototype.clearOutputs=function(){return this.outputs=[],this._clearSignatures(),this._outputAmount=void 0,this._changeIndex=void 0,this._updateChangeOutput(),this};Z.prototype._addOutput=function(e){this.outputs.push(e),this._outputAmount=void 0};Z.prototype._getOutputAmount=function(){if(me.isUndefined(this._outputAmount)){var e=this;this._outputAmount=0,me.each(this.outputs,function(t){e._outputAmount+=t.satoshis})}return this._outputAmount};Z.prototype._getInputAmount=function(){if(me.isUndefined(this._inputAmount)){var e=this;this._inputAmount=0,me.each(this.inputs,function(t){if(me.isUndefined(t.output))throw new Ht.Transaction.Input.MissingPreviousOutput;e._inputAmount+=t.output.satoshis})}return this._inputAmount};Z.prototype._updateChangeOutput=function(){if(this._changeScript){this._clearSignatures(),me.isUndefined(this._changeIndex)||this._removeOutput(this._changeIndex),this._changeIndex=this.outputs.length,this._addOutput(new Yr({script:this._changeScript,satoshis:0}));var e=this._getUnspentValue(),t=this.getFee(),r=e-t;this._removeOutput(this._changeIndex),this._changeIndex=void 0,r>=Z.DUST_AMOUNT&&(this._changeIndex=this.outputs.length,this._addOutput(new Yr({script:this._changeScript,satoshis:r})))}};Z.prototype.getFee=function(){return this.isCoinbase()?0:me.isUndefined(this._fee)?this._changeScript?this._estimateFee():this._getUnspentValue():this._fee};Z.prototype._estimateFee=function(){var e=this._estimateSize();return Math.ceil(e/1e3*(this._feePerKb||Z.FEE_PER_KB))};Z.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Z.prototype._clearSignatures=function(){me.each(this.inputs,function(e){e.clearSignatures!==qt.prototype.clearSignatures&&e.clearSignatures()})};Z.prototype._estimateSize=function(){var e=8;return e+=_x(this.inputs.length).toBuffer().length,e+=_x(this.outputs.length).toBuffer().length,me.each(this.inputs,function(t){e+=t._estimateSize()}),me.each(this.outputs,function(t){e+=t.getSize()}),e};Z.prototype._removeOutput=function(e){var t=this.outputs[e];this.outputs=me.without(this.outputs,t),this._outputAmount=void 0};Z.prototype.removeOutput=function(e){this._removeOutput(e),this._updateChangeOutput()};Z.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};Z.prototype.shuffleOutputs=function(){return this.sortOutputs(me.shuffle)};Z.prototype.sortOutputs=function(e){var t=e(this.outputs);return this._newOutputOrder(t)};Z.prototype.sortInputs=function(e){return this.inputs=e(this.inputs),this._clearSignatures(),this};Z.prototype._newOutputOrder=function(e){var t=this.outputs.length!==e.length||me.difference(this.outputs,e).length!==0;if(t)throw new Ht.Transaction.InvalidSorting;if(!me.isUndefined(this._changeIndex)){var r=this.outputs[this._changeIndex];this._changeIndex=e.indexOf(r)}return this.outputs=e,this};Z.prototype.removeInput=function(e,t){var r;if(!t&&me.isNumber(e)?r=e:r=me.findIndex(this.inputs,function(i){return i.prevTxId.toString("hex")===e&&i.outputIndex===t}),r<0||r>=this.inputs.length)throw new Ht.Transaction.InvalidIndex(r,this.inputs.length);var n=this.inputs[r];this.inputs=me.without(this.inputs,n),this._inputAmount=void 0,this._updateChangeOutput()};Z.prototype.sign=function(e,t){zt.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var r=this;if(me.isArray(e))return me.each(e,function(i){r.sign(i,t)}),this;var n=!this._sighashMidstates;n&&(this._sighashMidstates={});try{me.each(this.getSignatures(e,t),function(i){r.applySignature(i)})}finally{n&&delete this._sighashMidstates}return this};Z.prototype.getSignatures=function(e,t){e=new lC(e),t=t||jc.SIGHASH_ALL|jc.SIGHASH_FORKID;var r=this,n=[],i=Ex.sha256ripemd160(e.publicKey.toBuffer()),o=!this._sighashMidstates;o&&(this._sighashMidstates={});try{me.each(this.inputs,function(a,f){me.each(a.getSignatures(r,e,f,t,i),function(l){n.push(l)})})}finally{o&&delete this._sighashMidstates}return n};Z.prototype.applySignature=function(e){return this.inputs[e.inputIndex].addSignature(this,e),this};Z.prototype.isFullySigned=function(){return me.each(this.inputs,function(e){if(e.isFullySigned===qt.prototype.isFullySigned)throw new Ht.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script.This usually happens when creating a transaction from a serialized transaction")}),me.every(me.map(this.inputs,function(e){return e.isFullySigned()}))};Z.prototype.isValidSignature=function(e){var t=this;if(this.inputs[e.inputIndex].isValidSignature===qt.prototype.isValidSignature)throw new Ht.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)};Z.prototype.verifySignature=function(e,t,r,n,i,o){return xx.verify(this,e,t,r,n,i,o)};Z.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 Hc(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 Hc(Z.MAX_MONEY,10)))return"transaction txout "+t+" greater than MAX_MONEY";if(e=e.add(r._satoshisBN),e.gt(new Hc(Z.MAX_MONEY)))return"transaction txout "+t+" total output greater than MAX_MONEY"}if(this.toBuffer().length>yC)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(!me.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};Z.prototype.isCoinbase=function(){return this.inputs.length===1&&this.inputs[0].isNull()};Z.prototype.sighash=function(e,t,r,n,i){t=t||jc.SIGHASH_ALL|jc.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 Hc(o.output.satoshis)),i=i||dC,xx.sighash(this,t,e,r,n,i)};Ox.exports=Z});var jp=B((mq,co)=>{g();co.exports=Fp();co.exports.Input=Dc();co.exports.Output=jn();co.exports.UnspentOutput=qp();co.exports.Signature=ds();co.exports.Sighash=Ii()});var Fc=B((bq,Nx)=>{"use strict";g();var Kc=at(),Gc=Ip(),k=vp(),le=Ar(),Za=nr(),zn=fr(),Kp=Pr();function Rx(e){return e.map(function(t){return d.Buffer.isBuffer(t)?d.Buffer.from(t):t})}var R=function e(t){if(!(this instanceof e))return new e(t);t?(this.initialize(),this.set(t)):this.initialize()};R.prototype._verifyCore=function(e,t,r,n,i,o){var s=jp();if(Kc.isUndefined(r)&&(r=new s),Kc.isUndefined(n)&&(n=0),Kc.isUndefined(i)&&(i=R.currentConsensusFlags(),o||(i&=~R.SCRIPT_ENABLE_SIGHASH_FORKID)),i&R.SCRIPT_ENABLE_SIGHASH_FORKID&&(i|=R.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&R.SCRIPT_UTXO_AFTER_CHRONICLE)!==0&&(i&R.SCRIPT_UTXO_AFTER_GENESIS)===0)return this.errstr="SCRIPT_ERR_INVALID_FLAGS",!1;if((i&R.SCRIPT_VERIFY_SIGPUSHONLY)!==0){var f=(i&R.SCRIPT_CHRONICLE)!==0,l=(i&R.SCRIPT_GENESIS)!==0&&!f||f&&Bx(i,r);if(l&&!e.isPushOnly())return this.errstr="SCRIPT_ERR_SIG_PUSHONLY",!1}if(!this.evaluate())return!1;var m=(i&R.SCRIPT_VERIFY_P2SH)!==0&&(i&R.SCRIPT_UTXO_AFTER_GENESIS)===0;m&&(a=this.stack.slice());var y=this.stack;if(this.initialize(),this.set({script:t,stack:y,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 p=this.stack[this.stack.length-1];if(!R.castToBool(p))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK",!1;if(m&&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 S=a[a.length-1],O=Gc.fromBuffer(S);if(a.pop(),this.initialize(),this.set({script:O,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(!R.castToBool(a[a.length-1]))return this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK",!1}if((i&R.SCRIPT_VERIFY_CLEANSTACK)!==0){if((i&R.SCRIPT_VERIFY_P2SH)===0)return this.errstr="SCRIPT_ERR_INVALID_FLAGS",!1;if(this.enforceNonMalleability()&&this.stack.length!==1)return this.errstr="SCRIPT_ERR_CLEANSTACK",!1}return!0};Nx.exports=R;R.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};R.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};R.true=d.Buffer.from([1]);R.false=d.Buffer.from([]);R.MAX_SCRIPT_ELEMENT_SIZE=520;R.MAXIMUM_ELEMENT_SIZE=4;R.MAX_OPS_PER_SCRIPT=500;R.MAX_SCRIPT_SIZE=1e4;R.UNLIMITED=Number.MAX_SAFE_INTEGER;R.MAX_SCRIPT_NUM_LENGTH_AFTER_GENESIS=75e4;R.MAX_SCRIPT_NUM_LENGTH_AFTER_CHRONICLE=32e6;R.MAX_PUBKEYS_PER_MULTISIG_AFTER_GENESIS=4294967295;R.MAX_STACK_SIZE=1e3;R.MAX_STACK_MEMORY_USAGE_AFTER_GENESIS=R.UNLIMITED;R.STACK_MEMORY_USAGE_POLICY=100*1024*1024;R.STACK_ELEMENT_OVERHEAD=32;R.LOCKTIME_THRESHOLD=5e8;R.LOCKTIME_THRESHOLD_BN=new le(R.LOCKTIME_THRESHOLD);R.useGenesisLimits=function(e){return e=e||2147483647,R.MAX_SCRIPT_ELEMENT_SIZE=e,R.MAX_OPS_PER_SCRIPT=e,R.MAX_SCRIPT_SIZE=e,R};R.getLimits=function(){return{maxScriptElementSize:R.MAX_SCRIPT_ELEMENT_SIZE,maximumElementSize:R.MAXIMUM_ELEMENT_SIZE,maxOpsPerScript:R.MAX_OPS_PER_SCRIPT,maxScriptSize:R.MAX_SCRIPT_SIZE}};R.setLimits=function(e){return e=e||{},e.maxScriptElementSize!=null&&(R.MAX_SCRIPT_ELEMENT_SIZE=e.maxScriptElementSize),e.maximumElementSize!=null&&(R.MAXIMUM_ELEMENT_SIZE=e.maximumElementSize),e.maxOpsPerScript!=null&&(R.MAX_OPS_PER_SCRIPT=e.maxOpsPerScript),e.maxScriptSize!=null&&(R.MAX_SCRIPT_SIZE=e.maxScriptSize),R};R.SCRIPT_VERIFY_NONE=0;R.SCRIPT_VERIFY_P2SH=1;R.SCRIPT_VERIFY_STRICTENC=2;R.SCRIPT_VERIFY_DERSIG=4;R.SCRIPT_VERIFY_LOW_S=8;R.SCRIPT_VERIFY_NULLDUMMY=16;R.SCRIPT_VERIFY_SIGPUSHONLY=32;R.SCRIPT_VERIFY_MINIMALDATA=64;R.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=128;R.SCRIPT_VERIFY_CLEANSTACK=256;R.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=512;R.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1024;R.SCRIPT_VERIFY_MINIMALIF=8192;R.SCRIPT_VERIFY_NULLFAIL=16384;R.SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE=32768;R.SCRIPT_ENABLE_SIGHASH_FORKID=65536;R.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;R.SCRIPT_ENABLE_MONOLITH_OPCODES=2048;R.SCRIPT_ENABLE_MAGNETIC_OPCODES=4096;R.SCRIPT_GENESIS=1<<18;R.SCRIPT_UTXO_AFTER_GENESIS=1<<19;R.SCRIPT_ENABLE_CHRONICLE=1<<20;R.SCRIPT_CHRONICLE=R.SCRIPT_ENABLE_CHRONICLE;R.SCRIPT_UTXO_AFTER_CHRONICLE=1<<21;R.CHRONICLE_ACTIVATION_HEIGHT=943816;R.ERA_SENSITIVE_ERRORS={SCRIPT_ERR_PUSH_SIZE:{cap:"stack element size (capped at 520 bytes pre-Genesis, unbounded after)",lifts:R.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_SCRIPT_SIZE:{cap:"total script size (capped at 10,000 bytes pre-Genesis, unbounded after)",lifts:R.SCRIPT_UTXO_AFTER_GENESIS},SCRIPT_ERR_OP_COUNT:{cap:"opcode count (capped at 201 pre-Genesis, unbounded after)",lifts:R.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:R.SCRIPT_UTXO_AFTER_GENESIS|R.SCRIPT_UTXO_AFTER_CHRONICLE}};R.ERA_FLAGS=R.SCRIPT_GENESIS|R.SCRIPT_UTXO_AFTER_GENESIS|R.SCRIPT_ENABLE_CHRONICLE|R.SCRIPT_UTXO_AFTER_CHRONICLE;R.eraDiagnostics=!(typeof x.default<"u"&&x.default.env&&x.default.env.BSV_NO_ERA_HINT==="1");var Gp=!1;R.prototype._eraDiagnose=function(e){if(e!==void 0){var t=R.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.`,R.eraDiagnostics&&!Gp&&(Gp=!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.26.
|
|
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.26.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})}
|