@smartledger/bsv 7.5.8 → 7.6.1
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 +108 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +38 -38
- package/bsv-ltp.min.js +38 -38
- package/bsv-smartcontract.min.js +8 -8
- package/bsv.bundle.js +38 -38
- package/bsv.min.js +38 -38
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/lib/opcode.js +26 -10
- package/lib/script/interpreter.js +9 -6
- package/lib/smart_contract/opcode_map.js +9 -36
- package/lib/smart_contract/pushtx.js +22 -2
- package/lib/transaction/transaction.js +1 -1
- package/package.json +1 -1
- package/test/opcode.js +28 -3
- package/test/regressions.js +180 -0
- package/test/script/interpreter.js +43 -4
- package/test/script/script.js +5 -4
- package/version.js +1 -1
package/bsv-smartcontract.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var bsvSmartContract=(()=>{var yf=Object.create;var kn=Object.defineProperty;var wf=Object.getOwnPropertyDescriptor;var bf=Object.getOwnPropertyNames;var Sf=Object.getPrototypeOf,Ef=Object.prototype.hasOwnProperty;var _f=(t,e,r)=>e in t?kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var ve=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ae=(t,e,r)=>()=>{if(r)throw r[0];try{return t&&(e=t(t=0)),e}catch(n){throw r=[n],n}};var Z=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Of=(t,e)=>{for(var r in e)kn(t,r,{get:e[r],enumerable:!0})},na=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of bf(e))!Ef.call(t,i)&&i!==r&&kn(t,i,{get:()=>e[i],enumerable:!(n=wf(e,i))||n.enumerable});return t};var ia=(t,e,r)=>(r=t!=null?yf(Sf(t)):{},na(e||!t||!t.__esModule?kn(r,"default",{value:t,enumerable:!0}):r,t)),Af=t=>na(kn({},"__esModule",{value:!0}),t);var W=(t,e,r)=>_f(t,typeof e!="symbol"?e+"":e,r);var ua=Z((Bp,ca)=>{I();var Rt=ca.exports={},je,Ye;function co(){throw new Error("setTimeout has not been defined")}function uo(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?je=setTimeout:je=co}catch{je=co}try{typeof clearTimeout=="function"?Ye=clearTimeout:Ye=uo}catch{Ye=uo}})();function oa(t){if(je===setTimeout)return setTimeout(t,0);if((je===co||!je)&&setTimeout)return je=setTimeout,setTimeout(t,0);try{return je(t,0)}catch{try{return je.call(null,t,0)}catch{return je.call(this,t,0)}}}function If(t){if(Ye===clearTimeout)return clearTimeout(t);if((Ye===uo||!Ye)&&clearTimeout)return Ye=clearTimeout,clearTimeout(t);try{return Ye(t)}catch{try{return Ye.call(null,t)}catch{return Ye.call(this,t)}}}var ur=[],Wr=!1,kr,ri=-1;function Pf(){!Wr||!kr||(Wr=!1,kr.length?ur=kr.concat(ur):ri=-1,ur.length&&sa())}function sa(){if(!Wr){var t=oa(Pf);Wr=!0;for(var e=ur.length;e;){for(kr=ur,ur=[];++ri<e;)kr&&kr[ri].run();ri=-1,e=ur.length}kr=null,Wr=!1,If(t)}}Rt.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];ur.push(new aa(t,e)),ur.length===1&&!Wr&&oa(sa)};function aa(t,e){this.fun=t,this.array=e}aa.prototype.run=function(){this.fun.apply(null,this.array)};Rt.title="browser";Rt.browser=!0;Rt.env={};Rt.argv=[];Rt.version="";Rt.versions={};function hr(){}Rt.on=hr;Rt.addListener=hr;Rt.once=hr;Rt.off=hr;Rt.removeListener=hr;Rt.removeAllListeners=hr;Rt.emit=hr;Rt.prependListener=hr;Rt.prependOnceListener=hr;Rt.listeners=function(t){return[]};Rt.binding=function(t){throw new Error("process.binding is not supported")};Rt.cwd=function(){return"/"};Rt.chdir=function(t){throw new Error("process.chdir is not supported")};Rt.umask=function(){return 0}});var la=Z(ni=>{"use strict";I();ni.byteLength=Bf;ni.toByteArray=Rf;ni.fromByteArray=Hf;var $e=[],ke=[],Tf=typeof Uint8Array<"u"?Uint8Array:Array,ho="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Fr=0,ha=ho.length;Fr<ha;++Fr)$e[Fr]=ho[Fr],ke[ho.charCodeAt(Fr)]=Fr;var Fr,ha;ke[45]=62;ke[95]=63;function fa(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Bf(t){var e=fa(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Mf(t,e,r){return(e+r)*3/4-r}function Rf(t){var e,r=fa(t),n=r[0],i=r[1],o=new Tf(Mf(t,n,i)),c=0,h=i>0?n-4:n,d;for(d=0;d<h;d+=4)e=ke[t.charCodeAt(d)]<<18|ke[t.charCodeAt(d+1)]<<12|ke[t.charCodeAt(d+2)]<<6|ke[t.charCodeAt(d+3)],o[c++]=e>>16&255,o[c++]=e>>8&255,o[c++]=e&255;return i===2&&(e=ke[t.charCodeAt(d)]<<2|ke[t.charCodeAt(d+1)]>>4,o[c++]=e&255),i===1&&(e=ke[t.charCodeAt(d)]<<10|ke[t.charCodeAt(d+1)]<<4|ke[t.charCodeAt(d+2)]>>2,o[c++]=e>>8&255,o[c++]=e&255),o}function kf(t){return $e[t>>18&63]+$e[t>>12&63]+$e[t>>6&63]+$e[t&63]}function Ff(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(kf(n));return i.join("")}function Hf(t){for(var e,r=t.length,n=r%3,i=[],o=16383,c=0,h=r-n;c<h;c+=o)i.push(Ff(t,c,c+o>h?h:c+o));return n===1?(e=t[r-1],i.push($e[e>>2]+$e[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push($e[e>>10]+$e[e>>4&63]+$e[e<<2&63]+"=")),i.join("")}});var da=Z(fo=>{I();fo.read=function(t,e,r,n,i){var o,c,h=i*8-n-1,d=(1<<h)-1,x=d>>1,v=-7,y=r?i-1:0,A=r?-1:1,O=t[e+y];for(y+=A,o=O&(1<<-v)-1,O>>=-v,v+=h;v>0;o=o*256+t[e+y],y+=A,v-=8);for(c=o&(1<<-v)-1,o>>=-v,v+=n;v>0;c=c*256+t[e+y],y+=A,v-=8);if(o===0)o=1-x;else{if(o===d)return c?NaN:(O?-1:1)*(1/0);c=c+Math.pow(2,n),o=o-x}return(O?-1:1)*c*Math.pow(2,o-n)};fo.write=function(t,e,r,n,i,o){var c,h,d,x=o*8-i-1,v=(1<<x)-1,y=v>>1,A=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,O=n?0:o-1,T=n?1:-1,L=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(h=isNaN(e)?1:0,c=v):(c=Math.floor(Math.log(e)/Math.LN2),e*(d=Math.pow(2,-c))<1&&(c--,d*=2),c+y>=1?e+=A/d:e+=A*Math.pow(2,1-y),e*d>=2&&(c++,d/=2),c+y>=v?(h=0,c=v):c+y>=1?(h=(e*d-1)*Math.pow(2,i),c=c+y):(h=e*Math.pow(2,y-1)*Math.pow(2,i),c=0));i>=8;t[r+O]=h&255,O+=T,h/=256,i-=8);for(c=c<<i|h,x+=i;x>0;t[r+O]=c&255,O+=T,c/=256,x-=8);t[r+O-T]|=L*128}});var si=Z(en=>{"use strict";I();var lo=la(),Jr=da(),pa=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;en.Buffer=B;en.SlowBuffer=Df;en.INSPECT_MAX_BYTES=50;var ii=2147483647;en.kMaxLength=ii;B.TYPED_ARRAY_SUPPORT=Lf();!B.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Lf(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(B.prototype,"parent",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.buffer}});Object.defineProperty(B.prototype,"offset",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.byteOffset}});function fr(t){if(t>ii)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,B.prototype),e}function B(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return vo(t)}return xa(t,e,r)}B.poolSize=8192;function xa(t,e,r){if(typeof t=="string")return Cf(t,e);if(ArrayBuffer.isView(t))return Uf(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Ze(t,ArrayBuffer)||t&&Ze(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ze(t,SharedArrayBuffer)||t&&Ze(t.buffer,SharedArrayBuffer)))return mo(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return B.from(n,e,r);let i=qf(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return B.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}B.from=function(t,e,r){return xa(t,e,r)};Object.setPrototypeOf(B.prototype,Uint8Array.prototype);Object.setPrototypeOf(B,Uint8Array);function ya(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function Nf(t,e,r){return ya(t),t<=0?fr(t):e!==void 0?typeof r=="string"?fr(t).fill(e,r):fr(t).fill(e):fr(t)}B.alloc=function(t,e,r){return Nf(t,e,r)};function vo(t){return ya(t),fr(t<0?0:xo(t)|0)}B.allocUnsafe=function(t){return vo(t)};B.allocUnsafeSlow=function(t){return vo(t)};function Cf(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!B.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=wa(t,e)|0,n=fr(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function po(t){let e=t.length<0?0:xo(t.length)|0,r=fr(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Uf(t){if(Ze(t,Uint8Array)){let e=new Uint8Array(t);return mo(e.buffer,e.byteOffset,e.byteLength)}return po(t)}function mo(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,B.prototype),n}function qf(t){if(B.isBuffer(t)){let e=xo(t.length)|0,r=fr(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||wo(t.length)?fr(0):po(t);if(t.type==="Buffer"&&Array.isArray(t.data))return po(t.data)}function xo(t){if(t>=ii)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ii.toString(16)+" bytes");return t|0}function Df(t){return+t!=t&&(t=0),B.alloc(+t)}B.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==B.prototype};B.compare=function(e,r){if(Ze(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),Ze(r,Uint8Array)&&(r=B.from(r,r.offset,r.byteLength)),!B.isBuffer(e)||!B.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,c=Math.min(n,i);o<c;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};B.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};B.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return B.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=B.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let c=e[n];if(Ze(c,Uint8Array))o+c.length>i.length?(B.isBuffer(c)||(c=B.from(c)),c.copy(i,o)):Uint8Array.prototype.set.call(i,c,o);else if(B.isBuffer(c))c.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=c.length}return i};function wa(t,e){if(B.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Ze(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return go(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Ta(t).length;default:if(i)return n?-1:go(t).length;e=(""+e).toLowerCase(),i=!0}}B.byteLength=wa;function Gf(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return Qf(this,e,r);case"utf8":case"utf-8":return Sa(this,e,r);case"ascii":return Xf(this,e,r);case"latin1":case"binary":return Wf(this,e,r);case"base64":return $f(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Jf(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}B.prototype._isBuffer=!0;function Hr(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}B.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)Hr(this,r,r+1);return this};B.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)Hr(this,r,r+3),Hr(this,r+1,r+2);return this};B.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)Hr(this,r,r+7),Hr(this,r+1,r+6),Hr(this,r+2,r+5),Hr(this,r+3,r+4);return this};B.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Sa(this,0,e):Gf.apply(this,arguments)};B.prototype.toLocaleString=B.prototype.toString;B.prototype.equals=function(e){if(!B.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:B.compare(this,e)===0};B.prototype.inspect=function(){let e="",r=en.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};pa&&(B.prototype[pa]=B.prototype.inspect);B.prototype.compare=function(e,r,n,i,o){if(Ze(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),!B.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let c=o-i,h=n-r,d=Math.min(c,h),x=this.slice(i,o),v=e.slice(r,n);for(let y=0;y<d;++y)if(x[y]!==v[y]){c=x[y],h=v[y];break}return c<h?-1:h<c?1:0};function ba(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,wo(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=B.from(e,n)),B.isBuffer(e))return e.length===0?-1:ma(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):ma(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ma(t,e,r,n,i){let o=1,c=t.length,h=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,c/=2,h/=2,r/=2}function d(v,y){return o===1?v[y]:v.readUInt16BE(y*o)}let x;if(i){let v=-1;for(x=r;x<c;x++)if(d(t,x)===d(e,v===-1?0:x-v)){if(v===-1&&(v=x),x-v+1===h)return v*o}else v!==-1&&(x-=x-v),v=-1}else for(r+h>c&&(r=c-h),x=r;x>=0;x--){let v=!0;for(let y=0;y<h;y++)if(d(t,x+y)!==d(e,y)){v=!1;break}if(v)return x}return-1}B.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};B.prototype.indexOf=function(e,r,n){return ba(this,e,r,n,!0)};B.prototype.lastIndexOf=function(e,r,n){return ba(this,e,r,n,!1)};function zf(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let c;for(c=0;c<n;++c){let h=parseInt(e.substr(c*2,2),16);if(wo(h))return c;t[r+c]=h}return c}function Vf(t,e,r,n){return oi(go(e,t.length-r),t,r,n)}function Kf(t,e,r,n){return oi(nl(e),t,r,n)}function jf(t,e,r,n){return oi(Ta(e),t,r,n)}function Yf(t,e,r,n){return oi(il(e,t.length-r),t,r,n)}B.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let c=!1;for(;;)switch(i){case"hex":return zf(this,e,r,n);case"utf8":case"utf-8":return Vf(this,e,r,n);case"ascii":case"latin1":case"binary":return Kf(this,e,r,n);case"base64":return jf(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Yf(this,e,r,n);default:if(c)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),c=!0}};B.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function $f(t,e,r){return e===0&&r===t.length?lo.fromByteArray(t):lo.fromByteArray(t.slice(e,r))}function Sa(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],c=null,h=o>239?4:o>223?3:o>191?2:1;if(i+h<=r){let d,x,v,y;switch(h){case 1:o<128&&(c=o);break;case 2:d=t[i+1],(d&192)===128&&(y=(o&31)<<6|d&63,y>127&&(c=y));break;case 3:d=t[i+1],x=t[i+2],(d&192)===128&&(x&192)===128&&(y=(o&15)<<12|(d&63)<<6|x&63,y>2047&&(y<55296||y>57343)&&(c=y));break;case 4:d=t[i+1],x=t[i+2],v=t[i+3],(d&192)===128&&(x&192)===128&&(v&192)===128&&(y=(o&15)<<18|(d&63)<<12|(x&63)<<6|v&63,y>65535&&y<1114112&&(c=y))}}c===null?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|c&1023),n.push(c),i+=h}return Zf(n)}var ga=4096;function Zf(t){let e=t.length;if(e<=ga)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=ga));return r}function Xf(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function Wf(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function Qf(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=ol[t[o]];return i}function Jf(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}B.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,B.prototype),i};function he(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}B.prototype.readUintLE=B.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e],o=1,c=0;for(;++c<r&&(o*=256);)i+=this[e+c]*o;return i};B.prototype.readUintBE=B.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};B.prototype.readUint8=B.prototype.readUInt8=function(e,r){return e=e>>>0,r||he(e,1,this.length),this[e]};B.prototype.readUint16LE=B.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||he(e,2,this.length),this[e]|this[e+1]<<8};B.prototype.readUint16BE=B.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||he(e,2,this.length),this[e]<<8|this[e+1]};B.prototype.readUint32LE=B.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||he(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};B.prototype.readUint32BE=B.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};B.prototype.readBigUInt64LE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});B.prototype.readBigUInt64BE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});B.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e],o=1,c=0;for(;++c<r&&(o*=256);)i+=this[e+c]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};B.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=r,o=1,c=this[e+--i];for(;i>0&&(o*=256);)c+=this[e+--i]*o;return o*=128,c>=o&&(c-=Math.pow(2,8*r)),c};B.prototype.readInt8=function(e,r){return e=e>>>0,r||he(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};B.prototype.readInt16LE=function(e,r){e=e>>>0,r||he(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};B.prototype.readInt16BE=function(e,r){e=e>>>0,r||he(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};B.prototype.readInt32LE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};B.prototype.readInt32BE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};B.prototype.readBigInt64LE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});B.prototype.readBigInt64BE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});B.prototype.readFloatLE=function(e,r){return e=e>>>0,r||he(e,4,this.length),Jr.read(this,e,!0,23,4)};B.prototype.readFloatBE=function(e,r){return e=e>>>0,r||he(e,4,this.length),Jr.read(this,e,!1,23,4)};B.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||he(e,8,this.length),Jr.read(this,e,!0,52,8)};B.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||he(e,8,this.length),Jr.read(this,e,!1,52,8)};function be(t,e,r,n,i,o){if(!B.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}B.prototype.writeUintLE=B.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let h=Math.pow(2,8*n)-1;be(this,e,r,n,h,0)}let o=1,c=0;for(this[r]=e&255;++c<n&&(o*=256);)this[r+c]=e/o&255;return r+n};B.prototype.writeUintBE=B.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let h=Math.pow(2,8*n)-1;be(this,e,r,n,h,0)}let o=n-1,c=1;for(this[r+o]=e&255;--o>=0&&(c*=256);)this[r+o]=e/c&255;return r+n};B.prototype.writeUint8=B.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,1,255,0),this[r]=e&255,r+1};B.prototype.writeUint16LE=B.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};B.prototype.writeUint16BE=B.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};B.prototype.writeUint32LE=B.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};B.prototype.writeUint32BE=B.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Ea(t,e,r,n,i){Pa(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let c=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=c,c=c>>8,t[r++]=c,c=c>>8,t[r++]=c,c=c>>8,t[r++]=c,r}function _a(t,e,r,n,i){Pa(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let c=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=c,c=c>>8,t[r+2]=c,c=c>>8,t[r+1]=c,c=c>>8,t[r]=c,r+8}B.prototype.writeBigUInt64LE=Ir(function(e,r=0){return Ea(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeBigUInt64BE=Ir(function(e,r=0){return _a(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let d=Math.pow(2,8*n-1);be(this,e,r,n,d-1,-d)}let o=0,c=1,h=0;for(this[r]=e&255;++o<n&&(c*=256);)e<0&&h===0&&this[r+o-1]!==0&&(h=1),this[r+o]=(e/c>>0)-h&255;return r+n};B.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let d=Math.pow(2,8*n-1);be(this,e,r,n,d-1,-d)}let o=n-1,c=1,h=0;for(this[r+o]=e&255;--o>=0&&(c*=256);)e<0&&h===0&&this[r+o+1]!==0&&(h=1),this[r+o]=(e/c>>0)-h&255;return r+n};B.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};B.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};B.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};B.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};B.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};B.prototype.writeBigInt64LE=Ir(function(e,r=0){return Ea(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});B.prototype.writeBigInt64BE=Ir(function(e,r=0){return _a(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Oa(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Aa(t,e,r,n,i){return e=+e,r=r>>>0,i||Oa(t,e,r,4,34028234663852886e22,-34028234663852886e22),Jr.write(t,e,r,n,23,4),r+4}B.prototype.writeFloatLE=function(e,r,n){return Aa(this,e,r,!0,n)};B.prototype.writeFloatBE=function(e,r,n){return Aa(this,e,r,!1,n)};function Ia(t,e,r,n,i){return e=+e,r=r>>>0,i||Oa(t,e,r,8,17976931348623157e292,-17976931348623157e292),Jr.write(t,e,r,n,52,8),r+8}B.prototype.writeDoubleLE=function(e,r,n){return Ia(this,e,r,!0,n)};B.prototype.writeDoubleBE=function(e,r,n){return Ia(this,e,r,!1,n)};B.prototype.copy=function(e,r,n,i){if(!B.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};B.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!B.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let c=e.charCodeAt(0);(i==="utf8"&&c<128||i==="latin1")&&(e=c)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let c=B.isBuffer(e)?e:B.from(e,i),h=c.length;if(h===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=c[o%h]}return this};var Qr={};function yo(t,e,r){Qr[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}yo("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);yo("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);yo("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=va(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=va(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function va(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function tl(t,e,r){tn(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Fn(e,t.length-(r+1))}function Pa(t,e,r,n,i,o){if(t>r||t<e){let c=typeof e=="bigint"?"n":"",h;throw o>3?e===0||e===BigInt(0)?h=`>= 0${c} and < 2${c} ** ${(o+1)*8}${c}`:h=`>= -(2${c} ** ${(o+1)*8-1}${c}) and < 2 ** ${(o+1)*8-1}${c}`:h=`>= ${e}${c} and <= ${r}${c}`,new Qr.ERR_OUT_OF_RANGE("value",h,t)}tl(n,i,o)}function tn(t,e){if(typeof t!="number")throw new Qr.ERR_INVALID_ARG_TYPE(e,"number",t)}function Fn(t,e,r){throw Math.floor(t)!==t?(tn(t,r),new Qr.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new Qr.ERR_BUFFER_OUT_OF_BOUNDS:new Qr.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var el=/[^+/0-9A-Za-z-_]/g;function rl(t){if(t=t.split("=")[0],t=t.trim().replace(el,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function go(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let c=0;c<n;++c){if(r=t.charCodeAt(c),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(c+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function nl(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function il(t,e){let r,n,i,o=[];for(let c=0;c<t.length&&!((e-=2)<0);++c)r=t.charCodeAt(c),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Ta(t){return lo.toByteArray(rl(t))}function oi(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Ze(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function wo(t){return t!==t}var ol=(function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e})();function Ir(t){return typeof BigInt>"u"?sl:t}function sl(){throw new Error("BigInt not supported")}});var C,E,I=Ae(()=>{C=ia(ua()),E=ia(si())});var de=Z((qp,Ba)=>{I();Ba.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var se=Z((Gp,Ma)=>{"use strict";I();Ma.exports={}});var Fa=Z((Vp,ka)=>{"use strict";I();var At=de(),Ra=se(),lr;try{lr=se()}catch{lr=null}var al=function(){var t=typeof C.default<"u"&&C.default.env&&C.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG;t&&console.log.apply(console,arguments)};function Se(t,e){if(!(this instanceof Se))return new Se(t,e);this.privateKey=t,this.publicKey=t.publicKey,this.address=t.toAddress(),e=e||{},this.storageDir=e.storageDir||(typeof C.default<"u"?Ra.join(C.default.cwd(),".bsv-covenants"):".bsv-covenants"),this.covenantUtxoPath=Ra.join(this.storageDir,"covenant_utxos.json"),this.sighashType=At.crypto.Signature.SIGHASH_ALL|At.crypto.Signature.SIGHASH_FORKID,this.allowNonEnforcing=e.allowNonEnforcing===!0,lr&&this._ensureStorageDir()}Se.prototype.createFromP2PKH=function(t){if(!this.allowNonEnforcing)throw new Error("SmartContract.Covenant builds a NON-ENFORCING script that reduces to plain P2PK \u2014 it does not constrain the spend. Use SmartContract.PushTx.valueCovenant (output binding) or SmartContract.Token / perpetualCovenant (stateful covenants) for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.");t.script||(t.script=Se.reconstructP2pkhScript(this.address));var e=new At.Transaction().from({txId:t.txid,outputIndex:t.vout,script:t.script,satoshis:t.satoshis}).to(this.address,t.satoshis-1e3),r=At.Script.fromHex(t.script),n=At.Transaction.sighash.sighashPreimage(e,this.sighashType,0,r,new At.crypto.BN(t.satoshis)),i=At.crypto.Hash.sha256sha256(n),o=new At.Script().add("OP_DUP").add("OP_HASH256").add(i).add("OP_EQUALVERIFY").add("OP_DROP").add(this.publicKey.toBuffer()).add("OP_CHECKSIG");e.outputs[0].setScript(o),e.sign(this.privateKey);var c={txid:e.id,vout:0,satoshis:t.satoshis-1e3,script:o.toHex(),scriptPubKey:o.toHex(),preimageHash:i.toString("hex"),originalPreimage:n.toString("hex"),status:"local",createdAt:new Date().toISOString(),type:"preimage_covenant"};return{transaction:e,covenantUtxo:c}};Se.prototype.createSpendingTx=function(t,e,r){var n=e||this.address,i=r||t.satoshis-500,o=new At.Transaction;o.addInput(new At.Transaction.Input({prevTxId:t.txid,outputIndex:t.vout,script:At.Script.empty()}),At.Script.fromHex(t.script),t.satoshis),o.to(n,i);var c=At.Script.fromHex(t.script),h=At.Transaction.sighash.sign(o,this.privateKey,this.sighashType,0,c,new At.crypto.BN(t.satoshis)),d=E.Buffer.concat([h.toDER(),E.Buffer.from([this.sighashType])]),x=E.Buffer.from(t.originalPreimage,"hex"),v=new At.Script().add(d).add(x);return o.inputs[0].setScript(v),o};Se.prototype.validate=function(t,e){var r=new At.Script.Interpreter,n=At.Script.Interpreter.SCRIPT_VERIFY_P2SH|At.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|At.Script.Interpreter.SCRIPT_VERIFY_DERSIG|At.Script.Interpreter.SCRIPT_VERIFY_LOW_S|At.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,i=t.inputs[0].script,o=At.Script.fromHex(e.script),c=r.verify(i,o,t,0,n,new At.crypto.BN(e.satoshis));return{valid:c,error:c?null:r.errstr}};Se.prototype.save=function(t){if(!lr)return al("File system operations not available in browser environment"),t;var e=this.list();return e.push(t),lr.writeFileSync(this.covenantUtxoPath,JSON.stringify(e,null,2)),t};Se.prototype.load=function(t){var e=this.list();if(t){var r=e.find(function(n){return n.txid===t});if(!r)throw new Error("Covenant UTXO with TXID "+t+" not found");return r}else{var r=e.find(function(i){return i.type==="preimage_covenant"});if(!r)throw new Error("No preimage covenant UTXO found");return r}};Se.prototype.list=function(){return lr.existsSync(this.covenantUtxoPath)?JSON.parse(lr.readFileSync(this.covenantUtxoPath,"utf8")):[]};Se.prototype.getPortfolio=function(){var t=this.list(),e={total:t.length,totalValue:t.reduce(function(r,n){return r+n.satoshis},0),byStatus:{},recent:t.slice(-5)};return t.forEach(function(r){var n=r.status||"local";e.byStatus[n]||(e.byStatus[n]={count:0,value:0}),e.byStatus[n].count++,e.byStatus[n].value+=r.satoshis}),e};Se.prototype.completeFlow=function(t,e){var r=this.createFromP2PKH(t),n=this.save(r.covenantUtxo);e&&e(r.transaction,"creation");var i=this.createSpendingTx(n),o=this.validate(i,n);return e&&o.valid&&e(i,"spending"),{creationTx:r.transaction,spendingTx:i,covenantUtxo:n,validation:o,success:o.valid}};Se.prototype._ensureStorageDir=function(){lr.existsSync(this.storageDir)||lr.mkdirSync(this.storageDir,{recursive:!0})};Se.reconstructP2pkhScript=function(t){return At.Script.buildPublicKeyHashOut(t).toHex()};ka.exports=Se});var Xe=Z((Yp,Ha)=>{"use strict";I();var rn=de(),jp=se();function tt(t,e){if(!(this instanceof tt))return new tt(t,e);this.preimage=E.Buffer.isBuffer(t)?t:E.Buffer.from(t,"hex"),this.options=e||{},this.strategy=this.options.strategy||"DYNAMIC",this.fields=null,this.sighashInfo=null,this.options.deferExtraction||this._extractFields()}tt.LEFT_FIXED_LENGTH=104;tt.RIGHT_FIXED_LENGTH=52;tt.MIN_PREIMAGE_LENGTH=tt.LEFT_FIXED_LENGTH+1+tt.RIGHT_FIXED_LENGTH;tt.prototype.extract=function(t){return this.strategy=t||this.strategy,this._extractFields(),this.fields};tt.prototype.getSighashInfo=function(){return this.fields||this._extractFields(),this.sighashInfo};tt.prototype.getField=function(t){return this.fields||this._extractFields(),this.fields[t]};tt.prototype.extractField=function(t,e){e=e||{},this.fields||this._extractFields();var r=this._parsePreimageStructure(),n=this._generateBidirectionalASM(t,r,e.includeComments),i=this._extractSpecificField(t,r),o=this._interpretField(t,i,r);return{field:t,value:i?i.toString("hex"):null,buffer:i,asm:n,interpretation:o,strategy:this._getExtractionStrategy(t),structure:r._structure}};tt.prototype.generateASM=function(t,e){var r=this._parsePreimageStructure();return this._generateBidirectionalASM(t,r,e)};tt.prototype.extractFields=function(t){var e={};return t.forEach(function(r){e[r]=this.extractField(r)}.bind(this)),e};tt.prototype.validate=function(){var t=[],e=[];if(this.preimage.length<tt.MIN_PREIMAGE_LENGTH)return t.push("Preimage too short: "+this.preimage.length+" bytes (BIP-143 preimage requires at least "+tt.MIN_PREIMAGE_LENGTH+")"),{valid:!1,errors:t,warnings:e,sighashInfo:this.sighashInfo};this.fields||this._extractFields();var r=["version","hashPrevouts","hashSequence","outpoint","scriptCode","amount","sequence","hashOutputs","locktime","sighash"];return r.forEach(function(n){this.fields[n]||t.push("Missing required field: "+n)}.bind(this)),this.sighashInfo.hasZeroHashes&&e.push("Zero hashes detected - check SIGHASH flags: "+this.sighashInfo.zeroFields.join(", ")),{valid:t.length===0,errors:t,warnings:e,sighashInfo:this.sighashInfo}};tt.prototype.toObject=function(){return this.fields||this._extractFields(),{preimage:this.preimage.toString("hex"),length:this.preimage.length,strategy:this.strategy,fields:{version:this.fields.version?this.fields.version.toString("hex"):null,hashPrevouts:this.fields.hashPrevouts?this.fields.hashPrevouts.toString("hex"):null,hashSequence:this.fields.hashSequence?this.fields.hashSequence.toString("hex"):null,outpoint:this.fields.outpoint?this.fields.outpoint.toString("hex"):null,scriptCode:this.fields.scriptCode?this.fields.scriptCode.toString("hex"):null,scriptCodeLength:this.fields.scriptCodeLength,amount:this.fields.amount?this.fields.amount.toString("hex"):null,sequence:this.fields.sequence?this.fields.sequence.toString("hex"):null,hashOutputs:this.fields.hashOutputs?this.fields.hashOutputs.toString("hex"):null,locktime:this.fields.locktime?this.fields.locktime.toString("hex"):null,sighash:this.fields.sighash?this.fields.sighash.toString("hex"):null},sighashInfo:this.sighashInfo,validation:this.validate()}};tt.prototype._extractFields=function(){if(this.fields={},this.sighashInfo={flag:null,hasZeroHashes:!1,zeroFields:[],warnings:[]},this.preimage.length<tt.MIN_PREIMAGE_LENGTH)throw new Error("Preimage too short: "+this.preimage.length+" bytes (BIP-143 preimage requires at least "+tt.MIN_PREIMAGE_LENGTH+")");try{this.strategy==="LEFT"||this.strategy==="DYNAMIC"?this._extractFromLeft():this.strategy==="RIGHT"&&this._extractFromRight(),this._analyzeSighash()}catch(t){if(this.strategy==="DYNAMIC")try{this.strategy="RIGHT",this._extractFromRight(),this._analyzeSighash()}catch{throw new Error("Failed to extract preimage fields with any strategy: "+t.message)}else throw t}};tt.prototype._extractFromLeft=function(){var t=0;this.fields.version=this.preimage.slice(t,t+4),t+=4,this.fields.hashPrevouts=this.preimage.slice(t,t+32),t+=32,this.fields.hashSequence=this.preimage.slice(t,t+32),t+=32,this.fields.outpoint=this.preimage.slice(t,t+36),t+=36;var e=tt.decodeCompactSize(this.preimage,t);this.fields.scriptCodeLength=e.value,t=e.nextOffset,this.fields.scriptCode=this.preimage.slice(t,t+this.fields.scriptCodeLength),t+=this.fields.scriptCodeLength,this.fields.amount=this.preimage.slice(t,t+8),t+=8,this.fields.sequence=this.preimage.slice(t,t+4),t+=4,this.fields.hashOutputs=this.preimage.slice(t,t+32),t+=32,this.fields.locktime=this.preimage.slice(t,t+4),t+=4,this.fields.sighash=this.preimage.slice(t,t+4)};tt.prototype._extractFromRight=function(){var t=this.preimage.length,e=t;e-=4,this.fields.sighash=this.preimage.slice(e,e+4),e-=4,this.fields.locktime=this.preimage.slice(e,e+4),e-=32,this.fields.hashOutputs=this.preimage.slice(e,e+32),e-=4,this.fields.sequence=this.preimage.slice(e,e+4),e-=8,this.fields.amount=this.preimage.slice(e,e+8);var r=104,n=tt.decodeCompactSize(this.preimage,r);this.fields.scriptCodeLength=n.value,this.fields.scriptCode=this.preimage.slice(n.nextOffset,n.nextOffset+this.fields.scriptCodeLength),this.fields.version=this.preimage.slice(0,4),this.fields.hashPrevouts=this.preimage.slice(4,36),this.fields.hashSequence=this.preimage.slice(36,68),this.fields.outpoint=this.preimage.slice(68,104)};tt.prototype._analyzeSighash=function(){if(this.fields.sighash){var t=this.fields.sighash.readUInt32LE(0);this.sighashInfo.flag=t;var e=t&31,r=(t&128)!==0,n=(t&64)!==0,i=E.Buffer.alloc(32);r&&this.fields.hashPrevouts.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashPrevouts"),this.sighashInfo.warnings.push("ANYONECANPAY flag detected - hashPrevouts is zero")),e===2&&this.fields.hashSequence.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashSequence"),this.sighashInfo.warnings.push("SIGHASH_NONE flag detected - hashSequence is zero")),(e===2||e===3)&&this.fields.hashOutputs.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashOutputs"),this.sighashInfo.warnings.push("SIGHASH_NONE/SINGLE flag detected - hashOutputs is zero"));var o=[];e===1?o.push("ALL"):e===2?o.push("NONE"):e===3&&o.push("SINGLE"),r&&o.push("ANYONECANPAY"),n&&o.push("FORKID"),this.sighashInfo.flagName=o.join(" | ")}};tt.prototype._parsePreimageStructure=function(){for(var t=this.preimage,e=0,r={},n=[{name:"nVersion",len:4},{name:"hashPrevouts",len:32},{name:"hashSequence",len:32},{name:"outpoint_txid",len:32},{name:"outpoint_vout",len:4}],i=[{name:"value",len:8},{name:"nSequence",len:4},{name:"hashOutputs",len:32},{name:"nLocktime",len:4},{name:"sighashType",len:4}],o=0;o<n.length;o++){var c=n[o];r[c.name]=t.slice(e,e+c.len).toString("hex"),e+=c.len}var h=tt.decodeCompactSize(t,e);r.scriptLen=h.value,r.scriptLenSize=h.bytes,r.scriptLenRaw=t.slice(e,e+h.bytes).toString("hex"),e+=h.bytes,r.scriptCode=t.slice(e,e+r.scriptLen).toString("hex"),e+=r.scriptLen;for(var d=0;d<i.length;d++){var x=i[d];r[x.name]=t.slice(e,e+x.len).toString("hex"),e+=x.len}var v=n.reduce(function(A,O){return A+O.len},0),y=i.reduce(function(A,O){return A+O.len},0);return r._structure={leftFixed:v,scriptLenVarint:h.bytes,scriptCode:r.scriptLen,rightFixed:y,totalCalculated:v+h.bytes+r.scriptLen+y,totalActual:t.length},r};tt.prototype._generateBidirectionalASM=function(t,e,r){var n=["value","nSequence","hashOutputs","nLocktime","sighashType"],i=["nVersion","hashPrevouts","hashSequence","outpoint_txid","outpoint_vout"];if(n.includes(t))return this._generateRightExtractionASM(t,r);if(i.includes(t))return this._generateLeftExtractionASM(t,r);if(t==="scriptCode")return this._generateDynamicExtractionASM(e,r);if(t==="scriptLen")return this._generateScriptLenExtractionASM(e,r);throw new Error("Unknown field: "+t)};tt.prototype._generateRightExtractionASM=function(t,e){for(var r=[{name:"value",len:8},{name:"nSequence",len:4},{name:"hashOutputs",len:32},{name:"nLocktime",len:4},{name:"sighashType",len:4}],n=0,i=0,o=!1,c=0;c<r.length;c++){var h=r[c];if(h.name===t){i=h.len,o=!0;break}n+=h.len}if(!o)throw new Error("Field not found in RIGHT fields: "+t);var d=52,x=d-n,v=[];return e?(v.push("# \u{1F504} Extract "+t+" from RIGHT side (bidirectional strategy)"),v.push("OP_SIZE # Push preimage size: [preimage, size]")):v.push("OP_SIZE"),e?v=v.concat([x+" OP_SUB # Calculate split point: [preimage, split_point]","OP_SPLIT # Split: [left_part, right_part]","OP_NIP # Drop left (OP_SPLIT leaves right on top): [right_part]",i+" OP_SPLIT # Extract field: ["+t+", remaining]","OP_DROP # Clean up: ["+t+"]","# \u2705 Result: "+t+" is now on top of stack"]):v=v.concat([x+" OP_SUB","OP_SPLIT","OP_NIP",i+" OP_SPLIT","OP_DROP"]),v.join(`
|
|
1
|
+
var bsvSmartContract=(()=>{var yf=Object.create;var kn=Object.defineProperty;var wf=Object.getOwnPropertyDescriptor;var bf=Object.getOwnPropertyNames;var Sf=Object.getPrototypeOf,Ef=Object.prototype.hasOwnProperty;var _f=(t,e,r)=>e in t?kn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var ve=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ae=(t,e,r)=>()=>{if(r)throw r[0];try{return t&&(e=t(t=0)),e}catch(n){throw r=[n],n}};var Z=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Of=(t,e)=>{for(var r in e)kn(t,r,{get:e[r],enumerable:!0})},na=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of bf(e))!Ef.call(t,i)&&i!==r&&kn(t,i,{get:()=>e[i],enumerable:!(n=wf(e,i))||n.enumerable});return t};var ia=(t,e,r)=>(r=t!=null?yf(Sf(t)):{},na(e||!t||!t.__esModule?kn(r,"default",{value:t,enumerable:!0}):r,t)),Af=t=>na(kn({},"__esModule",{value:!0}),t);var W=(t,e,r)=>_f(t,typeof e!="symbol"?e+"":e,r);var ua=Z((Bp,ca)=>{I();var Rt=ca.exports={},je,Ye;function co(){throw new Error("setTimeout has not been defined")}function uo(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?je=setTimeout:je=co}catch{je=co}try{typeof clearTimeout=="function"?Ye=clearTimeout:Ye=uo}catch{Ye=uo}})();function oa(t){if(je===setTimeout)return setTimeout(t,0);if((je===co||!je)&&setTimeout)return je=setTimeout,setTimeout(t,0);try{return je(t,0)}catch{try{return je.call(null,t,0)}catch{return je.call(this,t,0)}}}function If(t){if(Ye===clearTimeout)return clearTimeout(t);if((Ye===uo||!Ye)&&clearTimeout)return Ye=clearTimeout,clearTimeout(t);try{return Ye(t)}catch{try{return Ye.call(null,t)}catch{return Ye.call(this,t)}}}var ur=[],Wr=!1,kr,ri=-1;function Pf(){!Wr||!kr||(Wr=!1,kr.length?ur=kr.concat(ur):ri=-1,ur.length&&sa())}function sa(){if(!Wr){var t=oa(Pf);Wr=!0;for(var e=ur.length;e;){for(kr=ur,ur=[];++ri<e;)kr&&kr[ri].run();ri=-1,e=ur.length}kr=null,Wr=!1,If(t)}}Rt.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];ur.push(new aa(t,e)),ur.length===1&&!Wr&&oa(sa)};function aa(t,e){this.fun=t,this.array=e}aa.prototype.run=function(){this.fun.apply(null,this.array)};Rt.title="browser";Rt.browser=!0;Rt.env={};Rt.argv=[];Rt.version="";Rt.versions={};function hr(){}Rt.on=hr;Rt.addListener=hr;Rt.once=hr;Rt.off=hr;Rt.removeListener=hr;Rt.removeAllListeners=hr;Rt.emit=hr;Rt.prependListener=hr;Rt.prependOnceListener=hr;Rt.listeners=function(t){return[]};Rt.binding=function(t){throw new Error("process.binding is not supported")};Rt.cwd=function(){return"/"};Rt.chdir=function(t){throw new Error("process.chdir is not supported")};Rt.umask=function(){return 0}});var la=Z(ni=>{"use strict";I();ni.byteLength=Bf;ni.toByteArray=Rf;ni.fromByteArray=Hf;var $e=[],ke=[],Tf=typeof Uint8Array<"u"?Uint8Array:Array,ho="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Fr=0,ha=ho.length;Fr<ha;++Fr)$e[Fr]=ho[Fr],ke[ho.charCodeAt(Fr)]=Fr;var Fr,ha;ke[45]=62;ke[95]=63;function fa(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Bf(t){var e=fa(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Mf(t,e,r){return(e+r)*3/4-r}function Rf(t){var e,r=fa(t),n=r[0],i=r[1],o=new Tf(Mf(t,n,i)),c=0,h=i>0?n-4:n,d;for(d=0;d<h;d+=4)e=ke[t.charCodeAt(d)]<<18|ke[t.charCodeAt(d+1)]<<12|ke[t.charCodeAt(d+2)]<<6|ke[t.charCodeAt(d+3)],o[c++]=e>>16&255,o[c++]=e>>8&255,o[c++]=e&255;return i===2&&(e=ke[t.charCodeAt(d)]<<2|ke[t.charCodeAt(d+1)]>>4,o[c++]=e&255),i===1&&(e=ke[t.charCodeAt(d)]<<10|ke[t.charCodeAt(d+1)]<<4|ke[t.charCodeAt(d+2)]>>2,o[c++]=e>>8&255,o[c++]=e&255),o}function kf(t){return $e[t>>18&63]+$e[t>>12&63]+$e[t>>6&63]+$e[t&63]}function Ff(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(kf(n));return i.join("")}function Hf(t){for(var e,r=t.length,n=r%3,i=[],o=16383,c=0,h=r-n;c<h;c+=o)i.push(Ff(t,c,c+o>h?h:c+o));return n===1?(e=t[r-1],i.push($e[e>>2]+$e[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push($e[e>>10]+$e[e>>4&63]+$e[e<<2&63]+"=")),i.join("")}});var da=Z(fo=>{I();fo.read=function(t,e,r,n,i){var o,c,h=i*8-n-1,d=(1<<h)-1,x=d>>1,v=-7,y=r?i-1:0,A=r?-1:1,O=t[e+y];for(y+=A,o=O&(1<<-v)-1,O>>=-v,v+=h;v>0;o=o*256+t[e+y],y+=A,v-=8);for(c=o&(1<<-v)-1,o>>=-v,v+=n;v>0;c=c*256+t[e+y],y+=A,v-=8);if(o===0)o=1-x;else{if(o===d)return c?NaN:(O?-1:1)*(1/0);c=c+Math.pow(2,n),o=o-x}return(O?-1:1)*c*Math.pow(2,o-n)};fo.write=function(t,e,r,n,i,o){var c,h,d,x=o*8-i-1,v=(1<<x)-1,y=v>>1,A=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,O=n?0:o-1,T=n?1:-1,L=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(h=isNaN(e)?1:0,c=v):(c=Math.floor(Math.log(e)/Math.LN2),e*(d=Math.pow(2,-c))<1&&(c--,d*=2),c+y>=1?e+=A/d:e+=A*Math.pow(2,1-y),e*d>=2&&(c++,d/=2),c+y>=v?(h=0,c=v):c+y>=1?(h=(e*d-1)*Math.pow(2,i),c=c+y):(h=e*Math.pow(2,y-1)*Math.pow(2,i),c=0));i>=8;t[r+O]=h&255,O+=T,h/=256,i-=8);for(c=c<<i|h,x+=i;x>0;t[r+O]=c&255,O+=T,c/=256,x-=8);t[r+O-T]|=L*128}});var si=Z(en=>{"use strict";I();var lo=la(),Jr=da(),pa=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;en.Buffer=B;en.SlowBuffer=Df;en.INSPECT_MAX_BYTES=50;var ii=2147483647;en.kMaxLength=ii;B.TYPED_ARRAY_SUPPORT=Lf();!B.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Lf(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(B.prototype,"parent",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.buffer}});Object.defineProperty(B.prototype,"offset",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.byteOffset}});function fr(t){if(t>ii)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,B.prototype),e}function B(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return vo(t)}return xa(t,e,r)}B.poolSize=8192;function xa(t,e,r){if(typeof t=="string")return Nf(t,e);if(ArrayBuffer.isView(t))return Uf(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Ze(t,ArrayBuffer)||t&&Ze(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ze(t,SharedArrayBuffer)||t&&Ze(t.buffer,SharedArrayBuffer)))return mo(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return B.from(n,e,r);let i=qf(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return B.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}B.from=function(t,e,r){return xa(t,e,r)};Object.setPrototypeOf(B.prototype,Uint8Array.prototype);Object.setPrototypeOf(B,Uint8Array);function ya(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function Cf(t,e,r){return ya(t),t<=0?fr(t):e!==void 0?typeof r=="string"?fr(t).fill(e,r):fr(t).fill(e):fr(t)}B.alloc=function(t,e,r){return Cf(t,e,r)};function vo(t){return ya(t),fr(t<0?0:xo(t)|0)}B.allocUnsafe=function(t){return vo(t)};B.allocUnsafeSlow=function(t){return vo(t)};function Nf(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!B.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=wa(t,e)|0,n=fr(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function po(t){let e=t.length<0?0:xo(t.length)|0,r=fr(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Uf(t){if(Ze(t,Uint8Array)){let e=new Uint8Array(t);return mo(e.buffer,e.byteOffset,e.byteLength)}return po(t)}function mo(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,B.prototype),n}function qf(t){if(B.isBuffer(t)){let e=xo(t.length)|0,r=fr(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||wo(t.length)?fr(0):po(t);if(t.type==="Buffer"&&Array.isArray(t.data))return po(t.data)}function xo(t){if(t>=ii)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ii.toString(16)+" bytes");return t|0}function Df(t){return+t!=t&&(t=0),B.alloc(+t)}B.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==B.prototype};B.compare=function(e,r){if(Ze(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),Ze(r,Uint8Array)&&(r=B.from(r,r.offset,r.byteLength)),!B.isBuffer(e)||!B.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,c=Math.min(n,i);o<c;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};B.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};B.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return B.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=B.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let c=e[n];if(Ze(c,Uint8Array))o+c.length>i.length?(B.isBuffer(c)||(c=B.from(c)),c.copy(i,o)):Uint8Array.prototype.set.call(i,c,o);else if(B.isBuffer(c))c.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=c.length}return i};function wa(t,e){if(B.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Ze(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return go(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Ta(t).length;default:if(i)return n?-1:go(t).length;e=(""+e).toLowerCase(),i=!0}}B.byteLength=wa;function Gf(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return Qf(this,e,r);case"utf8":case"utf-8":return Sa(this,e,r);case"ascii":return Xf(this,e,r);case"latin1":case"binary":return Wf(this,e,r);case"base64":return $f(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Jf(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}B.prototype._isBuffer=!0;function Hr(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}B.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)Hr(this,r,r+1);return this};B.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)Hr(this,r,r+3),Hr(this,r+1,r+2);return this};B.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)Hr(this,r,r+7),Hr(this,r+1,r+6),Hr(this,r+2,r+5),Hr(this,r+3,r+4);return this};B.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Sa(this,0,e):Gf.apply(this,arguments)};B.prototype.toLocaleString=B.prototype.toString;B.prototype.equals=function(e){if(!B.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:B.compare(this,e)===0};B.prototype.inspect=function(){let e="",r=en.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};pa&&(B.prototype[pa]=B.prototype.inspect);B.prototype.compare=function(e,r,n,i,o){if(Ze(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),!B.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let c=o-i,h=n-r,d=Math.min(c,h),x=this.slice(i,o),v=e.slice(r,n);for(let y=0;y<d;++y)if(x[y]!==v[y]){c=x[y],h=v[y];break}return c<h?-1:h<c?1:0};function ba(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,wo(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=B.from(e,n)),B.isBuffer(e))return e.length===0?-1:ma(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):ma(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ma(t,e,r,n,i){let o=1,c=t.length,h=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,c/=2,h/=2,r/=2}function d(v,y){return o===1?v[y]:v.readUInt16BE(y*o)}let x;if(i){let v=-1;for(x=r;x<c;x++)if(d(t,x)===d(e,v===-1?0:x-v)){if(v===-1&&(v=x),x-v+1===h)return v*o}else v!==-1&&(x-=x-v),v=-1}else for(r+h>c&&(r=c-h),x=r;x>=0;x--){let v=!0;for(let y=0;y<h;y++)if(d(t,x+y)!==d(e,y)){v=!1;break}if(v)return x}return-1}B.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};B.prototype.indexOf=function(e,r,n){return ba(this,e,r,n,!0)};B.prototype.lastIndexOf=function(e,r,n){return ba(this,e,r,n,!1)};function zf(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let c;for(c=0;c<n;++c){let h=parseInt(e.substr(c*2,2),16);if(wo(h))return c;t[r+c]=h}return c}function Vf(t,e,r,n){return oi(go(e,t.length-r),t,r,n)}function Kf(t,e,r,n){return oi(nl(e),t,r,n)}function jf(t,e,r,n){return oi(Ta(e),t,r,n)}function Yf(t,e,r,n){return oi(il(e,t.length-r),t,r,n)}B.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let c=!1;for(;;)switch(i){case"hex":return zf(this,e,r,n);case"utf8":case"utf-8":return Vf(this,e,r,n);case"ascii":case"latin1":case"binary":return Kf(this,e,r,n);case"base64":return jf(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Yf(this,e,r,n);default:if(c)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),c=!0}};B.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function $f(t,e,r){return e===0&&r===t.length?lo.fromByteArray(t):lo.fromByteArray(t.slice(e,r))}function Sa(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],c=null,h=o>239?4:o>223?3:o>191?2:1;if(i+h<=r){let d,x,v,y;switch(h){case 1:o<128&&(c=o);break;case 2:d=t[i+1],(d&192)===128&&(y=(o&31)<<6|d&63,y>127&&(c=y));break;case 3:d=t[i+1],x=t[i+2],(d&192)===128&&(x&192)===128&&(y=(o&15)<<12|(d&63)<<6|x&63,y>2047&&(y<55296||y>57343)&&(c=y));break;case 4:d=t[i+1],x=t[i+2],v=t[i+3],(d&192)===128&&(x&192)===128&&(v&192)===128&&(y=(o&15)<<18|(d&63)<<12|(x&63)<<6|v&63,y>65535&&y<1114112&&(c=y))}}c===null?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|c&1023),n.push(c),i+=h}return Zf(n)}var ga=4096;function Zf(t){let e=t.length;if(e<=ga)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=ga));return r}function Xf(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function Wf(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function Qf(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=ol[t[o]];return i}function Jf(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}B.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,B.prototype),i};function he(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}B.prototype.readUintLE=B.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e],o=1,c=0;for(;++c<r&&(o*=256);)i+=this[e+c]*o;return i};B.prototype.readUintBE=B.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};B.prototype.readUint8=B.prototype.readUInt8=function(e,r){return e=e>>>0,r||he(e,1,this.length),this[e]};B.prototype.readUint16LE=B.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||he(e,2,this.length),this[e]|this[e+1]<<8};B.prototype.readUint16BE=B.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||he(e,2,this.length),this[e]<<8|this[e+1]};B.prototype.readUint32LE=B.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||he(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};B.prototype.readUint32BE=B.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};B.prototype.readBigUInt64LE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});B.prototype.readBigUInt64BE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});B.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=this[e],o=1,c=0;for(;++c<r&&(o*=256);)i+=this[e+c]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};B.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||he(e,r,this.length);let i=r,o=1,c=this[e+--i];for(;i>0&&(o*=256);)c+=this[e+--i]*o;return o*=128,c>=o&&(c-=Math.pow(2,8*r)),c};B.prototype.readInt8=function(e,r){return e=e>>>0,r||he(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};B.prototype.readInt16LE=function(e,r){e=e>>>0,r||he(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};B.prototype.readInt16BE=function(e,r){e=e>>>0,r||he(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};B.prototype.readInt32LE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};B.prototype.readInt32BE=function(e,r){return e=e>>>0,r||he(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};B.prototype.readBigInt64LE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});B.prototype.readBigInt64BE=Ir(function(e){e=e>>>0,tn(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fn(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});B.prototype.readFloatLE=function(e,r){return e=e>>>0,r||he(e,4,this.length),Jr.read(this,e,!0,23,4)};B.prototype.readFloatBE=function(e,r){return e=e>>>0,r||he(e,4,this.length),Jr.read(this,e,!1,23,4)};B.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||he(e,8,this.length),Jr.read(this,e,!0,52,8)};B.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||he(e,8,this.length),Jr.read(this,e,!1,52,8)};function be(t,e,r,n,i,o){if(!B.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}B.prototype.writeUintLE=B.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let h=Math.pow(2,8*n)-1;be(this,e,r,n,h,0)}let o=1,c=0;for(this[r]=e&255;++c<n&&(o*=256);)this[r+c]=e/o&255;return r+n};B.prototype.writeUintBE=B.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let h=Math.pow(2,8*n)-1;be(this,e,r,n,h,0)}let o=n-1,c=1;for(this[r+o]=e&255;--o>=0&&(c*=256);)this[r+o]=e/c&255;return r+n};B.prototype.writeUint8=B.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,1,255,0),this[r]=e&255,r+1};B.prototype.writeUint16LE=B.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};B.prototype.writeUint16BE=B.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};B.prototype.writeUint32LE=B.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};B.prototype.writeUint32BE=B.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Ea(t,e,r,n,i){Pa(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let c=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=c,c=c>>8,t[r++]=c,c=c>>8,t[r++]=c,c=c>>8,t[r++]=c,r}function _a(t,e,r,n,i){Pa(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let c=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=c,c=c>>8,t[r+2]=c,c=c>>8,t[r+1]=c,c=c>>8,t[r]=c,r+8}B.prototype.writeBigUInt64LE=Ir(function(e,r=0){return Ea(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeBigUInt64BE=Ir(function(e,r=0){return _a(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let d=Math.pow(2,8*n-1);be(this,e,r,n,d-1,-d)}let o=0,c=1,h=0;for(this[r]=e&255;++o<n&&(c*=256);)e<0&&h===0&&this[r+o-1]!==0&&(h=1),this[r+o]=(e/c>>0)-h&255;return r+n};B.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let d=Math.pow(2,8*n-1);be(this,e,r,n,d-1,-d)}let o=n-1,c=1,h=0;for(this[r+o]=e&255;--o>=0&&(c*=256);)e<0&&h===0&&this[r+o+1]!==0&&(h=1),this[r+o]=(e/c>>0)-h&255;return r+n};B.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};B.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};B.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};B.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};B.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||be(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};B.prototype.writeBigInt64LE=Ir(function(e,r=0){return Ea(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});B.prototype.writeBigInt64BE=Ir(function(e,r=0){return _a(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Oa(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Aa(t,e,r,n,i){return e=+e,r=r>>>0,i||Oa(t,e,r,4,34028234663852886e22,-34028234663852886e22),Jr.write(t,e,r,n,23,4),r+4}B.prototype.writeFloatLE=function(e,r,n){return Aa(this,e,r,!0,n)};B.prototype.writeFloatBE=function(e,r,n){return Aa(this,e,r,!1,n)};function Ia(t,e,r,n,i){return e=+e,r=r>>>0,i||Oa(t,e,r,8,17976931348623157e292,-17976931348623157e292),Jr.write(t,e,r,n,52,8),r+8}B.prototype.writeDoubleLE=function(e,r,n){return Ia(this,e,r,!0,n)};B.prototype.writeDoubleBE=function(e,r,n){return Ia(this,e,r,!1,n)};B.prototype.copy=function(e,r,n,i){if(!B.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};B.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!B.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let c=e.charCodeAt(0);(i==="utf8"&&c<128||i==="latin1")&&(e=c)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let c=B.isBuffer(e)?e:B.from(e,i),h=c.length;if(h===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=c[o%h]}return this};var Qr={};function yo(t,e,r){Qr[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}yo("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);yo("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);yo("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=va(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=va(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function va(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function tl(t,e,r){tn(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Fn(e,t.length-(r+1))}function Pa(t,e,r,n,i,o){if(t>r||t<e){let c=typeof e=="bigint"?"n":"",h;throw o>3?e===0||e===BigInt(0)?h=`>= 0${c} and < 2${c} ** ${(o+1)*8}${c}`:h=`>= -(2${c} ** ${(o+1)*8-1}${c}) and < 2 ** ${(o+1)*8-1}${c}`:h=`>= ${e}${c} and <= ${r}${c}`,new Qr.ERR_OUT_OF_RANGE("value",h,t)}tl(n,i,o)}function tn(t,e){if(typeof t!="number")throw new Qr.ERR_INVALID_ARG_TYPE(e,"number",t)}function Fn(t,e,r){throw Math.floor(t)!==t?(tn(t,r),new Qr.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new Qr.ERR_BUFFER_OUT_OF_BOUNDS:new Qr.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var el=/[^+/0-9A-Za-z-_]/g;function rl(t){if(t=t.split("=")[0],t=t.trim().replace(el,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function go(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let c=0;c<n;++c){if(r=t.charCodeAt(c),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(c+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function nl(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function il(t,e){let r,n,i,o=[];for(let c=0;c<t.length&&!((e-=2)<0);++c)r=t.charCodeAt(c),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Ta(t){return lo.toByteArray(rl(t))}function oi(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Ze(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function wo(t){return t!==t}var ol=(function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e})();function Ir(t){return typeof BigInt>"u"?sl:t}function sl(){throw new Error("BigInt not supported")}});var N,E,I=Ae(()=>{N=ia(ua()),E=ia(si())});var de=Z((qp,Ba)=>{I();Ba.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var se=Z((Gp,Ma)=>{"use strict";I();Ma.exports={}});var Fa=Z((Vp,ka)=>{"use strict";I();var At=de(),Ra=se(),lr;try{lr=se()}catch{lr=null}var al=function(){var t=typeof N.default<"u"&&N.default.env&&N.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG;t&&console.log.apply(console,arguments)};function Se(t,e){if(!(this instanceof Se))return new Se(t,e);this.privateKey=t,this.publicKey=t.publicKey,this.address=t.toAddress(),e=e||{},this.storageDir=e.storageDir||(typeof N.default<"u"?Ra.join(N.default.cwd(),".bsv-covenants"):".bsv-covenants"),this.covenantUtxoPath=Ra.join(this.storageDir,"covenant_utxos.json"),this.sighashType=At.crypto.Signature.SIGHASH_ALL|At.crypto.Signature.SIGHASH_FORKID,this.allowNonEnforcing=e.allowNonEnforcing===!0,lr&&this._ensureStorageDir()}Se.prototype.createFromP2PKH=function(t){if(!this.allowNonEnforcing)throw new Error("SmartContract.Covenant builds a NON-ENFORCING script that reduces to plain P2PK \u2014 it does not constrain the spend. Use SmartContract.PushTx.valueCovenant (output binding) or SmartContract.Token / perpetualCovenant (stateful covenants) for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.");t.script||(t.script=Se.reconstructP2pkhScript(this.address));var e=new At.Transaction().from({txId:t.txid,outputIndex:t.vout,script:t.script,satoshis:t.satoshis}).to(this.address,t.satoshis-1e3),r=At.Script.fromHex(t.script),n=At.Transaction.sighash.sighashPreimage(e,this.sighashType,0,r,new At.crypto.BN(t.satoshis)),i=At.crypto.Hash.sha256sha256(n),o=new At.Script().add("OP_DUP").add("OP_HASH256").add(i).add("OP_EQUALVERIFY").add("OP_DROP").add(this.publicKey.toBuffer()).add("OP_CHECKSIG");e.outputs[0].setScript(o),e.sign(this.privateKey);var c={txid:e.id,vout:0,satoshis:t.satoshis-1e3,script:o.toHex(),scriptPubKey:o.toHex(),preimageHash:i.toString("hex"),originalPreimage:n.toString("hex"),status:"local",createdAt:new Date().toISOString(),type:"preimage_covenant"};return{transaction:e,covenantUtxo:c}};Se.prototype.createSpendingTx=function(t,e,r){var n=e||this.address,i=r||t.satoshis-500,o=new At.Transaction;o.addInput(new At.Transaction.Input({prevTxId:t.txid,outputIndex:t.vout,script:At.Script.empty()}),At.Script.fromHex(t.script),t.satoshis),o.to(n,i);var c=At.Script.fromHex(t.script),h=At.Transaction.sighash.sign(o,this.privateKey,this.sighashType,0,c,new At.crypto.BN(t.satoshis)),d=E.Buffer.concat([h.toDER(),E.Buffer.from([this.sighashType])]),x=E.Buffer.from(t.originalPreimage,"hex"),v=new At.Script().add(d).add(x);return o.inputs[0].setScript(v),o};Se.prototype.validate=function(t,e){var r=new At.Script.Interpreter,n=At.Script.Interpreter.SCRIPT_VERIFY_P2SH|At.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|At.Script.Interpreter.SCRIPT_VERIFY_DERSIG|At.Script.Interpreter.SCRIPT_VERIFY_LOW_S|At.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,i=t.inputs[0].script,o=At.Script.fromHex(e.script),c=r.verify(i,o,t,0,n,new At.crypto.BN(e.satoshis));return{valid:c,error:c?null:r.errstr}};Se.prototype.save=function(t){if(!lr)return al("File system operations not available in browser environment"),t;var e=this.list();return e.push(t),lr.writeFileSync(this.covenantUtxoPath,JSON.stringify(e,null,2)),t};Se.prototype.load=function(t){var e=this.list();if(t){var r=e.find(function(n){return n.txid===t});if(!r)throw new Error("Covenant UTXO with TXID "+t+" not found");return r}else{var r=e.find(function(i){return i.type==="preimage_covenant"});if(!r)throw new Error("No preimage covenant UTXO found");return r}};Se.prototype.list=function(){return lr.existsSync(this.covenantUtxoPath)?JSON.parse(lr.readFileSync(this.covenantUtxoPath,"utf8")):[]};Se.prototype.getPortfolio=function(){var t=this.list(),e={total:t.length,totalValue:t.reduce(function(r,n){return r+n.satoshis},0),byStatus:{},recent:t.slice(-5)};return t.forEach(function(r){var n=r.status||"local";e.byStatus[n]||(e.byStatus[n]={count:0,value:0}),e.byStatus[n].count++,e.byStatus[n].value+=r.satoshis}),e};Se.prototype.completeFlow=function(t,e){var r=this.createFromP2PKH(t),n=this.save(r.covenantUtxo);e&&e(r.transaction,"creation");var i=this.createSpendingTx(n),o=this.validate(i,n);return e&&o.valid&&e(i,"spending"),{creationTx:r.transaction,spendingTx:i,covenantUtxo:n,validation:o,success:o.valid}};Se.prototype._ensureStorageDir=function(){lr.existsSync(this.storageDir)||lr.mkdirSync(this.storageDir,{recursive:!0})};Se.reconstructP2pkhScript=function(t){return At.Script.buildPublicKeyHashOut(t).toHex()};ka.exports=Se});var Xe=Z((Yp,Ha)=>{"use strict";I();var rn=de(),jp=se();function tt(t,e){if(!(this instanceof tt))return new tt(t,e);this.preimage=E.Buffer.isBuffer(t)?t:E.Buffer.from(t,"hex"),this.options=e||{},this.strategy=this.options.strategy||"DYNAMIC",this.fields=null,this.sighashInfo=null,this.options.deferExtraction||this._extractFields()}tt.LEFT_FIXED_LENGTH=104;tt.RIGHT_FIXED_LENGTH=52;tt.MIN_PREIMAGE_LENGTH=tt.LEFT_FIXED_LENGTH+1+tt.RIGHT_FIXED_LENGTH;tt.prototype.extract=function(t){return this.strategy=t||this.strategy,this._extractFields(),this.fields};tt.prototype.getSighashInfo=function(){return this.fields||this._extractFields(),this.sighashInfo};tt.prototype.getField=function(t){return this.fields||this._extractFields(),this.fields[t]};tt.prototype.extractField=function(t,e){e=e||{},this.fields||this._extractFields();var r=this._parsePreimageStructure(),n=this._generateBidirectionalASM(t,r,e.includeComments),i=this._extractSpecificField(t,r),o=this._interpretField(t,i,r);return{field:t,value:i?i.toString("hex"):null,buffer:i,asm:n,interpretation:o,strategy:this._getExtractionStrategy(t),structure:r._structure}};tt.prototype.generateASM=function(t,e){var r=this._parsePreimageStructure();return this._generateBidirectionalASM(t,r,e)};tt.prototype.extractFields=function(t){var e={};return t.forEach(function(r){e[r]=this.extractField(r)}.bind(this)),e};tt.prototype.validate=function(){var t=[],e=[];if(this.preimage.length<tt.MIN_PREIMAGE_LENGTH)return t.push("Preimage too short: "+this.preimage.length+" bytes (BIP-143 preimage requires at least "+tt.MIN_PREIMAGE_LENGTH+")"),{valid:!1,errors:t,warnings:e,sighashInfo:this.sighashInfo};this.fields||this._extractFields();var r=["version","hashPrevouts","hashSequence","outpoint","scriptCode","amount","sequence","hashOutputs","locktime","sighash"];return r.forEach(function(n){this.fields[n]||t.push("Missing required field: "+n)}.bind(this)),this.sighashInfo.hasZeroHashes&&e.push("Zero hashes detected - check SIGHASH flags: "+this.sighashInfo.zeroFields.join(", ")),{valid:t.length===0,errors:t,warnings:e,sighashInfo:this.sighashInfo}};tt.prototype.toObject=function(){return this.fields||this._extractFields(),{preimage:this.preimage.toString("hex"),length:this.preimage.length,strategy:this.strategy,fields:{version:this.fields.version?this.fields.version.toString("hex"):null,hashPrevouts:this.fields.hashPrevouts?this.fields.hashPrevouts.toString("hex"):null,hashSequence:this.fields.hashSequence?this.fields.hashSequence.toString("hex"):null,outpoint:this.fields.outpoint?this.fields.outpoint.toString("hex"):null,scriptCode:this.fields.scriptCode?this.fields.scriptCode.toString("hex"):null,scriptCodeLength:this.fields.scriptCodeLength,amount:this.fields.amount?this.fields.amount.toString("hex"):null,sequence:this.fields.sequence?this.fields.sequence.toString("hex"):null,hashOutputs:this.fields.hashOutputs?this.fields.hashOutputs.toString("hex"):null,locktime:this.fields.locktime?this.fields.locktime.toString("hex"):null,sighash:this.fields.sighash?this.fields.sighash.toString("hex"):null},sighashInfo:this.sighashInfo,validation:this.validate()}};tt.prototype._extractFields=function(){if(this.fields={},this.sighashInfo={flag:null,hasZeroHashes:!1,zeroFields:[],warnings:[]},this.preimage.length<tt.MIN_PREIMAGE_LENGTH)throw new Error("Preimage too short: "+this.preimage.length+" bytes (BIP-143 preimage requires at least "+tt.MIN_PREIMAGE_LENGTH+")");try{this.strategy==="LEFT"||this.strategy==="DYNAMIC"?this._extractFromLeft():this.strategy==="RIGHT"&&this._extractFromRight(),this._analyzeSighash()}catch(t){if(this.strategy==="DYNAMIC")try{this.strategy="RIGHT",this._extractFromRight(),this._analyzeSighash()}catch{throw new Error("Failed to extract preimage fields with any strategy: "+t.message)}else throw t}};tt.prototype._extractFromLeft=function(){var t=0;this.fields.version=this.preimage.slice(t,t+4),t+=4,this.fields.hashPrevouts=this.preimage.slice(t,t+32),t+=32,this.fields.hashSequence=this.preimage.slice(t,t+32),t+=32,this.fields.outpoint=this.preimage.slice(t,t+36),t+=36;var e=tt.decodeCompactSize(this.preimage,t);this.fields.scriptCodeLength=e.value,t=e.nextOffset,this.fields.scriptCode=this.preimage.slice(t,t+this.fields.scriptCodeLength),t+=this.fields.scriptCodeLength,this.fields.amount=this.preimage.slice(t,t+8),t+=8,this.fields.sequence=this.preimage.slice(t,t+4),t+=4,this.fields.hashOutputs=this.preimage.slice(t,t+32),t+=32,this.fields.locktime=this.preimage.slice(t,t+4),t+=4,this.fields.sighash=this.preimage.slice(t,t+4)};tt.prototype._extractFromRight=function(){var t=this.preimage.length,e=t;e-=4,this.fields.sighash=this.preimage.slice(e,e+4),e-=4,this.fields.locktime=this.preimage.slice(e,e+4),e-=32,this.fields.hashOutputs=this.preimage.slice(e,e+32),e-=4,this.fields.sequence=this.preimage.slice(e,e+4),e-=8,this.fields.amount=this.preimage.slice(e,e+8);var r=104,n=tt.decodeCompactSize(this.preimage,r);this.fields.scriptCodeLength=n.value,this.fields.scriptCode=this.preimage.slice(n.nextOffset,n.nextOffset+this.fields.scriptCodeLength),this.fields.version=this.preimage.slice(0,4),this.fields.hashPrevouts=this.preimage.slice(4,36),this.fields.hashSequence=this.preimage.slice(36,68),this.fields.outpoint=this.preimage.slice(68,104)};tt.prototype._analyzeSighash=function(){if(this.fields.sighash){var t=this.fields.sighash.readUInt32LE(0);this.sighashInfo.flag=t;var e=t&31,r=(t&128)!==0,n=(t&64)!==0,i=E.Buffer.alloc(32);r&&this.fields.hashPrevouts.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashPrevouts"),this.sighashInfo.warnings.push("ANYONECANPAY flag detected - hashPrevouts is zero")),e===2&&this.fields.hashSequence.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashSequence"),this.sighashInfo.warnings.push("SIGHASH_NONE flag detected - hashSequence is zero")),(e===2||e===3)&&this.fields.hashOutputs.equals(i)&&(this.sighashInfo.hasZeroHashes=!0,this.sighashInfo.zeroFields.push("hashOutputs"),this.sighashInfo.warnings.push("SIGHASH_NONE/SINGLE flag detected - hashOutputs is zero"));var o=[];e===1?o.push("ALL"):e===2?o.push("NONE"):e===3&&o.push("SINGLE"),r&&o.push("ANYONECANPAY"),n&&o.push("FORKID"),this.sighashInfo.flagName=o.join(" | ")}};tt.prototype._parsePreimageStructure=function(){for(var t=this.preimage,e=0,r={},n=[{name:"nVersion",len:4},{name:"hashPrevouts",len:32},{name:"hashSequence",len:32},{name:"outpoint_txid",len:32},{name:"outpoint_vout",len:4}],i=[{name:"value",len:8},{name:"nSequence",len:4},{name:"hashOutputs",len:32},{name:"nLocktime",len:4},{name:"sighashType",len:4}],o=0;o<n.length;o++){var c=n[o];r[c.name]=t.slice(e,e+c.len).toString("hex"),e+=c.len}var h=tt.decodeCompactSize(t,e);r.scriptLen=h.value,r.scriptLenSize=h.bytes,r.scriptLenRaw=t.slice(e,e+h.bytes).toString("hex"),e+=h.bytes,r.scriptCode=t.slice(e,e+r.scriptLen).toString("hex"),e+=r.scriptLen;for(var d=0;d<i.length;d++){var x=i[d];r[x.name]=t.slice(e,e+x.len).toString("hex"),e+=x.len}var v=n.reduce(function(A,O){return A+O.len},0),y=i.reduce(function(A,O){return A+O.len},0);return r._structure={leftFixed:v,scriptLenVarint:h.bytes,scriptCode:r.scriptLen,rightFixed:y,totalCalculated:v+h.bytes+r.scriptLen+y,totalActual:t.length},r};tt.prototype._generateBidirectionalASM=function(t,e,r){var n=["value","nSequence","hashOutputs","nLocktime","sighashType"],i=["nVersion","hashPrevouts","hashSequence","outpoint_txid","outpoint_vout"];if(n.includes(t))return this._generateRightExtractionASM(t,r);if(i.includes(t))return this._generateLeftExtractionASM(t,r);if(t==="scriptCode")return this._generateDynamicExtractionASM(e,r);if(t==="scriptLen")return this._generateScriptLenExtractionASM(e,r);throw new Error("Unknown field: "+t)};tt.prototype._generateRightExtractionASM=function(t,e){for(var r=[{name:"value",len:8},{name:"nSequence",len:4},{name:"hashOutputs",len:32},{name:"nLocktime",len:4},{name:"sighashType",len:4}],n=0,i=0,o=!1,c=0;c<r.length;c++){var h=r[c];if(h.name===t){i=h.len,o=!0;break}n+=h.len}if(!o)throw new Error("Field not found in RIGHT fields: "+t);var d=52,x=d-n,v=[];return e?(v.push("# \u{1F504} Extract "+t+" from RIGHT side (bidirectional strategy)"),v.push("OP_SIZE # Push preimage size: [preimage, size]")):v.push("OP_SIZE"),e?v=v.concat([x+" OP_SUB # Calculate split point: [preimage, split_point]","OP_SPLIT # Split: [left_part, right_part]","OP_NIP # Drop left (OP_SPLIT leaves right on top): [right_part]",i+" OP_SPLIT # Extract field: ["+t+", remaining]","OP_DROP # Clean up: ["+t+"]","# \u2705 Result: "+t+" is now on top of stack"]):v=v.concat([x+" OP_SUB","OP_SPLIT","OP_NIP",i+" OP_SPLIT","OP_DROP"]),v.join(`
|
|
2
2
|
`)};tt.prototype._generateLeftExtractionASM=function(t,e){var r=[{name:"nVersion",len:4,offset:0},{name:"hashPrevouts",len:32,offset:4},{name:"hashSequence",len:32,offset:36},{name:"outpoint_txid",len:32,offset:68},{name:"outpoint_vout",len:4,offset:100}],n=r.find(function(o){return o.name===t});if(!n)throw new Error("Field not found in LEFT fields: "+t);var i=[];return e?i=["# \u{1F504} Extract "+t+" from LEFT side (bidirectional strategy)",n.offset+" OP_SPLIT # Skip to field: [prefix, remainder]","OP_NIP # Drop prefix (OP_SPLIT leaves remainder on top): [remainder]",n.len+" OP_SPLIT # Extract field: ["+t+", suffix]","OP_DROP # Clean up: ["+t+"]","# \u2705 Result: "+t+" is now on top of stack"]:i=[n.offset+" OP_SPLIT","OP_NIP",n.len+" OP_SPLIT","OP_DROP"],i.join(`
|
|
3
3
|
`)};tt.prototype._generateDynamicExtractionASM=function(t,e){var r=104+t.scriptLenSize;return["# \u{1F3AF} Extract scriptCode DYNAMICALLY with CompactSize varint support",r+" OP_SPLIT # Skip left zone + scriptLen varint: [left_zone, remainder]","OP_NIP # Drop left (OP_SPLIT leaves remainder on top): [remainder]",t.scriptLen+" OP_SPLIT # Extract scriptCode: [scriptCode, right_zone]","OP_DROP # Clean up: [scriptCode]","# \u2705 Result: scriptCode extracted with "+t.scriptLenSize+"-byte varint awareness"].join(`
|
|
4
4
|
`)};tt.prototype._generateScriptLenExtractionASM=function(t,e){return["# \u{1F3AF} Extract scriptLen CompactSize varint ("+t.scriptLenSize+" bytes)","104 OP_SPLIT # Skip left fixed fields: [left_zone, remainder]","OP_NIP # Drop left (OP_SPLIT leaves remainder on top): [remainder]",t.scriptLenSize+" OP_SPLIT # Extract varint: [scriptLen_varint, suffix]","OP_DROP # Clean up: [scriptLen_varint]","# \u2705 Result: CompactSize varint (decode off-chain to get "+t.scriptLen+")"].join(`
|
|
5
|
-
`)};tt.prototype._extractSpecificField=function(t,e){var r=e[t];return r?E.Buffer.from(r,"hex"):null};tt.prototype._interpretField=function(t,e,r){if(!e)return null;var n={raw:e.toString("hex"),bytes:e.length};try{switch(t){case"nVersion":n.value=e.readUInt32LE(0),n.description="Transaction version "+n.value;break;case"value":e.length===8&&(n.satoshis=e.readBigUInt64LE(0).toString(),n.description=n.satoshis+" satoshis");break;case"sighashType":var i=e.readUInt32LE(0),o={1:"SIGHASH_ALL",65:"SIGHASH_ALL | FORKID",2:"SIGHASH_NONE",66:"SIGHASH_NONE | FORKID",3:"SIGHASH_SINGLE",67:"SIGHASH_SINGLE | FORKID"};n.value=i,n.description=o[i]||"Custom ("+i+")";break;case"outpoint_vout":n.value=e.readUInt32LE(0),n.description="Output index "+n.value;break;case"scriptLen":n.varintSize=r.scriptLenSize,n.scriptLength=r.scriptLen,n.description=r.scriptLen+" bytes encoded as "+r.scriptLenSize+"-byte varint";break;case"scriptCode":e.length===25&&e[0]===118&&e[1]===169?(n.description="Standard P2PKH script (25 bytes)",n.type="P2PKH"):e.length>0&&e[0]===106?(n.description="OP_RETURN data script ("+e.length+" bytes)",n.type="OP_RETURN"):(n.description="Custom script ("+e.length+" bytes)",n.type="CUSTOM");break;default:if(["hashPrevouts","hashSequence","hashOutputs"].includes(t)){var c=E.Buffer.alloc(32);e.equals(c)?(n.isZero=!0,n.description="Zero hash (check SIGHASH flags)"):n.description="32-byte hash"}}}catch(h){n.error=h.message}return n};tt.prototype._getExtractionStrategy=function(t){var e=["value","nSequence","hashOutputs","nLocktime","sighashType"],r=["nVersion","hashPrevouts","hashSequence","outpoint_txid","outpoint_vout"];return e.includes(t)?"RIGHT":r.includes(t)?"LEFT":t==="scriptCode"?"DYNAMIC":t==="scriptLen"?"VARINT":"UNKNOWN"};tt.decodeCompactSize=function(t,e){if(e>=t.length)throw new Error("CompactSize read past end of preimage buffer (offset "+e+", length "+t.length+")");var r=t[e];if(r<253)return{value:r,nextOffset:e+1,bytes:1};if(r===253){if(e+3>t.length)throw new Error("Truncated 2-byte CompactSize in preimage at offset "+e);var n=t.readUInt16LE(e+1);return{value:n,nextOffset:e+3,bytes:3}}else if(r===254){if(e+5>t.length)throw new Error("Truncated 4-byte CompactSize in preimage at offset "+e);var i=t.readUInt32LE(e+1);return{value:i,nextOffset:e+5,bytes:5}}else throw new Error("Invalid CompactSize: 8-byte length prefix (0xff) is not a valid script length")};tt.fromTransaction=function(t,e,r,n,i){var o=rn.Transaction.sighash.sighashPreimage(t,i,e,r,new rn.crypto.BN(n));return new tt(o,{transaction:t,inputIndex:e,subscript:r,satoshis:n,sighashType:i})};tt.createExample=function(t){var e=rn.PrivateKey.fromRandom(),r=e.toAddress(),n={txId:"0".repeat(64),outputIndex:0,script:rn.Script.buildPublicKeyHashOut(r).toHex(),satoshis:1e5},i=new rn.Transaction().from(n).to(r,99e3),o=rn.Script.fromHex(n.script);return tt.fromTransaction(i,0,o,n.satoshis,t)};tt.extractFromHex=function(t,e,r){var n=new tt(t,{deferExtraction:!0});return n.extractField(e,r)};tt.generateASMFromHex=function(t,e,r){var n=new tt(t,{deferExtraction:!0});return n.generateASM(e,r)};tt.extractMultipleFromHex=function(t,e){var r=new tt(t,{deferExtraction:!0});return r.extractFields(e)};tt.validateFromHex=function(t){var e=new tt(t);return e.validate()};tt.analyzeFromHex=function(t){var e=new tt(t),r=e._parsePreimageStructure(),n=e.validate();return{hex:t,length:t.length/2,structure:r._structure,fields:r,validation:n,sighashInfo:e.getSighashInfo(),extractField:function(i){return e.extractField(i)},generateASM:function(i){return e.generateASM(i)},getSummary:function(){return{totalBytes:r._structure.totalActual,scriptLength:r.scriptLen,scriptVarintSize:r.scriptLenSize,sighashType:r.sighashType,valid:n.valid,warnings:n.warnings}}}};Ha.exports=tt});var Na=Z((Zp,La)=>{"use strict";I();var fe=de();function Ee(t){if(!(this instanceof Ee))return new Ee(t);this.sighashType=t||fe.crypto.Signature.SIGHASH_ALL|fe.crypto.Signature.SIGHASH_FORKID,this.analysis=this._analyzeFlags()}Ee.prototype.analyze=function(){return this.analysis};Ee.prototype.getZeroHashBehavior=function(){var t={hashPrevouts:!1,hashSequence:!1,hashOutputs:!1,explanation:[],criticalNote:null};return this.analysis.anyoneCanPay&&(t.hashPrevouts=!0,t.explanation.push("ANYONECANPAY: hashPrevouts becomes zero hash (0x00...00)")),this.analysis.baseType==="NONE"&&(t.hashSequence=!0,t.hashOutputs=!0,t.explanation.push("SIGHASH_NONE: hashSequence and hashOutputs become zero hash")),this.analysis.baseType==="SINGLE"&&(t.hashSequence=!0,t.hashOutputs=!0,t.explanation.push("SIGHASH_SINGLE: hashSequence becomes zero hash, hashOutputs covers only corresponding output")),(t.hashPrevouts||t.hashSequence||t.hashOutputs)&&(t.criticalNote="These zero hashes are NOT bugs - they are correct BIP-143 behavior for the specified SIGHASH flags!"),t};Ee.prototype.generateExample=function(){var t=fe.PrivateKey.fromRandom(),e=t.toAddress(),r={txId:"a".repeat(64),outputIndex:0,script:fe.Script.buildPublicKeyHashOut(e).toHex(),satoshis:1e5},n=new fe.Transaction().from(r).to(e,99e3),i=fe.Script.fromHex(r.script),o=fe.Transaction.sighash.sighashPreimage(n,this.sighashType,0,i,new fe.crypto.BN(r.satoshis)),c=Xe(),h=new c(o);return{transaction:n,preimage:h,sighashType:this.sighashType,analysis:this.analysis,zeroHashBehavior:this.getZeroHashBehavior(),fields:h.extract(),validation:h.validate()}};Ee.prototype.createDemonstration=function(){var t=this.generateExample(),e=E.Buffer.alloc(32).toString("hex"),r={sighashType:this.sighashType,analysis:this.analysis,zeroHashBehavior:this.getZeroHashBehavior(),preimageFields:{},observations:[],educationalNotes:[]},n=t.preimage.toObject().fields;return r.preimageFields=n,n.hashPrevouts===e&&r.observations.push({field:"hashPrevouts",value:"ZERO HASH (00...00)",reason:"ANYONECANPAY flag - this input can be combined with any other inputs"}),n.hashSequence===e&&r.observations.push({field:"hashSequence",value:"ZERO HASH (00...00)",reason:this.analysis.baseType+" flag - sequence numbers not covered by signature"}),n.hashOutputs===e&&r.observations.push({field:"hashOutputs",value:"ZERO HASH (00...00)",reason:this.analysis.baseType+" flag - outputs not fully covered by signature"}),r.educationalNotes=["Zero hashes in preimages are NOT errors - they indicate specific SIGHASH flag behavior","BIP-143 mandates these zero values when certain flags are used","ANYONECANPAY allows this input to be combined with different sets of inputs","SIGHASH_NONE means the signer doesn't care about any outputs","SIGHASH_SINGLE means the signer only cares about the corresponding output","Always check SIGHASH flags when you see 'mysterious' zero hashes in preimages"],r};Ee.prototype.checkCompliance=function(t){var e=t.toObject().fields,r=E.Buffer.alloc(32).toString("hex"),n={compliant:!0,issues:[],expectedZeros:[],unexpectedZeros:[]},i=this.getZeroHashBehavior();return i.hashPrevouts&&e.hashPrevouts!==r?(n.compliant=!1,n.issues.push("hashPrevouts should be zero due to ANYONECANPAY flag")):!i.hashPrevouts&&e.hashPrevouts===r&&n.unexpectedZeros.push("hashPrevouts is zero but ANYONECANPAY not set"),i.hashSequence&&e.hashSequence!==r?(n.compliant=!1,n.issues.push("hashSequence should be zero due to "+this.analysis.baseType+" flag")):!i.hashSequence&&e.hashSequence===r&&n.unexpectedZeros.push("hashSequence is zero but "+this.analysis.baseType+" allows sequence coverage"),i.hashOutputs&&e.hashOutputs!==r?(n.compliant=!1,n.issues.push("hashOutputs should be zero due to "+this.analysis.baseType+" flag")):!i.hashOutputs&&e.hashOutputs===r&&n.unexpectedZeros.push("hashOutputs is zero but "+this.analysis.baseType+" should cover outputs"),n};Ee.prototype._analyzeFlags=function(){var t=this.sighashType&31,e=(this.sighashType&128)!==0,r=(this.sighashType&64)!==0,n="UNKNOWN";t===1?n="ALL":t===2?n="NONE":t===3&&(n="SINGLE");var i=[];return i.push(n),e&&i.push("ANYONECANPAY"),r&&i.push("FORKID"),{sighashType:this.sighashType,baseType:n,anyoneCanPay:e,forkId:r,flagName:i.join(" | "),hex:"0x"+this.sighashType.toString(16).padStart(8,"0"),binary:"0b"+this.sighashType.toString(2).padStart(32,"0")}};Ee.getAllTypes=function(){var t=fe.crypto.Signature.SIGHASH_FORKID;return[{name:"ALL",value:fe.crypto.Signature.SIGHASH_ALL|t},{name:"NONE",value:fe.crypto.Signature.SIGHASH_NONE|t},{name:"SINGLE",value:fe.crypto.Signature.SIGHASH_SINGLE|t},{name:"ALL | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_ALL|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t},{name:"NONE | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_NONE|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t},{name:"SINGLE | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_SINGLE|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t}]};Ee.generateAllDemonstrations=function(){return Ee.getAllTypes().map(function(t){var e=new Ee(t.value);return{typeName:t.name,demonstration:e.createDemonstration()}})};Ee.explainZeroMystery=function(){return{title:"The 'Extra Zero' Mystery in Bitcoin Preimages",problem:"Developers often see zero hashes (0x00...00) in preimage fields and think it's a bug",reality:"These zeros are CORRECT behavior mandated by BIP-143 for specific SIGHASH flags",explanation:["ANYONECANPAY sets hashPrevouts to zero - allows input combination flexibility","SIGHASH_NONE sets hashSequence and hashOutputs to zero - signer doesn't care about outputs","SIGHASH_SINGLE sets hashSequence to zero - only corresponding output matters","These are features, not bugs - they enable advanced Bitcoin transaction patterns"],solution:"Always check SIGHASH flags when analyzing preimages with zero hashes",toolTip:"Use SIGHASH.checkCompliance() to verify if zero hashes match expected flag behavior"}};La.exports=Ee});var Ua=Z((Wp,Ca)=>{"use strict";I();var _t=de();function ae(t,e){if(!(this instanceof ae))return new ae(t,e);this.privateKey=t,this.publicKey=t?t.publicKey:null,this.options=e||{},this.allowNonEnforcing=this.options.allowNonEnforcing===!0,this.conditions=[],this.preimageFields=[],this.scriptTemplate=null,this.validationRules=[],this.sighashType=this.options.sighashType||_t.crypto.Signature.SIGHASH_ALL|_t.crypto.Signature.SIGHASH_FORKID}ae.prototype._assertEnforcingAllowed=function(){if(!this.allowNonEnforcing)throw new Error("SmartContract.Builder produces a NON-ENFORCING script (constant hash-lock \u2192 plain P2PK; it does not constrain the spend). Use SmartContract.policy() (declarative OP_PUSH_TX), or SmartContract.PushTx / Token / valueCovenant for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.")};ae.prototype.validateField=function(t,e,r){r=r||{};var n={field:t,expectedValue:e,operator:r.operator||"EQUAL",required:r.required!==!1,description:r.description||"Validate "+t};return this.validationRules.push(n),this};ae.prototype.addCondition=function(t,e){e=e||{};var r={type:typeof t=="function"?"CUSTOM":"OPCODE",condition:t,description:e.description||"Custom condition",required:e.required!==!1};return this.conditions.push(r),this};ae.prototype.useTemplate=function(t,e){return this.scriptTemplate={name:t,params:e||{},customScript:typeof t=="object"?t:null},this};ae.prototype.buildLockingScript=function(t){this._assertEnforcingAllowed();var e=new _t.Script;return this.scriptTemplate?this._buildFromTemplate(t):this._buildMultiFieldCovenant(t)};ae.prototype.buildUnlockingScript=function(t,e,r){var n=new _t.Script,i=_t.Script.fromHex(r.script),o=_t.Transaction.sighash.sign(t,this.privateKey,this.sighashType,e,i,new _t.crypto.BN(r.satoshis)),c=E.Buffer.concat([o.toDER(),E.Buffer.from([this.sighashType])]);return n.add(c),r.originalPreimage&&n.add(E.Buffer.from(r.originalPreimage,"hex")),this.conditions.forEach(function(h){h.type==="UNLOCK_DATA"&&n.add(h.data)}),n};ae.prototype.createCovenant=function(t,e){this._assertEnforcingAllowed(),e=e||{};var r=new _t.Transaction().from({txId:t.txid,outputIndex:t.vout,script:t.script,satoshis:t.satoshis}).to(this.privateKey.toAddress(),t.satoshis-(e.fee||1e3)),n=_t.Script.fromHex(t.script),i=_t.Transaction.sighash.sighashPreimage(r,this.sighashType,0,n,new _t.crypto.BN(t.satoshis)),o=Xe(),c=new o(i),h=c.extract(),d=this.buildLockingScript({preimage:i,fields:h,transaction:r});r.outputs[0].setScript(d),r.sign(this.privateKey);var x={txid:r.id,vout:0,satoshis:t.satoshis-(e.fee||1e3),script:d.toHex(),originalPreimage:i.toString("hex"),preimageFields:h,validationRules:this.validationRules.slice(),conditions:this.conditions.slice(),template:this.scriptTemplate,createdAt:new Date().toISOString(),type:"builder_covenant"};return{creationTx:r,covenantUtxo:x,lockingScript:d,preimageData:{preimage:i,fields:h}}};ae.prototype.validateSpending=function(t,e){var r={valid:!0,errors:[],warnings:[],fieldValidations:[]},n=_t.Script.fromHex(e.script),i=_t.Transaction.sighash.sighashPreimage(t,this.sighashType,0,n,new _t.crypto.BN(e.satoshis)),o=Xe(),c=new o(i),h=c.extract();e.validationRules&&e.validationRules.forEach(function(O){var T=this._validateFieldRule(O,h,e.preimageFields);r.fieldValidations.push(T),!T.passed&&O.required&&(r.valid=!1,r.errors.push(T.error))}.bind(this));var d=new _t.Script.Interpreter,x=_t.Script.Interpreter.SCRIPT_VERIFY_P2SH|_t.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|_t.Script.Interpreter.SCRIPT_VERIFY_DERSIG|_t.Script.Interpreter.SCRIPT_VERIFY_LOW_S|_t.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,v=t.inputs[0].script,y=_t.Script.fromHex(e.script),A=d.verify(v,y,t,0,x,new _t.crypto.BN(e.satoshis));return A||(r.valid=!1,r.errors.push("Script interpreter validation failed: "+d.errstr)),r};ae.prototype._buildFromTemplate=function(t){var e=this.scriptTemplate;if(e.name==="HASH_LOCK")return this._buildHashLockTemplate(t,e.params);if(e.name==="MULTI_FIELD")return this._buildMultiFieldTemplate(t,e.params);if(e.customScript)return e.customScript;throw new Error("Unknown template: "+e.name)};ae.prototype._buildMultiFieldCovenant=function(t){var e=new _t.Script;return e.add("OP_DUP"),this.validationRules.forEach(function(r,n){if(n>0&&e.add("OP_DUP"),e.add("OP_HASH256"),r.expectedValue){var i=_t.crypto.Hash.sha256sha256(E.Buffer.from(r.expectedValue,"hex"));e.add(i),e.add("OP_EQUALVERIFY")}}),e.add("OP_DROP"),this.publicKey&&(e.add(this.publicKey.toBuffer()),e.add("OP_CHECKSIG")),e};ae.prototype._buildHashLockTemplate=function(t,e){var r=new _t.Script;r.add("OP_DUP"),r.add("OP_HASH256");var n=e.hash||_t.crypto.Hash.sha256sha256(t.preimage);return r.add(n),r.add("OP_EQUALVERIFY"),r.add("OP_DROP"),this.publicKey&&(r.add(this.publicKey.toBuffer()),r.add("OP_CHECKSIG")),r};ae.prototype._validateFieldRule=function(t,e,r){var n=e[t.field],i=t.expectedValue;if(typeof i=="string"&&i.startsWith("ORIGINAL_")){var o=i.replace("ORIGINAL_","");i=r[o]}var c=!1,h=null;switch(t.operator){case"EQUAL":c=n&&n.equals?n.equals(i):n===i,c||(h=t.field+" does not equal expected value");break;case"NOT_EQUAL":c=n&&n.equals?!n.equals(i):n!==i,c||(h=t.field+" should not equal specified value");break;case"PRESENT":c=!!n,c||(h=t.field+" is required but not present");break;default:h="Unknown validation operator: "+t.operator}return{field:t.field,operator:t.operator,passed:c,error:h,description:t.description}};ae.createHashLock=function(t,e){return new ae(t).useTemplate("HASH_LOCK",{hash:e})};ae.createMultiField=function(t,e){var r=new ae(t);return e.forEach(function(n){r.validateField(n.field,n.expectedValue,n.options)}),r};Ca.exports=ae});var Da=Z((Jp,qa)=>{I();qa.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var ja=Z((em,Eo)=>{I();var Bt=function(){(typeof C.default<"u"&&C.default.env&&C.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG)&&console.log.apply(console,arguments)},cl,Pr,bo,nn;if(typeof window>"u"&&typeof ve=="function")try{Pr=se(),bo=se(),nn=bo.join(__dirname,"blockchain-state.json")}catch{Bt("BlockchainState: Running in browser mode - persistence disabled")}else cl=typeof window<"u"&&window.bsv||Da();function ai(){return{metadata:{createdAt:new Date().toISOString(),lastUpdated:new Date().toISOString(),totalWallets:0,totalUTXOs:0,totalValue:0,blockHeight:0},wallets:{},globalUTXOSet:{},spentUTXOs:{},transactionHistory:[]}}function on(){try{if(!Pr||!nn)return ai();if(!Pr.existsSync(nn)){Bt("\u{1F195} Creating new blockchain state...");let e=ai();return sn(e),e}let t=JSON.parse(Pr.readFileSync(nn,"utf8"));return Bt("\u{1F4D6} Loaded existing blockchain state"),t}catch(t){return console.error("\u274C Error loading blockchain state:",t.message),ai()}}function sn(t){try{t.metadata.lastUpdated=new Date().toISOString(),Pr&&nn&&(Pr.writeFileSync(nn,JSON.stringify(t,null,2)),Bt("\u{1F4BE} Blockchain state saved"))}catch(e){console.error("\u274C Error saving blockchain state:",e.message)}}function Ga(t,e){Bt(`\u{1F4DD} Registering wallet: ${t}`);let r=on();return r.wallets[t]&&Bt("\u2139\uFE0F Wallet already exists, updating..."),r.wallets[t]={address:t,registeredAt:e.registeredAt||new Date().toISOString(),utxos:e.utxos||[],totalValue:0},e.utxos&&e.utxos.forEach(n=>{let i=`${n.txid}:${n.vout}`;r.globalUTXOSet[i]={...n,ownerAddress:t}}),r.metadata.totalWallets=Object.keys(r.wallets).length,So(r),sn(r),Bt(`\u2705 Wallet registered: ${t}`),r}function za(t,e){let r=on(),n=`${t}:${e}`;return r.spentUTXOs[n]?{exists:!1,spent:!0,utxo:r.spentUTXOs[n]}:r.globalUTXOSet[n]?{exists:!0,spent:!1,utxo:r.globalUTXOSet[n]}:{exists:!1,spent:!1,utxo:null}}function ul(t,e){let r=za(t,e);return r.exists&&!r.spent}function hl(t,e,r){let n=on(),i=`${t}:${e}`;if(!n.globalUTXOSet[i])throw new Error(`UTXO ${i} does not exist`);if(n.spentUTXOs[i])throw new Error(`UTXO ${i} already spent`);let o=n.globalUTXOSet[i];n.spentUTXOs[i]={...o,spentInTx:r,spentAt:new Date().toISOString()},delete n.globalUTXOSet[i];let c=n.wallets[o.ownerAddress];c&&(c.utxos=c.utxos.filter(h=>!(h.txid===t&&h.vout===e))),So(n),sn(n),Bt(`\u274C UTXO spent: ${i} in tx ${r}`)}function fl(t,e){let r=on(),n=`${t.txid}:${t.vout}`;if(r.globalUTXOSet[n]){Bt(`\u26A0\uFE0F UTXO ${n} already exists, skipping`);return}r.globalUTXOSet[n]={...t,ownerAddress:e,createdAt:new Date().toISOString()},r.wallets[e]||(r.wallets[e]={address:e,registeredAt:new Date().toISOString(),utxos:[],totalValue:0}),r.wallets[e].utxos.some(o=>o.txid===t.txid&&o.vout===t.vout)||r.wallets[e].utxos.push(t),So(r),sn(r),Bt(`\u2705 UTXO added: ${n} for ${e}`)}function So(t){let e=Object.keys(t.globalUTXOSet).length,r=Object.values(t.globalUTXOSet).reduce((n,i)=>n+i.satoshis,0);t.metadata.totalUTXOs=e,t.metadata.totalValue=r,Object.values(t.wallets).forEach(n=>{n.totalValue=n.utxos.reduce((i,o)=>i+o.satoshis,0)})}function Va(){let t=on();return Bt("\u{1F310} Blockchain State Statistics:"),Bt("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),Bt(`\u{1F4CA} Total Wallets: ${t.metadata.totalWallets}`),Bt(`\u{1F4B0} Total UTXOs: ${t.metadata.totalUTXOs}`),Bt(`\u{1F48E} Total Value: ${t.metadata.totalValue} satoshis`),Bt(`\u{1F3D7}\uFE0F Block Height: ${t.metadata.blockHeight}`),Bt(`\u{1F550} Last Updated: ${t.metadata.lastUpdated}
|
|
6
|
-
`),Object.keys(t.wallets).length>0&&(Bt("\u{1F45B} Registered Wallets:"),Object.entries(t.wallets).forEach(([e,r])=>{Bt(` ${e}: ${r.utxos.length} UTXOs, ${r.totalValue} sats`)})),t}function Ka(){let t=bo.join(__dirname,"wallet.json");if(!Pr.existsSync(t))return Bt("\u274C No wallet.json found to import"),!1;try{let e=JSON.parse(Pr.readFileSync(t,"utf8"));Bt("\u{1F4E5} Importing wallet from wallet.json...");let r={registeredAt:new Date().toISOString(),utxos:e.availableUTXOs||[e.utxo]};return Ga(e.wallet.address,r),Bt("\u2705 Wallet imported successfully"),!0}catch(e){return console.error("\u274C Error importing wallet:",e.message),!1}}if(ve.main===Eo){let t=C.default.argv.slice(2);if(t[0]==="import")Ka();else if(t[0]==="init"){let e=ai();sn(e),Bt("\u{1F195} Initialized new blockchain state")}Va()}Eo.exports={loadBlockchainState:on,saveBlockchainState:sn,registerWallet:Ga,getUTXO:za,isUTXOAvailable:ul,spendUTXO:hl,addUTXO:fl,getBlockchainStats:Va,importWalletFromFile:Ka}});var $a=Z((im,Ya)=>{I();Ya.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var Wa=Z((sm,Xa)=>{"use strict";I();var Ce=function(){(typeof C.default<"u"&&C.default.env&&C.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG)&&console.log.apply(console,arguments)},_o,Za,ll,dr;if(typeof window>"u"&&typeof ve=="function")try{_o=se(),Za=se(),ll=se(),dr=ja()}catch{Ce("SmartUTXO: Running in browser mode - some features may be limited")}var Oo=class{constructor(e={}){this.options=e||{},this.loadState()}loadState(){try{return dr.loadBlockchainState()}catch(e){return Ce("\u26A0\uFE0F Could not load blockchain state:",e.message),null}}saveState(){try{let e=dr.loadBlockchainState();dr.saveBlockchainState(e);let r=Object.keys(e.globalUTXOSet||{}).length;Ce(`\u{1F4BE} Saved blockchain state with ${r} UTXOs`)}catch(e){Ce("\u26A0\uFE0F Could not save blockchain state:",e.message)}}getUTXOsForAddress(e){try{let r=dr.loadBlockchainState();return!r.wallets||!r.wallets[e]?[]:r.wallets[e].utxos||[]}catch(r){return Ce("\u26A0\uFE0F Error getting UTXOs:",r.message),[]}}addUTXO(e){try{dr.addUTXO(e,e.address)}catch(r){Ce("\u26A0\uFE0F Error adding UTXO:",r.message)}}spendUTXOs(e,r="manual-spend"){try{for(let n of e)dr.spendUTXO(n.txid,n.vout,r)}catch(n){Ce("\u26A0\uFE0F Error spending UTXOs:",n.message)}}createMockUTXOs(e,r=5,n=1e5){let i=$a(),o=i.Script.buildPublicKeyHashOut(i.Address.fromString(e)).toHex(),c=[];for(let h=0;h<r;h++)c.push({txid:i.crypto.Random.getRandomBuffer(32).toString("hex"),vout:h,address:e,satoshis:n,script:o});return c}getBalance(e){try{let r=dr.loadBlockchainState();return!r.wallets||!r.wallets[e]?0:r.wallets[e].totalValue||0}catch(r){return Ce("\u26A0\uFE0F Error getting balance:",r.message),0}}getStats(){try{let e=dr.getBlockchainStats();return{totalUTXOs:e.metadata.totalUTXOs,totalValue:e.metadata.totalValue,totalWallets:e.metadata.totalWallets,blockHeight:e.metadata.blockHeight,lastUpdated:e.metadata.lastUpdated}}catch(e){return Ce("\u26A0\uFE0F Error getting stats:",e.message),{totalUTXOs:0,totalValue:0,totalWallets:0,blockHeight:0}}}reset(){try{let e=Za.join(__dirname,"../utilities/blockchain-state.json");_o.existsSync(e)&&(_o.unlinkSync(e),Ce("\u{1F504} Blockchain state reset"))}catch(e){Ce("\u26A0\uFE0F Could not reset blockchain state:",e.message)}}};Xa.exports=Oo});var Ja=Z((um,Qa)=>{"use strict";I();var Ie=de(),dl=se();function Pe(t){if(!(this instanceof Pe))return new Pe(t);this.options=t||{},this.network=this.options.network||Ie.Networks.mainnet,this.keyRing={},this.utxoPool=[];try{var e=Wa();this.smartUTXO=new e(this.options)}catch{}}Pe.prototype.generateKeypair=function(t){t=t||"key_"+Date.now();var e=Ie.PrivateKey.fromRandom(this.network),r=e.toPublicKey(),n=e.toAddress(this.network),i={label:t,privateKey:e,publicKey:r,address:n,wif:e.toWIF(),addressString:n.toString()};return this.keyRing[t]=i,i};Pe.prototype.createRealUTXOs=function(t){t=t||{};for(var e=t.count||3,r=t.satoshis||1e5,n=t.scriptType||"P2PKH",i=t.keypair||this.generateKeypair("utxo_owner"),o=[],c=0;c<e;c++){var h=this._createSingleUTXO({keypair:i,satoshis:r,scriptType:n,vout:c});o.push(h),this.utxoPool.push(h),this.smartUTXO&&this.smartUTXO.addUTXO(h)}return o};Pe.prototype._createSingleUTXO=function(t){var e=dl.randomBytes(32).toString("hex"),r,n;switch(t.scriptType){case"P2PKH":r=Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex();break;case"P2SH":var i=Ie.Script.buildMultisigOut([t.keypair.publicKey],1);r=Ie.Script.buildScriptHashOut(i),n=r.toHex();break;case"CUSTOM":r=t.customScript||Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex();break;default:r=Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex()}return{txid:e,vout:t.vout,address:t.keypair.addressString,script:n,satoshis:t.satoshis,keypair:t.keypair,scriptType:t.scriptType,scriptObj:r,created:new Date().toISOString()}};Pe.prototype.createTestTransaction=function(t){t=t||{};var e=t.inputs||this.utxoPool.slice(0,1);if(e.length===0)throw new Error("No UTXOs available for transaction. Call createRealUTXOs() first.");var r=e.reduce(function(h,d){return h+d.satoshis},0),n=new Ie.Transaction;e.forEach(function(h){n.from({txId:h.txid,outputIndex:h.vout,address:h.address,script:h.script,satoshis:h.satoshis})});var i=t.outputAddress||e[0].keypair.addressString,o=t.outputAmount||r-1e4,c=t.fee||1e4;return n.to(i,o),n.fee(c),{transaction:n,inputUTXOs:e,unsignedHex:n.toString(),inputTotal:r,outputAmount:o,fee:c,sign:function(){return e.forEach(function(h){n.sign(h.keypair.privateKey)}),{signedTransaction:n,signedHex:n.toString(),txid:n.id}},generatePreimage:function(h,d){d=d||Ie.crypto.Signature.SIGHASH_ALL|Ie.crypto.Signature.SIGHASH_FORKID;var x=e[h];return Ie.Transaction.sighash.sighashPreimage(n,d,h,Ie.Script.fromHex(x.script),new Ie.crypto.BN(x.satoshis))}}};Pe.prototype.createCovenantTest=function(t){t=t||{};var e=this.generateKeypair("covenant_test"),r=this.createRealUTXOs({count:t.utxoCount||2,satoshis:t.satoshis||5e4,keypair:e,scriptType:t.scriptType||"P2PKH"}),n={inputs:r.slice(0,1),outputAmount:t.covenantAmount||4e4,fee:1e4},i=this.createTestTransaction(n),o=i.generatePreimage(0),c=o.toString("hex");return{keypair:e,utxos:r,transaction:i,preimage:{buffer:o,hex:c,length:o.length},extractField:function(h){try{var d=Xe();return d.extractFromHex(c,h)}catch(x){throw new Error("SmartContract.Preimage not available: "+x.message)}},validateCovenant:function(h){return{preimageValid:o.length>=182,covenantLogic:h,testPassed:!0}},getSummary:function(){return{keypair:e.addressString,utxoCount:r.length,totalValue:r.reduce(function(h,d){return h+d.satoshis},0),preimageLength:o.length,transactionId:i.transaction.id}}}};Pe.prototype.getKeypairs=function(){return this.keyRing};Pe.prototype.getUTXOs=function(){return this.utxoPool};Pe.prototype.reset=function(){this.keyRing={},this.utxoPool=[]};Pe.createTestEnvironment=function(t){var e=new Pe(t),r=e.createCovenantTest(t);return{generator:e,test:r,getPreimage:function(){return r.preimage.hex},getKeypair:function(){return r.keypair},extractField:function(n){return r.extractField(n)},generateASM:function(n){try{var i=Xe();return i.generateASMFromHex(r.preimage.hex,n)}catch(o){throw new Error("Cannot generate ASM: "+o.message)}}}};Qa.exports=Pe});var ec=Z((fm,tc)=>{"use strict";I();var pe=de();function ce(t){if(!(this instanceof ce))return new ce(t);this.options=t||{},this.flags=this.options.flags||pe.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,this.satoshis=this.options.satoshis||1e5}ce.prototype.execute=function(t){var e=this._parseScript(t.unlocking),r=this._parseScript(t.locking),n=this._createDummyTransaction(),i=new pe.Script.Interpreter,o=new pe.crypto.BN(this.satoshis);try{var c=i.verify(e,r,n,0,this.flags,o);return{success:c,unlocking:e.toASM(),locking:r.toASM(),finalStack:i.stack.map(function(h){return h.toString("hex")}),altStack:i.altstack.map(function(h){return h.toString("hex")}),error:null}}catch(h){return{success:!1,unlocking:e.toASM(),locking:r.toASM(),finalStack:[],altStack:[],error:h.message}}};ce.prototype.debug=function(t){var e=this._createCombinedScript(t),r=this._createDummyTransaction(),n=new pe.Script.Interpreter;n.script=e,n.tx=r,n.nIn=0,n.flags=this.flags;var i=[],o=e.chunks;try{for(var c=0;c<o.length;c++){var h=o[c],d=pe.Opcode.reverseMap[h.opcodenum]||"PUSH",x=n.stack.map(function(O){return O.toString("hex")}),v=n.altstack.map(function(O){return O.toString("hex")});try{n.step();var y=n.stack.map(function(O){return O.toString("hex")}),A=n.altstack.map(function(O){return O.toString("hex")});i.push({step:c+1,opcode:d,beforeStack:x,afterStack:y,beforeAltStack:v,afterAltStack:A,success:!0,error:null})}catch(O){i.push({step:c+1,opcode:d,beforeStack:x,afterStack:x,beforeAltStack:v,afterAltStack:v,success:!1,error:O.message});break}}}catch(O){i.push({step:0,opcode:"INITIALIZATION",beforeStack:[],afterStack:[],beforeAltStack:[],afterAltStack:[],success:!1,error:O.message})}return{script:e.toASM(),steps:i,totalSteps:o.length,success:i.length>0&&i[i.length-1].success}};ce.prototype.testCovenant=function(t){var e=t.preimage,r=t.constraints||{},n=this._buildCovenantScript(r,e),i=this.execute({unlocking:e,locking:n});return i.covenant={preimageLength:e.length/2,constraints:r,constraintResults:this._analyzeConstraints(e,r)},i};ce.prototype.testFieldExtraction=function(t,e){try{var r=Xe(),n=r.extractFromHex(t,e,{includeComments:!1}),i=this._cleanASM(n.asm),o=this.execute({unlocking:t,locking:i+" OP_DROP OP_TRUE"});return o.fieldExtraction={field:e,strategy:n.strategy,value:n.value,interpretation:n.interpretation,asmGenerated:n.asm,cleanedASM:i},o}catch(c){return{success:!1,error:c.message,fieldExtraction:{field:e,error:c.message}}}};ce.prototype._parseScript=function(t){if(!t)return new pe.Script;var e=t.trim(),r=/^[0-9a-fA-F]+$/.test(e.replace(/\s+/g,""));try{if(r){var n=e.length/2;return n>=180&&n<=250?new pe.Script().add(E.Buffer.from(e,"hex")):pe.Script.fromHex(e)}else return pe.Script.fromASM(e)}catch(i){throw new Error("Failed to parse script: "+i.message)}};ce.prototype._createCombinedScript=function(t){if(t.combined)return this._parseScript(t.combined);var e=this._parseScript(t.unlocking),r=this._parseScript(t.locking),n=E.Buffer.concat([e.toBuffer(),r.toBuffer()]);return pe.Script.fromBuffer(n)};ce.prototype._createDummyTransaction=function(){var t=new pe.Transaction,e=new pe.Transaction.Input({prevTxId:"0".repeat(64),outputIndex:0,script:pe.Script.empty(),satoshis:this.satoshis,output:new pe.Transaction.Output({satoshis:this.satoshis,script:pe.Script.empty()})});return t.addInput(e),t.addOutput(new pe.Transaction.Output({satoshis:this.satoshis,script:pe.Script.empty()})),t};ce.prototype._buildCovenantScript=function(t,e){var r=[];try{var n=Xe();if(t.minimumAmount){var i=n.generateASMFromHex(e,"value",!1);r.push(i),r.push("OP_BIN2NUM"),r.push(t.minimumAmount.toString()),r.push("OP_GREATERTHANOREQUAL"),r.push("OP_VERIFY")}if(t.requiredSighash){var o=n.generateASMFromHex(e,"sighashType",!1);r.push(o),r.push("OP_BIN2NUM"),r.push(t.requiredSighash.toString()),r.push("OP_EQUAL"),r.push("OP_VERIFY")}r.push("OP_TRUE");var c=r.join(" ");return this._cleanASM(c)}catch(h){throw new Error("Failed to build covenant script: "+h.message)}};ce.prototype._cleanASM=function(t){var e=t.split(`
|
|
7
|
-
`).map(function(r){return r.split("#")[0].trim()}).filter(function(r){return r.length>0}).join(" ").replace(/\s+/g," ").trim();return e=e.replace(/\b(\d+)\b/g,function(r,n){var i=parseInt(n);if(i>=1&&i<=16)return"OP_"+i;if(i===0)return"OP_0";if(i===-1)return"OP_1NEGATE";var o=i,c=o<0;c&&(o=-o);for(var h=[];o>0;)h.push(o&255),o=Math.floor(o/256);return h.length===0&&h.push(0),c?h[h.length-1]>=128?h.push(128):h[h.length-1]|=128:h.length>0&&h[h.length-1]>=128&&h.push(0),E.Buffer.from(h).toString("hex")}),e};ce.prototype._analyzeConstraints=function(t,e){var r={};try{var n=Xe();if(e.minimumAmount){var i=n.extractFromHex(t,"value",{includeComments:!1}),o=parseInt(i.interpretation.satoshis);r.amountCheck={constraint:e.minimumAmount,actual:o,satisfied:o>=e.minimumAmount}}if(e.requiredSighash){var c=n.extractFromHex(t,"sighashType",{includeComments:!1}),h=parseInt(c.value,16);r.sighashCheck={constraint:e.requiredSighash,actual:h,satisfied:(h&255)===e.requiredSighash}}}catch(d){r.error=d.message}return r};ce.test=function(t,e,r){var n=new ce(r);return n.execute({unlocking:t,locking:e})};ce.testCovenant=function(t,e,r){var n=new ce(r);return n.testCovenant({preimage:t,constraints:e})};ce.testFieldExtraction=function(t,e,r){var n=new ce(r);return n.testFieldExtraction(t,e)};tc.exports=ce});var Io=Z((dm,Ao)=>{I();var H={encode:t=>{if(t===0)return E.Buffer.alloc(0);let e=t<0,r=Math.abs(t),n=[],i=r;for(;i>0;)n.push(i&255),i>>=8;return n[n.length-1]&128?n.push(e?128:0):e&&(n[n.length-1]|=128),E.Buffer.from(n)},decode:t=>{if(t.length===0)return 0;let e=Array.from(t),r=e[e.length-1]&128;r&&(e[e.length-1]&=127);let n=0;for(let i=e.length-1;i>=0;i--)n=(n<<8)+e[i];return r?-n:n}},Ue={OP_FALSE:{code:0,category:"constants",description:"Push empty array (false value)",action:t=>t.push(E.Buffer.alloc(0))},OP_0:{code:0,category:"constants",description:"Push empty array (alias for OP_FALSE)",action:t=>t.push(E.Buffer.alloc(0))},OP_PUSHDATA1:{code:76,category:"pushdata",description:"Push next [1 byte] bytes of data",action:"Read next byte as length; push that many bytes"},OP_PUSHDATA2:{code:77,category:"pushdata",description:"Push next [2 bytes LE] bytes of data",action:"Read next 2 bytes as length; push that many bytes"},OP_PUSHDATA4:{code:78,category:"pushdata",description:"Push next [4 bytes LE] bytes of data",action:"Read next 4 bytes as length; push that many bytes"},OP_1NEGATE:{code:79,category:"constants",description:"Push number -1",action:t=>t.push(H.encode(-1))},OP_RESERVED:{code:80,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED encountered")}},OP_TRUE:{code:81,category:"constants",description:"Push number 1 (true value)",action:t=>t.push(H.encode(1))},OP_1:{code:81,category:"constants",description:"Push number 1 (alias for OP_TRUE)",action:t=>t.push(H.encode(1))},OP_2:{code:82,category:"constants",description:"Push number 2",action:t=>t.push(H.encode(2))},OP_3:{code:83,category:"constants",description:"Push number 3",action:t=>t.push(H.encode(3))},OP_4:{code:84,category:"constants",description:"Push number 4",action:t=>t.push(H.encode(4))},OP_5:{code:85,category:"constants",description:"Push number 5",action:t=>t.push(H.encode(5))},OP_6:{code:86,category:"constants",description:"Push number 6",action:t=>t.push(H.encode(6))},OP_7:{code:87,category:"constants",description:"Push number 7",action:t=>t.push(H.encode(7))},OP_8:{code:88,category:"constants",description:"Push number 8",action:t=>t.push(H.encode(8))},OP_9:{code:89,category:"constants",description:"Push number 9",action:t=>t.push(H.encode(9))},OP_10:{code:90,category:"constants",description:"Push number 10",action:t=>t.push(H.encode(10))},OP_11:{code:91,category:"constants",description:"Push number 11",action:t=>t.push(H.encode(11))},OP_12:{code:92,category:"constants",description:"Push number 12",action:t=>t.push(H.encode(12))},OP_13:{code:93,category:"constants",description:"Push number 13",action:t=>t.push(H.encode(13))},OP_14:{code:94,category:"constants",description:"Push number 14",action:t=>t.push(H.encode(14))},OP_15:{code:95,category:"constants",description:"Push number 15",action:t=>t.push(H.encode(15))},OP_16:{code:96,category:"constants",description:"Push number 16",action:t=>t.push(H.encode(16))},OP_NOP:{code:97,category:"flow_control",description:"No operation (do nothing)",action:t=>{}},OP_VER:{code:98,category:"flow_control",description:"Push transaction version (disabled)",action:()=>{throw new Error("OP_VER is disabled")}},OP_IF:{code:99,category:"flow_control",description:"Execute if top stack value is true",action:"// Conditional execution (requires parser state)"},OP_NOTIF:{code:100,category:"flow_control",description:"Execute if top stack value is false",action:"// Conditional execution (requires parser state)"},OP_VERIF:{code:101,category:"flow_control",description:"Conditional execution based on transaction version (disabled)",action:()=>{throw new Error("OP_VERIF is disabled")}},OP_VERNOTIF:{code:102,category:"flow_control",description:"Conditional execution based on transaction version (disabled)",action:()=>{throw new Error("OP_VERNOTIF is disabled")}},OP_ELSE:{code:103,category:"flow_control",description:"Else branch of conditional",action:"// Conditional execution (requires parser state)"},OP_ENDIF:{code:104,category:"flow_control",description:"End conditional block",action:"// Conditional execution (requires parser state)"},OP_VERIFY:{code:105,category:"flow_control",description:"Fail if top stack value is not true",action:t=>{let e=t.pop();if(!e||e.length===0||H.decode(e)===0)throw new Error("OP_VERIFY failed")}},OP_RETURN:{code:106,category:"flow_control",description:"Terminate script execution immediately",action:()=>{throw new Error("Script terminated by OP_RETURN")}},OP_TOALTSTACK:{code:107,category:"stack",description:"Move top item from main stack to alt stack",action:(t,e)=>e.push(t.pop())},OP_FROMALTSTACK:{code:108,category:"stack",description:"Move top item from alt stack to main stack",action:(t,e)=>t.push(e.pop())},OP_2DROP:{code:109,category:"stack",description:"Remove top two stack items",action:t=>{t.pop(),t.pop()}},OP_2DUP:{code:110,category:"stack",description:"Duplicate top two stack items",action:t=>{let e=t[t.length-1],r=t[t.length-2];t.push(E.Buffer.from(r),E.Buffer.from(e))}},OP_3DUP:{code:111,category:"stack",description:"Duplicate top three stack items",action:t=>{let e=t[t.length-1],r=t[t.length-2],n=t[t.length-3];t.push(E.Buffer.from(n),E.Buffer.from(r),E.Buffer.from(e))}},OP_2OVER:{code:112,category:"stack",description:"Copy 3rd and 4th items to top",action:t=>{let e=t[t.length-3],r=t[t.length-4];t.push(E.Buffer.from(r),E.Buffer.from(e))}},OP_2ROT:{code:113,category:"stack",description:"Move 5th and 6th items to top",action:t=>{let e=t.splice(-5,1)[0],r=t.splice(-5,1)[0];t.push(e,r)}},OP_2SWAP:{code:114,category:"stack",description:"Swap top two pairs of items",action:t=>{let e=t.pop(),r=t.pop(),n=t.pop(),i=t.pop();t.push(r,e,i,n)}},OP_IFDUP:{code:115,category:"stack",description:"Duplicate top item if it is not zero",action:t=>{let e=t[t.length-1];e.length>0&&H.decode(e)!==0&&t.push(E.Buffer.from(e))}},OP_DEPTH:{code:116,category:"stack",description:"Push stack size as number",action:t=>t.push(H.encode(t.length))},OP_DROP:{code:117,category:"stack",description:"Remove top stack item",action:t=>t.pop()},OP_DUP:{code:118,category:"stack",description:"Duplicate top stack item",action:t=>t.push(E.Buffer.from(t[t.length-1]))},OP_NIP:{code:119,category:"stack",description:"Remove second-to-top item",action:t=>{let e=t.pop();t.pop(),t.push(e)}},OP_OVER:{code:120,category:"stack",description:"Copy second-to-top item to top",action:t=>t.push(E.Buffer.from(t[t.length-2]))},OP_PICK:{code:121,category:"stack",description:"Copy nth item to top (0-indexed from top)",action:t=>{let e=H.decode(t.pop());t.push(E.Buffer.from(t[t.length-1-e]))}},OP_ROLL:{code:122,category:"stack",description:"Move nth item to top (0-indexed from top)",action:t=>{let e=H.decode(t.pop()),r=t.splice(t.length-1-e,1)[0];t.push(r)}},OP_ROT:{code:123,category:"stack",description:"Rotate top three items left",action:t=>{let e=t.pop(),r=t.pop(),n=t.pop();t.push(r,e,n)}},OP_SWAP:{code:124,category:"stack",description:"Swap top two items",action:t=>{let e=t.pop(),r=t.pop();t.push(e,r)}},OP_TUCK:{code:125,category:"stack",description:"Copy top item below second item",action:t=>{let e=t.pop(),r=t.pop();t.push(e,r,e)}},OP_CAT:{code:126,category:"data",description:"Concatenate top two items",action:t=>{let e=t.pop(),r=t.pop();t.push(E.Buffer.concat([r,e]))}},OP_SPLIT:{code:127,category:"data",description:"Split item at position n",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(0,e),r.slice(e))}},OP_NUM2BIN:{code:128,category:"data",description:"Convert number to byte sequence of length n",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=E.Buffer.alloc(e),i=H.encode(r);i.copy(n,0,0,Math.min(i.length,e)),t.push(n)}},OP_BIN2NUM:{code:129,category:"data",description:"Convert byte sequence to number",action:t=>{let e=t.pop();t.push(H.encode(H.decode(e)))}},OP_SIZE:{code:130,category:"data",description:"Push size of top item (without removing item)",action:t=>t.push(H.encode(t[t.length-1].length))},OP_INVERT:{code:131,category:"bitwise",description:"Bitwise NOT of top item",action:t=>{let e=t.pop();t.push(E.Buffer.from(e.map(r=>~r)))}},OP_AND:{code:132,category:"bitwise",description:"Bitwise AND of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)&(r[o]||0);t.push(i)}},OP_OR:{code:133,category:"bitwise",description:"Bitwise OR of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)|(r[o]||0);t.push(i)}},OP_XOR:{code:134,category:"bitwise",description:"Bitwise XOR of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)^(r[o]||0);t.push(i)}},OP_EQUAL:{code:135,category:"bitwise",description:"Push 1 if top two items are equal, 0 otherwise",action:t=>{let e=t.pop(),r=t.pop();t.push(e.equals(r)?H.encode(1):H.encode(0))}},OP_EQUALVERIFY:{code:136,category:"bitwise",description:"Fail if top two items are not equal",action:t=>{let e=t.pop(),r=t.pop();if(!e.equals(r))throw new Error("OP_EQUALVERIFY failed")}},OP_1ADD:{code:139,category:"arithmetic",description:"Add 1 to top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e+1))}},OP_1SUB:{code:140,category:"arithmetic",description:"Subtract 1 from top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e-1))}},OP_2MUL:{code:141,category:"arithmetic",description:"Multiply top item by 2 (disabled)",action:()=>{throw new Error("OP_2MUL is disabled")}},OP_2DIV:{code:142,category:"arithmetic",description:"Divide top item by 2 (disabled)",action:()=>{throw new Error("OP_2DIV is disabled")}},OP_NEGATE:{code:143,category:"arithmetic",description:"Negate top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(-e))}},OP_ABS:{code:144,category:"arithmetic",description:"Absolute value of top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(Math.abs(e)))}},OP_NOT:{code:145,category:"arithmetic",description:"Logical NOT (0\u21921, non-zero\u21920)",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e===0?1:0))}},OP_0NOTEQUAL:{code:146,category:"arithmetic",description:"Push 1 if top item is not zero, 0 otherwise",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e!==0?1:0))}},OP_ADD:{code:147,category:"arithmetic",description:"Add top two items",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r+e))}},OP_SUB:{code:148,category:"arithmetic",description:"Subtract: second - first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r-e))}},OP_MUL:{code:149,category:"arithmetic",description:"Multiply top two items",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r*e))}},OP_DIV:{code:150,category:"arithmetic",description:"Divide: second / first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e===0)throw new Error("Division by zero");t.push(H.encode(Math.floor(r/e)))}},OP_MOD:{code:151,category:"arithmetic",description:"Modulo: second % first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e===0)throw new Error("Division by zero");t.push(H.encode(r%e))}},OP_LSHIFT:{code:152,category:"arithmetic",description:"Left shift: second << first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<<e))}},OP_RSHIFT:{code:153,category:"arithmetic",description:"Right shift: second >> first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>>e))}},OP_BOOLAND:{code:154,category:"arithmetic",description:"Boolean AND: 1 if both non-zero, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==0&&r!==0?1:0))}},OP_BOOLOR:{code:155,category:"arithmetic",description:"Boolean OR: 1 if either non-zero, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==0||r!==0?1:0))}},OP_NUMEQUAL:{code:156,category:"arithmetic",description:"Push 1 if numbers are equal, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e===r?1:0))}},OP_NUMEQUALVERIFY:{code:157,category:"arithmetic",description:"Fail if numbers are not equal",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e!==r)throw new Error("OP_NUMEQUALVERIFY failed")}},OP_NUMNOTEQUAL:{code:158,category:"arithmetic",description:"Push 1 if numbers are not equal, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==r?1:0))}},OP_LESSTHAN:{code:159,category:"arithmetic",description:"Push 1 if second < first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<e?1:0))}},OP_GREATERTHAN:{code:160,category:"arithmetic",description:"Push 1 if second > first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>e?1:0))}},OP_LESSTHANOREQUAL:{code:161,category:"arithmetic",description:"Push 1 if second <= first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<=e?1:0))}},OP_GREATERTHANOREQUAL:{code:162,category:"arithmetic",description:"Push 1 if second >= first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>=e?1:0))}},OP_MIN:{code:163,category:"arithmetic",description:"Push smaller of top two numbers",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(Math.min(e,r)))}},OP_MAX:{code:164,category:"arithmetic",description:"Push larger of top two numbers",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(Math.max(e,r)))}},OP_WITHIN:{code:165,category:"arithmetic",description:"Push 1 if x is within [min, max), 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=H.decode(t.pop());t.push(H.encode(n>=r&&n<e?1:0))}},OP_RIPEMD160:{code:166,category:"crypto",description:"RIPEMD-160 hash of top item",action:t=>{let r=se().createHash("ripemd160").update(t.pop()).digest();t.push(r)}},OP_SHA1:{code:167,category:"crypto",description:"SHA-1 hash of top item",action:t=>{let r=se().createHash("sha1").update(t.pop()).digest();t.push(r)}},OP_SHA256:{code:168,category:"crypto",description:"SHA-256 hash of top item",action:t=>{let r=se().createHash("sha256").update(t.pop()).digest();t.push(r)}},OP_HASH160:{code:169,category:"crypto",description:"SHA-256 then RIPEMD-160 hash of top item",action:t=>{let e=se(),r=e.createHash("sha256").update(t.pop()).digest(),n=e.createHash("ripemd160").update(r).digest();t.push(n)}},OP_HASH256:{code:170,category:"crypto",description:"Double SHA-256 hash of top item",action:t=>{let e=se(),r=e.createHash("sha256").update(t.pop()).digest(),n=e.createHash("sha256").update(r).digest();t.push(n)}},OP_CODESEPARATOR:{code:171,category:"crypto",description:"Mark signature checking boundary",action:t=>{}},OP_CHECKSIG:{code:172,category:"crypto",description:"Verify signature against public key",action:"// Signature verification (requires transaction context)"},OP_CHECKSIGVERIFY:{code:173,category:"crypto",description:"Verify signature, then fail if invalid",action:"// Signature verification with VERIFY (requires transaction context)"},OP_CHECKMULTISIG:{code:174,category:"crypto",description:"Verify multiple signatures against public keys",action:"// Multi-signature verification (requires transaction context)"},OP_CHECKMULTISIGVERIFY:{code:175,category:"crypto",description:"Verify multiple signatures, then fail if invalid",action:"// Multi-signature verification with VERIFY (requires transaction context)"},OP_SUBSTR:{code:179,category:"string",description:"Extract substring: string[start:start+length]",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=t.pop();t.push(n.slice(r,r+e))}},OP_LEFT:{code:180,category:"string",description:"Extract leftmost n bytes",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(0,e))}},OP_RIGHT:{code:181,category:"string",description:"Extract rightmost n bytes",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(-e))}},OP_NOP1:{code:176,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP2:{code:177,category:"nop",description:"No operation (formerly CHECKLOCKTIMEVERIFY)",action:t=>{}},OP_NOP3:{code:178,category:"nop",description:"No operation (formerly CHECKSEQUENCEVERIFY)",action:t=>{}},OP_NOP4:{code:182,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP5:{code:183,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP6:{code:184,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP7:{code:185,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP8:{code:186,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP9:{code:187,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP10:{code:188,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_RESERVED1:{code:137,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED1 encountered")}},OP_RESERVED2:{code:138,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED2 encountered")}},OP_CHECKLOCKTIMEVERIFY:{code:177,category:"disabled",description:"Check locktime (disabled post-Genesis)",action:t=>{}},OP_CHECKSEQUENCEVERIFY:{code:178,category:"disabled",description:"Check sequence (disabled post-Genesis)",action:t=>{}},OP_PUBKEYHASH:{code:253,category:"pseudo",description:"Template matching: public key hash",action:"// Template matching only"},OP_PUBKEY:{code:254,category:"pseudo",description:"Template matching: public key",action:"// Template matching only"},OP_INVALIDOPCODE:{code:255,category:"pseudo",description:"Invalid opcode placeholder",action:()=>{throw new Error("Invalid opcode encountered")}}},Hn={getByCategory:t=>Object.entries(Ue).filter(([e,r])=>r.category===t).reduce((e,[r,n])=>({...e,[r]:n}),{}),getCategories:()=>{let t=new Set;return Object.values(Ue).forEach(e=>t.add(e.category)),Array.from(t).sort()},createASM:t=>{let e=[];return t.forEach(r=>{if(typeof r=="string"&&Ue[r])e.push(r);else if(typeof r=="number")if(r>=1&&r<=16)e.push(`OP_${r}`);else if(r===0)e.push("OP_0");else if(r===-1)e.push("OP_1NEGATE");else{let n=H.encode(r);e.push(n.toString("hex"))}else if(E.Buffer.isBuffer(r))e.push(r.toString("hex"));else throw new Error(`Invalid operation: ${r}`)}),e.join(" ")},simulate:(t,e=[])=>{let r=[...e],n=[],i=[];return t.forEach((o,c)=>{if(!Ue[o])throw new Error(`Unknown opcode: ${o}`);let h=Ue[o],d=[...r];if(typeof h.action=="function")try{h.action(r,n),i.push({step:c+1,opcode:o,beforeStack:d.map(x=>x.toString("hex")),afterStack:r.map(x=>x.toString("hex")),description:h.description})}catch(x){throw i.push({step:c+1,opcode:o,beforeStack:d.map(v=>v.toString("hex")),afterStack:[],error:x.message,description:h.description}),x}else i.push({step:c+1,opcode:o,beforeStack:d.map(x=>x.toString("hex")),afterStack:d.map(x=>x.toString("hex")),note:h.action,description:h.description})}),{finalStack:r.map(o=>o.toString("hex")),finalAltStack:n.map(o=>o.toString("hex")),history:i}},opcodeToName:t=>{let e=Object.entries(Ue).find(([r,n])=>n.code===t);return e?e[0]:`UNKNOWN_${t.toString(16).padStart(2,"0")}`},nameToOpcode:t=>Ue[t]&&Ue[t].code,generateCovenantTemplate:(t,e)=>{let r=[];return t==="value"&&(r.push("OP_SIZE"),r.push(52),r.push("OP_SUB"),r.push("OP_SPLIT"),r.push("OP_DROP"),r.push(8),r.push("OP_SPLIT"),r.push("OP_DROP")),e&&(r.push(E.Buffer.from(e,"hex")),r.push("OP_EQUAL")),{operations:r,asm:Hn.createASM(r),description:`Extract ${t} field and compare with expected value`}}};Ao.exports={opcodeMap:Ue,scriptNum:H,utils:Hn};if(ve.main===Ao){console.log("\u{1F527} Comprehensive Bitcoin Script Opcode Map"),console.log("=========================================="),console.log(`Total opcodes mapped: ${Object.keys(Ue).length}`),console.log(`
|
|
5
|
+
`)};tt.prototype._extractSpecificField=function(t,e){var r=e[t];return r?E.Buffer.from(r,"hex"):null};tt.prototype._interpretField=function(t,e,r){if(!e)return null;var n={raw:e.toString("hex"),bytes:e.length};try{switch(t){case"nVersion":n.value=e.readUInt32LE(0),n.description="Transaction version "+n.value;break;case"value":e.length===8&&(n.satoshis=e.readBigUInt64LE(0).toString(),n.description=n.satoshis+" satoshis");break;case"sighashType":var i=e.readUInt32LE(0),o={1:"SIGHASH_ALL",65:"SIGHASH_ALL | FORKID",2:"SIGHASH_NONE",66:"SIGHASH_NONE | FORKID",3:"SIGHASH_SINGLE",67:"SIGHASH_SINGLE | FORKID"};n.value=i,n.description=o[i]||"Custom ("+i+")";break;case"outpoint_vout":n.value=e.readUInt32LE(0),n.description="Output index "+n.value;break;case"scriptLen":n.varintSize=r.scriptLenSize,n.scriptLength=r.scriptLen,n.description=r.scriptLen+" bytes encoded as "+r.scriptLenSize+"-byte varint";break;case"scriptCode":e.length===25&&e[0]===118&&e[1]===169?(n.description="Standard P2PKH script (25 bytes)",n.type="P2PKH"):e.length>0&&e[0]===106?(n.description="OP_RETURN data script ("+e.length+" bytes)",n.type="OP_RETURN"):(n.description="Custom script ("+e.length+" bytes)",n.type="CUSTOM");break;default:if(["hashPrevouts","hashSequence","hashOutputs"].includes(t)){var c=E.Buffer.alloc(32);e.equals(c)?(n.isZero=!0,n.description="Zero hash (check SIGHASH flags)"):n.description="32-byte hash"}}}catch(h){n.error=h.message}return n};tt.prototype._getExtractionStrategy=function(t){var e=["value","nSequence","hashOutputs","nLocktime","sighashType"],r=["nVersion","hashPrevouts","hashSequence","outpoint_txid","outpoint_vout"];return e.includes(t)?"RIGHT":r.includes(t)?"LEFT":t==="scriptCode"?"DYNAMIC":t==="scriptLen"?"VARINT":"UNKNOWN"};tt.decodeCompactSize=function(t,e){if(e>=t.length)throw new Error("CompactSize read past end of preimage buffer (offset "+e+", length "+t.length+")");var r=t[e];if(r<253)return{value:r,nextOffset:e+1,bytes:1};if(r===253){if(e+3>t.length)throw new Error("Truncated 2-byte CompactSize in preimage at offset "+e);var n=t.readUInt16LE(e+1);return{value:n,nextOffset:e+3,bytes:3}}else if(r===254){if(e+5>t.length)throw new Error("Truncated 4-byte CompactSize in preimage at offset "+e);var i=t.readUInt32LE(e+1);return{value:i,nextOffset:e+5,bytes:5}}else throw new Error("Invalid CompactSize: 8-byte length prefix (0xff) is not a valid script length")};tt.fromTransaction=function(t,e,r,n,i){var o=rn.Transaction.sighash.sighashPreimage(t,i,e,r,new rn.crypto.BN(n));return new tt(o,{transaction:t,inputIndex:e,subscript:r,satoshis:n,sighashType:i})};tt.createExample=function(t){var e=rn.PrivateKey.fromRandom(),r=e.toAddress(),n={txId:"0".repeat(64),outputIndex:0,script:rn.Script.buildPublicKeyHashOut(r).toHex(),satoshis:1e5},i=new rn.Transaction().from(n).to(r,99e3),o=rn.Script.fromHex(n.script);return tt.fromTransaction(i,0,o,n.satoshis,t)};tt.extractFromHex=function(t,e,r){var n=new tt(t,{deferExtraction:!0});return n.extractField(e,r)};tt.generateASMFromHex=function(t,e,r){var n=new tt(t,{deferExtraction:!0});return n.generateASM(e,r)};tt.extractMultipleFromHex=function(t,e){var r=new tt(t,{deferExtraction:!0});return r.extractFields(e)};tt.validateFromHex=function(t){var e=new tt(t);return e.validate()};tt.analyzeFromHex=function(t){var e=new tt(t),r=e._parsePreimageStructure(),n=e.validate();return{hex:t,length:t.length/2,structure:r._structure,fields:r,validation:n,sighashInfo:e.getSighashInfo(),extractField:function(i){return e.extractField(i)},generateASM:function(i){return e.generateASM(i)},getSummary:function(){return{totalBytes:r._structure.totalActual,scriptLength:r.scriptLen,scriptVarintSize:r.scriptLenSize,sighashType:r.sighashType,valid:n.valid,warnings:n.warnings}}}};Ha.exports=tt});var Ca=Z((Zp,La)=>{"use strict";I();var fe=de();function Ee(t){if(!(this instanceof Ee))return new Ee(t);this.sighashType=t||fe.crypto.Signature.SIGHASH_ALL|fe.crypto.Signature.SIGHASH_FORKID,this.analysis=this._analyzeFlags()}Ee.prototype.analyze=function(){return this.analysis};Ee.prototype.getZeroHashBehavior=function(){var t={hashPrevouts:!1,hashSequence:!1,hashOutputs:!1,explanation:[],criticalNote:null};return this.analysis.anyoneCanPay&&(t.hashPrevouts=!0,t.explanation.push("ANYONECANPAY: hashPrevouts becomes zero hash (0x00...00)")),this.analysis.baseType==="NONE"&&(t.hashSequence=!0,t.hashOutputs=!0,t.explanation.push("SIGHASH_NONE: hashSequence and hashOutputs become zero hash")),this.analysis.baseType==="SINGLE"&&(t.hashSequence=!0,t.hashOutputs=!0,t.explanation.push("SIGHASH_SINGLE: hashSequence becomes zero hash, hashOutputs covers only corresponding output")),(t.hashPrevouts||t.hashSequence||t.hashOutputs)&&(t.criticalNote="These zero hashes are NOT bugs - they are correct BIP-143 behavior for the specified SIGHASH flags!"),t};Ee.prototype.generateExample=function(){var t=fe.PrivateKey.fromRandom(),e=t.toAddress(),r={txId:"a".repeat(64),outputIndex:0,script:fe.Script.buildPublicKeyHashOut(e).toHex(),satoshis:1e5},n=new fe.Transaction().from(r).to(e,99e3),i=fe.Script.fromHex(r.script),o=fe.Transaction.sighash.sighashPreimage(n,this.sighashType,0,i,new fe.crypto.BN(r.satoshis)),c=Xe(),h=new c(o);return{transaction:n,preimage:h,sighashType:this.sighashType,analysis:this.analysis,zeroHashBehavior:this.getZeroHashBehavior(),fields:h.extract(),validation:h.validate()}};Ee.prototype.createDemonstration=function(){var t=this.generateExample(),e=E.Buffer.alloc(32).toString("hex"),r={sighashType:this.sighashType,analysis:this.analysis,zeroHashBehavior:this.getZeroHashBehavior(),preimageFields:{},observations:[],educationalNotes:[]},n=t.preimage.toObject().fields;return r.preimageFields=n,n.hashPrevouts===e&&r.observations.push({field:"hashPrevouts",value:"ZERO HASH (00...00)",reason:"ANYONECANPAY flag - this input can be combined with any other inputs"}),n.hashSequence===e&&r.observations.push({field:"hashSequence",value:"ZERO HASH (00...00)",reason:this.analysis.baseType+" flag - sequence numbers not covered by signature"}),n.hashOutputs===e&&r.observations.push({field:"hashOutputs",value:"ZERO HASH (00...00)",reason:this.analysis.baseType+" flag - outputs not fully covered by signature"}),r.educationalNotes=["Zero hashes in preimages are NOT errors - they indicate specific SIGHASH flag behavior","BIP-143 mandates these zero values when certain flags are used","ANYONECANPAY allows this input to be combined with different sets of inputs","SIGHASH_NONE means the signer doesn't care about any outputs","SIGHASH_SINGLE means the signer only cares about the corresponding output","Always check SIGHASH flags when you see 'mysterious' zero hashes in preimages"],r};Ee.prototype.checkCompliance=function(t){var e=t.toObject().fields,r=E.Buffer.alloc(32).toString("hex"),n={compliant:!0,issues:[],expectedZeros:[],unexpectedZeros:[]},i=this.getZeroHashBehavior();return i.hashPrevouts&&e.hashPrevouts!==r?(n.compliant=!1,n.issues.push("hashPrevouts should be zero due to ANYONECANPAY flag")):!i.hashPrevouts&&e.hashPrevouts===r&&n.unexpectedZeros.push("hashPrevouts is zero but ANYONECANPAY not set"),i.hashSequence&&e.hashSequence!==r?(n.compliant=!1,n.issues.push("hashSequence should be zero due to "+this.analysis.baseType+" flag")):!i.hashSequence&&e.hashSequence===r&&n.unexpectedZeros.push("hashSequence is zero but "+this.analysis.baseType+" allows sequence coverage"),i.hashOutputs&&e.hashOutputs!==r?(n.compliant=!1,n.issues.push("hashOutputs should be zero due to "+this.analysis.baseType+" flag")):!i.hashOutputs&&e.hashOutputs===r&&n.unexpectedZeros.push("hashOutputs is zero but "+this.analysis.baseType+" should cover outputs"),n};Ee.prototype._analyzeFlags=function(){var t=this.sighashType&31,e=(this.sighashType&128)!==0,r=(this.sighashType&64)!==0,n="UNKNOWN";t===1?n="ALL":t===2?n="NONE":t===3&&(n="SINGLE");var i=[];return i.push(n),e&&i.push("ANYONECANPAY"),r&&i.push("FORKID"),{sighashType:this.sighashType,baseType:n,anyoneCanPay:e,forkId:r,flagName:i.join(" | "),hex:"0x"+this.sighashType.toString(16).padStart(8,"0"),binary:"0b"+this.sighashType.toString(2).padStart(32,"0")}};Ee.getAllTypes=function(){var t=fe.crypto.Signature.SIGHASH_FORKID;return[{name:"ALL",value:fe.crypto.Signature.SIGHASH_ALL|t},{name:"NONE",value:fe.crypto.Signature.SIGHASH_NONE|t},{name:"SINGLE",value:fe.crypto.Signature.SIGHASH_SINGLE|t},{name:"ALL | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_ALL|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t},{name:"NONE | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_NONE|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t},{name:"SINGLE | ANYONECANPAY",value:fe.crypto.Signature.SIGHASH_SINGLE|fe.crypto.Signature.SIGHASH_ANYONECANPAY|t}]};Ee.generateAllDemonstrations=function(){return Ee.getAllTypes().map(function(t){var e=new Ee(t.value);return{typeName:t.name,demonstration:e.createDemonstration()}})};Ee.explainZeroMystery=function(){return{title:"The 'Extra Zero' Mystery in Bitcoin Preimages",problem:"Developers often see zero hashes (0x00...00) in preimage fields and think it's a bug",reality:"These zeros are CORRECT behavior mandated by BIP-143 for specific SIGHASH flags",explanation:["ANYONECANPAY sets hashPrevouts to zero - allows input combination flexibility","SIGHASH_NONE sets hashSequence and hashOutputs to zero - signer doesn't care about outputs","SIGHASH_SINGLE sets hashSequence to zero - only corresponding output matters","These are features, not bugs - they enable advanced Bitcoin transaction patterns"],solution:"Always check SIGHASH flags when analyzing preimages with zero hashes",toolTip:"Use SIGHASH.checkCompliance() to verify if zero hashes match expected flag behavior"}};La.exports=Ee});var Ua=Z((Wp,Na)=>{"use strict";I();var _t=de();function ae(t,e){if(!(this instanceof ae))return new ae(t,e);this.privateKey=t,this.publicKey=t?t.publicKey:null,this.options=e||{},this.allowNonEnforcing=this.options.allowNonEnforcing===!0,this.conditions=[],this.preimageFields=[],this.scriptTemplate=null,this.validationRules=[],this.sighashType=this.options.sighashType||_t.crypto.Signature.SIGHASH_ALL|_t.crypto.Signature.SIGHASH_FORKID}ae.prototype._assertEnforcingAllowed=function(){if(!this.allowNonEnforcing)throw new Error("SmartContract.Builder produces a NON-ENFORCING script (constant hash-lock \u2192 plain P2PK; it does not constrain the spend). Use SmartContract.policy() (declarative OP_PUSH_TX), or SmartContract.PushTx / Token / valueCovenant for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.")};ae.prototype.validateField=function(t,e,r){r=r||{};var n={field:t,expectedValue:e,operator:r.operator||"EQUAL",required:r.required!==!1,description:r.description||"Validate "+t};return this.validationRules.push(n),this};ae.prototype.addCondition=function(t,e){e=e||{};var r={type:typeof t=="function"?"CUSTOM":"OPCODE",condition:t,description:e.description||"Custom condition",required:e.required!==!1};return this.conditions.push(r),this};ae.prototype.useTemplate=function(t,e){return this.scriptTemplate={name:t,params:e||{},customScript:typeof t=="object"?t:null},this};ae.prototype.buildLockingScript=function(t){this._assertEnforcingAllowed();var e=new _t.Script;return this.scriptTemplate?this._buildFromTemplate(t):this._buildMultiFieldCovenant(t)};ae.prototype.buildUnlockingScript=function(t,e,r){var n=new _t.Script,i=_t.Script.fromHex(r.script),o=_t.Transaction.sighash.sign(t,this.privateKey,this.sighashType,e,i,new _t.crypto.BN(r.satoshis)),c=E.Buffer.concat([o.toDER(),E.Buffer.from([this.sighashType])]);return n.add(c),r.originalPreimage&&n.add(E.Buffer.from(r.originalPreimage,"hex")),this.conditions.forEach(function(h){h.type==="UNLOCK_DATA"&&n.add(h.data)}),n};ae.prototype.createCovenant=function(t,e){this._assertEnforcingAllowed(),e=e||{};var r=new _t.Transaction().from({txId:t.txid,outputIndex:t.vout,script:t.script,satoshis:t.satoshis}).to(this.privateKey.toAddress(),t.satoshis-(e.fee||1e3)),n=_t.Script.fromHex(t.script),i=_t.Transaction.sighash.sighashPreimage(r,this.sighashType,0,n,new _t.crypto.BN(t.satoshis)),o=Xe(),c=new o(i),h=c.extract(),d=this.buildLockingScript({preimage:i,fields:h,transaction:r});r.outputs[0].setScript(d),r.sign(this.privateKey);var x={txid:r.id,vout:0,satoshis:t.satoshis-(e.fee||1e3),script:d.toHex(),originalPreimage:i.toString("hex"),preimageFields:h,validationRules:this.validationRules.slice(),conditions:this.conditions.slice(),template:this.scriptTemplate,createdAt:new Date().toISOString(),type:"builder_covenant"};return{creationTx:r,covenantUtxo:x,lockingScript:d,preimageData:{preimage:i,fields:h}}};ae.prototype.validateSpending=function(t,e){var r={valid:!0,errors:[],warnings:[],fieldValidations:[]},n=_t.Script.fromHex(e.script),i=_t.Transaction.sighash.sighashPreimage(t,this.sighashType,0,n,new _t.crypto.BN(e.satoshis)),o=Xe(),c=new o(i),h=c.extract();e.validationRules&&e.validationRules.forEach(function(O){var T=this._validateFieldRule(O,h,e.preimageFields);r.fieldValidations.push(T),!T.passed&&O.required&&(r.valid=!1,r.errors.push(T.error))}.bind(this));var d=new _t.Script.Interpreter,x=_t.Script.Interpreter.SCRIPT_VERIFY_P2SH|_t.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|_t.Script.Interpreter.SCRIPT_VERIFY_DERSIG|_t.Script.Interpreter.SCRIPT_VERIFY_LOW_S|_t.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,v=t.inputs[0].script,y=_t.Script.fromHex(e.script),A=d.verify(v,y,t,0,x,new _t.crypto.BN(e.satoshis));return A||(r.valid=!1,r.errors.push("Script interpreter validation failed: "+d.errstr)),r};ae.prototype._buildFromTemplate=function(t){var e=this.scriptTemplate;if(e.name==="HASH_LOCK")return this._buildHashLockTemplate(t,e.params);if(e.name==="MULTI_FIELD")return this._buildMultiFieldTemplate(t,e.params);if(e.customScript)return e.customScript;throw new Error("Unknown template: "+e.name)};ae.prototype._buildMultiFieldCovenant=function(t){var e=new _t.Script;return e.add("OP_DUP"),this.validationRules.forEach(function(r,n){if(n>0&&e.add("OP_DUP"),e.add("OP_HASH256"),r.expectedValue){var i=_t.crypto.Hash.sha256sha256(E.Buffer.from(r.expectedValue,"hex"));e.add(i),e.add("OP_EQUALVERIFY")}}),e.add("OP_DROP"),this.publicKey&&(e.add(this.publicKey.toBuffer()),e.add("OP_CHECKSIG")),e};ae.prototype._buildHashLockTemplate=function(t,e){var r=new _t.Script;r.add("OP_DUP"),r.add("OP_HASH256");var n=e.hash||_t.crypto.Hash.sha256sha256(t.preimage);return r.add(n),r.add("OP_EQUALVERIFY"),r.add("OP_DROP"),this.publicKey&&(r.add(this.publicKey.toBuffer()),r.add("OP_CHECKSIG")),r};ae.prototype._validateFieldRule=function(t,e,r){var n=e[t.field],i=t.expectedValue;if(typeof i=="string"&&i.startsWith("ORIGINAL_")){var o=i.replace("ORIGINAL_","");i=r[o]}var c=!1,h=null;switch(t.operator){case"EQUAL":c=n&&n.equals?n.equals(i):n===i,c||(h=t.field+" does not equal expected value");break;case"NOT_EQUAL":c=n&&n.equals?!n.equals(i):n!==i,c||(h=t.field+" should not equal specified value");break;case"PRESENT":c=!!n,c||(h=t.field+" is required but not present");break;default:h="Unknown validation operator: "+t.operator}return{field:t.field,operator:t.operator,passed:c,error:h,description:t.description}};ae.createHashLock=function(t,e){return new ae(t).useTemplate("HASH_LOCK",{hash:e})};ae.createMultiField=function(t,e){var r=new ae(t);return e.forEach(function(n){r.validateField(n.field,n.expectedValue,n.options)}),r};Na.exports=ae});var Da=Z((Jp,qa)=>{I();qa.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var ja=Z((em,Eo)=>{I();var Bt=function(){(typeof N.default<"u"&&N.default.env&&N.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG)&&console.log.apply(console,arguments)},cl,Pr,bo,nn;if(typeof window>"u"&&typeof ve=="function")try{Pr=se(),bo=se(),nn=bo.join(__dirname,"blockchain-state.json")}catch{Bt("BlockchainState: Running in browser mode - persistence disabled")}else cl=typeof window<"u"&&window.bsv||Da();function ai(){return{metadata:{createdAt:new Date().toISOString(),lastUpdated:new Date().toISOString(),totalWallets:0,totalUTXOs:0,totalValue:0,blockHeight:0},wallets:{},globalUTXOSet:{},spentUTXOs:{},transactionHistory:[]}}function on(){try{if(!Pr||!nn)return ai();if(!Pr.existsSync(nn)){Bt("\u{1F195} Creating new blockchain state...");let e=ai();return sn(e),e}let t=JSON.parse(Pr.readFileSync(nn,"utf8"));return Bt("\u{1F4D6} Loaded existing blockchain state"),t}catch(t){return console.error("\u274C Error loading blockchain state:",t.message),ai()}}function sn(t){try{t.metadata.lastUpdated=new Date().toISOString(),Pr&&nn&&(Pr.writeFileSync(nn,JSON.stringify(t,null,2)),Bt("\u{1F4BE} Blockchain state saved"))}catch(e){console.error("\u274C Error saving blockchain state:",e.message)}}function Ga(t,e){Bt(`\u{1F4DD} Registering wallet: ${t}`);let r=on();return r.wallets[t]&&Bt("\u2139\uFE0F Wallet already exists, updating..."),r.wallets[t]={address:t,registeredAt:e.registeredAt||new Date().toISOString(),utxos:e.utxos||[],totalValue:0},e.utxos&&e.utxos.forEach(n=>{let i=`${n.txid}:${n.vout}`;r.globalUTXOSet[i]={...n,ownerAddress:t}}),r.metadata.totalWallets=Object.keys(r.wallets).length,So(r),sn(r),Bt(`\u2705 Wallet registered: ${t}`),r}function za(t,e){let r=on(),n=`${t}:${e}`;return r.spentUTXOs[n]?{exists:!1,spent:!0,utxo:r.spentUTXOs[n]}:r.globalUTXOSet[n]?{exists:!0,spent:!1,utxo:r.globalUTXOSet[n]}:{exists:!1,spent:!1,utxo:null}}function ul(t,e){let r=za(t,e);return r.exists&&!r.spent}function hl(t,e,r){let n=on(),i=`${t}:${e}`;if(!n.globalUTXOSet[i])throw new Error(`UTXO ${i} does not exist`);if(n.spentUTXOs[i])throw new Error(`UTXO ${i} already spent`);let o=n.globalUTXOSet[i];n.spentUTXOs[i]={...o,spentInTx:r,spentAt:new Date().toISOString()},delete n.globalUTXOSet[i];let c=n.wallets[o.ownerAddress];c&&(c.utxos=c.utxos.filter(h=>!(h.txid===t&&h.vout===e))),So(n),sn(n),Bt(`\u274C UTXO spent: ${i} in tx ${r}`)}function fl(t,e){let r=on(),n=`${t.txid}:${t.vout}`;if(r.globalUTXOSet[n]){Bt(`\u26A0\uFE0F UTXO ${n} already exists, skipping`);return}r.globalUTXOSet[n]={...t,ownerAddress:e,createdAt:new Date().toISOString()},r.wallets[e]||(r.wallets[e]={address:e,registeredAt:new Date().toISOString(),utxos:[],totalValue:0}),r.wallets[e].utxos.some(o=>o.txid===t.txid&&o.vout===t.vout)||r.wallets[e].utxos.push(t),So(r),sn(r),Bt(`\u2705 UTXO added: ${n} for ${e}`)}function So(t){let e=Object.keys(t.globalUTXOSet).length,r=Object.values(t.globalUTXOSet).reduce((n,i)=>n+i.satoshis,0);t.metadata.totalUTXOs=e,t.metadata.totalValue=r,Object.values(t.wallets).forEach(n=>{n.totalValue=n.utxos.reduce((i,o)=>i+o.satoshis,0)})}function Va(){let t=on();return Bt("\u{1F310} Blockchain State Statistics:"),Bt("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),Bt(`\u{1F4CA} Total Wallets: ${t.metadata.totalWallets}`),Bt(`\u{1F4B0} Total UTXOs: ${t.metadata.totalUTXOs}`),Bt(`\u{1F48E} Total Value: ${t.metadata.totalValue} satoshis`),Bt(`\u{1F3D7}\uFE0F Block Height: ${t.metadata.blockHeight}`),Bt(`\u{1F550} Last Updated: ${t.metadata.lastUpdated}
|
|
6
|
+
`),Object.keys(t.wallets).length>0&&(Bt("\u{1F45B} Registered Wallets:"),Object.entries(t.wallets).forEach(([e,r])=>{Bt(` ${e}: ${r.utxos.length} UTXOs, ${r.totalValue} sats`)})),t}function Ka(){let t=bo.join(__dirname,"wallet.json");if(!Pr.existsSync(t))return Bt("\u274C No wallet.json found to import"),!1;try{let e=JSON.parse(Pr.readFileSync(t,"utf8"));Bt("\u{1F4E5} Importing wallet from wallet.json...");let r={registeredAt:new Date().toISOString(),utxos:e.availableUTXOs||[e.utxo]};return Ga(e.wallet.address,r),Bt("\u2705 Wallet imported successfully"),!0}catch(e){return console.error("\u274C Error importing wallet:",e.message),!1}}if(ve.main===Eo){let t=N.default.argv.slice(2);if(t[0]==="import")Ka();else if(t[0]==="init"){let e=ai();sn(e),Bt("\u{1F195} Initialized new blockchain state")}Va()}Eo.exports={loadBlockchainState:on,saveBlockchainState:sn,registerWallet:Ga,getUTXO:za,isUTXOAvailable:ul,spendUTXO:hl,addUTXO:fl,getBlockchainStats:Va,importWalletFromFile:Ka}});var $a=Z((im,Ya)=>{I();Ya.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var Wa=Z((sm,Xa)=>{"use strict";I();var Ne=function(){(typeof N.default<"u"&&N.default.env&&N.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG)&&console.log.apply(console,arguments)},_o,Za,ll,dr;if(typeof window>"u"&&typeof ve=="function")try{_o=se(),Za=se(),ll=se(),dr=ja()}catch{Ne("SmartUTXO: Running in browser mode - some features may be limited")}var Oo=class{constructor(e={}){this.options=e||{},this.loadState()}loadState(){try{return dr.loadBlockchainState()}catch(e){return Ne("\u26A0\uFE0F Could not load blockchain state:",e.message),null}}saveState(){try{let e=dr.loadBlockchainState();dr.saveBlockchainState(e);let r=Object.keys(e.globalUTXOSet||{}).length;Ne(`\u{1F4BE} Saved blockchain state with ${r} UTXOs`)}catch(e){Ne("\u26A0\uFE0F Could not save blockchain state:",e.message)}}getUTXOsForAddress(e){try{let r=dr.loadBlockchainState();return!r.wallets||!r.wallets[e]?[]:r.wallets[e].utxos||[]}catch(r){return Ne("\u26A0\uFE0F Error getting UTXOs:",r.message),[]}}addUTXO(e){try{dr.addUTXO(e,e.address)}catch(r){Ne("\u26A0\uFE0F Error adding UTXO:",r.message)}}spendUTXOs(e,r="manual-spend"){try{for(let n of e)dr.spendUTXO(n.txid,n.vout,r)}catch(n){Ne("\u26A0\uFE0F Error spending UTXOs:",n.message)}}createMockUTXOs(e,r=5,n=1e5){let i=$a(),o=i.Script.buildPublicKeyHashOut(i.Address.fromString(e)).toHex(),c=[];for(let h=0;h<r;h++)c.push({txid:i.crypto.Random.getRandomBuffer(32).toString("hex"),vout:h,address:e,satoshis:n,script:o});return c}getBalance(e){try{let r=dr.loadBlockchainState();return!r.wallets||!r.wallets[e]?0:r.wallets[e].totalValue||0}catch(r){return Ne("\u26A0\uFE0F Error getting balance:",r.message),0}}getStats(){try{let e=dr.getBlockchainStats();return{totalUTXOs:e.metadata.totalUTXOs,totalValue:e.metadata.totalValue,totalWallets:e.metadata.totalWallets,blockHeight:e.metadata.blockHeight,lastUpdated:e.metadata.lastUpdated}}catch(e){return Ne("\u26A0\uFE0F Error getting stats:",e.message),{totalUTXOs:0,totalValue:0,totalWallets:0,blockHeight:0}}}reset(){try{let e=Za.join(__dirname,"../utilities/blockchain-state.json");_o.existsSync(e)&&(_o.unlinkSync(e),Ne("\u{1F504} Blockchain state reset"))}catch(e){Ne("\u26A0\uFE0F Could not reset blockchain state:",e.message)}}};Xa.exports=Oo});var Ja=Z((um,Qa)=>{"use strict";I();var Ie=de(),dl=se();function Pe(t){if(!(this instanceof Pe))return new Pe(t);this.options=t||{},this.network=this.options.network||Ie.Networks.mainnet,this.keyRing={},this.utxoPool=[];try{var e=Wa();this.smartUTXO=new e(this.options)}catch{}}Pe.prototype.generateKeypair=function(t){t=t||"key_"+Date.now();var e=Ie.PrivateKey.fromRandom(this.network),r=e.toPublicKey(),n=e.toAddress(this.network),i={label:t,privateKey:e,publicKey:r,address:n,wif:e.toWIF(),addressString:n.toString()};return this.keyRing[t]=i,i};Pe.prototype.createRealUTXOs=function(t){t=t||{};for(var e=t.count||3,r=t.satoshis||1e5,n=t.scriptType||"P2PKH",i=t.keypair||this.generateKeypair("utxo_owner"),o=[],c=0;c<e;c++){var h=this._createSingleUTXO({keypair:i,satoshis:r,scriptType:n,vout:c});o.push(h),this.utxoPool.push(h),this.smartUTXO&&this.smartUTXO.addUTXO(h)}return o};Pe.prototype._createSingleUTXO=function(t){var e=dl.randomBytes(32).toString("hex"),r,n;switch(t.scriptType){case"P2PKH":r=Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex();break;case"P2SH":var i=Ie.Script.buildMultisigOut([t.keypair.publicKey],1);r=Ie.Script.buildScriptHashOut(i),n=r.toHex();break;case"CUSTOM":r=t.customScript||Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex();break;default:r=Ie.Script.buildPublicKeyHashOut(t.keypair.address),n=r.toHex()}return{txid:e,vout:t.vout,address:t.keypair.addressString,script:n,satoshis:t.satoshis,keypair:t.keypair,scriptType:t.scriptType,scriptObj:r,created:new Date().toISOString()}};Pe.prototype.createTestTransaction=function(t){t=t||{};var e=t.inputs||this.utxoPool.slice(0,1);if(e.length===0)throw new Error("No UTXOs available for transaction. Call createRealUTXOs() first.");var r=e.reduce(function(h,d){return h+d.satoshis},0),n=new Ie.Transaction;e.forEach(function(h){n.from({txId:h.txid,outputIndex:h.vout,address:h.address,script:h.script,satoshis:h.satoshis})});var i=t.outputAddress||e[0].keypair.addressString,o=t.outputAmount||r-1e4,c=t.fee||1e4;return n.to(i,o),n.fee(c),{transaction:n,inputUTXOs:e,unsignedHex:n.toString(),inputTotal:r,outputAmount:o,fee:c,sign:function(){return e.forEach(function(h){n.sign(h.keypair.privateKey)}),{signedTransaction:n,signedHex:n.toString(),txid:n.id}},generatePreimage:function(h,d){d=d||Ie.crypto.Signature.SIGHASH_ALL|Ie.crypto.Signature.SIGHASH_FORKID;var x=e[h];return Ie.Transaction.sighash.sighashPreimage(n,d,h,Ie.Script.fromHex(x.script),new Ie.crypto.BN(x.satoshis))}}};Pe.prototype.createCovenantTest=function(t){t=t||{};var e=this.generateKeypair("covenant_test"),r=this.createRealUTXOs({count:t.utxoCount||2,satoshis:t.satoshis||5e4,keypair:e,scriptType:t.scriptType||"P2PKH"}),n={inputs:r.slice(0,1),outputAmount:t.covenantAmount||4e4,fee:1e4},i=this.createTestTransaction(n),o=i.generatePreimage(0),c=o.toString("hex");return{keypair:e,utxos:r,transaction:i,preimage:{buffer:o,hex:c,length:o.length},extractField:function(h){try{var d=Xe();return d.extractFromHex(c,h)}catch(x){throw new Error("SmartContract.Preimage not available: "+x.message)}},validateCovenant:function(h){return{preimageValid:o.length>=182,covenantLogic:h,testPassed:!0}},getSummary:function(){return{keypair:e.addressString,utxoCount:r.length,totalValue:r.reduce(function(h,d){return h+d.satoshis},0),preimageLength:o.length,transactionId:i.transaction.id}}}};Pe.prototype.getKeypairs=function(){return this.keyRing};Pe.prototype.getUTXOs=function(){return this.utxoPool};Pe.prototype.reset=function(){this.keyRing={},this.utxoPool=[]};Pe.createTestEnvironment=function(t){var e=new Pe(t),r=e.createCovenantTest(t);return{generator:e,test:r,getPreimage:function(){return r.preimage.hex},getKeypair:function(){return r.keypair},extractField:function(n){return r.extractField(n)},generateASM:function(n){try{var i=Xe();return i.generateASMFromHex(r.preimage.hex,n)}catch(o){throw new Error("Cannot generate ASM: "+o.message)}}}};Qa.exports=Pe});var ec=Z((fm,tc)=>{"use strict";I();var pe=de();function ce(t){if(!(this instanceof ce))return new ce(t);this.options=t||{},this.flags=this.options.flags||pe.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,this.satoshis=this.options.satoshis||1e5}ce.prototype.execute=function(t){var e=this._parseScript(t.unlocking),r=this._parseScript(t.locking),n=this._createDummyTransaction(),i=new pe.Script.Interpreter,o=new pe.crypto.BN(this.satoshis);try{var c=i.verify(e,r,n,0,this.flags,o);return{success:c,unlocking:e.toASM(),locking:r.toASM(),finalStack:i.stack.map(function(h){return h.toString("hex")}),altStack:i.altstack.map(function(h){return h.toString("hex")}),error:null}}catch(h){return{success:!1,unlocking:e.toASM(),locking:r.toASM(),finalStack:[],altStack:[],error:h.message}}};ce.prototype.debug=function(t){var e=this._createCombinedScript(t),r=this._createDummyTransaction(),n=new pe.Script.Interpreter;n.script=e,n.tx=r,n.nIn=0,n.flags=this.flags;var i=[],o=e.chunks;try{for(var c=0;c<o.length;c++){var h=o[c],d=pe.Opcode.reverseMap[h.opcodenum]||"PUSH",x=n.stack.map(function(O){return O.toString("hex")}),v=n.altstack.map(function(O){return O.toString("hex")});try{n.step();var y=n.stack.map(function(O){return O.toString("hex")}),A=n.altstack.map(function(O){return O.toString("hex")});i.push({step:c+1,opcode:d,beforeStack:x,afterStack:y,beforeAltStack:v,afterAltStack:A,success:!0,error:null})}catch(O){i.push({step:c+1,opcode:d,beforeStack:x,afterStack:x,beforeAltStack:v,afterAltStack:v,success:!1,error:O.message});break}}}catch(O){i.push({step:0,opcode:"INITIALIZATION",beforeStack:[],afterStack:[],beforeAltStack:[],afterAltStack:[],success:!1,error:O.message})}return{script:e.toASM(),steps:i,totalSteps:o.length,success:i.length>0&&i[i.length-1].success}};ce.prototype.testCovenant=function(t){var e=t.preimage,r=t.constraints||{},n=this._buildCovenantScript(r,e),i=this.execute({unlocking:e,locking:n});return i.covenant={preimageLength:e.length/2,constraints:r,constraintResults:this._analyzeConstraints(e,r)},i};ce.prototype.testFieldExtraction=function(t,e){try{var r=Xe(),n=r.extractFromHex(t,e,{includeComments:!1}),i=this._cleanASM(n.asm),o=this.execute({unlocking:t,locking:i+" OP_DROP OP_TRUE"});return o.fieldExtraction={field:e,strategy:n.strategy,value:n.value,interpretation:n.interpretation,asmGenerated:n.asm,cleanedASM:i},o}catch(c){return{success:!1,error:c.message,fieldExtraction:{field:e,error:c.message}}}};ce.prototype._parseScript=function(t){if(!t)return new pe.Script;var e=t.trim(),r=/^[0-9a-fA-F]+$/.test(e.replace(/\s+/g,""));try{if(r){var n=e.length/2;return n>=180&&n<=250?new pe.Script().add(E.Buffer.from(e,"hex")):pe.Script.fromHex(e)}else return pe.Script.fromASM(e)}catch(i){throw new Error("Failed to parse script: "+i.message)}};ce.prototype._createCombinedScript=function(t){if(t.combined)return this._parseScript(t.combined);var e=this._parseScript(t.unlocking),r=this._parseScript(t.locking),n=E.Buffer.concat([e.toBuffer(),r.toBuffer()]);return pe.Script.fromBuffer(n)};ce.prototype._createDummyTransaction=function(){var t=new pe.Transaction,e=new pe.Transaction.Input({prevTxId:"0".repeat(64),outputIndex:0,script:pe.Script.empty(),satoshis:this.satoshis,output:new pe.Transaction.Output({satoshis:this.satoshis,script:pe.Script.empty()})});return t.addInput(e),t.addOutput(new pe.Transaction.Output({satoshis:this.satoshis,script:pe.Script.empty()})),t};ce.prototype._buildCovenantScript=function(t,e){var r=[];try{var n=Xe();if(t.minimumAmount){var i=n.generateASMFromHex(e,"value",!1);r.push(i),r.push("OP_BIN2NUM"),r.push(t.minimumAmount.toString()),r.push("OP_GREATERTHANOREQUAL"),r.push("OP_VERIFY")}if(t.requiredSighash){var o=n.generateASMFromHex(e,"sighashType",!1);r.push(o),r.push("OP_BIN2NUM"),r.push(t.requiredSighash.toString()),r.push("OP_EQUAL"),r.push("OP_VERIFY")}r.push("OP_TRUE");var c=r.join(" ");return this._cleanASM(c)}catch(h){throw new Error("Failed to build covenant script: "+h.message)}};ce.prototype._cleanASM=function(t){var e=t.split(`
|
|
7
|
+
`).map(function(r){return r.split("#")[0].trim()}).filter(function(r){return r.length>0}).join(" ").replace(/\s+/g," ").trim();return e=e.replace(/\b(\d+)\b/g,function(r,n){var i=parseInt(n);if(i>=1&&i<=16)return"OP_"+i;if(i===0)return"OP_0";if(i===-1)return"OP_1NEGATE";var o=i,c=o<0;c&&(o=-o);for(var h=[];o>0;)h.push(o&255),o=Math.floor(o/256);return h.length===0&&h.push(0),c?h[h.length-1]>=128?h.push(128):h[h.length-1]|=128:h.length>0&&h[h.length-1]>=128&&h.push(0),E.Buffer.from(h).toString("hex")}),e};ce.prototype._analyzeConstraints=function(t,e){var r={};try{var n=Xe();if(e.minimumAmount){var i=n.extractFromHex(t,"value",{includeComments:!1}),o=parseInt(i.interpretation.satoshis);r.amountCheck={constraint:e.minimumAmount,actual:o,satisfied:o>=e.minimumAmount}}if(e.requiredSighash){var c=n.extractFromHex(t,"sighashType",{includeComments:!1}),h=parseInt(c.value,16);r.sighashCheck={constraint:e.requiredSighash,actual:h,satisfied:(h&255)===e.requiredSighash}}}catch(d){r.error=d.message}return r};ce.test=function(t,e,r){var n=new ce(r);return n.execute({unlocking:t,locking:e})};ce.testCovenant=function(t,e,r){var n=new ce(r);return n.testCovenant({preimage:t,constraints:e})};ce.testFieldExtraction=function(t,e,r){var n=new ce(r);return n.testFieldExtraction(t,e)};tc.exports=ce});var Io=Z((dm,Ao)=>{I();var H={encode:t=>{if(t===0)return E.Buffer.alloc(0);let e=t<0,r=Math.abs(t),n=[],i=r;for(;i>0;)n.push(i&255),i>>=8;return n[n.length-1]&128?n.push(e?128:0):e&&(n[n.length-1]|=128),E.Buffer.from(n)},decode:t=>{if(t.length===0)return 0;let e=Array.from(t),r=e[e.length-1]&128;r&&(e[e.length-1]&=127);let n=0;for(let i=e.length-1;i>=0;i--)n=(n<<8)+e[i];return r?-n:n}},Ue={OP_FALSE:{code:0,category:"constants",description:"Push empty array (false value)",action:t=>t.push(E.Buffer.alloc(0))},OP_0:{code:0,category:"constants",description:"Push empty array (alias for OP_FALSE)",action:t=>t.push(E.Buffer.alloc(0))},OP_PUSHDATA1:{code:76,category:"pushdata",description:"Push next [1 byte] bytes of data",action:"Read next byte as length; push that many bytes"},OP_PUSHDATA2:{code:77,category:"pushdata",description:"Push next [2 bytes LE] bytes of data",action:"Read next 2 bytes as length; push that many bytes"},OP_PUSHDATA4:{code:78,category:"pushdata",description:"Push next [4 bytes LE] bytes of data",action:"Read next 4 bytes as length; push that many bytes"},OP_1NEGATE:{code:79,category:"constants",description:"Push number -1",action:t=>t.push(H.encode(-1))},OP_RESERVED:{code:80,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED encountered")}},OP_TRUE:{code:81,category:"constants",description:"Push number 1 (true value)",action:t=>t.push(H.encode(1))},OP_1:{code:81,category:"constants",description:"Push number 1 (alias for OP_TRUE)",action:t=>t.push(H.encode(1))},OP_2:{code:82,category:"constants",description:"Push number 2",action:t=>t.push(H.encode(2))},OP_3:{code:83,category:"constants",description:"Push number 3",action:t=>t.push(H.encode(3))},OP_4:{code:84,category:"constants",description:"Push number 4",action:t=>t.push(H.encode(4))},OP_5:{code:85,category:"constants",description:"Push number 5",action:t=>t.push(H.encode(5))},OP_6:{code:86,category:"constants",description:"Push number 6",action:t=>t.push(H.encode(6))},OP_7:{code:87,category:"constants",description:"Push number 7",action:t=>t.push(H.encode(7))},OP_8:{code:88,category:"constants",description:"Push number 8",action:t=>t.push(H.encode(8))},OP_9:{code:89,category:"constants",description:"Push number 9",action:t=>t.push(H.encode(9))},OP_10:{code:90,category:"constants",description:"Push number 10",action:t=>t.push(H.encode(10))},OP_11:{code:91,category:"constants",description:"Push number 11",action:t=>t.push(H.encode(11))},OP_12:{code:92,category:"constants",description:"Push number 12",action:t=>t.push(H.encode(12))},OP_13:{code:93,category:"constants",description:"Push number 13",action:t=>t.push(H.encode(13))},OP_14:{code:94,category:"constants",description:"Push number 14",action:t=>t.push(H.encode(14))},OP_15:{code:95,category:"constants",description:"Push number 15",action:t=>t.push(H.encode(15))},OP_16:{code:96,category:"constants",description:"Push number 16",action:t=>t.push(H.encode(16))},OP_NOP:{code:97,category:"flow_control",description:"No operation (do nothing)",action:t=>{}},OP_VER:{code:98,category:"flow_control",description:"Push transaction version (disabled)",action:()=>{throw new Error("OP_VER is disabled")}},OP_IF:{code:99,category:"flow_control",description:"Execute if top stack value is true",action:"// Conditional execution (requires parser state)"},OP_NOTIF:{code:100,category:"flow_control",description:"Execute if top stack value is false",action:"// Conditional execution (requires parser state)"},OP_VERIF:{code:101,category:"flow_control",description:"Conditional execution based on transaction version (disabled)",action:()=>{throw new Error("OP_VERIF is disabled")}},OP_VERNOTIF:{code:102,category:"flow_control",description:"Conditional execution based on transaction version (disabled)",action:()=>{throw new Error("OP_VERNOTIF is disabled")}},OP_ELSE:{code:103,category:"flow_control",description:"Else branch of conditional",action:"// Conditional execution (requires parser state)"},OP_ENDIF:{code:104,category:"flow_control",description:"End conditional block",action:"// Conditional execution (requires parser state)"},OP_VERIFY:{code:105,category:"flow_control",description:"Fail if top stack value is not true",action:t=>{let e=t.pop();if(!e||e.length===0||H.decode(e)===0)throw new Error("OP_VERIFY failed")}},OP_RETURN:{code:106,category:"flow_control",description:"Terminate script execution immediately",action:()=>{throw new Error("Script terminated by OP_RETURN")}},OP_TOALTSTACK:{code:107,category:"stack",description:"Move top item from main stack to alt stack",action:(t,e)=>e.push(t.pop())},OP_FROMALTSTACK:{code:108,category:"stack",description:"Move top item from alt stack to main stack",action:(t,e)=>t.push(e.pop())},OP_2DROP:{code:109,category:"stack",description:"Remove top two stack items",action:t=>{t.pop(),t.pop()}},OP_2DUP:{code:110,category:"stack",description:"Duplicate top two stack items",action:t=>{let e=t[t.length-1],r=t[t.length-2];t.push(E.Buffer.from(r),E.Buffer.from(e))}},OP_3DUP:{code:111,category:"stack",description:"Duplicate top three stack items",action:t=>{let e=t[t.length-1],r=t[t.length-2],n=t[t.length-3];t.push(E.Buffer.from(n),E.Buffer.from(r),E.Buffer.from(e))}},OP_2OVER:{code:112,category:"stack",description:"Copy 3rd and 4th items to top",action:t=>{let e=t[t.length-3],r=t[t.length-4];t.push(E.Buffer.from(r),E.Buffer.from(e))}},OP_2ROT:{code:113,category:"stack",description:"Move 5th and 6th items to top",action:t=>{let e=t.splice(-5,1)[0],r=t.splice(-5,1)[0];t.push(e,r)}},OP_2SWAP:{code:114,category:"stack",description:"Swap top two pairs of items",action:t=>{let e=t.pop(),r=t.pop(),n=t.pop(),i=t.pop();t.push(r,e,i,n)}},OP_IFDUP:{code:115,category:"stack",description:"Duplicate top item if it is not zero",action:t=>{let e=t[t.length-1];e.length>0&&H.decode(e)!==0&&t.push(E.Buffer.from(e))}},OP_DEPTH:{code:116,category:"stack",description:"Push stack size as number",action:t=>t.push(H.encode(t.length))},OP_DROP:{code:117,category:"stack",description:"Remove top stack item",action:t=>t.pop()},OP_DUP:{code:118,category:"stack",description:"Duplicate top stack item",action:t=>t.push(E.Buffer.from(t[t.length-1]))},OP_NIP:{code:119,category:"stack",description:"Remove second-to-top item",action:t=>{let e=t.pop();t.pop(),t.push(e)}},OP_OVER:{code:120,category:"stack",description:"Copy second-to-top item to top",action:t=>t.push(E.Buffer.from(t[t.length-2]))},OP_PICK:{code:121,category:"stack",description:"Copy nth item to top (0-indexed from top)",action:t=>{let e=H.decode(t.pop());t.push(E.Buffer.from(t[t.length-1-e]))}},OP_ROLL:{code:122,category:"stack",description:"Move nth item to top (0-indexed from top)",action:t=>{let e=H.decode(t.pop()),r=t.splice(t.length-1-e,1)[0];t.push(r)}},OP_ROT:{code:123,category:"stack",description:"Rotate top three items left",action:t=>{let e=t.pop(),r=t.pop(),n=t.pop();t.push(r,e,n)}},OP_SWAP:{code:124,category:"stack",description:"Swap top two items",action:t=>{let e=t.pop(),r=t.pop();t.push(e,r)}},OP_TUCK:{code:125,category:"stack",description:"Copy top item below second item",action:t=>{let e=t.pop(),r=t.pop();t.push(e,r,e)}},OP_CAT:{code:126,category:"data",description:"Concatenate top two items",action:t=>{let e=t.pop(),r=t.pop();t.push(E.Buffer.concat([r,e]))}},OP_SPLIT:{code:127,category:"data",description:"Split item at position n",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(0,e),r.slice(e))}},OP_NUM2BIN:{code:128,category:"data",description:"Convert number to byte sequence of length n",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=E.Buffer.alloc(e),i=H.encode(r);i.copy(n,0,0,Math.min(i.length,e)),t.push(n)}},OP_BIN2NUM:{code:129,category:"data",description:"Convert byte sequence to number",action:t=>{let e=t.pop();t.push(H.encode(H.decode(e)))}},OP_SIZE:{code:130,category:"data",description:"Push size of top item (without removing item)",action:t=>t.push(H.encode(t[t.length-1].length))},OP_INVERT:{code:131,category:"bitwise",description:"Bitwise NOT of top item",action:t=>{let e=t.pop();t.push(E.Buffer.from(e.map(r=>~r)))}},OP_AND:{code:132,category:"bitwise",description:"Bitwise AND of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)&(r[o]||0);t.push(i)}},OP_OR:{code:133,category:"bitwise",description:"Bitwise OR of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)|(r[o]||0);t.push(i)}},OP_XOR:{code:134,category:"bitwise",description:"Bitwise XOR of top two items",action:t=>{let e=t.pop(),r=t.pop(),n=Math.max(e.length,r.length),i=E.Buffer.alloc(n);for(let o=0;o<n;o++)i[o]=(e[o]||0)^(r[o]||0);t.push(i)}},OP_EQUAL:{code:135,category:"bitwise",description:"Push 1 if top two items are equal, 0 otherwise",action:t=>{let e=t.pop(),r=t.pop();t.push(e.equals(r)?H.encode(1):H.encode(0))}},OP_EQUALVERIFY:{code:136,category:"bitwise",description:"Fail if top two items are not equal",action:t=>{let e=t.pop(),r=t.pop();if(!e.equals(r))throw new Error("OP_EQUALVERIFY failed")}},OP_1ADD:{code:139,category:"arithmetic",description:"Add 1 to top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e+1))}},OP_1SUB:{code:140,category:"arithmetic",description:"Subtract 1 from top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e-1))}},OP_2MUL:{code:141,category:"arithmetic",description:"Multiply top item by 2 (disabled)",action:()=>{throw new Error("OP_2MUL is disabled")}},OP_2DIV:{code:142,category:"arithmetic",description:"Divide top item by 2 (disabled)",action:()=>{throw new Error("OP_2DIV is disabled")}},OP_NEGATE:{code:143,category:"arithmetic",description:"Negate top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(-e))}},OP_ABS:{code:144,category:"arithmetic",description:"Absolute value of top item",action:t=>{let e=H.decode(t.pop());t.push(H.encode(Math.abs(e)))}},OP_NOT:{code:145,category:"arithmetic",description:"Logical NOT (0\u21921, non-zero\u21920)",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e===0?1:0))}},OP_0NOTEQUAL:{code:146,category:"arithmetic",description:"Push 1 if top item is not zero, 0 otherwise",action:t=>{let e=H.decode(t.pop());t.push(H.encode(e!==0?1:0))}},OP_ADD:{code:147,category:"arithmetic",description:"Add top two items",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r+e))}},OP_SUB:{code:148,category:"arithmetic",description:"Subtract: second - first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r-e))}},OP_MUL:{code:149,category:"arithmetic",description:"Multiply top two items",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r*e))}},OP_DIV:{code:150,category:"arithmetic",description:"Divide: second / first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e===0)throw new Error("Division by zero");t.push(H.encode(Math.floor(r/e)))}},OP_MOD:{code:151,category:"arithmetic",description:"Modulo: second % first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e===0)throw new Error("Division by zero");t.push(H.encode(r%e))}},OP_LSHIFT:{code:152,category:"arithmetic",description:"Left shift: second << first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<<e))}},OP_RSHIFT:{code:153,category:"arithmetic",description:"Right shift: second >> first",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>>e))}},OP_BOOLAND:{code:154,category:"arithmetic",description:"Boolean AND: 1 if both non-zero, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==0&&r!==0?1:0))}},OP_BOOLOR:{code:155,category:"arithmetic",description:"Boolean OR: 1 if either non-zero, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==0||r!==0?1:0))}},OP_NUMEQUAL:{code:156,category:"arithmetic",description:"Push 1 if numbers are equal, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e===r?1:0))}},OP_NUMEQUALVERIFY:{code:157,category:"arithmetic",description:"Fail if numbers are not equal",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());if(e!==r)throw new Error("OP_NUMEQUALVERIFY failed")}},OP_NUMNOTEQUAL:{code:158,category:"arithmetic",description:"Push 1 if numbers are not equal, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(e!==r?1:0))}},OP_LESSTHAN:{code:159,category:"arithmetic",description:"Push 1 if second < first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<e?1:0))}},OP_GREATERTHAN:{code:160,category:"arithmetic",description:"Push 1 if second > first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>e?1:0))}},OP_LESSTHANOREQUAL:{code:161,category:"arithmetic",description:"Push 1 if second <= first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r<=e?1:0))}},OP_GREATERTHANOREQUAL:{code:162,category:"arithmetic",description:"Push 1 if second >= first, 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(r>=e?1:0))}},OP_MIN:{code:163,category:"arithmetic",description:"Push smaller of top two numbers",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(Math.min(e,r)))}},OP_MAX:{code:164,category:"arithmetic",description:"Push larger of top two numbers",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop());t.push(H.encode(Math.max(e,r)))}},OP_WITHIN:{code:165,category:"arithmetic",description:"Push 1 if x is within [min, max), 0 otherwise",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=H.decode(t.pop());t.push(H.encode(n>=r&&n<e?1:0))}},OP_RIPEMD160:{code:166,category:"crypto",description:"RIPEMD-160 hash of top item",action:t=>{let r=se().createHash("ripemd160").update(t.pop()).digest();t.push(r)}},OP_SHA1:{code:167,category:"crypto",description:"SHA-1 hash of top item",action:t=>{let r=se().createHash("sha1").update(t.pop()).digest();t.push(r)}},OP_SHA256:{code:168,category:"crypto",description:"SHA-256 hash of top item",action:t=>{let r=se().createHash("sha256").update(t.pop()).digest();t.push(r)}},OP_HASH160:{code:169,category:"crypto",description:"SHA-256 then RIPEMD-160 hash of top item",action:t=>{let e=se(),r=e.createHash("sha256").update(t.pop()).digest(),n=e.createHash("ripemd160").update(r).digest();t.push(n)}},OP_HASH256:{code:170,category:"crypto",description:"Double SHA-256 hash of top item",action:t=>{let e=se(),r=e.createHash("sha256").update(t.pop()).digest(),n=e.createHash("sha256").update(r).digest();t.push(n)}},OP_CODESEPARATOR:{code:171,category:"crypto",description:"Mark signature checking boundary",action:t=>{}},OP_CHECKSIG:{code:172,category:"crypto",description:"Verify signature against public key",action:"// Signature verification (requires transaction context)"},OP_CHECKSIGVERIFY:{code:173,category:"crypto",description:"Verify signature, then fail if invalid",action:"// Signature verification with VERIFY (requires transaction context)"},OP_CHECKMULTISIG:{code:174,category:"crypto",description:"Verify multiple signatures against public keys",action:"// Multi-signature verification (requires transaction context)"},OP_CHECKMULTISIGVERIFY:{code:175,category:"crypto",description:"Verify multiple signatures, then fail if invalid",action:"// Multi-signature verification with VERIFY (requires transaction context)"},OP_SUBSTR:{code:179,category:"string",description:"Extract substring: string[start:start+length]",action:t=>{let e=H.decode(t.pop()),r=H.decode(t.pop()),n=t.pop();t.push(n.slice(r,r+e))}},OP_LEFT:{code:180,category:"string",description:"Extract leftmost n bytes",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(0,e))}},OP_RIGHT:{code:181,category:"string",description:"Extract rightmost n bytes",action:t=>{let e=H.decode(t.pop()),r=t.pop();t.push(r.slice(-e))}},OP_NOP1:{code:176,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP2:{code:177,category:"nop",description:"No operation (formerly CHECKLOCKTIMEVERIFY)",action:t=>{}},OP_NOP3:{code:178,category:"nop",description:"No operation (formerly CHECKSEQUENCEVERIFY)",action:t=>{}},OP_NOP9:{code:184,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_NOP10:{code:185,category:"nop",description:"No operation (reserved for future use)",action:t=>{}},OP_RESERVED1:{code:137,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED1 encountered")}},OP_RESERVED2:{code:138,category:"reserved",description:"Reserved opcode (makes transaction invalid)",action:()=>{throw new Error("OP_RESERVED2 encountered")}},OP_CHECKLOCKTIMEVERIFY:{code:177,category:"disabled",description:"Check locktime (disabled post-Genesis)",action:t=>{}},OP_CHECKSEQUENCEVERIFY:{code:178,category:"disabled",description:"Check sequence (disabled post-Genesis)",action:t=>{}},OP_PUBKEYHASH:{code:253,category:"pseudo",description:"Template matching: public key hash",action:"// Template matching only"},OP_PUBKEY:{code:254,category:"pseudo",description:"Template matching: public key",action:"// Template matching only"},OP_INVALIDOPCODE:{code:255,category:"pseudo",description:"Invalid opcode placeholder",action:()=>{throw new Error("Invalid opcode encountered")}}},Hn={getByCategory:t=>Object.entries(Ue).filter(([e,r])=>r.category===t).reduce((e,[r,n])=>({...e,[r]:n}),{}),getCategories:()=>{let t=new Set;return Object.values(Ue).forEach(e=>t.add(e.category)),Array.from(t).sort()},createASM:t=>{let e=[];return t.forEach(r=>{if(typeof r=="string"&&Ue[r])e.push(r);else if(typeof r=="number")if(r>=1&&r<=16)e.push(`OP_${r}`);else if(r===0)e.push("OP_0");else if(r===-1)e.push("OP_1NEGATE");else{let n=H.encode(r);e.push(n.toString("hex"))}else if(E.Buffer.isBuffer(r))e.push(r.toString("hex"));else throw new Error(`Invalid operation: ${r}`)}),e.join(" ")},simulate:(t,e=[])=>{let r=[...e],n=[],i=[];return t.forEach((o,c)=>{if(!Ue[o])throw new Error(`Unknown opcode: ${o}`);let h=Ue[o],d=[...r];if(typeof h.action=="function")try{h.action(r,n),i.push({step:c+1,opcode:o,beforeStack:d.map(x=>x.toString("hex")),afterStack:r.map(x=>x.toString("hex")),description:h.description})}catch(x){throw i.push({step:c+1,opcode:o,beforeStack:d.map(v=>v.toString("hex")),afterStack:[],error:x.message,description:h.description}),x}else i.push({step:c+1,opcode:o,beforeStack:d.map(x=>x.toString("hex")),afterStack:d.map(x=>x.toString("hex")),note:h.action,description:h.description})}),{finalStack:r.map(o=>o.toString("hex")),finalAltStack:n.map(o=>o.toString("hex")),history:i}},opcodeToName:t=>{let e=Object.entries(Ue).find(([r,n])=>n.code===t);return e?e[0]:`UNKNOWN_${t.toString(16).padStart(2,"0")}`},nameToOpcode:t=>Ue[t]&&Ue[t].code,generateCovenantTemplate:(t,e)=>{let r=[];return t==="value"&&(r.push("OP_SIZE"),r.push(52),r.push("OP_SUB"),r.push("OP_SPLIT"),r.push("OP_DROP"),r.push(8),r.push("OP_SPLIT"),r.push("OP_DROP")),e&&(r.push(E.Buffer.from(e,"hex")),r.push("OP_EQUAL")),{operations:r,asm:Hn.createASM(r),description:`Extract ${t} field and compare with expected value`}}};Ao.exports={opcodeMap:Ue,scriptNum:H,utils:Hn};if(ve.main===Ao){console.log("\u{1F527} Comprehensive Bitcoin Script Opcode Map"),console.log("=========================================="),console.log(`Total opcodes mapped: ${Object.keys(Ue).length}`),console.log(`
|
|
8
8
|
\u{1F4CA} Categories:`),Hn.getCategories().forEach(e=>{let r=Object.values(Ue).filter(n=>n.category===e).length;console.log(` ${e}: ${r} opcodes`)}),console.log(`
|
|
9
9
|
\u{1F9EA} Example: Stack manipulation simulation`);try{let e=["OP_1","OP_2","OP_ADD","OP_3","OP_EQUAL"],r=Hn.simulate(e);console.log("Operations:",e.join(" ")),console.log("Final stack:",r.finalStack),console.log("Expected: ['01'] (true, since 1+2=3)"),console.log(`
|
|
10
10
|
\u{1F4DD} Step-by-step execution:`),r.history.forEach(n=>{console.log(` ${n.step}. ${n.opcode}: ${n.description}`),console.log(` Stack: [${n.beforeStack.join(", ")}] \u2192 [${n.afterStack.join(", ")}]`)})}catch(e){console.log("\u274C Simulation error:",e.message)}console.log(`
|
|
@@ -14,13 +14,13 @@ var bsvSmartContract=(()=>{var yf=Object.create;var kn=Object.defineProperty;var
|
|
|
14
14
|
\u{1F4CA} Example 3: Documentation Generation`);let i=r.document();console.log("Structure analysis:",i.structure),console.log("Comments:"),i.comments.forEach(o=>console.log(" "+o))}});var cc=Z((ym,ac)=>{"use strict";I();var Te=de();function Lr(t){if(E.Buffer.isBuffer(t))return Te.Script.fromBuffer(t).toASM();if(t&&typeof t.toASM=="function")return t.toASM();throw new Error("Input must be a Buffer or Script object")}function ml(t){try{return Te.Script.fromASM(t)}catch(e){throw new Error(`Invalid ASM string: ${e.message}`)}}function gl(t){try{return Te.Script.fromASM(t).toBuffer().toString("hex")}catch(e){throw new Error(`Cannot convert ASM to hex: ${e.message}`)}}function vl(t){try{let e=E.Buffer.from(t,"hex");return Te.Script.fromBuffer(e).toASM()}catch(e){throw new Error(`Cannot convert hex to ASM: ${e.message}`)}}function xl(t){if(E.Buffer.isBuffer(t))return t.toString("hex");if(t&&typeof t.toBuffer=="function")return t.toBuffer().toString("hex");throw new Error("Input must be a Buffer or Script object")}function ic(t){try{return Te.Script.fromASM(t),{valid:!0,error:null}}catch(e){return{valid:!1,error:e.message}}}function Ro(t){try{let e;if(typeof t=="string")e=Te.Script.fromASM(t);else if(E.Buffer.isBuffer(t))e=Te.Script.fromBuffer(t);else if(t&&typeof t.toBuffer=="function")e=t;else return{valid:!1,error:"Invalid script input type"};let r=e.toBuffer(),n=e.toASM();return{valid:!0,error:null,size:r.length,asm:n,operations:n.split(" ").length}}catch(e){return{valid:!1,error:e.message}}}function yl(t){let e=ic(t);if(!e.valid)return e;let r=t.split(" "),n=[];for(let i=0;i<r.length;i++){let o=r[i];o.startsWith("OP_")&&!Te.Opcode.map[o]&&n.push(`Unknown opcode: ${o} at position ${i}`),!o.startsWith("OP_")&&o.length>0&&(/^[0-9a-fA-F]*$/.test(o)||n.push(`Invalid hex data: ${o} at position ${i}`))}return{valid:n.length===0,error:n.length>0?n.join("; "):null,issues:n,operations:r.length}}function Mo(t){try{let e;if(typeof t=="string")e=Te.Script.fromASM(t);else if(Array.isArray(t))e=Te.Script.fromASM(t.join(" "));else{if(E.Buffer.isBuffer(t))return t.length;if(t&&typeof t.toBuffer=="function")e=t;else throw new Error("Invalid script input")}return e.toBuffer().length}catch(e){return{error:e.message}}}function ko(t){try{let e=Ro(t);if(!e.valid)return{error:e.error};let r=e.asm,n=r.split(" ").filter(d=>d.length>0),i=e.size,o=n.filter(d=>d.startsWith("OP_")).length,c=n.filter(d=>!d.startsWith("OP_")&&d.length>0).length,h=0;return n.forEach(d=>{d.startsWith("OP_")&&(["OP_CHECKSIG","OP_CHECKSIGVERIFY"].includes(d)?h+=100:["OP_SHA256","OP_HASH160","OP_HASH256"].includes(d)?h+=10:h+=1)}),{length:i,size:i,operations:n.length,opcodeCount:o,opcodes:o,dataElements:c,estimatedCost:h,complexity:h>50?"high":h>10?"medium":"low",asm:r}}catch(e){return{error:e.message}}}function oc(t){let e=ko(t);if(e.error)return e;let r={size:e.size,operations:e.operations,complexity:e.complexity,recommendations:[]};return e.size>520&&r.recommendations.push("Script exceeds standard size limit (520 bytes)"),e.estimatedCost>100&&r.recommendations.push("High execution cost - consider optimization"),e.operations>200&&r.recommendations.push("Many operations - may hit operation limits"),r}function wl(t){try{let e;typeof t=="string"?e=t:Array.isArray(t)?e=t.join(" "):e=Lr(t);let r=e.split(" "),n=[];for(let d=0;d<r.length;d++){let x=r[d],v=r[d+1];if(!(!x||x.trim()==="")){if(x==="OP_DUP"&&v==="OP_DROP"){d++;continue}!x.startsWith("OP_")&&v&&v.startsWith("OP_"),n.push(x)}}let i=n.join(" "),o=Mo(e),c=Mo(i),h=null;try{h=Te.Script.fromASM(i)}catch{h=null}return{original:e,optimized:i,originalSize:o,optimizedSize:c,savings:o-c,improvement:o>0?((o-c)/o*100).toFixed(1)+"%":"0%",script:h}}catch(e){return{error:e.message}}}function bl(t){let e=[];try{let r;typeof t=="string"?r=t:r=Lr(t);let n=r.split(" ");for(let i=0;i<n.length-1;i++){let o=n[i],c=n[i+1];if(o==="OP_DUP"&&c==="OP_DROP"&&e.push({type:"redundant_operation",position:i,description:"Remove redundant OP_DUP OP_DROP pair",savings:2}),o.match(/^[0-9a-fA-F]+$/)&&o.length===2){let h=parseInt(o,16);h>=1&&h<=16&&e.push({type:"inefficient_push",position:i,description:`Use OP_${h} instead of pushing ${o}`,savings:1})}}return{optimizations:e,totalSavings:e.reduce((i,o)=>i+o.savings,0)}}catch(r){return{error:r.message}}}function Sl(t,e){try{let r,n;return typeof t=="string"?r=Te.Script.fromASM(t).toBuffer():E.Buffer.isBuffer(t)?r=t:r=t.toBuffer(),typeof e=="string"?n=Te.Script.fromASM(e).toBuffer():E.Buffer.isBuffer(e)?n=e:n=e.toBuffer(),{identical:r.equals(n),scriptA:{size:r.length,asm:Lr(r)},scriptB:{size:n.length,asm:Lr(n)}}}catch(r){return{error:r.message}}}function sc(t){try{let e;typeof t=="string"?e=t:e=Lr(t);let r=e.split(" "),n=[];return r.forEach((i,o)=>{let c="";if(i.startsWith("OP_"))switch(i){case"OP_DUP":c="Duplicate the top stack item";break;case"OP_DROP":c="Remove the top stack item";break;case"OP_SWAP":c="Swap the top two stack items";break;case"OP_ADD":c="Add the top two numbers";break;case"OP_SUB":c="Subtract: second - first";break;case"OP_EQUAL":c="Check if top two items are equal";break;case"OP_VERIFY":c="Assert that top item is true (non-zero)";break;case"OP_CHECKSIG":c="Verify signature against public key";break;case"OP_SHA256":c="Calculate SHA256 hash of top item";break;case"OP_HASH160":c="Calculate RIPEMD160(SHA256(x)) hash";break;case"OP_IF":c="Begin conditional execution";break;case"OP_ELSE":c="Alternative branch of conditional";break;case"OP_ENDIF":c="End conditional execution";break;default:c=`Execute ${i}`}else i.length>0&&(c=`Push data: ${i} (${i.length/2} bytes)`);c&&n.push({operation:i,position:o,explanation:c})}),{asm:e,operations:r.length,explanations:n,summary:`Script with ${r.length} operations: ${n.map(i=>i.explanation).join(" \u2192 ")}`}}catch(e){return{error:e.message}}}function El(t){try{let e=sc(t);if(e.error)return e;let r=[];return e.explanations.forEach(n=>{switch(n.operation){case"OP_VERIFY":r.push("The condition must be true for the script to succeed.");break;case"OP_CHECKSIG":r.push("A valid signature must be provided.");break;case"OP_EQUAL":r.push("Two values must be identical.");break;case"OP_ADD":r.push("Two numbers are added together.");break;default:n.explanation.includes("Push data")&&r.push("Some data is made available for processing.")}}),{english:r.join(" "),technical:e.summary,operations:e.operations}}catch(e){return{error:e.message}}}function _l(t,e={}){let r=[];t.forEach((i,o)=>{try{let c=Ro(i),h=ko(i),d=oc(i);r.push({index:o,script:typeof i=="string"?i:Lr(i),valid:c.valid,size:c.size,operations:c.operations,complexity:d.complexity,estimatedCost:h.estimatedCost,recommendations:d.recommendations})}catch(c){r.push({index:o,script:typeof i=="string"?i:"Invalid script",valid:!1,error:c.message})}});let n={total:t.length,valid:r.filter(i=>i.valid).length,invalid:r.filter(i=>!i.valid).length,averageSize:r.filter(i=>i.size).reduce((i,o)=>i+o.size,0)/r.filter(i=>i.size).length||0,complexityDistribution:{low:r.filter(i=>i.complexity==="low").length,medium:r.filter(i=>i.complexity==="medium").length,high:r.filter(i=>i.complexity==="high").length}};return{results:r,summary:n}}ac.exports={scriptToASM:Lr,asmToScript:ml,asmToHex:gl,hexToASM:vl,scriptToHex:xl,validateASM:ic,validateScript:Ro,validateSyntax:yl,estimateScriptSize:Mo,scriptMetrics:ko,analyzeComplexity:oc,optimizeScript:wl,findOptimizations:bl,compareScripts:Sl,explainScript:sc,covenantToEnglish:El,batchTestScripts:_l}});var Fo=Z((bm,uc)=>{I();uc.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var fc=Z((_m,Ho)=>{I();var Be=typeof window<"u"&&window.bsv?window.bsv:Fo(),Em=se();function Ln(t){return t.map(e=>e.toString("hex"))}function hc(t,e){console.log("==========================================="),console.log("\u{1F50D} STACK EXAMINATION TOOL"),console.log(`===========================================
|
|
15
15
|
`),console.log("\u{1F510} Locking Script:",t),console.log("\u{1F513} Unlocking Script:",e),console.log("-------------------------------------------");try{let r=Be.Script.fromHex(t),n=Be.Script.fromHex(e),i=Be.Script.fromBuffer(E.Buffer.concat([n.toBuffer(),r.toBuffer()])),o=new Be.Script.Interpreter,c=new Be.Transaction,h=new Be.Transaction.Input({prevTxId:"0".repeat(64),outputIndex:0,script:Be.Script.empty()});c.addInput(h),c.addOutput(new Be.Transaction.Output({satoshis:1e5,script:r}));let d=i.chunks,x=new Be.Script.Interpreter;x.script=i,x.tx=c,x.nIn=0,x.flags=Be.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID;for(let A=0;A<d.length;A++){let O=d[A];try{if(typeof x.step=="function")x.step();else{console.log("\u26A0\uFE0F Step-by-step execution not supported in this BSV version");break}console.log(`
|
|
16
16
|
\u{1F9E9} Step ${A+1}: ${Be.Opcode.reverseMap[O.opcodenum]||"PUSH"}`),console.log("Stack:",Ln(x.stack)),console.log("AltStack:",Ln(x.altstack))}catch(T){console.log(`\u26A0\uFE0F Error executing opcode ${A+1}:`,T.message);break}}let v=new Be.crypto.BN(1e5),y=o.verify(n,r,c,0,Be.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,v);return console.log(`
|
|
17
|
-
===========================================`),console.log("\u2705 Final Result:",y?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",Ln(x.stack||[])),console.log("AltStack:",Ln(x.altstack||[])),console.log("==========================================="),y}catch(r){return console.error("\u274C Error in script execution:",r.message),!1}}if(typeof ve<"u"&&ve.main===Ho){
|
|
17
|
+
===========================================`),console.log("\u2705 Final Result:",y?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",Ln(x.stack||[])),console.log("AltStack:",Ln(x.altstack||[])),console.log("==========================================="),y}catch(r){return console.error("\u274C Error in script execution:",r.message),!1}}if(typeof ve<"u"&&ve.main===Ho){N.default.argv.length<4&&(console.log("Usage: node stack_examiner.js <locking_script_hex> <unlocking_script_hex>"),N.default.exit(1));let t=N.default.argv[2],e=N.default.argv[3];hc(t,e)}Ho.exports={runScript:hc,bufferToHexArray:Ln}});var mc=Z((Im,Co)=>{I();var ui=null;try{typeof window>"u"&&typeof ve<"u"&&(ui=se())}catch{ui=null}var ue=typeof window<"u"&&window.bsv?window.bsv:Fo();function ci(t){if(!t)return new ue.Script;let e=t.trim(),r=/^[0-9a-fA-F]+$/.test(e.replace(/\s+/g,""));try{return r?ue.Script.fromHex(e):ue.Script.fromASM(e)}catch(n){console.error("\u274C Error parsing script:",n.message),N.default.exit(1)}}function Lo(t,e=[]){let r=i=>i.length?i.toString("hex"):"(empty)",n=t.map(r);console.log("Stack:",n.length?n:["(empty)"]),e.length&&console.log("AltStack:",e.map(r))}async function lc(t,e,r=!0){let n=new ue.Script.Interpreter;n.script=t,n.tx=e,n.nIn=0,n.flags=ue.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID;let i=t.chunks,o=null;ui&&typeof N.default<"u"&&N.default.stdin&&(o=ui.createInterface({input:N.default.stdin,output:N.default.stdout})),console.log("==========================================="),console.log("\u{1F50D} SCRIPT INTERPRETER DEBUGGER (STEP MODE)"),console.log(`===========================================
|
|
18
18
|
`),console.log("Script:",t.toASM()),console.log("-------------------------------------------");for(let c=0;c<i.length;c++){let h=i[c],d=ue.Opcode.reverseMap[h.opcodenum]||"PUSH";r&&o?await new Promise(x=>o.question(`
|
|
19
19
|
[${c+1}/${i.length}] Step (${d}) \u2014 press Enter to execute...`,x)):r&&console.log(`
|
|
20
20
|
[${c+1}/${i.length}] Step (${d})`);try{if(typeof n.step=="function")n.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: ${d}`),Lo(n.stack,n.altstack)}catch(x){console.log(`\u26A0\uFE0F Error executing ${d}: ${x.message}`);break}}o&&o.close(),console.log(`
|
|
21
21
|
===========================================`),console.log("\u2705 Final Stack State:"),Lo(n.stack||[],n.altstack||[]),console.log("===========================================")}function dc(t,e,r){console.log("==========================================="),console.log("\u{1F50D} SCRIPT INTERPRETER DEBUGGER (FULL RUN)"),console.log(`===========================================
|
|
22
|
-
`);let n=new ue.Script.Interpreter,i=new ue.crypto.BN(1e5),o=n.verify(t,e,r,0,ue.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,i);console.log("\u{1F510} Locking Script:",e.toASM()),console.log("\u{1F513} Unlocking Script:",t.toASM()),console.log("-------------------------------------------"),console.log("\u2705 Result:",o?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",n.stack.map(c=>c.toString("hex"))),console.log("AltStack:",n.altstack.map(c=>c.toString("hex"))),console.log("===========================================")}async function pc(){if(typeof C.default>"u"||!C.default.argv){console.log("\u2699\uFE0F CLI mode not available in browser environment");return}let t=C.default.argv.slice(2),e=A=>{let O=t.indexOf(A);return O!==-1&&t[O+1]?t[O+1]:null},r=e("--unlocking"),n=e("--locking"),i=e("--combined"),o=t.includes("--step"),c=t.includes("--truth"),h,d,x;if(i)x=ci(i);else{h=ci(r),d=ci(n);let A=E.Buffer.concat([h.toBuffer(),d.toBuffer()]);x=ue.Script.fromBuffer(A)}let v=new ue.Transaction,y=new ue.Transaction.Input({prevTxId:"0".repeat(64),outputIndex:0,script:ue.Script.empty(),satoshis:1e5,output:new ue.Transaction.Output({satoshis:1e5,script:ue.Script.empty()})});v.addInput(y),v.addOutput(new ue.Transaction.Output({satoshis:1e5,script:ue.Script.empty()})),o?await lc(x,v,!0):c?dc(h||ue.Script.empty(),d||ue.Script.empty(),v):console.log("\u2699\uFE0F No mode specified. Use --step or --truth")}No.exports={parseScript:ci,printStack:Lo,stepThroughScript:lc,runFullEvaluation:dc,main:pc};typeof ve<"u"&&ve.main===No&&pc()});var vc=Z((gc,Co)=>{I();(function(t,e){"use strict";function r(b,s){if(!b)throw new Error(s||"Assertion failed")}function n(b,s){b.super_=s;var u=function(){};u.prototype=s.prototype,b.prototype=new u,b.prototype.constructor=b}function i(b,s,u){if(i.isBN(b))return b;this.negative=0,this.words=null,this.length=0,this.red=null,b!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(b||0,s||10,u||"be"))}typeof t=="object"?t.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=si().Buffer}catch{}i.isBN=function(s){return s instanceof i?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===i.wordSize&&Array.isArray(s.words)},i.max=function(s,u){return s.cmp(u)>0?s:u},i.min=function(s,u){return s.cmp(u)<0?s:u},i.prototype._init=function(s,u,f){if(typeof s=="number")return this._initNumber(s,u,f);if(typeof s=="object")return this._initArray(s,u,f);u==="hex"&&(u=16),r(u===(u|0)&&u>=2&&u<=36),s=s.toString().replace(/\s+/g,"");var l=0;s[0]==="-"&&(l++,this.negative=1),l<s.length&&(u===16?this._parseHex(s,l,f):(this._parseBase(s,u,l),f==="le"&&this._initArray(this.toArray(),u,f)))},i.prototype._initNumber=function(s,u,f){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(r(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),f==="le"&&this._initArray(this.toArray(),u,f)},i.prototype._initArray=function(s,u,f){if(r(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var l=0;l<this.length;l++)this.words[l]=0;var p,w,S=0;if(f==="be")for(l=s.length-1,p=0;l>=0;l-=3)w=s[l]|s[l-1]<<8|s[l-2]<<16,this.words[p]|=w<<S&67108863,this.words[p+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,p++);else if(f==="le")for(l=0,p=0;l<s.length;l+=3)w=s[l]|s[l+1]<<8|s[l+2]<<16,this.words[p]|=w<<S&67108863,this.words[p+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,p++);return this.strip()};function c(b,s){var u=b.charCodeAt(s);return u>=65&&u<=70?u-55:u>=97&&u<=102?u-87:u-48&15}function h(b,s,u){var f=c(b,u);return u-1>=s&&(f|=c(b,u-1)<<4),f}i.prototype._parseHex=function(s,u,f){this.length=Math.ceil((s.length-u)/6),this.words=new Array(this.length);for(var l=0;l<this.length;l++)this.words[l]=0;var p=0,w=0,S;if(f==="be")for(l=s.length-1;l>=u;l-=2)S=h(s,u,l)<<p,this.words[w]|=S&67108863,p>=18?(p-=18,w+=1,this.words[w]|=S>>>26):p+=8;else{var m=s.length-u;for(l=m%2===0?u+1:u;l<s.length;l+=2)S=h(s,u,l)<<p,this.words[w]|=S&67108863,p>=18?(p-=18,w+=1,this.words[w]|=S>>>26):p+=8}this.strip()};function d(b,s,u,f){for(var l=0,p=Math.min(b.length,u),w=s;w<p;w++){var S=b.charCodeAt(w)-48;l*=f,S>=49?l+=S-49+10:S>=17?l+=S-17+10:l+=S}return l}i.prototype._parseBase=function(s,u,f){this.words=[0],this.length=1;for(var l=0,p=1;p<=67108863;p*=u)l++;l--,p=p/u|0;for(var w=s.length-f,S=w%l,m=Math.min(w,w-S)+f,a=0,g=f;g<m;g+=l)a=d(s,g,g+l,u),this.imuln(p),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(S!==0){var F=1;for(a=d(s,g,s.length,u),g=0;g<S;g++)F*=u;this.imuln(F),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this.strip()},i.prototype.copy=function(s){s.words=new Array(this.length);for(var u=0;u<this.length;u++)s.words[u]=this.words[u];s.length=this.length,s.negative=this.negative,s.red=this.red},i.prototype.clone=function(){var s=new i(null);return this.copy(s),s},i.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},i.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],v=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],y=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(s,u){s=s||10,u=u|0||1;var f;if(s===16||s==="hex"){f="";for(var l=0,p=0,w=0;w<this.length;w++){var S=this.words[w],m=((S<<l|p)&16777215).toString(16);p=S>>>24-l&16777215,l+=2,l>=26&&(l-=26,w--),p!==0||w!==this.length-1?f=x[6-m.length]+m+f:f=m+f}for(p!==0&&(f=p.toString(16)+f);f.length%u!==0;)f="0"+f;return this.negative!==0&&(f="-"+f),f}if(s===(s|0)&&s>=2&&s<=36){var a=v[s],g=y[s];f="";var F=this.clone();for(F.negative=0;!F.isZero();){var k=F.modn(g).toString(s);F=F.idivn(g),F.isZero()?f=k+f:f=x[a-k.length]+k+f}for(this.isZero()&&(f="0"+f);f.length%u!==0;)f="0"+f;return this.negative!==0&&(f="-"+f),f}r(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(s,u){return r(typeof o<"u"),this.toArrayLike(o,s,u)},i.prototype.toArray=function(s,u){return this.toArrayLike(Array,s,u)},i.prototype.toArrayLike=function(s,u,f){var l=this.byteLength(),p=f||Math.max(1,l);r(l<=p,"byte array longer than desired length"),r(p>0,"Requested array length <= 0"),this.strip();var w=u==="le",S=new s(p),m,a,g=this.clone();if(w){for(a=0;!g.isZero();a++)m=g.andln(255),g.iushrn(8),S[a]=m;for(;a<p;a++)S[a]=0}else{for(a=0;a<p-l;a++)S[a]=0;for(a=0;!g.isZero();a++)m=g.andln(255),g.iushrn(8),S[p-a-1]=m}return S},Math.clz32?i.prototype._countBits=function(s){return 32-Math.clz32(s)}:i.prototype._countBits=function(s){var u=s,f=0;return u>=4096&&(f+=13,u>>>=13),u>=64&&(f+=7,u>>>=7),u>=8&&(f+=4,u>>>=4),u>=2&&(f+=2,u>>>=2),f+u},i.prototype._zeroBits=function(s){if(s===0)return 26;var u=s,f=0;return(u&8191)===0&&(f+=13,u>>>=13),(u&127)===0&&(f+=7,u>>>=7),(u&15)===0&&(f+=4,u>>>=4),(u&3)===0&&(f+=2,u>>>=2),(u&1)===0&&f++,f},i.prototype.bitLength=function(){var s=this.words[this.length-1],u=this._countBits(s);return(this.length-1)*26+u};function A(b){for(var s=new Array(b.bitLength()),u=0;u<s.length;u++){var f=u/26|0,l=u%26;s[u]=(b.words[f]&1<<l)>>>l}return s}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,u=0;u<this.length;u++){var f=this._zeroBits(this.words[u]);if(s+=f,f!==26)break}return s},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},i.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var u=0;u<s.length;u++)this.words[u]=this.words[u]|s.words[u];return this.strip()},i.prototype.ior=function(s){return r((this.negative|s.negative)===0),this.iuor(s)},i.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},i.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},i.prototype.iuand=function(s){var u;this.length>s.length?u=s:u=this;for(var f=0;f<u.length;f++)this.words[f]=this.words[f]&s.words[f];return this.length=u.length,this.strip()},i.prototype.iand=function(s){return r((this.negative|s.negative)===0),this.iuand(s)},i.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},i.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},i.prototype.iuxor=function(s){var u,f;this.length>s.length?(u=this,f=s):(u=s,f=this);for(var l=0;l<f.length;l++)this.words[l]=u.words[l]^f.words[l];if(this!==u)for(;l<u.length;l++)this.words[l]=u.words[l];return this.length=u.length,this.strip()},i.prototype.ixor=function(s){return r((this.negative|s.negative)===0),this.iuxor(s)},i.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},i.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},i.prototype.inotn=function(s){r(typeof s=="number"&&s>=0);var u=Math.ceil(s/26)|0,f=s%26;this._expand(u),f>0&&u--;for(var l=0;l<u;l++)this.words[l]=~this.words[l]&67108863;return f>0&&(this.words[l]=~this.words[l]&67108863>>26-f),this.strip()},i.prototype.notn=function(s){return this.clone().inotn(s)},i.prototype.setn=function(s,u){r(typeof s=="number"&&s>=0);var f=s/26|0,l=s%26;return this._expand(f+1),u?this.words[f]=this.words[f]|1<<l:this.words[f]=this.words[f]&~(1<<l),this.strip()},i.prototype.iadd=function(s){var u;if(this.negative!==0&&s.negative===0)return this.negative=0,u=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,u=this.isub(s),s.negative=1,u._normSign();var f,l;this.length>s.length?(f=this,l=s):(f=s,l=this);for(var p=0,w=0;w<l.length;w++)u=(f.words[w]|0)+(l.words[w]|0)+p,this.words[w]=u&67108863,p=u>>>26;for(;p!==0&&w<f.length;w++)u=(f.words[w]|0)+p,this.words[w]=u&67108863,p=u>>>26;if(this.length=f.length,p!==0)this.words[this.length]=p,this.length++;else if(f!==this)for(;w<f.length;w++)this.words[w]=f.words[w];return this},i.prototype.add=function(s){var u;return s.negative!==0&&this.negative===0?(s.negative=0,u=this.sub(s),s.negative^=1,u):s.negative===0&&this.negative!==0?(this.negative=0,u=s.sub(this),this.negative=1,u):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},i.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var u=this.iadd(s);return s.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var f=this.cmp(s);if(f===0)return this.negative=0,this.length=1,this.words[0]=0,this;var l,p;f>0?(l=this,p=s):(l=s,p=this);for(var w=0,S=0;S<p.length;S++)u=(l.words[S]|0)-(p.words[S]|0)+w,w=u>>26,this.words[S]=u&67108863;for(;w!==0&&S<l.length;S++)u=(l.words[S]|0)+w,w=u>>26,this.words[S]=u&67108863;if(w===0&&S<l.length&&l!==this)for(;S<l.length;S++)this.words[S]=l.words[S];return this.length=Math.max(this.length,S),l!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(s){return this.clone().isub(s)};function O(b,s,u){u.negative=s.negative^b.negative;var f=b.length+s.length|0;u.length=f,f=f-1|0;var l=b.words[0]|0,p=s.words[0]|0,w=l*p,S=w&67108863,m=w/67108864|0;u.words[0]=S;for(var a=1;a<f;a++){for(var g=m>>>26,F=m&67108863,k=Math.min(a,s.length-1),q=Math.max(0,a-b.length+1);q<=k;q++){var z=a-q|0;l=b.words[z]|0,p=s.words[q]|0,w=l*p+F,g+=w/67108864|0,F=w&67108863}u.words[a]=F|0,m=g|0}return m!==0?u.words[a]=m|0:u.length--,u.strip()}var T=function(s,u,f){var l=s.words,p=u.words,w=f.words,S=0,m,a,g,F=l[0]|0,k=F&8191,q=F>>>13,z=l[1]|0,j=z&8191,it=z>>>13,pt=l[2]|0,ut=pt&8191,_=pt>>>13,P=l[3]|0,R=P&8191,N=P>>>13,V=l[4]|0,G=V&8191,K=V>>>13,ot=l[5]|0,X=ot&8191,Q=ot>>>13,oe=l[6]|0,vt=oe&8191,st=oe>>>13,at=l[7]|0,ct=at&8191,ht=at>>>13,cr=l[8]|0,Tt=cr&8191,Et=cr>>>13,ei=l[9]|0,Mt=ei&8191,kt=ei>>>13,Ys=p[0]|0,Ft=Ys&8191,Ht=Ys>>>13,$s=p[1]|0,Lt=$s&8191,Nt=$s>>>13,Zs=p[2]|0,Ct=Zs&8191,Ut=Zs>>>13,Xs=p[3]|0,qt=Xs&8191,Dt=Xs>>>13,Ws=p[4]|0,Gt=Ws&8191,zt=Ws>>>13,Qs=p[5]|0,Vt=Qs&8191,Kt=Qs>>>13,Js=p[6]|0,jt=Js&8191,Yt=Js>>>13,ta=p[7]|0,$t=ta&8191,Zt=ta>>>13,ea=p[8]|0,Xt=ea&8191,Wt=ea>>>13,ra=p[9]|0,Qt=ra&8191,Jt=ra>>>13;f.negative=s.negative^u.negative,f.length=19,m=Math.imul(k,Ft),a=Math.imul(k,Ht),a=a+Math.imul(q,Ft)|0,g=Math.imul(q,Ht);var zi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(zi>>>26)|0,zi&=67108863,m=Math.imul(j,Ft),a=Math.imul(j,Ht),a=a+Math.imul(it,Ft)|0,g=Math.imul(it,Ht),m=m+Math.imul(k,Lt)|0,a=a+Math.imul(k,Nt)|0,a=a+Math.imul(q,Lt)|0,g=g+Math.imul(q,Nt)|0;var Vi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Vi>>>26)|0,Vi&=67108863,m=Math.imul(ut,Ft),a=Math.imul(ut,Ht),a=a+Math.imul(_,Ft)|0,g=Math.imul(_,Ht),m=m+Math.imul(j,Lt)|0,a=a+Math.imul(j,Nt)|0,a=a+Math.imul(it,Lt)|0,g=g+Math.imul(it,Nt)|0,m=m+Math.imul(k,Ct)|0,a=a+Math.imul(k,Ut)|0,a=a+Math.imul(q,Ct)|0,g=g+Math.imul(q,Ut)|0;var Ki=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Ki>>>26)|0,Ki&=67108863,m=Math.imul(R,Ft),a=Math.imul(R,Ht),a=a+Math.imul(N,Ft)|0,g=Math.imul(N,Ht),m=m+Math.imul(ut,Lt)|0,a=a+Math.imul(ut,Nt)|0,a=a+Math.imul(_,Lt)|0,g=g+Math.imul(_,Nt)|0,m=m+Math.imul(j,Ct)|0,a=a+Math.imul(j,Ut)|0,a=a+Math.imul(it,Ct)|0,g=g+Math.imul(it,Ut)|0,m=m+Math.imul(k,qt)|0,a=a+Math.imul(k,Dt)|0,a=a+Math.imul(q,qt)|0,g=g+Math.imul(q,Dt)|0;var ji=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(ji>>>26)|0,ji&=67108863,m=Math.imul(G,Ft),a=Math.imul(G,Ht),a=a+Math.imul(K,Ft)|0,g=Math.imul(K,Ht),m=m+Math.imul(R,Lt)|0,a=a+Math.imul(R,Nt)|0,a=a+Math.imul(N,Lt)|0,g=g+Math.imul(N,Nt)|0,m=m+Math.imul(ut,Ct)|0,a=a+Math.imul(ut,Ut)|0,a=a+Math.imul(_,Ct)|0,g=g+Math.imul(_,Ut)|0,m=m+Math.imul(j,qt)|0,a=a+Math.imul(j,Dt)|0,a=a+Math.imul(it,qt)|0,g=g+Math.imul(it,Dt)|0,m=m+Math.imul(k,Gt)|0,a=a+Math.imul(k,zt)|0,a=a+Math.imul(q,Gt)|0,g=g+Math.imul(q,zt)|0;var Yi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Yi>>>26)|0,Yi&=67108863,m=Math.imul(X,Ft),a=Math.imul(X,Ht),a=a+Math.imul(Q,Ft)|0,g=Math.imul(Q,Ht),m=m+Math.imul(G,Lt)|0,a=a+Math.imul(G,Nt)|0,a=a+Math.imul(K,Lt)|0,g=g+Math.imul(K,Nt)|0,m=m+Math.imul(R,Ct)|0,a=a+Math.imul(R,Ut)|0,a=a+Math.imul(N,Ct)|0,g=g+Math.imul(N,Ut)|0,m=m+Math.imul(ut,qt)|0,a=a+Math.imul(ut,Dt)|0,a=a+Math.imul(_,qt)|0,g=g+Math.imul(_,Dt)|0,m=m+Math.imul(j,Gt)|0,a=a+Math.imul(j,zt)|0,a=a+Math.imul(it,Gt)|0,g=g+Math.imul(it,zt)|0,m=m+Math.imul(k,Vt)|0,a=a+Math.imul(k,Kt)|0,a=a+Math.imul(q,Vt)|0,g=g+Math.imul(q,Kt)|0;var $i=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+($i>>>26)|0,$i&=67108863,m=Math.imul(vt,Ft),a=Math.imul(vt,Ht),a=a+Math.imul(st,Ft)|0,g=Math.imul(st,Ht),m=m+Math.imul(X,Lt)|0,a=a+Math.imul(X,Nt)|0,a=a+Math.imul(Q,Lt)|0,g=g+Math.imul(Q,Nt)|0,m=m+Math.imul(G,Ct)|0,a=a+Math.imul(G,Ut)|0,a=a+Math.imul(K,Ct)|0,g=g+Math.imul(K,Ut)|0,m=m+Math.imul(R,qt)|0,a=a+Math.imul(R,Dt)|0,a=a+Math.imul(N,qt)|0,g=g+Math.imul(N,Dt)|0,m=m+Math.imul(ut,Gt)|0,a=a+Math.imul(ut,zt)|0,a=a+Math.imul(_,Gt)|0,g=g+Math.imul(_,zt)|0,m=m+Math.imul(j,Vt)|0,a=a+Math.imul(j,Kt)|0,a=a+Math.imul(it,Vt)|0,g=g+Math.imul(it,Kt)|0,m=m+Math.imul(k,jt)|0,a=a+Math.imul(k,Yt)|0,a=a+Math.imul(q,jt)|0,g=g+Math.imul(q,Yt)|0;var Zi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Zi>>>26)|0,Zi&=67108863,m=Math.imul(ct,Ft),a=Math.imul(ct,Ht),a=a+Math.imul(ht,Ft)|0,g=Math.imul(ht,Ht),m=m+Math.imul(vt,Lt)|0,a=a+Math.imul(vt,Nt)|0,a=a+Math.imul(st,Lt)|0,g=g+Math.imul(st,Nt)|0,m=m+Math.imul(X,Ct)|0,a=a+Math.imul(X,Ut)|0,a=a+Math.imul(Q,Ct)|0,g=g+Math.imul(Q,Ut)|0,m=m+Math.imul(G,qt)|0,a=a+Math.imul(G,Dt)|0,a=a+Math.imul(K,qt)|0,g=g+Math.imul(K,Dt)|0,m=m+Math.imul(R,Gt)|0,a=a+Math.imul(R,zt)|0,a=a+Math.imul(N,Gt)|0,g=g+Math.imul(N,zt)|0,m=m+Math.imul(ut,Vt)|0,a=a+Math.imul(ut,Kt)|0,a=a+Math.imul(_,Vt)|0,g=g+Math.imul(_,Kt)|0,m=m+Math.imul(j,jt)|0,a=a+Math.imul(j,Yt)|0,a=a+Math.imul(it,jt)|0,g=g+Math.imul(it,Yt)|0,m=m+Math.imul(k,$t)|0,a=a+Math.imul(k,Zt)|0,a=a+Math.imul(q,$t)|0,g=g+Math.imul(q,Zt)|0;var Xi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Xi>>>26)|0,Xi&=67108863,m=Math.imul(Tt,Ft),a=Math.imul(Tt,Ht),a=a+Math.imul(Et,Ft)|0,g=Math.imul(Et,Ht),m=m+Math.imul(ct,Lt)|0,a=a+Math.imul(ct,Nt)|0,a=a+Math.imul(ht,Lt)|0,g=g+Math.imul(ht,Nt)|0,m=m+Math.imul(vt,Ct)|0,a=a+Math.imul(vt,Ut)|0,a=a+Math.imul(st,Ct)|0,g=g+Math.imul(st,Ut)|0,m=m+Math.imul(X,qt)|0,a=a+Math.imul(X,Dt)|0,a=a+Math.imul(Q,qt)|0,g=g+Math.imul(Q,Dt)|0,m=m+Math.imul(G,Gt)|0,a=a+Math.imul(G,zt)|0,a=a+Math.imul(K,Gt)|0,g=g+Math.imul(K,zt)|0,m=m+Math.imul(R,Vt)|0,a=a+Math.imul(R,Kt)|0,a=a+Math.imul(N,Vt)|0,g=g+Math.imul(N,Kt)|0,m=m+Math.imul(ut,jt)|0,a=a+Math.imul(ut,Yt)|0,a=a+Math.imul(_,jt)|0,g=g+Math.imul(_,Yt)|0,m=m+Math.imul(j,$t)|0,a=a+Math.imul(j,Zt)|0,a=a+Math.imul(it,$t)|0,g=g+Math.imul(it,Zt)|0,m=m+Math.imul(k,Xt)|0,a=a+Math.imul(k,Wt)|0,a=a+Math.imul(q,Xt)|0,g=g+Math.imul(q,Wt)|0;var Wi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Wi>>>26)|0,Wi&=67108863,m=Math.imul(Mt,Ft),a=Math.imul(Mt,Ht),a=a+Math.imul(kt,Ft)|0,g=Math.imul(kt,Ht),m=m+Math.imul(Tt,Lt)|0,a=a+Math.imul(Tt,Nt)|0,a=a+Math.imul(Et,Lt)|0,g=g+Math.imul(Et,Nt)|0,m=m+Math.imul(ct,Ct)|0,a=a+Math.imul(ct,Ut)|0,a=a+Math.imul(ht,Ct)|0,g=g+Math.imul(ht,Ut)|0,m=m+Math.imul(vt,qt)|0,a=a+Math.imul(vt,Dt)|0,a=a+Math.imul(st,qt)|0,g=g+Math.imul(st,Dt)|0,m=m+Math.imul(X,Gt)|0,a=a+Math.imul(X,zt)|0,a=a+Math.imul(Q,Gt)|0,g=g+Math.imul(Q,zt)|0,m=m+Math.imul(G,Vt)|0,a=a+Math.imul(G,Kt)|0,a=a+Math.imul(K,Vt)|0,g=g+Math.imul(K,Kt)|0,m=m+Math.imul(R,jt)|0,a=a+Math.imul(R,Yt)|0,a=a+Math.imul(N,jt)|0,g=g+Math.imul(N,Yt)|0,m=m+Math.imul(ut,$t)|0,a=a+Math.imul(ut,Zt)|0,a=a+Math.imul(_,$t)|0,g=g+Math.imul(_,Zt)|0,m=m+Math.imul(j,Xt)|0,a=a+Math.imul(j,Wt)|0,a=a+Math.imul(it,Xt)|0,g=g+Math.imul(it,Wt)|0,m=m+Math.imul(k,Qt)|0,a=a+Math.imul(k,Jt)|0,a=a+Math.imul(q,Qt)|0,g=g+Math.imul(q,Jt)|0;var Qi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Qi>>>26)|0,Qi&=67108863,m=Math.imul(Mt,Lt),a=Math.imul(Mt,Nt),a=a+Math.imul(kt,Lt)|0,g=Math.imul(kt,Nt),m=m+Math.imul(Tt,Ct)|0,a=a+Math.imul(Tt,Ut)|0,a=a+Math.imul(Et,Ct)|0,g=g+Math.imul(Et,Ut)|0,m=m+Math.imul(ct,qt)|0,a=a+Math.imul(ct,Dt)|0,a=a+Math.imul(ht,qt)|0,g=g+Math.imul(ht,Dt)|0,m=m+Math.imul(vt,Gt)|0,a=a+Math.imul(vt,zt)|0,a=a+Math.imul(st,Gt)|0,g=g+Math.imul(st,zt)|0,m=m+Math.imul(X,Vt)|0,a=a+Math.imul(X,Kt)|0,a=a+Math.imul(Q,Vt)|0,g=g+Math.imul(Q,Kt)|0,m=m+Math.imul(G,jt)|0,a=a+Math.imul(G,Yt)|0,a=a+Math.imul(K,jt)|0,g=g+Math.imul(K,Yt)|0,m=m+Math.imul(R,$t)|0,a=a+Math.imul(R,Zt)|0,a=a+Math.imul(N,$t)|0,g=g+Math.imul(N,Zt)|0,m=m+Math.imul(ut,Xt)|0,a=a+Math.imul(ut,Wt)|0,a=a+Math.imul(_,Xt)|0,g=g+Math.imul(_,Wt)|0,m=m+Math.imul(j,Qt)|0,a=a+Math.imul(j,Jt)|0,a=a+Math.imul(it,Qt)|0,g=g+Math.imul(it,Jt)|0;var Ji=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Ji>>>26)|0,Ji&=67108863,m=Math.imul(Mt,Ct),a=Math.imul(Mt,Ut),a=a+Math.imul(kt,Ct)|0,g=Math.imul(kt,Ut),m=m+Math.imul(Tt,qt)|0,a=a+Math.imul(Tt,Dt)|0,a=a+Math.imul(Et,qt)|0,g=g+Math.imul(Et,Dt)|0,m=m+Math.imul(ct,Gt)|0,a=a+Math.imul(ct,zt)|0,a=a+Math.imul(ht,Gt)|0,g=g+Math.imul(ht,zt)|0,m=m+Math.imul(vt,Vt)|0,a=a+Math.imul(vt,Kt)|0,a=a+Math.imul(st,Vt)|0,g=g+Math.imul(st,Kt)|0,m=m+Math.imul(X,jt)|0,a=a+Math.imul(X,Yt)|0,a=a+Math.imul(Q,jt)|0,g=g+Math.imul(Q,Yt)|0,m=m+Math.imul(G,$t)|0,a=a+Math.imul(G,Zt)|0,a=a+Math.imul(K,$t)|0,g=g+Math.imul(K,Zt)|0,m=m+Math.imul(R,Xt)|0,a=a+Math.imul(R,Wt)|0,a=a+Math.imul(N,Xt)|0,g=g+Math.imul(N,Wt)|0,m=m+Math.imul(ut,Qt)|0,a=a+Math.imul(ut,Jt)|0,a=a+Math.imul(_,Qt)|0,g=g+Math.imul(_,Jt)|0;var to=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(to>>>26)|0,to&=67108863,m=Math.imul(Mt,qt),a=Math.imul(Mt,Dt),a=a+Math.imul(kt,qt)|0,g=Math.imul(kt,Dt),m=m+Math.imul(Tt,Gt)|0,a=a+Math.imul(Tt,zt)|0,a=a+Math.imul(Et,Gt)|0,g=g+Math.imul(Et,zt)|0,m=m+Math.imul(ct,Vt)|0,a=a+Math.imul(ct,Kt)|0,a=a+Math.imul(ht,Vt)|0,g=g+Math.imul(ht,Kt)|0,m=m+Math.imul(vt,jt)|0,a=a+Math.imul(vt,Yt)|0,a=a+Math.imul(st,jt)|0,g=g+Math.imul(st,Yt)|0,m=m+Math.imul(X,$t)|0,a=a+Math.imul(X,Zt)|0,a=a+Math.imul(Q,$t)|0,g=g+Math.imul(Q,Zt)|0,m=m+Math.imul(G,Xt)|0,a=a+Math.imul(G,Wt)|0,a=a+Math.imul(K,Xt)|0,g=g+Math.imul(K,Wt)|0,m=m+Math.imul(R,Qt)|0,a=a+Math.imul(R,Jt)|0,a=a+Math.imul(N,Qt)|0,g=g+Math.imul(N,Jt)|0;var eo=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(eo>>>26)|0,eo&=67108863,m=Math.imul(Mt,Gt),a=Math.imul(Mt,zt),a=a+Math.imul(kt,Gt)|0,g=Math.imul(kt,zt),m=m+Math.imul(Tt,Vt)|0,a=a+Math.imul(Tt,Kt)|0,a=a+Math.imul(Et,Vt)|0,g=g+Math.imul(Et,Kt)|0,m=m+Math.imul(ct,jt)|0,a=a+Math.imul(ct,Yt)|0,a=a+Math.imul(ht,jt)|0,g=g+Math.imul(ht,Yt)|0,m=m+Math.imul(vt,$t)|0,a=a+Math.imul(vt,Zt)|0,a=a+Math.imul(st,$t)|0,g=g+Math.imul(st,Zt)|0,m=m+Math.imul(X,Xt)|0,a=a+Math.imul(X,Wt)|0,a=a+Math.imul(Q,Xt)|0,g=g+Math.imul(Q,Wt)|0,m=m+Math.imul(G,Qt)|0,a=a+Math.imul(G,Jt)|0,a=a+Math.imul(K,Qt)|0,g=g+Math.imul(K,Jt)|0;var ro=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(ro>>>26)|0,ro&=67108863,m=Math.imul(Mt,Vt),a=Math.imul(Mt,Kt),a=a+Math.imul(kt,Vt)|0,g=Math.imul(kt,Kt),m=m+Math.imul(Tt,jt)|0,a=a+Math.imul(Tt,Yt)|0,a=a+Math.imul(Et,jt)|0,g=g+Math.imul(Et,Yt)|0,m=m+Math.imul(ct,$t)|0,a=a+Math.imul(ct,Zt)|0,a=a+Math.imul(ht,$t)|0,g=g+Math.imul(ht,Zt)|0,m=m+Math.imul(vt,Xt)|0,a=a+Math.imul(vt,Wt)|0,a=a+Math.imul(st,Xt)|0,g=g+Math.imul(st,Wt)|0,m=m+Math.imul(X,Qt)|0,a=a+Math.imul(X,Jt)|0,a=a+Math.imul(Q,Qt)|0,g=g+Math.imul(Q,Jt)|0;var no=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(no>>>26)|0,no&=67108863,m=Math.imul(Mt,jt),a=Math.imul(Mt,Yt),a=a+Math.imul(kt,jt)|0,g=Math.imul(kt,Yt),m=m+Math.imul(Tt,$t)|0,a=a+Math.imul(Tt,Zt)|0,a=a+Math.imul(Et,$t)|0,g=g+Math.imul(Et,Zt)|0,m=m+Math.imul(ct,Xt)|0,a=a+Math.imul(ct,Wt)|0,a=a+Math.imul(ht,Xt)|0,g=g+Math.imul(ht,Wt)|0,m=m+Math.imul(vt,Qt)|0,a=a+Math.imul(vt,Jt)|0,a=a+Math.imul(st,Qt)|0,g=g+Math.imul(st,Jt)|0;var io=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(io>>>26)|0,io&=67108863,m=Math.imul(Mt,$t),a=Math.imul(Mt,Zt),a=a+Math.imul(kt,$t)|0,g=Math.imul(kt,Zt),m=m+Math.imul(Tt,Xt)|0,a=a+Math.imul(Tt,Wt)|0,a=a+Math.imul(Et,Xt)|0,g=g+Math.imul(Et,Wt)|0,m=m+Math.imul(ct,Qt)|0,a=a+Math.imul(ct,Jt)|0,a=a+Math.imul(ht,Qt)|0,g=g+Math.imul(ht,Jt)|0;var oo=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(oo>>>26)|0,oo&=67108863,m=Math.imul(Mt,Xt),a=Math.imul(Mt,Wt),a=a+Math.imul(kt,Xt)|0,g=Math.imul(kt,Wt),m=m+Math.imul(Tt,Qt)|0,a=a+Math.imul(Tt,Jt)|0,a=a+Math.imul(Et,Qt)|0,g=g+Math.imul(Et,Jt)|0;var so=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(so>>>26)|0,so&=67108863,m=Math.imul(Mt,Qt),a=Math.imul(Mt,Jt),a=a+Math.imul(kt,Qt)|0,g=Math.imul(kt,Jt);var ao=(S+m|0)+((a&8191)<<13)|0;return S=(g+(a>>>13)|0)+(ao>>>26)|0,ao&=67108863,w[0]=zi,w[1]=Vi,w[2]=Ki,w[3]=ji,w[4]=Yi,w[5]=$i,w[6]=Zi,w[7]=Xi,w[8]=Wi,w[9]=Qi,w[10]=Ji,w[11]=to,w[12]=eo,w[13]=ro,w[14]=no,w[15]=io,w[16]=oo,w[17]=so,w[18]=ao,S!==0&&(w[19]=S,f.length++),f};Math.imul||(T=O);function L(b,s,u){u.negative=s.negative^b.negative,u.length=b.length+s.length;for(var f=0,l=0,p=0;p<u.length-1;p++){var w=l;l=0;for(var S=f&67108863,m=Math.min(p,s.length-1),a=Math.max(0,p-b.length+1);a<=m;a++){var g=p-a,F=b.words[g]|0,k=s.words[a]|0,q=F*k,z=q&67108863;w=w+(q/67108864|0)|0,z=z+S|0,S=z&67108863,w=w+(z>>>26)|0,l+=w>>>26,w&=67108863}u.words[p]=S,f=w,w=l}return f!==0?u.words[p]=f:u.length--,u.strip()}function U(b,s,u){var f=new D;return f.mulp(b,s,u)}i.prototype.mulTo=function(s,u){var f,l=this.length+s.length;return this.length===10&&s.length===10?f=T(this,s,u):l<63?f=O(this,s,u):l<1024?f=L(this,s,u):f=U(this,s,u),f};function D(b,s){this.x=b,this.y=s}D.prototype.makeRBT=function(s){for(var u=new Array(s),f=i.prototype._countBits(s)-1,l=0;l<s;l++)u[l]=this.revBin(l,f,s);return u},D.prototype.revBin=function(s,u,f){if(s===0||s===f-1)return s;for(var l=0,p=0;p<u;p++)l|=(s&1)<<u-p-1,s>>=1;return l},D.prototype.permute=function(s,u,f,l,p,w){for(var S=0;S<w;S++)l[S]=u[s[S]],p[S]=f[s[S]]},D.prototype.transform=function(s,u,f,l,p,w){this.permute(w,s,u,f,l,p);for(var S=1;S<p;S<<=1)for(var m=S<<1,a=Math.cos(2*Math.PI/m),g=Math.sin(2*Math.PI/m),F=0;F<p;F+=m)for(var k=a,q=g,z=0;z<S;z++){var j=f[F+z],it=l[F+z],pt=f[F+z+S],ut=l[F+z+S],_=k*pt-q*ut;ut=k*ut+q*pt,pt=_,f[F+z]=j+pt,l[F+z]=it+ut,f[F+z+S]=j-pt,l[F+z+S]=it-ut,z!==m&&(_=a*k-g*q,q=a*q+g*k,k=_)}},D.prototype.guessLen13b=function(s,u){var f=Math.max(u,s)|1,l=f&1,p=0;for(f=f/2|0;f;f=f>>>1)p++;return 1<<p+1+l},D.prototype.conjugate=function(s,u,f){if(!(f<=1))for(var l=0;l<f/2;l++){var p=s[l];s[l]=s[f-l-1],s[f-l-1]=p,p=u[l],u[l]=-u[f-l-1],u[f-l-1]=-p}},D.prototype.normalize13b=function(s,u){for(var f=0,l=0;l<u/2;l++){var p=Math.round(s[2*l+1]/u)*8192+Math.round(s[2*l]/u)+f;s[l]=p&67108863,p<67108864?f=0:f=p/67108864|0}return s},D.prototype.convert13b=function(s,u,f,l){for(var p=0,w=0;w<u;w++)p=p+(s[w]|0),f[2*w]=p&8191,p=p>>>13,f[2*w+1]=p&8191,p=p>>>13;for(w=2*u;w<l;++w)f[w]=0;r(p===0),r((p&-8192)===0)},D.prototype.stub=function(s){for(var u=new Array(s),f=0;f<s;f++)u[f]=0;return u},D.prototype.mulp=function(s,u,f){var l=2*this.guessLen13b(s.length,u.length),p=this.makeRBT(l),w=this.stub(l),S=new Array(l),m=new Array(l),a=new Array(l),g=new Array(l),F=new Array(l),k=new Array(l),q=f.words;q.length=l,this.convert13b(s.words,s.length,S,l),this.convert13b(u.words,u.length,g,l),this.transform(S,w,m,a,l,p),this.transform(g,w,F,k,l,p);for(var z=0;z<l;z++){var j=m[z]*F[z]-a[z]*k[z];a[z]=m[z]*k[z]+a[z]*F[z],m[z]=j}return this.conjugate(m,a,l),this.transform(m,a,q,w,l,p),this.conjugate(q,w,l),this.normalize13b(q,l),f.negative=s.negative^u.negative,f.length=s.length+u.length,f.strip()},i.prototype.mul=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),this.mulTo(s,u)},i.prototype.mulf=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),U(this,s,u)},i.prototype.imul=function(s){return this.clone().mulTo(s,this)},i.prototype.imuln=function(s){r(typeof s=="number"),r(s<67108864);for(var u=0,f=0;f<this.length;f++){var l=(this.words[f]|0)*s,p=(l&67108863)+(u&67108863);u>>=26,u+=l/67108864|0,u+=p>>>26,this.words[f]=p&67108863}return u!==0&&(this.words[f]=u,this.length++),this.length=s===0?1:this.length,this},i.prototype.muln=function(s){return this.clone().imuln(s)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(s){var u=A(s);if(u.length===0)return new i(1);for(var f=this,l=0;l<u.length&&u[l]===0;l++,f=f.sqr());if(++l<u.length)for(var p=f.sqr();l<u.length;l++,p=p.sqr())u[l]!==0&&(f=f.mul(p));return f},i.prototype.iushln=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26,l=67108863>>>26-u<<26-u,p;if(u!==0){var w=0;for(p=0;p<this.length;p++){var S=this.words[p]&l,m=(this.words[p]|0)-S<<u;this.words[p]=m|w,w=S>>>26-u}w&&(this.words[p]=w,this.length++)}if(f!==0){for(p=this.length-1;p>=0;p--)this.words[p+f]=this.words[p];for(p=0;p<f;p++)this.words[p]=0;this.length+=f}return this.strip()},i.prototype.ishln=function(s){return r(this.negative===0),this.iushln(s)},i.prototype.iushrn=function(s,u,f){r(typeof s=="number"&&s>=0);var l;u?l=(u-u%26)/26:l=0;var p=s%26,w=Math.min((s-p)/26,this.length),S=67108863^67108863>>>p<<p,m=f;if(l-=w,l=Math.max(0,l),m){for(var a=0;a<w;a++)m.words[a]=this.words[a];m.length=w}if(w!==0)if(this.length>w)for(this.length-=w,a=0;a<this.length;a++)this.words[a]=this.words[a+w];else this.words[0]=0,this.length=1;var g=0;for(a=this.length-1;a>=0&&(g!==0||a>=l);a--){var F=this.words[a]|0;this.words[a]=g<<26-p|F>>>p,g=F&S}return m&&g!==0&&(m.words[m.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(s,u,f){return r(this.negative===0),this.iushrn(s,u,f)},i.prototype.shln=function(s){return this.clone().ishln(s)},i.prototype.ushln=function(s){return this.clone().iushln(s)},i.prototype.shrn=function(s){return this.clone().ishrn(s)},i.prototype.ushrn=function(s){return this.clone().iushrn(s)},i.prototype.testn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26,l=1<<u;if(this.length<=f)return!1;var p=this.words[f];return!!(p&l)},i.prototype.imaskn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=f)return this;if(u!==0&&f++,this.length=Math.min(f,this.length),u!==0){var l=67108863^67108863>>>u<<u;this.words[this.length-1]&=l}return this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.maskn=function(s){return this.clone().imaskn(s)},i.prototype.iaddn=function(s){return r(typeof s=="number"),r(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},i.prototype._iaddn=function(s){this.words[0]+=s;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},i.prototype.isubn=function(s){if(r(typeof s=="number"),r(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this.strip()},i.prototype.addn=function(s){return this.clone().iaddn(s)},i.prototype.subn=function(s){return this.clone().isubn(s)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(s,u,f){var l=s.length+f,p;this._expand(l);var w,S=0;for(p=0;p<s.length;p++){w=(this.words[p+f]|0)+S;var m=(s.words[p]|0)*u;w-=m&67108863,S=(w>>26)-(m/67108864|0),this.words[p+f]=w&67108863}for(;p<this.length-f;p++)w=(this.words[p+f]|0)+S,S=w>>26,this.words[p+f]=w&67108863;if(S===0)return this.strip();for(r(S===-1),S=0,p=0;p<this.length;p++)w=-(this.words[p]|0)+S,S=w>>26,this.words[p]=w&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(s,u){var f=this.length-s.length,l=this.clone(),p=s,w=p.words[p.length-1]|0,S=this._countBits(w);f=26-S,f!==0&&(p=p.ushln(f),l.iushln(f),w=p.words[p.length-1]|0);var m=l.length-p.length,a;if(u!=="mod"){a=new i(null),a.length=m+1,a.words=new Array(a.length);for(var g=0;g<a.length;g++)a.words[g]=0}var F=l.clone()._ishlnsubmul(p,1,m);F.negative===0&&(l=F,a&&(a.words[m]=1));for(var k=m-1;k>=0;k--){var q=(l.words[p.length+k]|0)*67108864+(l.words[p.length+k-1]|0);for(q=Math.min(q/w|0,67108863),l._ishlnsubmul(p,q,k);l.negative!==0;)q--,l.negative=0,l._ishlnsubmul(p,1,k),l.isZero()||(l.negative^=1);a&&(a.words[k]=q)}return a&&a.strip(),l.strip(),u!=="div"&&f!==0&&l.iushrn(f),{div:a||null,mod:l}},i.prototype.divmod=function(s,u,f){if(r(!s.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var l,p,w;return this.negative!==0&&s.negative===0?(w=this.neg().divmod(s,u),u!=="mod"&&(l=w.div.neg()),u!=="div"&&(p=w.mod.neg(),f&&p.negative!==0&&p.iadd(s)),{div:l,mod:p}):this.negative===0&&s.negative!==0?(w=this.divmod(s.neg(),u),u!=="mod"&&(l=w.div.neg()),{div:l,mod:w.mod}):(this.negative&s.negative)!==0?(w=this.neg().divmod(s.neg(),u),u!=="div"&&(p=w.mod.neg(),f&&p.negative!==0&&p.isub(s)),{div:w.div,mod:p}):s.length>this.length||this.cmp(s)<0?{div:new i(0),mod:this}:s.length===1?u==="div"?{div:this.divn(s.words[0]),mod:null}:u==="mod"?{div:null,mod:new i(this.modn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new i(this.modn(s.words[0]))}:this._wordDiv(s,u)},i.prototype.div=function(s){return this.divmod(s,"div",!1).div},i.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},i.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},i.prototype.divRound=function(s){var u=this.divmod(s);if(u.mod.isZero())return u.div;var f=u.div.negative!==0?u.mod.isub(s):u.mod,l=s.ushrn(1),p=s.andln(1),w=f.cmp(l);return w<0||p===1&&w===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},i.prototype.modn=function(s){r(s<=67108863);for(var u=(1<<26)%s,f=0,l=this.length-1;l>=0;l--)f=(u*f+(this.words[l]|0))%s;return f},i.prototype.idivn=function(s){r(s<=67108863);for(var u=0,f=this.length-1;f>=0;f--){var l=(this.words[f]|0)+u*67108864;this.words[f]=l/s|0,u=l%s}return this.strip()},i.prototype.divn=function(s){return this.clone().idivn(s)},i.prototype.egcd=function(s){r(s.negative===0),r(!s.isZero());var u=this,f=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var l=new i(1),p=new i(0),w=new i(0),S=new i(1),m=0;u.isEven()&&f.isEven();)u.iushrn(1),f.iushrn(1),++m;for(var a=f.clone(),g=u.clone();!u.isZero();){for(var F=0,k=1;(u.words[0]&k)===0&&F<26;++F,k<<=1);if(F>0)for(u.iushrn(F);F-- >0;)(l.isOdd()||p.isOdd())&&(l.iadd(a),p.isub(g)),l.iushrn(1),p.iushrn(1);for(var q=0,z=1;(f.words[0]&z)===0&&q<26;++q,z<<=1);if(q>0)for(f.iushrn(q);q-- >0;)(w.isOdd()||S.isOdd())&&(w.iadd(a),S.isub(g)),w.iushrn(1),S.iushrn(1);u.cmp(f)>=0?(u.isub(f),l.isub(w),p.isub(S)):(f.isub(u),w.isub(l),S.isub(p))}return{a:w,b:S,gcd:f.iushln(m)}},i.prototype._invmp=function(s){r(s.negative===0),r(!s.isZero());var u=this,f=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var l=new i(1),p=new i(0),w=f.clone();u.cmpn(1)>0&&f.cmpn(1)>0;){for(var S=0,m=1;(u.words[0]&m)===0&&S<26;++S,m<<=1);if(S>0)for(u.iushrn(S);S-- >0;)l.isOdd()&&l.iadd(w),l.iushrn(1);for(var a=0,g=1;(f.words[0]&g)===0&&a<26;++a,g<<=1);if(a>0)for(f.iushrn(a);a-- >0;)p.isOdd()&&p.iadd(w),p.iushrn(1);u.cmp(f)>=0?(u.isub(f),l.isub(p)):(f.isub(u),p.isub(l))}var F;return u.cmpn(1)===0?F=l:F=p,F.cmpn(0)<0&&F.iadd(s),F},i.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var u=this.clone(),f=s.clone();u.negative=0,f.negative=0;for(var l=0;u.isEven()&&f.isEven();l++)u.iushrn(1),f.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;f.isEven();)f.iushrn(1);var p=u.cmp(f);if(p<0){var w=u;u=f,f=w}else if(p===0||f.cmpn(1)===0)break;u.isub(f)}while(!0);return f.iushln(l)},i.prototype.invm=function(s){return this.egcd(s).a.umod(s)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(s){return this.words[0]&s},i.prototype.bincn=function(s){r(typeof s=="number");var u=s%26,f=(s-u)/26,l=1<<u;if(this.length<=f)return this._expand(f+1),this.words[f]|=l,this;for(var p=l,w=f;p!==0&&w<this.length;w++){var S=this.words[w]|0;S+=p,p=S>>>26,S&=67108863,this.words[w]=S}return p!==0&&(this.words[w]=p,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(s){var u=s<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this.strip();var f;if(this.length>1)f=1;else{u&&(s=-s),r(s<=67108863,"Number is too big");var l=this.words[0]|0;f=l===s?0:l<s?-1:1}return this.negative!==0?-f|0:f},i.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var u=this.ucmp(s);return this.negative!==0?-u|0:u},i.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var u=0,f=this.length-1;f>=0;f--){var l=this.words[f]|0,p=s.words[f]|0;if(l!==p){l<p?u=-1:l>p&&(u=1);break}}return u},i.prototype.gtn=function(s){return this.cmpn(s)===1},i.prototype.gt=function(s){return this.cmp(s)===1},i.prototype.gten=function(s){return this.cmpn(s)>=0},i.prototype.gte=function(s){return this.cmp(s)>=0},i.prototype.ltn=function(s){return this.cmpn(s)===-1},i.prototype.lt=function(s){return this.cmp(s)===-1},i.prototype.lten=function(s){return this.cmpn(s)<=0},i.prototype.lte=function(s){return this.cmp(s)<=0},i.prototype.eqn=function(s){return this.cmpn(s)===0},i.prototype.eq=function(s){return this.cmp(s)===0},i.red=function(s){return new nt(s)},i.prototype.toRed=function(s){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(s){return this.red=s,this},i.prototype.forceRed=function(s){return r(!this.red,"Already a number in reduction context"),this._forceRed(s)},i.prototype.redAdd=function(s){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},i.prototype.redIAdd=function(s){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},i.prototype.redSub=function(s){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},i.prototype.redISub=function(s){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},i.prototype.redShl=function(s){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},i.prototype.redMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},i.prototype.redIMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(s){return r(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var et={k256:null,p224:null,p192:null,p25519:null};function J(b,s){this.name=b,this.p=new i(s,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}J.prototype._tmp=function(){var s=new i(null);return s.words=new Array(Math.ceil(this.n/13)),s},J.prototype.ireduce=function(s){var u=s,f;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),f=u.bitLength();while(f>this.n);var l=f<this.n?-1:u.ucmp(this.p);return l===0?(u.words[0]=0,u.length=1):l>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},J.prototype.split=function(s,u){s.iushrn(this.n,0,u)},J.prototype.imulK=function(s){return s.imul(this.k)};function Y(){J.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Y,J),Y.prototype.split=function(s,u){for(var f=4194303,l=Math.min(s.length,9),p=0;p<l;p++)u.words[p]=s.words[p];if(u.length=l,s.length<=9){s.words[0]=0,s.length=1;return}var w=s.words[9];for(u.words[u.length++]=w&f,p=10;p<s.length;p++){var S=s.words[p]|0;s.words[p-10]=(S&f)<<4|w>>>22,w=S}w>>>=22,s.words[p-10]=w,w===0&&s.length>10?s.length-=10:s.length-=9},Y.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var u=0,f=0;f<s.length;f++){var l=s.words[f]|0;u+=l*977,s.words[f]=u&67108863,u=l*64+(u/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function $(){J.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n($,J);function ft(){J.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(ft,J);function Pt(){J.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(Pt,J),Pt.prototype.imulK=function(s){for(var u=0,f=0;f<s.length;f++){var l=(s.words[f]|0)*19+u,p=l&67108863;l>>>=26,s.words[f]=p,u=l}return u!==0&&(s.words[s.length++]=u),s},i._prime=function(s){if(et[s])return et[s];var u;if(s==="k256")u=new Y;else if(s==="p224")u=new $;else if(s==="p192")u=new ft;else if(s==="p25519")u=new Pt;else throw new Error("Unknown prime "+s);return et[s]=u,u};function nt(b){if(typeof b=="string"){var s=i._prime(b);this.m=s.p,this.prime=s}else r(b.gtn(1),"modulus must be greater than 1"),this.m=b,this.prime=null}nt.prototype._verify1=function(s){r(s.negative===0,"red works only with positives"),r(s.red,"red works only with red numbers")},nt.prototype._verify2=function(s,u){r((s.negative|u.negative)===0,"red works only with positives"),r(s.red&&s.red===u.red,"red works only with red numbers")},nt.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):s.umod(this.m)._forceRed(this)},nt.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},nt.prototype.add=function(s,u){this._verify2(s,u);var f=s.add(u);return f.cmp(this.m)>=0&&f.isub(this.m),f._forceRed(this)},nt.prototype.iadd=function(s,u){this._verify2(s,u);var f=s.iadd(u);return f.cmp(this.m)>=0&&f.isub(this.m),f},nt.prototype.sub=function(s,u){this._verify2(s,u);var f=s.sub(u);return f.cmpn(0)<0&&f.iadd(this.m),f._forceRed(this)},nt.prototype.isub=function(s,u){this._verify2(s,u);var f=s.isub(u);return f.cmpn(0)<0&&f.iadd(this.m),f},nt.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},nt.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},nt.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},nt.prototype.isqr=function(s){return this.imul(s,s.clone())},nt.prototype.sqr=function(s){return this.mul(s,s)},nt.prototype.sqrt=function(s){if(s.isZero())return s.clone();var u=this.m.andln(3);if(r(u%2===1),u===3){var f=this.m.add(new i(1)).iushrn(2);return this.pow(s,f)}for(var l=this.m.subn(1),p=0;!l.isZero()&&l.andln(1)===0;)p++,l.iushrn(1);r(!l.isZero());var w=new i(1).toRed(this),S=w.redNeg(),m=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new i(2*a*a).toRed(this);this.pow(a,m).cmp(S)!==0;)a.redIAdd(S);for(var g=this.pow(a,l),F=this.pow(s,l.addn(1).iushrn(1)),k=this.pow(s,l),q=p;k.cmp(w)!==0;){for(var z=k,j=0;z.cmp(w)!==0;j++)z=z.redSqr();r(j<q);var it=this.pow(g,new i(1).iushln(q-j-1));F=F.redMul(it),g=it.redSqr(),k=k.redMul(g),q=j}return F},nt.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},nt.prototype.pow=function(s,u){if(u.isZero())return new i(1).toRed(this);if(u.cmpn(1)===0)return s.clone();var f=4,l=new Array(1<<f);l[0]=new i(1).toRed(this),l[1]=s;for(var p=2;p<l.length;p++)l[p]=this.mul(l[p-1],s);var w=l[0],S=0,m=0,a=u.bitLength()%26;for(a===0&&(a=26),p=u.length-1;p>=0;p--){for(var g=u.words[p],F=a-1;F>=0;F--){var k=g>>F&1;if(w!==l[0]&&(w=this.sqr(w)),k===0&&S===0){m=0;continue}S<<=1,S|=k,m++,!(m!==f&&(p!==0||F!==0))&&(w=this.mul(w,l[S]),m=0,S=0)}a=26}return w},nt.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},nt.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},i.mont=function(s){return new dt(s)};function dt(b){nt.call(this,b),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(dt,nt),dt.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},dt.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},dt.prototype.imul=function(s,u){if(s.isZero()||u.isZero())return s.words[0]=0,s.length=1,s;var f=s.imul(u),l=f.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=f.isub(l).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},dt.prototype.mul=function(s,u){if(s.isZero()||u.isZero())return new i(0)._forceRed(this);var f=s.mul(u),l=f.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=f.isub(l).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},dt.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Co>"u"||Co,gc)});var yc=Z((Mm,xc)=>{"use strict";I();function an(){}an.getRandomBuffer=function(t){return C.default.browser?an.getRandomBufferBrowser(t):an.getRandomBufferNode(t)};an.getRandomBufferNode=function(t){var e=se();return e.randomBytes(t)};an.getRandomBufferBrowser=function(t){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");var e;if(window.crypto&&window.crypto.getRandomValues)e=window.crypto;else if(window.msCrypto&&window.msCrypto.getRandomValues)e=window.msCrypto;else throw new Error("window.crypto.getRandomValues not available");var r=new Uint8Array(t);e.getRandomValues(r);var n=E.Buffer.from(r);return n};xc.exports=an});var cn=Z((km,wc)=>{"use strict";I();var Ol=yc(),Ot={};Ot.isArray=t=>Array.isArray(t);Ot.isNumber=t=>typeof t=="number";Ot.isObject=t=>t&&typeof t=="object";Ot.isString=t=>typeof t=="string";Ot.isUndefined=t=>typeof t>"u";Ot.isFunction=t=>typeof t=="function";Ot.isNull=t=>t===null;Ot.isDate=t=>t instanceof Date;Ot.extend=(t,e)=>Object.assign(t,e);Ot.noop=()=>{};Ot.every=(t,e)=>t.every(e||(r=>r));Ot.map=(t,e)=>Array.from(t).map(e||(r=>r));Ot.includes=(t,e)=>t.includes(e);Ot.each=(t,e)=>t.forEach(e);Ot.clone=t=>Object.assign({},t);Ot.pick=(t,e)=>{let r={};return e.forEach(n=>{typeof t[n]<"u"&&(r[n]=t[n])}),r};Ot.values=t=>Object.values(t);Ot.filter=(t,e)=>t.filter(e);Ot.reduce=(t,e,r)=>t.reduce(e,r);Ot.without=(t,e)=>t.filter(r=>r!==e);Ot.shuffle=t=>{let e=t.slice(0);for(let r=e.length-1;r>0;r--){let i=Ol.getRandomBuffer(4).readUInt32BE(0)/4294967296,o=Math.floor(i*(r+1));[e[r],e[o]]=[e[o],e[r]]}return e};Ot.difference=(t,e)=>t.filter(r=>!e.includes(r));Ot.findIndex=(t,e)=>t.findIndex(e);Ot.some=(t,e)=>t.some(e);Ot.range=t=>[...Array(t).keys()];wc.exports=Ot});var Sc=Z((Hm,bc)=>{"use strict";I();var Al="https://docs.moneybutton.com/";bc.exports=[{name:"InvalidB58Char",message:"Invalid Base58 character: {0} in {1}"},{name:"InvalidB58Checksum",message:"Invalid Base58 checksum for {0}"},{name:"InvalidNetwork",message:"Invalid version for network: got {0}"},{name:"InvalidState",message:"Invalid state: {0}"},{name:"NotImplemented",message:"Function {0} was not implemented yet"},{name:"InvalidNetworkArgument",message:'Invalid network: must be "livenet" or "testnet", got {0}'},{name:"InvalidArgument",message:function(){return"Invalid Argument"+(arguments[0]?": "+arguments[0]:"")+(arguments[1]?" Documentation: "+Al+arguments[1]:"")}},{name:"AbstractMethodInvoked",message:"Abstract Method Invocation: {0}"},{name:"InvalidArgumentType",message:function(){return"Invalid Argument for "+arguments[2]+", expected "+arguments[1]+" but got "+typeof arguments[0]}},{name:"Unit",message:"Internal Error on Unit {0}",errors:[{name:"UnknownCode",message:"Unrecognized unit code: {0}"},{name:"InvalidRate",message:"Invalid exchange rate: {0}"}]},{name:"MerkleBlock",message:"Internal Error on MerkleBlock {0}",errors:[{name:"InvalidMerkleTree",message:"This MerkleBlock contain an invalid Merkle Tree"}]},{name:"Transaction",message:"Internal Error on Transaction {0}",errors:[{name:"Input",message:"Internal Error on Input {0}",errors:[{name:"MissingScript",message:"Need a script to create an input"},{name:"UnsupportedScript",message:"Unsupported input script type: {0}"},{name:"MissingPreviousOutput",message:"No previous output information."}]},{name:"NeedMoreInfo",message:"{0}"},{name:"InvalidSorting",message:"The sorting function provided did not return the change output as one of the array elements"},{name:"InvalidOutputAmountSum",message:"{0}"},{name:"MissingSignatures",message:"Some inputs have not been fully signed"},{name:"InvalidIndex",message:"Invalid index: {0} is not between 0, {1}"},{name:"UnableToVerifySignature",message:"Unable to verify signature: {0}"},{name:"DustOutputs",message:"Dust amount detected in one output"},{name:"InvalidSatoshis",message:"Output satoshis are invalid"},{name:"FeeError",message:"Internal Error on Fee {0}",errors:[{name:"TooSmall",message:"Fee is too small: {0}"},{name:"TooLarge",message:"Fee is too large: {0}"},{name:"Different",message:"Unspent value is different from specified fee: {0}"}]},{name:"ChangeAddressMissing",message:"Change address is missing"},{name:"BlockHeightTooHigh",message:"Block Height can be at most 2^32 -1"},{name:"NLockTimeOutOfRange",message:"Block Height can only be between 0 and 499 999 999"},{name:"LockTimeTooEarly",message:"Lock Time can't be earlier than UNIX date 500 000 000"}]},{name:"Script",message:"Internal Error on Script {0}",errors:[{name:"UnrecognizedAddress",message:"Expected argument {0} to be an address"},{name:"CantDeriveAddress",message:"Can't derive address associated with script {0}, needs to be p2pkh in, p2pkh out, p2sh in, or p2sh out."},{name:"InvalidBuffer",message:"Invalid script buffer: can't parse valid script from given buffer {0}"}]},{name:"HDPrivateKey",message:"Internal Error on HDPrivateKey {0}",errors:[{name:"InvalidDerivationArgument",message:"Invalid derivation argument {0}, expected string, or number and boolean"},{name:"InvalidEntropyArgument",message:"Invalid entropy: must be an hexa string or binary buffer, got {0}",errors:[{name:"TooMuchEntropy",message:'Invalid entropy: more than 512 bits is non standard, got "{0}"'},{name:"NotEnoughEntropy",message:'Invalid entropy: at least 128 bits needed, got "{0}"'}]},{name:"InvalidLength",message:"Invalid length for xprivkey string in {0}"},{name:"InvalidPath",message:"Invalid derivation path: {0}"},{name:"UnrecognizedArgument",message:'Invalid argument: creating a HDPrivateKey requires a string, buffer, json or object, got "{0}"'}]},{name:"HDPublicKey",message:"Internal Error on HDPublicKey {0}",errors:[{name:"ArgumentIsPrivateExtended",message:"Argument is an extended private key: {0}"},{name:"InvalidDerivationArgument",message:"Invalid derivation argument: got {0}"},{name:"InvalidLength",message:'Invalid length for xpubkey: got "{0}"'},{name:"InvalidPath",message:'Invalid derivation path, it should look like: "m/1/100", got "{0}"'},{name:"InvalidIndexCantDeriveHardened",message:"Invalid argument: creating a hardened path requires an HDPrivateKey"},{name:"MustSupplyArgument",message:"Must supply an argument to create a HDPublicKey"},{name:"UnrecognizedArgument",message:"Invalid argument for creation, must be string, json, buffer, or object"}]}]});var Oc=Z((Nm,qo)=>{"use strict";I();var Uo=cn();function Il(t,e){return t.replace("{0}",e[0]).replace("{1}",e[1]).replace("{2}",e[2])}var Ec=function(t,e){var r=function(){if(Uo.isString(e.message))this.message=Il(e.message,arguments);else if(Uo.isFunction(e.message))this.message=e.message.apply(null,arguments);else throw new Error("Invalid error definition for "+e.name);this.stack=this.message+`
|
|
22
|
+
`);let n=new ue.Script.Interpreter,i=new ue.crypto.BN(1e5),o=n.verify(t,e,r,0,ue.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,i);console.log("\u{1F510} Locking Script:",e.toASM()),console.log("\u{1F513} Unlocking Script:",t.toASM()),console.log("-------------------------------------------"),console.log("\u2705 Result:",o?"TRUE (Success)":"\u274C FALSE (Failure)"),console.log("Final Stack:",n.stack.map(c=>c.toString("hex"))),console.log("AltStack:",n.altstack.map(c=>c.toString("hex"))),console.log("===========================================")}async function pc(){if(typeof N.default>"u"||!N.default.argv){console.log("\u2699\uFE0F CLI mode not available in browser environment");return}let t=N.default.argv.slice(2),e=A=>{let O=t.indexOf(A);return O!==-1&&t[O+1]?t[O+1]:null},r=e("--unlocking"),n=e("--locking"),i=e("--combined"),o=t.includes("--step"),c=t.includes("--truth"),h,d,x;if(i)x=ci(i);else{h=ci(r),d=ci(n);let A=E.Buffer.concat([h.toBuffer(),d.toBuffer()]);x=ue.Script.fromBuffer(A)}let v=new ue.Transaction,y=new ue.Transaction.Input({prevTxId:"0".repeat(64),outputIndex:0,script:ue.Script.empty(),satoshis:1e5,output:new ue.Transaction.Output({satoshis:1e5,script:ue.Script.empty()})});v.addInput(y),v.addOutput(new ue.Transaction.Output({satoshis:1e5,script:ue.Script.empty()})),o?await lc(x,v,!0):c?dc(h||ue.Script.empty(),d||ue.Script.empty(),v):console.log("\u2699\uFE0F No mode specified. Use --step or --truth")}Co.exports={parseScript:ci,printStack:Lo,stepThroughScript:lc,runFullEvaluation:dc,main:pc};typeof ve<"u"&&ve.main===Co&&pc()});var vc=Z((gc,No)=>{I();(function(t,e){"use strict";function r(b,s){if(!b)throw new Error(s||"Assertion failed")}function n(b,s){b.super_=s;var u=function(){};u.prototype=s.prototype,b.prototype=new u,b.prototype.constructor=b}function i(b,s,u){if(i.isBN(b))return b;this.negative=0,this.words=null,this.length=0,this.red=null,b!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(b||0,s||10,u||"be"))}typeof t=="object"?t.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=si().Buffer}catch{}i.isBN=function(s){return s instanceof i?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===i.wordSize&&Array.isArray(s.words)},i.max=function(s,u){return s.cmp(u)>0?s:u},i.min=function(s,u){return s.cmp(u)<0?s:u},i.prototype._init=function(s,u,f){if(typeof s=="number")return this._initNumber(s,u,f);if(typeof s=="object")return this._initArray(s,u,f);u==="hex"&&(u=16),r(u===(u|0)&&u>=2&&u<=36),s=s.toString().replace(/\s+/g,"");var l=0;s[0]==="-"&&(l++,this.negative=1),l<s.length&&(u===16?this._parseHex(s,l,f):(this._parseBase(s,u,l),f==="le"&&this._initArray(this.toArray(),u,f)))},i.prototype._initNumber=function(s,u,f){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(r(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),f==="le"&&this._initArray(this.toArray(),u,f)},i.prototype._initArray=function(s,u,f){if(r(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var l=0;l<this.length;l++)this.words[l]=0;var p,w,S=0;if(f==="be")for(l=s.length-1,p=0;l>=0;l-=3)w=s[l]|s[l-1]<<8|s[l-2]<<16,this.words[p]|=w<<S&67108863,this.words[p+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,p++);else if(f==="le")for(l=0,p=0;l<s.length;l+=3)w=s[l]|s[l+1]<<8|s[l+2]<<16,this.words[p]|=w<<S&67108863,this.words[p+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,p++);return this.strip()};function c(b,s){var u=b.charCodeAt(s);return u>=65&&u<=70?u-55:u>=97&&u<=102?u-87:u-48&15}function h(b,s,u){var f=c(b,u);return u-1>=s&&(f|=c(b,u-1)<<4),f}i.prototype._parseHex=function(s,u,f){this.length=Math.ceil((s.length-u)/6),this.words=new Array(this.length);for(var l=0;l<this.length;l++)this.words[l]=0;var p=0,w=0,S;if(f==="be")for(l=s.length-1;l>=u;l-=2)S=h(s,u,l)<<p,this.words[w]|=S&67108863,p>=18?(p-=18,w+=1,this.words[w]|=S>>>26):p+=8;else{var m=s.length-u;for(l=m%2===0?u+1:u;l<s.length;l+=2)S=h(s,u,l)<<p,this.words[w]|=S&67108863,p>=18?(p-=18,w+=1,this.words[w]|=S>>>26):p+=8}this.strip()};function d(b,s,u,f){for(var l=0,p=Math.min(b.length,u),w=s;w<p;w++){var S=b.charCodeAt(w)-48;l*=f,S>=49?l+=S-49+10:S>=17?l+=S-17+10:l+=S}return l}i.prototype._parseBase=function(s,u,f){this.words=[0],this.length=1;for(var l=0,p=1;p<=67108863;p*=u)l++;l--,p=p/u|0;for(var w=s.length-f,S=w%l,m=Math.min(w,w-S)+f,a=0,g=f;g<m;g+=l)a=d(s,g,g+l,u),this.imuln(p),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(S!==0){var F=1;for(a=d(s,g,s.length,u),g=0;g<S;g++)F*=u;this.imuln(F),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this.strip()},i.prototype.copy=function(s){s.words=new Array(this.length);for(var u=0;u<this.length;u++)s.words[u]=this.words[u];s.length=this.length,s.negative=this.negative,s.red=this.red},i.prototype.clone=function(){var s=new i(null);return this.copy(s),s},i.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},i.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],v=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],y=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(s,u){s=s||10,u=u|0||1;var f;if(s===16||s==="hex"){f="";for(var l=0,p=0,w=0;w<this.length;w++){var S=this.words[w],m=((S<<l|p)&16777215).toString(16);p=S>>>24-l&16777215,l+=2,l>=26&&(l-=26,w--),p!==0||w!==this.length-1?f=x[6-m.length]+m+f:f=m+f}for(p!==0&&(f=p.toString(16)+f);f.length%u!==0;)f="0"+f;return this.negative!==0&&(f="-"+f),f}if(s===(s|0)&&s>=2&&s<=36){var a=v[s],g=y[s];f="";var F=this.clone();for(F.negative=0;!F.isZero();){var k=F.modn(g).toString(s);F=F.idivn(g),F.isZero()?f=k+f:f=x[a-k.length]+k+f}for(this.isZero()&&(f="0"+f);f.length%u!==0;)f="0"+f;return this.negative!==0&&(f="-"+f),f}r(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(s,u){return r(typeof o<"u"),this.toArrayLike(o,s,u)},i.prototype.toArray=function(s,u){return this.toArrayLike(Array,s,u)},i.prototype.toArrayLike=function(s,u,f){var l=this.byteLength(),p=f||Math.max(1,l);r(l<=p,"byte array longer than desired length"),r(p>0,"Requested array length <= 0"),this.strip();var w=u==="le",S=new s(p),m,a,g=this.clone();if(w){for(a=0;!g.isZero();a++)m=g.andln(255),g.iushrn(8),S[a]=m;for(;a<p;a++)S[a]=0}else{for(a=0;a<p-l;a++)S[a]=0;for(a=0;!g.isZero();a++)m=g.andln(255),g.iushrn(8),S[p-a-1]=m}return S},Math.clz32?i.prototype._countBits=function(s){return 32-Math.clz32(s)}:i.prototype._countBits=function(s){var u=s,f=0;return u>=4096&&(f+=13,u>>>=13),u>=64&&(f+=7,u>>>=7),u>=8&&(f+=4,u>>>=4),u>=2&&(f+=2,u>>>=2),f+u},i.prototype._zeroBits=function(s){if(s===0)return 26;var u=s,f=0;return(u&8191)===0&&(f+=13,u>>>=13),(u&127)===0&&(f+=7,u>>>=7),(u&15)===0&&(f+=4,u>>>=4),(u&3)===0&&(f+=2,u>>>=2),(u&1)===0&&f++,f},i.prototype.bitLength=function(){var s=this.words[this.length-1],u=this._countBits(s);return(this.length-1)*26+u};function A(b){for(var s=new Array(b.bitLength()),u=0;u<s.length;u++){var f=u/26|0,l=u%26;s[u]=(b.words[f]&1<<l)>>>l}return s}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,u=0;u<this.length;u++){var f=this._zeroBits(this.words[u]);if(s+=f,f!==26)break}return s},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},i.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var u=0;u<s.length;u++)this.words[u]=this.words[u]|s.words[u];return this.strip()},i.prototype.ior=function(s){return r((this.negative|s.negative)===0),this.iuor(s)},i.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},i.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},i.prototype.iuand=function(s){var u;this.length>s.length?u=s:u=this;for(var f=0;f<u.length;f++)this.words[f]=this.words[f]&s.words[f];return this.length=u.length,this.strip()},i.prototype.iand=function(s){return r((this.negative|s.negative)===0),this.iuand(s)},i.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},i.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},i.prototype.iuxor=function(s){var u,f;this.length>s.length?(u=this,f=s):(u=s,f=this);for(var l=0;l<f.length;l++)this.words[l]=u.words[l]^f.words[l];if(this!==u)for(;l<u.length;l++)this.words[l]=u.words[l];return this.length=u.length,this.strip()},i.prototype.ixor=function(s){return r((this.negative|s.negative)===0),this.iuxor(s)},i.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},i.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},i.prototype.inotn=function(s){r(typeof s=="number"&&s>=0);var u=Math.ceil(s/26)|0,f=s%26;this._expand(u),f>0&&u--;for(var l=0;l<u;l++)this.words[l]=~this.words[l]&67108863;return f>0&&(this.words[l]=~this.words[l]&67108863>>26-f),this.strip()},i.prototype.notn=function(s){return this.clone().inotn(s)},i.prototype.setn=function(s,u){r(typeof s=="number"&&s>=0);var f=s/26|0,l=s%26;return this._expand(f+1),u?this.words[f]=this.words[f]|1<<l:this.words[f]=this.words[f]&~(1<<l),this.strip()},i.prototype.iadd=function(s){var u;if(this.negative!==0&&s.negative===0)return this.negative=0,u=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,u=this.isub(s),s.negative=1,u._normSign();var f,l;this.length>s.length?(f=this,l=s):(f=s,l=this);for(var p=0,w=0;w<l.length;w++)u=(f.words[w]|0)+(l.words[w]|0)+p,this.words[w]=u&67108863,p=u>>>26;for(;p!==0&&w<f.length;w++)u=(f.words[w]|0)+p,this.words[w]=u&67108863,p=u>>>26;if(this.length=f.length,p!==0)this.words[this.length]=p,this.length++;else if(f!==this)for(;w<f.length;w++)this.words[w]=f.words[w];return this},i.prototype.add=function(s){var u;return s.negative!==0&&this.negative===0?(s.negative=0,u=this.sub(s),s.negative^=1,u):s.negative===0&&this.negative!==0?(this.negative=0,u=s.sub(this),this.negative=1,u):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},i.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var u=this.iadd(s);return s.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var f=this.cmp(s);if(f===0)return this.negative=0,this.length=1,this.words[0]=0,this;var l,p;f>0?(l=this,p=s):(l=s,p=this);for(var w=0,S=0;S<p.length;S++)u=(l.words[S]|0)-(p.words[S]|0)+w,w=u>>26,this.words[S]=u&67108863;for(;w!==0&&S<l.length;S++)u=(l.words[S]|0)+w,w=u>>26,this.words[S]=u&67108863;if(w===0&&S<l.length&&l!==this)for(;S<l.length;S++)this.words[S]=l.words[S];return this.length=Math.max(this.length,S),l!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(s){return this.clone().isub(s)};function O(b,s,u){u.negative=s.negative^b.negative;var f=b.length+s.length|0;u.length=f,f=f-1|0;var l=b.words[0]|0,p=s.words[0]|0,w=l*p,S=w&67108863,m=w/67108864|0;u.words[0]=S;for(var a=1;a<f;a++){for(var g=m>>>26,F=m&67108863,k=Math.min(a,s.length-1),q=Math.max(0,a-b.length+1);q<=k;q++){var z=a-q|0;l=b.words[z]|0,p=s.words[q]|0,w=l*p+F,g+=w/67108864|0,F=w&67108863}u.words[a]=F|0,m=g|0}return m!==0?u.words[a]=m|0:u.length--,u.strip()}var T=function(s,u,f){var l=s.words,p=u.words,w=f.words,S=0,m,a,g,F=l[0]|0,k=F&8191,q=F>>>13,z=l[1]|0,j=z&8191,it=z>>>13,pt=l[2]|0,ut=pt&8191,_=pt>>>13,P=l[3]|0,R=P&8191,C=P>>>13,V=l[4]|0,G=V&8191,K=V>>>13,ot=l[5]|0,X=ot&8191,Q=ot>>>13,oe=l[6]|0,vt=oe&8191,st=oe>>>13,at=l[7]|0,ct=at&8191,ht=at>>>13,cr=l[8]|0,Tt=cr&8191,Et=cr>>>13,ei=l[9]|0,Mt=ei&8191,kt=ei>>>13,Ys=p[0]|0,Ft=Ys&8191,Ht=Ys>>>13,$s=p[1]|0,Lt=$s&8191,Ct=$s>>>13,Zs=p[2]|0,Nt=Zs&8191,Ut=Zs>>>13,Xs=p[3]|0,qt=Xs&8191,Dt=Xs>>>13,Ws=p[4]|0,Gt=Ws&8191,zt=Ws>>>13,Qs=p[5]|0,Vt=Qs&8191,Kt=Qs>>>13,Js=p[6]|0,jt=Js&8191,Yt=Js>>>13,ta=p[7]|0,$t=ta&8191,Zt=ta>>>13,ea=p[8]|0,Xt=ea&8191,Wt=ea>>>13,ra=p[9]|0,Qt=ra&8191,Jt=ra>>>13;f.negative=s.negative^u.negative,f.length=19,m=Math.imul(k,Ft),a=Math.imul(k,Ht),a=a+Math.imul(q,Ft)|0,g=Math.imul(q,Ht);var zi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(zi>>>26)|0,zi&=67108863,m=Math.imul(j,Ft),a=Math.imul(j,Ht),a=a+Math.imul(it,Ft)|0,g=Math.imul(it,Ht),m=m+Math.imul(k,Lt)|0,a=a+Math.imul(k,Ct)|0,a=a+Math.imul(q,Lt)|0,g=g+Math.imul(q,Ct)|0;var Vi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Vi>>>26)|0,Vi&=67108863,m=Math.imul(ut,Ft),a=Math.imul(ut,Ht),a=a+Math.imul(_,Ft)|0,g=Math.imul(_,Ht),m=m+Math.imul(j,Lt)|0,a=a+Math.imul(j,Ct)|0,a=a+Math.imul(it,Lt)|0,g=g+Math.imul(it,Ct)|0,m=m+Math.imul(k,Nt)|0,a=a+Math.imul(k,Ut)|0,a=a+Math.imul(q,Nt)|0,g=g+Math.imul(q,Ut)|0;var Ki=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Ki>>>26)|0,Ki&=67108863,m=Math.imul(R,Ft),a=Math.imul(R,Ht),a=a+Math.imul(C,Ft)|0,g=Math.imul(C,Ht),m=m+Math.imul(ut,Lt)|0,a=a+Math.imul(ut,Ct)|0,a=a+Math.imul(_,Lt)|0,g=g+Math.imul(_,Ct)|0,m=m+Math.imul(j,Nt)|0,a=a+Math.imul(j,Ut)|0,a=a+Math.imul(it,Nt)|0,g=g+Math.imul(it,Ut)|0,m=m+Math.imul(k,qt)|0,a=a+Math.imul(k,Dt)|0,a=a+Math.imul(q,qt)|0,g=g+Math.imul(q,Dt)|0;var ji=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(ji>>>26)|0,ji&=67108863,m=Math.imul(G,Ft),a=Math.imul(G,Ht),a=a+Math.imul(K,Ft)|0,g=Math.imul(K,Ht),m=m+Math.imul(R,Lt)|0,a=a+Math.imul(R,Ct)|0,a=a+Math.imul(C,Lt)|0,g=g+Math.imul(C,Ct)|0,m=m+Math.imul(ut,Nt)|0,a=a+Math.imul(ut,Ut)|0,a=a+Math.imul(_,Nt)|0,g=g+Math.imul(_,Ut)|0,m=m+Math.imul(j,qt)|0,a=a+Math.imul(j,Dt)|0,a=a+Math.imul(it,qt)|0,g=g+Math.imul(it,Dt)|0,m=m+Math.imul(k,Gt)|0,a=a+Math.imul(k,zt)|0,a=a+Math.imul(q,Gt)|0,g=g+Math.imul(q,zt)|0;var Yi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Yi>>>26)|0,Yi&=67108863,m=Math.imul(X,Ft),a=Math.imul(X,Ht),a=a+Math.imul(Q,Ft)|0,g=Math.imul(Q,Ht),m=m+Math.imul(G,Lt)|0,a=a+Math.imul(G,Ct)|0,a=a+Math.imul(K,Lt)|0,g=g+Math.imul(K,Ct)|0,m=m+Math.imul(R,Nt)|0,a=a+Math.imul(R,Ut)|0,a=a+Math.imul(C,Nt)|0,g=g+Math.imul(C,Ut)|0,m=m+Math.imul(ut,qt)|0,a=a+Math.imul(ut,Dt)|0,a=a+Math.imul(_,qt)|0,g=g+Math.imul(_,Dt)|0,m=m+Math.imul(j,Gt)|0,a=a+Math.imul(j,zt)|0,a=a+Math.imul(it,Gt)|0,g=g+Math.imul(it,zt)|0,m=m+Math.imul(k,Vt)|0,a=a+Math.imul(k,Kt)|0,a=a+Math.imul(q,Vt)|0,g=g+Math.imul(q,Kt)|0;var $i=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+($i>>>26)|0,$i&=67108863,m=Math.imul(vt,Ft),a=Math.imul(vt,Ht),a=a+Math.imul(st,Ft)|0,g=Math.imul(st,Ht),m=m+Math.imul(X,Lt)|0,a=a+Math.imul(X,Ct)|0,a=a+Math.imul(Q,Lt)|0,g=g+Math.imul(Q,Ct)|0,m=m+Math.imul(G,Nt)|0,a=a+Math.imul(G,Ut)|0,a=a+Math.imul(K,Nt)|0,g=g+Math.imul(K,Ut)|0,m=m+Math.imul(R,qt)|0,a=a+Math.imul(R,Dt)|0,a=a+Math.imul(C,qt)|0,g=g+Math.imul(C,Dt)|0,m=m+Math.imul(ut,Gt)|0,a=a+Math.imul(ut,zt)|0,a=a+Math.imul(_,Gt)|0,g=g+Math.imul(_,zt)|0,m=m+Math.imul(j,Vt)|0,a=a+Math.imul(j,Kt)|0,a=a+Math.imul(it,Vt)|0,g=g+Math.imul(it,Kt)|0,m=m+Math.imul(k,jt)|0,a=a+Math.imul(k,Yt)|0,a=a+Math.imul(q,jt)|0,g=g+Math.imul(q,Yt)|0;var Zi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Zi>>>26)|0,Zi&=67108863,m=Math.imul(ct,Ft),a=Math.imul(ct,Ht),a=a+Math.imul(ht,Ft)|0,g=Math.imul(ht,Ht),m=m+Math.imul(vt,Lt)|0,a=a+Math.imul(vt,Ct)|0,a=a+Math.imul(st,Lt)|0,g=g+Math.imul(st,Ct)|0,m=m+Math.imul(X,Nt)|0,a=a+Math.imul(X,Ut)|0,a=a+Math.imul(Q,Nt)|0,g=g+Math.imul(Q,Ut)|0,m=m+Math.imul(G,qt)|0,a=a+Math.imul(G,Dt)|0,a=a+Math.imul(K,qt)|0,g=g+Math.imul(K,Dt)|0,m=m+Math.imul(R,Gt)|0,a=a+Math.imul(R,zt)|0,a=a+Math.imul(C,Gt)|0,g=g+Math.imul(C,zt)|0,m=m+Math.imul(ut,Vt)|0,a=a+Math.imul(ut,Kt)|0,a=a+Math.imul(_,Vt)|0,g=g+Math.imul(_,Kt)|0,m=m+Math.imul(j,jt)|0,a=a+Math.imul(j,Yt)|0,a=a+Math.imul(it,jt)|0,g=g+Math.imul(it,Yt)|0,m=m+Math.imul(k,$t)|0,a=a+Math.imul(k,Zt)|0,a=a+Math.imul(q,$t)|0,g=g+Math.imul(q,Zt)|0;var Xi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Xi>>>26)|0,Xi&=67108863,m=Math.imul(Tt,Ft),a=Math.imul(Tt,Ht),a=a+Math.imul(Et,Ft)|0,g=Math.imul(Et,Ht),m=m+Math.imul(ct,Lt)|0,a=a+Math.imul(ct,Ct)|0,a=a+Math.imul(ht,Lt)|0,g=g+Math.imul(ht,Ct)|0,m=m+Math.imul(vt,Nt)|0,a=a+Math.imul(vt,Ut)|0,a=a+Math.imul(st,Nt)|0,g=g+Math.imul(st,Ut)|0,m=m+Math.imul(X,qt)|0,a=a+Math.imul(X,Dt)|0,a=a+Math.imul(Q,qt)|0,g=g+Math.imul(Q,Dt)|0,m=m+Math.imul(G,Gt)|0,a=a+Math.imul(G,zt)|0,a=a+Math.imul(K,Gt)|0,g=g+Math.imul(K,zt)|0,m=m+Math.imul(R,Vt)|0,a=a+Math.imul(R,Kt)|0,a=a+Math.imul(C,Vt)|0,g=g+Math.imul(C,Kt)|0,m=m+Math.imul(ut,jt)|0,a=a+Math.imul(ut,Yt)|0,a=a+Math.imul(_,jt)|0,g=g+Math.imul(_,Yt)|0,m=m+Math.imul(j,$t)|0,a=a+Math.imul(j,Zt)|0,a=a+Math.imul(it,$t)|0,g=g+Math.imul(it,Zt)|0,m=m+Math.imul(k,Xt)|0,a=a+Math.imul(k,Wt)|0,a=a+Math.imul(q,Xt)|0,g=g+Math.imul(q,Wt)|0;var Wi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Wi>>>26)|0,Wi&=67108863,m=Math.imul(Mt,Ft),a=Math.imul(Mt,Ht),a=a+Math.imul(kt,Ft)|0,g=Math.imul(kt,Ht),m=m+Math.imul(Tt,Lt)|0,a=a+Math.imul(Tt,Ct)|0,a=a+Math.imul(Et,Lt)|0,g=g+Math.imul(Et,Ct)|0,m=m+Math.imul(ct,Nt)|0,a=a+Math.imul(ct,Ut)|0,a=a+Math.imul(ht,Nt)|0,g=g+Math.imul(ht,Ut)|0,m=m+Math.imul(vt,qt)|0,a=a+Math.imul(vt,Dt)|0,a=a+Math.imul(st,qt)|0,g=g+Math.imul(st,Dt)|0,m=m+Math.imul(X,Gt)|0,a=a+Math.imul(X,zt)|0,a=a+Math.imul(Q,Gt)|0,g=g+Math.imul(Q,zt)|0,m=m+Math.imul(G,Vt)|0,a=a+Math.imul(G,Kt)|0,a=a+Math.imul(K,Vt)|0,g=g+Math.imul(K,Kt)|0,m=m+Math.imul(R,jt)|0,a=a+Math.imul(R,Yt)|0,a=a+Math.imul(C,jt)|0,g=g+Math.imul(C,Yt)|0,m=m+Math.imul(ut,$t)|0,a=a+Math.imul(ut,Zt)|0,a=a+Math.imul(_,$t)|0,g=g+Math.imul(_,Zt)|0,m=m+Math.imul(j,Xt)|0,a=a+Math.imul(j,Wt)|0,a=a+Math.imul(it,Xt)|0,g=g+Math.imul(it,Wt)|0,m=m+Math.imul(k,Qt)|0,a=a+Math.imul(k,Jt)|0,a=a+Math.imul(q,Qt)|0,g=g+Math.imul(q,Jt)|0;var Qi=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Qi>>>26)|0,Qi&=67108863,m=Math.imul(Mt,Lt),a=Math.imul(Mt,Ct),a=a+Math.imul(kt,Lt)|0,g=Math.imul(kt,Ct),m=m+Math.imul(Tt,Nt)|0,a=a+Math.imul(Tt,Ut)|0,a=a+Math.imul(Et,Nt)|0,g=g+Math.imul(Et,Ut)|0,m=m+Math.imul(ct,qt)|0,a=a+Math.imul(ct,Dt)|0,a=a+Math.imul(ht,qt)|0,g=g+Math.imul(ht,Dt)|0,m=m+Math.imul(vt,Gt)|0,a=a+Math.imul(vt,zt)|0,a=a+Math.imul(st,Gt)|0,g=g+Math.imul(st,zt)|0,m=m+Math.imul(X,Vt)|0,a=a+Math.imul(X,Kt)|0,a=a+Math.imul(Q,Vt)|0,g=g+Math.imul(Q,Kt)|0,m=m+Math.imul(G,jt)|0,a=a+Math.imul(G,Yt)|0,a=a+Math.imul(K,jt)|0,g=g+Math.imul(K,Yt)|0,m=m+Math.imul(R,$t)|0,a=a+Math.imul(R,Zt)|0,a=a+Math.imul(C,$t)|0,g=g+Math.imul(C,Zt)|0,m=m+Math.imul(ut,Xt)|0,a=a+Math.imul(ut,Wt)|0,a=a+Math.imul(_,Xt)|0,g=g+Math.imul(_,Wt)|0,m=m+Math.imul(j,Qt)|0,a=a+Math.imul(j,Jt)|0,a=a+Math.imul(it,Qt)|0,g=g+Math.imul(it,Jt)|0;var Ji=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(Ji>>>26)|0,Ji&=67108863,m=Math.imul(Mt,Nt),a=Math.imul(Mt,Ut),a=a+Math.imul(kt,Nt)|0,g=Math.imul(kt,Ut),m=m+Math.imul(Tt,qt)|0,a=a+Math.imul(Tt,Dt)|0,a=a+Math.imul(Et,qt)|0,g=g+Math.imul(Et,Dt)|0,m=m+Math.imul(ct,Gt)|0,a=a+Math.imul(ct,zt)|0,a=a+Math.imul(ht,Gt)|0,g=g+Math.imul(ht,zt)|0,m=m+Math.imul(vt,Vt)|0,a=a+Math.imul(vt,Kt)|0,a=a+Math.imul(st,Vt)|0,g=g+Math.imul(st,Kt)|0,m=m+Math.imul(X,jt)|0,a=a+Math.imul(X,Yt)|0,a=a+Math.imul(Q,jt)|0,g=g+Math.imul(Q,Yt)|0,m=m+Math.imul(G,$t)|0,a=a+Math.imul(G,Zt)|0,a=a+Math.imul(K,$t)|0,g=g+Math.imul(K,Zt)|0,m=m+Math.imul(R,Xt)|0,a=a+Math.imul(R,Wt)|0,a=a+Math.imul(C,Xt)|0,g=g+Math.imul(C,Wt)|0,m=m+Math.imul(ut,Qt)|0,a=a+Math.imul(ut,Jt)|0,a=a+Math.imul(_,Qt)|0,g=g+Math.imul(_,Jt)|0;var to=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(to>>>26)|0,to&=67108863,m=Math.imul(Mt,qt),a=Math.imul(Mt,Dt),a=a+Math.imul(kt,qt)|0,g=Math.imul(kt,Dt),m=m+Math.imul(Tt,Gt)|0,a=a+Math.imul(Tt,zt)|0,a=a+Math.imul(Et,Gt)|0,g=g+Math.imul(Et,zt)|0,m=m+Math.imul(ct,Vt)|0,a=a+Math.imul(ct,Kt)|0,a=a+Math.imul(ht,Vt)|0,g=g+Math.imul(ht,Kt)|0,m=m+Math.imul(vt,jt)|0,a=a+Math.imul(vt,Yt)|0,a=a+Math.imul(st,jt)|0,g=g+Math.imul(st,Yt)|0,m=m+Math.imul(X,$t)|0,a=a+Math.imul(X,Zt)|0,a=a+Math.imul(Q,$t)|0,g=g+Math.imul(Q,Zt)|0,m=m+Math.imul(G,Xt)|0,a=a+Math.imul(G,Wt)|0,a=a+Math.imul(K,Xt)|0,g=g+Math.imul(K,Wt)|0,m=m+Math.imul(R,Qt)|0,a=a+Math.imul(R,Jt)|0,a=a+Math.imul(C,Qt)|0,g=g+Math.imul(C,Jt)|0;var eo=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(eo>>>26)|0,eo&=67108863,m=Math.imul(Mt,Gt),a=Math.imul(Mt,zt),a=a+Math.imul(kt,Gt)|0,g=Math.imul(kt,zt),m=m+Math.imul(Tt,Vt)|0,a=a+Math.imul(Tt,Kt)|0,a=a+Math.imul(Et,Vt)|0,g=g+Math.imul(Et,Kt)|0,m=m+Math.imul(ct,jt)|0,a=a+Math.imul(ct,Yt)|0,a=a+Math.imul(ht,jt)|0,g=g+Math.imul(ht,Yt)|0,m=m+Math.imul(vt,$t)|0,a=a+Math.imul(vt,Zt)|0,a=a+Math.imul(st,$t)|0,g=g+Math.imul(st,Zt)|0,m=m+Math.imul(X,Xt)|0,a=a+Math.imul(X,Wt)|0,a=a+Math.imul(Q,Xt)|0,g=g+Math.imul(Q,Wt)|0,m=m+Math.imul(G,Qt)|0,a=a+Math.imul(G,Jt)|0,a=a+Math.imul(K,Qt)|0,g=g+Math.imul(K,Jt)|0;var ro=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(ro>>>26)|0,ro&=67108863,m=Math.imul(Mt,Vt),a=Math.imul(Mt,Kt),a=a+Math.imul(kt,Vt)|0,g=Math.imul(kt,Kt),m=m+Math.imul(Tt,jt)|0,a=a+Math.imul(Tt,Yt)|0,a=a+Math.imul(Et,jt)|0,g=g+Math.imul(Et,Yt)|0,m=m+Math.imul(ct,$t)|0,a=a+Math.imul(ct,Zt)|0,a=a+Math.imul(ht,$t)|0,g=g+Math.imul(ht,Zt)|0,m=m+Math.imul(vt,Xt)|0,a=a+Math.imul(vt,Wt)|0,a=a+Math.imul(st,Xt)|0,g=g+Math.imul(st,Wt)|0,m=m+Math.imul(X,Qt)|0,a=a+Math.imul(X,Jt)|0,a=a+Math.imul(Q,Qt)|0,g=g+Math.imul(Q,Jt)|0;var no=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(no>>>26)|0,no&=67108863,m=Math.imul(Mt,jt),a=Math.imul(Mt,Yt),a=a+Math.imul(kt,jt)|0,g=Math.imul(kt,Yt),m=m+Math.imul(Tt,$t)|0,a=a+Math.imul(Tt,Zt)|0,a=a+Math.imul(Et,$t)|0,g=g+Math.imul(Et,Zt)|0,m=m+Math.imul(ct,Xt)|0,a=a+Math.imul(ct,Wt)|0,a=a+Math.imul(ht,Xt)|0,g=g+Math.imul(ht,Wt)|0,m=m+Math.imul(vt,Qt)|0,a=a+Math.imul(vt,Jt)|0,a=a+Math.imul(st,Qt)|0,g=g+Math.imul(st,Jt)|0;var io=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(io>>>26)|0,io&=67108863,m=Math.imul(Mt,$t),a=Math.imul(Mt,Zt),a=a+Math.imul(kt,$t)|0,g=Math.imul(kt,Zt),m=m+Math.imul(Tt,Xt)|0,a=a+Math.imul(Tt,Wt)|0,a=a+Math.imul(Et,Xt)|0,g=g+Math.imul(Et,Wt)|0,m=m+Math.imul(ct,Qt)|0,a=a+Math.imul(ct,Jt)|0,a=a+Math.imul(ht,Qt)|0,g=g+Math.imul(ht,Jt)|0;var oo=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(oo>>>26)|0,oo&=67108863,m=Math.imul(Mt,Xt),a=Math.imul(Mt,Wt),a=a+Math.imul(kt,Xt)|0,g=Math.imul(kt,Wt),m=m+Math.imul(Tt,Qt)|0,a=a+Math.imul(Tt,Jt)|0,a=a+Math.imul(Et,Qt)|0,g=g+Math.imul(Et,Jt)|0;var so=(S+m|0)+((a&8191)<<13)|0;S=(g+(a>>>13)|0)+(so>>>26)|0,so&=67108863,m=Math.imul(Mt,Qt),a=Math.imul(Mt,Jt),a=a+Math.imul(kt,Qt)|0,g=Math.imul(kt,Jt);var ao=(S+m|0)+((a&8191)<<13)|0;return S=(g+(a>>>13)|0)+(ao>>>26)|0,ao&=67108863,w[0]=zi,w[1]=Vi,w[2]=Ki,w[3]=ji,w[4]=Yi,w[5]=$i,w[6]=Zi,w[7]=Xi,w[8]=Wi,w[9]=Qi,w[10]=Ji,w[11]=to,w[12]=eo,w[13]=ro,w[14]=no,w[15]=io,w[16]=oo,w[17]=so,w[18]=ao,S!==0&&(w[19]=S,f.length++),f};Math.imul||(T=O);function L(b,s,u){u.negative=s.negative^b.negative,u.length=b.length+s.length;for(var f=0,l=0,p=0;p<u.length-1;p++){var w=l;l=0;for(var S=f&67108863,m=Math.min(p,s.length-1),a=Math.max(0,p-b.length+1);a<=m;a++){var g=p-a,F=b.words[g]|0,k=s.words[a]|0,q=F*k,z=q&67108863;w=w+(q/67108864|0)|0,z=z+S|0,S=z&67108863,w=w+(z>>>26)|0,l+=w>>>26,w&=67108863}u.words[p]=S,f=w,w=l}return f!==0?u.words[p]=f:u.length--,u.strip()}function U(b,s,u){var f=new D;return f.mulp(b,s,u)}i.prototype.mulTo=function(s,u){var f,l=this.length+s.length;return this.length===10&&s.length===10?f=T(this,s,u):l<63?f=O(this,s,u):l<1024?f=L(this,s,u):f=U(this,s,u),f};function D(b,s){this.x=b,this.y=s}D.prototype.makeRBT=function(s){for(var u=new Array(s),f=i.prototype._countBits(s)-1,l=0;l<s;l++)u[l]=this.revBin(l,f,s);return u},D.prototype.revBin=function(s,u,f){if(s===0||s===f-1)return s;for(var l=0,p=0;p<u;p++)l|=(s&1)<<u-p-1,s>>=1;return l},D.prototype.permute=function(s,u,f,l,p,w){for(var S=0;S<w;S++)l[S]=u[s[S]],p[S]=f[s[S]]},D.prototype.transform=function(s,u,f,l,p,w){this.permute(w,s,u,f,l,p);for(var S=1;S<p;S<<=1)for(var m=S<<1,a=Math.cos(2*Math.PI/m),g=Math.sin(2*Math.PI/m),F=0;F<p;F+=m)for(var k=a,q=g,z=0;z<S;z++){var j=f[F+z],it=l[F+z],pt=f[F+z+S],ut=l[F+z+S],_=k*pt-q*ut;ut=k*ut+q*pt,pt=_,f[F+z]=j+pt,l[F+z]=it+ut,f[F+z+S]=j-pt,l[F+z+S]=it-ut,z!==m&&(_=a*k-g*q,q=a*q+g*k,k=_)}},D.prototype.guessLen13b=function(s,u){var f=Math.max(u,s)|1,l=f&1,p=0;for(f=f/2|0;f;f=f>>>1)p++;return 1<<p+1+l},D.prototype.conjugate=function(s,u,f){if(!(f<=1))for(var l=0;l<f/2;l++){var p=s[l];s[l]=s[f-l-1],s[f-l-1]=p,p=u[l],u[l]=-u[f-l-1],u[f-l-1]=-p}},D.prototype.normalize13b=function(s,u){for(var f=0,l=0;l<u/2;l++){var p=Math.round(s[2*l+1]/u)*8192+Math.round(s[2*l]/u)+f;s[l]=p&67108863,p<67108864?f=0:f=p/67108864|0}return s},D.prototype.convert13b=function(s,u,f,l){for(var p=0,w=0;w<u;w++)p=p+(s[w]|0),f[2*w]=p&8191,p=p>>>13,f[2*w+1]=p&8191,p=p>>>13;for(w=2*u;w<l;++w)f[w]=0;r(p===0),r((p&-8192)===0)},D.prototype.stub=function(s){for(var u=new Array(s),f=0;f<s;f++)u[f]=0;return u},D.prototype.mulp=function(s,u,f){var l=2*this.guessLen13b(s.length,u.length),p=this.makeRBT(l),w=this.stub(l),S=new Array(l),m=new Array(l),a=new Array(l),g=new Array(l),F=new Array(l),k=new Array(l),q=f.words;q.length=l,this.convert13b(s.words,s.length,S,l),this.convert13b(u.words,u.length,g,l),this.transform(S,w,m,a,l,p),this.transform(g,w,F,k,l,p);for(var z=0;z<l;z++){var j=m[z]*F[z]-a[z]*k[z];a[z]=m[z]*k[z]+a[z]*F[z],m[z]=j}return this.conjugate(m,a,l),this.transform(m,a,q,w,l,p),this.conjugate(q,w,l),this.normalize13b(q,l),f.negative=s.negative^u.negative,f.length=s.length+u.length,f.strip()},i.prototype.mul=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),this.mulTo(s,u)},i.prototype.mulf=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),U(this,s,u)},i.prototype.imul=function(s){return this.clone().mulTo(s,this)},i.prototype.imuln=function(s){r(typeof s=="number"),r(s<67108864);for(var u=0,f=0;f<this.length;f++){var l=(this.words[f]|0)*s,p=(l&67108863)+(u&67108863);u>>=26,u+=l/67108864|0,u+=p>>>26,this.words[f]=p&67108863}return u!==0&&(this.words[f]=u,this.length++),this.length=s===0?1:this.length,this},i.prototype.muln=function(s){return this.clone().imuln(s)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(s){var u=A(s);if(u.length===0)return new i(1);for(var f=this,l=0;l<u.length&&u[l]===0;l++,f=f.sqr());if(++l<u.length)for(var p=f.sqr();l<u.length;l++,p=p.sqr())u[l]!==0&&(f=f.mul(p));return f},i.prototype.iushln=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26,l=67108863>>>26-u<<26-u,p;if(u!==0){var w=0;for(p=0;p<this.length;p++){var S=this.words[p]&l,m=(this.words[p]|0)-S<<u;this.words[p]=m|w,w=S>>>26-u}w&&(this.words[p]=w,this.length++)}if(f!==0){for(p=this.length-1;p>=0;p--)this.words[p+f]=this.words[p];for(p=0;p<f;p++)this.words[p]=0;this.length+=f}return this.strip()},i.prototype.ishln=function(s){return r(this.negative===0),this.iushln(s)},i.prototype.iushrn=function(s,u,f){r(typeof s=="number"&&s>=0);var l;u?l=(u-u%26)/26:l=0;var p=s%26,w=Math.min((s-p)/26,this.length),S=67108863^67108863>>>p<<p,m=f;if(l-=w,l=Math.max(0,l),m){for(var a=0;a<w;a++)m.words[a]=this.words[a];m.length=w}if(w!==0)if(this.length>w)for(this.length-=w,a=0;a<this.length;a++)this.words[a]=this.words[a+w];else this.words[0]=0,this.length=1;var g=0;for(a=this.length-1;a>=0&&(g!==0||a>=l);a--){var F=this.words[a]|0;this.words[a]=g<<26-p|F>>>p,g=F&S}return m&&g!==0&&(m.words[m.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(s,u,f){return r(this.negative===0),this.iushrn(s,u,f)},i.prototype.shln=function(s){return this.clone().ishln(s)},i.prototype.ushln=function(s){return this.clone().iushln(s)},i.prototype.shrn=function(s){return this.clone().ishrn(s)},i.prototype.ushrn=function(s){return this.clone().iushrn(s)},i.prototype.testn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26,l=1<<u;if(this.length<=f)return!1;var p=this.words[f];return!!(p&l)},i.prototype.imaskn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,f=(s-u)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=f)return this;if(u!==0&&f++,this.length=Math.min(f,this.length),u!==0){var l=67108863^67108863>>>u<<u;this.words[this.length-1]&=l}return this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.maskn=function(s){return this.clone().imaskn(s)},i.prototype.iaddn=function(s){return r(typeof s=="number"),r(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},i.prototype._iaddn=function(s){this.words[0]+=s;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},i.prototype.isubn=function(s){if(r(typeof s=="number"),r(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this.strip()},i.prototype.addn=function(s){return this.clone().iaddn(s)},i.prototype.subn=function(s){return this.clone().isubn(s)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(s,u,f){var l=s.length+f,p;this._expand(l);var w,S=0;for(p=0;p<s.length;p++){w=(this.words[p+f]|0)+S;var m=(s.words[p]|0)*u;w-=m&67108863,S=(w>>26)-(m/67108864|0),this.words[p+f]=w&67108863}for(;p<this.length-f;p++)w=(this.words[p+f]|0)+S,S=w>>26,this.words[p+f]=w&67108863;if(S===0)return this.strip();for(r(S===-1),S=0,p=0;p<this.length;p++)w=-(this.words[p]|0)+S,S=w>>26,this.words[p]=w&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(s,u){var f=this.length-s.length,l=this.clone(),p=s,w=p.words[p.length-1]|0,S=this._countBits(w);f=26-S,f!==0&&(p=p.ushln(f),l.iushln(f),w=p.words[p.length-1]|0);var m=l.length-p.length,a;if(u!=="mod"){a=new i(null),a.length=m+1,a.words=new Array(a.length);for(var g=0;g<a.length;g++)a.words[g]=0}var F=l.clone()._ishlnsubmul(p,1,m);F.negative===0&&(l=F,a&&(a.words[m]=1));for(var k=m-1;k>=0;k--){var q=(l.words[p.length+k]|0)*67108864+(l.words[p.length+k-1]|0);for(q=Math.min(q/w|0,67108863),l._ishlnsubmul(p,q,k);l.negative!==0;)q--,l.negative=0,l._ishlnsubmul(p,1,k),l.isZero()||(l.negative^=1);a&&(a.words[k]=q)}return a&&a.strip(),l.strip(),u!=="div"&&f!==0&&l.iushrn(f),{div:a||null,mod:l}},i.prototype.divmod=function(s,u,f){if(r(!s.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var l,p,w;return this.negative!==0&&s.negative===0?(w=this.neg().divmod(s,u),u!=="mod"&&(l=w.div.neg()),u!=="div"&&(p=w.mod.neg(),f&&p.negative!==0&&p.iadd(s)),{div:l,mod:p}):this.negative===0&&s.negative!==0?(w=this.divmod(s.neg(),u),u!=="mod"&&(l=w.div.neg()),{div:l,mod:w.mod}):(this.negative&s.negative)!==0?(w=this.neg().divmod(s.neg(),u),u!=="div"&&(p=w.mod.neg(),f&&p.negative!==0&&p.isub(s)),{div:w.div,mod:p}):s.length>this.length||this.cmp(s)<0?{div:new i(0),mod:this}:s.length===1?u==="div"?{div:this.divn(s.words[0]),mod:null}:u==="mod"?{div:null,mod:new i(this.modn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new i(this.modn(s.words[0]))}:this._wordDiv(s,u)},i.prototype.div=function(s){return this.divmod(s,"div",!1).div},i.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},i.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},i.prototype.divRound=function(s){var u=this.divmod(s);if(u.mod.isZero())return u.div;var f=u.div.negative!==0?u.mod.isub(s):u.mod,l=s.ushrn(1),p=s.andln(1),w=f.cmp(l);return w<0||p===1&&w===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},i.prototype.modn=function(s){r(s<=67108863);for(var u=(1<<26)%s,f=0,l=this.length-1;l>=0;l--)f=(u*f+(this.words[l]|0))%s;return f},i.prototype.idivn=function(s){r(s<=67108863);for(var u=0,f=this.length-1;f>=0;f--){var l=(this.words[f]|0)+u*67108864;this.words[f]=l/s|0,u=l%s}return this.strip()},i.prototype.divn=function(s){return this.clone().idivn(s)},i.prototype.egcd=function(s){r(s.negative===0),r(!s.isZero());var u=this,f=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var l=new i(1),p=new i(0),w=new i(0),S=new i(1),m=0;u.isEven()&&f.isEven();)u.iushrn(1),f.iushrn(1),++m;for(var a=f.clone(),g=u.clone();!u.isZero();){for(var F=0,k=1;(u.words[0]&k)===0&&F<26;++F,k<<=1);if(F>0)for(u.iushrn(F);F-- >0;)(l.isOdd()||p.isOdd())&&(l.iadd(a),p.isub(g)),l.iushrn(1),p.iushrn(1);for(var q=0,z=1;(f.words[0]&z)===0&&q<26;++q,z<<=1);if(q>0)for(f.iushrn(q);q-- >0;)(w.isOdd()||S.isOdd())&&(w.iadd(a),S.isub(g)),w.iushrn(1),S.iushrn(1);u.cmp(f)>=0?(u.isub(f),l.isub(w),p.isub(S)):(f.isub(u),w.isub(l),S.isub(p))}return{a:w,b:S,gcd:f.iushln(m)}},i.prototype._invmp=function(s){r(s.negative===0),r(!s.isZero());var u=this,f=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var l=new i(1),p=new i(0),w=f.clone();u.cmpn(1)>0&&f.cmpn(1)>0;){for(var S=0,m=1;(u.words[0]&m)===0&&S<26;++S,m<<=1);if(S>0)for(u.iushrn(S);S-- >0;)l.isOdd()&&l.iadd(w),l.iushrn(1);for(var a=0,g=1;(f.words[0]&g)===0&&a<26;++a,g<<=1);if(a>0)for(f.iushrn(a);a-- >0;)p.isOdd()&&p.iadd(w),p.iushrn(1);u.cmp(f)>=0?(u.isub(f),l.isub(p)):(f.isub(u),p.isub(l))}var F;return u.cmpn(1)===0?F=l:F=p,F.cmpn(0)<0&&F.iadd(s),F},i.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var u=this.clone(),f=s.clone();u.negative=0,f.negative=0;for(var l=0;u.isEven()&&f.isEven();l++)u.iushrn(1),f.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;f.isEven();)f.iushrn(1);var p=u.cmp(f);if(p<0){var w=u;u=f,f=w}else if(p===0||f.cmpn(1)===0)break;u.isub(f)}while(!0);return f.iushln(l)},i.prototype.invm=function(s){return this.egcd(s).a.umod(s)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(s){return this.words[0]&s},i.prototype.bincn=function(s){r(typeof s=="number");var u=s%26,f=(s-u)/26,l=1<<u;if(this.length<=f)return this._expand(f+1),this.words[f]|=l,this;for(var p=l,w=f;p!==0&&w<this.length;w++){var S=this.words[w]|0;S+=p,p=S>>>26,S&=67108863,this.words[w]=S}return p!==0&&(this.words[w]=p,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(s){var u=s<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this.strip();var f;if(this.length>1)f=1;else{u&&(s=-s),r(s<=67108863,"Number is too big");var l=this.words[0]|0;f=l===s?0:l<s?-1:1}return this.negative!==0?-f|0:f},i.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var u=this.ucmp(s);return this.negative!==0?-u|0:u},i.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var u=0,f=this.length-1;f>=0;f--){var l=this.words[f]|0,p=s.words[f]|0;if(l!==p){l<p?u=-1:l>p&&(u=1);break}}return u},i.prototype.gtn=function(s){return this.cmpn(s)===1},i.prototype.gt=function(s){return this.cmp(s)===1},i.prototype.gten=function(s){return this.cmpn(s)>=0},i.prototype.gte=function(s){return this.cmp(s)>=0},i.prototype.ltn=function(s){return this.cmpn(s)===-1},i.prototype.lt=function(s){return this.cmp(s)===-1},i.prototype.lten=function(s){return this.cmpn(s)<=0},i.prototype.lte=function(s){return this.cmp(s)<=0},i.prototype.eqn=function(s){return this.cmpn(s)===0},i.prototype.eq=function(s){return this.cmp(s)===0},i.red=function(s){return new nt(s)},i.prototype.toRed=function(s){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(s){return this.red=s,this},i.prototype.forceRed=function(s){return r(!this.red,"Already a number in reduction context"),this._forceRed(s)},i.prototype.redAdd=function(s){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},i.prototype.redIAdd=function(s){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},i.prototype.redSub=function(s){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},i.prototype.redISub=function(s){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},i.prototype.redShl=function(s){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},i.prototype.redMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},i.prototype.redIMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(s){return r(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var et={k256:null,p224:null,p192:null,p25519:null};function J(b,s){this.name=b,this.p=new i(s,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}J.prototype._tmp=function(){var s=new i(null);return s.words=new Array(Math.ceil(this.n/13)),s},J.prototype.ireduce=function(s){var u=s,f;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),f=u.bitLength();while(f>this.n);var l=f<this.n?-1:u.ucmp(this.p);return l===0?(u.words[0]=0,u.length=1):l>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},J.prototype.split=function(s,u){s.iushrn(this.n,0,u)},J.prototype.imulK=function(s){return s.imul(this.k)};function Y(){J.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Y,J),Y.prototype.split=function(s,u){for(var f=4194303,l=Math.min(s.length,9),p=0;p<l;p++)u.words[p]=s.words[p];if(u.length=l,s.length<=9){s.words[0]=0,s.length=1;return}var w=s.words[9];for(u.words[u.length++]=w&f,p=10;p<s.length;p++){var S=s.words[p]|0;s.words[p-10]=(S&f)<<4|w>>>22,w=S}w>>>=22,s.words[p-10]=w,w===0&&s.length>10?s.length-=10:s.length-=9},Y.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var u=0,f=0;f<s.length;f++){var l=s.words[f]|0;u+=l*977,s.words[f]=u&67108863,u=l*64+(u/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function $(){J.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n($,J);function ft(){J.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(ft,J);function Pt(){J.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(Pt,J),Pt.prototype.imulK=function(s){for(var u=0,f=0;f<s.length;f++){var l=(s.words[f]|0)*19+u,p=l&67108863;l>>>=26,s.words[f]=p,u=l}return u!==0&&(s.words[s.length++]=u),s},i._prime=function(s){if(et[s])return et[s];var u;if(s==="k256")u=new Y;else if(s==="p224")u=new $;else if(s==="p192")u=new ft;else if(s==="p25519")u=new Pt;else throw new Error("Unknown prime "+s);return et[s]=u,u};function nt(b){if(typeof b=="string"){var s=i._prime(b);this.m=s.p,this.prime=s}else r(b.gtn(1),"modulus must be greater than 1"),this.m=b,this.prime=null}nt.prototype._verify1=function(s){r(s.negative===0,"red works only with positives"),r(s.red,"red works only with red numbers")},nt.prototype._verify2=function(s,u){r((s.negative|u.negative)===0,"red works only with positives"),r(s.red&&s.red===u.red,"red works only with red numbers")},nt.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):s.umod(this.m)._forceRed(this)},nt.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},nt.prototype.add=function(s,u){this._verify2(s,u);var f=s.add(u);return f.cmp(this.m)>=0&&f.isub(this.m),f._forceRed(this)},nt.prototype.iadd=function(s,u){this._verify2(s,u);var f=s.iadd(u);return f.cmp(this.m)>=0&&f.isub(this.m),f},nt.prototype.sub=function(s,u){this._verify2(s,u);var f=s.sub(u);return f.cmpn(0)<0&&f.iadd(this.m),f._forceRed(this)},nt.prototype.isub=function(s,u){this._verify2(s,u);var f=s.isub(u);return f.cmpn(0)<0&&f.iadd(this.m),f},nt.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},nt.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},nt.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},nt.prototype.isqr=function(s){return this.imul(s,s.clone())},nt.prototype.sqr=function(s){return this.mul(s,s)},nt.prototype.sqrt=function(s){if(s.isZero())return s.clone();var u=this.m.andln(3);if(r(u%2===1),u===3){var f=this.m.add(new i(1)).iushrn(2);return this.pow(s,f)}for(var l=this.m.subn(1),p=0;!l.isZero()&&l.andln(1)===0;)p++,l.iushrn(1);r(!l.isZero());var w=new i(1).toRed(this),S=w.redNeg(),m=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new i(2*a*a).toRed(this);this.pow(a,m).cmp(S)!==0;)a.redIAdd(S);for(var g=this.pow(a,l),F=this.pow(s,l.addn(1).iushrn(1)),k=this.pow(s,l),q=p;k.cmp(w)!==0;){for(var z=k,j=0;z.cmp(w)!==0;j++)z=z.redSqr();r(j<q);var it=this.pow(g,new i(1).iushln(q-j-1));F=F.redMul(it),g=it.redSqr(),k=k.redMul(g),q=j}return F},nt.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},nt.prototype.pow=function(s,u){if(u.isZero())return new i(1).toRed(this);if(u.cmpn(1)===0)return s.clone();var f=4,l=new Array(1<<f);l[0]=new i(1).toRed(this),l[1]=s;for(var p=2;p<l.length;p++)l[p]=this.mul(l[p-1],s);var w=l[0],S=0,m=0,a=u.bitLength()%26;for(a===0&&(a=26),p=u.length-1;p>=0;p--){for(var g=u.words[p],F=a-1;F>=0;F--){var k=g>>F&1;if(w!==l[0]&&(w=this.sqr(w)),k===0&&S===0){m=0;continue}S<<=1,S|=k,m++,!(m!==f&&(p!==0||F!==0))&&(w=this.mul(w,l[S]),m=0,S=0)}a=26}return w},nt.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},nt.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},i.mont=function(s){return new dt(s)};function dt(b){nt.call(this,b),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(dt,nt),dt.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},dt.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},dt.prototype.imul=function(s,u){if(s.isZero()||u.isZero())return s.words[0]=0,s.length=1,s;var f=s.imul(u),l=f.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=f.isub(l).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},dt.prototype.mul=function(s,u){if(s.isZero()||u.isZero())return new i(0)._forceRed(this);var f=s.mul(u),l=f.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),p=f.isub(l).iushrn(this.shift),w=p;return p.cmp(this.m)>=0?w=p.isub(this.m):p.cmpn(0)<0&&(w=p.iadd(this.m)),w._forceRed(this)},dt.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof No>"u"||No,gc)});var yc=Z((Mm,xc)=>{"use strict";I();function an(){}an.getRandomBuffer=function(t){return N.default.browser?an.getRandomBufferBrowser(t):an.getRandomBufferNode(t)};an.getRandomBufferNode=function(t){var e=se();return e.randomBytes(t)};an.getRandomBufferBrowser=function(t){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");var e;if(window.crypto&&window.crypto.getRandomValues)e=window.crypto;else if(window.msCrypto&&window.msCrypto.getRandomValues)e=window.msCrypto;else throw new Error("window.crypto.getRandomValues not available");var r=new Uint8Array(t);e.getRandomValues(r);var n=E.Buffer.from(r);return n};xc.exports=an});var cn=Z((km,wc)=>{"use strict";I();var Ol=yc(),Ot={};Ot.isArray=t=>Array.isArray(t);Ot.isNumber=t=>typeof t=="number";Ot.isObject=t=>t&&typeof t=="object";Ot.isString=t=>typeof t=="string";Ot.isUndefined=t=>typeof t>"u";Ot.isFunction=t=>typeof t=="function";Ot.isNull=t=>t===null;Ot.isDate=t=>t instanceof Date;Ot.extend=(t,e)=>Object.assign(t,e);Ot.noop=()=>{};Ot.every=(t,e)=>t.every(e||(r=>r));Ot.map=(t,e)=>Array.from(t).map(e||(r=>r));Ot.includes=(t,e)=>t.includes(e);Ot.each=(t,e)=>t.forEach(e);Ot.clone=t=>Object.assign({},t);Ot.pick=(t,e)=>{let r={};return e.forEach(n=>{typeof t[n]<"u"&&(r[n]=t[n])}),r};Ot.values=t=>Object.values(t);Ot.filter=(t,e)=>t.filter(e);Ot.reduce=(t,e,r)=>t.reduce(e,r);Ot.without=(t,e)=>t.filter(r=>r!==e);Ot.shuffle=t=>{let e=t.slice(0);for(let r=e.length-1;r>0;r--){let i=Ol.getRandomBuffer(4).readUInt32BE(0)/4294967296,o=Math.floor(i*(r+1));[e[r],e[o]]=[e[o],e[r]]}return e};Ot.difference=(t,e)=>t.filter(r=>!e.includes(r));Ot.findIndex=(t,e)=>t.findIndex(e);Ot.some=(t,e)=>t.some(e);Ot.range=t=>[...Array(t).keys()];wc.exports=Ot});var Sc=Z((Hm,bc)=>{"use strict";I();var Al="https://docs.moneybutton.com/";bc.exports=[{name:"InvalidB58Char",message:"Invalid Base58 character: {0} in {1}"},{name:"InvalidB58Checksum",message:"Invalid Base58 checksum for {0}"},{name:"InvalidNetwork",message:"Invalid version for network: got {0}"},{name:"InvalidState",message:"Invalid state: {0}"},{name:"NotImplemented",message:"Function {0} was not implemented yet"},{name:"InvalidNetworkArgument",message:'Invalid network: must be "livenet" or "testnet", got {0}'},{name:"InvalidArgument",message:function(){return"Invalid Argument"+(arguments[0]?": "+arguments[0]:"")+(arguments[1]?" Documentation: "+Al+arguments[1]:"")}},{name:"AbstractMethodInvoked",message:"Abstract Method Invocation: {0}"},{name:"InvalidArgumentType",message:function(){return"Invalid Argument for "+arguments[2]+", expected "+arguments[1]+" but got "+typeof arguments[0]}},{name:"Unit",message:"Internal Error on Unit {0}",errors:[{name:"UnknownCode",message:"Unrecognized unit code: {0}"},{name:"InvalidRate",message:"Invalid exchange rate: {0}"}]},{name:"MerkleBlock",message:"Internal Error on MerkleBlock {0}",errors:[{name:"InvalidMerkleTree",message:"This MerkleBlock contain an invalid Merkle Tree"}]},{name:"Transaction",message:"Internal Error on Transaction {0}",errors:[{name:"Input",message:"Internal Error on Input {0}",errors:[{name:"MissingScript",message:"Need a script to create an input"},{name:"UnsupportedScript",message:"Unsupported input script type: {0}"},{name:"MissingPreviousOutput",message:"No previous output information."}]},{name:"NeedMoreInfo",message:"{0}"},{name:"InvalidSorting",message:"The sorting function provided did not return the change output as one of the array elements"},{name:"InvalidOutputAmountSum",message:"{0}"},{name:"MissingSignatures",message:"Some inputs have not been fully signed"},{name:"InvalidIndex",message:"Invalid index: {0} is not between 0, {1}"},{name:"UnableToVerifySignature",message:"Unable to verify signature: {0}"},{name:"DustOutputs",message:"Dust amount detected in one output"},{name:"InvalidSatoshis",message:"Output satoshis are invalid"},{name:"FeeError",message:"Internal Error on Fee {0}",errors:[{name:"TooSmall",message:"Fee is too small: {0}"},{name:"TooLarge",message:"Fee is too large: {0}"},{name:"Different",message:"Unspent value is different from specified fee: {0}"}]},{name:"ChangeAddressMissing",message:"Change address is missing"},{name:"BlockHeightTooHigh",message:"Block Height can be at most 2^32 -1"},{name:"NLockTimeOutOfRange",message:"Block Height can only be between 0 and 499 999 999"},{name:"LockTimeTooEarly",message:"Lock Time can't be earlier than UNIX date 500 000 000"}]},{name:"Script",message:"Internal Error on Script {0}",errors:[{name:"UnrecognizedAddress",message:"Expected argument {0} to be an address"},{name:"CantDeriveAddress",message:"Can't derive address associated with script {0}, needs to be p2pkh in, p2pkh out, p2sh in, or p2sh out."},{name:"InvalidBuffer",message:"Invalid script buffer: can't parse valid script from given buffer {0}"}]},{name:"HDPrivateKey",message:"Internal Error on HDPrivateKey {0}",errors:[{name:"InvalidDerivationArgument",message:"Invalid derivation argument {0}, expected string, or number and boolean"},{name:"InvalidEntropyArgument",message:"Invalid entropy: must be an hexa string or binary buffer, got {0}",errors:[{name:"TooMuchEntropy",message:'Invalid entropy: more than 512 bits is non standard, got "{0}"'},{name:"NotEnoughEntropy",message:'Invalid entropy: at least 128 bits needed, got "{0}"'}]},{name:"InvalidLength",message:"Invalid length for xprivkey string in {0}"},{name:"InvalidPath",message:"Invalid derivation path: {0}"},{name:"UnrecognizedArgument",message:'Invalid argument: creating a HDPrivateKey requires a string, buffer, json or object, got "{0}"'}]},{name:"HDPublicKey",message:"Internal Error on HDPublicKey {0}",errors:[{name:"ArgumentIsPrivateExtended",message:"Argument is an extended private key: {0}"},{name:"InvalidDerivationArgument",message:"Invalid derivation argument: got {0}"},{name:"InvalidLength",message:'Invalid length for xpubkey: got "{0}"'},{name:"InvalidPath",message:'Invalid derivation path, it should look like: "m/1/100", got "{0}"'},{name:"InvalidIndexCantDeriveHardened",message:"Invalid argument: creating a hardened path requires an HDPrivateKey"},{name:"MustSupplyArgument",message:"Must supply an argument to create a HDPublicKey"},{name:"UnrecognizedArgument",message:"Invalid argument for creation, must be string, json, buffer, or object"}]}]});var Oc=Z((Cm,qo)=>{"use strict";I();var Uo=cn();function Il(t,e){return t.replace("{0}",e[0]).replace("{1}",e[1]).replace("{2}",e[2])}var Ec=function(t,e){var r=function(){if(Uo.isString(e.message))this.message=Il(e.message,arguments);else if(Uo.isFunction(e.message))this.message=e.message.apply(null,arguments);else throw new Error("Invalid error definition for "+e.name);this.stack=this.message+`
|
|
23
23
|
`+new Error().stack};return r.prototype=Object.create(t.prototype),r.prototype.name=t.prototype.name+e.name,t[e.name]=r,e.errors&&_c(r,e.errors),r},_c=function(t,e){Uo.each(e,function(r){Ec(t,r)})},Pl=function(t,e){return _c(t,e),t},un={};un.Error=function(){this.message="Internal error",this.stack=this.message+`
|
|
24
|
-
`+new Error().stack};un.Error.prototype=Object.create(Error.prototype);un.Error.prototype.name="bsv.Error";var Tl=Sc();Pl(un.Error,Tl);qo.exports=un.Error;qo.exports.extend=function(t){return Ec(un.Error,t)}});var hn=Z((Um,Ac)=>{"use strict";I();var Nn=Oc(),Bl=cn();Ac.exports={checkState:function(t,e){if(!t)throw new Nn.InvalidState(e)},checkArgument:function(t,e,r,n){if(!t)throw new Nn.InvalidArgument(e,r,n)},checkArgumentType:function(t,e,r){if(r=r||"(unknown name)",Bl.isString(e)){if(e==="Buffer"){var n=si();if(!n.Buffer.isBuffer(t))throw new Nn.InvalidArgumentType(t,e,r)}else if(typeof t!==e)throw new Nn.InvalidArgumentType(t,e,r)}else if(!(t instanceof e))throw new Nn.InvalidArgumentType(t,e.name,r)}}});var Cn=Z((Dm,Pc)=>{"use strict";I();var mt=vc(),Do=hn(),Ic=cn(),hi=function(t){for(var e=E.Buffer.alloc(t.length),r=0;r<t.length;r++)e[r]=t[t.length-1-r];return e};mt.Zero=new mt(0);mt.One=new mt(1);mt.Minus1=new mt(-1);mt.fromNumber=function(t){return Do.checkArgument(Ic.isNumber(t)),new mt(t)};mt.fromString=function(t,e){return Do.checkArgument(Ic.isString(t)),new mt(t,e)};mt.fromBuffer=function(t,e){typeof e<"u"&&e.endian==="little"&&(t=hi(t));var r=t.toString("hex"),n=new mt(r,16);return n};mt.fromSM=function(t,e){var r;if(t.length===0)return mt.fromBuffer(E.Buffer.from([0]));var n="big";return e&&(n=e.endian),n==="little"&&(t=hi(t)),t[0]&128?(t[0]=t[0]&127,r=mt.fromBuffer(t),r.neg().copy(r)):r=mt.fromBuffer(t),r};mt.prototype.toNumber=function(){return parseInt(this.toString(10),10)};mt.prototype.toBuffer=function(t){var e,r;if(t&&t.size){r=this.toString(16,2);var n=r.length/2;e=E.Buffer.from(r,"hex"),n===t.size||(n>t.size?e=mt.trim(e,n):n<t.size&&(e=mt.pad(e,n,t.size)))}else r=this.toString(16,2),e=E.Buffer.from(r,"hex");return typeof t<"u"&&t.endian==="little"&&(e=hi(e)),e};mt.prototype.toSMBigEndian=function(){var t;return this.cmp(mt.Zero)===-1?(t=this.neg().toBuffer(),t[0]&128?t=E.Buffer.concat([E.Buffer.from([128]),t]):t[0]=t[0]|128):(t=this.toBuffer(),t[0]&128&&(t=E.Buffer.concat([E.Buffer.from([0]),t]))),t.length===1&&t[0]===0&&(t=E.Buffer.from([])),t};mt.prototype.toSM=function(t){var e=t?t.endian:"big",r=this.toSMBigEndian();return e==="little"&&(r=hi(r)),r};mt.fromScriptNumBuffer=function(t,e,r){var n=r||4;if(Do.checkArgument(t.length<=n,new Error("script number overflow")),e&&t.length>0&&(t[t.length-1]&127)===0&&(t.length<=1||(t[t.length-2]&128)===0))throw new Error("non-minimally encoded script number");return mt.fromSM(t,{endian:"little"})};mt.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})};mt.trim=function(t,e){return t.slice(e-t.length,t.length)};mt.pad=function(t,e,r){for(var n=E.Buffer.alloc(r),i=0;i<t.length;i++)n[n.length-1-i]=t[t.length-1-i];for(i=0;i<r-e;i++)n[i]=0;return n};mt.prototype.toHex=function(...t){return this.toBuffer(...t).toString("hex")};mt.fromHex=function(t,...e){return mt.fromBuffer(E.Buffer.from(t,"hex"),...e)};Pc.exports=mt});var fn=Z((zm,Bc)=>{I();Bc.exports=Tc;function Tc(t,e){if(!t)throw new Error(e||"Assertion failed")}Tc.equal=function(e,r,n){if(e!=r)throw new Error(n||"Assertion failed: "+e+" != "+r)}});var Mc=Z((Km,Go)=>{I();typeof Object.create=="function"?Go.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:Go.exports=function(e,r){if(r){e.super_=r;var n=function(){};n.prototype=r.prototype,e.prototype=new n,e.prototype.constructor=e}}});var qe=Z(wt=>{"use strict";I();var Ml=fn(),Rl=Mc();wt.inherits=Rl;function kl(t,e){return(t.charCodeAt(e)&64512)!==55296||e<0||e+1>=t.length?!1:(t.charCodeAt(e+1)&64512)===56320}function Fl(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if(typeof t=="string")if(e){if(e==="hex")for(t=t.replace(/[^a-z0-9]+/ig,""),t.length%2!==0&&(t="0"+t),i=0;i<t.length;i+=2)r.push(parseInt(t[i]+t[i+1],16))}else for(var n=0,i=0;i<t.length;i++){var o=t.charCodeAt(i);o<128?r[n++]=o:o<2048?(r[n++]=o>>6|192,r[n++]=o&63|128):kl(t,i)?(o=65536+((o&1023)<<10)+(t.charCodeAt(++i)&1023),r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=o&63|128):(r[n++]=o>>12|224,r[n++]=o>>6&63|128,r[n++]=o&63|128)}else for(i=0;i<t.length;i++)r[i]=t[i]|0;return r}wt.toArray=Fl;function Hl(t){for(var e="",r=0;r<t.length;r++)e+=kc(t[r].toString(16));return e}wt.toHex=Hl;function Rc(t){var e=t>>>24|t>>>8&65280|t<<8&16711680|(t&255)<<24;return e>>>0}wt.htonl=Rc;function Ll(t,e){for(var r="",n=0;n<t.length;n++){var i=t[n];e==="little"&&(i=Rc(i)),r+=Fc(i.toString(16))}return r}wt.toHex32=Ll;function kc(t){return t.length===1?"0"+t:t}wt.zero2=kc;function Fc(t){return t.length===7?"0"+t:t.length===6?"00"+t:t.length===5?"000"+t:t.length===4?"0000"+t:t.length===3?"00000"+t:t.length===2?"000000"+t:t.length===1?"0000000"+t:t}wt.zero8=Fc;function Nl(t,e,r,n){var i=r-e;Ml(i%4===0);for(var o=new Array(i/4),c=0,h=e;c<o.length;c++,h+=4){var d;n==="big"?d=t[h]<<24|t[h+1]<<16|t[h+2]<<8|t[h+3]:d=t[h+3]<<24|t[h+2]<<16|t[h+1]<<8|t[h],o[c]=d>>>0}return o}wt.join32=Nl;function Cl(t,e){for(var r=new Array(t.length*4),n=0,i=0;n<t.length;n++,i+=4){var o=t[n];e==="big"?(r[i]=o>>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=o&255):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=o&255)}return r}wt.split32=Cl;function Ul(t,e){return t>>>e|t<<32-e}wt.rotr32=Ul;function ql(t,e){return t<<e|t>>>32-e}wt.rotl32=ql;function Dl(t,e){return t+e>>>0}wt.sum32=Dl;function Gl(t,e,r){return t+e+r>>>0}wt.sum32_3=Gl;function zl(t,e,r,n){return t+e+r+n>>>0}wt.sum32_4=zl;function Vl(t,e,r,n,i){return t+e+r+n+i>>>0}wt.sum32_5=Vl;function Kl(t,e,r,n){var i=t[e],o=t[e+1],c=n+o>>>0,h=(c<n?1:0)+r+i;t[e]=h>>>0,t[e+1]=c}wt.sum64=Kl;function jl(t,e,r,n){var i=e+n>>>0,o=(i<e?1:0)+t+r;return o>>>0}wt.sum64_hi=jl;function Yl(t,e,r,n){var i=e+n;return i>>>0}wt.sum64_lo=Yl;function $l(t,e,r,n,i,o,c,h){var d=0,x=e;x=x+n>>>0,d+=x<e?1:0,x=x+o>>>0,d+=x<o?1:0,x=x+h>>>0,d+=x<h?1:0;var v=t+r+i+c+d;return v>>>0}wt.sum64_4_hi=$l;function Zl(t,e,r,n,i,o,c,h){var d=e+n+o+h;return d>>>0}wt.sum64_4_lo=Zl;function Xl(t,e,r,n,i,o,c,h,d,x){var v=0,y=e;y=y+n>>>0,v+=y<e?1:0,y=y+o>>>0,v+=y<o?1:0,y=y+h>>>0,v+=y<h?1:0,y=y+x>>>0,v+=y<x?1:0;var A=t+r+i+c+d+v;return A>>>0}wt.sum64_5_hi=Xl;function Wl(t,e,r,n,i,o,c,h,d,x){var v=e+n+o+h+x;return v>>>0}wt.sum64_5_lo=Wl;function Ql(t,e,r){var n=e<<32-r|t>>>r;return n>>>0}wt.rotr64_hi=Ql;function Jl(t,e,r){var n=t<<32-r|e>>>r;return n>>>0}wt.rotr64_lo=Jl;function t0(t,e,r){return t>>>r}wt.shr64_hi=t0;function e0(t,e,r){var n=t<<32-r|e>>>r;return n>>>0}wt.shr64_lo=e0});var ln=Z(Lc=>{"use strict";I();var Hc=qe(),r0=fn();function fi(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}Lc.BlockHash=fi;fi.prototype.update=function(e,r){if(e=Hc.toArray(e,r),this.pending?this.pending=this.pending.concat(e):this.pending=e,this.pendingTotal+=e.length,this.pending.length>=this._delta8){e=this.pending;var n=e.length%this._delta8;this.pending=e.slice(e.length-n,e.length),this.pending.length===0&&(this.pending=null),e=Hc.join32(e,0,e.length-n,this.endian);for(var i=0;i<e.length;i+=this._delta32)this._update(e,i,i+this._delta32)}return this};fi.prototype.digest=function(e){return this.update(this._pad()),r0(this.pending===null),this._digest(e)};fi.prototype._pad=function(){var e=this.pendingTotal,r=this._delta8,n=r-(e+this.padLength)%r,i=new Array(n+this.padLength);i[0]=128;for(var o=1;o<n;o++)i[o]=0;if(e<<=3,this.endian==="big"){for(var c=8;c<this.padLength;c++)i[o++]=0;i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=e>>>24&255,i[o++]=e>>>16&255,i[o++]=e>>>8&255,i[o++]=e&255}else for(i[o++]=e&255,i[o++]=e>>>8&255,i[o++]=e>>>16&255,i[o++]=e>>>24&255,i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=0,c=8;c<this.padLength;c++)i[o++]=0;return i}});var zo=Z(mr=>{"use strict";I();var n0=qe(),We=n0.rotr32;function i0(t,e,r,n){if(t===0)return Nc(e,r,n);if(t===1||t===3)return Uc(e,r,n);if(t===2)return Cc(e,r,n)}mr.ft_1=i0;function Nc(t,e,r){return t&e^~t&r}mr.ch32=Nc;function Cc(t,e,r){return t&e^t&r^e&r}mr.maj32=Cc;function Uc(t,e,r){return t^e^r}mr.p32=Uc;function o0(t){return We(t,2)^We(t,13)^We(t,22)}mr.s0_256=o0;function s0(t){return We(t,6)^We(t,11)^We(t,25)}mr.s1_256=s0;function a0(t){return We(t,7)^We(t,18)^t>>>3}mr.g0_256=a0;function c0(t){return We(t,17)^We(t,19)^t>>>10}mr.g1_256=c0});var Gc=Z((Jm,Dc)=>{"use strict";I();var dn=qe(),u0=ln(),h0=zo(),Vo=dn.rotl32,Un=dn.sum32,f0=dn.sum32_5,l0=h0.ft_1,qc=u0.BlockHash,d0=[1518500249,1859775393,2400959708,3395469782];function Qe(){if(!(this instanceof Qe))return new Qe;qc.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}dn.inherits(Qe,qc);Dc.exports=Qe;Qe.blockSize=512;Qe.outSize=160;Qe.hmacStrength=80;Qe.padLength=64;Qe.prototype._update=function(e,r){for(var n=this.W,i=0;i<16;i++)n[i]=e[r+i];for(;i<n.length;i++)n[i]=Vo(n[i-3]^n[i-8]^n[i-14]^n[i-16],1);var o=this.h[0],c=this.h[1],h=this.h[2],d=this.h[3],x=this.h[4];for(i=0;i<n.length;i++){var v=~~(i/20),y=f0(Vo(o,5),l0(v,c,h,d),x,n[i],d0[v]);x=d,d=h,h=Vo(c,30),c=o,o=y}this.h[0]=Un(this.h[0],o),this.h[1]=Un(this.h[1],c),this.h[2]=Un(this.h[2],h),this.h[3]=Un(this.h[3],d),this.h[4]=Un(this.h[4],x)};Qe.prototype._digest=function(e){return e==="hex"?dn.toHex32(this.h,"big"):dn.split32(this.h,"big")}});var Ko=Z((eg,Vc)=>{"use strict";I();var pn=qe(),p0=ln(),mn=zo(),m0=fn(),De=pn.sum32,g0=pn.sum32_4,v0=pn.sum32_5,x0=mn.ch32,y0=mn.maj32,w0=mn.s0_256,b0=mn.s1_256,S0=mn.g0_256,E0=mn.g1_256,zc=p0.BlockHash,_0=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function Je(){if(!(this instanceof Je))return new Je;zc.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=_0,this.W=new Array(64)}pn.inherits(Je,zc);Vc.exports=Je;Je.blockSize=512;Je.outSize=256;Je.hmacStrength=192;Je.padLength=64;Je.prototype._update=function(e,r){for(var n=this.W,i=0;i<16;i++)n[i]=e[r+i];for(;i<n.length;i++)n[i]=g0(E0(n[i-2]),n[i-7],S0(n[i-15]),n[i-16]);var o=this.h[0],c=this.h[1],h=this.h[2],d=this.h[3],x=this.h[4],v=this.h[5],y=this.h[6],A=this.h[7];for(m0(this.k.length===n.length),i=0;i<n.length;i++){var O=v0(A,b0(x),x0(x,v,y),this.k[i],n[i]),T=De(w0(o),y0(o,c,h));A=y,y=v,v=x,x=De(d,O),d=h,h=c,c=o,o=De(O,T)}this.h[0]=De(this.h[0],o),this.h[1]=De(this.h[1],c),this.h[2]=De(this.h[2],h),this.h[3]=De(this.h[3],d),this.h[4]=De(this.h[4],x),this.h[5]=De(this.h[5],v),this.h[6]=De(this.h[6],y),this.h[7]=De(this.h[7],A)};Je.prototype._digest=function(e){return e==="hex"?pn.toHex32(this.h,"big"):pn.split32(this.h,"big")}});var Yc=Z((ng,jc)=>{"use strict";I();var jo=qe(),Kc=Ko();function gr(){if(!(this instanceof gr))return new gr;Kc.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}jo.inherits(gr,Kc);jc.exports=gr;gr.blockSize=512;gr.outSize=224;gr.hmacStrength=192;gr.padLength=64;gr.prototype._digest=function(e){return e==="hex"?jo.toHex32(this.h.slice(0,7),"big"):jo.split32(this.h.slice(0,7),"big")}});var Zo=Z((og,Wc)=>{"use strict";I();var _e=qe(),O0=ln(),A0=fn(),tr=_e.rotr64_hi,er=_e.rotr64_lo,$c=_e.shr64_hi,Zc=_e.shr64_lo,Tr=_e.sum64,Yo=_e.sum64_hi,$o=_e.sum64_lo,I0=_e.sum64_4_hi,P0=_e.sum64_4_lo,T0=_e.sum64_5_hi,B0=_e.sum64_5_lo,Xc=O0.BlockHash,M0=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function Ge(){if(!(this instanceof Ge))return new Ge;Xc.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=M0,this.W=new Array(160)}_e.inherits(Ge,Xc);Wc.exports=Ge;Ge.blockSize=1024;Ge.outSize=512;Ge.hmacStrength=192;Ge.padLength=128;Ge.prototype._prepareBlock=function(e,r){for(var n=this.W,i=0;i<32;i++)n[i]=e[r+i];for(;i<n.length;i+=2){var o=G0(n[i-4],n[i-3]),c=z0(n[i-4],n[i-3]),h=n[i-14],d=n[i-13],x=q0(n[i-30],n[i-29]),v=D0(n[i-30],n[i-29]),y=n[i-32],A=n[i-31];n[i]=I0(o,c,h,d,x,v,y,A),n[i+1]=P0(o,c,h,d,x,v,y,A)}};Ge.prototype._update=function(e,r){this._prepareBlock(e,r);var n=this.W,i=this.h[0],o=this.h[1],c=this.h[2],h=this.h[3],d=this.h[4],x=this.h[5],v=this.h[6],y=this.h[7],A=this.h[8],O=this.h[9],T=this.h[10],L=this.h[11],U=this.h[12],D=this.h[13],et=this.h[14],J=this.h[15];A0(this.k.length===n.length);for(var Y=0;Y<n.length;Y+=2){var $=et,ft=J,Pt=C0(A,O),nt=U0(A,O),dt=R0(A,O,T,L,U,D),b=k0(A,O,T,L,U,D),s=this.k[Y],u=this.k[Y+1],f=n[Y],l=n[Y+1],p=T0($,ft,Pt,nt,dt,b,s,u,f,l),w=B0($,ft,Pt,nt,dt,b,s,u,f,l);$=L0(i,o),ft=N0(i,o),Pt=F0(i,o,c,h,d,x),nt=H0(i,o,c,h,d,x);var S=Yo($,ft,Pt,nt),m=$o($,ft,Pt,nt);et=U,J=D,U=T,D=L,T=A,L=O,A=Yo(v,y,p,w),O=$o(y,y,p,w),v=d,y=x,d=c,x=h,c=i,h=o,i=Yo(p,w,S,m),o=$o(p,w,S,m)}Tr(this.h,0,i,o),Tr(this.h,2,c,h),Tr(this.h,4,d,x),Tr(this.h,6,v,y),Tr(this.h,8,A,O),Tr(this.h,10,T,L),Tr(this.h,12,U,D),Tr(this.h,14,et,J)};Ge.prototype._digest=function(e){return e==="hex"?_e.toHex32(this.h,"big"):_e.split32(this.h,"big")};function R0(t,e,r,n,i){var o=t&r^~t&i;return o<0&&(o+=4294967296),o}function k0(t,e,r,n,i,o){var c=e&n^~e&o;return c<0&&(c+=4294967296),c}function F0(t,e,r,n,i){var o=t&r^t&i^r&i;return o<0&&(o+=4294967296),o}function H0(t,e,r,n,i,o){var c=e&n^e&o^n&o;return c<0&&(c+=4294967296),c}function L0(t,e){var r=tr(t,e,28),n=tr(e,t,2),i=tr(e,t,7),o=r^n^i;return o<0&&(o+=4294967296),o}function N0(t,e){var r=er(t,e,28),n=er(e,t,2),i=er(e,t,7),o=r^n^i;return o<0&&(o+=4294967296),o}function C0(t,e){var r=tr(t,e,14),n=tr(t,e,18),i=tr(e,t,9),o=r^n^i;return o<0&&(o+=4294967296),o}function U0(t,e){var r=er(t,e,14),n=er(t,e,18),i=er(e,t,9),o=r^n^i;return o<0&&(o+=4294967296),o}function q0(t,e){var r=tr(t,e,1),n=tr(t,e,8),i=$c(t,e,7),o=r^n^i;return o<0&&(o+=4294967296),o}function D0(t,e){var r=er(t,e,1),n=er(t,e,8),i=Zc(t,e,7),o=r^n^i;return o<0&&(o+=4294967296),o}function G0(t,e){var r=tr(t,e,19),n=tr(e,t,29),i=$c(t,e,6),o=r^n^i;return o<0&&(o+=4294967296),o}function z0(t,e){var r=er(t,e,19),n=er(e,t,29),i=Zc(t,e,6),o=r^n^i;return o<0&&(o+=4294967296),o}});var tu=Z((ag,Jc)=>{"use strict";I();var Xo=qe(),Qc=Zo();function vr(){if(!(this instanceof vr))return new vr;Qc.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}Xo.inherits(vr,Qc);Jc.exports=vr;vr.blockSize=1024;vr.outSize=384;vr.hmacStrength=192;vr.padLength=128;vr.prototype._digest=function(e){return e==="hex"?Xo.toHex32(this.h.slice(0,12),"big"):Xo.split32(this.h.slice(0,12),"big")}});var eu=Z(gn=>{"use strict";I();gn.sha1=Gc();gn.sha224=Yc();gn.sha256=Ko();gn.sha384=tu();gn.sha512=Zo()});var au=Z(su=>{"use strict";I();var Nr=qe(),V0=ln(),li=Nr.rotl32,ru=Nr.sum32,qn=Nr.sum32_3,nu=Nr.sum32_4,ou=V0.BlockHash;function rr(){if(!(this instanceof rr))return new rr;ou.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}Nr.inherits(rr,ou);su.ripemd160=rr;rr.blockSize=512;rr.outSize=160;rr.hmacStrength=192;rr.padLength=64;rr.prototype._update=function(e,r){for(var n=this.h[0],i=this.h[1],o=this.h[2],c=this.h[3],h=this.h[4],d=n,x=i,v=o,y=c,A=h,O=0;O<80;O++){var T=ru(li(nu(n,iu(O,i,o,c),e[Y0[O]+r],K0(O)),Z0[O]),h);n=h,h=c,c=li(o,10),o=i,i=T,T=ru(li(nu(d,iu(79-O,x,v,y),e[$0[O]+r],j0(O)),X0[O]),A),d=A,A=y,y=li(v,10),v=x,x=T}T=qn(this.h[1],o,y),this.h[1]=qn(this.h[2],c,A),this.h[2]=qn(this.h[3],h,d),this.h[3]=qn(this.h[4],n,x),this.h[4]=qn(this.h[0],i,v),this.h[0]=T};rr.prototype._digest=function(e){return e==="hex"?Nr.toHex32(this.h,"little"):Nr.split32(this.h,"little")};function iu(t,e,r,n){return t<=15?e^r^n:t<=31?e&r|~e&n:t<=47?(e|~r)^n:t<=63?e&n|r&~n:e^(r|~n)}function K0(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function j0(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}var Y0=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],$0=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Z0=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],X0=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]});var uu=Z((dg,cu)=>{"use strict";I();var W0=qe(),Q0=fn();function vn(t,e,r){if(!(this instanceof vn))return new vn(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(W0.toArray(e,r))}cu.exports=vn;vn.prototype._init=function(e){e.length>this.blockSize&&(e=new this.Hash().update(e).digest()),Q0(e.length<=this.blockSize);for(var r=e.length;r<this.blockSize;r++)e.push(0);for(r=0;r<e.length;r++)e[r]^=54;for(this.inner=new this.Hash().update(e),r=0;r<e.length;r++)e[r]^=106;this.outer=new this.Hash().update(e)};vn.prototype.update=function(e,r){return this.inner.update(e,r),this};vn.prototype.digest=function(e){return this.outer.update(this.inner.digest()),this.outer.digest(e)}});var fu=Z(hu=>{I();var me=hu;me.utils=qe();me.common=ln();me.sha=eu();me.ripemd=au();me.hmac=uu();me.sha1=me.sha.sha1;me.sha256=me.sha.sha256;me.sha224=me.sha.sha224;me.sha384=me.sha.sha384;me.sha512=me.sha.sha512;me.ripemd160=me.ripemd.ripemd160});var du=Z((vg,lu)=>{"use strict";I();var di=fu(),xr=hn(),te=lu.exports;te.sha1=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha1().update(t).digest("hex"),"hex")};te.sha1.blocksize=512;te.sha256=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha256().update(t).digest("hex"),"hex")};te.sha256.blocksize=512;te.sha256sha256=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),te.sha256(te.sha256(t))};te.ripemd160=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.ripemd160().update(t).digest("hex"),"hex")};te.sha256ripemd160=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),te.ripemd160(te.sha256(t))};te.sha512=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha512().update(t).digest("hex"),"hex")};te.sha512.blocksize=1024;te.hmac=function(t,e,r){xr.checkArgument(E.Buffer.isBuffer(e)),xr.checkArgument(E.Buffer.isBuffer(r)),xr.checkArgument(t.blocksize);var n=t.blocksize/8;if(r.length>n)r=t(r);else if(r.length<n){var i=E.Buffer.alloc(n);i.fill(0),r.copy(i),r=i}var o=E.Buffer.alloc(n);o.fill(92);var c=E.Buffer.alloc(n);c.fill(54);for(var h=E.Buffer.alloc(n),d=E.Buffer.alloc(n),x=0;x<n;x++)h[x]=o[x]^r[x],d[x]=c[x]^r[x];return t(E.Buffer.concat([h,t(E.Buffer.concat([d,e]))]))};te.sha256hmac=function(t,e){return te.hmac(te.sha256,t,e)};te.sha512hmac=function(t,e){return te.hmac(te.sha512,t,e)}});var mu=Z((yg,pu)=>{"use strict";I();var pi=se(),yr=hn(),ee=pu.exports;ee.sha1=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha1").update(t).digest()};ee.sha1.blocksize=512;ee.sha256=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha256").update(t).digest()};ee.sha256.blocksize=512;ee.sha256sha256=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),ee.sha256(ee.sha256(t))};ee.ripemd160=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("ripemd160").update(t).digest()};ee.sha256ripemd160=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),ee.ripemd160(ee.sha256(t))};ee.sha512=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha512").update(t).digest()};ee.sha512.blocksize=1024;ee.hmac=function(t,e,r){yr.checkArgument(E.Buffer.isBuffer(e)),yr.checkArgument(E.Buffer.isBuffer(r)),yr.checkArgument(t.blocksize);var n=t.blocksize/8;if(r.length>n)r=t(r);else if(r.length<n){var i=E.Buffer.alloc(n);i.fill(0),r.copy(i),r=i}var o=E.Buffer.alloc(n);o.fill(92);var c=E.Buffer.alloc(n);c.fill(54);for(var h=E.Buffer.alloc(n),d=E.Buffer.alloc(n),x=0;x<n;x++)h[x]=o[x]^r[x],d[x]=c[x]^r[x];return t(E.Buffer.concat([h,t(E.Buffer.concat([d,e]))]))};ee.sha256hmac=function(t,e){return ee.hmac(ee.sha256,t,e)};ee.sha512hmac=function(t,e){return ee.hmac(ee.sha512,t,e)}});var Dn=Z((bg,Wo)=>{I();C.default.browser?Wo.exports=du():Wo.exports=mu()});var yu=Z((Eg,xu)=>{"use strict";I();var vu=cn(),J0=hn(),gu=function(e){return vu.isString(e)?/^[0-9a-fA-F]+$/.test(e):!1};xu.exports={isValidJSON:function(e){var r;if(!vu.isString(e))return!1;try{r=JSON.parse(e)}catch{return!1}return typeof r=="object"},isHexa:gu,isHexaString:gu,defineImmutable:function(e,r){return Object.keys(r).forEach(function(n){Object.defineProperty(e,n,{configurable:!1,enumerable:!0,value:r[n]})}),e},isNaturalNumber:function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e&&e>=0},integerAsBuffer:function(e){J0.checkArgumentType(e,"number","integer");let r=E.Buffer.allocUnsafe(4);return r.writeUInt32BE(e,0),r}}});function Qo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Br(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function nr(t,e,r=""){let n=Qo(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let c=r&&`"${r}" `,h=o?` of length ${e}`:"",d=n?`length=${i}`:`type=${typeof t}`,x=c+"expected Uint8Array"+h+", got "+d;throw n?new RangeError(x):new TypeError(x)}return t}function mi(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Br(t.outputLen),Br(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function xn(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function gi(t,e){nr(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Cr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vi(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ze(t,e){return t<<32-e|t>>>e}function xi(t){if(nr(t),bu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=td[t[r]];return e}function wu(t){if(t>=wr._0&&t<=wr._9)return t-wr._0;if(t>=wr.A&&t<=wr.F)return t-(wr.A-10);if(t>=wr.a&&t<=wr.f)return t-(wr.a-10)}function Jo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(bu)try{return Uint8Array.fromHex(t)}catch(i){throw i instanceof SyntaxError?new RangeError(i.message):i}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let c=wu(t.charCodeAt(o)),h=wu(t.charCodeAt(o+1));if(c===void 0||h===void 0){let d=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+d+'" at index '+o)}n[i]=c*16+h}return n}function br(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Su(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];nr(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}function Eu(t,e={}){let r=(i,o)=>t(o).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function Gn(t=32){Br(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var bu,td,wr,_u,Mr=Ae(()=>{I();bu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",td=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));wr={_0:48,_9:57,A:65,F:70,a:97,f:102};_u=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Ou(t,e,r){return t&e^~t&r}function Au(t,e,r){return t&e^t&r^e&r}var yi,Sr,Iu=Ae(()=>{I();Mr();yi=class{constructor(e,r,n,i){W(this,"blockLen");W(this,"outputLen");W(this,"canXOF",!1);W(this,"padOffset");W(this,"isLE");W(this,"buffer");W(this,"view");W(this,"finished",!1);W(this,"length",0);W(this,"pos",0);W(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=vi(this.buffer)}update(e){xn(this),nr(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let c=0;c<o;){let h=Math.min(i-this.pos,o-c);if(h===i){let d=vi(e);for(;i<=o-c;c+=i)this.process(d,c);continue}n.set(e.subarray(c,c+h),this.pos),this.pos+=h,c+=h,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){xn(this),gi(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:c}=this;r[c++]=128,Cr(this.buffer.subarray(c)),this.padOffset>i-c&&(this.process(n,0),c=0);for(let y=c;y<i;y++)r[y]=0;n.setBigUint64(i-8,BigInt(this.length*8),o),this.process(n,0);let h=vi(e),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let x=d/4,v=this.get();if(x>v.length)throw new Error("_sha2: outputLen bigger than state");for(let y=0;y<x;y++)h.setUint32(4*y,v[y],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:c,pos:h}=this;return e.destroyed=c,e.finished=o,e.length=i,e.pos=h,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Sr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225])});var ed,Rr,ts,es,Ur,Pu=Ae(()=>{I();Iu();Mr();ed=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Rr=new Uint32Array(64),ts=class extends yi{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:o,F:c,G:h,H:d}=this;return[e,r,n,i,o,c,h,d]}set(e,r,n,i,o,c,h,d){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=c|0,this.G=h|0,this.H=d|0}process(e,r){for(let y=0;y<16;y++,r+=4)Rr[y]=e.getUint32(r,!1);for(let y=16;y<64;y++){let A=Rr[y-15],O=Rr[y-2],T=ze(A,7)^ze(A,18)^A>>>3,L=ze(O,17)^ze(O,19)^O>>>10;Rr[y]=L+Rr[y-7]+T+Rr[y-16]|0}let{A:n,B:i,C:o,D:c,E:h,F:d,G:x,H:v}=this;for(let y=0;y<64;y++){let A=ze(h,6)^ze(h,11)^ze(h,25),O=v+A+Ou(h,d,x)+ed[y]+Rr[y]|0,L=(ze(n,2)^ze(n,13)^ze(n,22))+Au(n,i,o)|0;v=x,x=d,d=h,h=c+O|0,c=o,o=i,i=n,n=O+L|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,c=c+this.D|0,h=h+this.E|0,d=d+this.F|0,x=x+this.G|0,v=v+this.H|0,this.set(n,i,o,c,h,d,x,v)}roundClean(){Cr(Rr)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Cr(this.buffer)}},es=class extends ts{constructor(){super(32);W(this,"A",Sr[0]|0);W(this,"B",Sr[1]|0);W(this,"C",Sr[2]|0);W(this,"D",Sr[3]|0);W(this,"E",Sr[4]|0);W(this,"F",Sr[5]|0);W(this,"G",Sr[6]|0);W(this,"H",Sr[7]|0)}},Ur=Eu(()=>new es,_u(1))});function Dr(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Si(t){if(typeof t=="bigint"){if(!wi(t))throw new RangeError("positive bigint expected, got "+t)}else ns(t);return t}function Fe(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function zn(t){let e=Si(t).toString(16);return e.length&1?"0"+e:e}function Tu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?bi:BigInt("0x"+t)}function ye(t){return Tu(xi(t))}function wn(t){return Tu(xi(_i(nr(t)).reverse()))}function Ei(t,e){if(Br(e),e===0)throw new RangeError("zero length");t=Si(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Jo(r.padStart(e*2,"0"))}function is(t,e){return Ei(t,e).reverse()}function _i(t){return Uint8Array.from(yt(t))}function bn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}function rd(t,e,r){return wi(t)&&wi(e)&&wi(r)&&e<=t&&t<r}function os(t,e,r,n){if(!rd(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Gr(t){if(t<bi)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>bi;t>>=rs,e+=1);return e}function Bu(t,e,r){if(Br(t,"hashLen"),Br(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=U=>new Uint8Array(U),i=Uint8Array.of(),o=Uint8Array.of(0),c=Uint8Array.of(1),h=1e3,d=n(t),x=n(t),v=0,y=()=>{d.fill(1),x.fill(0),v=0},A=(...U)=>r(x,gt(d,...U)),O=(U=i)=>{x=A(o,U),d=A(),U.length!==0&&(x=A(c,U),d=A())},T=()=>{if(v++>=h)throw new Error("drbg: tried max amount of iterations");let U=0,D=[];for(;U<e;){d=A();let et=d.slice();D.push(et),U+=d.length}return gt(...D)};return(U,D)=>{y(),O(U);let et;for(;(et=D(T()))===void 0;)O();return y(),et}}function He(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(o,c,h){if(!h&&c!=="function"&&!Object.hasOwn(t,o))throw new TypeError(`param "${o}" is invalid: expected own property`);let d=t[o];if(h&&d===void 0)return;let x=typeof d;if(x!==c||d===null)throw new TypeError(`param "${o}" is invalid: expected ${c}, got ${x}`)}let i=(o,c)=>Object.entries(o).forEach(([h,d])=>n(h,d,c));i(e,!1),i(r,!0)}var yt,ns,Er,gt,yn,qr,Oe,bi,rs,wi,Sn,zr=Ae(()=>{I();Mr();yt=(t,e,r)=>nr(t,e,r),ns=Br,Er=xi,gt=(...t)=>Su(...t),yn=t=>Jo(t),qr=Qo,Oe=t=>Gn(t),bi=BigInt(0),rs=BigInt(1);wi=t=>typeof t=="bigint"&&bi<=t;Sn=t=>(rs<<BigInt(t))-rs});function Me(t,e){if(e<=ge)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ge?r:e+r}function Re(t,e,r){if(e<ge)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ge;)n*=n,n%=r;return n}function Mu(t,e){if(t===ge)throw new Error("invert: expected non-zero number");if(e<=ge)throw new Error("invert: expected positive modulus, got "+e);let r=Me(t,e),n=e,i=ge,o=re,c=re,h=ge;for(;r!==ge;){let x=n/r,v=n-r*x,y=i-c*x,A=o-h*x;n=r,r=v,i=c,o=h,c=y,h=A}if(n!==re)throw new Error("invert: does not exist");return Me(i,e)}function as(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Cu(t,e){let r=t,n=(r.ORDER+re)/Fu,i=r.pow(e,n);return as(r,i,e),i}function od(t,e){let r=t,n=(r.ORDER-Hu)/Lu,i=r.mul(e,Vr),o=r.pow(i,n),c=r.mul(e,o),h=r.mul(r.mul(c,Vr),o),d=r.mul(c,r.sub(h,r.ONE));return as(r,d,e),d}function sd(t){let e=En(t),r=Uu(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),c=(t+nd)/Nu;return((h,d)=>{let x=h,v=x.pow(d,c),y=x.mul(v,n),A=x.mul(v,i),O=x.mul(v,o),T=x.eql(x.sqr(y),d),L=x.eql(x.sqr(A),d);v=x.cmov(v,y,T),y=x.cmov(O,A,L);let U=x.eql(x.sqr(y),d),D=x.cmov(v,y,U);return as(x,D,d),D})}function Uu(t){if(t<ku)throw new Error("sqrt is not defined for small field");let e=t-re,r=0;for(;e%Vr===ge;)e/=Vr,r++;let n=Vr,i=En(t);for(;ss(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Cu;let o=i.pow(n,e),c=(e+re)/Vr;return function(d,x){let v=d;if(v.is0(x))return x;if(ss(v,x)!==1)throw new Error("Cannot find square root");let y=r,A=v.mul(v.ONE,o),O=v.pow(x,e),T=v.pow(x,c);for(;!v.eql(O,v.ONE);){if(v.is0(O))return v.ZERO;let L=1,U=v.sqr(O);for(;!v.eql(U,v.ONE);)if(L++,U=v.sqr(U),L===y)throw new Error("Cannot find square root");let D=re<<BigInt(y-L-1),et=v.pow(A,D);y=L,A=v.sqr(et),O=v.mul(O,A),T=v.mul(T,et)}return T}}function ad(t){return t%Fu===ku?Cu:t%Lu===Hu?od:t%Nu===id?sd(t):Uu(t)}function Kr(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=cd.reduce((n,i)=>(n[i]="function",n),e);if(He(t,r),Fe(t.BYTES,"BYTES"),Fe(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=re)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ud(t,e,r){let n=t;if(r<ge)throw new Error("invalid exponent, negatives unsupported");if(r===ge)return n.ONE;if(r===re)return e;let i=n.ONE,o=e;for(;r>ge;)r&re&&(i=n.mul(i,o)),o=n.sqr(o),r>>=re;return i}function jr(t,e,r=!1){let n=t,i=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((h,d,x)=>n.is0(d)?h:(i[x]=h,n.mul(h,d)),n.ONE),c=n.inv(o);return e.reduceRight((h,d,x)=>n.is0(d)?h:(i[x]=n.mul(h,i[x]),n.mul(h,d)),c),i}function ss(t,e){let r=t,n=(r.ORDER-re)/Vr,i=r.pow(e,n),o=r.eql(i,r.ONE),c=r.eql(i,r.ZERO),h=r.eql(i,r.neg(r.ONE));if(!o&&!c&&!h)throw new Error("invalid Legendre symbol result");return o?1:c?0:-1}function cs(t,e){return ss(t,e)!==-1}function hd(t,e){if(e!==void 0&&ns(e),t<=ge)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Gr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,i=Math.ceil(n/8);return{nBitLength:n,nByteLength:i}}function En(t,e={}){return new Oi(t,e)}function qu(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=re)throw new Error("field order must be greater than 1");let e=Gr(t-re);return Math.ceil(e/8)}function Vn(t){let e=qu(t);return e+Math.ceil(e/2)}function _n(t,e,r=!1){yt(t);let n=t.length,i=qu(e),o=Math.max(Vn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let c=r?wn(t):ye(t),h=Me(c,e-re)+re;return r?is(h,i):Ei(h,i)}var ge,re,Vr,ku,Fu,Hu,nd,Lu,id,Nu,cd,Ru,Oi,On=Ae(()=>{I();zr();ge=BigInt(0),re=BigInt(1),Vr=BigInt(2),ku=BigInt(3),Fu=BigInt(4),Hu=BigInt(5),nd=BigInt(7),Lu=BigInt(8),id=BigInt(9),Nu=BigInt(16);cd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];Ru=new WeakMap,Oi=class{constructor(e,r={}){W(this,"ORDER");W(this,"BITS");W(this,"BYTES");W(this,"isLE");W(this,"ZERO",ge);W(this,"ONE",re);W(this,"_lengths");W(this,"_mod");if(e<=re)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:o}=hd(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=o,Object.freeze(this)}create(e){return Me(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ge<=e&&e<this.ORDER}is0(e){return e===ge}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&re)===re}neg(e){return Me(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Me(e*e,this.ORDER)}add(e,r){return Me(e+r,this.ORDER)}sub(e,r){return Me(e-r,this.ORDER)}mul(e,r){return Me(e*r,this.ORDER)}pow(e,r){return ud(this,e,r)}div(e,r){return Me(e*Mu(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Mu(e,this.ORDER)}sqrt(e){let r=Ru.get(this);return r||Ru.set(this,r=ad(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?is(e,this.BYTES):Ei(e,this.BYTES)}fromBytes(e,r=!1){yt(e);let{_lengths:n,BYTES:i,isLE:o,ORDER:c,_mod:h}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let x=new Uint8Array(i);x.set(e,o?0:x.length-e.length),e=x}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let d=o?wn(e):ye(e);if(h&&(d=Me(d,c)),!r&&!this.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d}invertBatch(e){return jr(this,e)}cmov(e,r,n){return Dr(n,"condition"),n?r:e}};Object.freeze(Oi.prototype)});function Vu(t){let e=t;if(typeof e!="function")throw new TypeError("Point must be a constructor");He({Fp:e.Fp,Fn:e.Fn,fromAffine:e.fromAffine,fromBytes:e.fromBytes,fromHex:e.fromHex},{Fp:"object",Fn:"object",fromAffine:"function",fromBytes:"function",fromHex:"function"}),Kr(e.Fp),Kr(e.Fn)}function Kn(t,e){let r=e.negate();return t?r:e}function ls(t,e){let r=jr(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Ku(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function us(t,e){Ku(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=Sn(t),c=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:c}}function Du(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:c}=r,h=Number(t&i),d=t>>c;h>n&&(h-=o,d+=Yr);let x=e*n,v=x+Math.abs(h)-1,y=h===0,A=h<0,O=e%2!==0;return{nextN:d,offset:v,isZero:y,isNeg:A,isNegF:O,offsetF:x}}function fd(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ld(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}function fs(t){return ju.get(t)||1}function Gu(t){if(t!==An)throw new Error("invalid wNAF")}function Yu(t,e,r,n){let i=e,o=t.ZERO,c=t.ZERO;for(;r>An||n>An;)r&Yr&&(o=o.add(i)),n&Yr&&(c=c.add(i)),i=i.double(),r>>=Yr,n>>=Yr;return{p1:o,p2:c}}function $u(t,e,r){let n=t.Fn;fd(e,t),ld(r,n);let i=e.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let c=t.ZERO,h=Gr(BigInt(i)),d=1;h>12?d=h-3:h>4?d=h-2:h>0&&(d=2);let x=Sn(d),v=new Array(Number(x)+1).fill(c),y=Math.floor((n.BITS-1)/d)*d,A=c;for(let O=y;O>=0;O-=d){v.fill(c);for(let L=0;L<o;L++){let U=r[L],D=Number(U>>BigInt(O)&x);v[D]=v[D].add(e[L])}let T=c;for(let L=v.length-1,U=c;L>0;L--)U=U.add(v[L]),T=T.add(U);if(A=A.add(T),O!==0)for(let L=0;L<d;L++)A=A.double()}return A}function zu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Kr(e),e}else return En(t,{isLE:r})}function Zu(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let d of["p","n","h"]){let x=e[d];if(!(typeof x=="bigint"&&x>An))throw new Error(`CURVE.${d} must be positive bigint`)}let i=zu(e.p,r.Fp,n),o=zu(e.n,r.Fn,n),h=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let d of h)if(!i.isValid(e[d]))throw new Error(`CURVE.${d} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}function Ii(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}var An,Yr,hs,ju,Ai,Pi=Ae(()=>{I();zr();On();An=BigInt(0),Yr=BigInt(1);hs=new WeakMap,ju=new WeakMap;Ai=class{constructor(e,r){W(this,"BASE");W(this,"ZERO");W(this,"Fn");W(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>An;)r&Yr&&(n=n.add(i)),i=i.double(),r>>=Yr;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=us(r,this.bits),o=[],c=e,h=c;for(let d=0;d<n;d++){h=c,o.push(h);for(let x=1;x<i;x++)h=h.add(c),o.push(h);c=h.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,c=us(e,this.bits);for(let h=0;h<c.windows;h++){let{nextN:d,offset:x,isZero:v,isNeg:y,isNegF:A,offsetF:O}=Du(n,h,c);n=d,v?o=o.add(Kn(A,r[O])):i=i.add(Kn(y,r[x]))}return Gu(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=us(e,this.bits);for(let c=0;c<o.windows&&n!==An;c++){let{nextN:h,offset:d,isZero:x,isNeg:v}=Du(n,c,o);if(n=h,!x){let y=r[d];i=i.add(v?y.negate():y)}}return Gu(n),i}getPrecomputes(e,r,n){let i=hs.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),hs.set(r,i))),i}cached(e,r,n){let i=fs(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=fs(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){Ku(r,this.bits),ju.set(e,r),hs.delete(e)}hasCache(e){return fs(e)!==1}}});function Xu(t){if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new Error("wrong u32 integer:"+t);return t}function dd(t){if(Xu(t),t<=1)return 1;if(t>2147483648)throw new Error("nextPowerOfTwo overflow: result does not fit u32");return 1<<ds(t-1)+1>>>0}function ds(t){return Xu(t),31-Math.clz32(t)}function Wu(t,e,r,n,i){let o=t,c=r||((v,y)=>new Array(v).fill(y??o.ZERO)),h=v=>{if(Array.isArray(v))return!0;if(!ArrayBuffer.isView(v))return!1;let y=v;return typeof y.length=="number"&&typeof y.slice=="function"&&typeof y[Symbol.iterator]=="function"},d=(...v)=>{if(!v.length)return 0;for(let A of v)if(!h(A))throw new Error("poly: not polynomial: "+A);let y=v[0].length;for(let A=1;A<v.length;A++)if(v[A].length!==y)throw new Error(`poly: mismatched lengths ${y} vs ${v[A].length}`);if(i!==void 0&&y!==i)throw new Error(`poly: expected fixed length ${i}, got ${y}`);return y};function x(v,y,A=!1){let O=ds(y),T=A?e.brp(O):e.roots(O);for(let L=0;L<y;L++)if(o.eql(v,T[L]))return L;return-1}return{roots:e,create:c,length:i,extend:(v,y)=>{d(v);let A=c(y,o.ZERO);for(let O=0;O<Math.min(v.length,y);O++)A[O]=v[O];return A},degree:v=>{d(v);for(let y=v.length-1;y>=0;y--)if(!o.is0(v[y]))return y;return-1},add:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.add(v[T],y[T]);return O},sub:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.sub(v[T],y[T]);return O},dot:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.mul(v[T],y[T]);return O},mul:(v,y)=>{if(h(y)){let A=d(v,y);if(n){let O=n.direct(v,!1,!0),T=n.direct(y,!1,!0);for(let L=0;L<O.length;L++)O[L]=o.mul(O[L],T[L]);return n.inverse(O,!0,!1)}else{let O=c(A);for(let T=0;T<A;T++)for(let L=0;L<A;L++){let U=(T+L)%A;O[U]=o.add(O[U],o.mul(v[T],y[L]))}return O}}else{let A=c(d(v));for(let O=0;O<A.length;O++)A[O]=o.mul(v[O],y);return A}},convolve(v,y){let A=dd(v.length+y.length-1);return this.mul(this.extend(v,A),this.extend(y,A))},shift(v,y){let A=c(d(v));A[0]=v[0];for(let O=1,T=o.ONE;O<v.length;O++)T=o.mul(T,y),A[O]=o.mul(v[O],T);return A},clone:v=>{d(v);let y=c(v.length);for(let A=0;A<v.length;A++)y[A]=v[A];return y},eval:(v,y)=>{d(v,y);let A=o.ZERO;for(let O=0;O<v.length;O++)A=o.add(A,o.mul(v[O],y[O]));return A},monomial:{basis:(v,y)=>{let A=c(y),O=o.ONE;for(let T=0;T<y;T++)A[T]=O,O=o.mul(O,v);return A},eval:(v,y)=>{d(v);let A=o.ZERO;for(let O=v.length-1;O>=0;O--)A=o.add(o.mul(A,y),v[O]);return A}},lagrange:{basis:(v,y,A=!1,O)=>{let T=ds(y),L=O||(A?e.brp(T):e.roots(T)),U=c(y),D=x(v,y,A);if(D!==-1)return U[D]=o.ONE,U;let et=o.pow(v,BigInt(y)),J=o.mul(o.sub(et,o.ONE),o.inv(BigInt(y))),Y=c(y);for(let ft=0;ft<y;ft++)Y[ft]=o.sub(v,L[ft]);let $=o.invertBatch(Y);for(let ft=0;ft<y;ft++)U[ft]=o.mul(J,o.mul(L[ft],$[ft]));return U},eval(v,y,A=!1){d(v);let O=x(y,v.length,A);if(O!==-1)return v[O];let T=this.basis(y,v.length,A),L=o.ZERO;for(let U=0;U<v.length;U++)o.is0(v[U])||(L=o.add(L,o.mul(v[U],T[U])));return L}},vanishing(v){d(v);let y=c(v.length+1,o.ZERO);y[0]=o.ONE;for(let A of v){let O=o.neg(A);for(let T=y.length-1;T>0;T--)y[T]=o.add(o.mul(y[T],O),y[T-1]);y[0]=o.mul(y[0],O)}return y}}}var Qu=Ae(()=>{I()});function $r(t,e){if(Fe(t),Fe(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function md(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Ju(t){if(!qr(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?bn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function gd(t,e,r,n){yt(t),Fe(r),e=Ju(e),e.length>255&&(e=n(gt(bn("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:o}=n,c=Math.ceil(r/i);if(r>65535||c>255)throw new Error("expand_message_xmd: invalid lenInBytes");let h=gt(e,$r(e.length,1)),d=new Uint8Array(o),x=$r(r,2),v=new Array(c),y=n(gt(d,t,x,$r(0,1),h));v[0]=n(gt(y,$r(1,1),h));for(let O=1;O<c;O++){let T=[md(y,v[O-1]),$r(O+1,1),h];v[O]=n(gt(...T))}return gt(...v).slice(0,r)}function vd(t,e,r,n,i){if(yt(t),Fe(r),e=Ju(e),e.length>255){let o=Math.ceil(2*n/8);e=i.create({dkLen:o}).update(bn("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:r}).update(t).update($r(r,2)).update(e).update($r(e.length,1)).digest()}function ps(t,e,r){He(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:i,m:o,hash:c,expand:h,DST:d}=r;if(Fe(c.outputLen,"valid hash"),yt(t),Fe(e),e<1)throw new Error("hash_to_field: expected count >= 1");if(o<1)throw new Error("hash_to_field: expected m >= 1");let x=n.toString(2).length,v=Math.ceil((x+i)/8),y=e*o*v,A;if(h==="xmd")A=gd(t,d,y,c);else if(h==="xof")A=vd(t,d,y,i,c);else if(h==="_internal_pass")A=t;else throw new Error('expand must be "xmd" or "xof"');let O=new Array(e);for(let T=0;T<e;T++){let L=new Array(o);for(let U=0;U<o;U++){let D=v*(U+T*o),et=A.subarray(D,D+v);L[U]=Me(pd(et),n)}O[T]=L}return O}function th(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,i)=>{let[o,c,h,d]=r.map(y=>y.reduce((A,O)=>t.add(t.mul(A,n),O))),[x,v]=jr(t,[c,d],!0);return n=t.mul(o,x),i=t.mul(i,t.mul(h,v)),{x:n,y:i}}}function eh(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");let n=h=>Object.freeze({...h,DST:qr(h.DST)?_i(h.DST):h.DST,...h.encodeDST===void 0?{}:{encodeDST:qr(h.encodeDST)?_i(h.encodeDST):h.encodeDST}}),i=n(r);function o(h){return t.fromAffine(e(h))}function c(h){let d=h.clearCofactor();return d.equals(t.ZERO)?t.ZERO:(d.assertValidity(),d)}return Object.freeze({get defaults(){return n(i)},Point:t,hashToCurve(h,d){let x=Object.assign({},i,d),v=ps(h,2,x),y=o(v[0]),A=o(v[1]);return c(y.add(A))},encodeToCurve(h,d){let x=i.encodeDST?{DST:i.encodeDST}:{},v=Object.assign({},i,x,d),y=ps(h,1,v),A=o(y[0]);return c(A)},mapToCurve(h){if(i.m===1){if(typeof h!="bigint")throw new Error("expected bigint (m=1)");return c(o([h]))}if(!Array.isArray(h))throw new Error("expected array of bigints");for(let d of h)if(typeof d!="bigint")throw new Error("expected array of bigints");return c(o(h))},hashToScalar(h,d){let x=t.Fn.ORDER,v=Object.assign({},i,{p:x,m:1,DST:xd},d);return ps(h,1,v)[0][0]}})}var pd,xd,rh=Ae(()=>{I();zr();On();pd=ye;xd="HashToScalar-"});function ms(t){He(t,{name:"string",hash:"function"},{hashToScalar:"function",validatePoint:"function",parsePublicKey:"function",adjustScalar:"function",adjustPoint:"function",challenge:"function",adjustNonces:"function",adjustSecret:"function",adjustPublic:"function",adjustGroupCommitmentShare:"function",adjustDKG:"function"}),Vu(t.Point);let{Point:e}=t,r=t.Fn===void 0?e.Fn:t.Fn,n=t.hash,i=t.hashToScalar===void 0?(_,P={DST:new Uint8Array})=>{let R=n(gt(P.DST,_));return r.create(r.isLE?wn(R):ye(R))}:t.hashToScalar,o=br(t.H1!==void 0?t.H1:t.name+"rho"),c=br(t.H2!==void 0?t.H2:t.name+"chal"),h=br(t.H3!==void 0?t.H3:t.name+"nonce"),d=br(t.H4!==void 0?t.H4:t.name+"msg"),x=br(t.H5!==void 0?t.H5:t.name+"com"),v=br(t.HDKG!==void 0?t.HDKG:t.name+"dkg"),y=br(t.HID!==void 0?t.HID:t.name+"id"),A=_=>i(_,{DST:o}),O=_=>i(_,{DST:c}),T=_=>i(_,{DST:h}),L=_=>n(gt(d,_)),U=_=>n(gt(x,_)),D=_=>i(_,{DST:v}),et=_=>i(_,{DST:y}),J=(_=Oe)=>{let P=_n(_(Vn(r.ORDER)),r.ORDER,r.isLE);return r.isLE?wn(P):ye(P)},Y=_=>_.toBytes(),$=_=>{let P=e.fromBytes(_);return t.validatePoint&&t.validatePoint(P),P},ft=(_,P)=>({identifier:_,hiding:Y(e.BASE.multiply(r.fromBytes(P.hiding))),binding:Y(e.BASE.multiply(r.fromBytes(P.binding)))}),Pt=t.adjustPoint===void 0?_=>_:t.adjustPoint,nt=_=>{if(!r.isValid(_)||r.is0(_))throw new Error("Invalid identifier "+_);return _},dt=_=>Er(r.toBytes(nt(_))),b=_=>{let P=nt(r.fromBytes(yn(_)));if(dt(P)!==_)throw new Error("expected canonical identifier hex");return P},s={encode:(_,P)=>{let R=gt(Y(_),r.toBytes(P));return t.adjustTx&&(R=t.adjustTx.encode(R)),R},decode:_=>{t.adjustTx&&(_=t.adjustTx.decode(_));let P=$(_.subarray(0,-r.BYTES)),R=r.fromBytes(_.subarray(-r.BYTES));return{R:P,z:R}}},u=(_=Oe)=>{let P=J(_);t.adjustScalar&&(P=t.adjustScalar(P));let R=e.BASE.multiply(P);return{scalar:P,point:R}},f="roots are unavailable in FROST polynomial mode",l={info:{G:r.ZERO,oddFactor:r.ZERO,powerOfTwo:0},roots(){throw new Error(f)},brp(){throw new Error(f)},inverse(){throw new Error(f)},omega(){throw new Error(f)},clear(){}},p=Wu(r,l),w=(_,P)=>$u(e,_,P),S=(_,P)=>{if(!P.length)throw new Error("empty coefficients");return p.monomial.eval(P,_)},m=(_,P)=>{let R="invalid parameters";if(!_.some(K=>r.eql(K,P)))throw new Error(R);let N=new Set(_);if(N.size!==_.length)throw new Error(R);if(!N.has(P))throw new Error(R);let V=r.ONE,G=r.ONE;for(let K of _)r.eql(K,P)||(V=r.mul(V,K),G=r.mul(G,r.sub(K,P)));return r.div(V,G)},a=(_,P)=>{let R=p.monomial.basis(_,P.length);return w(P,R)},g=(_,P,R,N=Oe)=>{Ti(_);let V=P===void 0?J(N):r.fromBytes(P);if(!R){R=[];for(let ot=0;ot<_.min-1;ot++)R.push(J(N))}if(R.length!==_.min-1)throw new Error("wrong coefficients length");let G=[V,...R],K=G.map(ot=>e.BASE.multiply(ot));return{coefficients:G,commitment:K,secret:V}},F={challenge:(_,P,R)=>D(gt(r.toBytes(_),Y(P),Y(R))),compute(_,P,R,N=Oe){if(P.length<1)throw new Error("coefficients should have at least one element");let{point:V,scalar:G}=u(N),K=R[0],ot=this.challenge(_,K,V),X=r.add(G,r.mul(P[0],ot));return s.encode(V,X)},validate(_,P,R){if(P.length<1)throw new Error("commitment should have at least one element");let{R:N,z:V}=s.decode(R),G=$(P[0]),K=this.challenge(_,G,N);if(!N.equals(e.BASE.multiply(V).subtract(G.multiply(K))))throw new Error("invalid proof of knowledge")}},k={challenge:(_,P,R)=>t.challenge?t.challenge(_,P,R):O(gt(Y(_),Y(P),R)),sign(_,P,R=Oe){let{point:N,scalar:V}=u(R),G=e.BASE.multiply(P),K=this.challenge(N,G,_),ot=r.add(V,r.mul(K,P));return[N,ot]},verify(_,P,R,N){t.adjustPoint&&(N=t.adjustPoint(N)),t.adjustPoint&&(P=t.adjustPoint(P));let V=this.challenge(P,N,_),G=e.BASE.multiply(R),K=N.multiply(V),ot=G.subtract(K).subtract(P);return ot.clearCofactor&&(ot=ot.clearCofactor()),e.ZERO.equals(ot)}},q=(_,P,R)=>{if(!e.BASE.multiply(R).equals(a(_,P)))throw new Error("invalid secret share")},z={fromNumber(_){if(!Number.isSafeInteger(_))throw new Error("expected safe interger");return dt(BigInt(_))},derive(_){if(typeof _!="string")throw new Error("wrong identifier string: "+_);return dt(et(br(_)))}},j=(_,P=Oe)=>T(gt(P(32),r.toBytes(_))),it=(_,P,R)=>{let N=P.map(st=>[st.identifier,b(st.identifier),$(st.hiding),$(st.binding)]);N.sort((st,at)=>st[1]<at[1]?-1:st[1]>at[1]?1:0);let V=[];for(let[st,at,ct,ht]of N)V.push(r.toBytes(at),Y(ct),Y(ht));let G=U(gt(...V)),K=gt(Y(_),L(R),G),ot={};for(let[st,at]of N)ot[st]=A(gt(K,r.toBytes(at)));let X=[],Q=[];for(let[st,at,ct,ht]of N){if(e.ZERO.equals(ct)||e.ZERO.equals(ht))throw new Error("infinity commitment");X.push(ct,ht),Q.push(r.ONE,ot[st])}let oe=w(X,Q);return{identifiers:N.map(st=>st[1]),groupCommitment:oe,bindingFactors:ot}},pt=(_,P,R,N)=>{let V=Pt($(_)),G=b(N),{identifiers:K,groupCommitment:ot,bindingFactors:X}=it(V,P,R),Q=X[N],oe=m(K,G),vt=k.challenge(ot,V,R);return{lambda:oe,challenge:vt,bindingFactor:Q,groupCommitment:ot}};Object.freeze(z);let ut={Identifier:z,DKG:Object.freeze({round1:(_,P,R,N=Oe)=>{Ti(P);let V=b(_),{coefficients:G,commitment:K}=g(P,R,void 0,N),ot=F.compute(V,G,K,N),X=K.map(Y),Q={identifier:dt(V),commitment:X,proofOfKnowledge:ot},oe={identifier:V,coefficients:G,commitment:K.map(Y),signers:{min:P.min,max:P.max},step:1};return{public:Q,secret:oe}},round2:(_,P)=>{if(P.length!==_.signers.max-1)throw new Error("wrong number of round1 packages");if(!_.coefficients||_.step===3)throw new Error("round3 package used in round2");let R={};for(let N of P){if(N.commitment.length!==_.signers.min)throw new Error("wrong number of commitments");let V=b(N.identifier);if(V===_.identifier)throw new Error("duplicate id="+dt(V));F.validate(V,N.commitment,N.proofOfKnowledge);for(let K of N.commitment)$(K);if(R[N.identifier])throw new Error("Duplicate id="+V);let G=r.toBytes(S(V,_.coefficients));R[N.identifier]={identifier:dt(_.identifier),signingShare:G}}return _.step=2,R},round3:(_,P,R)=>{if(P.length!==_.signers.max-1)throw new Error("wrong length of round1 packages");if(!_.coefficients||_.step!==2)throw new Error("round2 package used in round3");if(R.length!==P.length)throw new Error("wrong length of round2 packages");let N={};for(let at of P){if(!at.identifier||!at.commitment)throw new Error("wrong round1 share");N[at.identifier]={...at}}for(let at of R){if(!at.identifier||!at.signingShare)throw new Error("wrong round2 share");if(!N[at.identifier])throw new Error("round1 share for "+at.identifier+" is missing");N[at.identifier].signingShare=at.signingShare}if(Object.keys(N).length!==P.length)throw new Error("mismatch identifiers between rounds");let V=r.ZERO;if(_.commitment.length!==_.signers.min)throw new Error("wrong commitments length");let G=_.commitment.map($),K=S(_.identifier,_.coefficients);q(_.identifier,G,K);let ot=G.map(Y),X={[dt(_.identifier)]:ot};for(let at in N){let ct=N[at];if(!ct.signingShare||!ct.commitment)throw new Error("mismatch identifiers");let ht=b(at),cr=r.fromBytes(ct.signingShare),Tt=ct.commitment.map($);q(_.identifier,Tt,cr),V=r.add(V,cr);let Et=dt(ht);if(X[Et])throw new Error("duplicated id="+Et);X[Et]=ct.commitment}V=r.add(V,K);let Q=new Array(_.signers.min).fill(e.ZERO);for(let at in X){let ct=X[at];if(ct.length!==_.signers.min)throw new Error("wrong commitments length");for(let ht=0;ht<ct.length;ht++)Q[ht]=Q[ht].add($(ct[ht]))}let oe=Q.map(Y),vt={};for(let at in X)vt[at]=Y(a(b(at),Q));let st={public:{signers:{min:_.signers.min,max:_.signers.max},commitments:oe,verifyingShares:Object.fromEntries(Object.entries(vt).map(([at,ct])=>[at,ct.slice()]))},secret:{identifier:dt(_.identifier),signingShare:r.toBytes(V)}};t.adjustDKG&&(st=t.adjustDKG(st));for(let at=0;at<_.coefficients.length;at++)_.coefficients[at]-=_.coefficients[at];return delete _.coefficients,_.step=3,st},clean(_){if(_.identifier-=_.identifier,_.coefficients)for(let P=0;P<_.coefficients.length;P++)_.coefficients[P]-=_.coefficients[P];_.step=3}}),trustedDealer(_,P,R,N=Oe){if(Ti(_),P===void 0){P=[];for(let Q=1;Q<=_.max;Q++)P.push(z.fromNumber(Q))}else if(!Array.isArray(P)||P.length!==_.max)throw new Error("identifiers should be array of "+_.max);let V={};for(let Q of P){let oe=b(Q);if(Q in V)throw new Error("duplicated id="+Q);V[Q]=oe}let G=g(_,R,void 0,N),K=G.commitment.map(Y),ot={},X={};for(let Q of P){let oe=S(V[Q],G.coefficients);X[Q]=Y(e.BASE.multiply(oe)),ot[Q]={identifier:Q,signingShare:r.toBytes(oe)}}return{public:{signers:{min:_.min,max:_.max},commitments:K,verifyingShares:X},secretShares:ot}},validateSecret(_,P){let R=b(_.identifier),N=P.commitments.map($),V=r.fromBytes(_.signingShare);q(R,N,V)},commit(_,P=Oe){let R=r.fromBytes(_.signingShare),N=j(R,P),V=j(R,P),G={hiding:r.toBytes(N),binding:r.toBytes(V)};return{nonces:G,commitments:ft(_.identifier,G)}},signShare(_,P,R,N,V){nh(P.signers,N.length);let G=r.fromBytes(R.hiding),K=r.fromBytes(R.binding);if(r.is0(G)||r.is0(K))throw new Error("signing nonces already used");let ot={identifier:_.identifier,hiding:Y(e.BASE.multiply(G)),binding:Y(e.BASE.multiply(K))},X=N.find(Mt=>Mt.identifier===_.identifier);if(!X)throw new Error("missing signer commitment");if(Er(X.hiding)!==Er(ot.hiding)||Er(X.binding)!==Er(ot.binding))throw new Error("incorrect signer commitment");t.adjustSecret&&(_=t.adjustSecret(_,P)),t.adjustPublic&&(P=t.adjustPublic(P));let Q=r.fromBytes(_.signingShare),{lambda:oe,challenge:vt,bindingFactor:st,groupCommitment:at}=pt(P.commitments[0],N,V,_.identifier),ct=t.adjustNonces?t.adjustNonces(at,R):R,ht=t.adjustNonces?r.fromBytes(ct.hiding):G,cr=t.adjustNonces?r.fromBytes(ct.binding):K,Tt=r.mul(r.mul(oe,Q),vt),Et=r.mul(cr,st),ei=r.toBytes(r.add(r.add(ht,Et),Tt));return R.hiding.fill(0),R.binding.fill(0),ei},verifyShare(_,P,R,N,V){t.adjustPublic&&(_=t.adjustPublic(_));let G=P.find(cr=>cr.identifier===N);if(!G)throw new Error("cannot find identifier commitment");let K=$(_.verifyingShares[N]),ot=$(G.hiding),X=$(G.binding),{lambda:Q,challenge:oe,bindingFactor:vt,groupCommitment:st}=pt(_.commitments[0],P,R,N),at=ot.add(X.multiply(vt));t.adjustGroupCommitmentShare&&(at=t.adjustGroupCommitmentShare(st,at));let ct=e.BASE.multiply(r.fromBytes(V)),ht=at.add(K.multiply(r.mul(oe,Q)));return ct.equals(ht)},aggregate(_,P,R,N){t.adjustPublic&&(_=t.adjustPublic(_));try{nh(_.signers,P.length)}catch{throw new In("aggregation failed",[])}let V=P.map(X=>X.identifier);if(V.length!==Object.keys(N).length)throw new In("aggregation failed",[]);for(let X of V)if(!(X in N)||!(X in _.verifyingShares))throw new In("aggregation failed",[]);let G=$(_.commitments[0]),{groupCommitment:K}=it(G,P,R),ot=r.ZERO;for(let X of V)ot=r.add(ot,r.fromBytes(N[X]));if(!k.verify(R,K,ot,G)){let X=[];for(let Q of V)this.verifyShare(_,P,R,Q,N[Q])||X.push(Q);throw new In("aggregation failed",X)}return s.encode(K,ot)},sign(_,P){let R=r.fromBytes(P);t.adjustScalar&&(R=t.adjustScalar(R));let[N,V]=k.sign(_,R);return s.encode(N,V)},verify(_,P,R){let N=t.parsePublicKey?t.parsePublicKey(R):$(R),{R:V,z:G}=s.decode(_);return k.verify(P,V,G,N)},combineSecret(_,P){if(Ti(P),!Array.isArray(_)||_.length<P.min)throw new Error("wrong secret shares array");let R=[],N={};for(let K of _){let ot=b(K.identifier),X=dt(ot);if(N[X])throw new Error("duplicated id="+X);N[X]=!0,R.push([ot,r.fromBytes(K.signingShare)])}let V=R.map(([K])=>K),G=r.ZERO;for(let[K,ot]of R)G=r.add(G,r.mul(ot,m(V,K)));return r.toBytes(G)},utils:Object.freeze({Fn:r,randomScalar:(_=Oe)=>r.toBytes(u(_).scalar),generateSecretPolynomial:(_,P,R,N)=>{let V=g(_,P,R,N);return{...V,commitment:V.commitment.map(Y)}}})};return Object.freeze(ut)}var Ti,nh,In,ih=Ae(()=>{I();Mr();zr();Pi();Qu();On();Ti=t=>{if(!Number.isSafeInteger(t.min)||!Number.isSafeInteger(t.max))throw new Error("Wrong signers info: min="+t.min+" max="+t.max);if(t.min<2||t.max<2||t.min>t.max)throw new Error("Wrong signers info: min="+t.min+" max="+t.max)},nh=(t,e)=>{if(e<t.min||e>t.max)throw new Error("Wrong number of commitments="+e)},In=class extends Error{constructor(r,n){super(r);W(this,"cheaters");this.cheaters=n}}});var Bi,oh,sh=Ae(()=>{I();Mr();Bi=class{constructor(e,r){W(this,"oHash");W(this,"iHash");W(this,"blockLen");W(this,"outputLen");W(this,"canXOF",!1);W(this,"finished",!1);W(this,"destroyed",!1);if(mi(e),nr(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Cr(i)}update(e){return xn(this),this.iHash.update(e),this}digestInto(e){xn(this),gi(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:c,outputLen:h}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=c,e.outputLen=h,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},oh=(()=>{let t=((e,r,n)=>new Bi(e,r).update(n).digest());return t.create=(e,r)=>new Bi(e,r),t})()});function yd(t,e,r){os("scalar",t,Le,r);let[[n,i],[o,c]]=e,h=ah(c*t,r),d=ah(-i*t,r),x=t-h*n-d*o,v=-h*i-d*c,y=x<Le,A=v<Le;y&&(x=-x),A&&(v=-v);let O=Sn(Math.ceil(Gr(r)/2))+le;if(x<Le||x>=O||v<Le||v>=O)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:y,k1:x,k2neg:A,k2:v}}function vs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function gs(t,e){He(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Dr(r.lowS,"lowS"),Dr(r.prehash,"prehash"),r.format!==void 0&&vs(r.format),r}function ch(t,e={}){let r=Zu("weierstrass",t,e),n=r.Fp,i=r.Fn,o=r.CURVE,{h:c,n:h}=o;He(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:d,allowInfinityPoint:x}=e;if(d&&(!n.is0(o.a)||typeof d.beta!="bigint"||!Array.isArray(d.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let v=fh(n,i);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function A(u,f,l){if(x&&f.is0())return Uint8Array.of(0);let{x:p,y:w}=f.toAffine(),S=n.toBytes(p);if(Dr(l,"isCompressed"),l){y();let m=!n.isOdd(w);return gt(uh(m),S)}else return gt(Uint8Array.of(4),S,n.toBytes(w))}function O(u){yt(u,void 0,"Point");let{publicKey:f,publicKeyUncompressed:l}=v,p=u.length,w=u[0],S=u.subarray(1);if(x&&p===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(p===f&&(w===2||w===3)){let m=n.fromBytes(S);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let a=U(m),g;try{g=n.sqrt(a)}catch(q){let z=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}y();let F=n.isOdd(g);return(w&1)===1!==F&&(g=n.neg(g)),{x:m,y:g}}else if(p===l&&w===4){let m=n.BYTES,a=n.fromBytes(S.subarray(0,m)),g=n.fromBytes(S.subarray(m,m*2));if(!D(a,g))throw new Error("bad point: is not on curve");return{x:a,y:g}}else throw new Error(`bad point: got length ${p}, expected compressed=${f} or uncompressed=${l}`)}let T=e.toBytes===void 0?A:e.toBytes,L=e.fromBytes===void 0?O:e.fromBytes;function U(u){let f=n.sqr(u),l=n.mul(f,u);return n.add(n.add(l,n.mul(u,o.a)),o.b)}function D(u,f){let l=n.sqr(f),p=U(u);return n.eql(l,p)}if(!D(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let et=n.mul(n.pow(o.a,Pn),ys),J=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(et,J)))throw new Error("bad curve params: a or b");function Y(u,f,l=!1){if(!n.isValid(f)||l&&n.is0(f))throw new Error(`bad point coordinate ${u}`);return f}function $(u){if(!(u instanceof nt))throw new Error("Weierstrass Point expected")}function ft(u){if(!d||!d.basises)throw new Error("no endo");return yd(u,d.basises,i.ORDER)}function Pt(u,f,l,p,w){return l=new nt(n.mul(l.X,u),l.Y,l.Z),f=Kn(p,f),l=Kn(w,l),f.add(l)}let s=class s{constructor(f,l,p){W(this,"X");W(this,"Y");W(this,"Z");this.X=Y("x",f),this.Y=Y("y",l,!0),this.Z=Y("z",p),Object.freeze(this)}static CURVE(){return o}static fromAffine(f){let{x:l,y:p}=f||{};if(!f||!n.isValid(l)||!n.isValid(p))throw new Error("invalid affine point");if(f instanceof s)throw new Error("projective point not allowed");return n.is0(l)&&n.is0(p)?s.ZERO:new s(l,p,n.ONE)}static fromBytes(f){let l=s.fromAffine(L(yt(f,void 0,"point")));return l.assertValidity(),l}static fromHex(f){return s.fromBytes(yn(f))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(f=8,l=!0){return b.createCache(this,f),l||this.multiply(Pn),this}assertValidity(){let f=this;if(f.is0()){if(e.allowInfinityPoint&&n.is0(f.X)&&n.eql(f.Y,n.ONE)&&n.is0(f.Z))return;throw new Error("bad point: ZERO")}let{x:l,y:p}=f.toAffine();if(!n.isValid(l)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!D(l,p))throw new Error("bad point: equation left != right");if(!f.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:f}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(f)}equals(f){$(f);let{X:l,Y:p,Z:w}=this,{X:S,Y:m,Z:a}=f,g=n.eql(n.mul(l,a),n.mul(S,w)),F=n.eql(n.mul(p,a),n.mul(m,w));return g&&F}negate(){return new s(this.X,n.neg(this.Y),this.Z)}double(){let{a:f,b:l}=o,p=n.mul(l,Pn),{X:w,Y:S,Z:m}=this,a=n.ZERO,g=n.ZERO,F=n.ZERO,k=n.mul(w,w),q=n.mul(S,S),z=n.mul(m,m),j=n.mul(w,S);return j=n.add(j,j),F=n.mul(w,m),F=n.add(F,F),a=n.mul(f,F),g=n.mul(p,z),g=n.add(a,g),a=n.sub(q,g),g=n.add(q,g),g=n.mul(a,g),a=n.mul(j,a),F=n.mul(p,F),z=n.mul(f,z),j=n.sub(k,z),j=n.mul(f,j),j=n.add(j,F),F=n.add(k,k),k=n.add(F,k),k=n.add(k,z),k=n.mul(k,j),g=n.add(g,k),z=n.mul(S,m),z=n.add(z,z),k=n.mul(z,j),a=n.sub(a,k),F=n.mul(z,q),F=n.add(F,F),F=n.add(F,F),new s(a,g,F)}add(f){$(f);let{X:l,Y:p,Z:w}=this,{X:S,Y:m,Z:a}=f,g=n.ZERO,F=n.ZERO,k=n.ZERO,q=o.a,z=n.mul(o.b,Pn),j=n.mul(l,S),it=n.mul(p,m),pt=n.mul(w,a),ut=n.add(l,p),_=n.add(S,m);ut=n.mul(ut,_),_=n.add(j,it),ut=n.sub(ut,_),_=n.add(l,w);let P=n.add(S,a);return _=n.mul(_,P),P=n.add(j,pt),_=n.sub(_,P),P=n.add(p,w),g=n.add(m,a),P=n.mul(P,g),g=n.add(it,pt),P=n.sub(P,g),k=n.mul(q,_),g=n.mul(z,pt),k=n.add(g,k),g=n.sub(it,k),k=n.add(it,k),F=n.mul(g,k),it=n.add(j,j),it=n.add(it,j),pt=n.mul(q,pt),_=n.mul(z,_),it=n.add(it,pt),pt=n.sub(j,pt),pt=n.mul(q,pt),_=n.add(_,pt),j=n.mul(it,_),F=n.add(F,j),j=n.mul(P,_),g=n.mul(ut,g),g=n.sub(g,j),j=n.mul(ut,it),k=n.mul(P,k),k=n.add(k,j),new s(g,F,k)}subtract(f){return $(f),this.add(f.negate())}is0(){return this.equals(s.ZERO)}multiply(f){let{endo:l}=e;if(!i.isValidNot0(f))throw new RangeError("invalid scalar: out of range");let p,w,S=m=>b.cached(this,m,a=>ls(s,a));if(l){let{k1neg:m,k1:a,k2neg:g,k2:F}=ft(f),{p:k,f:q}=S(a),{p:z,f:j}=S(F);w=q.add(j),p=Pt(l.beta,k,z,m,g)}else{let{p:m,f:a}=S(f);p=m,w=a}return ls(s,[p,w])[0]}multiplyUnsafe(f){let{endo:l}=e,p=this,w=f;if(!i.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Le||p.is0())return s.ZERO;if(w===le)return p;if(b.hasCache(this))return this.multiply(w);if(l){let{k1neg:S,k1:m,k2neg:a,k2:g}=ft(w),{p1:F,p2:k}=Yu(s,p,m,g);return Pt(l.beta,F,k,S,a)}else return b.unsafe(p,w)}toAffine(f){let l=this,p=f,{X:w,Y:S,Z:m}=l;if(n.eql(m,n.ONE))return{x:w,y:S};let a=l.is0();p==null&&(p=a?n.ONE:n.inv(m));let g=n.mul(w,p),F=n.mul(S,p),k=n.mul(m,p);if(a)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:g,y:F}}isTorsionFree(){let{isTorsionFree:f}=e;return c===le?!0:f?f(s,this):b.unsafe(this,h).is0()}clearCofactor(){let{clearCofactor:f}=e;return c===le?this:f?f(s,this):this.multiplyUnsafe(c)}isSmallOrder(){return c===le?this.is0():this.clearCofactor().is0()}toBytes(f=!0){return Dr(f,"isCompressed"),this.assertValidity(),T(s,this,f)}toHex(f=!0){return Er(this.toBytes(f))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};W(s,"BASE",new s(o.Gx,o.Gy,n.ONE)),W(s,"ZERO",new s(n.ZERO,n.ONE,n.ZERO)),W(s,"Fp",n),W(s,"Fn",i);let nt=s,dt=i.BITS,b=new Ai(nt,e.endo?Math.ceil(dt/2):dt);return dt>=8&&nt.BASE.precompute(8),Object.freeze(nt.prototype),Object.freeze(nt),nt}function uh(t){return Uint8Array.of(t?2:3)}function wd(t,e){let r=Kr(t),n=r.ORDER,i=Le;for(let L=n-le;L%ir===Le;L/=ir)i+=le;let o=i,c=ir<<o-le-le,h=c*ir,d=(n-le)/h,x=(d-le)/ir,v=h-le,y=c,A=r.pow(e,d),O=r.pow(e,(d+le)/ir),T=(L,U)=>{let D=A,et=r.pow(U,v),J=r.sqr(et);J=r.mul(J,U);let Y=r.mul(L,J);Y=r.pow(Y,x),Y=r.mul(Y,et),et=r.mul(Y,U),J=r.mul(Y,L);let $=r.mul(J,et);Y=r.pow($,y);let ft=r.eql(Y,r.ONE);et=r.mul(J,O),Y=r.mul($,D),J=r.cmov(et,J,ft),$=r.cmov(Y,$,ft);for(let Pt=o;Pt>le;Pt--){let nt=Pt-ir;nt=ir<<nt-le;let dt=r.pow($,nt),b=r.eql(dt,r.ONE);et=r.mul(J,D),D=r.mul(D,D),dt=r.mul($,D),J=r.cmov(et,J,b),$=r.cmov(dt,$,b)}return{isValid:!r.is0(U)&&(ft||r.is0(L)),value:J}};if(r.ORDER%ys===Pn){let L=(r.ORDER-Pn)/ys,U=r.sqrt(r.neg(e));T=(D,et)=>{let J=r.sqr(et),Y=r.mul(D,et);J=r.mul(J,Y);let $=r.pow(J,L);$=r.mul($,Y);let ft=r.mul($,U),Pt=r.mul(r.sqr($),et),nt=r.eql(Pt,D),dt=r.cmov(ft,$,nt);return{isValid:!r.is0(et)&&nt,value:dt}}}return T}function hh(t,e){let r=Kr(t),{A:n,B:i,Z:o}=e;if(!r.isValidNot0(n)||!r.isValidNot0(i)||!r.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");if(r.eql(o,r.neg(r.ONE))||cs(r,o))throw new Error("mapToCurveSimpleSWU: invalid opts");let c=r.mul(i,r.inv(r.mul(o,n))),h=r.add(r.add(r.mul(r.sqr(c),c),r.mul(n,c)),i);if(!cs(r,h))throw new Error("mapToCurveSimpleSWU: invalid opts");let d=wd(r,o);if(!r.isOdd)throw new Error("Field does not have .isOdd()");return x=>{let v,y,A,O,T,L,U,D;v=r.sqr(x),v=r.mul(v,o),y=r.sqr(v),y=r.add(y,v),A=r.add(y,r.ONE),A=r.mul(A,i),O=r.cmov(o,r.neg(y),!r.eql(y,r.ZERO)),O=r.mul(O,n),y=r.sqr(A),L=r.sqr(O),T=r.mul(L,n),y=r.add(y,T),y=r.mul(y,A),L=r.mul(L,O),T=r.mul(L,i),y=r.add(y,T),U=r.mul(v,A);let{isValid:et,value:J}=d(y,L);D=r.mul(v,x),D=r.mul(D,J),U=r.cmov(U,A,et),D=r.cmov(D,J,et);let Y=r.isOdd(x)===r.isOdd(D);D=r.cmov(r.neg(D),D,Y);let $=jr(r,[O],!0)[0];return U=r.mul(U,$),{x:U,y:D}}}function fh(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function bd(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Oe:e.randomBytes,i=Object.assign(fh(t.Fp,r),{seed:Math.max(Vn(r.ORDER),16)});function o(O){try{let T=r.fromBytes(O);return r.isValidNot0(T)}catch{return!1}}function c(O,T){let{publicKey:L,publicKeyUncompressed:U}=i;try{let D=O.length;return T===!0&&D!==L||T===!1&&D!==U?!1:!!t.fromBytes(O)}catch{return!1}}function h(O){return O=O===void 0?n(i.seed):O,_n(yt(O,i.seed,"seed"),r.ORDER)}function d(O,T=!0){return t.BASE.multiply(r.fromBytes(O)).toBytes(T)}function x(O){let{secretKey:T,publicKey:L,publicKeyUncompressed:U}=i,D=r._lengths;if(!qr(O))return;let et=yt(O,void 0,"key").length,J=et===L||et===U,Y=et===T||!!D?.includes(et);if(!(J&&Y))return J}function v(O,T,L=!0){if(x(O)===!0)throw new Error("first arg must be private key");if(x(T)===!1)throw new Error("second arg must be public key");let U=r.fromBytes(O);return t.fromBytes(T).multiply(U).toBytes(L)}let y={isValidSecretKey:o,isValidPublicKey:c,randomSecretKey:h},A=Ii(h,d);return Object.freeze(y),Object.freeze(i),Object.freeze({getPublicKey:d,getSharedSecret:v,keygen:A,Point:t,utils:y,lengths:i})}function lh(t,e,r={}){let n=e;mi(n),He(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let i=r.randomBytes===void 0?Oe:r.randomBytes,o=r.hmac===void 0?(p,w)=>oh(n,p,w):r.hmac,{Fp:c,Fn:h}=t,{ORDER:d,BITS:x}=h,{keygen:v,getPublicKey:y,getSharedSecret:A,utils:O,lengths:T}=bd(t,r),L={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},U=d*ir+le<c.ORDER;function D(p){let w=d>>le;return p>w}function et(p,w){if(!h.isValidNot0(w))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return w}function J(){if(U)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function Y(p,w){vs(w);let S=T.signature,m=w==="compact"?S:w==="recovered"?S+1:void 0;return yt(p,m)}class ${constructor(w,S,m){W(this,"r");W(this,"s");W(this,"recovery");if(this.r=et("r",w),this.s=et("s",S),m!=null){if(J(),![0,1,2,3].includes(m))throw new Error("invalid recovery id");this.recovery=m}Object.freeze(this)}static fromBytes(w,S=L.format){Y(w,S);let m;if(S==="der"){let{r:k,s:q}=Ve.toSig(yt(w));return new $(k,q)}S==="recovered"&&(m=w[0],S="compact",w=w.subarray(1));let a=T.signature/2,g=w.subarray(0,a),F=w.subarray(a,a*2);return new $(h.fromBytes(g),h.fromBytes(F),m)}static fromHex(w,S){return this.fromBytes(yn(w),S)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new $(this.r,this.s,w)}recoverPublicKey(w){let{r:S,s:m}=this,a=this.assertRecovery(),g=a===2||a===3?S+d:S;if(!c.isValid(g))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=c.toBytes(g),k=t.fromBytes(gt(uh((a&1)===0),F)),q=h.inv(g),z=Pt(yt(w,void 0,"msgHash")),j=h.create(-z*q),it=h.create(m*q),pt=t.BASE.multiplyUnsafe(j).add(k.multiplyUnsafe(it));if(pt.is0())throw new Error("invalid recovery: point at infinify");return pt.assertValidity(),pt}hasHighS(){return D(this.s)}toBytes(w=L.format){if(vs(w),w==="der")return yn(Ve.hexFromSig(this));let{r:S,s:m}=this,a=h.toBytes(S),g=h.toBytes(m);return w==="recovered"?(J(),gt(Uint8Array.of(this.assertRecovery()),a,g)):gt(a,g)}toHex(w){return Er(this.toBytes(w))}}Object.freeze($.prototype),Object.freeze($);let ft=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let S=ye(w),m=w.length*8-x;return m>0?S>>BigInt(m):S}:r.bits2int,Pt=r.bits2int_modN===void 0?function(w){return h.create(ft(w))}:r.bits2int_modN,nt=Sn(x);function dt(p){return os("num < 2^"+x,p,Le,nt),h.toBytes(p)}function b(p,w){return yt(p,void 0,"message"),w?yt(n(p),void 0,"prehashed message"):p}function s(p,w,S){let{lowS:m,prehash:a,extraEntropy:g}=gs(S,L);p=b(p,a);let F=Pt(p),k=h.fromBytes(w);if(!h.isValidNot0(k))throw new Error("invalid private key");let q=[dt(k),dt(F)];if(g!=null&&g!==!1){let pt=g===!0?i(T.secretKey):g;q.push(yt(pt,void 0,"extraEntropy"))}let z=gt(...q),j=F;function it(pt){let ut=ft(pt);if(!h.isValidNot0(ut))return;let _=h.inv(ut),P=t.BASE.multiply(ut).toAffine(),R=h.create(P.x);if(R===Le)return;let N=h.create(_*h.create(j+R*k));if(N===Le)return;let V=(P.x===R?0:2)|Number(P.y&le),G=N;return m&&D(N)&&(G=h.neg(N),V^=1),new $(R,G,U?void 0:V)}return{seed:z,k2sig:it}}function u(p,w,S={}){let{seed:m,k2sig:a}=s(p,w,S);return Bu(n.outputLen,h.BYTES,o)(m,a).toBytes(S.format)}function f(p,w,S,m={}){let{lowS:a,prehash:g,format:F}=gs(m,L);if(S=yt(S,void 0,"publicKey"),w=b(w,g),!qr(p)){let k=p instanceof $?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}Y(p,F);try{let k=$.fromBytes(p,F),q=t.fromBytes(S);if(a&&k.hasHighS())return!1;let{r:z,s:j}=k,it=Pt(w),pt=h.inv(j),ut=h.create(it*pt),_=h.create(z*pt),P=t.BASE.multiplyUnsafe(ut).add(q.multiplyUnsafe(_));return P.is0()?!1:h.create(P.x)===z}catch{return!1}}function l(p,w,S={}){let{prehash:m}=gs(S,L);return w=b(w,m),$.fromBytes(p,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:v,getPublicKey:y,getSharedSecret:A,utils:O,lengths:T,Point:t,sign:u,verify:f,recoverPublicKey:l,Signature:$,hash:n})}var ah,xs,Ve,Le,le,ir,Pn,ys,dh=Ae(()=>{I();sh();Mr();zr();Pi();On();ah=(t,e)=>(t+(t>=0?e:-e)/ir)/e;xs=class extends Error{constructor(e=""){super(e)}},Ve={Err:xs,_tlv:{encode:(t,e)=>{let{Err:r}=Ve;if(Fe(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=zn(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?zn(i.length/2|128):"";return zn(t)+o+i+e},decode(t,e){let{Err:r}=Ve;e=yt(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),c=0;if(!o)c=i;else{let d=i&127;if(!d)throw new r("tlv.decode(long): indefinite length not supported");if(d>4)throw new r("tlv.decode(long): byte length is too big");let x=e.subarray(n,n+d);if(x.length!==d)throw new r("tlv.decode: length bytes not complete");if(x[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let v of x)c=c<<8|v;if(n+=d,c<128)throw new r("tlv.decode(long): not minimal encoding")}let h=e.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: wrong value length");return{v:h,l:e.subarray(n+c)}}},_int:{encode(t){let{Err:e}=Ve;if(Si(t),t<Le)throw new e("integer: negative integers are not allowed");let r=zn(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ve;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ye(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ve,i=yt(t,void 0,"signature"),{v:o,l:c}=n.decode(48,i);if(c.length)throw new e("invalid signature: left bytes after parsing");let{v:h,l:d}=n.decode(2,o),{v:x,l:v}=n.decode(2,d);if(v.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(h),s:r.decode(x)}},hexFromSig(t){let{_tlv:e,_int:r}=Ve,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}};Object.freeze(Ve._tlv);Object.freeze(Ve._int);Object.freeze(Ve);Le=BigInt(0),le=BigInt(1),ir=BigInt(2),Pn=BigInt(3),ys=BigInt(4)});var Sh={};Of(Sh,{__TEST:()=>Ad,schnorr:()=>Id,schnorr_FROST:()=>Fd,secp256k1:()=>_d,secp256k1_FROST:()=>Bd,secp256k1_hasher:()=>Ss});function Ed(t){let e=Mi.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),c=BigInt(23),h=BigInt(44),d=BigInt(88),x=t*t*t%e,v=x*x*t%e,y=Re(v,r,e)*v%e,A=Re(y,r,e)*v%e,O=Re(A,ws,e)*x%e,T=Re(O,i,e)*O%e,L=Re(T,o,e)*T%e,U=Re(L,h,e)*L%e,D=Re(U,d,e)*U%e,et=Re(D,h,e)*L%e,J=Re(et,r,e)*v%e,Y=Re(J,c,e)*T%e,$=Re(Y,n,e)*x%e,ft=Re($,ws,e);if(!_r.eql(_r.sqr(ft),t))throw new Error("Cannot find square root");return ft}function jn(t,...e){let r=ph[t];if(r===void 0){let n=Ur(bn(t));r=gt(n,n),ph[t]=r}return Ur(gt(r,...e))}function xh(t){let{Fn:e,BASE:r}=bt,n=e.fromBytes(t),i=r.multiply(n);return{scalar:or(i.y)?n:e.neg(n),bytes:Zr(i)}}function Ri(t){let e=_r;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);or(i)||(i=e.neg(i));let o=bt.fromAffine({x:t,y:i});return o.assertValidity(),o}function bs(...t){return bt.Fn.create(Tn(jn("BIP0340/challenge",...t)))}function mh(t){return xh(t).bytes}function Od(t,e,r=Gn(32)){let{Fn:n,BASE:i}=bt,o=yt(t,void 0,"message"),{bytes:c,scalar:h}=xh(e),d=yt(r,32,"auxRand"),x=n.toBytes(h^Tn(jn("BIP0340/aux",d))),v=jn("BIP0340/nonce",x,c,o),y=n.create(Tn(v));if(y===0n)throw new Error("sign failed: k is zero");let A=i.multiply(y),O=or(A.y)?y:n.neg(y),T=Zr(A),L=bs(T,c,o),U=new Uint8Array(64);if(U.set(T,0),U.set(n.toBytes(n.create(O+L*h)),32),!yh(U,o,c))throw new Error("sign: Invalid signature produced");return U}function yh(t,e,r){let{Fp:n,Fn:i,BASE:o}=bt,c=yt(t,64,"signature"),h=yt(e,void 0,"message"),d=yt(r,32,"publicKey");try{let x=Ri(Tn(d)),v=Tn(c.subarray(0,32));if(!n.isValidNot0(v))return!1;let y=Tn(c.subarray(32,64));if(!i.isValidNot0(y))return!1;let A=bs(i.toBytes(v),Zr(x),h),O=o.multiplyUnsafe(y).add(x.multiplyUnsafe(i.neg(A))),{x:T,y:L}=O.toAffine();return!(O.is0()||!or(L)||T!==v)}catch{return!1}}function wh(t,e){if(e===void 0)return vh;let r=Zr(t),n=ye(jn("TapTweak",r,e));if(!bt.Fn.isValid(n))throw new Error("invalid TapTweak hash");return n}function Es(t){let e=bt.fromBytes(t.commitments[0]);return or(e.y)?t:{signers:{min:t.signers.min,max:t.signers.max},commitments:t.commitments.map(r=>bt.fromBytes(r).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(t.verifyingShares).map(([r,n])=>[r,bt.fromBytes(n).negate().toBytes()]))}}function bh(t,e){let r=bt.fromBytes(e.commitments[0]);if(or(r.y))return t;let n=bt.Fn;return{...t,signingShare:n.toBytes(n.neg(n.fromBytes(t.signingShare)))}}function Md(t,e){if(or(t.y))return e;let r=bt.Fn;return{binding:r.toBytes(r.neg(r.fromBytes(e.binding))),hiding:r.toBytes(r.neg(r.fromBytes(e.hiding)))}}function Rd(t,e,r){let n=bt.Fn,i=bh(t,e),o=Es(e),c=wh(bt.fromBytes(o.commitments[0]),r),h=n.toBytes(n.add(n.fromBytes(i.signingShare),c));return{identifier:i.identifier,signingShare:h}}function kd(t,e){let r=Es(t),n=wh(bt.fromBytes(r.commitments[0]),e),i=bt.BASE.multiply(n),o=r.commitments.map((h,d)=>(d===0?bt.fromBytes(h).add(i):bt.fromBytes(h)).toBytes()),c={};for(let h in r.verifyingShares)c[h]=bt.fromBytes(r.verifyingShares[h]).add(i).toBytes();return{signers:{min:r.signers.min,max:r.signers.max},commitments:o,verifyingShares:c}}var Mi,Sd,vh,ws,_r,bt,_d,ph,Zr,or,Tn,Ad,Id,Pd,gh,Td,Ss,Bd,Fd,Eh=Ae(()=>{I();Pu();Mr();Pi();ih();rh();On();dh();zr();Mi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Sd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},vh=BigInt(0),ws=BigInt(2);_r=En(Mi.p,{sqrt:Ed}),bt=ch(Mi,{Fp:_r,endo:Sd}),_d=lh(bt,Ur),ph={};Zr=t=>t.toBytes(!0).slice(1),or=t=>t%ws===vh;Tn=ye;Ad=Object.freeze({lift_x:Ri}),Id=(()=>{let r=n=>(n=n===void 0?Gn(48):n,_n(n,Mi.n));return Object.freeze({keygen:Ii(r,mh),getPublicKey:mh,sign:Od,verify:yh,Point:bt,utils:Object.freeze({randomSecretKey:r,taggedHash:jn,lift_x:Ri,pointToBytes:Zr}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),Pd=th(_r,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),Td=()=>gh||(gh=hh(_r,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:_r.create(BigInt("-11"))})),Ss=eh(bt,t=>{let{x:e,y:r}=Td()(_r.create(t[0]));return Pd(e,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:_r.ORDER,m:1,k:128,expand:"xmd",hash:Ur}),Bd=ms({name:"FROST-secp256k1-SHA256-v1",Point:bt,hashToScalar:Ss.hashToScalar,hash:Ur});Fd=ms({name:"FROST-secp256k1-SHA256-TR-v1",Point:bt,hashToScalar:Ss.hashToScalar,hash:Ur,parsePublicKey(t){if(t.length===32)return Ri(ye(t));if(t.length===33)return bt.fromBytes(t);throw new Error(`expected x-only or compressed public key, got length=${t.length}`)},adjustScalar(t){let e=bt.BASE.multiply(t);return or(e.y)?t:bt.Fn.neg(t)},adjustPoint:t=>or(t.y)?t:t.negate(),challenge(t,e,r){return bs(Zr(t),Zr(e),r)},adjustNonces:Md,adjustGroupCommitmentShare:(t,e)=>or(t.y)?e:e.negate(),adjustPublic:Es,adjustSecret:bh,adjustTx:{encode:t=>t.subarray(1),decode:t=>gt(Uint8Array.of(2),t)},adjustDKG:t=>{let e=new Uint8Array(0);return{public:kd(t.public,e),secret:Rd(t.secret,t.public,e)}}})});var Zn=Z((Rv,Ih)=>{"use strict";I();var _h=Cn(),{secp256k1:Hd}=(Eh(),Af(Sh)),$n=Hd.Point,ki=$n.Fn.ORDER;function Ld(t){return BigInt("0x"+(t.toString(16)||"0"))}function _s(t){var e=t.toString(16);return e.length%2&&(e="0"+e),new _h(e,16)}function Fi(t){if(t==null)throw new Error("Invalid Point");if(typeof t=="bigint")return t;if(typeof t=="number")return BigInt(t);if(typeof t=="string")return BigInt(t.indexOf("0x")===0?t:"0x"+t);if(typeof t.toString=="function")return Ld(t);throw new Error("Invalid Point")}function Yn(t){var e=Object.create(St.prototype);return e._p=t,e}function Oh(t,e){var r=Fi(e).toString(16).padStart(64,"0");return $n.fromHex((t?"03":"02")+r)}function Ah(t,e){var r;try{r=Oh((e&1n)===1n,t)}catch{throw new Error("Point does not lie on the curve")}if(r.toAffine().y!==e)throw new Error("Invalid y value for curve.")}function St(t,e,r){if(!(this instanceof St))return new St(t,e,r);var n,i;try{n=Fi(t),i=Fi(e)}catch{throw new Error("Invalid Point")}Ah(n,i);try{this._p=$n.fromAffine({x:n,y:i})}catch{throw new Error("Invalid Point")}return this}St.fromX=function(e,r){try{var n=Yn(Oh(e,r))}catch{throw new Error("Invalid X")}return n.validate(),n};St.getG=function(){return Yn($n.BASE)};St.getN=function(){return _s(ki)};St.prototype.getX=function(){return _s(this._p.toAffine().x)};St.prototype.getY=function(){return _s(this._p.toAffine().y)};Object.defineProperty(St.prototype,"x",{configurable:!0,enumerable:!0,get:function(){return this.getX()}});Object.defineProperty(St.prototype,"y",{configurable:!0,enumerable:!0,get:function(){return this.getY()}});St.prototype.mul=function(e){var r=(Fi(e)%ki+ki)%ki;return r===0n||this._p.is0()?Yn($n.ZERO):Yn(this._p.multiply(r))};St.prototype.add=function(e){return Yn(this._p.add(e._p))};St.prototype.mulAdd=function(e,r,n){return this.mul(e).add(r.mul(n))};St.prototype.eq=function(e){return this._p.equals(e._p)};St.prototype.isInfinity=function(){return this._p.is0()};St.prototype.validate=function(){if(this.isInfinity())throw new Error("Point cannot be equal to Infinity");var e=this._p.toAffine();return Ah(e.x,e.y),this};St.pointToCompressed=function(e){var r=e.getX().toBuffer({size:32}),n=e.getY().toBuffer({size:32}),i,o=n[n.length-1]%2;return o?i=E.Buffer.from([3]):i=E.Buffer.from([2]),E.Buffer.concat([i,r])};St.pointFromCompressed=function(t){if(t.length!==33)throw new Error("invalid buffer length");var e=t[0],r;if(e===3)r=!0;else if(e===2)r=!1;else throw new Error("invalid value of compressed prefix");var n=_h.fromBuffer(t.slice(1,33));return St.fromX(r,n)};St.prototype.toBuffer=function(){return St.pointToCompressed(this)};St.prototype.toHex=function(){return this.toBuffer().toString("hex")};St.fromBuffer=function(t){return St.pointFromCompressed(t)};St.fromHex=function(t){return St.fromBuffer(E.Buffer.from(t,"hex"))};Ih.exports=St});var Bh=Z((Fv,Th)=>{"use strict";I();var Xr=Cn(),Nd=cn(),we=hn(),Cd=yu(),lt=function t(e,r){if(!(this instanceof t))return new t(e,r);if(e instanceof Xr)this.set({r:e,s:r});else if(e){var n=e;this.set(n)}};lt.prototype.set=function(t){return this.r=t.r||this.r||void 0,this.s=t.s||this.s||void 0,this.i=typeof t.i<"u"?t.i:this.i,this.compressed=typeof t.compressed<"u"?t.compressed:this.compressed,this.nhashtype=t.nhashtype||this.nhashtype||void 0,this};lt.fromCompact=function(t){we.checkArgument(E.Buffer.isBuffer(t),"Argument is expected to be a Buffer");var e=new lt,r=!0,n=t.slice(0,1)[0]-27-4;n<0&&(r=!1,n=n+4);var i=t.slice(1,33),o=t.slice(33,65);return we.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),we.checkArgument(i.length===32,new Error("r must be 32 bytes")),we.checkArgument(o.length===32,new Error("s must be 32 bytes")),e.compressed=r,e.i=n,e.r=Xr.fromBuffer(i),e.s=Xr.fromBuffer(o),e};lt.fromDER=lt.fromBuffer=function(t,e){var r=lt.parseDER(t,e),n=new lt;return n.r=r.r,n.s=r.s,n};lt.fromTxFormat=function(t){var e=t.readUInt8(t.length-1),r=t.slice(0,t.length-1),n=lt.fromDER(r,!1);return n.nhashtype=e,n};lt.fromString=function(t){var e=E.Buffer.from(t,"hex");return lt.fromDER(e)};function Ph(t,e){we.checkArgument(e.length>0,new Error("Length of "+t+" is zero")),we.checkArgument(!(e[0]&128),new Error("Value of "+t+" is negative")),we.checkArgument(!(e.length>1&&e[0]===0&&!(e[1]&128)),new Error("Value of "+t+" is excessively padded"))}lt.parseDER=function(t,e){we.checkArgument(E.Buffer.isBuffer(t),new Error("DER formatted signature should be a buffer")),Nd.isUndefined(e)&&(e=!0);var r=t[0];we.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=t[1],i=t.slice(2).length;we.checkArgument(!e||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=t[2];we.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var c=t[3],h=t.slice(4,4+c),d=Xr.fromBuffer(h),x=t[4]===0;we.checkArgument(c===h.length,new Error("Length of r incorrect"));var v=t[4+c+0];we.checkArgument(v===2,new Error("Integer byte for s should be 0x02"));var y=t[4+c+1],A=t.slice(4+c+2,4+c+2+y),O=Xr.fromBuffer(A),T=t[4+c+2]===0;we.checkArgument(y===A.length,new Error("Length of s incorrect"));var L=4+c+2+y;we.checkArgument(n===L-2,new Error("Length of signature incorrect")),e&&(Ph("r",h),Ph("s",A));var U={header:r,length:n,rheader:o,rlength:c,rneg:x,rbuf:h,r:d,sheader:v,slength:y,sneg:T,sbuf:A,s:O};return U};lt.prototype.toCompact=function(t,e){if(t=typeof t=="number"?t:this.i,e=typeof e=="boolean"?e:this.compressed,!(t===0||t===1||t===2||t===3))throw new Error("i must be equal to 0, 1, 2, or 3");var r=t+27+4;e===!1&&(r=r-4);var n=E.Buffer.from([r]),i=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return E.Buffer.concat([n,i,o])};lt.prototype.toBuffer=lt.prototype.toDER=function(){var t=this.r.toBuffer(),e=this.s.toBuffer(),r=!!(t[0]&128),n=!!(e[0]&128),i=r?E.Buffer.concat([E.Buffer.from([0]),t]):t,o=n?E.Buffer.concat([E.Buffer.from([0]),e]):e,c=i.length,h=o.length,d=2+c+2+h,x=2,v=2,y=48,A=E.Buffer.concat([E.Buffer.from([y,d,x,c]),i,E.Buffer.from([v,h]),o]);return A};lt.prototype.toString=function(){var t=this.toDER();return t.toString("hex")};lt.isTxDER=function(t){if(t.length<9||t.length>73||t[0]!==48||t[1]!==t.length-3)return!1;var e=t[3];if(5+e>=t.length)return!1;var r=t[5+e];if(e+r+7!==t.length)return!1;var n=t.slice(4);if(t[2]!==2||e===0||n[0]&128||e>1&&n[0]===0&&!(n[1]&128))return!1;var i=t.slice(6+e);return!(t[6+e-2]!==2||r===0||i[0]&128||r>1&&i[0]===0&&!(i[1]&128))};lt.prototype.hasLowS=function(){return!(this.s.lt(new Xr(1))||this.s.gt(new Xr("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};lt.prototype.hasDefinedHashtype=function(){if(!Cd.isNaturalNumber(this.nhashtype))return!1;var t=this.nhashtype&31;return!(t<lt.SIGHASH_ALL||t>lt.SIGHASH_SINGLE)};lt.prototype.toTxFormat=function(){var t=this.toDER(),e=E.Buffer.alloc(1);return e.writeUInt8(this.nhashtype,0),E.Buffer.concat([t,e])};lt.SIGHASH_ALL=1;lt.SIGHASH_NONE=2;lt.SIGHASH_SINGLE=3;lt.SIGHASH_FORKID=64;lt.SIGHASH_ANYONECANPAY=128;lt.prototype.isCanonical=function(){var t=Zn(),e=t.getN().shrn(1);return this.s.lte(e)};lt.prototype.toCanonical=function(){if(this.isCanonical())return new lt({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var t=Zn(),e=t.getN(),r=e.sub(this.s);return new lt({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};lt.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 t=Zn(),e=t.getN();if(this.r.gte(e))throw new Error("Signature r component >= curve order");if(this.s.gte(e))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};lt.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};lt.prototype.applySecurityPatches=function(){var t=Zn(),e=t.getN(),r=e.shrn(1);if(this.r.isZero()||this.s.isZero())throw new Error("Invalid signature: zero r or s");if(this.r.gte(e)||this.s.gte(e))throw new Error("Invalid signature: out of range");if(this.s.gt(r))throw new Error("Invalid signature: non-canonical (high) s");return this};Th.exports=lt});var Or=Z((Lv,Fh)=>{"use strict";I();var xe=de(),Hi=Cn(),Ud=Dn(),Mh=Bh(),Os=Mh.SIGHASH_ALL|Mh.SIGHASH_FORKID;function Rh(){var t=xe.Script.Interpreter;return t.SCRIPT_VERIFY_P2SH|t.SCRIPT_VERIFY_STRICTENC|t.SCRIPT_VERIFY_DERSIG|t.SCRIPT_VERIFY_LOW_S|t.SCRIPT_VERIFY_MINIMALDATA|t.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY|t.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY|t.SCRIPT_ENABLE_SIGHASH_FORKID|t.SCRIPT_ENABLE_MAGNETIC_OPCODES|t.SCRIPT_ENABLE_MONOLITH_OPCODES}function qd(t){return xe.Script.Interpreter.useGenesisLimits(t)}function Dd(t,e,r){r=r||{};var n=new xe.Script.Interpreter,i=n.verify(t,e,r.tx||new xe.Transaction,r.inputIndex||0,r.flags||Rh(),new Hi(r.satoshis||0));return{ok:i,err:n.errstr||""}}function kh(t,e,r,n,i){return xe.Transaction.sighash.sighashPreimage(t,i||Os,e,r,new Hi(n))}function Gd(t,e,r,n,i){return Ud.sha256sha256(kh(t,e,r,n,i))}function zd(t,e,r,n,i,o){o=o||Os;var c=xe.Transaction.sighash.sign(t,e,o,r,n,new Hi(i));return E.Buffer.concat([c.toDER(),E.Buffer.from([o])])}function Vd(t,e,r){r=r||{};var n=new xe.Transaction().addOutput(new xe.Transaction.Output({script:t,satoshis:e})),i=new xe.Transaction;return i.addInput(new xe.Transaction.Input({prevTxId:n.hash,outputIndex:0,script:xe.Script.empty()}),t,e),r.outputs&&r.outputs.forEach(function(o){i.addOutput(o)}),{funding:n,spend:i}}function Kd(t,e){var r=t.toAddress?t.toAddress():t;return new xe.Transaction.Output({script:xe.Script.buildPublicKeyHashOut(r),satoshis:e})}function jd(t){return t===0?xe.Opcode.OP_0:t===-1?xe.Opcode.OP_1NEGATE:t>=1&&t<=16?xe.Opcode["OP_"+t]:new Hi(t).toScriptNumBuffer()}Fh.exports={SIGHASH:Os,flags:Rh,enableGenesis:qd,verify:Dd,rawPreimage:kh,sighashDigest:Gd,signInput:zd,fundAndSpend:Vd,p2pkhOutput:Kd,scriptNum:jd}});var qh=Z((Cv,Uh)=>{"use strict";I();var Hh=de(),Lh=Dn(),Nh=Or(),Ke=Hh.Script,ne=Hh.Opcode,Xn=Nh.signInput,Ch=Nh.scriptNum;function Yd(t){var e=Lh.sha256(t),r=new Ke().add(ne.OP_SHA256).add(e).add(ne.OP_EQUAL);return{lock:r,meta:{name:"hash-lock",digest:e.toString("hex")},unlock:function(n,i,o){return new Ke().add(o||t)}}}function $d(t){var e=t.toPublicKey(),r=Ke.buildPublicKeyHashOut(e.toAddress());return{lock:r,meta:{name:"p2pkh",address:e.toAddress().toString()},unlock:function(n,i){return new Ke().add(Xn(n,t,0,r,i)).add(e.toBuffer())}}}function Zd(t,e){var r=t.toPublicKey(),n=new Ke().add(Ch(e)).add(ne.OP_CHECKLOCKTIMEVERIFY).add(ne.OP_DROP).add(r.toBuffer()).add(ne.OP_CHECKSIG);return{lock:n,meta:{name:"cltv-timelock",locktime:e},unlock:function(i,o){return new Ke().add(Xn(i,t,0,n,o))}}}function Xd(t,e){var r=e.map(function(i){return i.toPublicKey()}),n=new Ke().add(ne["OP_"+t]);return r.forEach(function(i){n.add(i.toBuffer())}),n.add(ne["OP_"+r.length]).add(ne.OP_CHECKMULTISIG),{lock:n,meta:{name:t+"-of-"+r.length+"-multisig"},unlock:function(i,o,c){c=c||e.slice(0,t);var h=new Ke().add(ne.OP_0);return c.forEach(function(d){h.add(Xn(i,d,0,n,o))}),h}}}function Wd(t){var e=Lh.sha256(t.secret),r=new Ke().add(ne.OP_IF).add(ne.OP_SHA256).add(e).add(ne.OP_EQUALVERIFY).add(t.receiver.toPublicKey().toBuffer()).add(ne.OP_CHECKSIG).add(ne.OP_ELSE).add(Ch(t.timeout)).add(ne.OP_CHECKLOCKTIMEVERIFY).add(ne.OP_DROP).add(t.sender.toPublicKey().toBuffer()).add(ne.OP_CHECKSIG).add(ne.OP_ENDIF);return{lock:r,meta:{name:"htlc",digest:e.toString("hex"),timeout:t.timeout},unlockClaim:function(n,i){return new Ke().add(Xn(n,t.receiver,0,r,i)).add(t.secret).add(ne.OP_1)},unlockRefund:function(n,i){return new Ke().add(Xn(n,t.sender,0,r,i)).add(ne.OP_0)}}}Uh.exports={hashLock:Yd,p2pkh:$d,timeLockCLTV:Zd,multisig:Xd,htlc:Wd}});var Wn=Z((qv,$h)=>{"use strict";I();var Is=de(),Li=Cn(),Dh=Dn(),Ps=Or(),Gh=Is.Script,xt=Is.Opcode,Ts=Ps.SIGHASH,Ni=Ps.scriptNum,Bn=E.Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Bs=new Li("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",16),Qd=E.Buffer.concat([E.Buffer.from([2]),Bn]),zh=E.Buffer.from(Bn).reverse(),Vh=E.Buffer.concat([E.Buffer.from(Bs.toBuffer()).reverse(),E.Buffer.from([0])]),Jd=E.Buffer.concat([E.Buffer.from([48,68,2,32]),Bn,E.Buffer.from([2,32])]);function As(t,e){var r;for(r=0;r<e-1;r++)t.add(xt.OP_1).add(xt.OP_SPLIT);for(r=0;r<e-1;r++)t.add(xt.OP_SWAP).add(xt.OP_CAT);return t}var sr=Is.crypto.Signature,tp=sr.SIGHASH_ALL|sr.SIGHASH_FORKID,ep=sr.SIGHASH_SINGLE|sr.SIGHASH_FORKID,rp=sr.SIGHASH_SINGLE|sr.SIGHASH_ANYONECANPAY|sr.SIGHASH_FORKID,np=sr.SIGHASH_ALL|sr.SIGHASH_ANYONECANPAY|sr.SIGHASH_FORKID;function Ms(t,e){var r=e&&e.sighashType||Ts;return t.add(xt.OP_HASH256),As(t,32),t.add(zh).add(xt.OP_ADD),t.add(Vh).add(xt.OP_MOD),t.add(Ni(32)).add(xt.OP_NUM2BIN),As(t,32),t.add(Bn).add(xt.OP_DUP),t.add(xt.OP_2).add(xt.OP_SWAP).add(xt.OP_CAT),t.add(xt.OP_TOALTSTACK),t.add(E.Buffer.from([48,68,2,32])).add(xt.OP_SWAP).add(xt.OP_CAT),t.add(E.Buffer.from([2,32])).add(xt.OP_CAT),t.add(xt.OP_SWAP).add(xt.OP_CAT),t.add(E.Buffer.from([r])).add(xt.OP_CAT),t.add(xt.OP_FROMALTSTACK).add(xt.OP_CHECKSIG),t}function ip(){return Ms(new Gh)}function Kh(t){return t.add(Ni(40)).add(xt.OP_RIGHT).add(Ni(32)).add(xt.OP_LEFT),t}function op(t){return jh(t,Ts)}function jh(t,e){var r=E.Buffer.from([e&255,0,0,0]);return t.add(xt.OP_DUP).add(Ni(4)).add(xt.OP_RIGHT).add(r).add(xt.OP_EQUALVERIFY),t}function sp(t){var e=E.Buffer.concat(t.map(function(r){return r.toBufferWriter().toBuffer()}));return Dh.sha256sha256(e)}function ap(t){var e=new Gh().add(xt.OP_DUP);return Ms(e),e.add(xt.OP_VERIFY),Kh(e),e.add(E.Buffer.from(t)).add(xt.OP_EQUAL),e}var cp=new Li("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex");function Yh(t){var e=Dh.sha256sha256(t);if(e[0]<1||e[0]>127)return null;var r=new Li(e).add(new Li(Bn)).mod(Bs);if(r.gt(cp))return null;var n=r.toBuffer("be",32);return n[0]>=1?n:null}function up(t,e,r,n,i){typeof i=="number"&&(i={maxTries:i}),i=i||{};var o=i.maxTries||5e3,c=i.start||0,h=i.field||"nLockTime",d=i.sighashType||Ts;if(h!=="nLockTime"&&h!=="sequence")throw new Error("grind field must be 'nLockTime' or 'sequence'");for(var x=t.inputs[e],v=0;v<o;v++){var y=c+v;h==="nLockTime"?t.nLockTime=y:x.sequenceNumber=4294967294-y;var A=Ps.rawPreimage(t,e,r,n,d);if(Yh(A))return{preimage:A,tries:v+1,field:h,nonce:y}}throw new Error("OP_PUSH_TX grind failed after "+o+" tries")}$h.exports={Gx:Bn,N:Bs,PUBKEY:Qd,gxLe:zh,N_LE:Vh,DER_PREFIX:Jd,reverseBytes:As,pushTxCore:Ms,authenticator:ip,extractHashOutputs:Kh,assertSighashAll:op,assertSighashType:jh,SIGHASH_ALL_FORKID:tp,SIGHASH_SINGLE_FORKID:ep,SIGHASH_SINGLE_ANYONECANPAY_FORKID:rp,SIGHASH_ALL_ANYONECANPAY_FORKID:np,hashOutputs:sp,valueCovenant:ap,sFromPreimage:Yh,grind:up}});var ks=Z((Gv,Xh)=>{"use strict";I();var Zh=de(),Rs=Wn(),hp=Or(),fp=Zh.Script,ie=Zh.Opcode,Mn=hp.scriptNum;function lp(t){var e=new fp;return e.add(ie.OP_DUP),Rs.pushTxCore(e),e.add(ie.OP_VERIFY),Rs.assertSighashAll(e),e.add(ie.OP_DUP),e.add(Mn(104)).add(ie.OP_SPLIT).add(ie.OP_NIP),e.add(ie.OP_SIZE).add(Mn(52)).add(ie.OP_SUB).add(ie.OP_SPLIT).add(ie.OP_DROP),e.add(ie.OP_OVER),e.add(Mn(52)).add(ie.OP_RIGHT).add(Mn(8)).add(ie.OP_LEFT),e.add(ie.OP_BIN2NUM).add(Mn(t)).add(ie.OP_SUB),e.add(Mn(8)).add(ie.OP_NUM2BIN),e.add(ie.OP_SWAP).add(ie.OP_CAT),e.add(ie.OP_HASH256),e.add(ie.OP_SWAP),Rs.extractHashOutputs(e),e.add(ie.OP_EQUAL),e}Xh.exports={pelsCovenant:lp}});var Ls=Z((Vv,Qh)=>{"use strict";I();var Ui=de(),Wh=Dn(),Hs=Or(),It=Ui.Opcode,Rn=Hs.scriptNum;function Ci(t){return t instanceof Ui.PrivateKey?t.toPublicKey().toBuffer():t instanceof Ui.PublicKey?t.toBuffer():t}function dp(){return{name:"single-key",commit:function(t){return Wh.sha256ripemd160(Ci(t))},emit:function(t){return t.add(It.OP_OVER).add(It.OP_HASH160).add(It.OP_EQUALVERIFY),t.add(It.OP_CHECKSIGVERIFY),t},unlockArgs:function(t,e,r,n,i){var o=Hs.signInput(t,i,e,r,n);return[o,i.toPublicKey().toBuffer()]}}}function Fs(t,e){var r=e.length;if(t<1||t>r||r<1||r>16)throw new Error("multisig requires 1 <= m <= n <= 16");var n=new Ui.Script().add(It["OP_"+t]);return e.forEach(function(i){n.add(E.Buffer.from(i))}),n.add(It["OP_"+r]).add(It.OP_CHECKMULTISIG),n.toBuffer()}function pp(t,e){if(typeof e!="number"||!Number.isInteger(e))throw new Error("multisig(m, nKeys): nKeys is the NUMBER of keys, not the keys themselves"+(Array.isArray(e)?" \u2014 pass "+e.length+" instead of the array":""));if(typeof t!="number"||!Number.isInteger(t))throw new Error("multisig(m, nKeys): m must be an integer");if(t<1||t>e||e<1||e>16)throw new Error("multisig requires 1 <= m <= n <= 16");return{name:t+"-of-"+e+"-multisig",m:t,n:e,commit:function(r){if(r.length!==e)throw new Error("expected "+e+" public keys");return Wh.sha256ripemd160(Fs(t,r.map(Ci)))},emit:function(r){r.add(It.OP_OVER).add(It.OP_HASH160).add(It.OP_EQUALVERIFY),r.add(Rn(1)).add(It.OP_SPLIT).add(It.OP_NIP),r.add(It.OP_SIZE).add(Rn(2)).add(It.OP_SUB).add(It.OP_SPLIT).add(It.OP_DROP);for(var n=0;n<this.n;n++)r.add(Rn(34)).add(It.OP_SPLIT),r.add(It.OP_SWAP).add(Rn(1)).add(It.OP_SPLIT).add(It.OP_NIP),r.add(It.OP_TOALTSTACK);for(r.add(It.OP_DROP),r.add(Rn(this.m)),n=0;n<this.n;n++)r.add(It.OP_FROMALTSTACK);return r.add(Rn(this.n)),r.add(It.OP_CHECKMULTISIGVERIFY),r},unlockArgs:function(r,n,i,o,c){var h=c.keys;if(h.length!==e)throw new Error("expected "+e+" public keys in signer.keys");var d=Fs(t,h.map(Ci)),x=h.map(Ci).map(function(A){return A.toString("hex")}),v=c.signWith.map(function(A){var O=x.indexOf(A.toPublicKey().toBuffer().toString("hex"));if(O<0)throw new Error("signWith key is not in the committed key set");return{idx:O,priv:A}}).sort(function(A,O){return O.idx-A.idx}).slice(0,t);if(v.length<t)throw new Error("need at least "+t+" signing keys");var y=v.map(function(A){return Hs.signInput(r,A.priv,n,i,o)});return[It.OP_0].concat(y).concat([d])}}}function mp(t){if(!t||typeof t.emit!="function"||typeof t.unlockArgs!="function"||typeof t.commit!="function")throw new Error("predicate authorizer needs { commit, emit, unlockArgs } functions");return{name:t.name||"predicate",commit:t.commit,emit:t.emit,unlockArgs:t.unlockArgs}}Qh.exports={singleKey:dp,multisig:pp,predicate:mp,redeemScript:Fs}});var Us=Z((jv,af)=>{"use strict";I();var Ns=de(),Qn=Wn(),Cs=Or(),Jn=Ls(),qi=Ns.Script,rt=Ns.Opcode,ar=Cs.scriptNum;function tf(t,e){var r=E.Buffer.isBuffer(t)?t:e.commit(t);if(r.length!==20)throw new Error("owner commitment must be 20 bytes (HASH160)");return r}function Jh(t,e){return e.length?t.add(E.Buffer.from(e)):t.add(rt.OP_0)}function ef(t,e){return t.add(rt.OP_DUP),Qn.pushTxCore(t),t.add(rt.OP_VERIFY),Qn.assertSighashAll(t),t.add(rt.OP_DUP).add(ar(52)).add(rt.OP_RIGHT).add(ar(8)).add(rt.OP_LEFT).add(rt.OP_TOALTSTACK),t.add(rt.OP_DUP),Qn.extractHashOutputs(t),t.add(rt.OP_TOALTSTACK),t.add(ar(104)).add(rt.OP_SPLIT).add(rt.OP_NIP).add(rt.OP_SIZE).add(ar(52)).add(rt.OP_SUB).add(rt.OP_SPLIT).add(rt.OP_DROP),t.add(rt.OP_DUP).add(ar(4)).add(ar(20)).add(rt.OP_SUBSTR),t.add(rt.OP_SWAP).add(rt.OP_TOALTSTACK),e.emit(t),t.add(rt.OP_FROMALTSTACK),t}function rf(t){return t.add(ar(4)).add(rt.OP_SPLIT).add(ar(20)).add(rt.OP_SPLIT).add(rt.OP_NIP),t.add(rt.OP_TOALTSTACK),t.add(rt.OP_SWAP).add(rt.OP_CAT),t.add(rt.OP_FROMALTSTACK).add(rt.OP_CAT),t}function nf(t){var e=t.toBuffer().length;if(e<=252||e>65535)throw new Error("token script length must use a 3-byte varint (253..65535); got "+e);return t}function gp(t,e,r){r=r||Jn.singleKey();var n=new qi;return n.add(tf(e,r)),n.add(rt.OP_DROP),ef(n,r),rf(n),n.add(rt.OP_FROMALTSTACK),n.add(rt.OP_SWAP),n.add(rt.OP_FROMALTSTACK),n.add(rt.OP_BIN2NUM).add(ar(t)).add(rt.OP_SUB).add(ar(8)).add(rt.OP_NUM2BIN),n.add(rt.OP_SWAP).add(rt.OP_CAT),n.add(rt.OP_HASH256),n.add(rt.OP_EQUAL),nf(n)}function of(t,e){e=e||Jn.singleKey();var r=new qi;return r.add(tf(t,e)),r.add(rt.OP_DROP),ef(r,e),rf(r),r.add(rt.OP_CAT),r.add(rt.OP_SWAP).add(rt.OP_CAT),r.add(rt.OP_CAT),r.add(rt.OP_FROMALTSTACK),r.add(rt.OP_FROMALTSTACK).add(rt.OP_DROP),r.add(rt.OP_SWAP).add(rt.OP_HASH256).add(rt.OP_EQUAL),nf(r)}function vp(t){return Jn.singleKey().commit(t)}function xp(t,e,r,n,i,o){o=o||{};var c=o.auth||Jn.singleKey(),h=o.inputIndex||0;if(e.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(n<=1&&!o.allowLowValue)throw new Error("unlockTransfer: single-output token sets output = input - fee, which burns a "+n+"-sat UTXO (e.g. a 1-sat ordinal). Use Token.transferOrdinal / ownershipTokenMulti to preserve the satoshi.");Qn.grind(r,h,i,n,o.grind);var d=Cs.rawPreimage(r,h,i,n),x=c.unlockArgs(r,h,i,n,t),v=new qi().add(E.Buffer.from(e));return x.forEach(function(y){v.add(y)}),v.add(E.Buffer.from(d)),v}function sf(t,e,r,n,i,o,c){c=c||{};var h=c.auth||Jn.singleKey(),d=c.inputIndex||0;if(e.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");Qn.grind(r,d,i,n,c.grind);var x=Cs.rawPreimage(r,d,i,n),v=h.unlockArgs(r,d,i,n,t),y=new qi;return Jh(y,o.before||E.Buffer.alloc(0)),Jh(y,o.after||E.Buffer.alloc(0)),y.add(E.Buffer.from(o.tokenValue)),y.add(E.Buffer.from(e)),v.forEach(function(A){y.add(A)}),y.add(E.Buffer.from(x)),y}function yp(t,e){return of(t,e)}function wp(t,e,r,n,i,o){o=o||{},n==null&&(n=1);var c=o.tokenIndex||0,h=r.outputs||[],d=h[c];if(!d)throw new Error("transferOrdinal: spend has no output at tokenIndex "+c);if(d.satoshis!==n)throw new Error("transferOrdinal: token output value ("+d.satoshis+" sat) must equal the ordinal value ("+n+" sat) to avoid burning the inscription");function x(O){return O.toBufferWriter().toBuffer()}var v=E.Buffer.concat(h.slice(0,c).map(x)),y=E.Buffer.concat(h.slice(c+1).map(x)),A=new Ns.crypto.BN(n).toBuffer({endian:"little",size:8});return sf(t,e,r,n,i,{before:v,after:y,tokenValue:A},o)}af.exports={ownershipToken:gp,ownershipTokenMulti:of,ordinalLock:yp,ownerId:vp,unlockTransfer:xp,unlockTransferMulti:sf,transferOrdinal:wp}});var js=Z(($v,cf)=>{"use strict";I();var zs=de(),Di=Wn(),bp=ks(),Sp=Us(),Vs=Or(),Ds=zs.Script,Ne=zs.Opcode,Gs=zs.Transaction,qs=Vs.scriptNum;function Ep(t,e){return t instanceof Gs.Output?t:t instanceof Ds?new Gs.Output({script:t,satoshis:e}):Vs.p2pkhOutput(t,e)}function _p(t,e,r,n,i,o){o=o||5e4;for(var c=0;c<o;c++){t.nLockTime=i+c;var h=Vs.rawPreimage(t,e,r,n);if(Di.sFromPreimage(h))return h}throw new Error("covenant grind failed after "+o+" tries")}function Ar(){if(!(this instanceof Ar))return new Ar;this._outputs=[],this._minLockTime=null}Ar.prototype.payTo=function(t,e){return this._outputs.push(Ep(t,e)),this};Ar.prototype.lockUntil=function(t){return this._minLockTime=t,this};Ar.prototype.outputs=function(){return this._outputs.map(function(t){return new Gs.Output(t.toObject())})};Ar.prototype.describe=function(){var t=[];return this._outputs.forEach(function(e,r){t.push("output["+r+"] = "+e.satoshis+" sat to "+e.script.toASM().slice(0,24)+"...")}),this._minLockTime!==null&&t.push("nLockTime >= "+this._minLockTime),"spend allowed iff: "+t.join(" AND ")};Ar.prototype.compile=function(){if(this._outputs.length===0&&this._minLockTime===null)throw new Error("empty policy: add at least one constraint (payTo / lockUntil)");var t=this,e=new Ds().add(Ne.OP_DUP);if(Di.pushTxCore(e),e.add(Ne.OP_VERIFY),this._outputs.length){var r=Di.hashOutputs(this._outputs);e.add(Ne.OP_DUP),Di.extractHashOutputs(e),e.add(E.Buffer.from(r)).add(Ne.OP_EQUALVERIFY)}return this._minLockTime!==null&&(e.add(Ne.OP_DUP),e.add(qs(8)).add(Ne.OP_RIGHT).add(qs(4)).add(Ne.OP_LEFT),e.add(Ne.OP_BIN2NUM).add(qs(this._minLockTime)).add(Ne.OP_GREATERTHANOREQUAL).add(Ne.OP_VERIFY)),e.add(Ne.OP_DROP).add(Ne.OP_1),{lock:e,outputs:t.outputs(),describe:function(){return t.describe()},unlock:function(n,i,o){o=o||0;var c=t._minLockTime===null?0:t._minLockTime;return t._minLockTime!==null&&(n.inputs[o].sequenceNumber=4294967294),new Ds().add(_p(n,o,e,i,c))}}};function Ks(){return new Ar}Ks.perpetual=function(t){return bp.pelsCovenant(t)};Ks.token=function(t,e){return Sp.ownershipToken(t,e)};cf.exports={policy:Ks,Policy:Ar}});var df=Z((Xv,lf)=>{"use strict";I();var Gi=de(),Op=Or();function hf(t){if(t===0)return"OP_0";if(t>=1&&t<=75)return"PUSH("+t+")";if(t===76)return"OP_PUSHDATA1";if(t===77)return"OP_PUSHDATA2";if(t===78)return"OP_PUSHDATA4";try{return Gi.Opcode.fromNumber(t).toString()}catch{return"0x"+t.toString(16)}}function uf(t,e){e=e||16;var r=E.Buffer.from(t).toString("hex");return r.length<=e*2?r||"0":r.slice(0,e*2)+"...("+t.length+"B)"}function Ap(t,e,r){r=r||{};var n=new Gi.Script.Interpreter,i=[];n.stepListener=function(c,h,d){i.push({phase:n.script===e?"lock":"unlock",op:hf(c.opcode&&typeof c.opcode.toNumber=="function"?c.opcode.toNumber():c.opcode.num),stack:h.map(function(x){return uf(x)}),altstack:d.map(function(x){return uf(x)})})};var o=n.verify(t,e,r.tx||new Gi.Transaction,r.inputIndex||0,typeof r.flags=="number"?r.flags:Op.flags(),new Gi.crypto.BN(r.satoshis||0));return{ok:o,err:n.errstr||"",steps:i}}function ff(t){var e=[],r=null;return t.steps.forEach(function(n,i){n.phase!==r&&(e.push("-- "+n.phase+" script --"),r=n.phase);var o=n.stack.length?n.stack.join(" | "):"(empty)",c=n.altstack.length?" alt:["+n.altstack.join(" | ")+"]":"";e.push(String(i).padStart(3)+" "+n.op.padEnd(16)+" -> ["+o+"]"+c)}),e.push((t.ok?"VALID":"INVALID")+(t.err?" ("+t.err+")":"")),e.join(`
|
|
25
|
-
`)}function Ip(t){return console.log(ff(t)),t}lf.exports={trace:Ap,format:ff,print:Ip,opLabel:hf}});var mf=Z((Qv,pf)=>{"use strict";I();pf.exports="7.
|
|
24
|
+
`+new Error().stack};un.Error.prototype=Object.create(Error.prototype);un.Error.prototype.name="bsv.Error";var Tl=Sc();Pl(un.Error,Tl);qo.exports=un.Error;qo.exports.extend=function(t){return Ec(un.Error,t)}});var hn=Z((Um,Ac)=>{"use strict";I();var Cn=Oc(),Bl=cn();Ac.exports={checkState:function(t,e){if(!t)throw new Cn.InvalidState(e)},checkArgument:function(t,e,r,n){if(!t)throw new Cn.InvalidArgument(e,r,n)},checkArgumentType:function(t,e,r){if(r=r||"(unknown name)",Bl.isString(e)){if(e==="Buffer"){var n=si();if(!n.Buffer.isBuffer(t))throw new Cn.InvalidArgumentType(t,e,r)}else if(typeof t!==e)throw new Cn.InvalidArgumentType(t,e,r)}else if(!(t instanceof e))throw new Cn.InvalidArgumentType(t,e.name,r)}}});var Nn=Z((Dm,Pc)=>{"use strict";I();var mt=vc(),Do=hn(),Ic=cn(),hi=function(t){for(var e=E.Buffer.alloc(t.length),r=0;r<t.length;r++)e[r]=t[t.length-1-r];return e};mt.Zero=new mt(0);mt.One=new mt(1);mt.Minus1=new mt(-1);mt.fromNumber=function(t){return Do.checkArgument(Ic.isNumber(t)),new mt(t)};mt.fromString=function(t,e){return Do.checkArgument(Ic.isString(t)),new mt(t,e)};mt.fromBuffer=function(t,e){typeof e<"u"&&e.endian==="little"&&(t=hi(t));var r=t.toString("hex"),n=new mt(r,16);return n};mt.fromSM=function(t,e){var r;if(t.length===0)return mt.fromBuffer(E.Buffer.from([0]));var n="big";return e&&(n=e.endian),n==="little"&&(t=hi(t)),t[0]&128?(t[0]=t[0]&127,r=mt.fromBuffer(t),r.neg().copy(r)):r=mt.fromBuffer(t),r};mt.prototype.toNumber=function(){return parseInt(this.toString(10),10)};mt.prototype.toBuffer=function(t){var e,r;if(t&&t.size){r=this.toString(16,2);var n=r.length/2;e=E.Buffer.from(r,"hex"),n===t.size||(n>t.size?e=mt.trim(e,n):n<t.size&&(e=mt.pad(e,n,t.size)))}else r=this.toString(16,2),e=E.Buffer.from(r,"hex");return typeof t<"u"&&t.endian==="little"&&(e=hi(e)),e};mt.prototype.toSMBigEndian=function(){var t;return this.cmp(mt.Zero)===-1?(t=this.neg().toBuffer(),t[0]&128?t=E.Buffer.concat([E.Buffer.from([128]),t]):t[0]=t[0]|128):(t=this.toBuffer(),t[0]&128&&(t=E.Buffer.concat([E.Buffer.from([0]),t]))),t.length===1&&t[0]===0&&(t=E.Buffer.from([])),t};mt.prototype.toSM=function(t){var e=t?t.endian:"big",r=this.toSMBigEndian();return e==="little"&&(r=hi(r)),r};mt.fromScriptNumBuffer=function(t,e,r){var n=r||4;if(Do.checkArgument(t.length<=n,new Error("script number overflow")),e&&t.length>0&&(t[t.length-1]&127)===0&&(t.length<=1||(t[t.length-2]&128)===0))throw new Error("non-minimally encoded script number");return mt.fromSM(t,{endian:"little"})};mt.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})};mt.trim=function(t,e){return t.slice(e-t.length,t.length)};mt.pad=function(t,e,r){for(var n=E.Buffer.alloc(r),i=0;i<t.length;i++)n[n.length-1-i]=t[t.length-1-i];for(i=0;i<r-e;i++)n[i]=0;return n};mt.prototype.toHex=function(...t){return this.toBuffer(...t).toString("hex")};mt.fromHex=function(t,...e){return mt.fromBuffer(E.Buffer.from(t,"hex"),...e)};Pc.exports=mt});var fn=Z((zm,Bc)=>{I();Bc.exports=Tc;function Tc(t,e){if(!t)throw new Error(e||"Assertion failed")}Tc.equal=function(e,r,n){if(e!=r)throw new Error(n||"Assertion failed: "+e+" != "+r)}});var Mc=Z((Km,Go)=>{I();typeof Object.create=="function"?Go.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:Go.exports=function(e,r){if(r){e.super_=r;var n=function(){};n.prototype=r.prototype,e.prototype=new n,e.prototype.constructor=e}}});var qe=Z(wt=>{"use strict";I();var Ml=fn(),Rl=Mc();wt.inherits=Rl;function kl(t,e){return(t.charCodeAt(e)&64512)!==55296||e<0||e+1>=t.length?!1:(t.charCodeAt(e+1)&64512)===56320}function Fl(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if(typeof t=="string")if(e){if(e==="hex")for(t=t.replace(/[^a-z0-9]+/ig,""),t.length%2!==0&&(t="0"+t),i=0;i<t.length;i+=2)r.push(parseInt(t[i]+t[i+1],16))}else for(var n=0,i=0;i<t.length;i++){var o=t.charCodeAt(i);o<128?r[n++]=o:o<2048?(r[n++]=o>>6|192,r[n++]=o&63|128):kl(t,i)?(o=65536+((o&1023)<<10)+(t.charCodeAt(++i)&1023),r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=o&63|128):(r[n++]=o>>12|224,r[n++]=o>>6&63|128,r[n++]=o&63|128)}else for(i=0;i<t.length;i++)r[i]=t[i]|0;return r}wt.toArray=Fl;function Hl(t){for(var e="",r=0;r<t.length;r++)e+=kc(t[r].toString(16));return e}wt.toHex=Hl;function Rc(t){var e=t>>>24|t>>>8&65280|t<<8&16711680|(t&255)<<24;return e>>>0}wt.htonl=Rc;function Ll(t,e){for(var r="",n=0;n<t.length;n++){var i=t[n];e==="little"&&(i=Rc(i)),r+=Fc(i.toString(16))}return r}wt.toHex32=Ll;function kc(t){return t.length===1?"0"+t:t}wt.zero2=kc;function Fc(t){return t.length===7?"0"+t:t.length===6?"00"+t:t.length===5?"000"+t:t.length===4?"0000"+t:t.length===3?"00000"+t:t.length===2?"000000"+t:t.length===1?"0000000"+t:t}wt.zero8=Fc;function Cl(t,e,r,n){var i=r-e;Ml(i%4===0);for(var o=new Array(i/4),c=0,h=e;c<o.length;c++,h+=4){var d;n==="big"?d=t[h]<<24|t[h+1]<<16|t[h+2]<<8|t[h+3]:d=t[h+3]<<24|t[h+2]<<16|t[h+1]<<8|t[h],o[c]=d>>>0}return o}wt.join32=Cl;function Nl(t,e){for(var r=new Array(t.length*4),n=0,i=0;n<t.length;n++,i+=4){var o=t[n];e==="big"?(r[i]=o>>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=o&255):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=o&255)}return r}wt.split32=Nl;function Ul(t,e){return t>>>e|t<<32-e}wt.rotr32=Ul;function ql(t,e){return t<<e|t>>>32-e}wt.rotl32=ql;function Dl(t,e){return t+e>>>0}wt.sum32=Dl;function Gl(t,e,r){return t+e+r>>>0}wt.sum32_3=Gl;function zl(t,e,r,n){return t+e+r+n>>>0}wt.sum32_4=zl;function Vl(t,e,r,n,i){return t+e+r+n+i>>>0}wt.sum32_5=Vl;function Kl(t,e,r,n){var i=t[e],o=t[e+1],c=n+o>>>0,h=(c<n?1:0)+r+i;t[e]=h>>>0,t[e+1]=c}wt.sum64=Kl;function jl(t,e,r,n){var i=e+n>>>0,o=(i<e?1:0)+t+r;return o>>>0}wt.sum64_hi=jl;function Yl(t,e,r,n){var i=e+n;return i>>>0}wt.sum64_lo=Yl;function $l(t,e,r,n,i,o,c,h){var d=0,x=e;x=x+n>>>0,d+=x<e?1:0,x=x+o>>>0,d+=x<o?1:0,x=x+h>>>0,d+=x<h?1:0;var v=t+r+i+c+d;return v>>>0}wt.sum64_4_hi=$l;function Zl(t,e,r,n,i,o,c,h){var d=e+n+o+h;return d>>>0}wt.sum64_4_lo=Zl;function Xl(t,e,r,n,i,o,c,h,d,x){var v=0,y=e;y=y+n>>>0,v+=y<e?1:0,y=y+o>>>0,v+=y<o?1:0,y=y+h>>>0,v+=y<h?1:0,y=y+x>>>0,v+=y<x?1:0;var A=t+r+i+c+d+v;return A>>>0}wt.sum64_5_hi=Xl;function Wl(t,e,r,n,i,o,c,h,d,x){var v=e+n+o+h+x;return v>>>0}wt.sum64_5_lo=Wl;function Ql(t,e,r){var n=e<<32-r|t>>>r;return n>>>0}wt.rotr64_hi=Ql;function Jl(t,e,r){var n=t<<32-r|e>>>r;return n>>>0}wt.rotr64_lo=Jl;function t0(t,e,r){return t>>>r}wt.shr64_hi=t0;function e0(t,e,r){var n=t<<32-r|e>>>r;return n>>>0}wt.shr64_lo=e0});var ln=Z(Lc=>{"use strict";I();var Hc=qe(),r0=fn();function fi(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}Lc.BlockHash=fi;fi.prototype.update=function(e,r){if(e=Hc.toArray(e,r),this.pending?this.pending=this.pending.concat(e):this.pending=e,this.pendingTotal+=e.length,this.pending.length>=this._delta8){e=this.pending;var n=e.length%this._delta8;this.pending=e.slice(e.length-n,e.length),this.pending.length===0&&(this.pending=null),e=Hc.join32(e,0,e.length-n,this.endian);for(var i=0;i<e.length;i+=this._delta32)this._update(e,i,i+this._delta32)}return this};fi.prototype.digest=function(e){return this.update(this._pad()),r0(this.pending===null),this._digest(e)};fi.prototype._pad=function(){var e=this.pendingTotal,r=this._delta8,n=r-(e+this.padLength)%r,i=new Array(n+this.padLength);i[0]=128;for(var o=1;o<n;o++)i[o]=0;if(e<<=3,this.endian==="big"){for(var c=8;c<this.padLength;c++)i[o++]=0;i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=e>>>24&255,i[o++]=e>>>16&255,i[o++]=e>>>8&255,i[o++]=e&255}else for(i[o++]=e&255,i[o++]=e>>>8&255,i[o++]=e>>>16&255,i[o++]=e>>>24&255,i[o++]=0,i[o++]=0,i[o++]=0,i[o++]=0,c=8;c<this.padLength;c++)i[o++]=0;return i}});var zo=Z(mr=>{"use strict";I();var n0=qe(),We=n0.rotr32;function i0(t,e,r,n){if(t===0)return Cc(e,r,n);if(t===1||t===3)return Uc(e,r,n);if(t===2)return Nc(e,r,n)}mr.ft_1=i0;function Cc(t,e,r){return t&e^~t&r}mr.ch32=Cc;function Nc(t,e,r){return t&e^t&r^e&r}mr.maj32=Nc;function Uc(t,e,r){return t^e^r}mr.p32=Uc;function o0(t){return We(t,2)^We(t,13)^We(t,22)}mr.s0_256=o0;function s0(t){return We(t,6)^We(t,11)^We(t,25)}mr.s1_256=s0;function a0(t){return We(t,7)^We(t,18)^t>>>3}mr.g0_256=a0;function c0(t){return We(t,17)^We(t,19)^t>>>10}mr.g1_256=c0});var Gc=Z((Jm,Dc)=>{"use strict";I();var dn=qe(),u0=ln(),h0=zo(),Vo=dn.rotl32,Un=dn.sum32,f0=dn.sum32_5,l0=h0.ft_1,qc=u0.BlockHash,d0=[1518500249,1859775393,2400959708,3395469782];function Qe(){if(!(this instanceof Qe))return new Qe;qc.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}dn.inherits(Qe,qc);Dc.exports=Qe;Qe.blockSize=512;Qe.outSize=160;Qe.hmacStrength=80;Qe.padLength=64;Qe.prototype._update=function(e,r){for(var n=this.W,i=0;i<16;i++)n[i]=e[r+i];for(;i<n.length;i++)n[i]=Vo(n[i-3]^n[i-8]^n[i-14]^n[i-16],1);var o=this.h[0],c=this.h[1],h=this.h[2],d=this.h[3],x=this.h[4];for(i=0;i<n.length;i++){var v=~~(i/20),y=f0(Vo(o,5),l0(v,c,h,d),x,n[i],d0[v]);x=d,d=h,h=Vo(c,30),c=o,o=y}this.h[0]=Un(this.h[0],o),this.h[1]=Un(this.h[1],c),this.h[2]=Un(this.h[2],h),this.h[3]=Un(this.h[3],d),this.h[4]=Un(this.h[4],x)};Qe.prototype._digest=function(e){return e==="hex"?dn.toHex32(this.h,"big"):dn.split32(this.h,"big")}});var Ko=Z((eg,Vc)=>{"use strict";I();var pn=qe(),p0=ln(),mn=zo(),m0=fn(),De=pn.sum32,g0=pn.sum32_4,v0=pn.sum32_5,x0=mn.ch32,y0=mn.maj32,w0=mn.s0_256,b0=mn.s1_256,S0=mn.g0_256,E0=mn.g1_256,zc=p0.BlockHash,_0=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function Je(){if(!(this instanceof Je))return new Je;zc.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=_0,this.W=new Array(64)}pn.inherits(Je,zc);Vc.exports=Je;Je.blockSize=512;Je.outSize=256;Je.hmacStrength=192;Je.padLength=64;Je.prototype._update=function(e,r){for(var n=this.W,i=0;i<16;i++)n[i]=e[r+i];for(;i<n.length;i++)n[i]=g0(E0(n[i-2]),n[i-7],S0(n[i-15]),n[i-16]);var o=this.h[0],c=this.h[1],h=this.h[2],d=this.h[3],x=this.h[4],v=this.h[5],y=this.h[6],A=this.h[7];for(m0(this.k.length===n.length),i=0;i<n.length;i++){var O=v0(A,b0(x),x0(x,v,y),this.k[i],n[i]),T=De(w0(o),y0(o,c,h));A=y,y=v,v=x,x=De(d,O),d=h,h=c,c=o,o=De(O,T)}this.h[0]=De(this.h[0],o),this.h[1]=De(this.h[1],c),this.h[2]=De(this.h[2],h),this.h[3]=De(this.h[3],d),this.h[4]=De(this.h[4],x),this.h[5]=De(this.h[5],v),this.h[6]=De(this.h[6],y),this.h[7]=De(this.h[7],A)};Je.prototype._digest=function(e){return e==="hex"?pn.toHex32(this.h,"big"):pn.split32(this.h,"big")}});var Yc=Z((ng,jc)=>{"use strict";I();var jo=qe(),Kc=Ko();function gr(){if(!(this instanceof gr))return new gr;Kc.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}jo.inherits(gr,Kc);jc.exports=gr;gr.blockSize=512;gr.outSize=224;gr.hmacStrength=192;gr.padLength=64;gr.prototype._digest=function(e){return e==="hex"?jo.toHex32(this.h.slice(0,7),"big"):jo.split32(this.h.slice(0,7),"big")}});var Zo=Z((og,Wc)=>{"use strict";I();var _e=qe(),O0=ln(),A0=fn(),tr=_e.rotr64_hi,er=_e.rotr64_lo,$c=_e.shr64_hi,Zc=_e.shr64_lo,Tr=_e.sum64,Yo=_e.sum64_hi,$o=_e.sum64_lo,I0=_e.sum64_4_hi,P0=_e.sum64_4_lo,T0=_e.sum64_5_hi,B0=_e.sum64_5_lo,Xc=O0.BlockHash,M0=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function Ge(){if(!(this instanceof Ge))return new Ge;Xc.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=M0,this.W=new Array(160)}_e.inherits(Ge,Xc);Wc.exports=Ge;Ge.blockSize=1024;Ge.outSize=512;Ge.hmacStrength=192;Ge.padLength=128;Ge.prototype._prepareBlock=function(e,r){for(var n=this.W,i=0;i<32;i++)n[i]=e[r+i];for(;i<n.length;i+=2){var o=G0(n[i-4],n[i-3]),c=z0(n[i-4],n[i-3]),h=n[i-14],d=n[i-13],x=q0(n[i-30],n[i-29]),v=D0(n[i-30],n[i-29]),y=n[i-32],A=n[i-31];n[i]=I0(o,c,h,d,x,v,y,A),n[i+1]=P0(o,c,h,d,x,v,y,A)}};Ge.prototype._update=function(e,r){this._prepareBlock(e,r);var n=this.W,i=this.h[0],o=this.h[1],c=this.h[2],h=this.h[3],d=this.h[4],x=this.h[5],v=this.h[6],y=this.h[7],A=this.h[8],O=this.h[9],T=this.h[10],L=this.h[11],U=this.h[12],D=this.h[13],et=this.h[14],J=this.h[15];A0(this.k.length===n.length);for(var Y=0;Y<n.length;Y+=2){var $=et,ft=J,Pt=N0(A,O),nt=U0(A,O),dt=R0(A,O,T,L,U,D),b=k0(A,O,T,L,U,D),s=this.k[Y],u=this.k[Y+1],f=n[Y],l=n[Y+1],p=T0($,ft,Pt,nt,dt,b,s,u,f,l),w=B0($,ft,Pt,nt,dt,b,s,u,f,l);$=L0(i,o),ft=C0(i,o),Pt=F0(i,o,c,h,d,x),nt=H0(i,o,c,h,d,x);var S=Yo($,ft,Pt,nt),m=$o($,ft,Pt,nt);et=U,J=D,U=T,D=L,T=A,L=O,A=Yo(v,y,p,w),O=$o(y,y,p,w),v=d,y=x,d=c,x=h,c=i,h=o,i=Yo(p,w,S,m),o=$o(p,w,S,m)}Tr(this.h,0,i,o),Tr(this.h,2,c,h),Tr(this.h,4,d,x),Tr(this.h,6,v,y),Tr(this.h,8,A,O),Tr(this.h,10,T,L),Tr(this.h,12,U,D),Tr(this.h,14,et,J)};Ge.prototype._digest=function(e){return e==="hex"?_e.toHex32(this.h,"big"):_e.split32(this.h,"big")};function R0(t,e,r,n,i){var o=t&r^~t&i;return o<0&&(o+=4294967296),o}function k0(t,e,r,n,i,o){var c=e&n^~e&o;return c<0&&(c+=4294967296),c}function F0(t,e,r,n,i){var o=t&r^t&i^r&i;return o<0&&(o+=4294967296),o}function H0(t,e,r,n,i,o){var c=e&n^e&o^n&o;return c<0&&(c+=4294967296),c}function L0(t,e){var r=tr(t,e,28),n=tr(e,t,2),i=tr(e,t,7),o=r^n^i;return o<0&&(o+=4294967296),o}function C0(t,e){var r=er(t,e,28),n=er(e,t,2),i=er(e,t,7),o=r^n^i;return o<0&&(o+=4294967296),o}function N0(t,e){var r=tr(t,e,14),n=tr(t,e,18),i=tr(e,t,9),o=r^n^i;return o<0&&(o+=4294967296),o}function U0(t,e){var r=er(t,e,14),n=er(t,e,18),i=er(e,t,9),o=r^n^i;return o<0&&(o+=4294967296),o}function q0(t,e){var r=tr(t,e,1),n=tr(t,e,8),i=$c(t,e,7),o=r^n^i;return o<0&&(o+=4294967296),o}function D0(t,e){var r=er(t,e,1),n=er(t,e,8),i=Zc(t,e,7),o=r^n^i;return o<0&&(o+=4294967296),o}function G0(t,e){var r=tr(t,e,19),n=tr(e,t,29),i=$c(t,e,6),o=r^n^i;return o<0&&(o+=4294967296),o}function z0(t,e){var r=er(t,e,19),n=er(e,t,29),i=Zc(t,e,6),o=r^n^i;return o<0&&(o+=4294967296),o}});var tu=Z((ag,Jc)=>{"use strict";I();var Xo=qe(),Qc=Zo();function vr(){if(!(this instanceof vr))return new vr;Qc.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}Xo.inherits(vr,Qc);Jc.exports=vr;vr.blockSize=1024;vr.outSize=384;vr.hmacStrength=192;vr.padLength=128;vr.prototype._digest=function(e){return e==="hex"?Xo.toHex32(this.h.slice(0,12),"big"):Xo.split32(this.h.slice(0,12),"big")}});var eu=Z(gn=>{"use strict";I();gn.sha1=Gc();gn.sha224=Yc();gn.sha256=Ko();gn.sha384=tu();gn.sha512=Zo()});var au=Z(su=>{"use strict";I();var Cr=qe(),V0=ln(),li=Cr.rotl32,ru=Cr.sum32,qn=Cr.sum32_3,nu=Cr.sum32_4,ou=V0.BlockHash;function rr(){if(!(this instanceof rr))return new rr;ou.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}Cr.inherits(rr,ou);su.ripemd160=rr;rr.blockSize=512;rr.outSize=160;rr.hmacStrength=192;rr.padLength=64;rr.prototype._update=function(e,r){for(var n=this.h[0],i=this.h[1],o=this.h[2],c=this.h[3],h=this.h[4],d=n,x=i,v=o,y=c,A=h,O=0;O<80;O++){var T=ru(li(nu(n,iu(O,i,o,c),e[Y0[O]+r],K0(O)),Z0[O]),h);n=h,h=c,c=li(o,10),o=i,i=T,T=ru(li(nu(d,iu(79-O,x,v,y),e[$0[O]+r],j0(O)),X0[O]),A),d=A,A=y,y=li(v,10),v=x,x=T}T=qn(this.h[1],o,y),this.h[1]=qn(this.h[2],c,A),this.h[2]=qn(this.h[3],h,d),this.h[3]=qn(this.h[4],n,x),this.h[4]=qn(this.h[0],i,v),this.h[0]=T};rr.prototype._digest=function(e){return e==="hex"?Cr.toHex32(this.h,"little"):Cr.split32(this.h,"little")};function iu(t,e,r,n){return t<=15?e^r^n:t<=31?e&r|~e&n:t<=47?(e|~r)^n:t<=63?e&n|r&~n:e^(r|~n)}function K0(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function j0(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}var Y0=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],$0=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Z0=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],X0=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]});var uu=Z((dg,cu)=>{"use strict";I();var W0=qe(),Q0=fn();function vn(t,e,r){if(!(this instanceof vn))return new vn(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(W0.toArray(e,r))}cu.exports=vn;vn.prototype._init=function(e){e.length>this.blockSize&&(e=new this.Hash().update(e).digest()),Q0(e.length<=this.blockSize);for(var r=e.length;r<this.blockSize;r++)e.push(0);for(r=0;r<e.length;r++)e[r]^=54;for(this.inner=new this.Hash().update(e),r=0;r<e.length;r++)e[r]^=106;this.outer=new this.Hash().update(e)};vn.prototype.update=function(e,r){return this.inner.update(e,r),this};vn.prototype.digest=function(e){return this.outer.update(this.inner.digest()),this.outer.digest(e)}});var fu=Z(hu=>{I();var me=hu;me.utils=qe();me.common=ln();me.sha=eu();me.ripemd=au();me.hmac=uu();me.sha1=me.sha.sha1;me.sha256=me.sha.sha256;me.sha224=me.sha.sha224;me.sha384=me.sha.sha384;me.sha512=me.sha.sha512;me.ripemd160=me.ripemd.ripemd160});var du=Z((vg,lu)=>{"use strict";I();var di=fu(),xr=hn(),te=lu.exports;te.sha1=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha1().update(t).digest("hex"),"hex")};te.sha1.blocksize=512;te.sha256=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha256().update(t).digest("hex"),"hex")};te.sha256.blocksize=512;te.sha256sha256=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),te.sha256(te.sha256(t))};te.ripemd160=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.ripemd160().update(t).digest("hex"),"hex")};te.sha256ripemd160=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),te.ripemd160(te.sha256(t))};te.sha512=function(t){return xr.checkArgument(E.Buffer.isBuffer(t)),E.Buffer.from(di.sha512().update(t).digest("hex"),"hex")};te.sha512.blocksize=1024;te.hmac=function(t,e,r){xr.checkArgument(E.Buffer.isBuffer(e)),xr.checkArgument(E.Buffer.isBuffer(r)),xr.checkArgument(t.blocksize);var n=t.blocksize/8;if(r.length>n)r=t(r);else if(r.length<n){var i=E.Buffer.alloc(n);i.fill(0),r.copy(i),r=i}var o=E.Buffer.alloc(n);o.fill(92);var c=E.Buffer.alloc(n);c.fill(54);for(var h=E.Buffer.alloc(n),d=E.Buffer.alloc(n),x=0;x<n;x++)h[x]=o[x]^r[x],d[x]=c[x]^r[x];return t(E.Buffer.concat([h,t(E.Buffer.concat([d,e]))]))};te.sha256hmac=function(t,e){return te.hmac(te.sha256,t,e)};te.sha512hmac=function(t,e){return te.hmac(te.sha512,t,e)}});var mu=Z((yg,pu)=>{"use strict";I();var pi=se(),yr=hn(),ee=pu.exports;ee.sha1=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha1").update(t).digest()};ee.sha1.blocksize=512;ee.sha256=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha256").update(t).digest()};ee.sha256.blocksize=512;ee.sha256sha256=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),ee.sha256(ee.sha256(t))};ee.ripemd160=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("ripemd160").update(t).digest()};ee.sha256ripemd160=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),ee.ripemd160(ee.sha256(t))};ee.sha512=function(t){return yr.checkArgument(E.Buffer.isBuffer(t)),pi.createHash("sha512").update(t).digest()};ee.sha512.blocksize=1024;ee.hmac=function(t,e,r){yr.checkArgument(E.Buffer.isBuffer(e)),yr.checkArgument(E.Buffer.isBuffer(r)),yr.checkArgument(t.blocksize);var n=t.blocksize/8;if(r.length>n)r=t(r);else if(r.length<n){var i=E.Buffer.alloc(n);i.fill(0),r.copy(i),r=i}var o=E.Buffer.alloc(n);o.fill(92);var c=E.Buffer.alloc(n);c.fill(54);for(var h=E.Buffer.alloc(n),d=E.Buffer.alloc(n),x=0;x<n;x++)h[x]=o[x]^r[x],d[x]=c[x]^r[x];return t(E.Buffer.concat([h,t(E.Buffer.concat([d,e]))]))};ee.sha256hmac=function(t,e){return ee.hmac(ee.sha256,t,e)};ee.sha512hmac=function(t,e){return ee.hmac(ee.sha512,t,e)}});var Dn=Z((bg,Wo)=>{I();N.default.browser?Wo.exports=du():Wo.exports=mu()});var yu=Z((Eg,xu)=>{"use strict";I();var vu=cn(),J0=hn(),gu=function(e){return vu.isString(e)?/^[0-9a-fA-F]+$/.test(e):!1};xu.exports={isValidJSON:function(e){var r;if(!vu.isString(e))return!1;try{r=JSON.parse(e)}catch{return!1}return typeof r=="object"},isHexa:gu,isHexaString:gu,defineImmutable:function(e,r){return Object.keys(r).forEach(function(n){Object.defineProperty(e,n,{configurable:!1,enumerable:!0,value:r[n]})}),e},isNaturalNumber:function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e&&e>=0},integerAsBuffer:function(e){J0.checkArgumentType(e,"number","integer");let r=E.Buffer.allocUnsafe(4);return r.writeUInt32BE(e,0),r}}});function Qo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Br(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function nr(t,e,r=""){let n=Qo(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let c=r&&`"${r}" `,h=o?` of length ${e}`:"",d=n?`length=${i}`:`type=${typeof t}`,x=c+"expected Uint8Array"+h+", got "+d;throw n?new RangeError(x):new TypeError(x)}return t}function mi(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Br(t.outputLen),Br(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function xn(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function gi(t,e){nr(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Nr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vi(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ze(t,e){return t<<32-e|t>>>e}function xi(t){if(nr(t),bu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=td[t[r]];return e}function wu(t){if(t>=wr._0&&t<=wr._9)return t-wr._0;if(t>=wr.A&&t<=wr.F)return t-(wr.A-10);if(t>=wr.a&&t<=wr.f)return t-(wr.a-10)}function Jo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(bu)try{return Uint8Array.fromHex(t)}catch(i){throw i instanceof SyntaxError?new RangeError(i.message):i}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let c=wu(t.charCodeAt(o)),h=wu(t.charCodeAt(o+1));if(c===void 0||h===void 0){let d=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+d+'" at index '+o)}n[i]=c*16+h}return n}function br(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Su(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];nr(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}function Eu(t,e={}){let r=(i,o)=>t(o).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function Gn(t=32){Br(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var bu,td,wr,_u,Mr=Ae(()=>{I();bu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",td=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));wr={_0:48,_9:57,A:65,F:70,a:97,f:102};_u=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Ou(t,e,r){return t&e^~t&r}function Au(t,e,r){return t&e^t&r^e&r}var yi,Sr,Iu=Ae(()=>{I();Mr();yi=class{constructor(e,r,n,i){W(this,"blockLen");W(this,"outputLen");W(this,"canXOF",!1);W(this,"padOffset");W(this,"isLE");W(this,"buffer");W(this,"view");W(this,"finished",!1);W(this,"length",0);W(this,"pos",0);W(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=vi(this.buffer)}update(e){xn(this),nr(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let c=0;c<o;){let h=Math.min(i-this.pos,o-c);if(h===i){let d=vi(e);for(;i<=o-c;c+=i)this.process(d,c);continue}n.set(e.subarray(c,c+h),this.pos),this.pos+=h,c+=h,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){xn(this),gi(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:c}=this;r[c++]=128,Nr(this.buffer.subarray(c)),this.padOffset>i-c&&(this.process(n,0),c=0);for(let y=c;y<i;y++)r[y]=0;n.setBigUint64(i-8,BigInt(this.length*8),o),this.process(n,0);let h=vi(e),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let x=d/4,v=this.get();if(x>v.length)throw new Error("_sha2: outputLen bigger than state");for(let y=0;y<x;y++)h.setUint32(4*y,v[y],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:c,pos:h}=this;return e.destroyed=c,e.finished=o,e.length=i,e.pos=h,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Sr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225])});var ed,Rr,ts,es,Ur,Pu=Ae(()=>{I();Iu();Mr();ed=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Rr=new Uint32Array(64),ts=class extends yi{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:o,F:c,G:h,H:d}=this;return[e,r,n,i,o,c,h,d]}set(e,r,n,i,o,c,h,d){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=c|0,this.G=h|0,this.H=d|0}process(e,r){for(let y=0;y<16;y++,r+=4)Rr[y]=e.getUint32(r,!1);for(let y=16;y<64;y++){let A=Rr[y-15],O=Rr[y-2],T=ze(A,7)^ze(A,18)^A>>>3,L=ze(O,17)^ze(O,19)^O>>>10;Rr[y]=L+Rr[y-7]+T+Rr[y-16]|0}let{A:n,B:i,C:o,D:c,E:h,F:d,G:x,H:v}=this;for(let y=0;y<64;y++){let A=ze(h,6)^ze(h,11)^ze(h,25),O=v+A+Ou(h,d,x)+ed[y]+Rr[y]|0,L=(ze(n,2)^ze(n,13)^ze(n,22))+Au(n,i,o)|0;v=x,x=d,d=h,h=c+O|0,c=o,o=i,i=n,n=O+L|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,c=c+this.D|0,h=h+this.E|0,d=d+this.F|0,x=x+this.G|0,v=v+this.H|0,this.set(n,i,o,c,h,d,x,v)}roundClean(){Nr(Rr)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Nr(this.buffer)}},es=class extends ts{constructor(){super(32);W(this,"A",Sr[0]|0);W(this,"B",Sr[1]|0);W(this,"C",Sr[2]|0);W(this,"D",Sr[3]|0);W(this,"E",Sr[4]|0);W(this,"F",Sr[5]|0);W(this,"G",Sr[6]|0);W(this,"H",Sr[7]|0)}},Ur=Eu(()=>new es,_u(1))});function Dr(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Si(t){if(typeof t=="bigint"){if(!wi(t))throw new RangeError("positive bigint expected, got "+t)}else ns(t);return t}function Fe(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function zn(t){let e=Si(t).toString(16);return e.length&1?"0"+e:e}function Tu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?bi:BigInt("0x"+t)}function ye(t){return Tu(xi(t))}function wn(t){return Tu(xi(_i(nr(t)).reverse()))}function Ei(t,e){if(Br(e),e===0)throw new RangeError("zero length");t=Si(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Jo(r.padStart(e*2,"0"))}function is(t,e){return Ei(t,e).reverse()}function _i(t){return Uint8Array.from(yt(t))}function bn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}function rd(t,e,r){return wi(t)&&wi(e)&&wi(r)&&e<=t&&t<r}function os(t,e,r,n){if(!rd(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Gr(t){if(t<bi)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>bi;t>>=rs,e+=1);return e}function Bu(t,e,r){if(Br(t,"hashLen"),Br(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=U=>new Uint8Array(U),i=Uint8Array.of(),o=Uint8Array.of(0),c=Uint8Array.of(1),h=1e3,d=n(t),x=n(t),v=0,y=()=>{d.fill(1),x.fill(0),v=0},A=(...U)=>r(x,gt(d,...U)),O=(U=i)=>{x=A(o,U),d=A(),U.length!==0&&(x=A(c,U),d=A())},T=()=>{if(v++>=h)throw new Error("drbg: tried max amount of iterations");let U=0,D=[];for(;U<e;){d=A();let et=d.slice();D.push(et),U+=d.length}return gt(...D)};return(U,D)=>{y(),O(U);let et;for(;(et=D(T()))===void 0;)O();return y(),et}}function He(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(o,c,h){if(!h&&c!=="function"&&!Object.hasOwn(t,o))throw new TypeError(`param "${o}" is invalid: expected own property`);let d=t[o];if(h&&d===void 0)return;let x=typeof d;if(x!==c||d===null)throw new TypeError(`param "${o}" is invalid: expected ${c}, got ${x}`)}let i=(o,c)=>Object.entries(o).forEach(([h,d])=>n(h,d,c));i(e,!1),i(r,!0)}var yt,ns,Er,gt,yn,qr,Oe,bi,rs,wi,Sn,zr=Ae(()=>{I();Mr();yt=(t,e,r)=>nr(t,e,r),ns=Br,Er=xi,gt=(...t)=>Su(...t),yn=t=>Jo(t),qr=Qo,Oe=t=>Gn(t),bi=BigInt(0),rs=BigInt(1);wi=t=>typeof t=="bigint"&&bi<=t;Sn=t=>(rs<<BigInt(t))-rs});function Me(t,e){if(e<=ge)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ge?r:e+r}function Re(t,e,r){if(e<ge)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ge;)n*=n,n%=r;return n}function Mu(t,e){if(t===ge)throw new Error("invert: expected non-zero number");if(e<=ge)throw new Error("invert: expected positive modulus, got "+e);let r=Me(t,e),n=e,i=ge,o=re,c=re,h=ge;for(;r!==ge;){let x=n/r,v=n-r*x,y=i-c*x,A=o-h*x;n=r,r=v,i=c,o=h,c=y,h=A}if(n!==re)throw new Error("invert: does not exist");return Me(i,e)}function as(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Nu(t,e){let r=t,n=(r.ORDER+re)/Fu,i=r.pow(e,n);return as(r,i,e),i}function od(t,e){let r=t,n=(r.ORDER-Hu)/Lu,i=r.mul(e,Vr),o=r.pow(i,n),c=r.mul(e,o),h=r.mul(r.mul(c,Vr),o),d=r.mul(c,r.sub(h,r.ONE));return as(r,d,e),d}function sd(t){let e=En(t),r=Uu(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),c=(t+nd)/Cu;return((h,d)=>{let x=h,v=x.pow(d,c),y=x.mul(v,n),A=x.mul(v,i),O=x.mul(v,o),T=x.eql(x.sqr(y),d),L=x.eql(x.sqr(A),d);v=x.cmov(v,y,T),y=x.cmov(O,A,L);let U=x.eql(x.sqr(y),d),D=x.cmov(v,y,U);return as(x,D,d),D})}function Uu(t){if(t<ku)throw new Error("sqrt is not defined for small field");let e=t-re,r=0;for(;e%Vr===ge;)e/=Vr,r++;let n=Vr,i=En(t);for(;ss(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Nu;let o=i.pow(n,e),c=(e+re)/Vr;return function(d,x){let v=d;if(v.is0(x))return x;if(ss(v,x)!==1)throw new Error("Cannot find square root");let y=r,A=v.mul(v.ONE,o),O=v.pow(x,e),T=v.pow(x,c);for(;!v.eql(O,v.ONE);){if(v.is0(O))return v.ZERO;let L=1,U=v.sqr(O);for(;!v.eql(U,v.ONE);)if(L++,U=v.sqr(U),L===y)throw new Error("Cannot find square root");let D=re<<BigInt(y-L-1),et=v.pow(A,D);y=L,A=v.sqr(et),O=v.mul(O,A),T=v.mul(T,et)}return T}}function ad(t){return t%Fu===ku?Nu:t%Lu===Hu?od:t%Cu===id?sd(t):Uu(t)}function Kr(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=cd.reduce((n,i)=>(n[i]="function",n),e);if(He(t,r),Fe(t.BYTES,"BYTES"),Fe(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=re)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ud(t,e,r){let n=t;if(r<ge)throw new Error("invalid exponent, negatives unsupported");if(r===ge)return n.ONE;if(r===re)return e;let i=n.ONE,o=e;for(;r>ge;)r&re&&(i=n.mul(i,o)),o=n.sqr(o),r>>=re;return i}function jr(t,e,r=!1){let n=t,i=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((h,d,x)=>n.is0(d)?h:(i[x]=h,n.mul(h,d)),n.ONE),c=n.inv(o);return e.reduceRight((h,d,x)=>n.is0(d)?h:(i[x]=n.mul(h,i[x]),n.mul(h,d)),c),i}function ss(t,e){let r=t,n=(r.ORDER-re)/Vr,i=r.pow(e,n),o=r.eql(i,r.ONE),c=r.eql(i,r.ZERO),h=r.eql(i,r.neg(r.ONE));if(!o&&!c&&!h)throw new Error("invalid Legendre symbol result");return o?1:c?0:-1}function cs(t,e){return ss(t,e)!==-1}function hd(t,e){if(e!==void 0&&ns(e),t<=ge)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Gr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,i=Math.ceil(n/8);return{nBitLength:n,nByteLength:i}}function En(t,e={}){return new Oi(t,e)}function qu(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=re)throw new Error("field order must be greater than 1");let e=Gr(t-re);return Math.ceil(e/8)}function Vn(t){let e=qu(t);return e+Math.ceil(e/2)}function _n(t,e,r=!1){yt(t);let n=t.length,i=qu(e),o=Math.max(Vn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let c=r?wn(t):ye(t),h=Me(c,e-re)+re;return r?is(h,i):Ei(h,i)}var ge,re,Vr,ku,Fu,Hu,nd,Lu,id,Cu,cd,Ru,Oi,On=Ae(()=>{I();zr();ge=BigInt(0),re=BigInt(1),Vr=BigInt(2),ku=BigInt(3),Fu=BigInt(4),Hu=BigInt(5),nd=BigInt(7),Lu=BigInt(8),id=BigInt(9),Cu=BigInt(16);cd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];Ru=new WeakMap,Oi=class{constructor(e,r={}){W(this,"ORDER");W(this,"BITS");W(this,"BYTES");W(this,"isLE");W(this,"ZERO",ge);W(this,"ONE",re);W(this,"_lengths");W(this,"_mod");if(e<=re)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:o}=hd(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=o,Object.freeze(this)}create(e){return Me(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ge<=e&&e<this.ORDER}is0(e){return e===ge}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&re)===re}neg(e){return Me(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Me(e*e,this.ORDER)}add(e,r){return Me(e+r,this.ORDER)}sub(e,r){return Me(e-r,this.ORDER)}mul(e,r){return Me(e*r,this.ORDER)}pow(e,r){return ud(this,e,r)}div(e,r){return Me(e*Mu(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Mu(e,this.ORDER)}sqrt(e){let r=Ru.get(this);return r||Ru.set(this,r=ad(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?is(e,this.BYTES):Ei(e,this.BYTES)}fromBytes(e,r=!1){yt(e);let{_lengths:n,BYTES:i,isLE:o,ORDER:c,_mod:h}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let x=new Uint8Array(i);x.set(e,o?0:x.length-e.length),e=x}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let d=o?wn(e):ye(e);if(h&&(d=Me(d,c)),!r&&!this.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d}invertBatch(e){return jr(this,e)}cmov(e,r,n){return Dr(n,"condition"),n?r:e}};Object.freeze(Oi.prototype)});function Vu(t){let e=t;if(typeof e!="function")throw new TypeError("Point must be a constructor");He({Fp:e.Fp,Fn:e.Fn,fromAffine:e.fromAffine,fromBytes:e.fromBytes,fromHex:e.fromHex},{Fp:"object",Fn:"object",fromAffine:"function",fromBytes:"function",fromHex:"function"}),Kr(e.Fp),Kr(e.Fn)}function Kn(t,e){let r=e.negate();return t?r:e}function ls(t,e){let r=jr(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Ku(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function us(t,e){Ku(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=Sn(t),c=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:c}}function Du(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:c}=r,h=Number(t&i),d=t>>c;h>n&&(h-=o,d+=Yr);let x=e*n,v=x+Math.abs(h)-1,y=h===0,A=h<0,O=e%2!==0;return{nextN:d,offset:v,isZero:y,isNeg:A,isNegF:O,offsetF:x}}function fd(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ld(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}function fs(t){return ju.get(t)||1}function Gu(t){if(t!==An)throw new Error("invalid wNAF")}function Yu(t,e,r,n){let i=e,o=t.ZERO,c=t.ZERO;for(;r>An||n>An;)r&Yr&&(o=o.add(i)),n&Yr&&(c=c.add(i)),i=i.double(),r>>=Yr,n>>=Yr;return{p1:o,p2:c}}function $u(t,e,r){let n=t.Fn;fd(e,t),ld(r,n);let i=e.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let c=t.ZERO,h=Gr(BigInt(i)),d=1;h>12?d=h-3:h>4?d=h-2:h>0&&(d=2);let x=Sn(d),v=new Array(Number(x)+1).fill(c),y=Math.floor((n.BITS-1)/d)*d,A=c;for(let O=y;O>=0;O-=d){v.fill(c);for(let L=0;L<o;L++){let U=r[L],D=Number(U>>BigInt(O)&x);v[D]=v[D].add(e[L])}let T=c;for(let L=v.length-1,U=c;L>0;L--)U=U.add(v[L]),T=T.add(U);if(A=A.add(T),O!==0)for(let L=0;L<d;L++)A=A.double()}return A}function zu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Kr(e),e}else return En(t,{isLE:r})}function Zu(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let d of["p","n","h"]){let x=e[d];if(!(typeof x=="bigint"&&x>An))throw new Error(`CURVE.${d} must be positive bigint`)}let i=zu(e.p,r.Fp,n),o=zu(e.n,r.Fn,n),h=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let d of h)if(!i.isValid(e[d]))throw new Error(`CURVE.${d} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}function Ii(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}var An,Yr,hs,ju,Ai,Pi=Ae(()=>{I();zr();On();An=BigInt(0),Yr=BigInt(1);hs=new WeakMap,ju=new WeakMap;Ai=class{constructor(e,r){W(this,"BASE");W(this,"ZERO");W(this,"Fn");W(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>An;)r&Yr&&(n=n.add(i)),i=i.double(),r>>=Yr;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=us(r,this.bits),o=[],c=e,h=c;for(let d=0;d<n;d++){h=c,o.push(h);for(let x=1;x<i;x++)h=h.add(c),o.push(h);c=h.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,c=us(e,this.bits);for(let h=0;h<c.windows;h++){let{nextN:d,offset:x,isZero:v,isNeg:y,isNegF:A,offsetF:O}=Du(n,h,c);n=d,v?o=o.add(Kn(A,r[O])):i=i.add(Kn(y,r[x]))}return Gu(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=us(e,this.bits);for(let c=0;c<o.windows&&n!==An;c++){let{nextN:h,offset:d,isZero:x,isNeg:v}=Du(n,c,o);if(n=h,!x){let y=r[d];i=i.add(v?y.negate():y)}}return Gu(n),i}getPrecomputes(e,r,n){let i=hs.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),hs.set(r,i))),i}cached(e,r,n){let i=fs(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=fs(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){Ku(r,this.bits),ju.set(e,r),hs.delete(e)}hasCache(e){return fs(e)!==1}}});function Xu(t){if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new Error("wrong u32 integer:"+t);return t}function dd(t){if(Xu(t),t<=1)return 1;if(t>2147483648)throw new Error("nextPowerOfTwo overflow: result does not fit u32");return 1<<ds(t-1)+1>>>0}function ds(t){return Xu(t),31-Math.clz32(t)}function Wu(t,e,r,n,i){let o=t,c=r||((v,y)=>new Array(v).fill(y??o.ZERO)),h=v=>{if(Array.isArray(v))return!0;if(!ArrayBuffer.isView(v))return!1;let y=v;return typeof y.length=="number"&&typeof y.slice=="function"&&typeof y[Symbol.iterator]=="function"},d=(...v)=>{if(!v.length)return 0;for(let A of v)if(!h(A))throw new Error("poly: not polynomial: "+A);let y=v[0].length;for(let A=1;A<v.length;A++)if(v[A].length!==y)throw new Error(`poly: mismatched lengths ${y} vs ${v[A].length}`);if(i!==void 0&&y!==i)throw new Error(`poly: expected fixed length ${i}, got ${y}`);return y};function x(v,y,A=!1){let O=ds(y),T=A?e.brp(O):e.roots(O);for(let L=0;L<y;L++)if(o.eql(v,T[L]))return L;return-1}return{roots:e,create:c,length:i,extend:(v,y)=>{d(v);let A=c(y,o.ZERO);for(let O=0;O<Math.min(v.length,y);O++)A[O]=v[O];return A},degree:v=>{d(v);for(let y=v.length-1;y>=0;y--)if(!o.is0(v[y]))return y;return-1},add:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.add(v[T],y[T]);return O},sub:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.sub(v[T],y[T]);return O},dot:(v,y)=>{let A=d(v,y),O=c(A);for(let T=0;T<A;T++)O[T]=o.mul(v[T],y[T]);return O},mul:(v,y)=>{if(h(y)){let A=d(v,y);if(n){let O=n.direct(v,!1,!0),T=n.direct(y,!1,!0);for(let L=0;L<O.length;L++)O[L]=o.mul(O[L],T[L]);return n.inverse(O,!0,!1)}else{let O=c(A);for(let T=0;T<A;T++)for(let L=0;L<A;L++){let U=(T+L)%A;O[U]=o.add(O[U],o.mul(v[T],y[L]))}return O}}else{let A=c(d(v));for(let O=0;O<A.length;O++)A[O]=o.mul(v[O],y);return A}},convolve(v,y){let A=dd(v.length+y.length-1);return this.mul(this.extend(v,A),this.extend(y,A))},shift(v,y){let A=c(d(v));A[0]=v[0];for(let O=1,T=o.ONE;O<v.length;O++)T=o.mul(T,y),A[O]=o.mul(v[O],T);return A},clone:v=>{d(v);let y=c(v.length);for(let A=0;A<v.length;A++)y[A]=v[A];return y},eval:(v,y)=>{d(v,y);let A=o.ZERO;for(let O=0;O<v.length;O++)A=o.add(A,o.mul(v[O],y[O]));return A},monomial:{basis:(v,y)=>{let A=c(y),O=o.ONE;for(let T=0;T<y;T++)A[T]=O,O=o.mul(O,v);return A},eval:(v,y)=>{d(v);let A=o.ZERO;for(let O=v.length-1;O>=0;O--)A=o.add(o.mul(A,y),v[O]);return A}},lagrange:{basis:(v,y,A=!1,O)=>{let T=ds(y),L=O||(A?e.brp(T):e.roots(T)),U=c(y),D=x(v,y,A);if(D!==-1)return U[D]=o.ONE,U;let et=o.pow(v,BigInt(y)),J=o.mul(o.sub(et,o.ONE),o.inv(BigInt(y))),Y=c(y);for(let ft=0;ft<y;ft++)Y[ft]=o.sub(v,L[ft]);let $=o.invertBatch(Y);for(let ft=0;ft<y;ft++)U[ft]=o.mul(J,o.mul(L[ft],$[ft]));return U},eval(v,y,A=!1){d(v);let O=x(y,v.length,A);if(O!==-1)return v[O];let T=this.basis(y,v.length,A),L=o.ZERO;for(let U=0;U<v.length;U++)o.is0(v[U])||(L=o.add(L,o.mul(v[U],T[U])));return L}},vanishing(v){d(v);let y=c(v.length+1,o.ZERO);y[0]=o.ONE;for(let A of v){let O=o.neg(A);for(let T=y.length-1;T>0;T--)y[T]=o.add(o.mul(y[T],O),y[T-1]);y[0]=o.mul(y[0],O)}return y}}}var Qu=Ae(()=>{I()});function $r(t,e){if(Fe(t),Fe(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function md(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Ju(t){if(!qr(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?bn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function gd(t,e,r,n){yt(t),Fe(r),e=Ju(e),e.length>255&&(e=n(gt(bn("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:o}=n,c=Math.ceil(r/i);if(r>65535||c>255)throw new Error("expand_message_xmd: invalid lenInBytes");let h=gt(e,$r(e.length,1)),d=new Uint8Array(o),x=$r(r,2),v=new Array(c),y=n(gt(d,t,x,$r(0,1),h));v[0]=n(gt(y,$r(1,1),h));for(let O=1;O<c;O++){let T=[md(y,v[O-1]),$r(O+1,1),h];v[O]=n(gt(...T))}return gt(...v).slice(0,r)}function vd(t,e,r,n,i){if(yt(t),Fe(r),e=Ju(e),e.length>255){let o=Math.ceil(2*n/8);e=i.create({dkLen:o}).update(bn("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:r}).update(t).update($r(r,2)).update(e).update($r(e.length,1)).digest()}function ps(t,e,r){He(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:i,m:o,hash:c,expand:h,DST:d}=r;if(Fe(c.outputLen,"valid hash"),yt(t),Fe(e),e<1)throw new Error("hash_to_field: expected count >= 1");if(o<1)throw new Error("hash_to_field: expected m >= 1");let x=n.toString(2).length,v=Math.ceil((x+i)/8),y=e*o*v,A;if(h==="xmd")A=gd(t,d,y,c);else if(h==="xof")A=vd(t,d,y,i,c);else if(h==="_internal_pass")A=t;else throw new Error('expand must be "xmd" or "xof"');let O=new Array(e);for(let T=0;T<e;T++){let L=new Array(o);for(let U=0;U<o;U++){let D=v*(U+T*o),et=A.subarray(D,D+v);L[U]=Me(pd(et),n)}O[T]=L}return O}function th(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,i)=>{let[o,c,h,d]=r.map(y=>y.reduce((A,O)=>t.add(t.mul(A,n),O))),[x,v]=jr(t,[c,d],!0);return n=t.mul(o,x),i=t.mul(i,t.mul(h,v)),{x:n,y:i}}}function eh(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");let n=h=>Object.freeze({...h,DST:qr(h.DST)?_i(h.DST):h.DST,...h.encodeDST===void 0?{}:{encodeDST:qr(h.encodeDST)?_i(h.encodeDST):h.encodeDST}}),i=n(r);function o(h){return t.fromAffine(e(h))}function c(h){let d=h.clearCofactor();return d.equals(t.ZERO)?t.ZERO:(d.assertValidity(),d)}return Object.freeze({get defaults(){return n(i)},Point:t,hashToCurve(h,d){let x=Object.assign({},i,d),v=ps(h,2,x),y=o(v[0]),A=o(v[1]);return c(y.add(A))},encodeToCurve(h,d){let x=i.encodeDST?{DST:i.encodeDST}:{},v=Object.assign({},i,x,d),y=ps(h,1,v),A=o(y[0]);return c(A)},mapToCurve(h){if(i.m===1){if(typeof h!="bigint")throw new Error("expected bigint (m=1)");return c(o([h]))}if(!Array.isArray(h))throw new Error("expected array of bigints");for(let d of h)if(typeof d!="bigint")throw new Error("expected array of bigints");return c(o(h))},hashToScalar(h,d){let x=t.Fn.ORDER,v=Object.assign({},i,{p:x,m:1,DST:xd},d);return ps(h,1,v)[0][0]}})}var pd,xd,rh=Ae(()=>{I();zr();On();pd=ye;xd="HashToScalar-"});function ms(t){He(t,{name:"string",hash:"function"},{hashToScalar:"function",validatePoint:"function",parsePublicKey:"function",adjustScalar:"function",adjustPoint:"function",challenge:"function",adjustNonces:"function",adjustSecret:"function",adjustPublic:"function",adjustGroupCommitmentShare:"function",adjustDKG:"function"}),Vu(t.Point);let{Point:e}=t,r=t.Fn===void 0?e.Fn:t.Fn,n=t.hash,i=t.hashToScalar===void 0?(_,P={DST:new Uint8Array})=>{let R=n(gt(P.DST,_));return r.create(r.isLE?wn(R):ye(R))}:t.hashToScalar,o=br(t.H1!==void 0?t.H1:t.name+"rho"),c=br(t.H2!==void 0?t.H2:t.name+"chal"),h=br(t.H3!==void 0?t.H3:t.name+"nonce"),d=br(t.H4!==void 0?t.H4:t.name+"msg"),x=br(t.H5!==void 0?t.H5:t.name+"com"),v=br(t.HDKG!==void 0?t.HDKG:t.name+"dkg"),y=br(t.HID!==void 0?t.HID:t.name+"id"),A=_=>i(_,{DST:o}),O=_=>i(_,{DST:c}),T=_=>i(_,{DST:h}),L=_=>n(gt(d,_)),U=_=>n(gt(x,_)),D=_=>i(_,{DST:v}),et=_=>i(_,{DST:y}),J=(_=Oe)=>{let P=_n(_(Vn(r.ORDER)),r.ORDER,r.isLE);return r.isLE?wn(P):ye(P)},Y=_=>_.toBytes(),$=_=>{let P=e.fromBytes(_);return t.validatePoint&&t.validatePoint(P),P},ft=(_,P)=>({identifier:_,hiding:Y(e.BASE.multiply(r.fromBytes(P.hiding))),binding:Y(e.BASE.multiply(r.fromBytes(P.binding)))}),Pt=t.adjustPoint===void 0?_=>_:t.adjustPoint,nt=_=>{if(!r.isValid(_)||r.is0(_))throw new Error("Invalid identifier "+_);return _},dt=_=>Er(r.toBytes(nt(_))),b=_=>{let P=nt(r.fromBytes(yn(_)));if(dt(P)!==_)throw new Error("expected canonical identifier hex");return P},s={encode:(_,P)=>{let R=gt(Y(_),r.toBytes(P));return t.adjustTx&&(R=t.adjustTx.encode(R)),R},decode:_=>{t.adjustTx&&(_=t.adjustTx.decode(_));let P=$(_.subarray(0,-r.BYTES)),R=r.fromBytes(_.subarray(-r.BYTES));return{R:P,z:R}}},u=(_=Oe)=>{let P=J(_);t.adjustScalar&&(P=t.adjustScalar(P));let R=e.BASE.multiply(P);return{scalar:P,point:R}},f="roots are unavailable in FROST polynomial mode",l={info:{G:r.ZERO,oddFactor:r.ZERO,powerOfTwo:0},roots(){throw new Error(f)},brp(){throw new Error(f)},inverse(){throw new Error(f)},omega(){throw new Error(f)},clear(){}},p=Wu(r,l),w=(_,P)=>$u(e,_,P),S=(_,P)=>{if(!P.length)throw new Error("empty coefficients");return p.monomial.eval(P,_)},m=(_,P)=>{let R="invalid parameters";if(!_.some(K=>r.eql(K,P)))throw new Error(R);let C=new Set(_);if(C.size!==_.length)throw new Error(R);if(!C.has(P))throw new Error(R);let V=r.ONE,G=r.ONE;for(let K of _)r.eql(K,P)||(V=r.mul(V,K),G=r.mul(G,r.sub(K,P)));return r.div(V,G)},a=(_,P)=>{let R=p.monomial.basis(_,P.length);return w(P,R)},g=(_,P,R,C=Oe)=>{Ti(_);let V=P===void 0?J(C):r.fromBytes(P);if(!R){R=[];for(let ot=0;ot<_.min-1;ot++)R.push(J(C))}if(R.length!==_.min-1)throw new Error("wrong coefficients length");let G=[V,...R],K=G.map(ot=>e.BASE.multiply(ot));return{coefficients:G,commitment:K,secret:V}},F={challenge:(_,P,R)=>D(gt(r.toBytes(_),Y(P),Y(R))),compute(_,P,R,C=Oe){if(P.length<1)throw new Error("coefficients should have at least one element");let{point:V,scalar:G}=u(C),K=R[0],ot=this.challenge(_,K,V),X=r.add(G,r.mul(P[0],ot));return s.encode(V,X)},validate(_,P,R){if(P.length<1)throw new Error("commitment should have at least one element");let{R:C,z:V}=s.decode(R),G=$(P[0]),K=this.challenge(_,G,C);if(!C.equals(e.BASE.multiply(V).subtract(G.multiply(K))))throw new Error("invalid proof of knowledge")}},k={challenge:(_,P,R)=>t.challenge?t.challenge(_,P,R):O(gt(Y(_),Y(P),R)),sign(_,P,R=Oe){let{point:C,scalar:V}=u(R),G=e.BASE.multiply(P),K=this.challenge(C,G,_),ot=r.add(V,r.mul(K,P));return[C,ot]},verify(_,P,R,C){t.adjustPoint&&(C=t.adjustPoint(C)),t.adjustPoint&&(P=t.adjustPoint(P));let V=this.challenge(P,C,_),G=e.BASE.multiply(R),K=C.multiply(V),ot=G.subtract(K).subtract(P);return ot.clearCofactor&&(ot=ot.clearCofactor()),e.ZERO.equals(ot)}},q=(_,P,R)=>{if(!e.BASE.multiply(R).equals(a(_,P)))throw new Error("invalid secret share")},z={fromNumber(_){if(!Number.isSafeInteger(_))throw new Error("expected safe interger");return dt(BigInt(_))},derive(_){if(typeof _!="string")throw new Error("wrong identifier string: "+_);return dt(et(br(_)))}},j=(_,P=Oe)=>T(gt(P(32),r.toBytes(_))),it=(_,P,R)=>{let C=P.map(st=>[st.identifier,b(st.identifier),$(st.hiding),$(st.binding)]);C.sort((st,at)=>st[1]<at[1]?-1:st[1]>at[1]?1:0);let V=[];for(let[st,at,ct,ht]of C)V.push(r.toBytes(at),Y(ct),Y(ht));let G=U(gt(...V)),K=gt(Y(_),L(R),G),ot={};for(let[st,at]of C)ot[st]=A(gt(K,r.toBytes(at)));let X=[],Q=[];for(let[st,at,ct,ht]of C){if(e.ZERO.equals(ct)||e.ZERO.equals(ht))throw new Error("infinity commitment");X.push(ct,ht),Q.push(r.ONE,ot[st])}let oe=w(X,Q);return{identifiers:C.map(st=>st[1]),groupCommitment:oe,bindingFactors:ot}},pt=(_,P,R,C)=>{let V=Pt($(_)),G=b(C),{identifiers:K,groupCommitment:ot,bindingFactors:X}=it(V,P,R),Q=X[C],oe=m(K,G),vt=k.challenge(ot,V,R);return{lambda:oe,challenge:vt,bindingFactor:Q,groupCommitment:ot}};Object.freeze(z);let ut={Identifier:z,DKG:Object.freeze({round1:(_,P,R,C=Oe)=>{Ti(P);let V=b(_),{coefficients:G,commitment:K}=g(P,R,void 0,C),ot=F.compute(V,G,K,C),X=K.map(Y),Q={identifier:dt(V),commitment:X,proofOfKnowledge:ot},oe={identifier:V,coefficients:G,commitment:K.map(Y),signers:{min:P.min,max:P.max},step:1};return{public:Q,secret:oe}},round2:(_,P)=>{if(P.length!==_.signers.max-1)throw new Error("wrong number of round1 packages");if(!_.coefficients||_.step===3)throw new Error("round3 package used in round2");let R={};for(let C of P){if(C.commitment.length!==_.signers.min)throw new Error("wrong number of commitments");let V=b(C.identifier);if(V===_.identifier)throw new Error("duplicate id="+dt(V));F.validate(V,C.commitment,C.proofOfKnowledge);for(let K of C.commitment)$(K);if(R[C.identifier])throw new Error("Duplicate id="+V);let G=r.toBytes(S(V,_.coefficients));R[C.identifier]={identifier:dt(_.identifier),signingShare:G}}return _.step=2,R},round3:(_,P,R)=>{if(P.length!==_.signers.max-1)throw new Error("wrong length of round1 packages");if(!_.coefficients||_.step!==2)throw new Error("round2 package used in round3");if(R.length!==P.length)throw new Error("wrong length of round2 packages");let C={};for(let at of P){if(!at.identifier||!at.commitment)throw new Error("wrong round1 share");C[at.identifier]={...at}}for(let at of R){if(!at.identifier||!at.signingShare)throw new Error("wrong round2 share");if(!C[at.identifier])throw new Error("round1 share for "+at.identifier+" is missing");C[at.identifier].signingShare=at.signingShare}if(Object.keys(C).length!==P.length)throw new Error("mismatch identifiers between rounds");let V=r.ZERO;if(_.commitment.length!==_.signers.min)throw new Error("wrong commitments length");let G=_.commitment.map($),K=S(_.identifier,_.coefficients);q(_.identifier,G,K);let ot=G.map(Y),X={[dt(_.identifier)]:ot};for(let at in C){let ct=C[at];if(!ct.signingShare||!ct.commitment)throw new Error("mismatch identifiers");let ht=b(at),cr=r.fromBytes(ct.signingShare),Tt=ct.commitment.map($);q(_.identifier,Tt,cr),V=r.add(V,cr);let Et=dt(ht);if(X[Et])throw new Error("duplicated id="+Et);X[Et]=ct.commitment}V=r.add(V,K);let Q=new Array(_.signers.min).fill(e.ZERO);for(let at in X){let ct=X[at];if(ct.length!==_.signers.min)throw new Error("wrong commitments length");for(let ht=0;ht<ct.length;ht++)Q[ht]=Q[ht].add($(ct[ht]))}let oe=Q.map(Y),vt={};for(let at in X)vt[at]=Y(a(b(at),Q));let st={public:{signers:{min:_.signers.min,max:_.signers.max},commitments:oe,verifyingShares:Object.fromEntries(Object.entries(vt).map(([at,ct])=>[at,ct.slice()]))},secret:{identifier:dt(_.identifier),signingShare:r.toBytes(V)}};t.adjustDKG&&(st=t.adjustDKG(st));for(let at=0;at<_.coefficients.length;at++)_.coefficients[at]-=_.coefficients[at];return delete _.coefficients,_.step=3,st},clean(_){if(_.identifier-=_.identifier,_.coefficients)for(let P=0;P<_.coefficients.length;P++)_.coefficients[P]-=_.coefficients[P];_.step=3}}),trustedDealer(_,P,R,C=Oe){if(Ti(_),P===void 0){P=[];for(let Q=1;Q<=_.max;Q++)P.push(z.fromNumber(Q))}else if(!Array.isArray(P)||P.length!==_.max)throw new Error("identifiers should be array of "+_.max);let V={};for(let Q of P){let oe=b(Q);if(Q in V)throw new Error("duplicated id="+Q);V[Q]=oe}let G=g(_,R,void 0,C),K=G.commitment.map(Y),ot={},X={};for(let Q of P){let oe=S(V[Q],G.coefficients);X[Q]=Y(e.BASE.multiply(oe)),ot[Q]={identifier:Q,signingShare:r.toBytes(oe)}}return{public:{signers:{min:_.min,max:_.max},commitments:K,verifyingShares:X},secretShares:ot}},validateSecret(_,P){let R=b(_.identifier),C=P.commitments.map($),V=r.fromBytes(_.signingShare);q(R,C,V)},commit(_,P=Oe){let R=r.fromBytes(_.signingShare),C=j(R,P),V=j(R,P),G={hiding:r.toBytes(C),binding:r.toBytes(V)};return{nonces:G,commitments:ft(_.identifier,G)}},signShare(_,P,R,C,V){nh(P.signers,C.length);let G=r.fromBytes(R.hiding),K=r.fromBytes(R.binding);if(r.is0(G)||r.is0(K))throw new Error("signing nonces already used");let ot={identifier:_.identifier,hiding:Y(e.BASE.multiply(G)),binding:Y(e.BASE.multiply(K))},X=C.find(Mt=>Mt.identifier===_.identifier);if(!X)throw new Error("missing signer commitment");if(Er(X.hiding)!==Er(ot.hiding)||Er(X.binding)!==Er(ot.binding))throw new Error("incorrect signer commitment");t.adjustSecret&&(_=t.adjustSecret(_,P)),t.adjustPublic&&(P=t.adjustPublic(P));let Q=r.fromBytes(_.signingShare),{lambda:oe,challenge:vt,bindingFactor:st,groupCommitment:at}=pt(P.commitments[0],C,V,_.identifier),ct=t.adjustNonces?t.adjustNonces(at,R):R,ht=t.adjustNonces?r.fromBytes(ct.hiding):G,cr=t.adjustNonces?r.fromBytes(ct.binding):K,Tt=r.mul(r.mul(oe,Q),vt),Et=r.mul(cr,st),ei=r.toBytes(r.add(r.add(ht,Et),Tt));return R.hiding.fill(0),R.binding.fill(0),ei},verifyShare(_,P,R,C,V){t.adjustPublic&&(_=t.adjustPublic(_));let G=P.find(cr=>cr.identifier===C);if(!G)throw new Error("cannot find identifier commitment");let K=$(_.verifyingShares[C]),ot=$(G.hiding),X=$(G.binding),{lambda:Q,challenge:oe,bindingFactor:vt,groupCommitment:st}=pt(_.commitments[0],P,R,C),at=ot.add(X.multiply(vt));t.adjustGroupCommitmentShare&&(at=t.adjustGroupCommitmentShare(st,at));let ct=e.BASE.multiply(r.fromBytes(V)),ht=at.add(K.multiply(r.mul(oe,Q)));return ct.equals(ht)},aggregate(_,P,R,C){t.adjustPublic&&(_=t.adjustPublic(_));try{nh(_.signers,P.length)}catch{throw new In("aggregation failed",[])}let V=P.map(X=>X.identifier);if(V.length!==Object.keys(C).length)throw new In("aggregation failed",[]);for(let X of V)if(!(X in C)||!(X in _.verifyingShares))throw new In("aggregation failed",[]);let G=$(_.commitments[0]),{groupCommitment:K}=it(G,P,R),ot=r.ZERO;for(let X of V)ot=r.add(ot,r.fromBytes(C[X]));if(!k.verify(R,K,ot,G)){let X=[];for(let Q of V)this.verifyShare(_,P,R,Q,C[Q])||X.push(Q);throw new In("aggregation failed",X)}return s.encode(K,ot)},sign(_,P){let R=r.fromBytes(P);t.adjustScalar&&(R=t.adjustScalar(R));let[C,V]=k.sign(_,R);return s.encode(C,V)},verify(_,P,R){let C=t.parsePublicKey?t.parsePublicKey(R):$(R),{R:V,z:G}=s.decode(_);return k.verify(P,V,G,C)},combineSecret(_,P){if(Ti(P),!Array.isArray(_)||_.length<P.min)throw new Error("wrong secret shares array");let R=[],C={};for(let K of _){let ot=b(K.identifier),X=dt(ot);if(C[X])throw new Error("duplicated id="+X);C[X]=!0,R.push([ot,r.fromBytes(K.signingShare)])}let V=R.map(([K])=>K),G=r.ZERO;for(let[K,ot]of R)G=r.add(G,r.mul(ot,m(V,K)));return r.toBytes(G)},utils:Object.freeze({Fn:r,randomScalar:(_=Oe)=>r.toBytes(u(_).scalar),generateSecretPolynomial:(_,P,R,C)=>{let V=g(_,P,R,C);return{...V,commitment:V.commitment.map(Y)}}})};return Object.freeze(ut)}var Ti,nh,In,ih=Ae(()=>{I();Mr();zr();Pi();Qu();On();Ti=t=>{if(!Number.isSafeInteger(t.min)||!Number.isSafeInteger(t.max))throw new Error("Wrong signers info: min="+t.min+" max="+t.max);if(t.min<2||t.max<2||t.min>t.max)throw new Error("Wrong signers info: min="+t.min+" max="+t.max)},nh=(t,e)=>{if(e<t.min||e>t.max)throw new Error("Wrong number of commitments="+e)},In=class extends Error{constructor(r,n){super(r);W(this,"cheaters");this.cheaters=n}}});var Bi,oh,sh=Ae(()=>{I();Mr();Bi=class{constructor(e,r){W(this,"oHash");W(this,"iHash");W(this,"blockLen");W(this,"outputLen");W(this,"canXOF",!1);W(this,"finished",!1);W(this,"destroyed",!1);if(mi(e),nr(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Nr(i)}update(e){return xn(this),this.iHash.update(e),this}digestInto(e){xn(this),gi(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:c,outputLen:h}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=c,e.outputLen=h,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},oh=(()=>{let t=((e,r,n)=>new Bi(e,r).update(n).digest());return t.create=(e,r)=>new Bi(e,r),t})()});function yd(t,e,r){os("scalar",t,Le,r);let[[n,i],[o,c]]=e,h=ah(c*t,r),d=ah(-i*t,r),x=t-h*n-d*o,v=-h*i-d*c,y=x<Le,A=v<Le;y&&(x=-x),A&&(v=-v);let O=Sn(Math.ceil(Gr(r)/2))+le;if(x<Le||x>=O||v<Le||v>=O)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:y,k1:x,k2neg:A,k2:v}}function vs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function gs(t,e){He(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Dr(r.lowS,"lowS"),Dr(r.prehash,"prehash"),r.format!==void 0&&vs(r.format),r}function ch(t,e={}){let r=Zu("weierstrass",t,e),n=r.Fp,i=r.Fn,o=r.CURVE,{h:c,n:h}=o;He(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:d,allowInfinityPoint:x}=e;if(d&&(!n.is0(o.a)||typeof d.beta!="bigint"||!Array.isArray(d.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let v=fh(n,i);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function A(u,f,l){if(x&&f.is0())return Uint8Array.of(0);let{x:p,y:w}=f.toAffine(),S=n.toBytes(p);if(Dr(l,"isCompressed"),l){y();let m=!n.isOdd(w);return gt(uh(m),S)}else return gt(Uint8Array.of(4),S,n.toBytes(w))}function O(u){yt(u,void 0,"Point");let{publicKey:f,publicKeyUncompressed:l}=v,p=u.length,w=u[0],S=u.subarray(1);if(x&&p===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(p===f&&(w===2||w===3)){let m=n.fromBytes(S);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let a=U(m),g;try{g=n.sqrt(a)}catch(q){let z=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}y();let F=n.isOdd(g);return(w&1)===1!==F&&(g=n.neg(g)),{x:m,y:g}}else if(p===l&&w===4){let m=n.BYTES,a=n.fromBytes(S.subarray(0,m)),g=n.fromBytes(S.subarray(m,m*2));if(!D(a,g))throw new Error("bad point: is not on curve");return{x:a,y:g}}else throw new Error(`bad point: got length ${p}, expected compressed=${f} or uncompressed=${l}`)}let T=e.toBytes===void 0?A:e.toBytes,L=e.fromBytes===void 0?O:e.fromBytes;function U(u){let f=n.sqr(u),l=n.mul(f,u);return n.add(n.add(l,n.mul(u,o.a)),o.b)}function D(u,f){let l=n.sqr(f),p=U(u);return n.eql(l,p)}if(!D(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let et=n.mul(n.pow(o.a,Pn),ys),J=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(et,J)))throw new Error("bad curve params: a or b");function Y(u,f,l=!1){if(!n.isValid(f)||l&&n.is0(f))throw new Error(`bad point coordinate ${u}`);return f}function $(u){if(!(u instanceof nt))throw new Error("Weierstrass Point expected")}function ft(u){if(!d||!d.basises)throw new Error("no endo");return yd(u,d.basises,i.ORDER)}function Pt(u,f,l,p,w){return l=new nt(n.mul(l.X,u),l.Y,l.Z),f=Kn(p,f),l=Kn(w,l),f.add(l)}let s=class s{constructor(f,l,p){W(this,"X");W(this,"Y");W(this,"Z");this.X=Y("x",f),this.Y=Y("y",l,!0),this.Z=Y("z",p),Object.freeze(this)}static CURVE(){return o}static fromAffine(f){let{x:l,y:p}=f||{};if(!f||!n.isValid(l)||!n.isValid(p))throw new Error("invalid affine point");if(f instanceof s)throw new Error("projective point not allowed");return n.is0(l)&&n.is0(p)?s.ZERO:new s(l,p,n.ONE)}static fromBytes(f){let l=s.fromAffine(L(yt(f,void 0,"point")));return l.assertValidity(),l}static fromHex(f){return s.fromBytes(yn(f))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(f=8,l=!0){return b.createCache(this,f),l||this.multiply(Pn),this}assertValidity(){let f=this;if(f.is0()){if(e.allowInfinityPoint&&n.is0(f.X)&&n.eql(f.Y,n.ONE)&&n.is0(f.Z))return;throw new Error("bad point: ZERO")}let{x:l,y:p}=f.toAffine();if(!n.isValid(l)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!D(l,p))throw new Error("bad point: equation left != right");if(!f.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:f}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(f)}equals(f){$(f);let{X:l,Y:p,Z:w}=this,{X:S,Y:m,Z:a}=f,g=n.eql(n.mul(l,a),n.mul(S,w)),F=n.eql(n.mul(p,a),n.mul(m,w));return g&&F}negate(){return new s(this.X,n.neg(this.Y),this.Z)}double(){let{a:f,b:l}=o,p=n.mul(l,Pn),{X:w,Y:S,Z:m}=this,a=n.ZERO,g=n.ZERO,F=n.ZERO,k=n.mul(w,w),q=n.mul(S,S),z=n.mul(m,m),j=n.mul(w,S);return j=n.add(j,j),F=n.mul(w,m),F=n.add(F,F),a=n.mul(f,F),g=n.mul(p,z),g=n.add(a,g),a=n.sub(q,g),g=n.add(q,g),g=n.mul(a,g),a=n.mul(j,a),F=n.mul(p,F),z=n.mul(f,z),j=n.sub(k,z),j=n.mul(f,j),j=n.add(j,F),F=n.add(k,k),k=n.add(F,k),k=n.add(k,z),k=n.mul(k,j),g=n.add(g,k),z=n.mul(S,m),z=n.add(z,z),k=n.mul(z,j),a=n.sub(a,k),F=n.mul(z,q),F=n.add(F,F),F=n.add(F,F),new s(a,g,F)}add(f){$(f);let{X:l,Y:p,Z:w}=this,{X:S,Y:m,Z:a}=f,g=n.ZERO,F=n.ZERO,k=n.ZERO,q=o.a,z=n.mul(o.b,Pn),j=n.mul(l,S),it=n.mul(p,m),pt=n.mul(w,a),ut=n.add(l,p),_=n.add(S,m);ut=n.mul(ut,_),_=n.add(j,it),ut=n.sub(ut,_),_=n.add(l,w);let P=n.add(S,a);return _=n.mul(_,P),P=n.add(j,pt),_=n.sub(_,P),P=n.add(p,w),g=n.add(m,a),P=n.mul(P,g),g=n.add(it,pt),P=n.sub(P,g),k=n.mul(q,_),g=n.mul(z,pt),k=n.add(g,k),g=n.sub(it,k),k=n.add(it,k),F=n.mul(g,k),it=n.add(j,j),it=n.add(it,j),pt=n.mul(q,pt),_=n.mul(z,_),it=n.add(it,pt),pt=n.sub(j,pt),pt=n.mul(q,pt),_=n.add(_,pt),j=n.mul(it,_),F=n.add(F,j),j=n.mul(P,_),g=n.mul(ut,g),g=n.sub(g,j),j=n.mul(ut,it),k=n.mul(P,k),k=n.add(k,j),new s(g,F,k)}subtract(f){return $(f),this.add(f.negate())}is0(){return this.equals(s.ZERO)}multiply(f){let{endo:l}=e;if(!i.isValidNot0(f))throw new RangeError("invalid scalar: out of range");let p,w,S=m=>b.cached(this,m,a=>ls(s,a));if(l){let{k1neg:m,k1:a,k2neg:g,k2:F}=ft(f),{p:k,f:q}=S(a),{p:z,f:j}=S(F);w=q.add(j),p=Pt(l.beta,k,z,m,g)}else{let{p:m,f:a}=S(f);p=m,w=a}return ls(s,[p,w])[0]}multiplyUnsafe(f){let{endo:l}=e,p=this,w=f;if(!i.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Le||p.is0())return s.ZERO;if(w===le)return p;if(b.hasCache(this))return this.multiply(w);if(l){let{k1neg:S,k1:m,k2neg:a,k2:g}=ft(w),{p1:F,p2:k}=Yu(s,p,m,g);return Pt(l.beta,F,k,S,a)}else return b.unsafe(p,w)}toAffine(f){let l=this,p=f,{X:w,Y:S,Z:m}=l;if(n.eql(m,n.ONE))return{x:w,y:S};let a=l.is0();p==null&&(p=a?n.ONE:n.inv(m));let g=n.mul(w,p),F=n.mul(S,p),k=n.mul(m,p);if(a)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:g,y:F}}isTorsionFree(){let{isTorsionFree:f}=e;return c===le?!0:f?f(s,this):b.unsafe(this,h).is0()}clearCofactor(){let{clearCofactor:f}=e;return c===le?this:f?f(s,this):this.multiplyUnsafe(c)}isSmallOrder(){return c===le?this.is0():this.clearCofactor().is0()}toBytes(f=!0){return Dr(f,"isCompressed"),this.assertValidity(),T(s,this,f)}toHex(f=!0){return Er(this.toBytes(f))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};W(s,"BASE",new s(o.Gx,o.Gy,n.ONE)),W(s,"ZERO",new s(n.ZERO,n.ONE,n.ZERO)),W(s,"Fp",n),W(s,"Fn",i);let nt=s,dt=i.BITS,b=new Ai(nt,e.endo?Math.ceil(dt/2):dt);return dt>=8&&nt.BASE.precompute(8),Object.freeze(nt.prototype),Object.freeze(nt),nt}function uh(t){return Uint8Array.of(t?2:3)}function wd(t,e){let r=Kr(t),n=r.ORDER,i=Le;for(let L=n-le;L%ir===Le;L/=ir)i+=le;let o=i,c=ir<<o-le-le,h=c*ir,d=(n-le)/h,x=(d-le)/ir,v=h-le,y=c,A=r.pow(e,d),O=r.pow(e,(d+le)/ir),T=(L,U)=>{let D=A,et=r.pow(U,v),J=r.sqr(et);J=r.mul(J,U);let Y=r.mul(L,J);Y=r.pow(Y,x),Y=r.mul(Y,et),et=r.mul(Y,U),J=r.mul(Y,L);let $=r.mul(J,et);Y=r.pow($,y);let ft=r.eql(Y,r.ONE);et=r.mul(J,O),Y=r.mul($,D),J=r.cmov(et,J,ft),$=r.cmov(Y,$,ft);for(let Pt=o;Pt>le;Pt--){let nt=Pt-ir;nt=ir<<nt-le;let dt=r.pow($,nt),b=r.eql(dt,r.ONE);et=r.mul(J,D),D=r.mul(D,D),dt=r.mul($,D),J=r.cmov(et,J,b),$=r.cmov(dt,$,b)}return{isValid:!r.is0(U)&&(ft||r.is0(L)),value:J}};if(r.ORDER%ys===Pn){let L=(r.ORDER-Pn)/ys,U=r.sqrt(r.neg(e));T=(D,et)=>{let J=r.sqr(et),Y=r.mul(D,et);J=r.mul(J,Y);let $=r.pow(J,L);$=r.mul($,Y);let ft=r.mul($,U),Pt=r.mul(r.sqr($),et),nt=r.eql(Pt,D),dt=r.cmov(ft,$,nt);return{isValid:!r.is0(et)&&nt,value:dt}}}return T}function hh(t,e){let r=Kr(t),{A:n,B:i,Z:o}=e;if(!r.isValidNot0(n)||!r.isValidNot0(i)||!r.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");if(r.eql(o,r.neg(r.ONE))||cs(r,o))throw new Error("mapToCurveSimpleSWU: invalid opts");let c=r.mul(i,r.inv(r.mul(o,n))),h=r.add(r.add(r.mul(r.sqr(c),c),r.mul(n,c)),i);if(!cs(r,h))throw new Error("mapToCurveSimpleSWU: invalid opts");let d=wd(r,o);if(!r.isOdd)throw new Error("Field does not have .isOdd()");return x=>{let v,y,A,O,T,L,U,D;v=r.sqr(x),v=r.mul(v,o),y=r.sqr(v),y=r.add(y,v),A=r.add(y,r.ONE),A=r.mul(A,i),O=r.cmov(o,r.neg(y),!r.eql(y,r.ZERO)),O=r.mul(O,n),y=r.sqr(A),L=r.sqr(O),T=r.mul(L,n),y=r.add(y,T),y=r.mul(y,A),L=r.mul(L,O),T=r.mul(L,i),y=r.add(y,T),U=r.mul(v,A);let{isValid:et,value:J}=d(y,L);D=r.mul(v,x),D=r.mul(D,J),U=r.cmov(U,A,et),D=r.cmov(D,J,et);let Y=r.isOdd(x)===r.isOdd(D);D=r.cmov(r.neg(D),D,Y);let $=jr(r,[O],!0)[0];return U=r.mul(U,$),{x:U,y:D}}}function fh(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function bd(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Oe:e.randomBytes,i=Object.assign(fh(t.Fp,r),{seed:Math.max(Vn(r.ORDER),16)});function o(O){try{let T=r.fromBytes(O);return r.isValidNot0(T)}catch{return!1}}function c(O,T){let{publicKey:L,publicKeyUncompressed:U}=i;try{let D=O.length;return T===!0&&D!==L||T===!1&&D!==U?!1:!!t.fromBytes(O)}catch{return!1}}function h(O){return O=O===void 0?n(i.seed):O,_n(yt(O,i.seed,"seed"),r.ORDER)}function d(O,T=!0){return t.BASE.multiply(r.fromBytes(O)).toBytes(T)}function x(O){let{secretKey:T,publicKey:L,publicKeyUncompressed:U}=i,D=r._lengths;if(!qr(O))return;let et=yt(O,void 0,"key").length,J=et===L||et===U,Y=et===T||!!D?.includes(et);if(!(J&&Y))return J}function v(O,T,L=!0){if(x(O)===!0)throw new Error("first arg must be private key");if(x(T)===!1)throw new Error("second arg must be public key");let U=r.fromBytes(O);return t.fromBytes(T).multiply(U).toBytes(L)}let y={isValidSecretKey:o,isValidPublicKey:c,randomSecretKey:h},A=Ii(h,d);return Object.freeze(y),Object.freeze(i),Object.freeze({getPublicKey:d,getSharedSecret:v,keygen:A,Point:t,utils:y,lengths:i})}function lh(t,e,r={}){let n=e;mi(n),He(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let i=r.randomBytes===void 0?Oe:r.randomBytes,o=r.hmac===void 0?(p,w)=>oh(n,p,w):r.hmac,{Fp:c,Fn:h}=t,{ORDER:d,BITS:x}=h,{keygen:v,getPublicKey:y,getSharedSecret:A,utils:O,lengths:T}=bd(t,r),L={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},U=d*ir+le<c.ORDER;function D(p){let w=d>>le;return p>w}function et(p,w){if(!h.isValidNot0(w))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return w}function J(){if(U)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function Y(p,w){vs(w);let S=T.signature,m=w==="compact"?S:w==="recovered"?S+1:void 0;return yt(p,m)}class ${constructor(w,S,m){W(this,"r");W(this,"s");W(this,"recovery");if(this.r=et("r",w),this.s=et("s",S),m!=null){if(J(),![0,1,2,3].includes(m))throw new Error("invalid recovery id");this.recovery=m}Object.freeze(this)}static fromBytes(w,S=L.format){Y(w,S);let m;if(S==="der"){let{r:k,s:q}=Ve.toSig(yt(w));return new $(k,q)}S==="recovered"&&(m=w[0],S="compact",w=w.subarray(1));let a=T.signature/2,g=w.subarray(0,a),F=w.subarray(a,a*2);return new $(h.fromBytes(g),h.fromBytes(F),m)}static fromHex(w,S){return this.fromBytes(yn(w),S)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new $(this.r,this.s,w)}recoverPublicKey(w){let{r:S,s:m}=this,a=this.assertRecovery(),g=a===2||a===3?S+d:S;if(!c.isValid(g))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=c.toBytes(g),k=t.fromBytes(gt(uh((a&1)===0),F)),q=h.inv(g),z=Pt(yt(w,void 0,"msgHash")),j=h.create(-z*q),it=h.create(m*q),pt=t.BASE.multiplyUnsafe(j).add(k.multiplyUnsafe(it));if(pt.is0())throw new Error("invalid recovery: point at infinify");return pt.assertValidity(),pt}hasHighS(){return D(this.s)}toBytes(w=L.format){if(vs(w),w==="der")return yn(Ve.hexFromSig(this));let{r:S,s:m}=this,a=h.toBytes(S),g=h.toBytes(m);return w==="recovered"?(J(),gt(Uint8Array.of(this.assertRecovery()),a,g)):gt(a,g)}toHex(w){return Er(this.toBytes(w))}}Object.freeze($.prototype),Object.freeze($);let ft=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let S=ye(w),m=w.length*8-x;return m>0?S>>BigInt(m):S}:r.bits2int,Pt=r.bits2int_modN===void 0?function(w){return h.create(ft(w))}:r.bits2int_modN,nt=Sn(x);function dt(p){return os("num < 2^"+x,p,Le,nt),h.toBytes(p)}function b(p,w){return yt(p,void 0,"message"),w?yt(n(p),void 0,"prehashed message"):p}function s(p,w,S){let{lowS:m,prehash:a,extraEntropy:g}=gs(S,L);p=b(p,a);let F=Pt(p),k=h.fromBytes(w);if(!h.isValidNot0(k))throw new Error("invalid private key");let q=[dt(k),dt(F)];if(g!=null&&g!==!1){let pt=g===!0?i(T.secretKey):g;q.push(yt(pt,void 0,"extraEntropy"))}let z=gt(...q),j=F;function it(pt){let ut=ft(pt);if(!h.isValidNot0(ut))return;let _=h.inv(ut),P=t.BASE.multiply(ut).toAffine(),R=h.create(P.x);if(R===Le)return;let C=h.create(_*h.create(j+R*k));if(C===Le)return;let V=(P.x===R?0:2)|Number(P.y&le),G=C;return m&&D(C)&&(G=h.neg(C),V^=1),new $(R,G,U?void 0:V)}return{seed:z,k2sig:it}}function u(p,w,S={}){let{seed:m,k2sig:a}=s(p,w,S);return Bu(n.outputLen,h.BYTES,o)(m,a).toBytes(S.format)}function f(p,w,S,m={}){let{lowS:a,prehash:g,format:F}=gs(m,L);if(S=yt(S,void 0,"publicKey"),w=b(w,g),!qr(p)){let k=p instanceof $?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}Y(p,F);try{let k=$.fromBytes(p,F),q=t.fromBytes(S);if(a&&k.hasHighS())return!1;let{r:z,s:j}=k,it=Pt(w),pt=h.inv(j),ut=h.create(it*pt),_=h.create(z*pt),P=t.BASE.multiplyUnsafe(ut).add(q.multiplyUnsafe(_));return P.is0()?!1:h.create(P.x)===z}catch{return!1}}function l(p,w,S={}){let{prehash:m}=gs(S,L);return w=b(w,m),$.fromBytes(p,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:v,getPublicKey:y,getSharedSecret:A,utils:O,lengths:T,Point:t,sign:u,verify:f,recoverPublicKey:l,Signature:$,hash:n})}var ah,xs,Ve,Le,le,ir,Pn,ys,dh=Ae(()=>{I();sh();Mr();zr();Pi();On();ah=(t,e)=>(t+(t>=0?e:-e)/ir)/e;xs=class extends Error{constructor(e=""){super(e)}},Ve={Err:xs,_tlv:{encode:(t,e)=>{let{Err:r}=Ve;if(Fe(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=zn(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?zn(i.length/2|128):"";return zn(t)+o+i+e},decode(t,e){let{Err:r}=Ve;e=yt(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),c=0;if(!o)c=i;else{let d=i&127;if(!d)throw new r("tlv.decode(long): indefinite length not supported");if(d>4)throw new r("tlv.decode(long): byte length is too big");let x=e.subarray(n,n+d);if(x.length!==d)throw new r("tlv.decode: length bytes not complete");if(x[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let v of x)c=c<<8|v;if(n+=d,c<128)throw new r("tlv.decode(long): not minimal encoding")}let h=e.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: wrong value length");return{v:h,l:e.subarray(n+c)}}},_int:{encode(t){let{Err:e}=Ve;if(Si(t),t<Le)throw new e("integer: negative integers are not allowed");let r=zn(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ve;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ye(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ve,i=yt(t,void 0,"signature"),{v:o,l:c}=n.decode(48,i);if(c.length)throw new e("invalid signature: left bytes after parsing");let{v:h,l:d}=n.decode(2,o),{v:x,l:v}=n.decode(2,d);if(v.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(h),s:r.decode(x)}},hexFromSig(t){let{_tlv:e,_int:r}=Ve,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}};Object.freeze(Ve._tlv);Object.freeze(Ve._int);Object.freeze(Ve);Le=BigInt(0),le=BigInt(1),ir=BigInt(2),Pn=BigInt(3),ys=BigInt(4)});var Sh={};Of(Sh,{__TEST:()=>Ad,schnorr:()=>Id,schnorr_FROST:()=>Fd,secp256k1:()=>_d,secp256k1_FROST:()=>Bd,secp256k1_hasher:()=>Ss});function Ed(t){let e=Mi.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),c=BigInt(23),h=BigInt(44),d=BigInt(88),x=t*t*t%e,v=x*x*t%e,y=Re(v,r,e)*v%e,A=Re(y,r,e)*v%e,O=Re(A,ws,e)*x%e,T=Re(O,i,e)*O%e,L=Re(T,o,e)*T%e,U=Re(L,h,e)*L%e,D=Re(U,d,e)*U%e,et=Re(D,h,e)*L%e,J=Re(et,r,e)*v%e,Y=Re(J,c,e)*T%e,$=Re(Y,n,e)*x%e,ft=Re($,ws,e);if(!_r.eql(_r.sqr(ft),t))throw new Error("Cannot find square root");return ft}function jn(t,...e){let r=ph[t];if(r===void 0){let n=Ur(bn(t));r=gt(n,n),ph[t]=r}return Ur(gt(r,...e))}function xh(t){let{Fn:e,BASE:r}=bt,n=e.fromBytes(t),i=r.multiply(n);return{scalar:or(i.y)?n:e.neg(n),bytes:Zr(i)}}function Ri(t){let e=_r;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);or(i)||(i=e.neg(i));let o=bt.fromAffine({x:t,y:i});return o.assertValidity(),o}function bs(...t){return bt.Fn.create(Tn(jn("BIP0340/challenge",...t)))}function mh(t){return xh(t).bytes}function Od(t,e,r=Gn(32)){let{Fn:n,BASE:i}=bt,o=yt(t,void 0,"message"),{bytes:c,scalar:h}=xh(e),d=yt(r,32,"auxRand"),x=n.toBytes(h^Tn(jn("BIP0340/aux",d))),v=jn("BIP0340/nonce",x,c,o),y=n.create(Tn(v));if(y===0n)throw new Error("sign failed: k is zero");let A=i.multiply(y),O=or(A.y)?y:n.neg(y),T=Zr(A),L=bs(T,c,o),U=new Uint8Array(64);if(U.set(T,0),U.set(n.toBytes(n.create(O+L*h)),32),!yh(U,o,c))throw new Error("sign: Invalid signature produced");return U}function yh(t,e,r){let{Fp:n,Fn:i,BASE:o}=bt,c=yt(t,64,"signature"),h=yt(e,void 0,"message"),d=yt(r,32,"publicKey");try{let x=Ri(Tn(d)),v=Tn(c.subarray(0,32));if(!n.isValidNot0(v))return!1;let y=Tn(c.subarray(32,64));if(!i.isValidNot0(y))return!1;let A=bs(i.toBytes(v),Zr(x),h),O=o.multiplyUnsafe(y).add(x.multiplyUnsafe(i.neg(A))),{x:T,y:L}=O.toAffine();return!(O.is0()||!or(L)||T!==v)}catch{return!1}}function wh(t,e){if(e===void 0)return vh;let r=Zr(t),n=ye(jn("TapTweak",r,e));if(!bt.Fn.isValid(n))throw new Error("invalid TapTweak hash");return n}function Es(t){let e=bt.fromBytes(t.commitments[0]);return or(e.y)?t:{signers:{min:t.signers.min,max:t.signers.max},commitments:t.commitments.map(r=>bt.fromBytes(r).negate().toBytes()),verifyingShares:Object.fromEntries(Object.entries(t.verifyingShares).map(([r,n])=>[r,bt.fromBytes(n).negate().toBytes()]))}}function bh(t,e){let r=bt.fromBytes(e.commitments[0]);if(or(r.y))return t;let n=bt.Fn;return{...t,signingShare:n.toBytes(n.neg(n.fromBytes(t.signingShare)))}}function Md(t,e){if(or(t.y))return e;let r=bt.Fn;return{binding:r.toBytes(r.neg(r.fromBytes(e.binding))),hiding:r.toBytes(r.neg(r.fromBytes(e.hiding)))}}function Rd(t,e,r){let n=bt.Fn,i=bh(t,e),o=Es(e),c=wh(bt.fromBytes(o.commitments[0]),r),h=n.toBytes(n.add(n.fromBytes(i.signingShare),c));return{identifier:i.identifier,signingShare:h}}function kd(t,e){let r=Es(t),n=wh(bt.fromBytes(r.commitments[0]),e),i=bt.BASE.multiply(n),o=r.commitments.map((h,d)=>(d===0?bt.fromBytes(h).add(i):bt.fromBytes(h)).toBytes()),c={};for(let h in r.verifyingShares)c[h]=bt.fromBytes(r.verifyingShares[h]).add(i).toBytes();return{signers:{min:r.signers.min,max:r.signers.max},commitments:o,verifyingShares:c}}var Mi,Sd,vh,ws,_r,bt,_d,ph,Zr,or,Tn,Ad,Id,Pd,gh,Td,Ss,Bd,Fd,Eh=Ae(()=>{I();Pu();Mr();Pi();ih();rh();On();dh();zr();Mi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Sd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},vh=BigInt(0),ws=BigInt(2);_r=En(Mi.p,{sqrt:Ed}),bt=ch(Mi,{Fp:_r,endo:Sd}),_d=lh(bt,Ur),ph={};Zr=t=>t.toBytes(!0).slice(1),or=t=>t%ws===vh;Tn=ye;Ad=Object.freeze({lift_x:Ri}),Id=(()=>{let r=n=>(n=n===void 0?Gn(48):n,_n(n,Mi.n));return Object.freeze({keygen:Ii(r,mh),getPublicKey:mh,sign:Od,verify:yh,Point:bt,utils:Object.freeze({randomSecretKey:r,taggedHash:jn,lift_x:Ri,pointToBytes:Zr}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),Pd=th(_r,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),Td=()=>gh||(gh=hh(_r,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:_r.create(BigInt("-11"))})),Ss=eh(bt,t=>{let{x:e,y:r}=Td()(_r.create(t[0]));return Pd(e,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:_r.ORDER,m:1,k:128,expand:"xmd",hash:Ur}),Bd=ms({name:"FROST-secp256k1-SHA256-v1",Point:bt,hashToScalar:Ss.hashToScalar,hash:Ur});Fd=ms({name:"FROST-secp256k1-SHA256-TR-v1",Point:bt,hashToScalar:Ss.hashToScalar,hash:Ur,parsePublicKey(t){if(t.length===32)return Ri(ye(t));if(t.length===33)return bt.fromBytes(t);throw new Error(`expected x-only or compressed public key, got length=${t.length}`)},adjustScalar(t){let e=bt.BASE.multiply(t);return or(e.y)?t:bt.Fn.neg(t)},adjustPoint:t=>or(t.y)?t:t.negate(),challenge(t,e,r){return bs(Zr(t),Zr(e),r)},adjustNonces:Md,adjustGroupCommitmentShare:(t,e)=>or(t.y)?e:e.negate(),adjustPublic:Es,adjustSecret:bh,adjustTx:{encode:t=>t.subarray(1),decode:t=>gt(Uint8Array.of(2),t)},adjustDKG:t=>{let e=new Uint8Array(0);return{public:kd(t.public,e),secret:Rd(t.secret,t.public,e)}}})});var Zn=Z((Rv,Ih)=>{"use strict";I();var _h=Nn(),{secp256k1:Hd}=(Eh(),Af(Sh)),$n=Hd.Point,ki=$n.Fn.ORDER;function Ld(t){return BigInt("0x"+(t.toString(16)||"0"))}function _s(t){var e=t.toString(16);return e.length%2&&(e="0"+e),new _h(e,16)}function Fi(t){if(t==null)throw new Error("Invalid Point");if(typeof t=="bigint")return t;if(typeof t=="number")return BigInt(t);if(typeof t=="string")return BigInt(t.indexOf("0x")===0?t:"0x"+t);if(typeof t.toString=="function")return Ld(t);throw new Error("Invalid Point")}function Yn(t){var e=Object.create(St.prototype);return e._p=t,e}function Oh(t,e){var r=Fi(e).toString(16).padStart(64,"0");return $n.fromHex((t?"03":"02")+r)}function Ah(t,e){var r;try{r=Oh((e&1n)===1n,t)}catch{throw new Error("Point does not lie on the curve")}if(r.toAffine().y!==e)throw new Error("Invalid y value for curve.")}function St(t,e,r){if(!(this instanceof St))return new St(t,e,r);var n,i;try{n=Fi(t),i=Fi(e)}catch{throw new Error("Invalid Point")}Ah(n,i);try{this._p=$n.fromAffine({x:n,y:i})}catch{throw new Error("Invalid Point")}return this}St.fromX=function(e,r){try{var n=Yn(Oh(e,r))}catch{throw new Error("Invalid X")}return n.validate(),n};St.getG=function(){return Yn($n.BASE)};St.getN=function(){return _s(ki)};St.prototype.getX=function(){return _s(this._p.toAffine().x)};St.prototype.getY=function(){return _s(this._p.toAffine().y)};Object.defineProperty(St.prototype,"x",{configurable:!0,enumerable:!0,get:function(){return this.getX()}});Object.defineProperty(St.prototype,"y",{configurable:!0,enumerable:!0,get:function(){return this.getY()}});St.prototype.mul=function(e){var r=(Fi(e)%ki+ki)%ki;return r===0n||this._p.is0()?Yn($n.ZERO):Yn(this._p.multiply(r))};St.prototype.add=function(e){return Yn(this._p.add(e._p))};St.prototype.mulAdd=function(e,r,n){return this.mul(e).add(r.mul(n))};St.prototype.eq=function(e){return this._p.equals(e._p)};St.prototype.isInfinity=function(){return this._p.is0()};St.prototype.validate=function(){if(this.isInfinity())throw new Error("Point cannot be equal to Infinity");var e=this._p.toAffine();return Ah(e.x,e.y),this};St.pointToCompressed=function(e){var r=e.getX().toBuffer({size:32}),n=e.getY().toBuffer({size:32}),i,o=n[n.length-1]%2;return o?i=E.Buffer.from([3]):i=E.Buffer.from([2]),E.Buffer.concat([i,r])};St.pointFromCompressed=function(t){if(t.length!==33)throw new Error("invalid buffer length");var e=t[0],r;if(e===3)r=!0;else if(e===2)r=!1;else throw new Error("invalid value of compressed prefix");var n=_h.fromBuffer(t.slice(1,33));return St.fromX(r,n)};St.prototype.toBuffer=function(){return St.pointToCompressed(this)};St.prototype.toHex=function(){return this.toBuffer().toString("hex")};St.fromBuffer=function(t){return St.pointFromCompressed(t)};St.fromHex=function(t){return St.fromBuffer(E.Buffer.from(t,"hex"))};Ih.exports=St});var Bh=Z((Fv,Th)=>{"use strict";I();var Xr=Nn(),Cd=cn(),we=hn(),Nd=yu(),lt=function t(e,r){if(!(this instanceof t))return new t(e,r);if(e instanceof Xr)this.set({r:e,s:r});else if(e){var n=e;this.set(n)}};lt.prototype.set=function(t){return this.r=t.r||this.r||void 0,this.s=t.s||this.s||void 0,this.i=typeof t.i<"u"?t.i:this.i,this.compressed=typeof t.compressed<"u"?t.compressed:this.compressed,this.nhashtype=t.nhashtype||this.nhashtype||void 0,this};lt.fromCompact=function(t){we.checkArgument(E.Buffer.isBuffer(t),"Argument is expected to be a Buffer");var e=new lt,r=!0,n=t.slice(0,1)[0]-27-4;n<0&&(r=!1,n=n+4);var i=t.slice(1,33),o=t.slice(33,65);return we.checkArgument(n===0||n===1||n===2||n===3,new Error("i must be 0, 1, 2, or 3")),we.checkArgument(i.length===32,new Error("r must be 32 bytes")),we.checkArgument(o.length===32,new Error("s must be 32 bytes")),e.compressed=r,e.i=n,e.r=Xr.fromBuffer(i),e.s=Xr.fromBuffer(o),e};lt.fromDER=lt.fromBuffer=function(t,e){var r=lt.parseDER(t,e),n=new lt;return n.r=r.r,n.s=r.s,n};lt.fromTxFormat=function(t){var e=t.readUInt8(t.length-1),r=t.slice(0,t.length-1),n=lt.fromDER(r,!1);return n.nhashtype=e,n};lt.fromString=function(t){var e=E.Buffer.from(t,"hex");return lt.fromDER(e)};function Ph(t,e){we.checkArgument(e.length>0,new Error("Length of "+t+" is zero")),we.checkArgument(!(e[0]&128),new Error("Value of "+t+" is negative")),we.checkArgument(!(e.length>1&&e[0]===0&&!(e[1]&128)),new Error("Value of "+t+" is excessively padded"))}lt.parseDER=function(t,e){we.checkArgument(E.Buffer.isBuffer(t),new Error("DER formatted signature should be a buffer")),Cd.isUndefined(e)&&(e=!0);var r=t[0];we.checkArgument(r===48,new Error("Header byte should be 0x30"));var n=t[1],i=t.slice(2).length;we.checkArgument(!e||n===i,new Error("Length byte should length of what follows")),n=n<i?n:i;var o=t[2];we.checkArgument(o===2,new Error("Integer byte for r should be 0x02"));var c=t[3],h=t.slice(4,4+c),d=Xr.fromBuffer(h),x=t[4]===0;we.checkArgument(c===h.length,new Error("Length of r incorrect"));var v=t[4+c+0];we.checkArgument(v===2,new Error("Integer byte for s should be 0x02"));var y=t[4+c+1],A=t.slice(4+c+2,4+c+2+y),O=Xr.fromBuffer(A),T=t[4+c+2]===0;we.checkArgument(y===A.length,new Error("Length of s incorrect"));var L=4+c+2+y;we.checkArgument(n===L-2,new Error("Length of signature incorrect")),e&&(Ph("r",h),Ph("s",A));var U={header:r,length:n,rheader:o,rlength:c,rneg:x,rbuf:h,r:d,sheader:v,slength:y,sneg:T,sbuf:A,s:O};return U};lt.prototype.toCompact=function(t,e){if(t=typeof t=="number"?t:this.i,e=typeof e=="boolean"?e:this.compressed,!(t===0||t===1||t===2||t===3))throw new Error("i must be equal to 0, 1, 2, or 3");var r=t+27+4;e===!1&&(r=r-4);var n=E.Buffer.from([r]),i=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return E.Buffer.concat([n,i,o])};lt.prototype.toBuffer=lt.prototype.toDER=function(){var t=this.r.toBuffer(),e=this.s.toBuffer(),r=!!(t[0]&128),n=!!(e[0]&128),i=r?E.Buffer.concat([E.Buffer.from([0]),t]):t,o=n?E.Buffer.concat([E.Buffer.from([0]),e]):e,c=i.length,h=o.length,d=2+c+2+h,x=2,v=2,y=48,A=E.Buffer.concat([E.Buffer.from([y,d,x,c]),i,E.Buffer.from([v,h]),o]);return A};lt.prototype.toString=function(){var t=this.toDER();return t.toString("hex")};lt.isTxDER=function(t){if(t.length<9||t.length>73||t[0]!==48||t[1]!==t.length-3)return!1;var e=t[3];if(5+e>=t.length)return!1;var r=t[5+e];if(e+r+7!==t.length)return!1;var n=t.slice(4);if(t[2]!==2||e===0||n[0]&128||e>1&&n[0]===0&&!(n[1]&128))return!1;var i=t.slice(6+e);return!(t[6+e-2]!==2||r===0||i[0]&128||r>1&&i[0]===0&&!(i[1]&128))};lt.prototype.hasLowS=function(){return!(this.s.lt(new Xr(1))||this.s.gt(new Xr("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))};lt.prototype.hasDefinedHashtype=function(){if(!Nd.isNaturalNumber(this.nhashtype))return!1;var t=this.nhashtype&31;return!(t<lt.SIGHASH_ALL||t>lt.SIGHASH_SINGLE)};lt.prototype.toTxFormat=function(){var t=this.toDER(),e=E.Buffer.alloc(1);return e.writeUInt8(this.nhashtype,0),E.Buffer.concat([t,e])};lt.SIGHASH_ALL=1;lt.SIGHASH_NONE=2;lt.SIGHASH_SINGLE=3;lt.SIGHASH_FORKID=64;lt.SIGHASH_ANYONECANPAY=128;lt.prototype.isCanonical=function(){var t=Zn(),e=t.getN().shrn(1);return this.s.lte(e)};lt.prototype.toCanonical=function(){if(this.isCanonical())return new lt({r:this.r,s:this.s,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype});var t=Zn(),e=t.getN(),r=e.sub(this.s);return new lt({r:this.r,s:r,i:this.i,compressed:this.compressed,nhashtype:this.nhashtype})};lt.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 t=Zn(),e=t.getN();if(this.r.gte(e))throw new Error("Signature r component >= curve order");if(this.s.gte(e))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};lt.prototype.isValid=function(){try{return this.validate(),!0}catch{return!1}};lt.prototype.applySecurityPatches=function(){var t=Zn(),e=t.getN(),r=e.shrn(1);if(this.r.isZero()||this.s.isZero())throw new Error("Invalid signature: zero r or s");if(this.r.gte(e)||this.s.gte(e))throw new Error("Invalid signature: out of range");if(this.s.gt(r))throw new Error("Invalid signature: non-canonical (high) s");return this};Th.exports=lt});var Or=Z((Lv,Fh)=>{"use strict";I();var xe=de(),Hi=Nn(),Ud=Dn(),Mh=Bh(),Os=Mh.SIGHASH_ALL|Mh.SIGHASH_FORKID;function Rh(){var t=xe.Script.Interpreter;return t.SCRIPT_VERIFY_P2SH|t.SCRIPT_VERIFY_STRICTENC|t.SCRIPT_VERIFY_DERSIG|t.SCRIPT_VERIFY_LOW_S|t.SCRIPT_VERIFY_MINIMALDATA|t.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY|t.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY|t.SCRIPT_ENABLE_SIGHASH_FORKID|t.SCRIPT_ENABLE_MAGNETIC_OPCODES|t.SCRIPT_ENABLE_MONOLITH_OPCODES}function qd(t){return xe.Script.Interpreter.useGenesisLimits(t)}function Dd(t,e,r){r=r||{};var n=new xe.Script.Interpreter,i=n.verify(t,e,r.tx||new xe.Transaction,r.inputIndex||0,r.flags||Rh(),new Hi(r.satoshis||0));return{ok:i,err:n.errstr||""}}function kh(t,e,r,n,i){return xe.Transaction.sighash.sighashPreimage(t,i||Os,e,r,new Hi(n))}function Gd(t,e,r,n,i){return Ud.sha256sha256(kh(t,e,r,n,i))}function zd(t,e,r,n,i,o){o=o||Os;var c=xe.Transaction.sighash.sign(t,e,o,r,n,new Hi(i));return E.Buffer.concat([c.toDER(),E.Buffer.from([o])])}function Vd(t,e,r){r=r||{};var n=new xe.Transaction().addOutput(new xe.Transaction.Output({script:t,satoshis:e})),i=new xe.Transaction;return i.addInput(new xe.Transaction.Input({prevTxId:n.hash,outputIndex:0,script:xe.Script.empty()}),t,e),r.outputs&&r.outputs.forEach(function(o){i.addOutput(o)}),{funding:n,spend:i}}function Kd(t,e){var r=t.toAddress?t.toAddress():t;return new xe.Transaction.Output({script:xe.Script.buildPublicKeyHashOut(r),satoshis:e})}function jd(t){return t===0?xe.Opcode.OP_0:t===-1?xe.Opcode.OP_1NEGATE:t>=1&&t<=16?xe.Opcode["OP_"+t]:new Hi(t).toScriptNumBuffer()}Fh.exports={SIGHASH:Os,flags:Rh,enableGenesis:qd,verify:Dd,rawPreimage:kh,sighashDigest:Gd,signInput:zd,fundAndSpend:Vd,p2pkhOutput:Kd,scriptNum:jd}});var qh=Z((Nv,Uh)=>{"use strict";I();var Hh=de(),Lh=Dn(),Ch=Or(),Ke=Hh.Script,ne=Hh.Opcode,Xn=Ch.signInput,Nh=Ch.scriptNum;function Yd(t){var e=Lh.sha256(t),r=new Ke().add(ne.OP_SHA256).add(e).add(ne.OP_EQUAL);return{lock:r,meta:{name:"hash-lock",digest:e.toString("hex")},unlock:function(n,i,o){return new Ke().add(o||t)}}}function $d(t){var e=t.toPublicKey(),r=Ke.buildPublicKeyHashOut(e.toAddress());return{lock:r,meta:{name:"p2pkh",address:e.toAddress().toString()},unlock:function(n,i){return new Ke().add(Xn(n,t,0,r,i)).add(e.toBuffer())}}}function Zd(t,e){var r=t.toPublicKey(),n=new Ke().add(Nh(e)).add(ne.OP_CHECKLOCKTIMEVERIFY).add(ne.OP_DROP).add(r.toBuffer()).add(ne.OP_CHECKSIG);return{lock:n,meta:{name:"cltv-timelock",locktime:e},unlock:function(i,o){return new Ke().add(Xn(i,t,0,n,o))}}}function Xd(t,e){var r=e.map(function(i){return i.toPublicKey()}),n=new Ke().add(ne["OP_"+t]);return r.forEach(function(i){n.add(i.toBuffer())}),n.add(ne["OP_"+r.length]).add(ne.OP_CHECKMULTISIG),{lock:n,meta:{name:t+"-of-"+r.length+"-multisig"},unlock:function(i,o,c){c=c||e.slice(0,t);var h=new Ke().add(ne.OP_0);return c.forEach(function(d){h.add(Xn(i,d,0,n,o))}),h}}}function Wd(t){var e=Lh.sha256(t.secret),r=new Ke().add(ne.OP_IF).add(ne.OP_SHA256).add(e).add(ne.OP_EQUALVERIFY).add(t.receiver.toPublicKey().toBuffer()).add(ne.OP_CHECKSIG).add(ne.OP_ELSE).add(Nh(t.timeout)).add(ne.OP_CHECKLOCKTIMEVERIFY).add(ne.OP_DROP).add(t.sender.toPublicKey().toBuffer()).add(ne.OP_CHECKSIG).add(ne.OP_ENDIF);return{lock:r,meta:{name:"htlc",digest:e.toString("hex"),timeout:t.timeout},unlockClaim:function(n,i){return new Ke().add(Xn(n,t.receiver,0,r,i)).add(t.secret).add(ne.OP_1)},unlockRefund:function(n,i){return new Ke().add(Xn(n,t.sender,0,r,i)).add(ne.OP_0)}}}Uh.exports={hashLock:Yd,p2pkh:$d,timeLockCLTV:Zd,multisig:Xd,htlc:Wd}});var Wn=Z((qv,$h)=>{"use strict";I();var Is=de(),Li=Nn(),Dh=Dn(),Ps=Or(),Gh=Is.Script,xt=Is.Opcode,Ts=Ps.SIGHASH,Ci=Ps.scriptNum,Bn=E.Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Bs=new Li("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",16),Qd=E.Buffer.concat([E.Buffer.from([2]),Bn]),zh=E.Buffer.from(Bn).reverse(),Vh=E.Buffer.concat([E.Buffer.from(Bs.toBuffer()).reverse(),E.Buffer.from([0])]),Jd=E.Buffer.concat([E.Buffer.from([48,68,2,32]),Bn,E.Buffer.from([2,32])]);function As(t,e){var r;for(r=0;r<e-1;r++)t.add(xt.OP_1).add(xt.OP_SPLIT);for(r=0;r<e-1;r++)t.add(xt.OP_SWAP).add(xt.OP_CAT);return t}var sr=Is.crypto.Signature,tp=sr.SIGHASH_ALL|sr.SIGHASH_FORKID,ep=sr.SIGHASH_SINGLE|sr.SIGHASH_FORKID,rp=sr.SIGHASH_SINGLE|sr.SIGHASH_ANYONECANPAY|sr.SIGHASH_FORKID,np=sr.SIGHASH_ALL|sr.SIGHASH_ANYONECANPAY|sr.SIGHASH_FORKID;function Ms(t,e){var r=e&&e.sighashType||Ts;return t.add(xt.OP_HASH256),As(t,32),t.add(zh).add(xt.OP_ADD),t.add(Vh).add(xt.OP_MOD),t.add(Ci(32)).add(xt.OP_NUM2BIN),As(t,32),t.add(Bn).add(xt.OP_DUP),t.add(xt.OP_2).add(xt.OP_SWAP).add(xt.OP_CAT),t.add(xt.OP_TOALTSTACK),t.add(E.Buffer.from([48,68,2,32])).add(xt.OP_SWAP).add(xt.OP_CAT),t.add(E.Buffer.from([2,32])).add(xt.OP_CAT),t.add(xt.OP_SWAP).add(xt.OP_CAT),t.add(E.Buffer.from([r])).add(xt.OP_CAT),t.add(xt.OP_FROMALTSTACK).add(xt.OP_CHECKSIG),t}function ip(){return Ms(new Gh)}function Kh(t){return t.add(Ci(40)).add(xt.OP_RIGHT).add(Ci(32)).add(xt.OP_LEFT),t}function op(t){return jh(t,Ts)}function jh(t,e){var r=E.Buffer.from([e&255,0,0,0]);return t.add(xt.OP_DUP).add(Ci(4)).add(xt.OP_RIGHT).add(r).add(xt.OP_EQUALVERIFY),t}function sp(t){var e=E.Buffer.concat(t.map(function(r){return r.toBufferWriter().toBuffer()}));return Dh.sha256sha256(e)}function ap(t){var e=new Gh().add(xt.OP_DUP);return Ms(e),e.add(xt.OP_VERIFY),Kh(e),e.add(E.Buffer.from(t)).add(xt.OP_EQUAL),e}var cp=new Li("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex");function Yh(t){var e=Dh.sha256sha256(t);if(e[0]<1||e[0]>127)return null;var r=new Li(e).add(new Li(Bn)).mod(Bs);if(r.gt(cp))return null;var n=r.toBuffer({size:32});return n[0]>=1?n:null}function up(t,e,r,n,i){typeof i=="number"&&(i={maxTries:i}),i=i||{};var o=i.maxTries||5e3,c=i.start||0,h=i.field||"nLockTime",d=i.sighashType||Ts;if(h!=="nLockTime"&&h!=="sequence")throw new Error("grind field must be 'nLockTime' or 'sequence'");for(var x=t.inputs[e],v=0;v<o;v++){var y=c+v;h==="nLockTime"?t.nLockTime=y:x.sequenceNumber=4294967294-y;var A=Ps.rawPreimage(t,e,r,n,d),O=Yh(A);if(O&&O.length===32)return{preimage:A,tries:v+1,field:h,nonce:y}}throw new Error("OP_PUSH_TX grind failed after "+o+" tries")}$h.exports={Gx:Bn,N:Bs,PUBKEY:Qd,gxLe:zh,N_LE:Vh,DER_PREFIX:Jd,reverseBytes:As,pushTxCore:Ms,authenticator:ip,extractHashOutputs:Kh,assertSighashAll:op,assertSighashType:jh,SIGHASH_ALL_FORKID:tp,SIGHASH_SINGLE_FORKID:ep,SIGHASH_SINGLE_ANYONECANPAY_FORKID:rp,SIGHASH_ALL_ANYONECANPAY_FORKID:np,hashOutputs:sp,valueCovenant:ap,sFromPreimage:Yh,grind:up}});var ks=Z((Gv,Xh)=>{"use strict";I();var Zh=de(),Rs=Wn(),hp=Or(),fp=Zh.Script,ie=Zh.Opcode,Mn=hp.scriptNum;function lp(t){var e=new fp;return e.add(ie.OP_DUP),Rs.pushTxCore(e),e.add(ie.OP_VERIFY),Rs.assertSighashAll(e),e.add(ie.OP_DUP),e.add(Mn(104)).add(ie.OP_SPLIT).add(ie.OP_NIP),e.add(ie.OP_SIZE).add(Mn(52)).add(ie.OP_SUB).add(ie.OP_SPLIT).add(ie.OP_DROP),e.add(ie.OP_OVER),e.add(Mn(52)).add(ie.OP_RIGHT).add(Mn(8)).add(ie.OP_LEFT),e.add(ie.OP_BIN2NUM).add(Mn(t)).add(ie.OP_SUB),e.add(Mn(8)).add(ie.OP_NUM2BIN),e.add(ie.OP_SWAP).add(ie.OP_CAT),e.add(ie.OP_HASH256),e.add(ie.OP_SWAP),Rs.extractHashOutputs(e),e.add(ie.OP_EQUAL),e}Xh.exports={pelsCovenant:lp}});var Ls=Z((Vv,Qh)=>{"use strict";I();var Ui=de(),Wh=Dn(),Hs=Or(),It=Ui.Opcode,Rn=Hs.scriptNum;function Ni(t){return t instanceof Ui.PrivateKey?t.toPublicKey().toBuffer():t instanceof Ui.PublicKey?t.toBuffer():t}function dp(){return{name:"single-key",commit:function(t){return Wh.sha256ripemd160(Ni(t))},emit:function(t){return t.add(It.OP_OVER).add(It.OP_HASH160).add(It.OP_EQUALVERIFY),t.add(It.OP_CHECKSIGVERIFY),t},unlockArgs:function(t,e,r,n,i){var o=Hs.signInput(t,i,e,r,n);return[o,i.toPublicKey().toBuffer()]}}}function Fs(t,e){var r=e.length;if(t<1||t>r||r<1||r>16)throw new Error("multisig requires 1 <= m <= n <= 16");var n=new Ui.Script().add(It["OP_"+t]);return e.forEach(function(i){n.add(E.Buffer.from(i))}),n.add(It["OP_"+r]).add(It.OP_CHECKMULTISIG),n.toBuffer()}function pp(t,e){if(typeof e!="number"||!Number.isInteger(e))throw new Error("multisig(m, nKeys): nKeys is the NUMBER of keys, not the keys themselves"+(Array.isArray(e)?" \u2014 pass "+e.length+" instead of the array":""));if(typeof t!="number"||!Number.isInteger(t))throw new Error("multisig(m, nKeys): m must be an integer");if(t<1||t>e||e<1||e>16)throw new Error("multisig requires 1 <= m <= n <= 16");return{name:t+"-of-"+e+"-multisig",m:t,n:e,commit:function(r){if(r.length!==e)throw new Error("expected "+e+" public keys");return Wh.sha256ripemd160(Fs(t,r.map(Ni)))},emit:function(r){r.add(It.OP_OVER).add(It.OP_HASH160).add(It.OP_EQUALVERIFY),r.add(Rn(1)).add(It.OP_SPLIT).add(It.OP_NIP),r.add(It.OP_SIZE).add(Rn(2)).add(It.OP_SUB).add(It.OP_SPLIT).add(It.OP_DROP);for(var n=0;n<this.n;n++)r.add(Rn(34)).add(It.OP_SPLIT),r.add(It.OP_SWAP).add(Rn(1)).add(It.OP_SPLIT).add(It.OP_NIP),r.add(It.OP_TOALTSTACK);for(r.add(It.OP_DROP),r.add(Rn(this.m)),n=0;n<this.n;n++)r.add(It.OP_FROMALTSTACK);return r.add(Rn(this.n)),r.add(It.OP_CHECKMULTISIGVERIFY),r},unlockArgs:function(r,n,i,o,c){var h=c.keys;if(h.length!==e)throw new Error("expected "+e+" public keys in signer.keys");var d=Fs(t,h.map(Ni)),x=h.map(Ni).map(function(A){return A.toString("hex")}),v=c.signWith.map(function(A){var O=x.indexOf(A.toPublicKey().toBuffer().toString("hex"));if(O<0)throw new Error("signWith key is not in the committed key set");return{idx:O,priv:A}}).sort(function(A,O){return O.idx-A.idx}).slice(0,t);if(v.length<t)throw new Error("need at least "+t+" signing keys");var y=v.map(function(A){return Hs.signInput(r,A.priv,n,i,o)});return[It.OP_0].concat(y).concat([d])}}}function mp(t){if(!t||typeof t.emit!="function"||typeof t.unlockArgs!="function"||typeof t.commit!="function")throw new Error("predicate authorizer needs { commit, emit, unlockArgs } functions");return{name:t.name||"predicate",commit:t.commit,emit:t.emit,unlockArgs:t.unlockArgs}}Qh.exports={singleKey:dp,multisig:pp,predicate:mp,redeemScript:Fs}});var Us=Z((jv,af)=>{"use strict";I();var Cs=de(),Qn=Wn(),Ns=Or(),Jn=Ls(),qi=Cs.Script,rt=Cs.Opcode,ar=Ns.scriptNum;function tf(t,e){var r=E.Buffer.isBuffer(t)?t:e.commit(t);if(r.length!==20)throw new Error("owner commitment must be 20 bytes (HASH160)");return r}function Jh(t,e){return e.length?t.add(E.Buffer.from(e)):t.add(rt.OP_0)}function ef(t,e){return t.add(rt.OP_DUP),Qn.pushTxCore(t),t.add(rt.OP_VERIFY),Qn.assertSighashAll(t),t.add(rt.OP_DUP).add(ar(52)).add(rt.OP_RIGHT).add(ar(8)).add(rt.OP_LEFT).add(rt.OP_TOALTSTACK),t.add(rt.OP_DUP),Qn.extractHashOutputs(t),t.add(rt.OP_TOALTSTACK),t.add(ar(104)).add(rt.OP_SPLIT).add(rt.OP_NIP).add(rt.OP_SIZE).add(ar(52)).add(rt.OP_SUB).add(rt.OP_SPLIT).add(rt.OP_DROP),t.add(rt.OP_DUP).add(ar(4)).add(ar(20)).add(rt.OP_SUBSTR),t.add(rt.OP_SWAP).add(rt.OP_TOALTSTACK),e.emit(t),t.add(rt.OP_FROMALTSTACK),t}function rf(t){return t.add(ar(4)).add(rt.OP_SPLIT).add(ar(20)).add(rt.OP_SPLIT).add(rt.OP_NIP),t.add(rt.OP_TOALTSTACK),t.add(rt.OP_SWAP).add(rt.OP_CAT),t.add(rt.OP_FROMALTSTACK).add(rt.OP_CAT),t}function nf(t){var e=t.toBuffer().length;if(e<=252||e>65535)throw new Error("token script length must use a 3-byte varint (253..65535); got "+e);return t}function gp(t,e,r){r=r||Jn.singleKey();var n=new qi;return n.add(tf(e,r)),n.add(rt.OP_DROP),ef(n,r),rf(n),n.add(rt.OP_FROMALTSTACK),n.add(rt.OP_SWAP),n.add(rt.OP_FROMALTSTACK),n.add(rt.OP_BIN2NUM).add(ar(t)).add(rt.OP_SUB).add(ar(8)).add(rt.OP_NUM2BIN),n.add(rt.OP_SWAP).add(rt.OP_CAT),n.add(rt.OP_HASH256),n.add(rt.OP_EQUAL),nf(n)}function of(t,e){e=e||Jn.singleKey();var r=new qi;return r.add(tf(t,e)),r.add(rt.OP_DROP),ef(r,e),rf(r),r.add(rt.OP_CAT),r.add(rt.OP_SWAP).add(rt.OP_CAT),r.add(rt.OP_CAT),r.add(rt.OP_FROMALTSTACK),r.add(rt.OP_FROMALTSTACK).add(rt.OP_DROP),r.add(rt.OP_SWAP).add(rt.OP_HASH256).add(rt.OP_EQUAL),nf(r)}function vp(t){return Jn.singleKey().commit(t)}function xp(t,e,r,n,i,o){o=o||{};var c=o.auth||Jn.singleKey(),h=o.inputIndex||0;if(e.length!==20)throw new Error("newOwnerHash must be 20 bytes (HASH160)");if(n<=1&&!o.allowLowValue)throw new Error("unlockTransfer: single-output token sets output = input - fee, which burns a "+n+"-sat UTXO (e.g. a 1-sat ordinal). Use Token.transferOrdinal / ownershipTokenMulti to preserve the satoshi.");Qn.grind(r,h,i,n,o.grind);var d=Ns.rawPreimage(r,h,i,n),x=c.unlockArgs(r,h,i,n,t),v=new qi().add(E.Buffer.from(e));return x.forEach(function(y){v.add(y)}),v.add(E.Buffer.from(d)),v}function sf(t,e,r,n,i,o,c){c=c||{};var h=c.auth||Jn.singleKey(),d=c.inputIndex||0;if(e.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");Qn.grind(r,d,i,n,c.grind);var x=Ns.rawPreimage(r,d,i,n),v=h.unlockArgs(r,d,i,n,t),y=new qi;return Jh(y,o.before||E.Buffer.alloc(0)),Jh(y,o.after||E.Buffer.alloc(0)),y.add(E.Buffer.from(o.tokenValue)),y.add(E.Buffer.from(e)),v.forEach(function(A){y.add(A)}),y.add(E.Buffer.from(x)),y}function yp(t,e){return of(t,e)}function wp(t,e,r,n,i,o){o=o||{},n==null&&(n=1);var c=o.tokenIndex||0,h=r.outputs||[],d=h[c];if(!d)throw new Error("transferOrdinal: spend has no output at tokenIndex "+c);if(d.satoshis!==n)throw new Error("transferOrdinal: token output value ("+d.satoshis+" sat) must equal the ordinal value ("+n+" sat) to avoid burning the inscription");function x(O){return O.toBufferWriter().toBuffer()}var v=E.Buffer.concat(h.slice(0,c).map(x)),y=E.Buffer.concat(h.slice(c+1).map(x)),A=new Cs.crypto.BN(n).toBuffer({endian:"little",size:8});return sf(t,e,r,n,i,{before:v,after:y,tokenValue:A},o)}af.exports={ownershipToken:gp,ownershipTokenMulti:of,ordinalLock:yp,ownerId:vp,unlockTransfer:xp,unlockTransferMulti:sf,transferOrdinal:wp}});var js=Z(($v,cf)=>{"use strict";I();var zs=de(),Di=Wn(),bp=ks(),Sp=Us(),Vs=Or(),Ds=zs.Script,Ce=zs.Opcode,Gs=zs.Transaction,qs=Vs.scriptNum;function Ep(t,e){return t instanceof Gs.Output?t:t instanceof Ds?new Gs.Output({script:t,satoshis:e}):Vs.p2pkhOutput(t,e)}function _p(t,e,r,n,i,o){o=o||5e4;for(var c=0;c<o;c++){t.nLockTime=i+c;var h=Vs.rawPreimage(t,e,r,n);if(Di.sFromPreimage(h))return h}throw new Error("covenant grind failed after "+o+" tries")}function Ar(){if(!(this instanceof Ar))return new Ar;this._outputs=[],this._minLockTime=null}Ar.prototype.payTo=function(t,e){return this._outputs.push(Ep(t,e)),this};Ar.prototype.lockUntil=function(t){return this._minLockTime=t,this};Ar.prototype.outputs=function(){return this._outputs.map(function(t){return new Gs.Output(t.toObject())})};Ar.prototype.describe=function(){var t=[];return this._outputs.forEach(function(e,r){t.push("output["+r+"] = "+e.satoshis+" sat to "+e.script.toASM().slice(0,24)+"...")}),this._minLockTime!==null&&t.push("nLockTime >= "+this._minLockTime),"spend allowed iff: "+t.join(" AND ")};Ar.prototype.compile=function(){if(this._outputs.length===0&&this._minLockTime===null)throw new Error("empty policy: add at least one constraint (payTo / lockUntil)");var t=this,e=new Ds().add(Ce.OP_DUP);if(Di.pushTxCore(e),e.add(Ce.OP_VERIFY),this._outputs.length){var r=Di.hashOutputs(this._outputs);e.add(Ce.OP_DUP),Di.extractHashOutputs(e),e.add(E.Buffer.from(r)).add(Ce.OP_EQUALVERIFY)}return this._minLockTime!==null&&(e.add(Ce.OP_DUP),e.add(qs(8)).add(Ce.OP_RIGHT).add(qs(4)).add(Ce.OP_LEFT),e.add(Ce.OP_BIN2NUM).add(qs(this._minLockTime)).add(Ce.OP_GREATERTHANOREQUAL).add(Ce.OP_VERIFY)),e.add(Ce.OP_DROP).add(Ce.OP_1),{lock:e,outputs:t.outputs(),describe:function(){return t.describe()},unlock:function(n,i,o){o=o||0;var c=t._minLockTime===null?0:t._minLockTime;return t._minLockTime!==null&&(n.inputs[o].sequenceNumber=4294967294),new Ds().add(_p(n,o,e,i,c))}}};function Ks(){return new Ar}Ks.perpetual=function(t){return bp.pelsCovenant(t)};Ks.token=function(t,e){return Sp.ownershipToken(t,e)};cf.exports={policy:Ks,Policy:Ar}});var df=Z((Xv,lf)=>{"use strict";I();var Gi=de(),Op=Or();function hf(t){if(t===0)return"OP_0";if(t>=1&&t<=75)return"PUSH("+t+")";if(t===76)return"OP_PUSHDATA1";if(t===77)return"OP_PUSHDATA2";if(t===78)return"OP_PUSHDATA4";try{return Gi.Opcode.fromNumber(t).toString()}catch{return"0x"+t.toString(16)}}function uf(t,e){e=e||16;var r=E.Buffer.from(t).toString("hex");return r.length<=e*2?r||"0":r.slice(0,e*2)+"...("+t.length+"B)"}function Ap(t,e,r){r=r||{};var n=new Gi.Script.Interpreter,i=[];n.stepListener=function(c,h,d){i.push({phase:n.script===e?"lock":"unlock",op:hf(c.opcode&&typeof c.opcode.toNumber=="function"?c.opcode.toNumber():c.opcode.num),stack:h.map(function(x){return uf(x)}),altstack:d.map(function(x){return uf(x)})})};var o=n.verify(t,e,r.tx||new Gi.Transaction,r.inputIndex||0,typeof r.flags=="number"?r.flags:Op.flags(),new Gi.crypto.BN(r.satoshis||0));return{ok:o,err:n.errstr||"",steps:i}}function ff(t){var e=[],r=null;return t.steps.forEach(function(n,i){n.phase!==r&&(e.push("-- "+n.phase+" script --"),r=n.phase);var o=n.stack.length?n.stack.join(" | "):"(empty)",c=n.altstack.length?" alt:["+n.altstack.join(" | ")+"]":"";e.push(String(i).padStart(3)+" "+n.op.padEnd(16)+" -> ["+o+"]"+c)}),e.push((t.ok?"VALID":"INVALID")+(t.err?" ("+t.err+")":"")),e.join(`
|
|
25
|
+
`)}function Ip(t){return console.log(ff(t)),t}lf.exports={trace:Ap,format:ff,print:Ip,opLabel:hf}});var mf=Z((Qv,pf)=>{"use strict";I();pf.exports="7.6.1"});var vf=Z((tx,gf)=>{"use strict";I();var ti=de(),M={Covenant:Fa(),Preimage:Xe(),SIGHASH:Ca(),Builder:Ua(),UTXOGenerator:Ja(),ScriptTester:ec(),CovenantBuilder:Bo().CovenantBuilder,CovenantTemplates:Bo().CovenantTemplates,OpcodeMap:Io(),ScriptUtils:cc(),StackExaminer:fc(),ScriptInterpreter:mc(),CovenantHelpers:Or(),Locks:qh(),PushTx:Wn(),PELS:ks(),Token:Us(),Authorizers:Ls(),DSL:js(),Policy:js().Policy,Debugger:df()};M.policy=M.DSL.policy;M.trace=function(t,e,r){return M.Debugger.trace(t,e,r)};M.enableGenesis=function(t){return M.CovenantHelpers.enableGenesis(t)};M.verifyScript=function(t,e,r){return M.CovenantHelpers.verify(t,e,r)};M.perpetualCovenant=function(t){return M.PELS.pelsCovenant(t)};M.ownershipToken=function(t,e,r){return M.Token.ownershipToken(t,e,r)};M.valueCovenant=function(t){return M.PushTx.valueCovenant(t)};M.ordinalLock=function(t,e){return M.Token.ordinalLock(t,e)};M.transferOrdinal=function(t,e,r,n,i,o){return M.Token.transferOrdinal(t,e,r,n,i,o)};M.createCovenant=function(t,e){return new M.Covenant(t,e)};M.extractPreimage=function(t,e){return new M.Preimage(t,e)};M.analyzeSIGHASH=function(t){return new M.SIGHASH(t)};M.buildCovenant=function(t,e){return new M.Builder(t,e)};M.createUTXOGenerator=function(t){return new M.UTXOGenerator(t)};M.createTestEnvironment=function(t){return M.UTXOGenerator.createTestEnvironment(t)};M.testScript=function(t,e,r){return M.ScriptTester.test(t,e,r)};M.testCovenant=function(t,e,r){return M.ScriptTester.testCovenant(t,e,r)};M.testFieldExtraction=function(t,e,r){return M.ScriptTester.testFieldExtraction(t,e,r)};M.debugScript=function(t,e){var r=new M.ScriptTester(e);return r.debug(t)};M.explainZeroHashes=function(){return M.SIGHASH.explainZeroMystery()};M.getAllSIGHASHTypes=function(){return M.SIGHASH.getAllTypes()};M.demonstrateAllSIGHASH=function(){return M.SIGHASH.generateAllDemonstrations()};M.createCovenantBuilder=function(){return new M.CovenantBuilder};M.createValueLockCovenant=function(t){return M.CovenantTemplates.valueLock(t)};M.createHashLockCovenant=function(t){return M.CovenantTemplates.hashLock(t)};M.createComplexValidationCovenant=function(t){return M.CovenantTemplates.complexValidation(t)};M.getOpcodeMap=function(){return M.OpcodeMap.opcodeMap};M.simulateScript=function(t,e){return M.OpcodeMap.utils.simulate(t,e)};M.createASMFromJS=function(t){return M.OpcodeMap.utils.createASM(t)};M.scriptToASM=function(t){return M.ScriptUtils.scriptToASM(t)};M.asmToScript=function(t){return M.ScriptUtils.asmToScript(t)};M.asmToHex=function(t){return M.ScriptUtils.asmToHex(t)};M.hexToASM=function(t){return M.ScriptUtils.hexToASM(t)};M.scriptToHex=function(t){return M.ScriptUtils.scriptToHex(t)};M.validateASM=function(t){return M.ScriptUtils.validateASM(t)};M.validateScript=function(t){return M.ScriptUtils.validateScript(t)};M.estimateScriptSize=function(t){return M.ScriptUtils.estimateScriptSize(t)};M.optimizeScript=function(t){return M.ScriptUtils.optimizeScript(t)};M.compareScripts=function(t,e){return M.ScriptUtils.compareScripts(t,e)};M.explainScript=function(t){return M.ScriptUtils.explainScript(t)};M.scriptMetrics=function(t){return M.ScriptUtils.scriptMetrics(t)};M.analyzeComplexity=function(t){return M.ScriptUtils.analyzeComplexity(t)};M.findOptimizations=function(t){return M.ScriptUtils.findOptimizations(t)};M.covenantToEnglish=function(t){return M.ScriptUtils.covenantToEnglish(t)};M.batchTestScripts=function(t,e){return M.ScriptUtils.batchTestScripts(t,e)};M.examineStack=function(t,e){return M.StackExaminer.runScript(t,e)};M.debugScriptExecution=function(t,e,r){return r=r||{},r.stepMode?M.ScriptInterpreter.stepThroughScript(M.ScriptInterpreter.parseScript(t+" "+e),new ti.Transaction,!0):M.ScriptInterpreter.runFullEvaluation(M.ScriptInterpreter.parseScript(t),M.ScriptInterpreter.parseScript(e),new ti.Transaction)};M.parseScript=function(t){return M.ScriptInterpreter.parseScript(t)};M.printStack=function(t,e){return M.ScriptInterpreter.printStack(t,e)};M.createQuickCovenant=function(t,e){let r=M.createCovenantBuilder();switch(t){case"value_lock":return r.comment(`Value lock: minimum ${e.value} satoshis`).extractField("value").push(e.value).greaterThanOrEqual().verify().build();case"hash_lock":return r.comment(`Hash lock: requires preimage of ${e.hash}`).push("secret_placeholder").sha256().push(e.hash).equalVerify().build();case"time_lock":return r.comment(`Time lock: requires nLockTime > ${e.timestamp}`).extractField("nLockTime").push(e.timestamp).greaterThan().verify().build();case"multi_condition":let n=r.comment("Multi-condition covenant");return e.conditions.forEach(i=>{switch(i.type){case"value":n=n.extractField("value").push(i.value).greaterThanOrEqual().verify();break;case"hash":n=n.push("secret_placeholder").sha256().push(i.hash).equalVerify();break;case"time":n=n.extractField("nLockTime").push(i.timestamp).greaterThan().verify();break}}),n.build();default:throw new Error(`Unknown covenant type: ${t}`)}};M.completeCovenantFlow=function(t,e,r){var n=new M.Covenant(t);return n.completeFlow(e,r)};M.getEducationalResources=function(){return{zeroHashMystery:M.SIGHASH.explainZeroMystery(),sighashTypes:M.SIGHASH.getAllTypes(),exampleDemonstrations:M.SIGHASH.generateAllDemonstrations()}};M.utils={};M.utils.reconstructP2pkhScript=function(t){return ti.Script.buildPublicKeyHashOut(t).toHex()};M.utils.createCovenantAddress=function(t){var e=ti.crypto.Hash.sha256ripemd160(t.toBuffer());return ti.Address.fromScriptHash(e)};M.utils.decodeCompactSize=function(t,e){return M.Preimage.decodeCompactSize(t,e)};M.version=mf();M.description="Smart Contract Framework for Bitcoin SV";M.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};M.interpretScript=M.debugScriptExecution;M.getScriptMetrics=M.scriptMetrics;gf.exports=M});var Pp=Z((rx,xf)=>{I();xf.exports=vf()});return Pp();})();
|
|
26
26
|
if(typeof module!=="undefined"&&module.exports){module.exports=bsvSmartContract}else if(typeof define==="function"&&define.amd){define([],function(){return bsvSmartContract})}
|