@mikeargento/bitgraph-player 0.8.1 → 0.10.0

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.
@@ -136,7 +136,7 @@ h1.bg-page-title { font-size: clamp(26px, 6vw, 40px); font-weight: 600; letter-s
136
136
  </div>
137
137
  </main>
138
138
  <script>
139
- "use strict";(()=>{var uc=Object.create;var oi=Object.defineProperty;var dc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var lc=Object.getPrototypeOf,pc=Object.prototype.hasOwnProperty;var mc=(t,e)=>()=>(t&&(e=t(t=0)),e);var nr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var gc=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of hc(e))!pc.call(t,o)&&o!==n&&oi(t,o,{get:()=>e[o],enumerable:!(r=dc(e,o))||r.enumerable});return t};var bc=(t,e,n)=>(n=t!=null?uc(lc(t)):{},gc(e||!t||!t.__esModule?oi(n,"default",{value:t,enumerable:!0}):n,t));var ai=nr(an=>{"use strict";w();an.byteLength=wc;an.toByteArray=Ec;an.fromByteArray=Ac;var ve=[],pe=[],yc=typeof Uint8Array<"u"?Uint8Array:Array,rr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(it=0,ii=rr.length;it<ii;++it)ve[it]=rr[it],pe[rr.charCodeAt(it)]=it;var it,ii;pe[45]=62;pe[95]=63;function si(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");n===-1&&(n=e);var r=n===e?0:4-n%4;return[n,r]}function wc(t){var e=si(t),n=e[0],r=e[1];return(n+r)*3/4-r}function xc(t,e,n){return(e+n)*3/4-n}function Ec(t){var e,n=si(t),r=n[0],o=n[1],i=new yc(xc(t,r,o)),s=0,a=o>0?r-4:r,c;for(c=0;c<a;c+=4)e=pe[t.charCodeAt(c)]<<18|pe[t.charCodeAt(c+1)]<<12|pe[t.charCodeAt(c+2)]<<6|pe[t.charCodeAt(c+3)],i[s++]=e>>16&255,i[s++]=e>>8&255,i[s++]=e&255;return o===2&&(e=pe[t.charCodeAt(c)]<<2|pe[t.charCodeAt(c+1)]>>4,i[s++]=e&255),o===1&&(e=pe[t.charCodeAt(c)]<<10|pe[t.charCodeAt(c+1)]<<4|pe[t.charCodeAt(c+2)]>>2,i[s++]=e>>8&255,i[s++]=e&255),i}function Bc(t){return ve[t>>18&63]+ve[t>>12&63]+ve[t>>6&63]+ve[t&63]}function vc(t,e,n){for(var r,o=[],i=e;i<n;i+=3)r=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),o.push(Bc(r));return o.join("")}function Ac(t){for(var e,n=t.length,r=n%3,o=[],i=16383,s=0,a=n-r;s<a;s+=i)o.push(vc(t,s,s+i>a?a:s+i));return r===1?(e=t[n-1],o.push(ve[e>>2]+ve[e<<4&63]+"==")):r===2&&(e=(t[n-2]<<8)+t[n-1],o.push(ve[e>>10]+ve[e>>4&63]+ve[e<<2&63]+"=")),o.join("")}});var ci=nr(or=>{w();or.read=function(t,e,n,r,o){var i,s,a=o*8-r-1,c=(1<<a)-1,f=c>>1,u=-7,d=n?o-1:0,h=n?-1:1,l=t[e+d];for(d+=h,i=l&(1<<-u)-1,l>>=-u,u+=a;u>0;i=i*256+t[e+d],d+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=r;u>0;s=s*256+t[e+d],d+=h,u-=8);if(i===0)i=1-f;else{if(i===c)return s?NaN:(l?-1:1)*(1/0);s=s+Math.pow(2,r),i=i-f}return(l?-1:1)*s*Math.pow(2,i-r)};or.write=function(t,e,n,r,o,i){var s,a,c,f=i*8-o-1,u=(1<<f)-1,d=u>>1,h=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=r?0:i-1,m=r?1:-1,p=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=h/c:e+=h*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=u?(a=0,s=u):s+d>=1?(a=(e*c-1)*Math.pow(2,o),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,o),s=0));o>=8;t[n+l]=a&255,l+=m,a/=256,o-=8);for(s=s<<o|a,f+=o;f>0;t[n+l]=s&255,l+=m,s/=256,f-=8);t[n+l-m]|=p*128}});var ki=nr(xt=>{"use strict";w();var ir=ai(),yt=ci(),fi=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;xt.Buffer=g;xt.SlowBuffer=Cc;xt.INSPECT_MAX_BYTES=50;var cn=2147483647;xt.kMaxLength=cn;g.TYPED_ARRAY_SUPPORT=kc();!g.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 kc(){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(g.prototype,"parent",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.buffer}});Object.defineProperty(g.prototype,"offset",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.byteOffset}});function Pe(t){if(t>cn)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,g.prototype),e}function g(t,e,n){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return fr(t)}return li(t,e,n)}g.poolSize=8192;function li(t,e,n){if(typeof t=="string")return Hc(t,e);if(ArrayBuffer.isView(t))return Sc(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(Ae(t,ArrayBuffer)||t&&Ae(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ae(t,SharedArrayBuffer)||t&&Ae(t.buffer,SharedArrayBuffer)))return ar(t,e,n);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=t.valueOf&&t.valueOf();if(r!=null&&r!==t)return g.from(r,e,n);let o=Tc(t);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return g.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}g.from=function(t,e,n){return li(t,e,n)};Object.setPrototypeOf(g.prototype,Uint8Array.prototype);Object.setPrototypeOf(g,Uint8Array);function pi(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 Ic(t,e,n){return pi(t),t<=0?Pe(t):e!==void 0?typeof n=="string"?Pe(t).fill(e,n):Pe(t).fill(e):Pe(t)}g.alloc=function(t,e,n){return Ic(t,e,n)};function fr(t){return pi(t),Pe(t<0?0:ur(t)|0)}g.allocUnsafe=function(t){return fr(t)};g.allocUnsafeSlow=function(t){return fr(t)};function Hc(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!g.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let n=mi(t,e)|0,r=Pe(n),o=r.write(t,e);return o!==n&&(r=r.slice(0,o)),r}function sr(t){let e=t.length<0?0:ur(t.length)|0,n=Pe(e);for(let r=0;r<e;r+=1)n[r]=t[r]&255;return n}function Sc(t){if(Ae(t,Uint8Array)){let e=new Uint8Array(t);return ar(e.buffer,e.byteOffset,e.byteLength)}return sr(t)}function ar(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return e===void 0&&n===void 0?r=new Uint8Array(t):n===void 0?r=new Uint8Array(t,e):r=new Uint8Array(t,e,n),Object.setPrototypeOf(r,g.prototype),r}function Tc(t){if(g.isBuffer(t)){let e=ur(t.length)|0,n=Pe(e);return n.length===0||t.copy(n,0,0,e),n}if(t.length!==void 0)return typeof t.length!="number"||hr(t.length)?Pe(0):sr(t);if(t.type==="Buffer"&&Array.isArray(t.data))return sr(t.data)}function ur(t){if(t>=cn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+cn.toString(16)+" bytes");return t|0}function Cc(t){return+t!=t&&(t=0),g.alloc(+t)}g.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==g.prototype};g.compare=function(e,n){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),Ae(n,Uint8Array)&&(n=g.from(n,n.offset,n.byteLength)),!g.isBuffer(e)||!g.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===n)return 0;let r=e.length,o=n.length;for(let i=0,s=Math.min(r,o);i<s;++i)if(e[i]!==n[i]){r=e[i],o=n[i];break}return r<o?-1:o<r?1:0};g.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}};g.concat=function(e,n){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return g.alloc(0);let r;if(n===void 0)for(n=0,r=0;r<e.length;++r)n+=e[r].length;let o=g.allocUnsafe(n),i=0;for(r=0;r<e.length;++r){let s=e[r];if(Ae(s,Uint8Array))i+s.length>o.length?(g.isBuffer(s)||(s=g.from(s)),s.copy(o,i)):Uint8Array.prototype.set.call(o,s,i);else if(g.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function mi(t,e){if(g.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Ae(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 n=t.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return cr(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return Ai(t).length;default:if(o)return r?-1:cr(t).length;e=(""+e).toLowerCase(),o=!0}}g.byteLength=mi;function Rc(t,e,n){let r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,e>>>=0,n<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return _c(this,e,n);case"utf8":case"utf-8":return bi(this,e,n);case"ascii":return Fc(this,e,n);case"latin1":case"binary":return Uc(this,e,n);case"base64":return Lc(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Kc(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}g.prototype._isBuffer=!0;function st(t,e,n){let r=t[e];t[e]=t[n],t[n]=r}g.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 n=0;n<e;n+=2)st(this,n,n+1);return this};g.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 n=0;n<e;n+=4)st(this,n,n+3),st(this,n+1,n+2);return this};g.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 n=0;n<e;n+=8)st(this,n,n+7),st(this,n+1,n+6),st(this,n+2,n+5),st(this,n+3,n+4);return this};g.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?bi(this,0,e):Rc.apply(this,arguments)};g.prototype.toLocaleString=g.prototype.toString;g.prototype.equals=function(e){if(!g.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:g.compare(this,e)===0};g.prototype.inspect=function(){let e="",n=xt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"};fi&&(g.prototype[fi]=g.prototype.inspect);g.prototype.compare=function(e,n,r,o,i){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),!g.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(n===void 0&&(n=0),r===void 0&&(r=e?e.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),n<0||r>e.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&n>=r)return 0;if(o>=i)return-1;if(n>=r)return 1;if(n>>>=0,r>>>=0,o>>>=0,i>>>=0,this===e)return 0;let s=i-o,a=r-n,c=Math.min(s,a),f=this.slice(o,i),u=e.slice(n,r);for(let d=0;d<c;++d)if(f[d]!==u[d]){s=f[d],a=u[d];break}return s<a?-1:a<s?1:0};function gi(t,e,n,r,o){if(t.length===0)return-1;if(typeof n=="string"?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,hr(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0)if(o)n=0;else return-1;if(typeof e=="string"&&(e=g.from(e,r)),g.isBuffer(e))return e.length===0?-1:ui(t,e,n,r,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):ui(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function ui(t,e,n,r,o){let i=1,s=t.length,a=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(t.length<2||e.length<2)return-1;i=2,s/=2,a/=2,n/=2}function c(u,d){return i===1?u[d]:u.readUInt16BE(d*i)}let f;if(o){let u=-1;for(f=n;f<s;f++)if(c(t,f)===c(e,u===-1?0:f-u)){if(u===-1&&(u=f),f-u+1===a)return u*i}else u!==-1&&(f-=f-u),u=-1}else for(n+a>s&&(n=s-a),f=n;f>=0;f--){let u=!0;for(let d=0;d<a;d++)if(c(t,f+d)!==c(e,d)){u=!1;break}if(u)return f}return-1}g.prototype.includes=function(e,n,r){return this.indexOf(e,n,r)!==-1};g.prototype.indexOf=function(e,n,r){return gi(this,e,n,r,!0)};g.prototype.lastIndexOf=function(e,n,r){return gi(this,e,n,r,!1)};function $c(t,e,n,r){n=Number(n)||0;let o=t.length-n;r?(r=Number(r),r>o&&(r=o)):r=o;let i=e.length;r>i/2&&(r=i/2);let s;for(s=0;s<r;++s){let a=parseInt(e.substr(s*2,2),16);if(hr(a))return s;t[n+s]=a}return s}function Pc(t,e,n,r){return fn(cr(e,t.length-n),t,n,r)}function Dc(t,e,n,r){return fn(qc(e),t,n,r)}function Nc(t,e,n,r){return fn(Ai(e),t,n,r)}function Oc(t,e,n,r){return fn(Gc(e,t.length-n),t,n,r)}g.prototype.write=function(e,n,r,o){if(n===void 0)o="utf8",r=this.length,n=0;else if(r===void 0&&typeof n=="string")o=n,r=this.length,n=0;else if(isFinite(n))n=n>>>0,isFinite(r)?(r=r>>>0,o===void 0&&(o="utf8")):(o=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-n;if((r===void 0||r>i)&&(r=i),e.length>0&&(r<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let s=!1;for(;;)switch(o){case"hex":return $c(this,e,n,r);case"utf8":case"utf-8":return Pc(this,e,n,r);case"ascii":case"latin1":case"binary":return Dc(this,e,n,r);case"base64":return Nc(this,e,n,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Oc(this,e,n,r);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Lc(t,e,n){return e===0&&n===t.length?ir.fromByteArray(t):ir.fromByteArray(t.slice(e,n))}function bi(t,e,n){n=Math.min(t.length,n);let r=[],o=e;for(;o<n;){let i=t[o],s=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=n){let c,f,u,d;switch(a){case 1:i<128&&(s=i);break;case 2:c=t[o+1],(c&192)===128&&(d=(i&31)<<6|c&63,d>127&&(s=d));break;case 3:c=t[o+1],f=t[o+2],(c&192)===128&&(f&192)===128&&(d=(i&15)<<12|(c&63)<<6|f&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=t[o+1],f=t[o+2],u=t[o+3],(c&192)===128&&(f&192)===128&&(u&192)===128&&(d=(i&15)<<18|(c&63)<<12|(f&63)<<6|u&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),o+=a}return Mc(r)}var di=4096;function Mc(t){let e=t.length;if(e<=di)return String.fromCharCode.apply(String,t);let n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=di));return n}function Fc(t,e,n){let r="";n=Math.min(t.length,n);for(let o=e;o<n;++o)r+=String.fromCharCode(t[o]&127);return r}function Uc(t,e,n){let r="";n=Math.min(t.length,n);for(let o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function _c(t,e,n){let r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);let o="";for(let i=e;i<n;++i)o+=Wc[t[i]];return o}function Kc(t,e,n){let r=t.slice(e,n),o="";for(let i=0;i<r.length-1;i+=2)o+=String.fromCharCode(r[i]+r[i+1]*256);return o}g.prototype.slice=function(e,n){let r=this.length;e=~~e,n=n===void 0?r:~~n,e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),n<0?(n+=r,n<0&&(n=0)):n>r&&(n=r),n<e&&(n=e);let o=this.subarray(e,n);return Object.setPrototypeOf(o,g.prototype),o};function J(t,e,n){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}g.prototype.readUintLE=g.prototype.readUIntLE=function(e,n,r){e=e>>>0,n=n>>>0,r||J(e,n,this.length);let o=this[e],i=1,s=0;for(;++s<n&&(i*=256);)o+=this[e+s]*i;return o};g.prototype.readUintBE=g.prototype.readUIntBE=function(e,n,r){e=e>>>0,n=n>>>0,r||J(e,n,this.length);let o=this[e+--n],i=1;for(;n>0&&(i*=256);)o+=this[e+--n]*i;return o};g.prototype.readUint8=g.prototype.readUInt8=function(e,n){return e=e>>>0,n||J(e,1,this.length),this[e]};g.prototype.readUint16LE=g.prototype.readUInt16LE=function(e,n){return e=e>>>0,n||J(e,2,this.length),this[e]|this[e+1]<<8};g.prototype.readUint16BE=g.prototype.readUInt16BE=function(e,n){return e=e>>>0,n||J(e,2,this.length),this[e]<<8|this[e+1]};g.prototype.readUint32LE=g.prototype.readUInt32LE=function(e,n){return e=e>>>0,n||J(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};g.prototype.readUint32BE=g.prototype.readUInt32BE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};g.prototype.readBigUInt64LE=qe(function(e){e=e>>>0,wt(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&Ft(e,this.length-8);let o=n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*2**8+this[++e]*2**16+r*2**24;return BigInt(o)+(BigInt(i)<<BigInt(32))});g.prototype.readBigUInt64BE=qe(function(e){e=e>>>0,wt(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&Ft(e,this.length-8);let o=n*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r;return(BigInt(o)<<BigInt(32))+BigInt(i)});g.prototype.readIntLE=function(e,n,r){e=e>>>0,n=n>>>0,r||J(e,n,this.length);let o=this[e],i=1,s=0;for(;++s<n&&(i*=256);)o+=this[e+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*n)),o};g.prototype.readIntBE=function(e,n,r){e=e>>>0,n=n>>>0,r||J(e,n,this.length);let o=n,i=1,s=this[e+--o];for(;o>0&&(i*=256);)s+=this[e+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*n)),s};g.prototype.readInt8=function(e,n){return e=e>>>0,n||J(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};g.prototype.readInt16LE=function(e,n){e=e>>>0,n||J(e,2,this.length);let r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};g.prototype.readInt16BE=function(e,n){e=e>>>0,n||J(e,2,this.length);let r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};g.prototype.readInt32LE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};g.prototype.readInt32BE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};g.prototype.readBigInt64LE=qe(function(e){e=e>>>0,wt(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&Ft(e,this.length-8);let o=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(r<<24);return(BigInt(o)<<BigInt(32))+BigInt(n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});g.prototype.readBigInt64BE=qe(function(e){e=e>>>0,wt(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&Ft(e,this.length-8);let o=(n<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(o)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r)});g.prototype.readFloatLE=function(e,n){return e=e>>>0,n||J(e,4,this.length),yt.read(this,e,!0,23,4)};g.prototype.readFloatBE=function(e,n){return e=e>>>0,n||J(e,4,this.length),yt.read(this,e,!1,23,4)};g.prototype.readDoubleLE=function(e,n){return e=e>>>0,n||J(e,8,this.length),yt.read(this,e,!0,52,8)};g.prototype.readDoubleBE=function(e,n){return e=e>>>0,n||J(e,8,this.length),yt.read(this,e,!1,52,8)};function ce(t,e,n,r,o,i){if(!g.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}g.prototype.writeUintLE=g.prototype.writeUIntLE=function(e,n,r,o){if(e=+e,n=n>>>0,r=r>>>0,!o){let a=Math.pow(2,8*r)-1;ce(this,e,n,r,a,0)}let i=1,s=0;for(this[n]=e&255;++s<r&&(i*=256);)this[n+s]=e/i&255;return n+r};g.prototype.writeUintBE=g.prototype.writeUIntBE=function(e,n,r,o){if(e=+e,n=n>>>0,r=r>>>0,!o){let a=Math.pow(2,8*r)-1;ce(this,e,n,r,a,0)}let i=r-1,s=1;for(this[n+i]=e&255;--i>=0&&(s*=256);)this[n+i]=e/s&255;return n+r};g.prototype.writeUint8=g.prototype.writeUInt8=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,1,255,0),this[n]=e&255,n+1};g.prototype.writeUint16LE=g.prototype.writeUInt16LE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,2,65535,0),this[n]=e&255,this[n+1]=e>>>8,n+2};g.prototype.writeUint16BE=g.prototype.writeUInt16BE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,2,65535,0),this[n]=e>>>8,this[n+1]=e&255,n+2};g.prototype.writeUint32LE=g.prototype.writeUInt32LE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,4,4294967295,0),this[n+3]=e>>>24,this[n+2]=e>>>16,this[n+1]=e>>>8,this[n]=e&255,n+4};g.prototype.writeUint32BE=g.prototype.writeUInt32BE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,4,4294967295,0),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};function yi(t,e,n,r,o){vi(e,r,o,t,n,7);let i=Number(e&BigInt(4294967295));t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,n}function wi(t,e,n,r,o){vi(e,r,o,t,n,7);let i=Number(e&BigInt(4294967295));t[n+7]=i,i=i>>8,t[n+6]=i,i=i>>8,t[n+5]=i,i=i>>8,t[n+4]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=s,s=s>>8,t[n+2]=s,s=s>>8,t[n+1]=s,s=s>>8,t[n]=s,n+8}g.prototype.writeBigUInt64LE=qe(function(e,n=0){return yi(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeBigUInt64BE=qe(function(e,n=0){return wi(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeIntLE=function(e,n,r,o){if(e=+e,n=n>>>0,!o){let c=Math.pow(2,8*r-1);ce(this,e,n,r,c-1,-c)}let i=0,s=1,a=0;for(this[n]=e&255;++i<r&&(s*=256);)e<0&&a===0&&this[n+i-1]!==0&&(a=1),this[n+i]=(e/s>>0)-a&255;return n+r};g.prototype.writeIntBE=function(e,n,r,o){if(e=+e,n=n>>>0,!o){let c=Math.pow(2,8*r-1);ce(this,e,n,r,c-1,-c)}let i=r-1,s=1,a=0;for(this[n+i]=e&255;--i>=0&&(s*=256);)e<0&&a===0&&this[n+i+1]!==0&&(a=1),this[n+i]=(e/s>>0)-a&255;return n+r};g.prototype.writeInt8=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,1,127,-128),e<0&&(e=255+e+1),this[n]=e&255,n+1};g.prototype.writeInt16LE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,2,32767,-32768),this[n]=e&255,this[n+1]=e>>>8,n+2};g.prototype.writeInt16BE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,2,32767,-32768),this[n]=e>>>8,this[n+1]=e&255,n+2};g.prototype.writeInt32LE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,4,2147483647,-2147483648),this[n]=e&255,this[n+1]=e>>>8,this[n+2]=e>>>16,this[n+3]=e>>>24,n+4};g.prototype.writeInt32BE=function(e,n,r){return e=+e,n=n>>>0,r||ce(this,e,n,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};g.prototype.writeBigInt64LE=qe(function(e,n=0){return yi(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});g.prototype.writeBigInt64BE=qe(function(e,n=0){return wi(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function xi(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Ei(t,e,n,r,o){return e=+e,n=n>>>0,o||xi(t,e,n,4,34028234663852886e22,-34028234663852886e22),yt.write(t,e,n,r,23,4),n+4}g.prototype.writeFloatLE=function(e,n,r){return Ei(this,e,n,!0,r)};g.prototype.writeFloatBE=function(e,n,r){return Ei(this,e,n,!1,r)};function Bi(t,e,n,r,o){return e=+e,n=n>>>0,o||xi(t,e,n,8,17976931348623157e292,-17976931348623157e292),yt.write(t,e,n,r,52,8),n+8}g.prototype.writeDoubleLE=function(e,n,r){return Bi(this,e,n,!0,r)};g.prototype.writeDoubleBE=function(e,n,r){return Bi(this,e,n,!1,r)};g.prototype.copy=function(e,n,r,o){if(!g.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!o&&o!==0&&(o=this.length),n>=e.length&&(n=e.length),n||(n=0),o>0&&o<r&&(o=r),o===r||e.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-n<o-r&&(o=e.length-n+r);let i=o-r;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(n,r,o):Uint8Array.prototype.set.call(e,this.subarray(r,o),n),i};g.prototype.fill=function(e,n,r,o){if(typeof e=="string"){if(typeof n=="string"?(o=n,n=0,r=this.length):typeof r=="string"&&(o=r,r=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!g.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(e.length===1){let s=e.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(n<0||this.length<n||this.length<r)throw new RangeError("Out of range index");if(r<=n)return this;n=n>>>0,r=r===void 0?this.length:r>>>0,e||(e=0);let i;if(typeof e=="number")for(i=n;i<r;++i)this[i]=e;else{let s=g.isBuffer(e)?e:g.from(e,o),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-n;++i)this[i+n]=s[i%a]}return this};var bt={};function dr(t,e,n){bt[t]=class extends n{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(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}dr("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);dr("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);dr("ERR_OUT_OF_RANGE",function(t,e,n){let r=`The value of "${t}" is out of range.`,o=n;return Number.isInteger(n)&&Math.abs(n)>2**32?o=hi(String(n)):typeof n=="bigint"&&(o=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(o=hi(o)),o+="n"),r+=` It must be ${e}. Received ${o}`,r},RangeError);function hi(t){let e="",n=t.length,r=t[0]==="-"?1:0;for(;n>=r+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function jc(t,e,n){wt(e,"offset"),(t[e]===void 0||t[e+n]===void 0)&&Ft(e,t.length-(n+1))}function vi(t,e,n,r,o,i){if(t>n||t<e){let s=typeof e=="bigint"?"n":"",a;throw i>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:a=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${n}${s}`,new bt.ERR_OUT_OF_RANGE("value",a,t)}jc(r,o,i)}function wt(t,e){if(typeof t!="number")throw new bt.ERR_INVALID_ARG_TYPE(e,"number",t)}function Ft(t,e,n){throw Math.floor(t)!==t?(wt(t,n),new bt.ERR_OUT_OF_RANGE(n||"offset","an integer",t)):e<0?new bt.ERR_BUFFER_OUT_OF_BOUNDS:new bt.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${e}`,t)}var Vc=/[^+/0-9A-Za-z-_]/g;function zc(t){if(t=t.split("=")[0],t=t.trim().replace(Vc,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function cr(t,e){e=e||1/0;let n,r=t.length,o=null,i=[];for(let s=0;s<r;++s){if(n=t.charCodeAt(s),n>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function qc(t){let e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n)&255);return e}function Gc(t,e){let n,r,o,i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}function Ai(t){return ir.toByteArray(zc(t))}function fn(t,e,n,r){let o;for(o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function Ae(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function hr(t){return t!==t}var Wc=(function(){let t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){let r=n*16;for(let o=0;o<16;++o)e[r+o]=t[n]+t[o]}return e})();function qe(t){return typeof BigInt>"u"?Zc:t}function Zc(){throw new Error("BigInt not supported")}});var B,w=mc(()=>{"use strict";B=bc(ki(),1);globalThis.Buffer=B.Buffer});w();w();var Yc={p:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,n:0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,h:8n,a:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,d:0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,Gx:0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Gy:0x6666666666666666666666666666666666666666666666666666666666666658n},{p:ne,n:un,Gx:Ii,Gy:Hi,a:lr,d:pr}=Yc,Xc=8n,Ut=32,mr=64,me=(t="")=>{throw new Error(t)},Jc=t=>typeof t=="bigint",Pi=t=>typeof t=="string",Qc=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array",Bt=(t,e)=>!Qc(t)||typeof e=="number"&&e>0&&t.length!==e?me("Uint8Array expected"):t,pn=t=>new Uint8Array(t),wr=t=>Uint8Array.from(t),Di=(t,e)=>t.toString(16).padStart(e,"0"),xr=t=>Array.from(Bt(t)).map(e=>Di(e,2)).join(""),De={_0:48,_9:57,A:65,F:70,a:97,f:102},Si=t=>{if(t>=De._0&&t<=De._9)return t-De._0;if(t>=De.A&&t<=De.F)return t-(De.A-10);if(t>=De.a&&t<=De.f)return t-(De.a-10)},Er=t=>{let e="hex invalid";if(!Pi(t))return me(e);let n=t.length,r=n/2;if(n%2)return me(e);let o=pn(r);for(let i=0,s=0;i<r;i++,s+=2){let a=Si(t.charCodeAt(s)),c=Si(t.charCodeAt(s+1));if(a===void 0||c===void 0)return me(e);o[i]=a*16+c}return o},dn=(t,e)=>Bt(Pi(t)?Er(t):wr(Bt(t)),e),Ni=()=>globalThis?.crypto,ef=()=>Ni()?.subtle??me("crypto.subtle must be defined"),gr=(...t)=>{let e=pn(t.reduce((r,o)=>r+Bt(o).length,0)),n=0;return t.forEach(r=>{e.set(r,n),n+=r.length}),e},tf=(t=Ut)=>Ni().getRandomValues(pn(t)),hn=BigInt,at=(t,e,n,r="bad number: out of range")=>Jc(t)&&e<=t&&t<n?t:me(r),S=(t,e=ne)=>{let n=t%e;return n>=0n?n:e+n},nf=t=>S(t,un),Oi=(t,e)=>{(t===0n||e<=0n)&&me("no inverse n="+t+" mod="+e);let n=S(t,e),r=e,o=0n,i=1n,s=1n,a=0n;for(;n!==0n;){let c=r/n,f=r%n,u=o-s*c,d=i-a*c;r=n,n=f,o=s,i=a,s=u,a=d}return r===1n?S(o,e):me("no inverse")};var Ti=t=>t instanceof Ne?t:me("Point expected"),br=2n**256n,Ne=class t{static BASE;static ZERO;ex;ey;ez;et;constructor(e,n,r,o){let i=br;this.ex=at(e,0n,i),this.ey=at(n,0n,i),this.ez=at(r,1n,i),this.et=at(o,0n,i),Object.freeze(this)}static fromAffine(e){return new t(e.x,e.y,1n,S(e.x*e.y))}static fromBytes(e,n=!1){let r=pr,o=wr(Bt(e,Ut)),i=e[31];o[31]=i&-129;let s=Br(o);at(s,0n,n?br:ne);let c=S(s*s),f=S(c-1n),u=S(r*c+1n),{isValid:d,value:h}=sf(f,u);d||me("bad point: y not sqrt");let l=(h&1n)===1n,m=(i&128)!==0;return!n&&h===0n&&m&&me("bad point: x==0, isLastByteOdd"),m!==l&&(h=S(-h)),new t(h,s,1n,S(h*s))}assertValidity(){let e=lr,n=pr,r=this;if(r.is0())throw new Error("bad point: ZERO");let{ex:o,ey:i,ez:s,et:a}=r,c=S(o*o),f=S(i*i),u=S(s*s),d=S(u*u),h=S(c*e),l=S(u*S(h+f)),m=S(d+S(n*S(c*f)));if(l!==m)throw new Error("bad point: equation left != right (1)");let p=S(o*i),y=S(s*a);if(p!==y)throw new Error("bad point: equation left != right (2)");return this}equals(e){let{ex:n,ey:r,ez:o}=this,{ex:i,ey:s,ez:a}=Ti(e),c=S(n*a),f=S(i*o),u=S(r*a),d=S(s*o);return c===f&&u===d}is0(){return this.equals(Et)}negate(){return new t(S(-this.ex),this.ey,this.ez,S(-this.et))}double(){let{ex:e,ey:n,ez:r}=this,o=lr,i=S(e*e),s=S(n*n),a=S(2n*S(r*r)),c=S(o*i),f=e+n,u=S(S(f*f)-i-s),d=c+s,h=d-a,l=c-s,m=S(u*h),p=S(d*l),y=S(u*l),b=S(h*d);return new t(m,p,b,y)}add(e){let{ex:n,ey:r,ez:o,et:i}=this,{ex:s,ey:a,ez:c,et:f}=Ti(e),u=lr,d=pr,h=S(n*s),l=S(r*a),m=S(i*d*f),p=S(o*c),y=S((n+r)*(s+a)-h-l),b=S(p-m),I=S(p+m),v=S(l-u*h),M=S(y*b),z=S(I*v),H=S(y*v),U=S(b*I);return new t(M,z,U,H)}multiply(e,n=!0){if(!n&&(e===0n||this.is0()))return Et;if(at(e,1n,un),e===1n)return this;if(this.equals(vt))return lf(e).p;let r=Et,o=vt;for(let i=this;e>0n;i=i.double(),e>>=1n)e&1n?r=r.add(i):n&&(o=o.add(i));return r}toAffine(){let{ex:e,ey:n,ez:r}=this;if(this.equals(Et))return{x:0n,y:1n};let o=Oi(r,ne);return S(r*o)!==1n&&me("invalid inverse"),{x:S(e*o),y:S(n*o)}}toBytes(){let{x:e,y:n}=this.assertValidity().toAffine(),r=rf(n);return r[31]|=e&1n?128:0,r}toHex(){return xr(this.toBytes())}clearCofactor(){return this.multiply(hn(Xc),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.multiply(un/2n,!1).double();return un%2n&&(e=e.add(this)),e.is0()}static fromHex(e,n){return t.fromBytes(dn(e),n)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(){return this.toBytes()}},vt=new Ne(Ii,Hi,1n,S(Ii*Hi)),Et=new Ne(0n,1n,1n,0n);Ne.BASE=vt;Ne.ZERO=Et;var rf=t=>Er(Di(at(t,0n,br),mr)).reverse(),Br=t=>hn("0x"+xr(wr(Bt(t)).reverse())),ke=(t,e)=>{let n=t;for(;e-- >0n;)n*=n,n%=ne;return n},of=t=>{let n=t*t%ne*t%ne,r=ke(n,2n)*n%ne,o=ke(r,1n)*t%ne,i=ke(o,5n)*o%ne,s=ke(i,10n)*i%ne,a=ke(s,20n)*s%ne,c=ke(a,40n)*a%ne,f=ke(c,80n)*c%ne,u=ke(f,80n)*c%ne,d=ke(u,10n)*i%ne;return{pow_p_5_8:ke(d,2n)*t%ne,b2:n}},Ci=0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n,sf=(t,e)=>{let n=S(e*e*e),r=S(n*n*e),o=of(t*r).pow_p_5_8,i=S(t*n*o),s=S(e*i*i),a=i,c=S(i*Ci),f=s===t,u=s===S(-t),d=s===S(-t*Ci);return f&&(i=a),(u||d)&&(i=c),(S(i)&1n)===1n&&(i=S(-i)),{isValid:f||u,value:i}},af=t=>nf(Br(t)),cf=(...t)=>mn.sha512Async(...t);var ff=t=>cf(t.hashable).then(t.finish);var Li={zip215:!0},uf=(t,e,n,r=Li)=>{t=dn(t,mr),e=dn(e),n=dn(n,Ut);let{zip215:o}=r,i,s,a,c,f=Uint8Array.of();try{i=Ne.fromHex(n,o),s=Ne.fromHex(t.slice(0,Ut),o),a=Br(t.slice(Ut,mr)),c=vt.multiply(a,!1),f=gr(s.toBytes(),i.toBytes(),e)}catch{}return{hashable:f,finish:d=>{if(c==null||!o&&i.isSmallOrder())return!1;let h=af(d);return s.add(i.multiply(h,!1)).add(c.negate()).clearCofactor().is0()}}},vr=async(t,e,n,r=Li)=>ff(uf(t,e,n,r));var mn={sha512Async:async(...t)=>{let e=ef(),n=gr(...t);return pn(await e.digest("SHA-512",n.buffer))},sha512Sync:void 0,bytesToHex:xr,hexToBytes:Er,concatBytes:gr,mod:S,invert:Oi,randomBytes:tf};var ln=8,df=256,Mi=Math.ceil(df/ln)+1,yr=2**(ln-1),hf=()=>{let t=[],e=vt,n=e;for(let r=0;r<Mi;r++){n=e,t.push(n);for(let o=1;o<yr;o++)n=n.add(e),t.push(n);e=n.double()}return t},Ri,$i=(t,e)=>{let n=e.negate();return t?n:e},lf=t=>{let e=Ri||(Ri=hf()),n=Et,r=vt,o=2**ln,i=o,s=hn(o-1),a=hn(ln);for(let c=0;c<Mi;c++){let f=Number(t&s);t>>=a,f>yr&&(f-=i,t+=1n);let u=c*yr,d=u,h=u+Math.abs(f)-1,l=c%2!==0,m=f<0;f===0?r=r.add($i(l,e[d])):n=n.add($i(m,e[h]))}return{p:n,f:r}};w();w();w();function mf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ar(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ct(t,...e){if(!mf(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function kt(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 gn(t,e){ct(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Fi(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ie(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function bn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ye(t,e){return t<<32-e|t>>>e}var gf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function bf(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function yf(t){for(let e=0;e<t.length;e++)t[e]=bf(t[e]);return t}var kr=gf?t=>t:yf;function wf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function _t(t){return typeof t=="string"&&(t=wf(t)),ct(t),t}var At=class{};function Kt(t){let e=r=>t().update(_t(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function xf(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,f=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+f,a,r)}function Ui(t,e,n){return t&e^~t&n}function _i(t,e,n){return t&e^t&n^e&n}var jt=class extends At{constructor(e,n,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=bn(this.buffer)}update(e){kt(this),e=_t(e),ct(e);let{view:n,buffer:r,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=bn(e);for(;o<=i-s;s+=o)this.process(c,s);continue}r.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){kt(this),gn(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,Ie(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(r,0),s=0);for(let d=s;d<o;d++)n[d]=0;xf(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=bn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],i)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Oe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);w();var yn=BigInt(4294967295),Ki=BigInt(32);function Ef(t,e=!1){return e?{h:Number(t&yn),l:Number(t>>Ki&yn)}:{h:Number(t>>Ki&yn)|0,l:Number(t&yn)|0}}function wn(t,e=!1){let n=t.length,r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){let{h:s,l:a}=Ef(t[i],e);[r[i],o[i]]=[s,a]}return[r,o]}var Ir=(t,e,n)=>t>>>n,Hr=(t,e,n)=>t<<32-n|e>>>n,ft=(t,e,n)=>t>>>n|e<<32-n,ut=(t,e,n)=>t<<32-n|e>>>n,Vt=(t,e,n)=>t<<64-n|e>>>n-32,zt=(t,e,n)=>t>>>n-32|e<<64-n;var ji=(t,e,n)=>t<<n|e>>>32-n,Vi=(t,e,n)=>e<<n|t>>>32-n,zi=(t,e,n)=>e<<n-32|t>>>64-n,qi=(t,e,n)=>t<<n-32|e>>>64-n;function He(t,e,n,r){let o=(e>>>0)+(r>>>0);return{h:t+n+(o/2**32|0)|0,l:o|0}}var Gi=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Wi=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Zi=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Yi=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,Xi=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Ji=(t,e,n,r,o,i)=>e+n+r+o+i+(t/2**32|0)|0;var vf=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]),Ge=new Uint32Array(64),xn=class extends jt{constructor(e=32){super(64,e,8,!1),this.A=Oe[0]|0,this.B=Oe[1]|0,this.C=Oe[2]|0,this.D=Oe[3]|0,this.E=Oe[4]|0,this.F=Oe[5]|0,this.G=Oe[6]|0,this.H=Oe[7]|0}get(){let{A:e,B:n,C:r,D:o,E:i,F:s,G:a,H:c}=this;return[e,n,r,o,i,s,a,c]}set(e,n,r,o,i,s,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,n){for(let d=0;d<16;d++,n+=4)Ge[d]=e.getUint32(n,!1);for(let d=16;d<64;d++){let h=Ge[d-15],l=Ge[d-2],m=ye(h,7)^ye(h,18)^h>>>3,p=ye(l,17)^ye(l,19)^l>>>10;Ge[d]=p+Ge[d-7]+m+Ge[d-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){let h=ye(a,6)^ye(a,11)^ye(a,25),l=u+h+Ui(a,c,f)+vf[d]+Ge[d]|0,p=(ye(r,2)^ye(r,13)^ye(r,22))+_i(r,o,i)|0;u=f,f=c,c=a,a=s+l|0,s=i,i=o,o=r,r=l+p|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(r,o,i,s,a,c,f,u)}roundClean(){Ie(Ge)}destroy(){this.set(0,0,0,0,0,0,0,0),Ie(this.buffer)}};var Qi=wn(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Af=Qi[0],kf=Qi[1],We=new Uint32Array(80),Ze=new Uint32Array(80),Sr=class extends jt{constructor(e=64){super(128,e,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:e,Al:n,Bh:r,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:d,Fl:h,Gh:l,Gl:m,Hh:p,Hl:y}=this;return[e,n,r,o,i,s,a,c,f,u,d,h,l,m,p,y]}set(e,n,r,o,i,s,a,c,f,u,d,h,l,m,p,y){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=d|0,this.Fl=h|0,this.Gh=l|0,this.Gl=m|0,this.Hh=p|0,this.Hl=y|0}process(e,n){for(let v=0;v<16;v++,n+=4)We[v]=e.getUint32(n),Ze[v]=e.getUint32(n+=4);for(let v=16;v<80;v++){let M=We[v-15]|0,z=Ze[v-15]|0,H=ft(M,z,1)^ft(M,z,8)^Ir(M,z,7),U=ut(M,z,1)^ut(M,z,8)^Hr(M,z,7),F=We[v-2]|0,G=Ze[v-2]|0,q=ft(F,G,19)^Vt(F,G,61)^Ir(F,G,6),le=ut(F,G,19)^zt(F,G,61)^Hr(F,G,6),N=Zi(U,le,Ze[v-7],Ze[v-16]),se=Yi(N,H,q,We[v-7],We[v-16]);We[v]=se|0,Ze[v]=N|0}let{Ah:r,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:d,El:h,Fh:l,Fl:m,Gh:p,Gl:y,Hh:b,Hl:I}=this;for(let v=0;v<80;v++){let M=ft(d,h,14)^ft(d,h,18)^Vt(d,h,41),z=ut(d,h,14)^ut(d,h,18)^zt(d,h,41),H=d&l^~d&p,U=h&m^~h&y,F=Xi(I,z,U,kf[v],Ze[v]),G=Ji(F,b,M,H,Af[v],We[v]),q=F|0,le=ft(r,o,28)^Vt(r,o,34)^Vt(r,o,39),N=ut(r,o,28)^zt(r,o,34)^zt(r,o,39),se=r&i^r&a^i&a,re=o&s^o&c^s&c;b=p|0,I=y|0,p=l|0,y=m|0,l=d|0,m=h|0,{h:d,l:h}=He(f|0,u|0,G|0,q|0),f=a|0,u=c|0,a=i|0,c=s|0,i=r|0,s=o|0;let L=Gi(q,N,re);r=Wi(L,G,le,se),o=L|0}({h:r,l:o}=He(this.Ah|0,this.Al|0,r|0,o|0)),{h:i,l:s}=He(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=He(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=He(this.Dh|0,this.Dl|0,f|0,u|0),{h:d,l:h}=He(this.Eh|0,this.El|0,d|0,h|0),{h:l,l:m}=He(this.Fh|0,this.Fl|0,l|0,m|0),{h:p,l:y}=He(this.Gh|0,this.Gl|0,p|0,y|0),{h:b,l:I}=He(this.Hh|0,this.Hl|0,b|0,I|0),this.set(r,o,i,s,a,c,f,u,d,h,l,m,p,y,b,I)}roundClean(){Ie(We,Ze)}destroy(){Ie(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var es=Kt(()=>new xn);var En=Kt(()=>new Sr);w();w();w();function fe(t){return()=>{throw new Error(`${t} is not available in the browser verifier`)}}var ts=fe("fs.createReadStream"),al=fe("fs.readFileSync"),cl=fe("fs.existsSync"),fl=fe("fs.writeFileSync"),If=fe("fs.open"),Hf=fe("fs.readdir"),ns=fe("fs.readFile"),Sf=fe("fs.stat"),ul=fe("fs.mkdir"),dl=fe("fs.writeFile"),rs=fe("path.join"),hl=fe("path.basename"),os=fe("zlib.createGunzip"),Tf=fe("zlib.gzipSync");w();var _=es;w();w();w();w();w();w();w();var Cf=t=>t/2**32|0,Rf=t=>t>>>0;function is(t,e,n,r){let o=Cf(n),i=Rf(n);t.setUint32(e,r?i:o,r),t.setUint32(e+4,r?o:i,r)}w();function Bn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Tr=t=>t?`"${t}" `:"";function Le(t,e=""){if(typeof t!="number")throw new TypeError(Tr(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Tr(e)+"expected integer >= 0, got "+t);return t}function Se(t,e,n=""){if(Bn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Le(e,"length");let r=Bn(t),o=e!==void 0?` of length ${e}`:"",i=r?`length=${t.length}`:`type=${typeof t}`,s=Tr(n)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}function vn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Le(t.outputLen),Le(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var ss=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function It(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function An(t,e){Se(t,void 0,"output");let n=e.outputLen;if(!(t.length>=n))throw new RangeError('"output" expected length >= '+n)}function qt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function kn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function we(t,e){return t<<32-e|t>>>e}var cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",$f=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function In(t){if(Se(t),cs)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=$f[t[n]];return e}function as(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Cr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(cs)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,n=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let o=0,i=0;o<n;o++,i+=2){let s=as(t.charCodeAt(i)),a=as(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}r[o]=s*16+a}return r}function fs(...t){let e=0;for(let r=0;r<t.length;r++){let o=t[r];Se(o),e+=o.length}let n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){let i=t[r];n.set(i,o),o+=i.length}return n}function Pf(t,e,n="opts"){return ss(t,"defaults"),e!==void 0&&ss(e,n),Object.assign(t,e)}function us(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Pf({},e,"info");let n=(o,i)=>t(i).update(o).digest(),r=t(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=o=>t(o),Object.assign(n,e),Object.freeze(n)}function ds(t=32){Le(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 hs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ls(t,e,n){return t&e^~t&n}function ps(t,e,n){return t&e^t&n^e&n}var Hn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,n,r,o){this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=kn(this.buffer)}update(e){It(this),Se(e);let{view:n,buffer:r,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let f=kn(e);for(;o<=i-a;a+=o)this.process(f,a);s=!0;continue}r.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(n,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){It(this),An(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,n.fill(0,s),this.padOffset>o-s&&(this.process(r,0),n.fill(0)),is(r,o-8,this.length*8,i),this.process(r,0),this.roundClean();let a=e===n?r:kn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],i)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneIntoMeta(e){let{buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,s&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ms=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Df=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]),Ye=new Uint32Array(64),Rr=class extends Hn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,n){super(64,e,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:e,B:n,C:r,D:o,E:i,F:s,G:a,H:c}=this;return[e,n,r,o,i,s,a,c]}set(e,n,r,o,i,s,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,n){for(let d=0;d<16;d++,n+=4)Ye[d]=e.getUint32(n,!1);for(let d=16;d<64;d++){let h=Ye[d-15],l=Ye[d-2],m=we(h,7)^we(h,18)^h>>>3,p=we(l,17)^we(l,19)^l>>>10;Ye[d]=p+Ye[d-7]+m+Ye[d-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){let h=we(a,6)^we(a,11)^we(a,25),l=u+h+ls(a,c,f)+Df[d]+Ye[d]|0,p=(we(r,2)^we(r,13)^we(r,22))+ps(r,o,i)|0;u=f,f=c,c=a,a=s+l|0,s=i,i=o,o=r,r=l+p|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(r,o,i,s,a,c,f,u)}roundClean(){qt(Ye)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}},$r=class extends Rr{constructor(){super(32,ms)}};var gs=us(()=>new $r,hs(1));w();function Tn(t,e,n=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let r=0;r<t.length;r++)n(t[r],`${e}[${r}]`);return t}var X=(t,e,n)=>Se(t,e,n),Pr=Le;function ys(t,e=""){if(typeof t!="string"){let n=e&&`"${e}" `;throw new TypeError(n+"expected string, got type="+typeof t)}return t}function Xe(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function dt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Dr=In,Me=(...t)=>fs(...t),Cn=t=>Cr(t),Ht=Bn,Rn=t=>ds(t),Sn=BigInt(0),bs=BigInt(1),Nf=t=>t?`"${t}" `:"";function Te(t,e=""){if(typeof t!="boolean")throw new TypeError(Nf(e)+"expected boolean, got type="+typeof t);return t}function $n(t){if(typeof t=="bigint"){if(!Je(t))throw new RangeError("positive bigint expected, got "+t)}else Pr(t);return t}function St(t,e=""){if(typeof t!="number"){let n=e&&`"${e}" `;throw new TypeError(n+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let n=e&&`"${e}" `;throw new RangeError(n+"expected safe integer, got "+t)}}function Gt(t){let e=$n(t).toString(16);return e.length&1?"0"+e:e}function ws(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Sn:BigInt("0x"+t)}function Ce(t){return ws(In(t))}function Nr(t){return ws(In(Of(Se(t)).reverse()))}function Pn(t,e){if(Le(e),e===0)throw new Error("zero output length is invalid");t=$n(t);let n=e*2,r=t.toString(16);if(r.length>n)throw new RangeError("number is too large");return Cr(r.padStart(n,"0"))}function Or(t,e){return Pn(t,e).reverse()}function Of(t){return Uint8Array.from(X(t))}function Je(t){return typeof t=="bigint"&&Sn<=t}function Lr(t,e,n){return Je(t)&&Je(e)&&Je(n)&&e<=t&&t<n}function Mr(t,e,n,r){if(!Lr(e,n,r))throw new RangeError("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Tt(t){if(t<Sn)throw new Error("expected non-negative bigint, got "+t);return t===Sn?0:t.toString(2).length}var Wt=t=>(St(t,"n"),(bs<<BigInt(t))-bs);function xs(t,e,n){if(Le(t,"hashLen"),Le(e,"qByteLen"),typeof n!="function")throw new TypeError("hmacFn must be a function");let r=y=>new Uint8Array(y),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=r(t),f=r(t),u=0,d=()=>{c.fill(1),f.fill(0),u=0},h=(...y)=>n(f,Me(c,...y)),l=(y=o)=>{f=h(i,y),c=h(),y.length!==0&&(f=h(s,y),c=h())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,b=[];for(;y<e;){c=h();let I=c.slice();b.push(I),y+=c.length}return Me(...b)};return(y,b)=>{d(),l(y);let I;for(;(I=b(m()))===void 0;)l();return d(),I}}function Qe(t,e={},n={},r="object"){Xe(t,r),Xe(e,"fields"),Xe(n,"optFields");function o(s,a,c){let f=r==="object"?`param "${String(s)}"`:`"${r}.${String(s)}"`,u=t[s];if(!Object.hasOwn(t,s)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let d=typeof u;if(d!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${d}`)}let i=(s,a)=>Object.entries(s).forEach(([c,f])=>o(c,f,a));i(e,!1),i(n,!0)}w();w();var ee=BigInt(0),V=BigInt(1),et=BigInt(2),As=BigInt(3),Fr=BigInt(4),ks=BigInt(5),Lf=BigInt(7),Is=BigInt(8),Mf=BigInt(9),Ff=BigInt(15),Hs=BigInt(16),Uf=BigInt("0x10000000000000000");function de(t,e){if(e<=ee)throw new Error("mod: expected positive modulus, got "+e);let n=t%e;return n>=ee?n:e+n}function Ss(t,e,n){if(n<=V)throw new Error("pow: expected modulus > 1, got "+n);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ee)throw new Error("invalid exponent, negatives unsupported");if(e===ee)return V;if(e===V)return t;let r=t%n;if(r<ee&&(r+=n),e<Uf){let a=V;for(;e>ee;)e&V&&(a=a*r%n),r=r*r%n,e>>=V;return a}let o=[];for(;e>ee;)o.push(Number(e&Ff)),e>>=Fr;let i=new Array(16);i[0]=V,i[1]=r;for(let a=2;a<16;a++)i[a]=i[a-1]*r%n;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%n,s=s*s%n,s=s*s%n,s=s*s%n;let c=o[a];c!==0&&(s=s*i[c]%n)}return s}function Es(t,e){if(t===ee)throw new Error("invert: expected non-zero number");if(e<=V)throw new Error("invert: expected modulus > 1, got "+e);let n=de(t,e),r=e,o=ee,i=V;for(;n!==ee;){let a=r/n,c=r-n*a,f=o-i*a;r=n,n=c,o=i,i=f}if(r!==V)throw new Error("invert: does not exist");return de(o,e)}function Ts(t,e){if(e<=V)throw new Error("invertCt: expected prime modulus > 1, got "+e);let n=de(t,e);if(n===ee)throw new Error("invertCt: expected non-zero number");let r=Ss(n,e-et,e);if(de(n*r,e)!==V)throw new Error("invertCt: does not exist");return r}function Ur(t,e,n){let r=t;if(!r.eql(r.sqr(e),n))throw new Error("Cannot find square root")}function _r(t,e){if((t&V)===ee)throw new Error(e+": expected odd modulus, got "+t)}function Cs(t,e){let n=t,r=(n.ORDER+V)/Fr,o=n.pow(e,r);return Ur(n,o,e),o}function _f(t,e){let n=t,r=(n.ORDER-ks)/Is,o=n.mul(e,et),i=n.pow(o,r),s=n.mul(e,i),a=n.mul(n.mul(s,et),i),c=n.mul(s,n.sub(a,n.ONE));return Ur(n,c,e),c}function Kf(t){let e=Nn(t),n=Rs(t),r=n(e,e.neg(e.ONE)),o=n(e,r),i=n(e,e.neg(r)),s=(t+Lf)/Hs;return((a,c)=>{let f=a,u=f.pow(c,s),d=f.mul(u,r),h=f.mul(u,o),l=f.mul(u,i),m=f.eql(f.sqr(d),c),p=f.eql(f.sqr(h),c);u=f.cmov(u,d,m),d=f.cmov(l,h,p);let y=f.eql(f.sqr(d),c),b=f.cmov(u,d,y);return Ur(f,b,c),b})}function Rs(t){if(t<As)throw new Error("sqrt is not defined for small field");_r(t,"tonelliShanks");let e=t-V,n=0;for(;e%et===ee;)e/=et,n++;let r=et,o=Nn(t);for(;Bs(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Cs;let i=o.pow(r,e),s=(e+V)/et;return function(c,f){let u=c;if(u.is0(f))return f;if(Bs(u,f)!==1)throw new Error("Cannot find square root");let d=n,h=u.mul(u.ONE,i),l=u.pow(f,e),m=u.pow(f,s);for(;!u.eql(l,u.ONE);){if(u.is0(l))throw new Error("Cannot find square root: probably non-prime P");let p=1,y=u.sqr(l);for(;!u.eql(y,u.ONE);)if(p++,y=u.sqr(y),p===d)throw new Error("Cannot find square root");let b=V<<BigInt(d-p-1),I=u.pow(h,b);d=p,h=u.sqr(I),l=u.mul(l,h),m=u.mul(m,I)}return m}}function jf(t){return _r(t,"Fp.sqrt"),t%Fr===As?Cs:t%Is===ks?_f:t%Hs===Mf?Kf(t):Rs(t)}var Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ct(t){if(Xe(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);St(t.BYTES,"BYTES"),St(t.BITS,"BITS");for(let e of Vf)dt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Kr(t,e,n=!1){Ct(t),Tn(e,"nums"),Te(n,"passZero");let r=t,o=new Array(e.length).fill(n?r.ZERO:void 0),i=e.reduce((a,c,f)=>r.is0(c)?a:(o[f]=a,r.mul(a,c)),r.ONE),s=r.inv(i);return e.reduceRight((a,c,f)=>r.is0(c)?a:(o[f]=r.mul(a,o[f]),r.mul(a,c)),s),o}function Bs(t,e){Ct(t);let n=t;_r(n.ORDER,"FpLegendre");let r=(n.ORDER-V)/et,o=n.pow(e,r),i=n.eql(o,n.ONE),s=n.eql(o,n.ZERO),a=n.eql(o,n.neg(n.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function zf(t,e){if(e!==void 0&&Pr(e),t<=ee)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 n=Tt(t);if(e!==void 0&&e<n)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${n})`);let r=e!==void 0?e:n,o=Math.ceil(r/8);return{nBitLength:r,nByteLength:o}}var vs=new WeakMap,Dn=class{ORDER;BITS;BYTES;isLE;ZERO=ee;ONE=V;_lengths;_mod;constructor(e,n={}){if(e<=V)throw new Error("invalid field: expected ORDER > 1, got "+e);let r;this.isLE=!1,n!=null&&typeof n=="object"&&(typeof n.BITS=="number"&&(r=n.BITS),typeof n.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:n.sqrt,enumerable:!0}),typeof n.isLE=="boolean"&&(this.isLE=n.isLE),n.allowedLengths&&(this._lengths=Object.freeze(n.allowedLengths.slice())),typeof n.modFromBytes=="boolean"&&(this._mod=n.modFromBytes));let{nBitLength:o,nByteLength:i}=zf(e,r);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return de(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ee<=e&&e<this.ORDER}is0(e){return e===ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&V)===V}neg(e){return de(-e,this.ORDER)}eql(e,n){return e===n}sqr(e){return de(e*e,this.ORDER)}add(e,n){return de(e+n,this.ORDER)}sub(e,n){return de(e-n,this.ORDER)}mul(e,n){return de(e*n,this.ORDER)}pow(e,n){return Ss(e,n,this.ORDER)}div(e,n){return de(e*Es(n,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,n){return e+n}subN(e,n){return e-n}mulN(e,n){return e*n}inv(e){return Es(e,this.ORDER)}sqrt(e){let n=vs.get(this);return n||vs.set(this,n=jf(this.ORDER)),n(this,e)}toBytes(e){return this.isLE?Or(e,this.BYTES):Pn(e,this.BYTES)}fromBytes(e,n=!1){X(e);let{_lengths:r,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(r){if(e.length<1||!r.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Nr(e):Ce(e);if(a&&(c=de(c,s)),!n&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Kr(this,e,!0)}cmov(e,n,r){return Te(r,"condition"),r?n:e}};function Nn(t,e={}){return Object.freeze(Dn.prototype),new Dn(t,e)}function $s(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=V)throw new Error("field order must be greater than 1");let e=Tt(t-V);return Math.ceil(e/8)}function On(t){let e=$s(t);return e+Math.ceil(e/2)}function jr(t,e,n=!1){X(t);let r=t.length,o=$s(e),i=Math.max(On(e),16);if(r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);let s=n?Nr(t):Ce(t),a=de(s,e-V)+V;return n?Or(a,o):Pn(a,o)}var qr=BigInt(0),Zt=BigInt(1),qf=BigInt(4),Vr=16,Ps=128,Gf=5,Ds=2**31;function Rt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);dt(e.fromAffine,"Point.fromAffine"),dt(e.fromBytes,"Point.fromBytes"),dt(e.fromHex,"Point.fromHex"),Xe(e.BASE,"Point.BASE"),Xe(e.ZERO,"Point.ZERO"),Ct(e.Fp),Ct(e.Fn)}function Os(t,e){Rt(t),Ls(e,t);let n=Kr(t.Fp,e.map(r=>r.Z));return e.map((r,o)=>t.fromAffine(r.toAffine(n[o])))}function Wf(t,e,n=1){if(!Number.isSafeInteger(t)||t<n||t>e)throw new Error("invalid window size, expected ["+n+".."+e+"], got W="+t)}function Zf(t,e){let n=t*(4*e+128);if(n>Ds)throw new Error("invalid window size: table would need ~"+Math.ceil(n/2**20)+" MiB, max "+Ds/2**20+" MiB")}function Gr(t,e){if(t!==void 0){dt(t,"randomBytes");try{let n=t(e);if(!Ht(n)||n.length!==e)return}catch{return}return t}}function Ls(t,e){Tn(t,"points"),t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function Yf(t,e,n){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,o)=>{if(!(n===void 0?e.isValid(r):Je(r)&&r<n))throw new Error("invalid scalar at index "+o)})}var Ms=new WeakMap;function zr(t){return Ms.get(t)||1}function Xf(t,e){let n=t.double(),r=[t];for(let o=1;o<e;o++)r.push(r[o-1].add(n));return r}function Jf(t,e){let n=2**e,r=n/2,o=BigInt(n-1),i=[];for(;t>qr;){let s=0;t&Zt&&(s=Number(t&o),s>=r&&(s-=n),t-=BigInt(s)),i.push(s),t>>=Zt}return i}function Qf(t,e,n){let r=2**e,o=r/2,i=BigInt(r-1),s=BigInt(e),a=[];for(let c=0;c<n;c++){let f=Number(t&i);t>>=s,f>o&&(f-=r,t+=Zt),a.push(f)}if(t!==qr)throw new Error("invalid wnaf");return a}function eu(t,e,n){let r=0;for(let i of n)r=Math.max(r,i.length);let o=t;for(let i=r-1;i>=0;i--){i!==r-1&&(o=o.double());for(let s=0;s<n.length;s++){let a=n[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Ln=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,n){Rt(e),this.randomBytes=Gr(n,Vr),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,n,r){let o=Math.ceil(r/n)+1,i=2**(n-1),s=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<i;u++)s.push(f),f=f.add(a);a=s[s.length-1].double()}return{W:n,bits:r,windows:o,comp:s}}wnafCachedCT(e,n){let{W:r,windows:o,comp:i}=e,s=2**(r-1),a=Qf(n,r,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let d=a[u],h=u*s,l=Math.abs(d)-1,m=i[h];for(let y=1;y<s;y++)m=y===l?i[h+y]:m;let p=m.negate();d===0?f=f.add(i[h]):c=c.add(d<0?p:m)}return{p:c,f}}getWnafPrecomputes(e,n,r,o){let i=this.wnafPrecomputes.get(n),s=i?.find(a=>a.W===e&&a.bits===r);return s||(s=this.buildWnafTable(n,e,r),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(n,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,n){if(this.assertPoint(e),!Lr(n,Zt,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,n,r,o){let i=zr(e);return i===1?this.fixedWindowCT(e,n,r):this.wnafCachedCT(this.getWnafPrecomputes(i,e,r,o),n)}mulCT(e,n,r){return this.validateMulInput(e,n),this.runCT(e,n,this.bits,r)}mulCTBlinded(e,n,r){if(this.validateMulInput(e,n),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ps,i=this.randomBytes(Vr);if(!Ht(i)||i.length!==Vr)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=n+Ce(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,r)}fixedWindowCT(e,n,r){let o=Gf,i=1<<o,s=Wt(o),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(e);let c=Math.ceil(r/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let l=0;l<o;l++)f=f.double();let d=Number(n>>BigInt(u*o)&s),h=a[0];for(let l=1;l<i;l++)h=l===d?a[l]:h;f=f.add(h)}return{p:f,f}}shouldBlind(e,n){return this.randomBytes===void 0?!1:n===Zt?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,n,r,o){return this.shouldBlind(e,r)?this.mulCTBlinded(e,n,o):this.mulCT(e,n,o)}mulUnsafe(e,n,r){if(this.assertPoint(e),!Je(n))throw new Error("invalid scalar");let o=zr(e);if(o===1||n>=this.Point.Fn.ORDER)return Mn(this.Point,[e],[n],!0);let i=this.getWnafPrecomputes(o,e,this.bits,r);return this.wnafCachedCT(i,n).p}setWindowSize(e,n){this.assertPoint(e),Wf(n,this.bits);let r=Math.ceil((this.bits+Ps)/n)+1;Zf(r*2**(n-1),this.Point.Fp.BYTES),Ms.set(e,n),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return zr(e)!==1}};function Mn(t,e,n,r=!1){if(Rt(t),Ls(e,t),Te(r,"allowOversized"),Yf(n,t.Fn,r?t.Fn.ORDER**qf:void 0),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>Xf(s,4)),i=n.map(s=>Jf(s,4));return eu(t.ZERO,o,i)}function Ns(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ct(e),e}else return Nn(t,{isLE:n})}function Fs(t,e,n={},r){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Qe(n);for(let c of["p","n","h"]){let f=e[c];if(!(Je(f)&&f!==qr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ns(e.p,n.Fp,r),i=Ns(e.n,n.Fn,r),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function Us(t,e){return function(r){let o=t(r);return{secretKey:o,publicKey:e(o)}}}w();w();var Fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,n){if(vn(e),Se(n,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),qt(o)}update(e){return It(this),this.iHash.update(e),this}digestInto(e){It(this),An(e,this),this.finished=!0;let n=e.subarray(0,this.outputLen);this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:n,iHash:r,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},_s=(()=>{let t=((e,n,r)=>new Fn(e,n).update(r).digest());return t.create=(e,n)=>new Fn(e,n),t})();w();var tu=BigInt(0),Wr=class extends Error{constructor(e=""){super(e)}},Fe={Err:Wr,_tlv:{encode:(t,e)=>{let{Err:n}=Fe;if(St(t,"tag"),t<0||t>255)throw new n("tlv.encode: wrong tag");if(ys(e,"data"),e.length&1)throw new n("tlv.encode: unpadded data");let r=e.length/2,o=Gt(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");let i=r>127?Gt(o.length/2|128):"";return Gt(t)+i+o+e},decode(t,e){let{Err:n}=Fe;e=X(e,void 0,"DER data");let r=0;if(t<0||t>255)throw new n("tlv.decode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");let o=e[r++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");let f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(r+=c,s<128)throw new n("tlv.decode(long): not minimal encoding")}let a=e.subarray(r,r+s);if(a.length!==s)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+s)}}},_int:{encode(t){let{Err:e}=Fe;if($n(t),t<tu)throw new e("integer: negative integers are not allowed");let n=Gt(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){let{Err:e}=Fe;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 Ce(t)}},toSig(t){let{Err:e,_int:n,_tlv:r}=Fe,o=X(t,void 0,"signature"),{v:i,l:s}=r.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=r.decode(2,i),{v:f,l:u}=r.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:n}=Fe;Qe(t,{r:"bigint",s:"bigint"},{},"sig");let r=e.encode(2,n.encode(t.r)),o=e.encode(2,n.encode(t.s)),i=r+o;return e.encode(48,i)}},Zr=(Object.freeze(Fe._tlv),Object.freeze(Fe._int),Object.freeze(Fe));var Ks=(t,e)=>(t+(t>=0?e:-e)/js)/e;function nu(t,e,n){Mr("scalar",t,Ue,n);let[[r,o],[i,s]]=e,a=Ks(s*t,n),c=Ks(-o*t,n),f=t-a*r-c*i,u=-a*o-c*s,d=f<Ue,h=u<Ue;d&&(f=-f),h&&(u=-u);let l=Wt(Math.ceil(Tt(n)/2))+ht;if(f<Ue||f>=l||u<Ue||u>=l)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:h,k2:u}}function Jr(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Yr(t,e){Qe(t);let n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return Te(n.lowS,"lowS"),Te(n.prehash,"prehash"),n.format!==void 0&&Jr(n.format),n}var Ue=BigInt(0),ht=BigInt(1),js=BigInt(2),Xr=BigInt(3),ru=BigInt(4);function Vs(t,e={}){let n=Fs("weierstrass",t,e),r=n.Fp,o=n.Fn,i=n.CURVE,{h:s,n:a}=i;Qe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,u=e.randomBytes===void 0?Rn:e.randomBytes;if(c&&(!r.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=qs(r,o);function h(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,E,A){if(f&&E.is0())return Uint8Array.of(0);let{x:C,y:D}=E.toAffine(),k=r.toBytes(C);if(Te(A,"isCompressed"),A){h();let x=!r.isOdd(D);return Me(zs(x),k)}else return Me(Uint8Array.of(4),k,r.toBytes(D))}function m(L){X(L,void 0,"Point");let{publicKey:E,publicKeyUncompressed:A}=d,C=L.length,D=L[0],k=L.subarray(1);if(f&&C===1&&D===0)return{x:r.ZERO,y:r.ZERO};if(C===E&&(D===2||D===3)){let x=r.fromBytes(k);if(!r.isValid(x))throw new Error("bad point: is not on curve, wrong x");let T=v(x),R;try{R=r.sqrt(T)}catch(j){let K=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}h();let O=r.isOdd(R);return(D&1)===1!==O&&(R=r.neg(R)),{x,y:R}}else if(C===A&&D===4){let x=r.BYTES,T=r.fromBytes(k.subarray(0,x)),R=r.fromBytes(k.subarray(x,x*2));if(!M(T,R))throw new Error("bad point: is not on curve");return{x:T,y:R}}else throw new Error(`bad point: got length ${C}, expected compressed=${E} or uncompressed=${A}`)}let p=e.toBytes===void 0?l:e.toBytes,y=e.fromBytes===void 0?m:e.fromBytes,b=r.mul(i.b,Xr),I=r.is0(i.a)?L=>r.ZERO:L=>r.mul(i.a,L);function v(L){let E=r.sqr(L),A=r.mul(E,L);return r.add(r.add(A,r.mul(L,i.a)),i.b)}function M(L,E){let A=r.sqr(E),C=v(L);return r.eql(A,C)}if(!M(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let z=r.mul(r.pow(i.a,Xr),ru),H=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(z,H)))throw new Error("bad curve params: a or b");function U(L,E,A=!1){if(!r.isValid(E)||A&&r.is0(E))throw new Error(`bad point coordinate ${L}`);return E}function F(L){if(!(L instanceof N))throw new Error("Weierstrass Point expected")}function G(L){if(!c||!c.basises)throw new Error("no endo");return nu(L,c.basises,o.ORDER)}function q(L,E,A,C){if(!o.isValid(C))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:D,k1:k,k2neg:x,k2:T}=G(C),R=new N(r.mul(A.X,c.beta),A.Y,A.Z);L.push(D?A.negate():A,x?R.negate():R),E.push(k,T)}else L.push(A),E.push(C)}let le=new WeakSet;class N{static BASE=new N(i.Gx,i.Gy,r.ONE);static ZERO=new N(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=o;X;Y;Z;constructor(E,A,C){this.X=U("x",E),this.Y=U("y",A,!0),this.Z=U("z",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){let{x:A,y:C}=E||{};if(!E||!r.isValid(A)||!r.isValid(C))throw new Error("invalid affine point");if(E instanceof N)throw new Error("projective point not allowed");return r.is0(A)&&r.is0(C)?N.ZERO:new N(A,C,r.ONE)}static fromBytes(E){let A=N.fromAffine(y(X(E,void 0,"point")));return A.assertValidity(),A}static fromHex(E){return N.fromBytes(Cn(E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=6,A=!0){return re.setWindowSize(this,E),A||this.multiply(Xr),this}assertValidity(){let E=this;if(E.is0()){if(e.allowInfinityPoint&&r.is0(E.X)&&r.eql(E.Y,r.ONE)&&r.is0(E.Z))return;throw new Error("bad point: ZERO")}if(le.has(E))return;let{x:A,y:C}=E.toAffine();if(!r.isValid(A)||!r.isValid(C))throw new Error("bad point: x or y not field elements");if(!M(A,C))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");le.add(E)}hasEvenY(){let{y:E}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(E)}equals(E){F(E);let{X:A,Y:C,Z:D}=this,{X:k,Y:x,Z:T}=E,R=r.eql(r.mul(A,T),r.mul(k,D)),O=r.eql(r.mul(C,T),r.mul(x,D));return R&&O}negate(){return new N(this.X,r.neg(this.Y),this.Z)}double(){let{X:E,Y:A,Z:C}=this,D=r.ZERO,k=r.ZERO,x=r.ZERO,T=r.mul(E,E),R=r.mul(A,A),O=r.mul(C,C),P=r.mul(E,A);return P=r.add(P,P),x=r.mul(E,C),x=r.add(x,x),D=I(x),k=r.mul(b,O),k=r.add(D,k),D=r.sub(R,k),k=r.add(R,k),k=r.mul(D,k),D=r.mul(P,D),x=r.mul(b,x),O=I(O),P=r.sub(T,O),P=I(P),P=r.add(P,x),x=r.add(T,T),T=r.add(x,T),T=r.add(T,O),T=r.mul(T,P),k=r.add(k,T),O=r.mul(A,C),O=r.add(O,O),T=r.mul(O,P),D=r.sub(D,T),x=r.mul(O,R),x=r.add(x,x),x=r.add(x,x),new N(D,k,x)}add(E){F(E);let{X:A,Y:C,Z:D}=this,{X:k,Y:x,Z:T}=E,R=r.ZERO,O=r.ZERO,P=r.ZERO,j=r.mul(A,k),K=r.mul(C,x),Z=r.mul(D,T),ae=r.add(A,C),W=r.add(k,x);ae=r.mul(ae,W),W=r.add(j,K),ae=r.sub(ae,W),W=r.add(A,D);let te=r.add(k,T);return W=r.mul(W,te),te=r.add(j,Z),W=r.sub(W,te),te=r.add(C,D),R=r.add(x,T),te=r.mul(te,R),R=r.add(K,Z),te=r.sub(te,R),P=I(W),R=r.mul(b,Z),P=r.add(R,P),R=r.sub(K,P),P=r.add(K,P),O=r.mul(R,P),K=r.add(j,j),K=r.add(K,j),Z=I(Z),W=r.mul(b,W),K=r.add(K,Z),Z=r.sub(j,Z),Z=I(Z),W=r.add(W,Z),j=r.mul(K,W),O=r.add(O,j),j=r.mul(te,W),R=r.mul(ae,R),R=r.sub(R,j),j=r.mul(ae,K),P=r.mul(te,P),P=r.add(P,j),new N(R,O,P)}subtract(E){return F(E),this.add(E.negate())}is0(){return this.equals(N.ZERO)}multiply(E){if(!o.isValidNot0(E))throw new RangeError("invalid scalar: out of range");let{p:A,f:C}=re.mulSecret(this,E,s,se);return se([A,C])[0]}multiplyUnsafe(E){let A=this,C=E;if(!o.isValid(C))throw new RangeError("invalid scalar: out of range");if(C===Ue||A.is0())return N.ZERO;if(C===ht)return A;if(re.hasWindowSize(this))return re.mulUnsafe(A,C,se);let D=[],k=[];return q(D,k,A,C),Mn(N,D,k)}mulAddUnsafe(E,A,C){F(A);let D=[],k=[];return q(D,k,this,E),q(D,k,A,C),Mn(N,D,k)}toAffine(E){let A=this,C=E;if(C!=null&&!r.isValid(C))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:k,Z:x}=A;if(r.eql(x,r.ONE))return{x:D,y:k};let T=A.is0();C==null&&(C=T?r.ONE:r.inv(x));let R=r.mul(D,C),O=r.mul(k,C),P=r.mul(x,C);if(T)return{x:r.ZERO,y:r.ZERO};if(!r.eql(P,r.ONE))throw new Error("invZ was invalid");return{x:R,y:O}}isTorsionFree(){let{isTorsionFree:E}=e;return s===ht?!0:E?E(N,this):re.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:E}=e;return s===ht?this:E?E(N,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===ht?this.is0():this.clearCofactor().is0()}toBytes(E=!0){return Te(E,"isCompressed"),this.assertValidity(),p(N,this,E)}toHex(E=!0){return Dr(this.toBytes(E))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let se=L=>Os(N,L),re=new Ln(N,u);return re.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function zs(t){return Uint8Array.of(t?2:3)}function qs(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function ou(t,e={}){Rt(t);let{Fn:n}=t,r=e.randomBytes===void 0?Rn:e.randomBytes,o=Object.assign(qs(t.Fp,n),{seed:Math.max(On(n.ORDER),16)});function i(l){try{let m=n.fromBytes(l);return n.isValidNot0(m)}catch{return!1}}function s(l,m){let{publicKey:p,publicKeyUncompressed:y}=o;try{let b=l.length;return m===!0&&b!==p||m===!1&&b!==y?!1:!!t.fromBytes(l)}catch{return!1}}function a(l){return l=l===void 0?r(o.seed):l,jr(X(l,o.seed,"seed"),n.ORDER)}function c(l,m=!0){return t.BASE.multiply(n.fromBytes(l)).toBytes(m)}function f(l){let{secretKey:m,publicKey:p,publicKeyUncompressed:y}=o,b=n._lengths;if(!Ht(l))return;let I=X(l,void 0,"key").length,v=I===p||I===y,M=I===m||!!b?.includes(I);if(!(v&&M))return v}function u(l,m,p=!0){if(f(l)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let y=n.fromBytes(l);return t.fromBytes(m).multiply(y).toBytes(p)}let d={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=Us(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:t,utils:d,lengths:o})}function Gs(t,e,n={}){Rt(t);let r=e;vn(r),Qe(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},n),i=o.randomBytes===void 0?Rn:o.randomBytes,s=o.hmac===void 0?(k,x)=>_s(r,k,x):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,d=On(f),h=Gr(i,d),{keygen:l,getPublicKey:m,getSharedSecret:p,utils:y,lengths:b}=ou(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},v=f*js+ht<a.ORDER;function M(k){let x=f>>ht;return k>x}function z(k,x){if(!c.isValidNot0(x))throw new Error(`invalid signature ${k}: out of range 1..Point.Fn.ORDER`);return x}function H(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(k,x,T){return H(),(k===T?0:2)|Number(a.isOdd(x))}function F(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function G(k,x){Jr(x);let T=b.signature,R=x==="compact"?T:x==="recovered"?T+1:void 0;return X(k,R)}class q{r;s;recovery;constructor(x,T,R){if(this.r=z("r",x),this.s=z("s",T),R!=null){if(F(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,T=I.format){G(x,T);let R;if(T==="der"){let{r:K,s:Z}=Zr.toSig(X(x));return new q(K,Z)}T==="recovered"&&(R=x[0],T="compact",x=x.subarray(1));let O=b.signature/2,P=x.subarray(0,O),j=x.subarray(O,O*2);return new q(c.fromBytes(P),c.fromBytes(j),R)}static fromHex(x,T){return this.fromBytes(Cn(x),T)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new q(this.r,this.s,x)}recoverPublicKey(x){let{r:T,s:R}=this,O=this.assertRecovery(),P=O===2||O===3?T+f:T;if(!a.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let j=a.toBytes(P),K=t.fromBytes(Me(zs((O&1)===0),j)),Z=c.inv(P),ae=N(X(x,void 0,"msgHash")),W=c.create(-ae*Z),te=c.create(R*Z),Ee=t.BASE.mulAddUnsafe(W,K,te);if(Ee.is0())throw new Error("invalid recovery: point at infinify");return Ee.assertValidity(),Ee}hasHighS(){return M(this.s)}toBytes(x=I.format){if(Jr(x),x==="der")return Cn(Zr.hexFromSig(this));let{r:T,s:R}=this,O=c.toBytes(T),P=c.toBytes(R);return x==="recovered"?(F(),Me(Uint8Array.of(this.assertRecovery()),O,P)):Me(O,P)}toHex(x){return Dr(this.toBytes(x))}}Object.freeze(q.prototype),Object.freeze(q);let le=o.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let T=Ce(x),R=x.length*8-u;return R>0?T>>BigInt(R):T}:o.bits2int,N=o.bits2int_modN===void 0?function(x){return c.create(le(x))}:o.bits2int_modN,se=Wt(u);function re(k){return Mr("num < 2^"+u,k,Ue,se),c.toBytes(k)}function L(k,x){return X(k,void 0,"message"),x?X(r(k),void 0,"prehashed message"):k}function E(k,x,T){let{lowS:R,prehash:O,extraEntropy:P}=Yr(T,I);k=L(k,O);let j=N(k),K=c.fromBytes(x);if(!c.isValidNot0(K))throw new Error("invalid private key");let Z=[re(K),re(j)];if(P!=null&&P!==!1){let Ee=P===!0?i(b.secretKey):P;Z.push(X(Ee,void 0,"extraEntropy"))}let ae=Me(...Z),W=j;function te(Ee){let gt=le(Ee);if(!c.isValidNot0(gt))return;let Lt=t.BASE.multiply(gt).toAffine(),ze=c.create(Lt.x);if(ze===Ue)return;let Be;if(h!==void 0){let Mt=Ce(jr(h(d),f)),ac=c.inv(c.mul(Mt,gt)),cc=c.mul(Mt,W),fc=c.mul(Mt,K);Be=c.create(ac*c.create(cc+fc*ze))}else{let Mt=Ts(gt,f);Be=c.create(Mt*c.create(W+ze*K))}if(Be===Ue)return;let tr=U(Lt.x,Lt.y,ze),ri=Be;return R&&M(Be)&&(ri=c.neg(Be),tr^=1),new q(ze,ri,v?void 0:tr)}return{seed:ae,k2sig:te}}function A(k,x,T={}){let{seed:R,k2sig:O}=E(k,x,T);return xs(r.outputLen,c.BYTES,s)(R,O).toBytes(T.format)}function C(k,x,T,R={}){let{lowS:O,prehash:P,format:j}=Yr(R,I);if(T=X(T,void 0,"publicKey"),x=L(x,P),!Ht(k)){let K=k instanceof q?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}G(k,j);try{let K=q.fromBytes(k,j),Z=t.fromBytes(T);if(O&&K.hasHighS())return!1;let{r:ae,s:W}=K,te=N(x),Ee=c.inv(W),gt=c.create(te*Ee),Lt=c.create(ae*Ee),ze=t.BASE.mulAddUnsafe(gt,Z,Lt);if(ze.is0())return!1;let Be=ze.toAffine();return!(c.create(Be.x)!==ae||j==="recovered"&&K.recovery!==U(Be.x,Be.y,ae))}catch{return!1}}function D(k,x,T={}){let{prehash:R}=Yr(T,I);return x=L(x,R),q.fromBytes(k,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:l,getPublicKey:m,getSharedSecret:p,utils:y,lengths:b,Point:t,sign:A,verify:C,recoverPublicKey:D,Signature:q,hash:r})}var iu={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")};var su=Vs(iu),Ws=Gs(su,gs);var eo=globalThis.crypto,Qr=class{hasher;constructor(e){let n=e.toLowerCase().replace("-","");if(n==="sha256")this.hasher=_.create();else if(n==="sha512")this.hasher=En.create();else throw new Error(`createHash: unsupported algorithm ${e} in the browser verifier`)}update(e){return this.hasher.update(typeof e=="string"?new TextEncoder().encode(e):e),this}digest(e){let n=this.hasher.digest(),r=B.Buffer.from(n);return e===void 0?r:r.toString(e)}};function Un(t){return new Qr(t)}function to(t){let e=[];return{update(n){return e.push(n),this},verify(n,r){try{let o=n instanceof Uint8Array?n:n.key,i=o.subarray(o.length-65);if(i.length!==65||i[0]!==4)return!1;let s=0;for(let f of e)s+=f.length;let a=new Uint8Array(s),c=0;for(let f of e)a.set(f,c),c+=f.length;return Ws.verify(r,_(a),i,{format:"der",prehash:!1,lowS:!1})}catch{return!1}}}}w();function xe(t){let e=Zs(t);return new TextEncoder().encode(e)}function Zs(t){return JSON.stringify(no(t))}function no(t){if(t===null||typeof t!="object"){if(typeof t>"u")throw new TypeError("bitgraph-core/canonical: undefined values are not serializable to canonical JSON");if(typeof t=="function"||typeof t=="symbol")throw new TypeError(`bitgraph-core/canonical: ${typeof t} values are not serializable to canonical JSON`);if(typeof t=="bigint")throw new TypeError("bitgraph-core/canonical: BigInt values are not serializable to canonical JSON; convert to string (decimal) before canonicalizing");return t}if(Array.isArray(t))return t.map(no);let e={};for(let n of Object.keys(t).sort()){let r=t[n];typeof r>"u"||(e[n]=no(r))}return e}function _n(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}async function oo(t){let{proof:e,bytes:n,trustAnchors:r}=t,o=await Ys(e,n,r);return o===null?{valid:!0}:mu(o)}async function lt(t){let{proof:e,trustAnchors:n}=t,r=await Ys(e,void 0,n);return r===null?{valid:!0,artifactBinding:"not-checked"}:{valid:!1,artifactBinding:"not-checked",reason:r}}async function Ys(t,e,n){let r=cu(t);if(r!==null)return r;let o=e===void 0?void 0:_(e),i;try{i=$t(t.artifact.digestB64)}catch{return"artifact.digestB64 is not valid base64"}if(o!==void 0&&!_n(o,i))return"artifact digest mismatch: the provided bytes do not match the committed digest";let s;try{s=$t(t.signer.publicKeyB64)}catch{return"signer.publicKeyB64 is not valid base64"}if(s.length!==32)return`signer.publicKeyB64 decodes to ${s.length} bytes; expected 32 (Ed25519)`;let a={version:t.version,artifact:t.artifact,commit:t.commit,publicKeyB64:t.signer.publicKeyB64,enforcement:t.environment.enforcement,measurement:t.environment.measurement};t.environment.attestation!==void 0&&(a.attestationFormat=t.environment.attestation.format),t.agency!==void 0&&(a.actor=t.agency.actor),t.policy!==void 0&&(a.policy=t.policy),t.attribution!==void 0&&(a.attribution=t.attribution);let c=xe(a),f;try{f=$t(t.signer.signatureB64)}catch{return"signer.signatureB64 is not valid base64"}if(f.length!==64)return`signer.signatureB64 decodes to ${f.length} bytes; expected 64 (Ed25519)`;let u;try{u=await vr(f,c,s)}catch(d){return`signature verification error: ${d instanceof Error?d.message:String(d)}`}if(!u)return"signature verification failed: signature does not match";if(t.agency!==void 0){let d=du(t);if(d!==null)return d}if(t.slotAllocation!==void 0){let d=await hu(t);if(d!==null)return d}if(t.commit.epochLink!==void 0){let d=pu(t);if(d!==null)return d}if(n!==void 0){let d=fu(t,n);if(d!==null)return d}return null}var au=new Set(["stub","hw-key","measured-tee"]);function cu(t){if(t===null||typeof t!="object")return"proof must be an object";let e=t;if(e.version!=="bitgraph/1")return`unsupported proof version: ${String(e.version)}`;if(!Yt(e.artifact))return"proof.artifact is missing or not an object";let n=e.artifact;if(n.hashAlg!=="sha256")return`unsupported hashAlg: ${String(n.hashAlg)}`;if(typeof n.digestB64!="string"||n.digestB64.length===0)return"proof.artifact.digestB64 must be a non-empty string";if(!Yt(e.commit))return"proof.commit is missing or not an object";let r=e.commit;if(typeof r.nonceB64!="string"||r.nonceB64.length===0)return"proof.commit.nonceB64 must be a non-empty string";if(r.counter!==void 0&&typeof r.counter!="string")return"proof.commit.counter must be a string when present";if(r.time!==void 0&&(typeof r.time!="number"||!Number.isFinite(r.time)||r.time<0))return"proof.commit.time must be a non-negative finite number when present";if(r.prevB64!==void 0&&typeof r.prevB64!="string")return"proof.commit.prevB64 must be a string when present";if(r.epochId!==void 0&&typeof r.epochId!="string")return"proof.commit.epochId must be a string when present";if(!Yt(e.signer))return"proof.signer is missing or not an object";let o=e.signer;if(typeof o.publicKeyB64!="string"||o.publicKeyB64.length===0)return"proof.signer.publicKeyB64 must be a non-empty string";if(typeof o.signatureB64!="string"||o.signatureB64.length===0)return"proof.signer.signatureB64 must be a non-empty string";if(!Yt(e.environment))return"proof.environment is missing or not an object";let i=e.environment;if(typeof i.enforcement!="string"||!au.has(i.enforcement))return"proof.environment.enforcement must be one of: stub, hw-key, measured-tee";if(typeof i.measurement!="string"||i.measurement.length===0)return"proof.environment.measurement must be a non-empty string";if(i.attestation!==void 0){if(!Yt(i.attestation))return"proof.environment.attestation must be an object when present";let s=i.attestation;if(typeof s.format!="string"||s.format.length===0)return"proof.environment.attestation.format must be a non-empty string";if(typeof s.reportB64!="string"||s.reportB64.length===0)return"proof.environment.attestation.reportB64 must be a non-empty string"}return null}function fu(t,e){if(e.requireEnforcement!==void 0&&t.environment.enforcement!==e.requireEnforcement)return`enforcement tier "${t.environment.enforcement}" does not meet required tier "${e.requireEnforcement}"`;if(e.allowedMeasurements!==void 0&&e.allowedMeasurements.length>0&&!e.allowedMeasurements.includes(t.environment.measurement))return`measurement "${t.environment.measurement}" is not in the allowed set`;if(e.allowedPublicKeys!==void 0&&e.allowedPublicKeys.length>0&&!e.allowedPublicKeys.includes(t.signer.publicKeyB64))return"proof public key is not in the allowed set";if(e.requireAttestation===!0&&t.environment.attestation===void 0)return"policy requires attestation but proof has none";if(e.requireAttestationFormat!==void 0&&e.requireAttestationFormat.length>0){if(t.environment.attestation===void 0)return"policy requires attestation format but proof has no attestation";if(!e.requireAttestationFormat.includes(t.environment.attestation.format))return`attestation format "${t.environment.attestation.format}" is not in the required set`}if(e.minCounter!==void 0||e.maxCounter!==void 0){if(t.commit.counter===void 0)return"policy requires a counter but proof has none";let n;try{n=BigInt(t.commit.counter)}catch{return"could not parse proof counter value as integer"}if(e.minCounter!==void 0){let r;try{r=BigInt(e.minCounter)}catch{return"could not parse policy minCounter as integer"}if(n<r)return`counter ${t.commit.counter} is below minimum ${e.minCounter}`}if(e.maxCounter!==void 0){let r;try{r=BigInt(e.maxCounter)}catch{return"could not parse policy maxCounter as integer"}if(n>r)return`counter ${t.commit.counter} is above maximum ${e.maxCounter}`}}if(e.minTime!==void 0||e.maxTime!==void 0){if(t.commit.time===void 0)return"policy requires a time field but proof has none";if(e.minTime!==void 0&&t.commit.time<e.minTime)return`commit time ${t.commit.time} is before minimum ${e.minTime}`;if(e.maxTime!==void 0&&t.commit.time>e.maxTime)return`commit time ${t.commit.time} is after maximum ${e.maxTime}`}if(e.requireEpochId===!0&&(t.commit.epochId===void 0||t.commit.epochId.length===0))return"policy requires epochId but proof has none";if(e.requireActor===!0&&t.agency===void 0)return"policy requires actor (agency) but proof has none";if(e.allowedActorKeyIds!==void 0&&e.allowedActorKeyIds.length>0){if(t.agency===void 0)return"policy requires allowed actor key ID but proof has no agency";if(!e.allowedActorKeyIds.includes(t.agency.actor.keyId))return"actor key ID is not in the allowed set"}if(e.allowedActorProviders!==void 0&&e.allowedActorProviders.length>0){if(t.agency===void 0)return"policy requires allowed actor provider but proof has no agency";if(!e.allowedActorProviders.includes(t.agency.actor.provider))return`actor provider "${t.agency.actor.provider}" is not in the allowed set`}if(e.allowedOrigins!==void 0&&e.allowedOrigins.length>0){if(t.agency===void 0)return"policy requires an allowed origin but proof has no agency";let n=t.agency.authorization;if(!("format"in n)||n.format!=="webauthn")return"policy requires an allowed WebAuthn origin but the authorization is not WebAuthn";let r;try{r=JSON.parse(n.clientDataJSON).origin}catch{r=void 0}if(typeof r!="string"||!e.allowedOrigins.includes(r))return`WebAuthn origin "${r??"(none)"}" is not in the allowed set`}return e.requireSlot===!0&&t.slotAllocation===void 0?"policy requires slotAllocation (BitGraph causal slot) but proof has none":null}function uu(t,e){if(typeof t!="string"||t.length===0)return"agency: clientDataJSON missing origin field";let n;try{n=new URL(t).hostname.toLowerCase()}catch{return"agency: clientDataJSON origin is not a valid origin"}if(!n)return"agency: clientDataJSON origin has no host";let r=e.subarray(0,32).toString("hex"),o=n.split("."),i=[];for(let a=0;a<o.length;a++){let c=o.slice(a).join(".");if(a>0&&o.length-a<2)break;i.push(c)}return i.some(a=>Un("sha256").update(a,"utf8").digest("hex")===r)?null:"agency: authenticatorData rpIdHash does not match the origin's domain"}function du(t){let e=t.agency,{actor:n,authorization:r}=e,o="format"in r&&r.format==="webauthn";if(typeof n.keyId!="string"||n.keyId.length===0)return"agency.actor.keyId must be a non-empty string";if(typeof n.publicKeyB64!="string"||n.publicKeyB64.length===0)return"agency.actor.publicKeyB64 must be a non-empty string";if(n.algorithm!=="ES256")return`agency.actor.algorithm must be "ES256", got "${String(n.algorithm)}"`;if(typeof n.provider!="string"||n.provider.length===0)return"agency.actor.provider must be a non-empty string";if(r.purpose!=="bitgraph/commit-authorize/v1")return`agency.authorization.purpose must be "bitgraph/commit-authorize/v1", got "${String(r.purpose)}"`;if(typeof r.signatureB64!="string"||r.signatureB64.length===0)return"agency.authorization.signatureB64 must be a non-empty string";let i;try{i=B.Buffer.from(n.publicKeyB64,"base64")}catch{return"agency.actor.publicKeyB64 is not valid base64"}if(Un("sha256").update(i).digest("hex")!==n.keyId)return"agency: actor.keyId does not match SHA-256 of public key";if(r.actorKeyId!==n.keyId)return"agency: authorization.actorKeyId does not match actor.keyId";if(r.artifactHash!==t.artifact.digestB64){let c=e.batchContext;if(!c||!Array.isArray(c.batchDigests)||!c.batchDigests.includes(t.artifact.digestB64)||c.batchDigests[0]!==r.artifactHash)return"agency: authorization.artifactHash does not match proof.artifact.digestB64"}let a;try{a=B.Buffer.from(r.signatureB64,"base64")}catch{return"agency.authorization.signatureB64 is not valid base64"}try{if(o){let c=r;if(typeof c.clientDataJSON!="string"||!c.clientDataJSON)return"agency: WebAuthn authorization missing clientDataJSON";if(typeof c.authenticatorDataB64!="string"||!c.authenticatorDataB64)return"agency: WebAuthn authorization missing authenticatorDataB64";let f;try{f=JSON.parse(c.clientDataJSON)}catch{return"agency: clientDataJSON is not valid JSON"}if(f.type!=="webauthn.get")return`agency: clientDataJSON.type must be "webauthn.get", got "${f.type}"`;if(!f.challenge)return"agency: clientDataJSON missing challenge field";let u=f.challenge.replace(/-/g,"+").replace(/_/g,"/");for(;u.length%4;)u+="=";if(u!==r.challenge)return"agency: clientDataJSON challenge does not match authorization.challenge";let d=B.Buffer.from(c.authenticatorDataB64,"base64");if(d.length<37)return"agency: authenticatorData too short";let h=d[32];if(!(h&1))return"agency: authenticatorData UP flag not set";if(!(h&4))return"agency: authenticatorData UV flag not set";let l=uu(f.origin,d);if(l!==null)return l;let m=Un("sha256").update(B.Buffer.from(c.clientDataJSON,"utf8")).digest(),p=B.Buffer.concat([d,m]),y=to("SHA256");if(y.update(p),!y.verify({key:i,format:"der",type:"spki"},a))return"agency: WebAuthn P-256 signature verification failed"}else{let c={purpose:r.purpose,actorKeyId:r.actorKeyId,artifactHash:r.artifactHash,challenge:r.challenge,timestamp:r.timestamp};"protocolVersion"in r&&r.protocolVersion!==void 0&&(c.protocolVersion=r.protocolVersion);let f=B.Buffer.from(JSON.stringify(c,Object.keys(c).sort()),"utf8"),u=to("SHA256");if(u.update(f),!u.verify({key:i,format:"der",type:"spki"},a))return"agency: P-256 signature verification failed"}}catch(c){return`agency: P-256 signature verification error: ${c instanceof Error?c.message:String(c)}`}return null}async function hu(t){let e=t.slotAllocation;if(e.version!=="bitgraph/slot/1")return`slotAllocation.version must be "bitgraph/slot/1", got "${String(e.version)}"`;if(typeof e.nonceB64!="string"||e.nonceB64.length===0)return"slotAllocation.nonceB64 must be a non-empty string";if(typeof e.counter!="string"||e.counter.length===0)return"slotAllocation.counter must be a non-empty string";if(e.time!==void 0&&(typeof e.time!="number"||!Number.isFinite(e.time)||e.time<0))return"slotAllocation.time must be a non-negative finite number when present";if(typeof e.epochId!="string"||e.epochId.length===0)return"slotAllocation.epochId must be a non-empty string";if(typeof e.publicKeyB64!="string"||e.publicKeyB64.length===0)return"slotAllocation.publicKeyB64 must be a non-empty string";if(typeof e.signatureB64!="string"||e.signatureB64.length===0)return"slotAllocation.signatureB64 must be a non-empty string";let n={version:e.version,nonceB64:e.nonceB64,counter:e.counter,...e.time!==void 0?{time:e.time}:{},epochId:e.epochId,publicKeyB64:e.publicKeyB64,...e.chainId?{chainId:e.chainId}:{}},r=xe(n),o,i;try{o=$t(e.signatureB64),i=$t(e.publicKeyB64)}catch{return"slotAllocation contains invalid base64"}if(o.length!==64)return`slotAllocation.signatureB64 decodes to ${o.length} bytes; expected 64 (Ed25519)`;if(i.length!==32)return`slotAllocation.publicKeyB64 decodes to ${i.length} bytes; expected 32 (Ed25519)`;let s;try{s=await vr(o,r,i)}catch(d){return`slotAllocation signature verification error: ${d instanceof Error?d.message:String(d)}`}if(!s)return"slotAllocation signature verification failed";let a=new Set(["digestB64","artifact","hashAlg","signatureB64"]),c=Object.keys(n);for(let d of c)if(a.has(d))return`slotAllocation body contains forbidden field '${d}' \u2014 causal independence violated`;if(typeof t.commit.slotHashB64!="string"||t.commit.slotHashB64.length===0)return"commit.slotHashB64 must be present when slotAllocation is present";let f=_(r),u;try{u=$t(t.commit.slotHashB64)}catch{return"commit.slotHashB64 is not valid base64"}if(!_n(f,u))return"commit.slotHashB64 does not match SHA-256 of canonical slot body \u2014 slot binding broken";if(e.nonceB64!==t.commit.nonceB64)return"slotAllocation.nonceB64 does not match commit.nonceB64";if(typeof t.commit.slotCounter!="string"||t.commit.slotCounter.length===0)return"commit.slotCounter must be present when slotAllocation is present";if(t.commit.slotCounter!==e.counter)return"commit.slotCounter does not match slotAllocation.counter";if(t.commit.counter===void 0)return"commit.counter must be present for slot ordering verification";try{let d=BigInt(e.counter),h=BigInt(t.commit.counter);if(d>=h)return`slotAllocation.counter (${e.counter}) must be less than commit.counter (${t.commit.counter})`}catch{return"could not parse slot or commit counter as integer"}return e.publicKeyB64!==t.signer.publicKeyB64?"slotAllocation.publicKeyB64 does not match signer.publicKeyB64 \u2014 different enclave":t.commit.epochId!==void 0&&e.epochId!==t.commit.epochId?"slotAllocation.epochId does not match commit.epochId \u2014 different lifecycle":null}var ro=new Map;function lu(t){let e=`${t.prevEpochId}|${t.prevCounter}|${t.prevProofHashB64}`,n=_(new TextEncoder().encode(e));return B.Buffer.from(n).toString("base64")}function pu(t){let e=t.commit.epochLink;if(typeof e.prevEpochId!="string"||e.prevEpochId.length===0)return"epochLink.prevEpochId must be a non-empty string";if(typeof e.prevPublicKeyB64!="string"||e.prevPublicKeyB64.length===0)return"epochLink.prevPublicKeyB64 must be a non-empty string";if(typeof e.prevCounter!="string"||e.prevCounter.length===0)return"epochLink.prevCounter must be a non-empty string";if(typeof e.prevProofHashB64!="string"||e.prevProofHashB64.length===0)return"epochLink.prevProofHashB64 must be a non-empty string";if(typeof e.toEpochId!="string"||e.toEpochId.length===0)return"epochLink.toEpochId must be a non-empty string";if(typeof e.toPublicKeyB64!="string"||e.toPublicKeyB64.length===0)return"epochLink.toPublicKeyB64 must be a non-empty string";try{BigInt(e.prevCounter)}catch{return"epochLink.prevCounter is not a valid decimal string"}if(t.commit.epochId!==void 0&&e.toEpochId!==t.commit.epochId)return`epochLink.toEpochId "${e.toEpochId}" does not match proof commit.epochId "${t.commit.epochId}" \u2014 successor binding broken`;if(e.toPublicKeyB64!==t.signer.publicKeyB64)return"epochLink.toPublicKeyB64 does not match proof signer.publicKeyB64 \u2014 successor binding broken";if(e.prevEpochId===e.toEpochId)return"epochLink.prevEpochId equals toEpochId \u2014 epoch link must cross epoch boundary";if(e.prevPublicKeyB64===e.toPublicKeyB64)return"epochLink.prevPublicKeyB64 equals toPublicKeyB64 \u2014 epochs must have different keys";let n=lu(e),r=ro.get(n);if(r!==void 0){if(r!==e.toEpochId)return`FORK DETECTED: predecessor (epoch=${e.prevEpochId.slice(0,12)}..., counter=${e.prevCounter}) already consumed by epoch ${r.slice(0,12)}..., but this proof claims consumption by epoch ${e.toEpochId.slice(0,12)}... \u2014 single-successor invariant violated`}else ro.set(n,e.toEpochId);return null}function _e(){ro.clear()}function mu(t){return{valid:!1,reason:t}}function Yt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function $t(t){let e=B.Buffer.from(t,"base64");if(e.toString("base64")!==t)throw new Error(`invalid base64 string: "${t}"`);return new Uint8Array(e)}w();function Kn(t){let e=t,n=e.signer,r=e.environment,o={version:e.version,artifact:e.artifact,commit:e.commit,publicKeyB64:n?.publicKeyB64,enforcement:r?.enforcement,measurement:r?.measurement};e.attribution&&(o.attribution=e.attribution),r?.attestation&&(o.attestationFormat=r.attestation.format);let i=xe(o),s=_(i);return so(s)}var Xs=["proofHash","ethereum"];function io(t){let e=t,n=e;if(Xs.some(o=>Object.prototype.hasOwnProperty.call(e,o))){n={};for(let o of Object.keys(e))Xs.includes(o)||(n[o]=e[o])}let r=xe(n);return so(_(r))}function so(t){if(typeof B.Buffer<"u")return B.Buffer.from(t).toString("base64");let e="";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}function Js(t){let e=t,n=e.signer,r=e.environment,o={version:e.version,artifact:e.artifact,commit:e.commit,publicKeyB64:n?.publicKeyB64,enforcement:r?.enforcement,measurement:r?.measurement};r?.attestation!==void 0&&(o.attestationFormat=r.attestation.format);let i=e.agency;return i!==void 0&&(o.actor=i.actor),e.policy!==void 0&&(o.policy=e.policy),e.attribution!==void 0&&(o.attribution=e.attribution),o}function ao(t){return so(_(xe(Js(t))))}w();var pt="bitgraph-fuse/1",ta=(()=>{let t=new TextEncoder().encode(pt),e=new Uint8Array(t.length+1);return e.set(t,0),e[t.length]=0,e})(),na=pt,co="BGFUSE01",jn=48,uo="bitgraph-fuse/manifest.json",ho="bitgraph-fuse/original",Pt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xt={};for(let t=0;t<Pt.length;t++)Xt[Pt[t]]=t;function tt(t){let e="";for(let n=0;n<t.length;n+=3){let r=t[n],o=n+1<t.length?t[n+1]:0,i=n+2<t.length?t[n+2]:0;e+=Pt[r>>2]+Pt[(r&3)<<4|o>>4],e+=n+1<t.length?Pt[(o&15)<<2|i>>6]:"=",e+=n+2<t.length?Pt[i&63]:"="}return e}function Jt(t){if(typeof t!="string"||t.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(t))return null;let e=t.endsWith("==")?2:t.endsWith("=")?1:0,n=new Uint8Array(t.length/4*3-e),r=0;for(let o=0;o<t.length;o+=4){let i=Xt[t[o]]<<18|Xt[t[o+1]]<<12|(t[o+2]==="="?0:Xt[t[o+2]])<<6|(t[o+3]==="="?0:Xt[t[o+3]]);n[r++]=i>>16&255,r<n.length&&(n[r++]=i>>8&255),r<n.length&&(n[r++]=i&255)}return tt(n)!==t?null:n}function Nt(t){let e="";for(let n of t)e+=(n<16?"0":"")+n.toString(16);return e}function lo(t){if(typeof t!="string"||t.length%2!==0||!/^[0-9a-f]*$/.test(t))return null;let e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}function nt(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}function po(...t){let e=0;for(let o of t)e+=o.length;let n=new Uint8Array(e),r=0;for(let o of t)n.set(o,r),r+=o.length;return n}var ge=t=>new TextEncoder().encode(t);function ra(t){return{version:t.version,nonceB64:t.nonceB64,counter:t.counter,...t.time!==void 0?{time:t.time}:{},epochId:t.epochId,publicKeyB64:t.publicKeyB64,...t.chainId?{chainId:t.chainId}:{}}}function oa(t){return _(xe(ra(t)))}function ia(t){let e=Jt(t.nonceB64);if(e===null||e.length!==32)throw new TypeError("slot.nonceB64 must decode to exactly 32 bytes");return po(ta,oa(t),e)}function zn(t){return _(ia(t))}function qn(t,e){if(t.length!==32)throw new TypeError("commitment must be 32 bytes");if(e!==void 0&&e.length!==32)throw new TypeError("originDigest must be 32 bytes");let n={type:pt,...e!==void 0?{origin:{algorithm:"sha256",digest:Nt(e)}}:{},slotCommitment:{algorithm:"sha256",digest:Nt(t)}};return xe(n)}function Dt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function Vn(t){if(!Dt(t)||Object.keys(t).length!==2||t.algorithm!=="sha256"||typeof t.digest!="string")return null;let n=lo(t.digest);return n!==null&&n.length===32?n:null}function mo(t){let e;try{e=new TextDecoder("utf-8",{fatal:!0}).decode(t)}catch{return null}let n;try{n=JSON.parse(e)}catch{return null}if(!Dt(n))return null;let r=Object.keys(n).sort(),o=r.length===2?["slotCommitment","type"]:r.length===3?["origin","slotCommitment","type"]:null;if(o===null||r.join(",")!==o.join(",")||n.type!==pt)return null;let i=Vn(n.slotCommitment);if(i===null)return null;let s;if("origin"in n){let a=Vn(n.origin);if(a===null)return null;s=a}return nt(qn(i,s),t)?s!==void 0?{commitment:i,originDigest:s}:{commitment:i}:null}var be=512,gu=8589934591;function bu(t,e){let n=t.toString(8).padStart(e-1,"0")+"\0";if(n.length!==e)throw new RangeError("field overflow");return ge(n)}function Qs(t,e){if(e>gu)throw new RangeError("container/1 entries are limited to 8 GiB");let n=new Uint8Array(be),r=ge(t);if(r.length>100)throw new RangeError("ustar name too long");n.set(r,0),n.set(ge("0000644\0"),100),n.set(ge("0000000\0"),108),n.set(ge("0000000\0"),116),n.set(bu(e,12),124),n.set(ge("00000000000\0"),136),n.set(ge(" "),148),n[156]=48,n.set(ge("ustar\0"),257),n.set(ge("00"),263);let o=0;for(let i of n)o+=i;return n.set(ge(o.toString(8).padStart(6,"0")+"\0 "),148),n}function fo(t){return(be-t%be)%be}function ea(t,e){return po(Qs(uo,e.length),e,new Uint8Array(fo(e.length)),Qs(ho,t.length),t,new Uint8Array(fo(t.length)),new Uint8Array(be*2))}function yu(t){let e=[],n=0;for(;n+be<=t.length;){let r=t.subarray(n,n+be);if(r.every(f=>f===0)){let f=t.subarray(n);return f.length!==be*2||!f.every(u=>u===0)?null:e}let o=r.indexOf(0,0),i=new TextDecoder().decode(r.subarray(0,o<0||o>100?100:o)),s=new TextDecoder().decode(r.subarray(124,135));if(!/^[0-7]{11}$/.test(s))return null;let a=parseInt(s,8);if(n+be+a>t.length)return null;let c=t.subarray(n+be,n+be+a);e.push({name:i,data:c,headerBytes:r}),n+=be+a+fo(a)}return null}var wu={id:"trailer/1",form:"A",byteExact:!0,build({original:t,commitment:e}){if(t===void 0)throw new TypeError("trailer/1 requires the original bytes");if(e.length!==32)throw new TypeError("commitment must be 32 bytes");return po(t,ge(co),new Uint8Array(8),e)},locate(t){if(t.length<jn)return null;let e=t.subarray(t.length-jn);return!nt(e.subarray(0,8),ge(co))||!e.subarray(8,16).every(n=>n===0)?null:{commitment:new Uint8Array(e.subarray(16,48)),originalBytes:t.subarray(0,t.length-jn)}}},xu={id:"container/1",form:"B",byteExact:!0,build({original:t,originDigest:e,commitment:n}){if(t===void 0)throw new TypeError("container/1 requires the original bytes");let r=e??_(t);return ea(t,qn(n,r))},locate(t){let e=yu(t);if(e===null||e.length!==2)return null;let[n,r]=e;if(n.name!==uo||r.name!==ho)return null;let o=mo(n.data);if(o===null||o.originDigest===void 0)return null;let i=ea(r.data,n.data);return nt(i,t)?{commitment:o.commitment,originDigest:o.originDigest,originalBytes:r.data}:null}},Eu={id:"produced/1",form:"C",byteExact:!1,build({original:t,originDigest:e,commitment:n}){if(t!==void 0)throw new TypeError("produced/1 takes no original; pass originDigest for a source reference");return qn(n,e)},locate(t){let e=mo(t);return e===null?null:e.originDigest!==void 0?{commitment:e.commitment,originDigest:e.originDigest}:{commitment:e.commitment}}},Qt=Object.freeze([wu,xu,Eu]);function Gn(t){return Qt.find(e=>e.id===t)}function Ot(t){let e=t.attribution;if(e===void 0||e.name!==na)return null;let n=typeof e.title=="string"&&e.title.length>0,r={placement:n?e.title:null,placementSource:n?"attribution":null,source:"attribution"};if(typeof e.message=="string"&&e.message.length>0){let o=Jt(e.message);o!==null&&o.length===32&&(r.originDigest=o,r.originSource="attribution")}return r}function go(t,e){if(t===null)return e;if(e===null)return t;let n={...t};return n.placement===null&&e.placement!==null&&(n.placement=e.placement,n.placementSource="manifest"),n.originDigest===void 0&&e.originDigest!==void 0&&(n.originDigest=e.originDigest,n.originSource="manifest"),n}function bo(t){let e=typeof t=="string"?(()=>{try{return JSON.parse(t)}catch{return null}})():t;if(!Dt(e)||e.type!==pt)return null;let n=e.manifest;if(!Dt(n)||n.placement!==void 0&&typeof n.placement!="string"||Vn(n.artifact)===null||n.origin!==void 0&&Vn(n.origin)===null||n.fusedFile!==null&&typeof n.fusedFile!="string")return null;let o=e.proof;if(!Dt(o)||o.version!=="bitgraph/1")return null;let i={type:pt,manifest:{placement:typeof n.placement=="string"?n.placement:"",...n.origin!==void 0?{origin:n.origin}:{},artifact:n.artifact,fusedFile:n.fusedFile},proof:o};if(e.fusePayload!==void 0){if(!Dt(e.fusePayload))return null;i.fusePayload=e.fusePayload}return i}function yo(t){let e=t.manifest.placement.length>0,n={placement:e?t.manifest.placement:null,placementSource:e?"manifest":null,source:"manifest"};if(t.manifest.origin!==void 0){let r=lo(t.manifest.origin.digest);r!==null&&r.length===32&&(n.originDigest=r,n.originSource="manifest")}return n}w();function Bu(t){let e=t.commit;if(typeof e.counter!="string"||typeof e.slotCounter!="string"||typeof e.epochId!="string")return null;let n;try{n=(BigInt(e.counter)-BigInt(e.slotCounter)).toString()}catch{return null}return{slotCounter:e.slotCounter,commitCounter:e.counter,epochId:e.epochId,chainId:typeof e.chainId=="string"?e.chainId:null,positions:n}}function wo(t,e,n){if(e===null)return[];let r=[];return t==="FUSED_FROM_ORIGIN"?r.push(`The supplied original rebuilds the committed fused artifact byte for byte, so these exact original bytes existed no later than commit position ${e.commitCounter}.`):t==="FUSED_DIRECT"&&n&&r.push("The fused bytes carry an origin digest that matches the signed marker; the original itself was not supplied and was not checked."),(t==="FUSED_DIRECT"||t==="FUSED_FROM_ORIGIN")&&r.push(`The exact fused bytes could not feasibly have been finalized before their signed slot allocation at position ${e.slotCounter}, and were committed no later than position ${e.commitCounter}.`),t==="RECORDED"&&r.push(`These exact bytes existed no later than commit position ${e.commitCounter}.`),r}async function xo(t){let{proof:e,bytes:n}=t,r=t.frame===void 0||t.frame===null?null:bo(t.frame)??null,o=_(n),i=tt(o),s=e?.artifact?.digestB64??"",a=(y,b,I)=>({category:y,proof:b.proof??{valid:!0},marker:b.marker??null,placement:b.placement??null,fileDigestB64:i,artifactDigestB64:s,originDigestB64:b.originDigestB64??null,slotCommitmentB64:b.slotCommitmentB64??null,span:b.span??null,policy:b.policy??{spanExceeded:!1,maxPositions:null},statements:b.statements??[],reason:I}),c=await lt(t.trustAnchors!==void 0?{proof:e,trustAnchors:t.trustAnchors}:{proof:e});if(!c.valid){let y=c.reason??"proof failed verification";return a("INVALID_UNDERLYING_PROOF",{proof:{valid:!1,reason:y}},y)}let f=go(Ot(e),r!==null?yo(r):null),u=f?.originDigest,d=u!==void 0?tt(u):null,h=Bu(e),l=t.maxPositions===void 0?null:BigInt(t.maxPositions),m={spanExceeded:l!==null&&h!==null&&BigInt(h.positions)>l,maxPositions:l===null?null:l.toString()},p={proof:{valid:!0},marker:f,originDigestB64:d,span:h,policy:m};if(i===s){if(f===null)return a("RECORDED",{...p,statements:wo("RECORDED",h,!1)},null);let y=e.slotAllocation;if(y===void 0)return a("INVALID_SLOT_COMMITMENT",p,"the proof carries no slot record, so no commitment can be recomputed");let b;try{b=zn(y)}catch(H){return a("INVALID_SLOT_COMMITMENT",p,`commitment could not be recomputed: ${H instanceof Error?H.message:String(H)}`)}let I=tt(b),v=f.placement===null?void 0:Gn(f.placement),M=v===void 0?null:v.locate(n);if(f.placement===null){for(let H of Qt){let U=H.locate(n);if(U!==null){v=H,M=U;break}}if(v===void 0)return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:I},"no registered placement finds a commitment in the fused bytes")}else if(v===void 0)return a("UNDETERMINED_PLACEMENT",{...p,slotCommitmentB64:I},`placement "${f.placement}" is not registered; the commitment cannot be located`);if(M===null)return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:I,placement:v.id},`no ${v.id} commitment found in the fused bytes`);if(!nt(M.commitment,b))return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:I,placement:v.id},"the commitment in the fused bytes does not match the proof's slot record");let z=!1;if(u!==void 0){let H=M.originDigest??(M.originalBytes!==void 0?_(M.originalBytes):void 0);if(H!==void 0){if(!nt(H,u))return a("INVALID_ORIGIN_ATTRIBUTION",{...p,slotCommitmentB64:I,placement:v.id},f.originSource==="attribution"?"the origin digest in the signed attribution does not match the origin inside the fused bytes":"the origin digest in the manifest does not match the origin inside the fused bytes");z=!0}}return a("FUSED_DIRECT",{...p,slotCommitmentB64:I,placement:v.id,statements:wo("FUSED_DIRECT",h,z)},null)}if(u!==void 0&&nt(o,u)){let y=e.slotAllocation;if(y===void 0)return a("INVALID_SLOT_COMMITMENT",p,"the proof carries no slot record, so the fused bytes cannot be rebuilt");let b;try{b=zn(y)}catch(H){return a("INVALID_SLOT_COMMITMENT",p,`commitment could not be recomputed: ${H instanceof Error?H.message:String(H)}`)}let I=tt(b),v=f!==null&&f.placement!==null?Gn(f.placement):void 0;if(f!==null&&f.placement!==null&&v===void 0)return a("UNDETERMINED_PLACEMENT",{...p,slotCommitmentB64:I},`placement "${f.placement}" is not registered; the fused bytes cannot be rebuilt`);let M=v!==void 0?[v]:Qt.filter(H=>H.byteExact),z=e.artifact.digestB64;for(let H of M){if(!H.byteExact)continue;let U;try{U=H.build({original:n,originDigest:u,commitment:b})}catch{continue}if(tt(_(U))===z)return a("FUSED_FROM_ORIGIN",{...p,slotCommitmentB64:I,placement:H.id,statements:wo("FUSED_FROM_ORIGIN",h,!0)},null)}return a("RECONSTRUCTION_MISMATCH",{...p,slotCommitmentB64:I,placement:v?.id??null},v!==void 0?`rebuilding ${v.id} from this file and the proof's slot record does not reproduce the committed artifact digest`:"no registered byte-exact placement rebuilds the committed artifact digest from this file")}return a("NO_MATCH",p,"this file matches neither the committed artifact digest nor the origin digest; the proof proves nothing about it")}w();async function*aa(t,e){let n=new Bo(t,e?.maxTotalBytes),r=e?.maxEntryCount??Number.POSITIVE_INFINITY,o=e?.maxMetadataEntryBytes??Number.POSITIVE_INFINITY,i=null,s=null,a=null,c=0,f=(u,d)=>{if(u>o)throw new Error(`tar: ${d} metadata entry of ${u} bytes exceeds the ${o}-byte cap`)};for(;;){let u=await n.readExact(512);if(u===null||Iu(u))return;if(++c>r)throw new Error(`tar: archive exceeds the maximum of ${r} entries`);let d=Au(u),h=d.typeflag;if(h==="x"||h==="g"){f(d.size,"PAX");let v=await sa(n,d.size);await n.skip(Wn(d.size));let M=Hu(v);h==="x"?i=M:s=Su(s,M);continue}if(h==="L"){f(d.size,"GNU long-name");let v=await sa(n,d.size);await n.skip(Wn(d.size)),a=mt(Tu(v));continue}if(h==="K"){await n.skip(d.size+Wn(d.size));continue}let l=d.name;s!==null&&s.has("path")&&(l=s.get("path")),a!==null&&(l=a),i!==null&&i.has("path")&&(l=i.get("path"));let m=d.size,p=i?.get("size")??s?.get("size");if(p!==void 0){let v=Number(p);if(!Number.isSafeInteger(v)||v<0)throw new Error("tar: invalid PAX size value");m=v}i=null,a=null;let y=h==="0"||h==="\0",b={remaining:m},I=vu(n,b);yield{path:l,size:m,kind:y?"file":"other",typeflag:h,body:I},b.remaining>0&&(await n.skip(b.remaining),b.remaining=0),await n.skip(Wn(m))}}async function*vu(t,e){for(;e.remaining>0;){let n=await t.readSome(e.remaining);if(n===null)throw new Error("tar: truncated archive (unexpected end of stream inside entry body)");e.remaining-=n.length,yield n}}async function sa(t,e){if(e===0)return new Uint8Array(0);let n=await t.readExact(e);if(n===null)throw new Error("tar: truncated archive (unexpected end of stream)");return n}function Au(t){ku(t);let e=t[156],n=e===0?"\0":String.fromCharCode(e),r=mt(Eo(t,0,100));if(mt(Eo(t,257,6))==="ustar"){let s=mt(Eo(t,345,155));s.length>0&&(r=`${s}/${r}`)}let i=ca(t.subarray(124,136));return{name:r,size:i,typeflag:n}}function Eo(t,e,n){let r=t.subarray(e,e+n),o=r.indexOf(0);return o===-1&&(o=r.length),r.subarray(0,o)}function ca(t){if(t.length>0&&(t[0]&128)!==0){let r=0n;for(let o=0;o<t.length;o++){let i=o===0?t[0]&127:t[o];r=r<<8n|BigInt(i)}if(r>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("tar: numeric field exceeds the supported range");return Number(r)}let e=mt(t).trim().replace(/\0+$/,"").trim();if(e.length===0)return 0;let n=Number.parseInt(e,8);if(!Number.isSafeInteger(n)||n<0)throw new Error(`tar: invalid octal numeric field: "${e}"`);return n}function ku(t){let e=ca(t.subarray(148,156)),n=0;for(let r=0;r<512;r++)n+=r>=148&&r<156?32:t[r];if(n!==e)throw new Error("tar: header checksum mismatch (corrupt or not a tar archive)")}function Iu(t){for(let e=0;e<t.length;e++)if(t[e]!==0)return!1;return!0}function Hu(t){let e=new Map,n=0;for(;n<t.length;){let r=n;for(;r<t.length&&t[r]!==32;)r++;if(r>=t.length)throw new Error("tar: malformed PAX record (no length delimiter)");let o=Number(mt(t.subarray(n,r)));if(!Number.isInteger(o)||o<=0||n+o>t.length)throw new Error("tar: malformed PAX record (bad length)");let i=t.subarray(r+1,n+o);if(i.length===0||i[i.length-1]!==10)throw new Error("tar: malformed PAX record (missing newline)");let s=mt(i.subarray(0,i.length-1)),a=s.indexOf("=");if(a===-1)throw new Error("tar: malformed PAX record (missing '=')");e.set(s.slice(0,a),s.slice(a+1)),n+=o}return e}function Su(t,e){let n=new Map(t??[]);for(let[r,o]of e)n.set(r,o);return n}function mt(t){return new TextDecoder("utf-8").decode(t)}function Tu(t){let e=t.length;for(;e>0&&t[e-1]===0;)e--;return t.subarray(0,e)}var Bo=class{iter;chunks=[];head=0;available=0;ended=!1;totalPulled=0;maxTotalBytes;constructor(e,n){this.iter=e[Symbol.asyncIterator](),this.maxTotalBytes=n??Number.POSITIVE_INFINITY}async fill(){if(this.ended)return!1;let e=await this.iter.next();if(e.done===!0)return this.ended=!0,!1;let n=e.value;if(n.length>0){if(this.totalPulled+=n.length,this.totalPulled>this.maxTotalBytes)throw new Error(`tar: archive exceeds the maximum decompressed size of ${this.maxTotalBytes} bytes`);this.chunks.push(n),this.available+=n.length}return!0}async readExact(e){for(;this.available<e;)if(!await this.fill()){if(this.available===0)return null;throw new Error("tar: truncated archive (unexpected end of stream)")}return this.take(e)}async readSome(e){for(;this.available===0;)if(!await this.fill())return null;let n=this.chunks[0],r=Math.min(e,n.length-this.head),o=n.subarray(this.head,this.head+r);return this.advance(r,n),o}async skip(e){let n=e;for(;n>0;){let r=await this.readSome(n);if(r===null)throw new Error("tar: truncated archive (unexpected end of stream)");n-=r.length}}take(e){let n=new Uint8Array(e),r=0;for(;r<e;){let o=this.chunks[0],i=Math.min(e-r,o.length-this.head);n.set(o.subarray(this.head,this.head+i),r),r+=i,this.advance(i,o)}return n}advance(e,n){this.head+=e,this.available-=e,this.head===n.length&&(this.chunks.shift(),this.head=0)}};function Wn(t){return(512-t%512)%512}w();var Yp=new Uint8Array([0]);function fa(t){let e=Array.from(t,r=>({pathBytes:Cu(r.path),entryDigest:r.entryDigest}));e.sort((r,o)=>Ru(r.pathBytes,o.pathBytes));let n=_.create();for(let r of e)n.update(r.entryDigest);return B.Buffer.from(n.digest()).toString("base64")}function Cu(t){if(t.includes("\0"))throw new TypeError("bitgraph-audit: bundle entry paths must not contain NUL bytes");return new TextEncoder().encode(t)}function Ru(t,e){let n=Math.min(t.length,e.length);for(let r=0;r<n;r++){let o=t[r]-e[r];if(o!==0)return o}return t.length-e.length}var ua=8*1024*1024,pa={maxTotalBytes:2*1024*1024*1024,maxEntryCount:1e6,maxMetadataEntryBytes:8*1024*1024},da=new Uint8Array([0]),ha="manifest.json",vo="bitgraph-bundle/1",$u="bitgraph-anchor-witness/1";var ma=new WeakMap;async function Ao(t,e){let n=[],r=0,o=0,i=[],s=new Map,a=Array.from(t).sort((f,u)=>f.path<u.path?-1:f.path>u.path?1:0);for(let f of a){o++;let u=ya(f.path);if(u.unsafe){r++,n.push({code:"unsafe-path",path:f.path,message:`entry skipped: ${u.reason}`});continue}let d=await Ou(u.path,void 0,void 0,ga(f.open()));i.push(Lu(u.path,d)),s.set(u.path,f)}let c=Du({bundlePath:e?.label??"",container:"memory",scanned:i,strippedRootPrefix:void 0,findings:n,entriesScanned:o,skippedUnsafePaths:r});return ma.set(c,s),c}async function*ga(t){let e=await Promise.resolve(t);if(e instanceof Uint8Array){yield e;return}for await(let n of t)yield n}async function Pu(t){let e=[],n=0;for await(let r of ga(t.open()))e.push(r),n+=r.length;return Io(e,n)}function Du(t){let{bundlePath:e,container:n,scanned:r,strippedRootPrefix:o,findings:i,entriesScanned:s,skippedUnsafePaths:a}=t,c=new Map;for(let H of r){let U=H.rawPath,F=H.entryDigestFull;o!==void 0&&(U=H.rawPath.slice(o.length+1),F=H.entryDigestStripped),c.has(U)&&i.push({code:"duplicate-path",path:U,message:"multiple archive entries normalized to the same path; the last entry wins"}),c.set(U,{path:U,sha256Hex:H.sha256Hex,byteLength:H.byteLength,entryDigest:F,...H.json!==void 0?{json:H.json}:{}})}let f=Array.from(c.values()),u=fa(f.filter(H=>H.path!==ha).map(H=>({path:H.path,entryDigest:H.entryDigest}))),d=[],h=new Map,l=[],m=[],p=new Map,y,b=0,I=0,v=0;for(let H of f){if(H.path===ha){y=ju(H,u,i);continue}let F=Fu(H.json)??H.json;if(F!==void 0&&wa(F)){let G=F.version;if(G==="bitgraph/1"){b++;let q=Uu(H,F,h,d,i);q==="exact-duplicate"&&I++,q==="semantic-duplicate"&&v++;continue}l.push({code:"unsupported-version",path:H.path,version:G,fileSha256Hex:H.sha256Hex}),i.push({code:"unsupported-version",path:H.path,message:`proof-shaped file rejected: version "${G}" is not "bitgraph/1"`,details:{version:G}}),la(H,p);continue}if(F!==void 0&&F.version===$u){m.push({path:H.path,fileSha256Hex:H.sha256Hex,witness:F});continue}la(H,p)}for(let H of d){let U=Ku(H.proof.artifact);if(U===null)continue;let F=p.get(U);F!==void 0&&F.matchedProofHashes.push(H.proofHash)}let M=Array.from(p.values()),z={observed:d.length,proofFiles:b,exactDuplicates:I,semanticDuplicates:v,unsupportedVersion:l.length,artifacts:M.length,witnesses:m.length,skippedUnsafePaths:a};return{bundlePath:e,container:n,...o!==void 0?{strippedRootPrefix:o}:{},entriesScanned:s,proofs:d,unsupportedVersions:l,artifacts:M,witnesses:m,...y!==void 0?{manifest:y}:{},computedContentsHashB64:u,findings:i,counts:z}}async function*en(t){yield*ba(t,t.artifacts.filter(e=>e.matchedProofHashes.length>0))}async function*ko(t,e){let n=new Set(e);n.size!==0&&(yield*ba(t,t.artifacts.filter(r=>n.has(r.sha256Hex))))}async function*ba(t,e){if(e.length===0)return;if(t.container==="memory"){let s=ma.get(t);if(s===void 0)return;for(let a of e)for(let c of a.paths){let f=s.get(c);if(f===void 0)continue;let u;try{u=await Pu(f)}catch{continue}if(Zn(_(u))===a.sha256Hex){yield{sha256Hex:a.sha256Hex,path:c,bytes:u};break}}return}if(t.container==="directory"){for(let s of e)for(let a of s.paths){let c;try{c=new Uint8Array(await ns(rs(t.bundlePath,...a.split("/"))))}catch{continue}if(Zn(_(c))===s.sha256Hex){yield{sha256Hex:s.sha256Hex,path:a,bytes:c};break}}return}let n=new Map;for(let s of e)for(let a of s.paths)n.set(a,s);let r=new Set,{stream:o,close:i}=Nu(t.bundlePath,t.container);try{for await(let s of aa(o,pa)){if(r.size===e.length)break;if(s.kind!=="file")continue;let a=ya(s.path);if(a.unsafe)continue;let c=a.path;if(t.strippedRootPrefix!==void 0){if(!c.startsWith(`${t.strippedRootPrefix}/`))continue;c=c.slice(t.strippedRootPrefix.length+1)}let f=n.get(c);if(f===void 0||r.has(f.sha256Hex))continue;let u=[],d=0;for await(let l of s.body)u.push(l.slice()),d+=l.length;let h=Io(u,d);Zn(_(h))===f.sha256Hex&&(r.add(f.sha256Hex),yield{sha256Hex:f.sha256Hex,path:c,bytes:h})}}finally{i()}}function Nu(t,e){let n=ts(t);if(e==="tar-gz"){let r=os();return n.pipe(r),n.on("error",o=>r.destroy(o)),{stream:r,close:()=>{r.destroy(),n.destroy()}}}return{stream:n,close:()=>n.destroy()}}async function Ou(t,e,n,r){let o=new TextEncoder,i=_.create(),s=_.create();s.update(o.encode(t)),s.update(da);let a=e===void 0?void 0:_.create();a!==void 0&&(a.update(o.encode(e)),a.update(da));let c=n===void 0||n<=ua,f=[],u=0;for await(let d of r)i.update(d),s.update(d),a?.update(d),u+=d.length,c&&(u>ua?(f.length=0,c=!1):f.push(d.slice()));return{sha256Hex:Zn(i.digest()),byteLength:u,entryDigestFull:s.digest(),...a!==void 0?{entryDigestStripped:a.digest()}:{},...c?{buffered:Io(f,u)}:{}}}function Lu(t,e){let n=e.buffered===void 0?void 0:Mu(e.buffered);return{rawPath:t,sha256Hex:e.sha256Hex,byteLength:e.byteLength,entryDigestFull:e.entryDigestFull,...e.entryDigestStripped!==void 0?{entryDigestStripped:e.entryDigestStripped}:{},...n!==void 0?{json:n}:{}}}function Mu(t){let e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.subarray(3));let n;try{n=new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return}let r;try{r=JSON.parse(n)}catch{return}if(!(r===null||typeof r!="object"||Array.isArray(r)))return r}function ya(t){if(t.includes("\0"))return{path:t,unsafe:!0,reason:"path contains a NUL byte"};let e=t.startsWith("/"),n=t.split("/").filter(o=>o!==""&&o!=="."),r=n.join("/");return e?{path:r,unsafe:!0,reason:"absolute path"}:n.some(o=>o==="..")?{path:r,unsafe:!0,reason:"path escapes the bundle root"}:r===""?{path:r,unsafe:!0,reason:"empty path"}:{path:r,unsafe:!1}}function oe(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Fu(t){if(!oe(t)||t.type!=="bitgraph-fuse/1")return;let e=t.proof;return wa(e)?e:void 0}function wa(t){return oe(t)?typeof t.version=="string"&&oe(t.artifact)&&oe(t.commit)&&oe(t.signer):!1}function Uu(t,e,n,r,o){let i=Kn(e),s={path:t.path,fileSha256Hex:t.sha256Hex,byteLength:t.byteLength},a=_u(e,i);a==="mismatch"&&o.push({code:"proofhash-mismatch",path:t.path,message:"embedded proofHash does not match the computed canonical proof hash",details:{embedded:e.proofHash,computed:i}});let c=n.get(i);if(c!==void 0){let y=c.sources.some(b=>b.fileSha256Hex===s.fileSha256Hex);return c.sources.push(s),a==="mismatch"&&(c.embeddedProofHash="mismatch"),o.push({code:y?"exact-duplicate":"semantic-duplicate",path:t.path,message:y?"byte-identical copy of an already observed proof":"different byte encoding of an already observed proof (same canonical identity)",details:{proofHash:i,firstObservedAt:c.sources[0].path}}),y?"exact-duplicate":"semantic-duplicate"}let f=oe(e.commit)?e.commit:{},u=oe(e.signer)?e.signer:{},d=oe(e.environment)?e.environment:{},h=he(f.counter),l=he(f.epochId),m=he(f.chainId),p={proofHash:i,chainHash:io(e),proof:e,sources:[s],version:"bitgraph/1",...h!==void 0?{counter:h}:{},...he(f.slotCounter)!==void 0?{slotCounter:he(f.slotCounter)}:{},...he(f.prevB64)!==void 0?{prevB64:he(f.prevB64)}:{},...l!==void 0?{epochId:l}:{},chainId:m!==void 0&&m.length>0?m:"global",...he(u.publicKeyB64)!==void 0?{publicKeyB64:he(u.publicKeyB64)}:{},...he(d.measurement)!==void 0?{measurement:he(d.measurement)}:{},...he(d.enforcement)!==void 0?{enforcement:he(d.enforcement)}:{},hasSlotAllocation:oe(e.slotAllocation),hasAttestation:oe(d.attestation),hasAgency:oe(e.agency),hasEpochLink:oe(f.epochLink),embeddedProofHash:a,chainless:h===void 0&&l===void 0};return n.set(i,p),r.push(p),"new"}function _u(t,e){let n=t.proofHash;return n===void 0?"absent":typeof n=="string"&&n===e?"match":"mismatch"}function he(t){return typeof t=="string"?t:void 0}function la(t,e){let n=e.get(t.sha256Hex);if(n!==void 0){n.paths.push(t.path);return}e.set(t.sha256Hex,{sha256Hex:t.sha256Hex,sha256B64:B.Buffer.from(t.sha256Hex,"hex").toString("base64"),byteLength:t.byteLength,paths:[t.path],matchedProofHashes:[]})}function Ku(t){if(!oe(t))return null;let e=t.digestB64;if(typeof e!="string"||e.length===0)return null;let n=B.Buffer.from(e,"base64");return n.toString("base64")!==e||n.length!==32?null:n.toString("hex")}function ju(t,e,n){if(t.json===void 0)return n.push({code:"manifest-unparseable",path:t.path,message:"root manifest.json did not parse as a single JSON object; proceeding as if no manifest were present"}),{path:t.path,parsed:!1,recognized:!1,problems:[]};let r=t.json,o=r.version;if(o!==vo)return n.push({code:"manifest-unrecognized-version",path:t.path,message:`manifest version ${JSON.stringify(o)} is not "${vo}"; the manifest was not interpreted`,...typeof o=="string"?{details:{version:o}}:{}}),{path:t.path,parsed:!0,...typeof o=="string"?{version:o}:{},recognized:!1,problems:[]};let i=Vu(r);for(let c of i)n.push({code:"manifest-field-invalid",path:t.path,message:c});let s={path:t.path,parsed:!0,version:vo,recognized:!0,manifest:r,problems:i},a=r.contentsHashB64;if(typeof a=="string"&&a.length>0){let c=a===e;s.contentsHash={declaredB64:a,computedB64:e,match:c},c||n.push({code:"manifest-contents-hash-mismatch",path:t.path,message:"manifest contentsHashB64 does not match the computed contents hash; the bundle held is not byte-for-byte the bundle the manifest describes. Advisory: this does not fail any proof.",details:{declared:a,computed:e}})}return s}function Vu(t){let e=[],n=r=>Array.isArray(r)&&r.every(o=>typeof o=="string");if(t.epochIds!==void 0&&!n(t.epochIds)&&e.push("manifest.epochIds must be an array of strings when present"),t.chainIds!==void 0&&!n(t.chainIds)&&e.push("manifest.chainIds must be an array of strings when present"),t.proofCount!==void 0&&(typeof t.proofCount!="number"||!Number.isInteger(t.proofCount)||t.proofCount<0)&&e.push("manifest.proofCount must be a non-negative integer when present"),t.counterRanges!==void 0&&(Array.isArray(t.counterRanges)&&t.counterRanges.every(o=>oe(o)&&typeof o.epochId=="string"&&typeof o.chainId=="string"&&typeof o.min=="string"&&typeof o.max=="string")||e.push("manifest.counterRanges must be an array of { epochId, chainId, min, max } string fields when present")),t.generatedAt!==void 0&&typeof t.generatedAt!="string"&&e.push("manifest.generatedAt must be a string when present"),t.contentsHashB64!==void 0){let r=t.contentsHashB64,o=typeof r=="string"&&r.length>0;if(o){let i=B.Buffer.from(r,"base64");o=i.toString("base64")===r&&i.length===32}o||e.push("manifest.contentsHashB64 must be standard base64 of 32 bytes when present")}return t.artifactsIncluded!==void 0&&typeof t.artifactsIncluded!="boolean"&&e.push("manifest.artifactsIncluded must be a boolean when present"),t.openEpochs!==void 0&&(Array.isArray(t.openEpochs)&&t.openEpochs.every(o=>oe(o)&&typeof o.epochId=="string"&&typeof o.counterAtSnapshot=="string")||e.push("manifest.openEpochs must be an array of { epochId, counterAtSnapshot } string fields when present")),e}function Zn(t){return B.Buffer.from(t).toString("hex")}function Io(t,e){let n=new Uint8Array(e),r=0;for(let o of t)n.set(o,r),r+=o.length;return n}w();async function Ho(t,e){_e();let n=e?.trustAnchors,r=new Map(t.proofs.map(f=>[f.proofHash,f])),o=new Map;for(let f of t.artifacts){if(f.matchedProofHashes.length===0)continue;let u=f.matchedProofHashes.map(d=>r.get(d)).filter(d=>d!==void 0);o.set(f.sha256Hex,u)}for await(let f of en(t)){let u=o.get(f.sha256Hex)??[];for(let d of u){if(d.verification!==void 0)continue;let h=await oo({proof:d.proof,bytes:f.bytes,...n!==void 0?{trustAnchors:n}:{}}),l={tier:"full",status:h.valid?"verified":"failed",...h.reason!==void 0?{reason:h.reason}:{},artifactPath:f.path};d.verification=l}}for(let f of t.proofs){if(f.verification!==void 0)continue;let u=await lt({proof:f.proof,...n!==void 0?{trustAnchors:n}:{}}),d={tier:"integrity",status:u.valid?"artifact-unavailable":"failed",...u.reason!==void 0?{reason:u.reason}:{}};f.verification=d}let i=0,s=0,a=0,c=0;for(let f of t.proofs){let u=f.verification?.status;u==="verified"?i++:u==="failed"?s++:u==="artifact-unavailable"&&a++,f.chainless&&c++}return{total:t.proofs.length,verified:i,failed:s,artifactUnavailable:a,chainless:c}}w();w();var xa=new WeakMap;async function Ke(t){let e=t.verification?.status;if(e==="verified"||e==="artifact-unavailable")return!0;let n=xa.get(t);if(n!==void 0)return n;_e();let r=!1;try{r=(await lt({proof:t.proof})).valid}catch{r=!1}return _e(),xa.set(t,r),r}function Y(t){if(!(t===void 0||t.length===0||!/^[0-9]+$/.test(t)))return BigInt(t)}function Re(t,e){let n=Y(t.counter),r=Y(e.counter);return n!==void 0&&r!==void 0&&n!==r?n<r?-1:1:n!==void 0&&r===void 0?-1:n===void 0&&r!==void 0?1:t.proofHash<e.proofHash?-1:t.proofHash>e.proofHash?1:0}function ue(t,e,n){let r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}async function To(t){let e=[],n=[],r=new Map;for(let f of t.proofs){if(f.chainless){e.push(f.proofHash);continue}if(f.publicKeyB64===void 0){n.push(f.proofHash);continue}let u={publicKeyB64:f.publicKeyB64,...f.epochId!==void 0?{epochId:f.epochId}:{},chainId:f.chainId},d=JSON.stringify([u.publicKeyB64,u.epochId??null,u.chainId]),h=r.get(d);h===void 0?r.set(d,{key:u,members:[f]}):h.members.push(f)}let o=[...r.values()].sort((f,u)=>zu(f.key,u.key)),i=[],s=new Set,a=new Map;for(let f of o){let u=qu(f.key,f.members,s);i.push(u);for(let d of u.memberProofHashes)a.set(d,f.key)}let c=await Zu(t,i,s,a);return{partitions:i,unchainedProofHashes:e,unpartitionedProofHashes:n,epochRelationships:c}}function zu(t,e){if(t.chainId!==e.chainId)return t.chainId<e.chainId?-1:1;let n=t.epochId??"",r=e.epochId??"";return n!==r?n<r?-1:1:t.publicKeyB64!==e.publicKeyB64?t.publicKeyB64<e.publicKeyB64?-1:1:0}function qu(t,e,n){let r=new Map(e.map(h=>[h.chainHash,h])),o=new Map,i=new Set,s=new Map;for(let h of e)s.set(h.proofHash,h.proofHash);let a=h=>{let l=h;for(;s.get(l)!==l;)l=s.get(l);let m=h;for(;m!==l;){let p=s.get(m);s.set(m,l),m=p}return l},c=(h,l)=>{let m=a(h),p=a(l);m!==p&&s.set(m,p)};for(let h of e){if(h.prevB64===void 0)continue;let l=r.get(h.prevB64);l===void 0||l.proofHash===h.proofHash||(i.add(h.proofHash),ue(o,l.proofHash,h),n.add(l.proofHash),c(l.proofHash,h.proofHash))}let f=new Map;for(let h of e)ue(f,a(h.proofHash),h);let u=[];for(let h of f.values())u.push(Gu(h,o,i));u.sort(Wu);let d=[...e].sort(Re).map(h=>h.proofHash);return{key:t,memberProofHashes:d,components:u}}function Gu(t,e,n){let r=[...t].sort(Re),o=r.filter(h=>h.prevB64===void 0),i=r.filter(h=>h.prevB64!==void 0&&!n.has(h.proofHash)),s=r.filter(h=>(e.get(h.proofHash)??[]).length===0),a=new Set,c=[],f=h=>{let l=[h];for(;l.length>0;){let m=l.pop();if(a.has(m))continue;a.add(m),c.push(m);let p=[...e.get(m)??[]].sort(Re);for(let y=p.length-1;y>=0;y--)l.push(p[y].proofHash)}};for(let h of[...o,...i])f(h.proofHash);for(let h of r)a.has(h.proofHash)||f(h.proofHash);let u,d;for(let h of t)for(let l of[h.counter,h.slotCounter]){let m=Y(l);m!==void 0&&((u===void 0||m<u)&&(u=m),(d===void 0||m>d)&&(d=m))}return{memberProofHashes:c,genesisProofHashes:o.map(h=>h.proofHash),brokenLinkProofHashes:i.map(h=>h.proofHash),terminalProofHashes:s.map(h=>h.proofHash),hasCounterEvidence:u!==void 0,...u!==void 0&&d!==void 0?{positionRange:{min:String(u),max:String(d)}}:{}}}function Wu(t,e){let n=t.positionRange?.min,r=e.positionRange?.min;if(n!==void 0&&r!==void 0&&n!==r)return BigInt(n)<BigInt(r)?-1:1;if(n!==void 0&&r===void 0)return-1;if(n===void 0&&r!==void 0)return 1;let o=t.memberProofHashes[0]??"",i=e.memberProofHashes[0]??"";return o<i?-1:o>i?1:0}async function Zu(t,e,n,r){let o=new Map;for(let h of e){let l=h.key.epochId;if(l===void 0)continue;let m=o.get(l);m===void 0&&(m={chainIds:new Set,publicKeys:new Set,proofCount:0},o.set(l,m)),m.chainIds.add(h.key.chainId),m.publicKeys.add(h.key.publicKeyB64),m.proofCount+=h.memberProofHashes.length}let i=new Map(t.proofs.map(h=>[h.chainHash,h])),s=[];for(let h of t.proofs){if(!h.hasEpochLink)continue;let l=Yu(h);l!==null&&s.push(await Xu(l,h,i,o,n,r))}let a=Qu(s),c=new Set,f=new Map,u=new Map;for(let h of s)h.hardEdge&&(c.add(h.fromEpochId),c.add(h.toEpochId),So(f,h.toEpochId,h.fromEpochId),So(u,h.fromEpochId,h.toEpochId));return{epochs:[...o.entries()].sort(([h],[l])=>h<l?-1:h>l?1:0).map(([h,l])=>({epochId:h,chainIds:[...l.chainIds].sort(),publicKeysB64:[...l.publicKeys].sort(),proofCount:l.proofCount,ordering:c.has(h)?"linked":"observed-but-unordered",linkedPredecessorEpochIds:[...f.get(h)??[]].sort(),linkedSuccessorEpochIds:[...u.get(h)??[]].sort()})),edges:s,orderedPairs:a}}function Yu(t){let e=t.proof.commit;if(e===null||typeof e!="object")return null;let n=e.epochLink;if(n===null||typeof n!="object"||Array.isArray(n))return null;let r=n,o=["prevEpochId","prevPublicKeyB64","prevCounter","prevProofHashB64","toEpochId","toPublicKeyB64"],i={};for(let s of o){let a=r[s];if(typeof a!="string"||a.length===0)return null;i[s]=a}return i}async function Xu(t,e,n,r,o,i){let s=await Ke(e),a=n.get(t.prevProofHashB64);if(a===void 0){let h=r.has(t.prevEpochId);return{fromEpochId:t.prevEpochId,toEpochId:t.toEpochId,viaProofHash:e.proofHash,link:t,resolution:h?"terminal-missing":"dangling",viaProofValid:s,hardEdge:!1}}let c=[];a.epochId!==t.prevEpochId&&c.push(`the referenced proof's epochId (${a.epochId??"absent"}) does not match epochLink.prevEpochId (${t.prevEpochId})`),a.publicKeyB64!==t.prevPublicKeyB64&&c.push("the referenced proof's signer key does not match epochLink.prevPublicKeyB64"),Ju(a.counter,t.prevCounter)||c.push(`the referenced proof's counter (${a.counter??"absent"}) does not match epochLink.prevCounter (${t.prevCounter})`);let f=await Ke(a),u=c.length===0,d=i.has(a.proofHash);return{fromEpochId:t.prevEpochId,toEpochId:t.toEpochId,viaProofHash:e.proofHash,link:t,resolution:"matched",predecessorProofHash:a.proofHash,metadataConsistent:u,...u?{}:{inconsistencies:c},...d?{referencedProofIsTerminal:!o.has(a.proofHash)}:{},viaProofValid:s,predecessorValid:f,hardEdge:u&&s&&f}}function Ju(t,e){if(t===void 0)return!1;if(t===e)return!0;let n=Y(t),r=Y(e);return n!==void 0&&r!==void 0&&n===r}function Qu(t){let e=new Map,n=new Set;for(let i of t)i.hardEdge&&(So(e,i.fromEpochId,i.toEpochId),n.add(i.fromEpochId),n.add(i.toEpochId));let r=new Set;for(let i of n){let s=new Set,a=[...e.get(i)??[]];for(;a.length>0;){let c=a.pop();if(!s.has(c)){s.add(c);for(let f of e.get(c)??[])a.push(f)}}for(let c of s)c!==i&&r.add(`${i}\0${c}`)}let o=[];for(let i of r){let[s,a]=i.split("\0");r.has(`${a}\0${s}`)||o.push({beforeEpochId:s,afterEpochId:a})}return o.sort((i,s)=>i.beforeEpochId!==s.beforeEpochId?i.beforeEpochId<s.beforeEpochId?-1:1:i.afterEpochId<s.afterEpochId?-1:i.afterEpochId>s.afterEpochId?1:0),o}function So(t,e,n){let r=t.get(e);r===void 0?t.set(e,new Set([n])):r.add(n)}w();var ed=1e4;async function Co(t,e){let n=[],r=[],o=[],i=new Map(t.proofs.map(c=>[c.proofHash,c])),s=new Map(t.proofs.map(c=>[c.chainHash,c])),a=new Map;for(let c of e.partitions)for(let f of c.memberProofHashes)a.set(f,c.key);for(let c of e.partitions){let f=c.memberProofHashes.map(u=>i.get(u));td(c,f,n),await Ea(c,f,"counter",n,r),await Ea(c,f,"slot",n,r),await nd(c,f,n,r),await rd(c,f,s,n,r),od(c,f,s,a,n,o),await sd(c,f,n,r),ad(c,f,n)}return await cd(e.epochRelationships.edges,i,n,r),{anomalies:n,divergences:r,boundaryEntryPoints:o}}function td(t,e,n){let r=new Set;for(let d of e){let h=Y(d.counter);h!==void 0&&r.add(h);let l=Y(d.slotCounter);l!==void 0&&r.add(l)}if(r.size<2)return;let o=[...r].sort((d,h)=>d<h?-1:d>h?1:0),i=[],s=[],a=0n;for(let d=1;d<o.length;d++){let h=o[d-1]+1n,l=o[d]-1n;if(!(h>l)){i.push({start:String(h),end:String(l)}),a+=l-h+1n;for(let m=h;m<=l&&s.length<ed;m++)s.push(String(m))}}if(i.length===0)return;let c={count:String(a),ranges:i,positions:s,truncated:a>BigInt(s.length)},f=String(o[0]),u=String(o[o.length-1]);n.push({code:"unexplained-counter-positions",partition:t.key,proofHashes:[],message:`${a} counter position${a===1n?"":"s"} within the observed range [${f}, ${u}] of this partition ${a===1n?"is":"are"} neither a commit position nor a referenced slot position in the supplied bundle. Such ${a===1n?"a position":"positions"} may mean a proof is absent from the bundle, or a slot that was allocated but never committed (a routine, benign occurrence); this offline audit cannot distinguish the two. It does not, by itself, establish that the authority failed to create or withheld any proof.`,details:c})}async function Ea(t,e,n,r,o){let i=new Map;for(let s of e){let a=n==="counter"?s.counter:s.slotCounter;if(a===void 0)continue;let c=Y(a);ue(i,c!==void 0?String(c):`raw:${a}`,s)}for(let[s,a]of Ro(i)){if(a.length<2)continue;let{parties:c,context:f}=await Yn(a);if(c.length<2)continue;let u=s.startsWith("raw:")?s.slice(4):s,d=n==="counter"?"counter-collision":"slot-collision";r.push({code:d,partition:t.key,proofHashes:a.map(h=>h.proofHash),message:n==="counter"?`${c.length} distinct valid proofs claim commit counter ${u} in one partition. The audit does not choose between them; all parties are preserved for adjudication.`:`${c.length} distinct valid proofs reference slot counter ${u} in one partition. A slot position is consumed exactly once; all parties are preserved for adjudication.`,details:{position:u,validParties:c.map(h=>h.proofHash),invalidObserved:f.map(h=>h.proofHash)}}),o.push({kind:d,partition:t.key,contested:n==="counter"?{counter:u}:{slotCounter:u},parties:c.map($e),invalidContext:f.map($e),explanation:n==="counter"?`Two or more independently valid proof objects claim commit counter ${u} in the same signer, epoch, and chain partition. A commit counter position can be consumed only once, so at most one of these can belong to the authoritative sequence. The audit tool does not choose between them; every party and its predecessor relationship is preserved for adjudication.`:`Two or more independently valid proof objects reference slot counter ${u} in the same signer, epoch, and chain partition. A slot position is allocated once and consumed by one commit, so at most one of these can belong to the authoritative sequence. The audit tool does not choose between them.`})}}async function nd(t,e,n,r){let o=new Map,i=new Map;for(let a of e){let c=Y(a.counter);c!==void 0&&ue(o,String(c),a);let f=Y(a.slotCounter);f!==void 0&&ue(i,String(f),a)}let s=[...o.keys()].filter(a=>i.has(a)).sort((a,c)=>BigInt(a)<BigInt(c)?-1:BigInt(a)>BigInt(c)?1:0);for(let a of s){let c=o.get(a),f=i.get(a),u=[];for(let b of c)await Ke(b)&&u.push(b);let d=[];for(let b of f)await Ke(b)&&d.push(b);if(!u.some(b=>d.some(I=>I.proofHash!==b.proofHash)))continue;let l=new Map;for(let b of[...u,...d])l.set(b.proofHash,b);let m=[...l.values()],p=new Map;for(let b of[...c,...f])p.set(b.proofHash,b);let y=[...p.values()].filter(b=>!l.has(b.proofHash));n.push({code:"cross-kind-position-reuse",partition:t.key,proofHashes:[...p.keys()],message:`Counter position ${a} is committed by one proof and reserved as a slot by a different proof in the same partition. A single causal position is consumed once, as a slot or as a commit, never both across distinct proofs. The audit does not choose between them; all parties are preserved for adjudication.`,details:{position:a,commitParties:u.map(b=>b.proofHash),slotParties:d.map(b=>b.proofHash),validParties:m.map(b=>b.proofHash),invalidObserved:y.map(b=>b.proofHash)}}),r.push({kind:"cross-kind-position-reuse",partition:t.key,contested:{position:a},parties:m.map($e),invalidContext:y.map($e),explanation:`Two or more independently valid proof objects allocate counter position ${a} in the same signer, epoch, and chain partition through different roles: at least one commits at it and at least one reserves it as a slot. Each position in a chain is consumed exactly once, so at most one of these allocations can belong to the authoritative sequence. This pattern only arises through enclave malfunction, replay, or compromise. The audit tool does not choose between them; every party is preserved for adjudication.`})}}async function rd(t,e,n,r,o){let i=new Map;for(let s of e)s.prevB64!==void 0&&ue(i,s.prevB64,s);for(let[s,a]of Ro(i)){if(a.length<2)continue;let{parties:c,context:f}=await Yn(a);if(c.length<2)continue;let u=n.has(s);r.push({code:"predecessor-reuse",partition:t.key,proofHashes:a.map(d=>d.proofHash),message:`${c.length} distinct valid proofs claim the same predecessor hash: a detectable fork. All branches are preserved; the audit does not choose between them.`,details:{prevB64:s,predecessorObserved:u,validParties:c.map(d=>d.proofHash),invalidObserved:f.map(d=>d.proofHash)}}),o.push({kind:"predecessor-reuse",partition:t.key,contested:{prevB64:s},parties:c.map($e),invalidContext:f.map($e),explanation:`Two or more independently valid proof objects name the same predecessor proof in their prevB64 hash link. Each proof has exactly one successor in an intact chain, so this is a fork: the history diverges into multiple branches at that predecessor${u?", which is itself observed in the bundle":", which is absent from the bundle"}. All branches are shown; the audit tool does not select one.`})}}function od(t,e,n,r,o,i){let s=new Set(e.map(c=>c.chainHash)),a;for(let c of e){let f=Y(c.counter);f!==void 0&&(a===void 0||f<a)&&(a=f)}for(let c of[...e].sort(Re)){if(c.prevB64===void 0||s.has(c.prevB64))continue;if(!id(c.prevB64)){o.push({code:"chain-break-malformed",partition:t.key,proofHashes:[c.proofHash],message:"commit.prevB64 is not standard base64 of 32 bytes, so it can never match a canonical proof hash. The predecessor link is unusable as reconstruction evidence.",details:{prevB64:c.prevB64}});continue}let f=n.get(c.prevB64);if(f!==void 0){let h=r.get(f.proofHash);o.push({code:"chain-break-cross-partition",partition:t.key,proofHashes:[c.proofHash,f.proofHash],message:"commit.prevB64 resolves to an observed proof outside this proof's own signer, epoch, and chain partition. prevB64 never bridges partitions (each epoch and chain keeps its own hash chain), so this link does not join the two.",details:{prevB64:c.prevB64,predecessorProofHash:f.proofHash,predecessorPartition:h!==void 0?{publicKeyB64:h.publicKeyB64,...h.epochId!==void 0?{epochId:h.epochId}:{},chainId:h.chainId}:"unchained-or-unpartitioned"}});continue}let u=Y(c.counter);if(u===void 0||a===void 0||u<=a){i.push({partition:t.key,proofHash:c.proofHash,prevB64:c.prevB64});continue}o.push({code:"chain-break-missing",partition:t.key,proofHashes:[c.proofHash],message:"commit.prevB64 references a predecessor proof that is absent from the supplied bundle, and a lower-positioned proof IS present, so this is an interior break (a hole), not the excerpt's starting boundary. The chain cannot be reconstructed across this link from the supplied evidence; this does not, by itself, establish that the predecessor never existed.",details:{prevB64:c.prevB64}})}}function id(t){if(t.length===0)return!1;let e=B.Buffer.from(t,"base64");return e.length===32&&e.toString("base64")===t}async function sd(t,e,n,r){let o=[...e.filter(a=>a.prevB64===void 0)].sort(Re);if(o.length<2)return;let{parties:i,context:s}=await Yn(o);n.push({code:"multiple-genesis",partition:t.key,proofHashes:o.map(a=>a.proofHash),message:`${o.length} proofs in one partition carry no prevB64 link. An epoch has exactly one first proof, so at most one of these can be the genesis of this partition's chain.`,details:{validParties:i.map(a=>a.proofHash),invalidObserved:s.map(a=>a.proofHash)}}),!(i.length<2)&&r.push({kind:"multiple-genesis",partition:t.key,contested:{...t.key.epochId!==void 0?{epochId:t.key.epochId}:{},chainId:t.key.chainId},parties:i.map($e),invalidContext:s.map($e),explanation:"Two or more independently valid proof objects in the same signer, epoch, and chain partition carry no predecessor link, each presenting itself as the first proof of the chain. An epoch has exactly one first proof, so at most one of these can be the genesis. The audit tool does not choose between them."})}function ad(t,e,n){for(let r of[...e].sort(Re)){let o=Y(r.slotCounter),i=Y(r.counter);o===void 0||i===void 0||o<i||n.push({code:"slot-order-violation",partition:t.key,proofHashes:[r.proofHash],message:"commit.slotCounter is not strictly less than commit.counter. The slot must be allocated before the commit that consumes it, so this proof's declared positions contradict the nonce-first construction order.",details:{slotCounter:r.slotCounter,counter:r.counter}})}}async function cd(t,e,n,r){for(let s of t)s.resolution==="terminal-missing"?n.push({code:"epochlink-terminal-missing",proofHashes:[s.viaProofHash],message:"commit.epochLink references a prior epoch that is observed in the bundle, but the referenced terminal proof is absent from the bundle. The lineage claim cannot be confirmed from the supplied evidence; this does not, by itself, establish that the terminal never existed.",details:{link:{...s.link}}}):s.resolution==="dangling"?n.push({code:"epochlink-dangling",proofHashes:[s.viaProofHash],message:"commit.epochLink references a prior epoch and terminal proof, neither of which is observed in the bundle. The lineage claim dangles into unobserved history; it cannot be confirmed from the supplied evidence.",details:{link:{...s.link}}}):s.metadataConsistent===!1&&n.push({code:"epochlink-mismatch",proofHashes:[s.viaProofHash,...s.predecessorProofHash!==void 0?[s.predecessorProofHash]:[]],message:"commit.epochLink's prevProofHashB64 matches an observed proof, but the link's declared epoch, signer key, or counter disagrees with that proof. The hash reference and the declared metadata cannot both be right.",details:{link:{...s.link},inconsistencies:s.inconsistencies??[]}});let o=new Map;for(let s of t)ue(o,`${s.link.prevEpochId}|${s.link.prevCounter}|${s.link.prevProofHashB64}`,s);for(let[,s]of Ro(o)){let a=new Set(s.map(h=>h.link.toEpochId));if(a.size<2)continue;let c=s.map(h=>e.get(h.viaProofHash)),{parties:f,context:u}=await Yn(c),d=s[0].link;n.push({code:"epochlink-fork",proofHashes:s.map(h=>h.viaProofHash),message:`The same predecessor terminal (epoch ${d.prevEpochId}, counter ${d.prevCounter}) is consumed by genesis proofs of ${a.size} distinct successor epochs. A predecessor may be consumed by at most one successor epoch, so this is a detectable fork at the epoch boundary. All branches are preserved.`,details:{prevEpochId:d.prevEpochId,prevCounter:d.prevCounter,prevProofHashB64:d.prevProofHashB64,successorEpochIds:[...a].sort(),validParties:f.map(h=>h.proofHash),invalidObserved:u.map(h=>h.proofHash)}}),!(f.length<2)&&r.push({kind:"epochlink-fork",contested:{prevEpochId:d.prevEpochId,prevCounter:d.prevCounter,prevProofHashB64:d.prevProofHashB64},parties:f.map($e),invalidContext:u.map($e),explanation:"Two or more independently valid epoch-genesis proofs consume the same terminal proof of a prior epoch through their epochLink. The single-successor rule allows a terminal to be consumed by exactly one successor epoch, so at most one of these lineages can be the authoritative continuation. Note that whichever party verified second in this run carries a fork-detection failure from the canonical verifier; that ordering is an artifact of verification order, not evidence of which branch is authoritative. The audit tool does not choose between them."})}let i=new Map;for(let s of t){if(s.resolution!=="matched")continue;let a=i.get(s.fromEpochId);a===void 0?i.set(s.fromEpochId,new Set([s.toEpochId])):a.add(s.toEpochId)}for(let s of fd(i)){let a=t.filter(c=>c.resolution==="matched"&&s.includes(c.fromEpochId)&&s.includes(c.toEpochId)).map(c=>c.viaProofHash);n.push({code:"epochlink-cycle",proofHashes:a,message:`Epoch lineage links form a cycle among ${s.length} epochs. Each link claims its successor epoch came after its predecessor, so a cycle means these ordering claims contradict each other; no ordering is asserted for the epochs involved.`,details:{epochIds:s}})}}function fd(t){let e=new Map,n=new Set,r=[...t.keys()].sort();for(let o of r){if(n.has(o))continue;let i=[],s=new Set,a=new Map,c=[o];for(;c.length>0;){let f=c[c.length-1];s.has(f)||(s.add(f),i.push(f),a.set(f,[...t.get(f)??[]].sort()));let d=a.get(f).shift();if(d===void 0){c.pop(),s.delete(f),i.pop(),n.add(f);continue}if(s.has(d)){let h=i.indexOf(d),l=i.slice(h),m=ud(l);e.set(m.join("|"),m);continue}n.has(d)||c.push(d)}}return[...e.values()].sort((o,i)=>{let s=o.join("|"),a=i.join("|");return s<a?-1:s>a?1:0})}function ud(t){let e=0;for(let n=1;n<t.length;n++)t[n]<t[e]&&(e=n);return[...t.slice(e),...t.slice(0,e)]}async function Yn(t){let e=[],n=[];for(let r of t)await Ke(r)?e.push(r):n.push(r);return{parties:e,context:n}}function $e(t){let e=t.verification;return{proofHash:t.proofHash,sourcePaths:t.sources.map(n=>n.path),...e!==void 0?{verificationTier:e.tier,verificationStatus:e.status,...e.reason!==void 0?{verificationReason:e.reason}:{}}:{},...t.counter!==void 0?{counter:t.counter}:{},...t.slotCounter!==void 0?{slotCounter:t.slotCounter}:{},...t.prevB64!==void 0?{prevB64:t.prevB64}:{},...t.publicKeyB64!==void 0?{publicKeyB64:t.publicKeyB64}:{},...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.measurement!==void 0?{measurement:t.measurement}:{}}}function Ro(t){return[...t.entries()].sort(([e],[n])=>{let r=/^[0-9]+$/.test(e)?BigInt(e):void 0,o=/^[0-9]+$/.test(n)?BigInt(n):void 0;return r!==void 0&&o!==void 0&&r!==o?r<o?-1:1:r!==void 0&&o===void 0?-1:r===void 0&&o!==void 0?1:e<n?-1:e>n?1:0})}w();function $o(t){let e=new Map;for(let a of t.proofs){let c=JSON.stringify([a.measurement??null,a.publicKeyB64??null,a.epochId??null,a.chainId,a.hasAttestation]),f=e.get(c);if(f!==void 0){f.proofHashes.push(a.proofHash);continue}e.set(c,{...a.measurement!==void 0?{measurement:a.measurement}:{},...a.publicKeyB64!==void 0?{publicKeyB64:a.publicKeyB64}:{},...a.epochId!==void 0?{epochId:a.epochId}:{},chainId:a.chainId,attestationPresent:a.hasAttestation,proofHashes:[a.proofHash]})}let n=[...e.values()].sort(dd),r=new Map;for(let a of t.proofs)a.epochId!==void 0&&ue(r,a.epochId,a);let o=[];for(let[a,c]of[...r.entries()].sort(([f],[u])=>f<u?-1:f>u?1:0)){let f=new Set,u=new Set;for(let d of c)d.publicKeyB64!==void 0&&f.add(d.publicKeyB64),d.measurement!==void 0&&u.add(d.measurement);f.size>=2&&o.push({code:"mid-epoch-signer-change",proofHashes:c.map(d=>d.proofHash),message:`${f.size} distinct signer keys appear within epoch ${a}. A single enclave boot generates exactly one keypair per epoch, so multiple keys under one epochId cannot come from one healthy authority lifecycle. All key groups are preserved for adjudication.`,details:{epochId:a,publicKeysB64:[...f].sort()}}),u.size>=2&&o.push({code:"mid-epoch-measurement-change",proofHashes:c.map(d=>d.proofHash),message:`${u.size} distinct declared measurements appear within epoch ${a}. A single enclave boot has exactly one measurement, so multiple declared measurements under one epochId cannot come from one healthy authority lifecycle. Declared measurements are self-reported; attestation validation is reported separately.`,details:{epochId:a,measurements:[...u].sort()}})}let i=new Map;for(let a of t.proofs){if(a.publicKeyB64===void 0||a.epochId===void 0)continue;let c=i.get(a.publicKeyB64);c===void 0?i.set(a.publicKeyB64,new Set([a.epochId])):c.add(a.epochId)}let s=[...i.entries()].filter(([,a])=>a.size>=2).map(([a,c])=>({publicKeyB64:a,epochIds:[...c].sort()})).sort((a,c)=>a.publicKeyB64<c.publicKeyB64?-1:a.publicKeyB64>c.publicKeyB64?1:0);return{groups:n,anomalies:o,sharedSignersAcrossEpochs:s}}function dd(t,e){if(t.chainId!==e.chainId)return t.chainId<e.chainId?-1:1;let n=t.epochId??"",r=e.epochId??"";if(n!==r)return n<r?-1:1;let o=t.publicKeyB64??"",i=e.publicKeyB64??"";if(o!==i)return o<i?-1:1;let s=t.measurement??"",a=e.measurement??"";return s!==a?s<a?-1:1:t.attestationPresent!==e.attestationPresent?t.attestationPresent?-1:1:0}w();var hd="Ethereum Anchor",Ba="ethereum-anchor",ld=/^https:\/\/etherscan\.io\/block\/([0-9]+)$/;function No(t){let e=[],n=[],r=[];for(let o of t.proofs){let i=Po(o,"name"),s=pd(o);if(!(i===hd)){s===Ba&&(n.push(o.proofHash),r.push({code:"anchor-metadata-only-claim",...Do(o),message:"unsigned metadata.type claims ethereum-anchor, but the signed attribution does not identify this proof as an anchor. Metadata is advisory and unsigned; the proof is not treated as an anchor.",details:{proofHash:o.proofHash}}));continue}let c=s===Ba?"agrees":s===void 0?"absent":"disagrees";c==="disagrees"&&r.push({code:"anchor-metadata-disagreement",...Do(o),message:`signed attribution identifies an Ethereum anchor, but unsigned metadata.type is ${JSON.stringify(s)}. The signed field governs; the disagreement is recorded.`,details:{proofHash:o.proofHash,metadataType:s}});let f=Po(o,"message"),u=Po(o,"title"),d=u!==void 0?ld.exec(u)?.[1]??void 0:void 0;d===void 0&&r.push({code:"anchor-title-unparseable",...Do(o),message:u===void 0?"anchor proof carries no signed attribution.title; the signed block number is absent":"anchor attribution.title does not parse as an Etherscan block URL; the signed block number is treated as absent",details:{proofHash:o.proofHash,...u!==void 0?{title:u}:{}}});let h=o.verification;e.push({proofHash:o.proofHash,...o.epochId!==void 0?{epochId:o.epochId}:{},chainId:o.chainId,...o.counter!==void 0?{counter:o.counter}:{},...o.slotCounter!==void 0?{slotCounter:o.slotCounter}:{},...f!==void 0?{blockHash:f}:{},...d!==void 0?{blockNumber:d}:{},metadataCorroboration:c,...h!==void 0?{verificationTier:h.tier,verificationStatus:h.status,...h.reason!==void 0?{verificationReason:h.reason}:{}}:{}})}return{anchors:e,metadataOnlyProofHashes:n,findings:r}}function Po(t,e){let n=t.proof.attribution;if(n===null||typeof n!="object"||Array.isArray(n))return;let r=n[e];return typeof r=="string"?r:void 0}function pd(t){let e=t.proof.metadata;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.type;return typeof n=="string"?n:void 0}function Do(t){let e=t.sources[0]?.path;return e!==void 0?{path:e}:{}}w();w();var md=BigInt(0),tn=BigInt(1),gd=BigInt(2),bd=BigInt(7),yd=BigInt(256),wd=BigInt(113),ka=[],Ia=[],Ha=[];for(let t=0,e=tn,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],ka.push(2*(5*r+n)),Ia.push((t+1)*(t+2)/2%64);let o=md;for(let i=0;i<7;i++)e=(e<<tn^(e>>bd)*wd)%yd,e&gd&&(o^=tn<<(tn<<BigInt(i))-tn);Ha.push(o)}var Sa=wn(Ha,!0),xd=Sa[0],Ed=Sa[1],va=(t,e,n)=>n>32?zi(t,e,n):ji(t,e,n),Aa=(t,e,n)=>n>32?qi(t,e,n):Vi(t,e,n);function Bd(t,e=24){let n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let s=0;s<10;s++)n[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let a=(s+8)%10,c=(s+2)%10,f=n[c],u=n[c+1],d=va(f,u,1)^n[a],h=Aa(f,u,1)^n[a+1];for(let l=0;l<50;l+=10)t[s+l]^=d,t[s+l+1]^=h}let o=t[2],i=t[3];for(let s=0;s<24;s++){let a=Ia[s],c=va(o,i,a),f=Aa(o,i,a),u=ka[s];o=t[u],i=t[u+1],t[u]=c,t[u+1]=f}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)n[a]=t[s+a];for(let a=0;a<10;a++)t[s+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=xd[r],t[1]^=Ed[r]}Ie(n)}var Oo=class t extends At{constructor(e,n,r,o=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=i,Ar(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Fi(this.state)}clone(){return this._cloneInto()}keccak(){kr(this.state32),Bd(this.state32,this.rounds),kr(this.state32),this.posOut=0,this.pos=0}update(e){kt(this),e=_t(e),ct(e);let{blockLen:n,state:r}=this,o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);for(let a=0;a<s;a++)r[this.pos++]^=e[i++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:r,blockLen:o}=this;e[r]^=n,(n&128)!==0&&r===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){kt(this,!1),ct(e),this.finish();let n=this.state,{blockLen:r}=this;for(let o=0,i=e.length;o<i;){this.posOut>=r&&this.keccak();let s=Math.min(r-this.posOut,i-o);e.set(n.subarray(this.posOut,this.posOut+s),o),this.posOut+=s,o+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Ar(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(gn(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Ie(this.state)}_cloneInto(e){let{blockLen:n,suffix:r,outputLen:o,rounds:i,enableXOF:s}=this;return e||(e=new t(n,r,o,s,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=r,e.outputLen=o,e.enableXOF=s,e.destroyed=this.destroyed,e}},vd=(t,e,n)=>Kt(()=>new Oo(e,t,n));var Ta=vd(1,136,256/8);w();function $a(t){if(t.length===0)throw new Error("RLP: empty input");let{item:e,next:n}=Pa(t,0);if(n!==t.length)throw new Error(`RLP: ${t.length-n} trailing byte(s) after the top-level item`);if(!Array.isArray(e))throw new Error("RLP: top-level item is not a list");return e}function Pa(t,e){let n=Da(t,e);if(n<128)return{item:t.subarray(e,e+1),next:e+1};if(n<=183){let a=n-128,c=Xn(t,e+1,a);return{item:t.subarray(e+1,c),next:c}}if(n<=191){let a=n-183,c=Ra(t,e+1,a),f=e+1+a,u=Xn(t,f,c);return{item:t.subarray(f,u),next:u}}if(n<=247){let a=n-192,c=Xn(t,e+1,a);return{item:Ca(t,e+1,c),next:c}}let r=n-247,o=Ra(t,e+1,r),i=e+1+r,s=Xn(t,i,o);return{item:Ca(t,i,s),next:s}}function Ca(t,e,n){let r=[],o=e;for(;o<n;){let i=Pa(t,o);if(i.next>n)throw new Error("RLP: list item overruns its list payload");r.push(i.item),o=i.next}return r}function Ra(t,e,n){if(n<1||n>8)throw new Error(`RLP: invalid length-of-length ${n}`);let r=0;for(let o=0;o<n;o++)r=r*256+Da(t,e+o);if(r>t.length)throw new Error("RLP: declared length exceeds the input size");return r}function Xn(t,e,n){let r=e+n;if(r>t.length)throw new Error("RLP: item is truncated");return r}function Da(t,e){let n=t[e];if(n===void 0)throw new Error("RLP: unexpected end of input");return n}function Lo(t){let e=0n;for(let n of t)e=e<<8n|BigInt(n);return e}function Na(t){if(!t.startsWith("0x"))return null;let e=t.slice(2);if(e.length%2!==0||!/^[0-9a-fA-F]*$/.test(e))return null;let n=new Uint8Array(e.length/2);for(let r=0;r<n.length;r++)n[r]=Number.parseInt(e.slice(r*2,r*2+2),16);return n}function Oa(t){return`0x${B.Buffer.from(t).toString("hex")}`}var La=8,Ma=11,Ad=/^0x[0-9a-fA-F]{64}$/,kd=/^https:\/\/etherscan\.io\/block\/([0-9]+)$/;async function Fo(t,e){let n=[],r=[],o=new Map(t.proofs.map(i=>[i.proofHash,i]));for(let i of t.witnesses){let s=Id(i);if(s.failure!==void 0){let u={witnessPath:i.path,verified:!1,reason:s.failure.reason,detail:s.failure.detail};n.push(u),r.push(Mo(u));continue}let a=s.computedHash,c=s.claimedHash.toLowerCase(),f=e.anchors.filter(u=>{let d=u.blockHash?.toLowerCase();return d!==void 0&&(d===a||d===c)});if(f.length===0){let u={witnessPath:i.path,verified:!1,reason:"witness-unmatched",detail:"neither the locally recomputed block hash nor the claimed blockHash matches any observed anchor's signed attribution.message",computedBlockHash:a};n.push(u),r.push(Mo(u));continue}for(let u of f){let d=o.get(u.proofHash),h=d!==void 0&&await Ke(d),l=Hd(s,i.path,u.proofHash,d,h);n.push(l),l.verified||r.push(Mo(l))}}return{outcomes:n,findings:r}}function Id(t){let e=t.witness,n=e.headerRlpHex;if(typeof n!="string")return Jn("headerRlpHex is missing or not a string");let r=e.blockNumber;if(typeof r!="number"||!Number.isInteger(r)||r<0)return Jn("blockNumber is missing or not a non-negative integer");let o=e.blockHash;if(typeof o!="string"||!Ad.test(o))return Jn("blockHash is missing or not 0x followed by 64 hex characters");let i=Na(n);if(i===null)return Jn("headerRlpHex is not 0x-prefixed even-length hex");let s;try{s=$a(i)}catch(c){return{failure:{reason:"witness-rlp-invalid",detail:c instanceof Error?c.message:String(c)}}}return{computedHash:Oa(Ta(i)),items:s,claimedHash:o,claimedNumber:BigInt(r)}}function Jn(t){return{failure:{reason:"witness-malformed",detail:t}}}function Hd(t,e,n,r,o){let i=t.computedHash,s={witnessPath:e,anchorProofHash:n,computedBlockHash:i},a=(b,I,v)=>({...s,verified:!1,reason:b,detail:I,...v?.blockNumber!==void 0?{blockNumber:v.blockNumber}:{}});if(r===void 0||!o)return a("witness-anchor-invalid","the candidate anchor proof is not cryptographically valid; the witness confers nothing");let c=Sd(r);if(c===void 0||c.toLowerCase()!==i)return a("witness-hash-mismatch",c===void 0?"the anchor carries no signed attribution.message to compare against":"the locally recomputed block hash does not equal the anchor's signed attribution.message");let f=Rd(Cd(r));if(f===null)return a("witness-digest-mismatch","the anchor's artifact.digestB64 does not strictly decode as base64 of 32 bytes");let u=_(new TextEncoder().encode(c));if(!$d(u,f))return a("witness-digest-mismatch","SHA-256 of the exact signed attribution.message string does not equal the anchor's artifact digest");let d=t.items,h=d[La];if(h===void 0||!(h instanceof Uint8Array))return a("witness-header-shape",`header RLP item ${La} (block number) is missing or not a byte string`);let l=Lo(h);if(l!==t.claimedNumber)return a("witness-block-number-mismatch",`the witness claims blockNumber ${t.claimedNumber}, but the header's number field is ${l}`,{blockNumber:String(l)});let m=Td(r);if(m!==void 0){let b=kd.exec(m)?.[1];if(b!==void 0&&BigInt(b)!==l)return a("witness-block-number-mismatch",`the anchor's signed Etherscan URL names block ${b}, but the header's number field is ${l}`,{blockNumber:String(l)})}if(t.claimedHash.toLowerCase()!==i)return a("witness-claimed-hash-mismatch","the witness's claimed blockHash does not equal the locally recomputed block hash",{blockNumber:String(l)});let p=d[Ma];if(p===void 0||!(p instanceof Uint8Array))return a("witness-header-shape",`header RLP item ${Ma} (timestamp) is missing or not a byte string`,{blockNumber:String(l)});let y=Lo(p);return y>BigInt(Number.MAX_SAFE_INTEGER)?a("witness-header-shape","header timestamp does not fit a safe integer",{blockNumber:String(l)}):{...s,verified:!0,blockNumber:String(l),timestamp:Number(y)}}function Sd(t){return Fa(t,"message")}function Td(t){return Fa(t,"title")}function Fa(t,e){let n=t.proof.attribution;if(n===null||typeof n!="object"||Array.isArray(n))return;let r=n[e];return typeof r=="string"?r:void 0}function Cd(t){let e=t.proof.artifact;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.digestB64;return typeof n=="string"?n:void 0}function Rd(t){if(t===void 0||t.length===0)return null;let e=B.Buffer.from(t,"base64");return e.length!==32||e.toString("base64")!==t?null:new Uint8Array(e)}function $d(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}function Mo(t){return{code:t.reason,path:t.witnessPath,message:`anchor witness rejected: ${t.detail??"verification failed"}. The witness confers nothing; the anchor proof's own standing is unchanged.`,details:{...t.anchorProofHash!==void 0?{anchorProofHash:t.anchorProofHash}:{},...t.computedBlockHash!==void 0?{computedBlockHash:t.computedBlockHash}:{}}}}w();function Uo(t,e,n,r){let o=new Map(t.proofs.map(u=>[u.proofHash,u])),i=new Map;for(let u of r.outcomes)!u.verified||u.anchorProofHash===void 0||i.has(u.anchorProofHash)||i.set(u.anchorProofHash,{anchorProofHash:u.anchorProofHash,timestamp:u.timestamp,blockHash:u.computedBlockHash,...u.blockNumber!==void 0?{blockNumber:u.blockNumber}:{}});let s=[...i.keys()].sort(),a=n.anchors.map(u=>u.proofHash).filter(u=>!i.has(u)).sort(),c=[];for(let u of e.partitions)c.push(...Pd(u,o,i));let f=Fd(e,c);return{segments:c,anchorOrderedPairs:f,verifiedAnchorProofHashes:s,unverifiedAnchorProofHashes:a}}function Pd(t,e,n){let r=t.memberProofHashes.map(h=>e.get(h)),o=new Map(r.map(h=>[h.chainHash,h])),i=r.filter(h=>n.has(h.proofHash)),s=new Map;for(let h of r){if(h.prevB64===void 0)continue;let l=o.get(h.prevB64);l===void 0||l.proofHash===h.proofHash||ue(s,l.proofHash,h)}let a=new Map,c=new Map;for(let h of i)a.set(h.proofHash,Nd(h,s)),c.set(h.proofHash,Od(h,o));let f=r.map(h=>{let l=new Map,m=new Map,p=Y(h.counter);for(let y of i){let b=y.proofHash,I=Y(y.counter);h.proofHash===b||a.get(b).has(h.proofHash)?l.set(b,"chain-link"):p!==void 0&&I!==void 0&&p>I&&(l.has(b)||l.set(b,"counter-order")),c.get(b).has(h.proofHash)?m.set(b,"chain-link"):h.proofHash!==b&&p!==void 0&&I!==void 0&&p<I&&(m.has(b)||m.set(b,"counter-order"))}return{member:h,lower:Ua("not-before",l,n),upper:Ua("not-after",m,n)}}),u=new Map;for(let h of f)ue(u,Dd(h),h);let d=[];for(let h of u.values()){let l=h.map(v=>v.member).sort(Re),m=h[0],p=m.lower,y=m.upper,b=p.length>0&&y.length>0?"lower-bounded-with-following-anchor":p.length>0?"lower-bounded":y.length>0?"upper-bounded":"ordered-but-unanchored",I=Ld(l);d.push({partition:t.key,memberProofHashes:l.map(v=>v.proofHash),...I!==void 0?{positionRange:I}:{},status:b,lowerBounds:p,upperBounds:y})}return d.sort(Md),d}function Ua(t,e,n){if(e.size===0)return[];let r=[...e.entries()].map(([c,f])=>({anchorHash:c,evidenceKind:f,info:n.get(c)})),o=(c,f)=>f===void 0?!0:c.info.timestamp!==f.info.timestamp?t==="not-before"?c.info.timestamp>f.info.timestamp:c.info.timestamp<f.info.timestamp:c.evidenceKind!==f.evidenceKind?c.evidenceKind==="chain-link":c.anchorHash<f.anchorHash,i,s;for(let c of r)o(c,i)&&(i=c),c.evidenceKind==="chain-link"&&o(c,s)&&(s=c);let a=[_a(t,i)];return s!==void 0&&(i.anchorHash!==s.anchorHash||i.evidenceKind!=="chain-link")&&a.push(_a(t,s)),a}function _a(t,e){let{info:n,evidenceKind:r}=e,o=new Date(n.timestamp*1e3).toISOString(),i=n.blockNumber!==void 0?`Ethereum block ${n.blockNumber}`:"an Ethereum block",s=r==="chain-link"?"Evidence: a verified hash-link path connects these proofs and the anchor.":"Evidence: commit-counter ordering within the partition only, which relies on the authority's counter discipline rather than verifiable hash links (weaker).",a=t==="not-before"?`These proofs were committed no earlier than ${o} (unix ${n.timestamp}), the timestamp of ${i}: the block hash was unpredictable before that time and the anchor commit consumed it. Reading this as a wall-clock floor additionally assumes the anchored header is a genuine, publicly published Ethereum block: this offline audit checks the header's structure and hash binding, not proof-of-work, consensus, or chain membership, so it cannot confirm the block is real. ${s}`:`These proofs existed before the anchor commit that consumed the hash of ${i} (block timestamp ${o}, unix ${n.timestamp}). The block timestamp proves the anchor commit came at or after it, not how promptly; reading it as a wall-clock ceiling additionally assumes the anchor consumed a recently published block. ${s}`;return{kind:t,anchorProofHash:e.anchorHash,...n.blockNumber!==void 0?{blockNumber:n.blockNumber}:{},blockHash:n.blockHash,timestamp:n.timestamp,evidence:r,weaker:r==="counter-order",basis:t==="not-before"?"block-hash-unpredictability":"causal-precedence",boundClass:t==="not-before"?"evidence":"assumption",claim:t==="not-before"?a:"NOT a proof-carried upper bound. "+a}}function Dd(t){let e=n=>n.map(r=>`${r.anchorProofHash}:${r.evidence}`).join(",");return`${e(t.lower)}|${e(t.upper)}`}function Nd(t,e){let n=new Set,r=[...e.get(t.proofHash)??[]];for(;r.length>0;){let o=r.pop();if(!n.has(o.proofHash)){n.add(o.proofHash);for(let i of e.get(o.proofHash)??[])r.push(i)}}return n}function Od(t,e){let n=new Set,r=t;for(;r!==void 0&&r.prevB64!==void 0;){let o=e.get(r.prevB64);if(o===void 0||n.has(o.proofHash)||o.proofHash===t.proofHash)break;n.add(o.proofHash),r=o}return n}function Ld(t){let e,n;for(let r of t)for(let o of[r.counter,r.slotCounter]){let i=Y(o);i!==void 0&&((e===void 0||i<e)&&(e=i),(n===void 0||i>n)&&(n=i))}return e!==void 0&&n!==void 0?{min:String(e),max:String(n)}:void 0}function Md(t,e){let n=t.positionRange?.min,r=e.positionRange?.min;if(n!==void 0&&r!==void 0&&n!==r)return BigInt(n)<BigInt(r)?-1:1;if(n!==void 0&&r===void 0)return-1;if(n===void 0&&r!==void 0)return 1;let o=t.memberProofHashes[0]??"",i=e.memberProofHashes[0]??"";return o<i?-1:o>i?1:0}function Ka(t){return t?" The representative bound rests on commit-counter ordering rather than a verified hash-link path, which relies on the authority's counter discipline (weaker evidence).":""}function Fd(t,e){let n=new Map;for(let i of t.epochRelationships.epochs)n.set(i.epochId,{totalProofCount:i.proofCount,lowerCovered:new Set,upperCovered:new Set});for(let i of e){let s=i.partition.epochId;if(s===void 0)continue;let a=n.get(s);if(a!==void 0){for(let c of i.lowerBounds){for(let f of i.memberProofHashes)a.lowerCovered.add(f);(a.lowerMin===void 0||c.timestamp<a.lowerMin.timestamp||c.timestamp===a.lowerMin.timestamp&&a.lowerMin.weaker&&!c.weaker)&&(a.lowerMin={timestamp:c.timestamp,anchorProofHash:c.anchorProofHash,blockHash:c.blockHash,...c.blockNumber!==void 0?{blockNumber:c.blockNumber}:{},evidence:c.evidence,weaker:c.weaker})}for(let c of i.upperBounds){for(let f of i.memberProofHashes)a.upperCovered.add(f);(a.upperMax===void 0||c.timestamp>a.upperMax.timestamp||c.timestamp===a.upperMax.timestamp&&a.upperMax.weaker&&!c.weaker)&&(a.upperMax={timestamp:c.timestamp,anchorProofHash:c.anchorProofHash,blockHash:c.blockHash,...c.blockNumber!==void 0?{blockNumber:c.blockNumber}:{},evidence:c.evidence,weaker:c.weaker})}}}for(let i of t.epochRelationships.epochs){let s=n.get(i.epochId),a=[];s.lowerMin!==void 0&&a.push({kind:"not-before",anchorProofHash:s.lowerMin.anchorProofHash,...s.lowerMin.blockNumber!==void 0?{blockNumber:s.lowerMin.blockNumber}:{},blockHash:s.lowerMin.blockHash,witnessTimestamp:s.lowerMin.timestamp,coverage:"members-after-anchor",coveredProofCount:s.lowerCovered.size,totalProofCount:s.totalProofCount,basis:"block-hash-unpredictability",evidence:s.lowerMin.evidence,weaker:s.lowerMin.weaker,claim:`${s.lowerCovered.size} of ${s.totalProofCount} observed proofs of this epoch were committed no earlier than unix ${s.lowerMin.timestamp}, grounded in block-hash unpredictability through verified anchor witnesses. This additionally assumes the anchored header is a genuine, publicly published Ethereum block, which this offline audit cannot confirm.`+Ka(s.lowerMin.weaker)+" The remaining proofs sit causally before the covering anchors and carry no lower bound from this evidence."}),s.upperMax!==void 0&&a.push({kind:"not-after",anchorProofHash:s.upperMax.anchorProofHash,...s.upperMax.blockNumber!==void 0?{blockNumber:s.upperMax.blockNumber}:{},blockHash:s.upperMax.blockHash,witnessTimestamp:s.upperMax.timestamp,coverage:"members-before-anchor",coveredProofCount:s.upperCovered.size,totalProofCount:s.totalProofCount,basis:"causal-precedence",evidence:s.upperMax.evidence,weaker:s.upperMax.weaker,claim:`${s.upperCovered.size} of ${s.totalProofCount} observed proofs of this epoch existed before an anchor commit that consumed a block published at unix ${s.upperMax.timestamp}. Reading that timestamp as a wall-clock ceiling additionally assumes the anchor consumed a recently published block; the causal precedence itself is verified.`+Ka(s.upperMax.weaker)+" Proofs after the covering anchors are not covered."}),a.length>0&&(i.anchorBounds=a)}let r=[],o=t.epochRelationships.epochs;for(let i of o){let s=n.get(i.epochId);if(s.upperMax!==void 0)for(let a of o){if(a.epochId===i.epochId)continue;let c=n.get(a.epochId);if(c.lowerMin===void 0||s.upperMax.timestamp>=c.lowerMin.timestamp)continue;let f=s.upperMax.evidence,u=c.lowerMin.evidence,d=s.upperMax.weaker||c.lowerMin.weaker;r.push({beforeEpochId:i.epochId,afterEpochId:a.epochId,upperAnchorProofHash:s.upperMax.anchorProofHash,upperBoundTimestamp:s.upperMax.timestamp,lowerAnchorProofHash:c.lowerMin.anchorProofHash,lowerBoundTimestamp:c.lowerMin.timestamp,basis:"anchor-bounds",assumptionDependent:!0,upperEvidence:f,lowerEvidence:u,weaker:d,beforeCoveredProofCount:s.upperCovered.size,beforeTotalProofCount:s.totalProofCount,afterCoveredProofCount:c.lowerCovered.size,afterTotalProofCount:c.totalProofCount,note:`The anchor-covered portion of epoch ${i.epochId} (${s.upperCovered.size} of ${s.totalProofCount} proofs) precedes the anchor-covered portion of epoch ${a.epochId} (${c.lowerCovered.size} of ${c.totalProofCount} proofs): the first is bounded not-after unix ${s.upperMax.timestamp} and the second not-before unix ${c.lowerMin.timestamp}. One-sided evidence about the covered portions only; the not-after side rests on the anchor-freshness assumption documented on its bound.`+(d?" At least one side rests on commit-counter ordering rather than a verified hash-link path (weaker evidence), which relies on the authority's counter discipline.":"")+" This is ordering evidence, never divergence."})}}return r.sort((i,s)=>i.beforeEpochId!==s.beforeEpochId?i.beforeEpochId<s.beforeEpochId?-1:1:i.afterEpochId<s.afterEpochId?-1:i.afterEpochId>s.afterEpochId?1:0),r}w();w();var ja=`-----BEGIN CERTIFICATE-----
139
+ "use strict";(()=>{var mc=Object.create;var si=Object.defineProperty;var gc=Object.getOwnPropertyDescriptor;var bc=Object.getOwnPropertyNames;var yc=Object.getPrototypeOf,wc=Object.prototype.hasOwnProperty;var xc=(t,e)=>()=>(t&&(e=t(t=0)),e);var no=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ec=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of bc(e))!wc.call(t,r)&&r!==n&&si(t,r,{get:()=>e[r],enumerable:!(o=gc(e,r))||o.enumerable});return t};var Bc=(t,e,n)=>(n=t!=null?mc(yc(t)):{},Ec(e||!t||!t.__esModule?si(n,"default",{value:t,enumerable:!0}):n,t));var fi=no(un=>{"use strict";y();un.byteLength=Ac;un.toByteArray=kc;un.fromByteArray=Hc;var ve=[],pe=[],vc=typeof Uint8Array<"u"?Uint8Array:Array,oo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ft=0,ai=oo.length;ft<ai;++ft)ve[ft]=oo[ft],pe[oo.charCodeAt(ft)]=ft;var ft,ai;pe[45]=62;pe[95]=63;function ci(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");n===-1&&(n=e);var o=n===e?0:4-n%4;return[n,o]}function Ac(t){var e=ci(t),n=e[0],o=e[1];return(n+o)*3/4-o}function Ic(t,e,n){return(e+n)*3/4-n}function kc(t){var e,n=ci(t),o=n[0],r=n[1],i=new vc(Ic(t,o,r)),s=0,a=r>0?o-4:o,c;for(c=0;c<a;c+=4)e=pe[t.charCodeAt(c)]<<18|pe[t.charCodeAt(c+1)]<<12|pe[t.charCodeAt(c+2)]<<6|pe[t.charCodeAt(c+3)],i[s++]=e>>16&255,i[s++]=e>>8&255,i[s++]=e&255;return r===2&&(e=pe[t.charCodeAt(c)]<<2|pe[t.charCodeAt(c+1)]>>4,i[s++]=e&255),r===1&&(e=pe[t.charCodeAt(c)]<<10|pe[t.charCodeAt(c+1)]<<4|pe[t.charCodeAt(c+2)]>>2,i[s++]=e>>8&255,i[s++]=e&255),i}function Sc(t){return ve[t>>18&63]+ve[t>>12&63]+ve[t>>6&63]+ve[t&63]}function Tc(t,e,n){for(var o,r=[],i=e;i<n;i+=3)o=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),r.push(Sc(o));return r.join("")}function Hc(t){for(var e,n=t.length,o=n%3,r=[],i=16383,s=0,a=n-o;s<a;s+=i)r.push(Tc(t,s,s+i>a?a:s+i));return o===1?(e=t[n-1],r.push(ve[e>>2]+ve[e<<4&63]+"==")):o===2&&(e=(t[n-2]<<8)+t[n-1],r.push(ve[e>>10]+ve[e>>4&63]+ve[e<<2&63]+"=")),r.join("")}});var ui=no(ro=>{y();ro.read=function(t,e,n,o,r){var i,s,a=r*8-o-1,c=(1<<a)-1,f=c>>1,u=-7,d=n?r-1:0,h=n?-1:1,l=t[e+d];for(d+=h,i=l&(1<<-u)-1,l>>=-u,u+=a;u>0;i=i*256+t[e+d],d+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=o;u>0;s=s*256+t[e+d],d+=h,u-=8);if(i===0)i=1-f;else{if(i===c)return s?NaN:(l?-1:1)*(1/0);s=s+Math.pow(2,o),i=i-f}return(l?-1:1)*s*Math.pow(2,i-o)};ro.write=function(t,e,n,o,r,i){var s,a,c,f=i*8-r-1,u=(1<<f)-1,d=u>>1,h=r===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=o?0:i-1,m=o?1:-1,p=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=h/c:e+=h*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=u?(a=0,s=u):s+d>=1?(a=(e*c-1)*Math.pow(2,r),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,r),s=0));r>=8;t[n+l]=a&255,l+=m,a/=256,r-=8);for(s=s<<r|a,f+=r;f>0;t[n+l]=s&255,l+=m,s/=256,f-=8);t[n+l-m]|=p*128}});var Si=no(It=>{"use strict";y();var io=fi(),vt=ui(),di=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;It.Buffer=g;It.SlowBuffer=Nc;It.INSPECT_MAX_BYTES=50;var dn=2147483647;It.kMaxLength=dn;g.TYPED_ARRAY_SUPPORT=Cc();!g.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 Cc(){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(g.prototype,"parent",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.buffer}});Object.defineProperty(g.prototype,"offset",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.byteOffset}});function Ne(t){if(t>dn)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,g.prototype),e}function g(t,e,n){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return fo(t)}return mi(t,e,n)}g.poolSize=8192;function mi(t,e,n){if(typeof t=="string")return $c(t,e);if(ArrayBuffer.isView(t))return Pc(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(Ae(t,ArrayBuffer)||t&&Ae(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ae(t,SharedArrayBuffer)||t&&Ae(t.buffer,SharedArrayBuffer)))return ao(t,e,n);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let o=t.valueOf&&t.valueOf();if(o!=null&&o!==t)return g.from(o,e,n);let r=Dc(t);if(r)return r;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return g.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}g.from=function(t,e,n){return mi(t,e,n)};Object.setPrototypeOf(g.prototype,Uint8Array.prototype);Object.setPrototypeOf(g,Uint8Array);function gi(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 Rc(t,e,n){return gi(t),t<=0?Ne(t):e!==void 0?typeof n=="string"?Ne(t).fill(e,n):Ne(t).fill(e):Ne(t)}g.alloc=function(t,e,n){return Rc(t,e,n)};function fo(t){return gi(t),Ne(t<0?0:uo(t)|0)}g.allocUnsafe=function(t){return fo(t)};g.allocUnsafeSlow=function(t){return fo(t)};function $c(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!g.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let n=bi(t,e)|0,o=Ne(n),r=o.write(t,e);return r!==n&&(o=o.slice(0,r)),o}function so(t){let e=t.length<0?0:uo(t.length)|0,n=Ne(e);for(let o=0;o<e;o+=1)n[o]=t[o]&255;return n}function Pc(t){if(Ae(t,Uint8Array)){let e=new Uint8Array(t);return ao(e.buffer,e.byteOffset,e.byteLength)}return so(t)}function ao(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let o;return e===void 0&&n===void 0?o=new Uint8Array(t):n===void 0?o=new Uint8Array(t,e):o=new Uint8Array(t,e,n),Object.setPrototypeOf(o,g.prototype),o}function Dc(t){if(g.isBuffer(t)){let e=uo(t.length)|0,n=Ne(e);return n.length===0||t.copy(n,0,0,e),n}if(t.length!==void 0)return typeof t.length!="number"||lo(t.length)?Ne(0):so(t);if(t.type==="Buffer"&&Array.isArray(t.data))return so(t.data)}function uo(t){if(t>=dn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+dn.toString(16)+" bytes");return t|0}function Nc(t){return+t!=t&&(t=0),g.alloc(+t)}g.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==g.prototype};g.compare=function(e,n){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),Ae(n,Uint8Array)&&(n=g.from(n,n.offset,n.byteLength)),!g.isBuffer(e)||!g.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===n)return 0;let o=e.length,r=n.length;for(let i=0,s=Math.min(o,r);i<s;++i)if(e[i]!==n[i]){o=e[i],r=n[i];break}return o<r?-1:r<o?1:0};g.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}};g.concat=function(e,n){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return g.alloc(0);let o;if(n===void 0)for(n=0,o=0;o<e.length;++o)n+=e[o].length;let r=g.allocUnsafe(n),i=0;for(o=0;o<e.length;++o){let s=e[o];if(Ae(s,Uint8Array))i+s.length>r.length?(g.isBuffer(s)||(s=g.from(s)),s.copy(r,i)):Uint8Array.prototype.set.call(r,s,i);else if(g.isBuffer(s))s.copy(r,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return r};function bi(t,e){if(g.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Ae(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 n=t.length,o=arguments.length>2&&arguments[2]===!0;if(!o&&n===0)return 0;let r=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return co(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return ki(t).length;default:if(r)return o?-1:co(t).length;e=(""+e).toLowerCase(),r=!0}}g.byteLength=bi;function Mc(t,e,n){let o=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,e>>>=0,n<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return qc(this,e,n);case"utf8":case"utf-8":return wi(this,e,n);case"ascii":return Vc(this,e,n);case"latin1":case"binary":return zc(this,e,n);case"base64":return jc(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Gc(this,e,n);default:if(o)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}g.prototype._isBuffer=!0;function ut(t,e,n){let o=t[e];t[e]=t[n],t[n]=o}g.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 n=0;n<e;n+=2)ut(this,n,n+1);return this};g.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 n=0;n<e;n+=4)ut(this,n,n+3),ut(this,n+1,n+2);return this};g.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 n=0;n<e;n+=8)ut(this,n,n+7),ut(this,n+1,n+6),ut(this,n+2,n+5),ut(this,n+3,n+4);return this};g.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?wi(this,0,e):Mc.apply(this,arguments)};g.prototype.toLocaleString=g.prototype.toString;g.prototype.equals=function(e){if(!g.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:g.compare(this,e)===0};g.prototype.inspect=function(){let e="",n=It.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"};di&&(g.prototype[di]=g.prototype.inspect);g.prototype.compare=function(e,n,o,r,i){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),!g.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(n===void 0&&(n=0),o===void 0&&(o=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),n<0||o>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&n>=o)return 0;if(r>=i)return-1;if(n>=o)return 1;if(n>>>=0,o>>>=0,r>>>=0,i>>>=0,this===e)return 0;let s=i-r,a=o-n,c=Math.min(s,a),f=this.slice(r,i),u=e.slice(n,o);for(let d=0;d<c;++d)if(f[d]!==u[d]){s=f[d],a=u[d];break}return s<a?-1:a<s?1:0};function yi(t,e,n,o,r){if(t.length===0)return-1;if(typeof n=="string"?(o=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,lo(n)&&(n=r?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(r)return-1;n=t.length-1}else if(n<0)if(r)n=0;else return-1;if(typeof e=="string"&&(e=g.from(e,o)),g.isBuffer(e))return e.length===0?-1:hi(t,e,n,o,r);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?r?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):hi(t,[e],n,o,r);throw new TypeError("val must be string, number or Buffer")}function hi(t,e,n,o,r){let i=1,s=t.length,a=e.length;if(o!==void 0&&(o=String(o).toLowerCase(),o==="ucs2"||o==="ucs-2"||o==="utf16le"||o==="utf-16le")){if(t.length<2||e.length<2)return-1;i=2,s/=2,a/=2,n/=2}function c(u,d){return i===1?u[d]:u.readUInt16BE(d*i)}let f;if(r){let u=-1;for(f=n;f<s;f++)if(c(t,f)===c(e,u===-1?0:f-u)){if(u===-1&&(u=f),f-u+1===a)return u*i}else u!==-1&&(f-=f-u),u=-1}else for(n+a>s&&(n=s-a),f=n;f>=0;f--){let u=!0;for(let d=0;d<a;d++)if(c(t,f+d)!==c(e,d)){u=!1;break}if(u)return f}return-1}g.prototype.includes=function(e,n,o){return this.indexOf(e,n,o)!==-1};g.prototype.indexOf=function(e,n,o){return yi(this,e,n,o,!0)};g.prototype.lastIndexOf=function(e,n,o){return yi(this,e,n,o,!1)};function Lc(t,e,n,o){n=Number(n)||0;let r=t.length-n;o?(o=Number(o),o>r&&(o=r)):o=r;let i=e.length;o>i/2&&(o=i/2);let s;for(s=0;s<o;++s){let a=parseInt(e.substr(s*2,2),16);if(lo(a))return s;t[n+s]=a}return s}function Oc(t,e,n,o){return hn(co(e,t.length-n),t,n,o)}function Fc(t,e,n,o){return hn(Xc(e),t,n,o)}function Uc(t,e,n,o){return hn(ki(e),t,n,o)}function _c(t,e,n,o){return hn(Jc(e,t.length-n),t,n,o)}g.prototype.write=function(e,n,o,r){if(n===void 0)r="utf8",o=this.length,n=0;else if(o===void 0&&typeof n=="string")r=n,o=this.length,n=0;else if(isFinite(n))n=n>>>0,isFinite(o)?(o=o>>>0,r===void 0&&(r="utf8")):(r=o,o=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-n;if((o===void 0||o>i)&&(o=i),e.length>0&&(o<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let s=!1;for(;;)switch(r){case"hex":return Lc(this,e,n,o);case"utf8":case"utf-8":return Oc(this,e,n,o);case"ascii":case"latin1":case"binary":return Fc(this,e,n,o);case"base64":return Uc(this,e,n,o);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _c(this,e,n,o);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}};g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function jc(t,e,n){return e===0&&n===t.length?io.fromByteArray(t):io.fromByteArray(t.slice(e,n))}function wi(t,e,n){n=Math.min(t.length,n);let o=[],r=e;for(;r<n;){let i=t[r],s=null,a=i>239?4:i>223?3:i>191?2:1;if(r+a<=n){let c,f,u,d;switch(a){case 1:i<128&&(s=i);break;case 2:c=t[r+1],(c&192)===128&&(d=(i&31)<<6|c&63,d>127&&(s=d));break;case 3:c=t[r+1],f=t[r+2],(c&192)===128&&(f&192)===128&&(d=(i&15)<<12|(c&63)<<6|f&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=t[r+1],f=t[r+2],u=t[r+3],(c&192)===128&&(f&192)===128&&(u&192)===128&&(d=(i&15)<<18|(c&63)<<12|(f&63)<<6|u&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,o.push(s>>>10&1023|55296),s=56320|s&1023),o.push(s),r+=a}return Kc(o)}var li=4096;function Kc(t){let e=t.length;if(e<=li)return String.fromCharCode.apply(String,t);let n="",o=0;for(;o<e;)n+=String.fromCharCode.apply(String,t.slice(o,o+=li));return n}function Vc(t,e,n){let o="";n=Math.min(t.length,n);for(let r=e;r<n;++r)o+=String.fromCharCode(t[r]&127);return o}function zc(t,e,n){let o="";n=Math.min(t.length,n);for(let r=e;r<n;++r)o+=String.fromCharCode(t[r]);return o}function qc(t,e,n){let o=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>o)&&(n=o);let r="";for(let i=e;i<n;++i)r+=Qc[t[i]];return r}function Gc(t,e,n){let o=t.slice(e,n),r="";for(let i=0;i<o.length-1;i+=2)r+=String.fromCharCode(o[i]+o[i+1]*256);return r}g.prototype.slice=function(e,n){let o=this.length;e=~~e,n=n===void 0?o:~~n,e<0?(e+=o,e<0&&(e=0)):e>o&&(e=o),n<0?(n+=o,n<0&&(n=0)):n>o&&(n=o),n<e&&(n=e);let r=this.subarray(e,n);return Object.setPrototypeOf(r,g.prototype),r};function J(t,e,n){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}g.prototype.readUintLE=g.prototype.readUIntLE=function(e,n,o){e=e>>>0,n=n>>>0,o||J(e,n,this.length);let r=this[e],i=1,s=0;for(;++s<n&&(i*=256);)r+=this[e+s]*i;return r};g.prototype.readUintBE=g.prototype.readUIntBE=function(e,n,o){e=e>>>0,n=n>>>0,o||J(e,n,this.length);let r=this[e+--n],i=1;for(;n>0&&(i*=256);)r+=this[e+--n]*i;return r};g.prototype.readUint8=g.prototype.readUInt8=function(e,n){return e=e>>>0,n||J(e,1,this.length),this[e]};g.prototype.readUint16LE=g.prototype.readUInt16LE=function(e,n){return e=e>>>0,n||J(e,2,this.length),this[e]|this[e+1]<<8};g.prototype.readUint16BE=g.prototype.readUInt16BE=function(e,n){return e=e>>>0,n||J(e,2,this.length),this[e]<<8|this[e+1]};g.prototype.readUint32LE=g.prototype.readUInt32LE=function(e,n){return e=e>>>0,n||J(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};g.prototype.readUint32BE=g.prototype.readUInt32BE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};g.prototype.readBigUInt64LE=Ye(function(e){e=e>>>0,At(e,"offset");let n=this[e],o=this[e+7];(n===void 0||o===void 0)&&Kt(e,this.length-8);let r=n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*2**8+this[++e]*2**16+o*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))});g.prototype.readBigUInt64BE=Ye(function(e){e=e>>>0,At(e,"offset");let n=this[e],o=this[e+7];(n===void 0||o===void 0)&&Kt(e,this.length-8);let r=n*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+o;return(BigInt(r)<<BigInt(32))+BigInt(i)});g.prototype.readIntLE=function(e,n,o){e=e>>>0,n=n>>>0,o||J(e,n,this.length);let r=this[e],i=1,s=0;for(;++s<n&&(i*=256);)r+=this[e+s]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*n)),r};g.prototype.readIntBE=function(e,n,o){e=e>>>0,n=n>>>0,o||J(e,n,this.length);let r=n,i=1,s=this[e+--r];for(;r>0&&(i*=256);)s+=this[e+--r]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*n)),s};g.prototype.readInt8=function(e,n){return e=e>>>0,n||J(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};g.prototype.readInt16LE=function(e,n){e=e>>>0,n||J(e,2,this.length);let o=this[e]|this[e+1]<<8;return o&32768?o|4294901760:o};g.prototype.readInt16BE=function(e,n){e=e>>>0,n||J(e,2,this.length);let o=this[e+1]|this[e]<<8;return o&32768?o|4294901760:o};g.prototype.readInt32LE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};g.prototype.readInt32BE=function(e,n){return e=e>>>0,n||J(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};g.prototype.readBigInt64LE=Ye(function(e){e=e>>>0,At(e,"offset");let n=this[e],o=this[e+7];(n===void 0||o===void 0)&&Kt(e,this.length-8);let r=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(o<<24);return(BigInt(r)<<BigInt(32))+BigInt(n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});g.prototype.readBigInt64BE=Ye(function(e){e=e>>>0,At(e,"offset");let n=this[e],o=this[e+7];(n===void 0||o===void 0)&&Kt(e,this.length-8);let r=(n<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+o)});g.prototype.readFloatLE=function(e,n){return e=e>>>0,n||J(e,4,this.length),vt.read(this,e,!0,23,4)};g.prototype.readFloatBE=function(e,n){return e=e>>>0,n||J(e,4,this.length),vt.read(this,e,!1,23,4)};g.prototype.readDoubleLE=function(e,n){return e=e>>>0,n||J(e,8,this.length),vt.read(this,e,!0,52,8)};g.prototype.readDoubleBE=function(e,n){return e=e>>>0,n||J(e,8,this.length),vt.read(this,e,!1,52,8)};function ce(t,e,n,o,r,i){if(!g.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||e<i)throw new RangeError('"value" argument is out of bounds');if(n+o>t.length)throw new RangeError("Index out of range")}g.prototype.writeUintLE=g.prototype.writeUIntLE=function(e,n,o,r){if(e=+e,n=n>>>0,o=o>>>0,!r){let a=Math.pow(2,8*o)-1;ce(this,e,n,o,a,0)}let i=1,s=0;for(this[n]=e&255;++s<o&&(i*=256);)this[n+s]=e/i&255;return n+o};g.prototype.writeUintBE=g.prototype.writeUIntBE=function(e,n,o,r){if(e=+e,n=n>>>0,o=o>>>0,!r){let a=Math.pow(2,8*o)-1;ce(this,e,n,o,a,0)}let i=o-1,s=1;for(this[n+i]=e&255;--i>=0&&(s*=256);)this[n+i]=e/s&255;return n+o};g.prototype.writeUint8=g.prototype.writeUInt8=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,1,255,0),this[n]=e&255,n+1};g.prototype.writeUint16LE=g.prototype.writeUInt16LE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,2,65535,0),this[n]=e&255,this[n+1]=e>>>8,n+2};g.prototype.writeUint16BE=g.prototype.writeUInt16BE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,2,65535,0),this[n]=e>>>8,this[n+1]=e&255,n+2};g.prototype.writeUint32LE=g.prototype.writeUInt32LE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,4,4294967295,0),this[n+3]=e>>>24,this[n+2]=e>>>16,this[n+1]=e>>>8,this[n]=e&255,n+4};g.prototype.writeUint32BE=g.prototype.writeUInt32BE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,4,4294967295,0),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};function xi(t,e,n,o,r){Ii(e,o,r,t,n,7);let i=Number(e&BigInt(4294967295));t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,n}function Ei(t,e,n,o,r){Ii(e,o,r,t,n,7);let i=Number(e&BigInt(4294967295));t[n+7]=i,i=i>>8,t[n+6]=i,i=i>>8,t[n+5]=i,i=i>>8,t[n+4]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=s,s=s>>8,t[n+2]=s,s=s>>8,t[n+1]=s,s=s>>8,t[n]=s,n+8}g.prototype.writeBigUInt64LE=Ye(function(e,n=0){return xi(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeBigUInt64BE=Ye(function(e,n=0){return Ei(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeIntLE=function(e,n,o,r){if(e=+e,n=n>>>0,!r){let c=Math.pow(2,8*o-1);ce(this,e,n,o,c-1,-c)}let i=0,s=1,a=0;for(this[n]=e&255;++i<o&&(s*=256);)e<0&&a===0&&this[n+i-1]!==0&&(a=1),this[n+i]=(e/s>>0)-a&255;return n+o};g.prototype.writeIntBE=function(e,n,o,r){if(e=+e,n=n>>>0,!r){let c=Math.pow(2,8*o-1);ce(this,e,n,o,c-1,-c)}let i=o-1,s=1,a=0;for(this[n+i]=e&255;--i>=0&&(s*=256);)e<0&&a===0&&this[n+i+1]!==0&&(a=1),this[n+i]=(e/s>>0)-a&255;return n+o};g.prototype.writeInt8=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,1,127,-128),e<0&&(e=255+e+1),this[n]=e&255,n+1};g.prototype.writeInt16LE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,2,32767,-32768),this[n]=e&255,this[n+1]=e>>>8,n+2};g.prototype.writeInt16BE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,2,32767,-32768),this[n]=e>>>8,this[n+1]=e&255,n+2};g.prototype.writeInt32LE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,4,2147483647,-2147483648),this[n]=e&255,this[n+1]=e>>>8,this[n+2]=e>>>16,this[n+3]=e>>>24,n+4};g.prototype.writeInt32BE=function(e,n,o){return e=+e,n=n>>>0,o||ce(this,e,n,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};g.prototype.writeBigInt64LE=Ye(function(e,n=0){return xi(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});g.prototype.writeBigInt64BE=Ye(function(e,n=0){return Ei(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Bi(t,e,n,o,r,i){if(n+o>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function vi(t,e,n,o,r){return e=+e,n=n>>>0,r||Bi(t,e,n,4,34028234663852886e22,-34028234663852886e22),vt.write(t,e,n,o,23,4),n+4}g.prototype.writeFloatLE=function(e,n,o){return vi(this,e,n,!0,o)};g.prototype.writeFloatBE=function(e,n,o){return vi(this,e,n,!1,o)};function Ai(t,e,n,o,r){return e=+e,n=n>>>0,r||Bi(t,e,n,8,17976931348623157e292,-17976931348623157e292),vt.write(t,e,n,o,52,8),n+8}g.prototype.writeDoubleLE=function(e,n,o){return Ai(this,e,n,!0,o)};g.prototype.writeDoubleBE=function(e,n,o){return Ai(this,e,n,!1,o)};g.prototype.copy=function(e,n,o,r){if(!g.isBuffer(e))throw new TypeError("argument should be a Buffer");if(o||(o=0),!r&&r!==0&&(r=this.length),n>=e.length&&(n=e.length),n||(n=0),r>0&&r<o&&(r=o),r===o||e.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(o<0||o>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-n<r-o&&(r=e.length-n+o);let i=r-o;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(n,o,r):Uint8Array.prototype.set.call(e,this.subarray(o,r),n),i};g.prototype.fill=function(e,n,o,r){if(typeof e=="string"){if(typeof n=="string"?(r=n,n=0,o=this.length):typeof o=="string"&&(r=o,o=this.length),r!==void 0&&typeof r!="string")throw new TypeError("encoding must be a string");if(typeof r=="string"&&!g.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(e.length===1){let s=e.charCodeAt(0);(r==="utf8"&&s<128||r==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(n<0||this.length<n||this.length<o)throw new RangeError("Out of range index");if(o<=n)return this;n=n>>>0,o=o===void 0?this.length:o>>>0,e||(e=0);let i;if(typeof e=="number")for(i=n;i<o;++i)this[i]=e;else{let s=g.isBuffer(e)?e:g.from(e,r),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<o-n;++i)this[i+n]=s[i%a]}return this};var Bt={};function ho(t,e,n){Bt[t]=class extends n{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(r){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:r,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}ho("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);ho("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);ho("ERR_OUT_OF_RANGE",function(t,e,n){let o=`The value of "${t}" is out of range.`,r=n;return Number.isInteger(n)&&Math.abs(n)>2**32?r=pi(String(n)):typeof n=="bigint"&&(r=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(r=pi(r)),r+="n"),o+=` It must be ${e}. Received ${r}`,o},RangeError);function pi(t){let e="",n=t.length,o=t[0]==="-"?1:0;for(;n>=o+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function Wc(t,e,n){At(e,"offset"),(t[e]===void 0||t[e+n]===void 0)&&Kt(e,t.length-(n+1))}function Ii(t,e,n,o,r,i){if(t>n||t<e){let s=typeof e=="bigint"?"n":"",a;throw i>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:a=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${n}${s}`,new Bt.ERR_OUT_OF_RANGE("value",a,t)}Wc(o,r,i)}function At(t,e){if(typeof t!="number")throw new Bt.ERR_INVALID_ARG_TYPE(e,"number",t)}function Kt(t,e,n){throw Math.floor(t)!==t?(At(t,n),new Bt.ERR_OUT_OF_RANGE(n||"offset","an integer",t)):e<0?new Bt.ERR_BUFFER_OUT_OF_BOUNDS:new Bt.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${e}`,t)}var Zc=/[^+/0-9A-Za-z-_]/g;function Yc(t){if(t=t.split("=")[0],t=t.trim().replace(Zc,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function co(t,e){e=e||1/0;let n,o=t.length,r=null,i=[];for(let s=0;s<o;++s){if(n=t.charCodeAt(s),n>55295&&n<57344){if(!r){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(s+1===o){(e-=3)>-1&&i.push(239,191,189);continue}r=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),r=n;continue}n=(r-55296<<10|n-56320)+65536}else r&&(e-=3)>-1&&i.push(239,191,189);if(r=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function Xc(t){let e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n)&255);return e}function Jc(t,e){let n,o,r,i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),o=n>>8,r=n%256,i.push(r),i.push(o);return i}function ki(t){return io.toByteArray(Yc(t))}function hn(t,e,n,o){let r;for(r=0;r<o&&!(r+n>=e.length||r>=t.length);++r)e[r+n]=t[r];return r}function Ae(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function lo(t){return t!==t}var Qc=(function(){let t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){let o=n*16;for(let r=0;r<16;++r)e[o+r]=t[n]+t[r]}return e})();function Ye(t){return typeof BigInt>"u"?ef:t}function ef(){throw new Error("BigInt not supported")}});var B,y=xc(()=>{"use strict";B=Bc(Si(),1);globalThis.Buffer=B.Buffer});y();y();var tf={p:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,n:0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,h:8n,a:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,d:0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,Gx:0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Gy:0x6666666666666666666666666666666666666666666666666666666666666658n},{p:ne,n:ln,Gx:Ti,Gy:Hi,a:po,d:mo}=tf,nf=8n,Vt=32,go=64,me=(t="")=>{throw new Error(t)},of=t=>typeof t=="bigint",Ni=t=>typeof t=="string",rf=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array",St=(t,e)=>!rf(t)||typeof e=="number"&&e>0&&t.length!==e?me("Uint8Array expected"):t,bn=t=>new Uint8Array(t),xo=t=>Uint8Array.from(t),Mi=(t,e)=>t.toString(16).padStart(e,"0"),Eo=t=>Array.from(St(t)).map(e=>Mi(e,2)).join(""),Me={_0:48,_9:57,A:65,F:70,a:97,f:102},Ci=t=>{if(t>=Me._0&&t<=Me._9)return t-Me._0;if(t>=Me.A&&t<=Me.F)return t-(Me.A-10);if(t>=Me.a&&t<=Me.f)return t-(Me.a-10)},Bo=t=>{let e="hex invalid";if(!Ni(t))return me(e);let n=t.length,o=n/2;if(n%2)return me(e);let r=bn(o);for(let i=0,s=0;i<o;i++,s+=2){let a=Ci(t.charCodeAt(s)),c=Ci(t.charCodeAt(s+1));if(a===void 0||c===void 0)return me(e);r[i]=a*16+c}return r},pn=(t,e)=>St(Ni(t)?Bo(t):xo(St(t)),e),Li=()=>globalThis?.crypto,sf=()=>Li()?.subtle??me("crypto.subtle must be defined"),bo=(...t)=>{let e=bn(t.reduce((o,r)=>o+St(r).length,0)),n=0;return t.forEach(o=>{e.set(o,n),n+=o.length}),e},af=(t=Vt)=>Li().getRandomValues(bn(t)),mn=BigInt,dt=(t,e,n,o="bad number: out of range")=>of(t)&&e<=t&&t<n?t:me(o),T=(t,e=ne)=>{let n=t%e;return n>=0n?n:e+n},cf=t=>T(t,ln),Oi=(t,e)=>{(t===0n||e<=0n)&&me("no inverse n="+t+" mod="+e);let n=T(t,e),o=e,r=0n,i=1n,s=1n,a=0n;for(;n!==0n;){let c=o/n,f=o%n,u=r-s*c,d=i-a*c;o=n,n=f,r=s,i=a,s=u,a=d}return o===1n?T(r,e):me("no inverse")};var Ri=t=>t instanceof Le?t:me("Point expected"),yo=2n**256n,Le=class t{static BASE;static ZERO;ex;ey;ez;et;constructor(e,n,o,r){let i=yo;this.ex=dt(e,0n,i),this.ey=dt(n,0n,i),this.ez=dt(o,1n,i),this.et=dt(r,0n,i),Object.freeze(this)}static fromAffine(e){return new t(e.x,e.y,1n,T(e.x*e.y))}static fromBytes(e,n=!1){let o=mo,r=xo(St(e,Vt)),i=e[31];r[31]=i&-129;let s=vo(r);dt(s,0n,n?yo:ne);let c=T(s*s),f=T(c-1n),u=T(o*c+1n),{isValid:d,value:h}=df(f,u);d||me("bad point: y not sqrt");let l=(h&1n)===1n,m=(i&128)!==0;return!n&&h===0n&&m&&me("bad point: x==0, isLastByteOdd"),m!==l&&(h=T(-h)),new t(h,s,1n,T(h*s))}assertValidity(){let e=po,n=mo,o=this;if(o.is0())throw new Error("bad point: ZERO");let{ex:r,ey:i,ez:s,et:a}=o,c=T(r*r),f=T(i*i),u=T(s*s),d=T(u*u),h=T(c*e),l=T(u*T(h+f)),m=T(d+T(n*T(c*f)));if(l!==m)throw new Error("bad point: equation left != right (1)");let p=T(r*i),w=T(s*a);if(p!==w)throw new Error("bad point: equation left != right (2)");return this}equals(e){let{ex:n,ey:o,ez:r}=this,{ex:i,ey:s,ez:a}=Ri(e),c=T(n*a),f=T(i*r),u=T(o*a),d=T(s*r);return c===f&&u===d}is0(){return this.equals(kt)}negate(){return new t(T(-this.ex),this.ey,this.ez,T(-this.et))}double(){let{ex:e,ey:n,ez:o}=this,r=po,i=T(e*e),s=T(n*n),a=T(2n*T(o*o)),c=T(r*i),f=e+n,u=T(T(f*f)-i-s),d=c+s,h=d-a,l=c-s,m=T(u*h),p=T(d*l),w=T(u*l),b=T(h*d);return new t(m,p,b,w)}add(e){let{ex:n,ey:o,ez:r,et:i}=this,{ex:s,ey:a,ez:c,et:f}=Ri(e),u=po,d=mo,h=T(n*s),l=T(o*a),m=T(i*d*f),p=T(r*c),w=T((n+o)*(s+a)-h-l),b=T(p-m),k=T(p+m),v=T(l-u*h),O=T(w*b),z=T(k*v),S=T(w*v),U=T(b*k);return new t(O,z,U,S)}multiply(e,n=!0){if(!n&&(e===0n||this.is0()))return kt;if(dt(e,1n,ln),e===1n)return this;if(this.equals(Tt))return yf(e).p;let o=kt,r=Tt;for(let i=this;e>0n;i=i.double(),e>>=1n)e&1n?o=o.add(i):n&&(r=r.add(i));return o}toAffine(){let{ex:e,ey:n,ez:o}=this;if(this.equals(kt))return{x:0n,y:1n};let r=Oi(o,ne);return T(o*r)!==1n&&me("invalid inverse"),{x:T(e*r),y:T(n*r)}}toBytes(){let{x:e,y:n}=this.assertValidity().toAffine(),o=ff(n);return o[31]|=e&1n?128:0,o}toHex(){return Eo(this.toBytes())}clearCofactor(){return this.multiply(mn(nf),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.multiply(ln/2n,!1).double();return ln%2n&&(e=e.add(this)),e.is0()}static fromHex(e,n){return t.fromBytes(pn(e),n)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(){return this.toBytes()}},Tt=new Le(Ti,Hi,1n,T(Ti*Hi)),kt=new Le(0n,1n,1n,0n);Le.BASE=Tt;Le.ZERO=kt;var ff=t=>Bo(Mi(dt(t,0n,yo),go)).reverse(),vo=t=>mn("0x"+Eo(xo(St(t)).reverse())),Ie=(t,e)=>{let n=t;for(;e-- >0n;)n*=n,n%=ne;return n},uf=t=>{let n=t*t%ne*t%ne,o=Ie(n,2n)*n%ne,r=Ie(o,1n)*t%ne,i=Ie(r,5n)*r%ne,s=Ie(i,10n)*i%ne,a=Ie(s,20n)*s%ne,c=Ie(a,40n)*a%ne,f=Ie(c,80n)*c%ne,u=Ie(f,80n)*c%ne,d=Ie(u,10n)*i%ne;return{pow_p_5_8:Ie(d,2n)*t%ne,b2:n}},$i=0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n,df=(t,e)=>{let n=T(e*e*e),o=T(n*n*e),r=uf(t*o).pow_p_5_8,i=T(t*n*r),s=T(e*i*i),a=i,c=T(i*$i),f=s===t,u=s===T(-t),d=s===T(-t*$i);return f&&(i=a),(u||d)&&(i=c),(T(i)&1n)===1n&&(i=T(-i)),{isValid:f||u,value:i}},hf=t=>cf(vo(t)),lf=(...t)=>yn.sha512Async(...t);var pf=t=>lf(t.hashable).then(t.finish);var Fi={zip215:!0},mf=(t,e,n,o=Fi)=>{t=pn(t,go),e=pn(e),n=pn(n,Vt);let{zip215:r}=o,i,s,a,c,f=Uint8Array.of();try{i=Le.fromHex(n,r),s=Le.fromHex(t.slice(0,Vt),r),a=vo(t.slice(Vt,go)),c=Tt.multiply(a,!1),f=bo(s.toBytes(),i.toBytes(),e)}catch{}return{hashable:f,finish:d=>{if(c==null||!r&&i.isSmallOrder())return!1;let h=hf(d);return s.add(i.multiply(h,!1)).add(c.negate()).clearCofactor().is0()}}},Ao=async(t,e,n,o=Fi)=>pf(mf(t,e,n,o));var yn={sha512Async:async(...t)=>{let e=sf(),n=bo(...t);return bn(await e.digest("SHA-512",n.buffer))},sha512Sync:void 0,bytesToHex:Eo,hexToBytes:Bo,concatBytes:bo,mod:T,invert:Oi,randomBytes:af};var gn=8,gf=256,Ui=Math.ceil(gf/gn)+1,wo=2**(gn-1),bf=()=>{let t=[],e=Tt,n=e;for(let o=0;o<Ui;o++){n=e,t.push(n);for(let r=1;r<wo;r++)n=n.add(e),t.push(n);e=n.double()}return t},Pi,Di=(t,e)=>{let n=e.negate();return t?n:e},yf=t=>{let e=Pi||(Pi=bf()),n=kt,o=Tt,r=2**gn,i=r,s=mn(r-1),a=mn(gn);for(let c=0;c<Ui;c++){let f=Number(t&s);t>>=a,f>wo&&(f-=i,t+=1n);let u=c*wo,d=u,h=u+Math.abs(f)-1,l=c%2!==0,m=f<0;f===0?o=o.add(Di(l,e[d])):n=n.add(Di(m,e[h]))}return{p:n,f:o}};y();y();y();function xf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Io(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ht(t,...e){if(!xf(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Ct(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 wn(t,e){ht(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function _i(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ke(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function xn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function we(t,e){return t<<32-e|t>>>e}var Ef=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Bf(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function vf(t){for(let e=0;e<t.length;e++)t[e]=Bf(t[e]);return t}var ko=Ef?t=>t:vf;function Af(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function zt(t){return typeof t=="string"&&(t=Af(t)),ht(t),t}var Ht=class{};function qt(t){let e=o=>t().update(zt(o)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function If(t,e,n,o){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,o);let r=BigInt(32),i=BigInt(4294967295),s=Number(n>>r&i),a=Number(n&i),c=o?4:0,f=o?0:4;t.setUint32(e+c,s,o),t.setUint32(e+f,a,o)}function ji(t,e,n){return t&e^~t&n}function Ki(t,e,n){return t&e^t&n^e&n}var Gt=class extends Ht{constructor(e,n,o,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=o,this.isLE=r,this.buffer=new Uint8Array(e),this.view=xn(this.buffer)}update(e){Ct(this),e=zt(e),ht(e);let{view:n,buffer:o,blockLen:r}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(r-this.pos,i-s);if(a===r){let c=xn(e);for(;r<=i-s;s+=r)this.process(c,s);continue}o.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ct(this),wn(e,this),this.finished=!0;let{buffer:n,view:o,blockLen:r,isLE:i}=this,{pos:s}=this;n[s++]=128,ke(this.buffer.subarray(s)),this.padOffset>r-s&&(this.process(o,0),s=0);for(let d=s;d<r;d++)n[d]=0;If(o,r-8,BigInt(this.length*8),i),this.process(o,0);let a=xn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],i)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let o=e.slice(0,n);return this.destroy(),o}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:o,length:r,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=r,e.pos=a,r%n&&e.buffer.set(o),e}clone(){return this._cloneInto()}},Oe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);y();var En=BigInt(4294967295),Vi=BigInt(32);function kf(t,e=!1){return e?{h:Number(t&En),l:Number(t>>Vi&En)}:{h:Number(t>>Vi&En)|0,l:Number(t&En)|0}}function Bn(t,e=!1){let n=t.length,o=new Uint32Array(n),r=new Uint32Array(n);for(let i=0;i<n;i++){let{h:s,l:a}=kf(t[i],e);[o[i],r[i]]=[s,a]}return[o,r]}var So=(t,e,n)=>t>>>n,To=(t,e,n)=>t<<32-n|e>>>n,lt=(t,e,n)=>t>>>n|e<<32-n,pt=(t,e,n)=>t<<32-n|e>>>n,Wt=(t,e,n)=>t<<64-n|e>>>n-32,Zt=(t,e,n)=>t>>>n-32|e<<64-n;var zi=(t,e,n)=>t<<n|e>>>32-n,qi=(t,e,n)=>e<<n|t>>>32-n,Gi=(t,e,n)=>e<<n-32|t>>>64-n,Wi=(t,e,n)=>t<<n-32|e>>>64-n;function Se(t,e,n,o){let r=(e>>>0)+(o>>>0);return{h:t+n+(r/2**32|0)|0,l:r|0}}var Zi=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Yi=(t,e,n,o)=>e+n+o+(t/2**32|0)|0,Xi=(t,e,n,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ji=(t,e,n,o,r)=>e+n+o+r+(t/2**32|0)|0,Qi=(t,e,n,o,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0)+(r>>>0),es=(t,e,n,o,r,i)=>e+n+o+r+i+(t/2**32|0)|0;var Tf=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]),Xe=new Uint32Array(64),vn=class extends Gt{constructor(e=32){super(64,e,8,!1),this.A=Oe[0]|0,this.B=Oe[1]|0,this.C=Oe[2]|0,this.D=Oe[3]|0,this.E=Oe[4]|0,this.F=Oe[5]|0,this.G=Oe[6]|0,this.H=Oe[7]|0}get(){let{A:e,B:n,C:o,D:r,E:i,F:s,G:a,H:c}=this;return[e,n,o,r,i,s,a,c]}set(e,n,o,r,i,s,a,c){this.A=e|0,this.B=n|0,this.C=o|0,this.D=r|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,n){for(let d=0;d<16;d++,n+=4)Xe[d]=e.getUint32(n,!1);for(let d=16;d<64;d++){let h=Xe[d-15],l=Xe[d-2],m=we(h,7)^we(h,18)^h>>>3,p=we(l,17)^we(l,19)^l>>>10;Xe[d]=p+Xe[d-7]+m+Xe[d-16]|0}let{A:o,B:r,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){let h=we(a,6)^we(a,11)^we(a,25),l=u+h+ji(a,c,f)+Tf[d]+Xe[d]|0,p=(we(o,2)^we(o,13)^we(o,22))+Ki(o,r,i)|0;u=f,f=c,c=a,a=s+l|0,s=i,i=r,r=o,o=l+p|0}o=o+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(o,r,i,s,a,c,f,u)}roundClean(){ke(Xe)}destroy(){this.set(0,0,0,0,0,0,0,0),ke(this.buffer)}};var ts=Bn(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Hf=ts[0],Cf=ts[1],Je=new Uint32Array(80),Qe=new Uint32Array(80),Ho=class extends Gt{constructor(e=64){super(128,e,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:e,Al:n,Bh:o,Bl:r,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:d,Fl:h,Gh:l,Gl:m,Hh:p,Hl:w}=this;return[e,n,o,r,i,s,a,c,f,u,d,h,l,m,p,w]}set(e,n,o,r,i,s,a,c,f,u,d,h,l,m,p,w){this.Ah=e|0,this.Al=n|0,this.Bh=o|0,this.Bl=r|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=d|0,this.Fl=h|0,this.Gh=l|0,this.Gl=m|0,this.Hh=p|0,this.Hl=w|0}process(e,n){for(let v=0;v<16;v++,n+=4)Je[v]=e.getUint32(n),Qe[v]=e.getUint32(n+=4);for(let v=16;v<80;v++){let O=Je[v-15]|0,z=Qe[v-15]|0,S=lt(O,z,1)^lt(O,z,8)^So(O,z,7),U=pt(O,z,1)^pt(O,z,8)^To(O,z,7),F=Je[v-2]|0,G=Qe[v-2]|0,q=lt(F,G,19)^Wt(F,G,61)^So(F,G,6),le=pt(F,G,19)^Zt(F,G,61)^To(F,G,6),N=Xi(U,le,Qe[v-7],Qe[v-16]),se=Ji(N,S,q,Je[v-7],Je[v-16]);Je[v]=se|0,Qe[v]=N|0}let{Ah:o,Al:r,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:d,El:h,Fh:l,Fl:m,Gh:p,Gl:w,Hh:b,Hl:k}=this;for(let v=0;v<80;v++){let O=lt(d,h,14)^lt(d,h,18)^Wt(d,h,41),z=pt(d,h,14)^pt(d,h,18)^Zt(d,h,41),S=d&l^~d&p,U=h&m^~h&w,F=Qi(k,z,U,Cf[v],Qe[v]),G=es(F,b,O,S,Hf[v],Je[v]),q=F|0,le=lt(o,r,28)^Wt(o,r,34)^Wt(o,r,39),N=pt(o,r,28)^Zt(o,r,34)^Zt(o,r,39),se=o&i^o&a^i&a,oe=r&s^r&c^s&c;b=p|0,k=w|0,p=l|0,w=m|0,l=d|0,m=h|0,{h:d,l:h}=Se(f|0,u|0,G|0,q|0),f=a|0,u=c|0,a=i|0,c=s|0,i=o|0,s=r|0;let L=Zi(q,N,oe);o=Yi(L,G,le,se),r=L|0}({h:o,l:r}=Se(this.Ah|0,this.Al|0,o|0,r|0)),{h:i,l:s}=Se(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Se(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Se(this.Dh|0,this.Dl|0,f|0,u|0),{h:d,l:h}=Se(this.Eh|0,this.El|0,d|0,h|0),{h:l,l:m}=Se(this.Fh|0,this.Fl|0,l|0,m|0),{h:p,l:w}=Se(this.Gh|0,this.Gl|0,p|0,w|0),{h:b,l:k}=Se(this.Hh|0,this.Hl|0,b|0,k|0),this.set(o,r,i,s,a,c,f,u,d,h,l,m,p,w,b,k)}roundClean(){ke(Je,Qe)}destroy(){ke(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ns=qt(()=>new vn);var An=qt(()=>new Ho);y();y();y();function fe(t){return()=>{throw new Error(`${t} is not available in the browser verifier`)}}var os=fe("fs.createReadStream"),dl=fe("fs.readFileSync"),hl=fe("fs.existsSync"),ll=fe("fs.writeFileSync"),Rf=fe("fs.open"),$f=fe("fs.readdir"),rs=fe("fs.readFile"),Pf=fe("fs.stat"),pl=fe("fs.mkdir"),ml=fe("fs.writeFile"),is=fe("path.join"),gl=fe("path.basename"),ss=fe("zlib.createGunzip"),Df=fe("zlib.gzipSync");y();var _=ns;y();y();y();y();y();y();y();var Nf=t=>t/2**32|0,Mf=t=>t>>>0;function as(t,e,n,o){let r=Nf(n),i=Mf(n);t.setUint32(e,o?i:r,o),t.setUint32(e+4,o?r:i,o)}y();function In(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Co=t=>t?`"${t}" `:"";function Fe(t,e=""){if(typeof t!="number")throw new TypeError(Co(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Co(e)+"expected integer >= 0, got "+t);return t}function Te(t,e,n=""){if(In(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Fe(e,"length");let o=In(t),r=e!==void 0?` of length ${e}`:"",i=o?`length=${t.length}`:`type=${typeof t}`,s=Co(n)+"expected Uint8Array"+r+", got "+i;throw o?new RangeError(s):new TypeError(s)}function kn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Fe(t.outputLen),Fe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var cs=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Rt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Sn(t,e){Te(t,void 0,"output");let n=e.outputLen;if(!(t.length>=n))throw new RangeError('"output" expected length >= '+n)}function Yt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Tn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function xe(t,e){return t<<32-e|t>>>e}var us=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Hn(t){if(Te(t),us)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=Lf[t[n]];return e}function fs(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Ro(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(us)try{return Uint8Array.fromHex(t)}catch(r){throw r instanceof SyntaxError?new RangeError(r.message):r}let e=t.length,n=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let o=new Uint8Array(n);for(let r=0,i=0;r<n;r++,i+=2){let s=fs(t.charCodeAt(i)),a=fs(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}o[r]=s*16+a}return o}function ds(...t){let e=0;for(let o=0;o<t.length;o++){let r=t[o];Te(r),e+=r.length}let n=new Uint8Array(e);for(let o=0,r=0;o<t.length;o++){let i=t[o];n.set(i,r),r+=i.length}return n}function Of(t,e,n="opts"){return cs(t,"defaults"),e!==void 0&&cs(e,n),Object.assign(t,e)}function hs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Of({},e,"info");let n=(r,i)=>t(i).update(r).digest(),o=t(void 0);return n.outputLen=o.outputLen,n.blockLen=o.blockLen,n.canXOF=o.canXOF,n.create=r=>t(r),Object.assign(n,e),Object.freeze(n)}function ls(t=32){Fe(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 ps=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ms(t,e,n){return t&e^~t&n}function gs(t,e,n){return t&e^t&n^e&n}var Cn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,n,o,r){this.blockLen=e,this.outputLen=n,this.padOffset=o,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Tn(this.buffer)}update(e){Rt(this),Te(e);let{view:n,buffer:o,blockLen:r}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(r-this.pos,i-a);if(c===r){let f=Tn(e);for(;r<=i-a;a+=r)this.process(f,a);s=!0;continue}o.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===r&&(this.process(n,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){Rt(this),Sn(e,this),this.finished=!0;let{buffer:n,view:o,blockLen:r,isLE:i}=this,{pos:s}=this;n[s++]=128,n.fill(0,s),this.padOffset>r-s&&(this.process(o,0),n.fill(0)),as(o,r-8,this.length*8,i),this.process(o,0),this.roundClean();let a=e===n?o:Tn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],i)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let o=e.slice(0,n);return this.destroy(),o}_cloneIntoMeta(e){let{buffer:n,length:o,finished:r,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=r,e.length=o,e.pos=s,s&&e.buffer.set(n),e}clone(){return this._cloneInto()}},bs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ff=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]),et=new Uint32Array(64),$o=class extends Cn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,n){super(64,e,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:e,B:n,C:o,D:r,E:i,F:s,G:a,H:c}=this;return[e,n,o,r,i,s,a,c]}set(e,n,o,r,i,s,a,c){this.A=e|0,this.B=n|0,this.C=o|0,this.D=r|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,n){for(let d=0;d<16;d++,n+=4)et[d]=e.getUint32(n,!1);for(let d=16;d<64;d++){let h=et[d-15],l=et[d-2],m=xe(h,7)^xe(h,18)^h>>>3,p=xe(l,17)^xe(l,19)^l>>>10;et[d]=p+et[d-7]+m+et[d-16]|0}let{A:o,B:r,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){let h=xe(a,6)^xe(a,11)^xe(a,25),l=u+h+ms(a,c,f)+Ff[d]+et[d]|0,p=(xe(o,2)^xe(o,13)^xe(o,22))+gs(o,r,i)|0;u=f,f=c,c=a,a=s+l|0,s=i,i=r,r=o,o=l+p|0}o=o+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(o,r,i,s,a,c,f,u)}roundClean(){Yt(et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Yt(this.buffer)}},Po=class extends $o{constructor(){super(32,bs)}};var ys=hs(()=>new Po,ps(1));y();function $n(t,e,n=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let o=0;o<t.length;o++)n(t[o],`${e}[${o}]`);return t}var X=(t,e,n)=>Te(t,e,n),Do=Fe;function xs(t,e=""){if(typeof t!="string"){let n=e&&`"${e}" `;throw new TypeError(n+"expected string, got type="+typeof t)}return t}function tt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function mt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var No=Hn,Ue=(...t)=>ds(...t),Pn=t=>Ro(t),$t=In,Dn=t=>ls(t),Rn=BigInt(0),ws=BigInt(1),Uf=t=>t?`"${t}" `:"";function He(t,e=""){if(typeof t!="boolean")throw new TypeError(Uf(e)+"expected boolean, got type="+typeof t);return t}function Nn(t){if(typeof t=="bigint"){if(!nt(t))throw new RangeError("positive bigint expected, got "+t)}else Do(t);return t}function Pt(t,e=""){if(typeof t!="number"){let n=e&&`"${e}" `;throw new TypeError(n+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let n=e&&`"${e}" `;throw new RangeError(n+"expected safe integer, got "+t)}}function Xt(t){let e=Nn(t).toString(16);return e.length&1?"0"+e:e}function Es(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Rn:BigInt("0x"+t)}function Ce(t){return Es(Hn(t))}function Mo(t){return Es(Hn(_f(Te(t)).reverse()))}function Mn(t,e){if(Fe(e),e===0)throw new Error("zero output length is invalid");t=Nn(t);let n=e*2,o=t.toString(16);if(o.length>n)throw new RangeError("number is too large");return Ro(o.padStart(n,"0"))}function Lo(t,e){return Mn(t,e).reverse()}function _f(t){return Uint8Array.from(X(t))}function nt(t){return typeof t=="bigint"&&Rn<=t}function Oo(t,e,n){return nt(t)&&nt(e)&&nt(n)&&e<=t&&t<n}function Fo(t,e,n,o){if(!Oo(e,n,o))throw new RangeError("expected valid "+t+": "+n+" <= n < "+o+", got "+e)}function Dt(t){if(t<Rn)throw new Error("expected non-negative bigint, got "+t);return t===Rn?0:t.toString(2).length}var Jt=t=>(Pt(t,"n"),(ws<<BigInt(t))-ws);function Bs(t,e,n){if(Fe(t,"hashLen"),Fe(e,"qByteLen"),typeof n!="function")throw new TypeError("hmacFn must be a function");let o=w=>new Uint8Array(w),r=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=o(t),f=o(t),u=0,d=()=>{c.fill(1),f.fill(0),u=0},h=(...w)=>n(f,Ue(c,...w)),l=(w=r)=>{f=h(i,w),c=h(),w.length!==0&&(f=h(s,w),c=h())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,b=[];for(;w<e;){c=h();let k=c.slice();b.push(k),w+=c.length}return Ue(...b)};return(w,b)=>{d(),l(w);let k;for(;(k=b(m()))===void 0;)l();return d(),k}}function ot(t,e={},n={},o="object"){tt(t,o),tt(e,"fields"),tt(n,"optFields");function r(s,a,c){let f=o==="object"?`param "${String(s)}"`:`"${o}.${String(s)}"`,u=t[s];if(!Object.hasOwn(t,s)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let d=typeof u;if(d!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${d}`)}let i=(s,a)=>Object.entries(s).forEach(([c,f])=>r(c,f,a));i(e,!1),i(n,!0)}y();y();var ee=BigInt(0),V=BigInt(1),rt=BigInt(2),ks=BigInt(3),Uo=BigInt(4),Ss=BigInt(5),jf=BigInt(7),Ts=BigInt(8),Kf=BigInt(9),Vf=BigInt(15),Hs=BigInt(16),zf=BigInt("0x10000000000000000");function de(t,e){if(e<=ee)throw new Error("mod: expected positive modulus, got "+e);let n=t%e;return n>=ee?n:e+n}function Cs(t,e,n){if(n<=V)throw new Error("pow: expected modulus > 1, got "+n);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ee)throw new Error("invalid exponent, negatives unsupported");if(e===ee)return V;if(e===V)return t;let o=t%n;if(o<ee&&(o+=n),e<zf){let a=V;for(;e>ee;)e&V&&(a=a*o%n),o=o*o%n,e>>=V;return a}let r=[];for(;e>ee;)r.push(Number(e&Vf)),e>>=Uo;let i=new Array(16);i[0]=V,i[1]=o;for(let a=2;a<16;a++)i[a]=i[a-1]*o%n;let s=i[r[r.length-1]];for(let a=r.length-2;a>=0;a--){s=s*s%n,s=s*s%n,s=s*s%n,s=s*s%n;let c=r[a];c!==0&&(s=s*i[c]%n)}return s}function vs(t,e){if(t===ee)throw new Error("invert: expected non-zero number");if(e<=V)throw new Error("invert: expected modulus > 1, got "+e);let n=de(t,e),o=e,r=ee,i=V;for(;n!==ee;){let a=o/n,c=o-n*a,f=r-i*a;o=n,n=c,r=i,i=f}if(o!==V)throw new Error("invert: does not exist");return de(r,e)}function Rs(t,e){if(e<=V)throw new Error("invertCt: expected prime modulus > 1, got "+e);let n=de(t,e);if(n===ee)throw new Error("invertCt: expected non-zero number");let o=Cs(n,e-rt,e);if(de(n*o,e)!==V)throw new Error("invertCt: does not exist");return o}function _o(t,e,n){let o=t;if(!o.eql(o.sqr(e),n))throw new Error("Cannot find square root")}function jo(t,e){if((t&V)===ee)throw new Error(e+": expected odd modulus, got "+t)}function $s(t,e){let n=t,o=(n.ORDER+V)/Uo,r=n.pow(e,o);return _o(n,r,e),r}function qf(t,e){let n=t,o=(n.ORDER-Ss)/Ts,r=n.mul(e,rt),i=n.pow(r,o),s=n.mul(e,i),a=n.mul(n.mul(s,rt),i),c=n.mul(s,n.sub(a,n.ONE));return _o(n,c,e),c}function Gf(t){let e=On(t),n=Ps(t),o=n(e,e.neg(e.ONE)),r=n(e,o),i=n(e,e.neg(o)),s=(t+jf)/Hs;return((a,c)=>{let f=a,u=f.pow(c,s),d=f.mul(u,o),h=f.mul(u,r),l=f.mul(u,i),m=f.eql(f.sqr(d),c),p=f.eql(f.sqr(h),c);u=f.cmov(u,d,m),d=f.cmov(l,h,p);let w=f.eql(f.sqr(d),c),b=f.cmov(u,d,w);return _o(f,b,c),b})}function Ps(t){if(t<ks)throw new Error("sqrt is not defined for small field");jo(t,"tonelliShanks");let e=t-V,n=0;for(;e%rt===ee;)e/=rt,n++;let o=rt,r=On(t);for(;As(r,o)===1;)if(o++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return $s;let i=r.pow(o,e),s=(e+V)/rt;return function(c,f){let u=c;if(u.is0(f))return f;if(As(u,f)!==1)throw new Error("Cannot find square root");let d=n,h=u.mul(u.ONE,i),l=u.pow(f,e),m=u.pow(f,s);for(;!u.eql(l,u.ONE);){if(u.is0(l))throw new Error("Cannot find square root: probably non-prime P");let p=1,w=u.sqr(l);for(;!u.eql(w,u.ONE);)if(p++,w=u.sqr(w),p===d)throw new Error("Cannot find square root");let b=V<<BigInt(d-p-1),k=u.pow(h,b);d=p,h=u.sqr(k),l=u.mul(l,h),m=u.mul(m,k)}return m}}function Wf(t){return jo(t,"Fp.sqrt"),t%Uo===ks?$s:t%Ts===Ss?qf:t%Hs===Kf?Gf(t):Ps(t)}var Zf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Nt(t){if(tt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Pt(t.BYTES,"BYTES"),Pt(t.BITS,"BITS");for(let e of Zf)mt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Ko(t,e,n=!1){Nt(t),$n(e,"nums"),He(n,"passZero");let o=t,r=new Array(e.length).fill(n?o.ZERO:void 0),i=e.reduce((a,c,f)=>o.is0(c)?a:(r[f]=a,o.mul(a,c)),o.ONE),s=o.inv(i);return e.reduceRight((a,c,f)=>o.is0(c)?a:(r[f]=o.mul(a,r[f]),o.mul(a,c)),s),r}function As(t,e){Nt(t);let n=t;jo(n.ORDER,"FpLegendre");let o=(n.ORDER-V)/rt,r=n.pow(e,o),i=n.eql(r,n.ONE),s=n.eql(r,n.ZERO),a=n.eql(r,n.neg(n.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Yf(t,e){if(e!==void 0&&Do(e),t<=ee)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 n=Dt(t);if(e!==void 0&&e<n)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${n})`);let o=e!==void 0?e:n,r=Math.ceil(o/8);return{nBitLength:o,nByteLength:r}}var Is=new WeakMap,Ln=class{ORDER;BITS;BYTES;isLE;ZERO=ee;ONE=V;_lengths;_mod;constructor(e,n={}){if(e<=V)throw new Error("invalid field: expected ORDER > 1, got "+e);let o;this.isLE=!1,n!=null&&typeof n=="object"&&(typeof n.BITS=="number"&&(o=n.BITS),typeof n.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:n.sqrt,enumerable:!0}),typeof n.isLE=="boolean"&&(this.isLE=n.isLE),n.allowedLengths&&(this._lengths=Object.freeze(n.allowedLengths.slice())),typeof n.modFromBytes=="boolean"&&(this._mod=n.modFromBytes));let{nBitLength:r,nByteLength:i}=Yf(e,o);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return de(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ee<=e&&e<this.ORDER}is0(e){return e===ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&V)===V}neg(e){return de(-e,this.ORDER)}eql(e,n){return e===n}sqr(e){return de(e*e,this.ORDER)}add(e,n){return de(e+n,this.ORDER)}sub(e,n){return de(e-n,this.ORDER)}mul(e,n){return de(e*n,this.ORDER)}pow(e,n){return Cs(e,n,this.ORDER)}div(e,n){return de(e*vs(n,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,n){return e+n}subN(e,n){return e-n}mulN(e,n){return e*n}inv(e){return vs(e,this.ORDER)}sqrt(e){let n=Is.get(this);return n||Is.set(this,n=Wf(this.ORDER)),n(this,e)}toBytes(e){return this.isLE?Lo(e,this.BYTES):Mn(e,this.BYTES)}fromBytes(e,n=!1){X(e);let{_lengths:o,BYTES:r,isLE:i,ORDER:s,_mod:a}=this;if(o){if(e.length<1||!o.includes(e.length)||e.length>r)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let f=new Uint8Array(r);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let c=i?Mo(e):Ce(e);if(a&&(c=de(c,s)),!n&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Ko(this,e,!0)}cmov(e,n,o){return He(o,"condition"),o?n:e}};function On(t,e={}){return Object.freeze(Ln.prototype),new Ln(t,e)}function Ds(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=V)throw new Error("field order must be greater than 1");let e=Dt(t-V);return Math.ceil(e/8)}function Fn(t){let e=Ds(t);return e+Math.ceil(e/2)}function Vo(t,e,n=!1){X(t);let o=t.length,r=Ds(e),i=Math.max(Fn(e),16);if(o<i||o>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+o);let s=n?Mo(t):Ce(t),a=de(s,e-V)+V;return n?Lo(a,r):Mn(a,r)}var Go=BigInt(0),Qt=BigInt(1),Xf=BigInt(4),zo=16,Ns=128,Jf=5,Ms=2**31;function Mt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);mt(e.fromAffine,"Point.fromAffine"),mt(e.fromBytes,"Point.fromBytes"),mt(e.fromHex,"Point.fromHex"),tt(e.BASE,"Point.BASE"),tt(e.ZERO,"Point.ZERO"),Nt(e.Fp),Nt(e.Fn)}function Os(t,e){Mt(t),Fs(e,t);let n=Ko(t.Fp,e.map(o=>o.Z));return e.map((o,r)=>t.fromAffine(o.toAffine(n[r])))}function Qf(t,e,n=1){if(!Number.isSafeInteger(t)||t<n||t>e)throw new Error("invalid window size, expected ["+n+".."+e+"], got W="+t)}function eu(t,e){let n=t*(4*e+128);if(n>Ms)throw new Error("invalid window size: table would need ~"+Math.ceil(n/2**20)+" MiB, max "+Ms/2**20+" MiB")}function Wo(t,e){if(t!==void 0){mt(t,"randomBytes");try{let n=t(e);if(!$t(n)||n.length!==e)return}catch{return}return t}}function Fs(t,e){$n(t,"points"),t.forEach((n,o)=>{if(!(n instanceof e))throw new Error("invalid point at index "+o)})}function tu(t,e,n){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((o,r)=>{if(!(n===void 0?e.isValid(o):nt(o)&&o<n))throw new Error("invalid scalar at index "+r)})}var Us=new WeakMap;function qo(t){return Us.get(t)||1}function nu(t,e){let n=t.double(),o=[t];for(let r=1;r<e;r++)o.push(o[r-1].add(n));return o}function ou(t,e){let n=2**e,o=n/2,r=BigInt(n-1),i=[];for(;t>Go;){let s=0;t&Qt&&(s=Number(t&r),s>=o&&(s-=n),t-=BigInt(s)),i.push(s),t>>=Qt}return i}function ru(t,e,n){let o=2**e,r=o/2,i=BigInt(o-1),s=BigInt(e),a=[];for(let c=0;c<n;c++){let f=Number(t&i);t>>=s,f>r&&(f-=o,t+=Qt),a.push(f)}if(t!==Go)throw new Error("invalid wnaf");return a}function iu(t,e,n){let o=0;for(let i of n)o=Math.max(o,i.length);let r=t;for(let i=o-1;i>=0;i--){i!==o-1&&(r=r.double());for(let s=0;s<n.length;s++){let a=n[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];r=r.add(a<0?c.negate():c)}}}return r}var Un=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,n){Mt(e),this.randomBytes=Wo(n,zo),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,n,o){let r=Math.ceil(o/n)+1,i=2**(n-1),s=[],a=e;for(let c=0;c<r;c++){let f=a;for(let u=0;u<i;u++)s.push(f),f=f.add(a);a=s[s.length-1].double()}return{W:n,bits:o,windows:r,comp:s}}wnafCachedCT(e,n){let{W:o,windows:r,comp:i}=e,s=2**(o-1),a=ru(n,o,r),c=this.ZERO,f=this.BASE;for(let u=0;u<r;u++){let d=a[u],h=u*s,l=Math.abs(d)-1,m=i[h];for(let w=1;w<s;w++)m=w===l?i[h+w]:m;let p=m.negate();d===0?f=f.add(i[h]):c=c.add(d<0?p:m)}return{p:c,f}}getWnafPrecomputes(e,n,o,r){let i=this.wnafPrecomputes.get(n),s=i?.find(a=>a.W===e&&a.bits===o);return s||(s=this.buildWnafTable(n,e,o),typeof r=="function"&&(s={...s,comp:r(s.comp)}),i||(i=[],this.wnafPrecomputes.set(n,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,n){if(this.assertPoint(e),!Oo(n,Qt,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,n,o,r){let i=qo(e);return i===1?this.fixedWindowCT(e,n,o):this.wnafCachedCT(this.getWnafPrecomputes(i,e,o,r),n)}mulCT(e,n,o){return this.validateMulInput(e,n),this.runCT(e,n,this.bits,o)}mulCTBlinded(e,n,o){if(this.validateMulInput(e,n),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let r=this.Point.Fn.BITS+Ns,i=this.randomBytes(zo);if(!$t(i)||i.length!==zo)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=n+Ce(i)*this.Point.Fn.ORDER;return this.runCT(e,s,r,o)}fixedWindowCT(e,n,o){let r=Jf,i=1<<r,s=Jt(r),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(e);let c=Math.ceil(o/r),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let l=0;l<r;l++)f=f.double();let d=Number(n>>BigInt(u*r)&s),h=a[0];for(let l=1;l<i;l++)h=l===d?a[l]:h;f=f.add(h)}return{p:f,f}}shouldBlind(e,n){return this.randomBytes===void 0?!1:n===Qt?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,n,o,r){return this.shouldBlind(e,o)?this.mulCTBlinded(e,n,r):this.mulCT(e,n,r)}mulUnsafe(e,n,o){if(this.assertPoint(e),!nt(n))throw new Error("invalid scalar");let r=qo(e);if(r===1||n>=this.Point.Fn.ORDER)return _n(this.Point,[e],[n],!0);let i=this.getWnafPrecomputes(r,e,this.bits,o);return this.wnafCachedCT(i,n).p}setWindowSize(e,n){this.assertPoint(e),Qf(n,this.bits);let o=Math.ceil((this.bits+Ns)/n)+1;eu(o*2**(n-1),this.Point.Fp.BYTES),Us.set(e,n),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return qo(e)!==1}};function _n(t,e,n,o=!1){if(Mt(t),Fs(e,t),He(o,"allowOversized"),tu(n,t.Fn,o?t.Fn.ORDER**Xf:void 0),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let r=e.map(s=>nu(s,4)),i=n.map(s=>ou(s,4));return iu(t.ZERO,r,i)}function Ls(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Nt(e),e}else return On(t,{isLE:n})}function _s(t,e,n={},o){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(o===void 0&&(o=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);ot(n);for(let c of["p","n","h"]){let f=e[c];if(!(nt(f)&&f!==Go))throw new Error(`CURVE.${c} must be positive bigint`)}let r=Ls(e.p,n.Fp,o),i=Ls(e.n,n.Fn,o),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!r.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:r,Fn:i}}function js(t,e){return function(o){let r=t(o);return{secretKey:r,publicKey:e(r)}}}y();y();var jn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,n){if(kn(e),Te(n,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,r=new Uint8Array(o);r.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<r.length;i++)r[i]^=54;this.iHash.update(r),this.oHash=e.create();for(let i=0;i<r.length;i++)r[i]^=106;this.oHash.update(r),Yt(r)}update(e){return Rt(this),this.iHash.update(e),this}digestInto(e){Rt(this),Sn(e,this),this.finished=!0;let n=e.subarray(0,this.outputLen);this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:n,iHash:o,finished:r,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=n._cloneInto(e.oHash),e.iHash=o._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ks=(()=>{let t=((e,n,o)=>new jn(e,n).update(o).digest());return t.create=(e,n)=>new jn(e,n),t})();y();var su=BigInt(0),Zo=class extends Error{constructor(e=""){super(e)}},_e={Err:Zo,_tlv:{encode:(t,e)=>{let{Err:n}=_e;if(Pt(t,"tag"),t<0||t>255)throw new n("tlv.encode: wrong tag");if(xs(e,"data"),e.length&1)throw new n("tlv.encode: unpadded data");let o=e.length/2,r=Xt(o);if(r.length/2&128)throw new n("tlv.encode: long form length too big");let i=o>127?Xt(r.length/2|128):"";return Xt(t)+i+r+e},decode(t,e){let{Err:n}=_e;e=X(e,void 0,"DER data");let o=0;if(t<0||t>255)throw new n("tlv.decode: wrong tag");if(e.length<2||e[o++]!==t)throw new n("tlv.decode: wrong tlv");let r=e[o++],i=!!(r&128),s=0;if(!i)s=r;else{let c=r&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");let f=e.subarray(o,o+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(o+=c,s<128)throw new n("tlv.decode(long): not minimal encoding")}let a=e.subarray(o,o+s);if(a.length!==s)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(o+s)}}},_int:{encode(t){let{Err:e}=_e;if(Nn(t),t<su)throw new e("integer: negative integers are not allowed");let n=Xt(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){let{Err:e}=_e;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 Ce(t)}},toSig(t){let{Err:e,_int:n,_tlv:o}=_e,r=X(t,void 0,"signature"),{v:i,l:s}=o.decode(48,r);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=o.decode(2,i),{v:f,l:u}=o.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:n}=_e;ot(t,{r:"bigint",s:"bigint"},{},"sig");let o=e.encode(2,n.encode(t.r)),r=e.encode(2,n.encode(t.s)),i=o+r;return e.encode(48,i)}},Yo=(Object.freeze(_e._tlv),Object.freeze(_e._int),Object.freeze(_e));var Vs=(t,e)=>(t+(t>=0?e:-e)/zs)/e;function au(t,e,n){Fo("scalar",t,je,n);let[[o,r],[i,s]]=e,a=Vs(s*t,n),c=Vs(-r*t,n),f=t-a*o-c*i,u=-a*r-c*s,d=f<je,h=u<je;d&&(f=-f),h&&(u=-u);let l=Jt(Math.ceil(Dt(n)/2))+gt;if(f<je||f>=l||u<je||u>=l)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:h,k2:u}}function Qo(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Xo(t,e){ot(t);let n={};for(let o of Object.keys(e))n[o]=t[o]===void 0?e[o]:t[o];return He(n.lowS,"lowS"),He(n.prehash,"prehash"),n.format!==void 0&&Qo(n.format),n}var je=BigInt(0),gt=BigInt(1),zs=BigInt(2),Jo=BigInt(3),cu=BigInt(4);function qs(t,e={}){let n=_s("weierstrass",t,e),o=n.Fp,r=n.Fn,i=n.CURVE,{h:s,n:a}=i;ot(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,u=e.randomBytes===void 0?Dn:e.randomBytes;if(c&&(!o.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=Ws(o,r);function h(){if(!o.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,E,A){if(f&&E.is0())return Uint8Array.of(0);let{x:C,y:D}=E.toAffine(),I=o.toBytes(C);if(He(A,"isCompressed"),A){h();let x=!o.isOdd(D);return Ue(Gs(x),I)}else return Ue(Uint8Array.of(4),I,o.toBytes(D))}function m(L){X(L,void 0,"Point");let{publicKey:E,publicKeyUncompressed:A}=d,C=L.length,D=L[0],I=L.subarray(1);if(f&&C===1&&D===0)return{x:o.ZERO,y:o.ZERO};if(C===E&&(D===2||D===3)){let x=o.fromBytes(I);if(!o.isValid(x))throw new Error("bad point: is not on curve, wrong x");let H=v(x),R;try{R=o.sqrt(H)}catch(K){let j=K instanceof Error?": "+K.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}h();let M=o.isOdd(R);return(D&1)===1!==M&&(R=o.neg(R)),{x,y:R}}else if(C===A&&D===4){let x=o.BYTES,H=o.fromBytes(I.subarray(0,x)),R=o.fromBytes(I.subarray(x,x*2));if(!O(H,R))throw new Error("bad point: is not on curve");return{x:H,y:R}}else throw new Error(`bad point: got length ${C}, expected compressed=${E} or uncompressed=${A}`)}let p=e.toBytes===void 0?l:e.toBytes,w=e.fromBytes===void 0?m:e.fromBytes,b=o.mul(i.b,Jo),k=o.is0(i.a)?L=>o.ZERO:L=>o.mul(i.a,L);function v(L){let E=o.sqr(L),A=o.mul(E,L);return o.add(o.add(A,o.mul(L,i.a)),i.b)}function O(L,E){let A=o.sqr(E),C=v(L);return o.eql(A,C)}if(!O(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let z=o.mul(o.pow(i.a,Jo),cu),S=o.mul(o.sqr(i.b),BigInt(27));if(o.is0(o.add(z,S)))throw new Error("bad curve params: a or b");function U(L,E,A=!1){if(!o.isValid(E)||A&&o.is0(E))throw new Error(`bad point coordinate ${L}`);return E}function F(L){if(!(L instanceof N))throw new Error("Weierstrass Point expected")}function G(L){if(!c||!c.basises)throw new Error("no endo");return au(L,c.basises,r.ORDER)}function q(L,E,A,C){if(!r.isValid(C))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:D,k1:I,k2neg:x,k2:H}=G(C),R=new N(o.mul(A.X,c.beta),A.Y,A.Z);L.push(D?A.negate():A,x?R.negate():R),E.push(I,H)}else L.push(A),E.push(C)}let le=new WeakSet;class N{static BASE=new N(i.Gx,i.Gy,o.ONE);static ZERO=new N(o.ZERO,o.ONE,o.ZERO);static Fp=o;static Fn=r;X;Y;Z;constructor(E,A,C){this.X=U("x",E),this.Y=U("y",A,!0),this.Z=U("z",C),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){let{x:A,y:C}=E||{};if(!E||!o.isValid(A)||!o.isValid(C))throw new Error("invalid affine point");if(E instanceof N)throw new Error("projective point not allowed");return o.is0(A)&&o.is0(C)?N.ZERO:new N(A,C,o.ONE)}static fromBytes(E){let A=N.fromAffine(w(X(E,void 0,"point")));return A.assertValidity(),A}static fromHex(E){return N.fromBytes(Pn(E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=6,A=!0){return oe.setWindowSize(this,E),A||this.multiply(Jo),this}assertValidity(){let E=this;if(E.is0()){if(e.allowInfinityPoint&&o.is0(E.X)&&o.eql(E.Y,o.ONE)&&o.is0(E.Z))return;throw new Error("bad point: ZERO")}if(le.has(E))return;let{x:A,y:C}=E.toAffine();if(!o.isValid(A)||!o.isValid(C))throw new Error("bad point: x or y not field elements");if(!O(A,C))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");le.add(E)}hasEvenY(){let{y:E}=this.toAffine();if(!o.isOdd)throw new Error("Field doesn't support isOdd");return!o.isOdd(E)}equals(E){F(E);let{X:A,Y:C,Z:D}=this,{X:I,Y:x,Z:H}=E,R=o.eql(o.mul(A,H),o.mul(I,D)),M=o.eql(o.mul(C,H),o.mul(x,D));return R&&M}negate(){return new N(this.X,o.neg(this.Y),this.Z)}double(){let{X:E,Y:A,Z:C}=this,D=o.ZERO,I=o.ZERO,x=o.ZERO,H=o.mul(E,E),R=o.mul(A,A),M=o.mul(C,C),P=o.mul(E,A);return P=o.add(P,P),x=o.mul(E,C),x=o.add(x,x),D=k(x),I=o.mul(b,M),I=o.add(D,I),D=o.sub(R,I),I=o.add(R,I),I=o.mul(D,I),D=o.mul(P,D),x=o.mul(b,x),M=k(M),P=o.sub(H,M),P=k(P),P=o.add(P,x),x=o.add(H,H),H=o.add(x,H),H=o.add(H,M),H=o.mul(H,P),I=o.add(I,H),M=o.mul(A,C),M=o.add(M,M),H=o.mul(M,P),D=o.sub(D,H),x=o.mul(M,R),x=o.add(x,x),x=o.add(x,x),new N(D,I,x)}add(E){F(E);let{X:A,Y:C,Z:D}=this,{X:I,Y:x,Z:H}=E,R=o.ZERO,M=o.ZERO,P=o.ZERO,K=o.mul(A,I),j=o.mul(C,x),Z=o.mul(D,H),ae=o.add(A,C),W=o.add(I,x);ae=o.mul(ae,W),W=o.add(K,j),ae=o.sub(ae,W),W=o.add(A,D);let te=o.add(I,H);return W=o.mul(W,te),te=o.add(K,Z),W=o.sub(W,te),te=o.add(C,D),R=o.add(x,H),te=o.mul(te,R),R=o.add(j,Z),te=o.sub(te,R),P=k(W),R=o.mul(b,Z),P=o.add(R,P),R=o.sub(j,P),P=o.add(j,P),M=o.mul(R,P),j=o.add(K,K),j=o.add(j,K),Z=k(Z),W=o.mul(b,W),j=o.add(j,Z),Z=o.sub(K,Z),Z=k(Z),W=o.add(W,Z),K=o.mul(j,W),M=o.add(M,K),K=o.mul(te,W),R=o.mul(ae,R),R=o.sub(R,K),K=o.mul(ae,j),P=o.mul(te,P),P=o.add(P,K),new N(R,M,P)}subtract(E){return F(E),this.add(E.negate())}is0(){return this.equals(N.ZERO)}multiply(E){if(!r.isValidNot0(E))throw new RangeError("invalid scalar: out of range");let{p:A,f:C}=oe.mulSecret(this,E,s,se);return se([A,C])[0]}multiplyUnsafe(E){let A=this,C=E;if(!r.isValid(C))throw new RangeError("invalid scalar: out of range");if(C===je||A.is0())return N.ZERO;if(C===gt)return A;if(oe.hasWindowSize(this))return oe.mulUnsafe(A,C,se);let D=[],I=[];return q(D,I,A,C),_n(N,D,I)}mulAddUnsafe(E,A,C){F(A);let D=[],I=[];return q(D,I,this,E),q(D,I,A,C),_n(N,D,I)}toAffine(E){let A=this,C=E;if(C!=null&&!o.isValid(C))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:I,Z:x}=A;if(o.eql(x,o.ONE))return{x:D,y:I};let H=A.is0();C==null&&(C=H?o.ONE:o.inv(x));let R=o.mul(D,C),M=o.mul(I,C),P=o.mul(x,C);if(H)return{x:o.ZERO,y:o.ZERO};if(!o.eql(P,o.ONE))throw new Error("invZ was invalid");return{x:R,y:M}}isTorsionFree(){let{isTorsionFree:E}=e;return s===gt?!0:E?E(N,this):oe.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:E}=e;return s===gt?this:E?E(N,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===gt?this.is0():this.clearCofactor().is0()}toBytes(E=!0){return He(E,"isCompressed"),this.assertValidity(),p(N,this,E)}toHex(E=!0){return No(this.toBytes(E))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let se=L=>Os(N,L),oe=new Un(N,u);return oe.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function Gs(t){return Uint8Array.of(t?2:3)}function Ws(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function fu(t,e={}){Mt(t);let{Fn:n}=t,o=e.randomBytes===void 0?Dn:e.randomBytes,r=Object.assign(Ws(t.Fp,n),{seed:Math.max(Fn(n.ORDER),16)});function i(l){try{let m=n.fromBytes(l);return n.isValidNot0(m)}catch{return!1}}function s(l,m){let{publicKey:p,publicKeyUncompressed:w}=r;try{let b=l.length;return m===!0&&b!==p||m===!1&&b!==w?!1:!!t.fromBytes(l)}catch{return!1}}function a(l){return l=l===void 0?o(r.seed):l,Vo(X(l,r.seed,"seed"),n.ORDER)}function c(l,m=!0){return t.BASE.multiply(n.fromBytes(l)).toBytes(m)}function f(l){let{secretKey:m,publicKey:p,publicKeyUncompressed:w}=r,b=n._lengths;if(!$t(l))return;let k=X(l,void 0,"key").length,v=k===p||k===w,O=k===m||!!b?.includes(k);if(!(v&&O))return v}function u(l,m,p=!0){if(f(l)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let w=n.fromBytes(l);return t.fromBytes(m).multiply(w).toBytes(p)}let d={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=js(a,c);return Object.freeze(d),Object.freeze(r),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:t,utils:d,lengths:r})}function Zs(t,e,n={}){Mt(t);let o=e;kn(o),ot(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let r=Object.assign({},n),i=r.randomBytes===void 0?Dn:r.randomBytes,s=r.hmac===void 0?(I,x)=>Ks(o,I,x):r.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,d=Fn(f),h=Wo(i,d),{keygen:l,getPublicKey:m,getSharedSecret:p,utils:w,lengths:b}=fu(t,r),k={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},v=f*zs+gt<a.ORDER;function O(I){let x=f>>gt;return I>x}function z(I,x){if(!c.isValidNot0(x))throw new Error(`invalid signature ${I}: out of range 1..Point.Fn.ORDER`);return x}function S(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(I,x,H){return S(),(I===H?0:2)|Number(a.isOdd(x))}function F(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function G(I,x){Qo(x);let H=b.signature,R=x==="compact"?H:x==="recovered"?H+1:void 0;return X(I,R)}class q{r;s;recovery;constructor(x,H,R){if(this.r=z("r",x),this.s=z("s",H),R!=null){if(F(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,H=k.format){G(x,H);let R;if(H==="der"){let{r:j,s:Z}=Yo.toSig(X(x));return new q(j,Z)}H==="recovered"&&(R=x[0],H="compact",x=x.subarray(1));let M=b.signature/2,P=x.subarray(0,M),K=x.subarray(M,M*2);return new q(c.fromBytes(P),c.fromBytes(K),R)}static fromHex(x,H){return this.fromBytes(Pn(x),H)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new q(this.r,this.s,x)}recoverPublicKey(x){let{r:H,s:R}=this,M=this.assertRecovery(),P=M===2||M===3?H+f:H;if(!a.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=a.toBytes(P),j=t.fromBytes(Ue(Gs((M&1)===0),K)),Z=c.inv(P),ae=N(X(x,void 0,"msgHash")),W=c.create(-ae*Z),te=c.create(R*Z),Ee=t.BASE.mulAddUnsafe(W,j,te);if(Ee.is0())throw new Error("invalid recovery: point at infinify");return Ee.assertValidity(),Ee}hasHighS(){return O(this.s)}toBytes(x=k.format){if(Qo(x),x==="der")return Pn(Yo.hexFromSig(this));let{r:H,s:R}=this,M=c.toBytes(H),P=c.toBytes(R);return x==="recovered"?(F(),Ue(Uint8Array.of(this.assertRecovery()),M,P)):Ue(M,P)}toHex(x){return No(this.toBytes(x))}}Object.freeze(q.prototype),Object.freeze(q);let le=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let H=Ce(x),R=x.length*8-u;return R>0?H>>BigInt(R):H}:r.bits2int,N=r.bits2int_modN===void 0?function(x){return c.create(le(x))}:r.bits2int_modN,se=Jt(u);function oe(I){return Fo("num < 2^"+u,I,je,se),c.toBytes(I)}function L(I,x){return X(I,void 0,"message"),x?X(o(I),void 0,"prehashed message"):I}function E(I,x,H){let{lowS:R,prehash:M,extraEntropy:P}=Xo(H,k);I=L(I,M);let K=N(I),j=c.fromBytes(x);if(!c.isValidNot0(j))throw new Error("invalid private key");let Z=[oe(j),oe(K)];if(P!=null&&P!==!1){let Ee=P===!0?i(b.secretKey):P;Z.push(X(Ee,void 0,"extraEntropy"))}let ae=Ue(...Z),W=K;function te(Ee){let Et=le(Ee);if(!c.isValidNot0(Et))return;let _t=t.BASE.multiply(Et).toAffine(),Ze=c.create(_t.x);if(Ze===je)return;let Be;if(h!==void 0){let jt=Ce(Vo(h(d),f)),hc=c.inv(c.mul(jt,Et)),lc=c.mul(jt,W),pc=c.mul(jt,j);Be=c.create(hc*c.create(lc+pc*Ze))}else{let jt=Rs(Et,f);Be=c.create(jt*c.create(W+Ze*j))}if(Be===je)return;let to=U(_t.x,_t.y,Ze),ii=Be;return R&&O(Be)&&(ii=c.neg(Be),to^=1),new q(Ze,ii,v?void 0:to)}return{seed:ae,k2sig:te}}function A(I,x,H={}){let{seed:R,k2sig:M}=E(I,x,H);return Bs(o.outputLen,c.BYTES,s)(R,M).toBytes(H.format)}function C(I,x,H,R={}){let{lowS:M,prehash:P,format:K}=Xo(R,k);if(H=X(H,void 0,"publicKey"),x=L(x,P),!$t(I)){let j=I instanceof q?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+j)}G(I,K);try{let j=q.fromBytes(I,K),Z=t.fromBytes(H);if(M&&j.hasHighS())return!1;let{r:ae,s:W}=j,te=N(x),Ee=c.inv(W),Et=c.create(te*Ee),_t=c.create(ae*Ee),Ze=t.BASE.mulAddUnsafe(Et,Z,_t);if(Ze.is0())return!1;let Be=Ze.toAffine();return!(c.create(Be.x)!==ae||K==="recovered"&&j.recovery!==U(Be.x,Be.y,ae))}catch{return!1}}function D(I,x,H={}){let{prehash:R}=Xo(H,k);return x=L(x,R),q.fromBytes(I,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:l,getPublicKey:m,getSharedSecret:p,utils:w,lengths:b,Point:t,sign:A,verify:C,recoverPublicKey:D,Signature:q,hash:o})}var uu={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")};var du=qs(uu),Ys=Zs(du,ys);var tr=globalThis.crypto,er=class{hasher;constructor(e){let n=e.toLowerCase().replace("-","");if(n==="sha256")this.hasher=_.create();else if(n==="sha512")this.hasher=An.create();else throw new Error(`createHash: unsupported algorithm ${e} in the browser verifier`)}update(e){return this.hasher.update(typeof e=="string"?new TextEncoder().encode(e):e),this}digest(e){let n=this.hasher.digest(),o=B.Buffer.from(n);return e===void 0?o:o.toString(e)}};function Kn(t){return new er(t)}function nr(t){let e=[];return{update(n){return e.push(n),this},verify(n,o){try{let r=n instanceof Uint8Array?n:n.key,i=r.subarray(r.length-65);if(i.length!==65||i[0]!==4)return!1;let s=0;for(let f of e)s+=f.length;let a=new Uint8Array(s),c=0;for(let f of e)a.set(f,c),c+=f.length;return Ys.verify(o,_(a),i,{format:"der",prehash:!1,lowS:!1})}catch{return!1}}}}y();function ge(t){let e=Xs(t);return new TextEncoder().encode(e)}function Xs(t){return JSON.stringify(or(t))}function or(t){if(t===null||typeof t!="object"){if(typeof t>"u")throw new TypeError("bitgraph-core/canonical: undefined values are not serializable to canonical JSON");if(typeof t=="function"||typeof t=="symbol")throw new TypeError(`bitgraph-core/canonical: ${typeof t} values are not serializable to canonical JSON`);if(typeof t=="bigint")throw new TypeError("bitgraph-core/canonical: BigInt values are not serializable to canonical JSON; convert to string (decimal) before canonicalizing");return t}if(Array.isArray(t))return t.map(or);let e={};for(let n of Object.keys(t).sort()){let o=t[n];typeof o>"u"||(e[n]=or(o))}return e}function Vn(t,e){if(t.length!==e.length)return!1;let n=0;for(let o=0;o<t.length;o++)n|=t[o]^e[o];return n===0}async function ir(t){let{proof:e,bytes:n,trustAnchors:o}=t,r=await Js(e,n,o);return r===null?{valid:!0}:xu(r)}async function it(t){let{proof:e,trustAnchors:n}=t,o=await Js(e,void 0,n);return o===null?{valid:!0,artifactBinding:"not-checked"}:{valid:!1,artifactBinding:"not-checked",reason:o}}async function Js(t,e,n){let o=lu(t);if(o!==null)return o;let r=e===void 0?void 0:_(e),i;try{i=Lt(t.artifact.digestB64)}catch{return"artifact.digestB64 is not valid base64"}if(r!==void 0&&!Vn(r,i))return"artifact digest mismatch: the provided bytes do not match the committed digest";let s;try{s=Lt(t.signer.publicKeyB64)}catch{return"signer.publicKeyB64 is not valid base64"}if(s.length!==32)return`signer.publicKeyB64 decodes to ${s.length} bytes; expected 32 (Ed25519)`;let a={version:t.version,artifact:t.artifact,commit:t.commit,publicKeyB64:t.signer.publicKeyB64,enforcement:t.environment.enforcement,measurement:t.environment.measurement};t.environment.attestation!==void 0&&(a.attestationFormat=t.environment.attestation.format),t.agency!==void 0&&(a.actor=t.agency.actor),t.policy!==void 0&&(a.policy=t.policy),t.attribution!==void 0&&(a.attribution=t.attribution);let c=ge(a),f;try{f=Lt(t.signer.signatureB64)}catch{return"signer.signatureB64 is not valid base64"}if(f.length!==64)return`signer.signatureB64 decodes to ${f.length} bytes; expected 64 (Ed25519)`;let u;try{u=await Ao(f,c,s)}catch(d){return`signature verification error: ${d instanceof Error?d.message:String(d)}`}if(!u)return"signature verification failed: signature does not match";if(t.agency!==void 0){let d=gu(t);if(d!==null)return d}if(t.slotAllocation!==void 0){let d=await bu(t);if(d!==null)return d}if(t.commit.epochLink!==void 0){let d=wu(t);if(d!==null)return d}if(n!==void 0){let d=pu(t,n);if(d!==null)return d}return null}var hu=new Set(["stub","hw-key","measured-tee"]);function lu(t){if(t===null||typeof t!="object")return"proof must be an object";let e=t;if(e.version!=="bitgraph/1")return`unsupported proof version: ${String(e.version)}`;if(!en(e.artifact))return"proof.artifact is missing or not an object";let n=e.artifact;if(n.hashAlg!=="sha256")return`unsupported hashAlg: ${String(n.hashAlg)}`;if(typeof n.digestB64!="string"||n.digestB64.length===0)return"proof.artifact.digestB64 must be a non-empty string";if(!en(e.commit))return"proof.commit is missing or not an object";let o=e.commit;if(typeof o.nonceB64!="string"||o.nonceB64.length===0)return"proof.commit.nonceB64 must be a non-empty string";if(o.counter!==void 0&&typeof o.counter!="string")return"proof.commit.counter must be a string when present";if(o.time!==void 0&&(typeof o.time!="number"||!Number.isFinite(o.time)||o.time<0))return"proof.commit.time must be a non-negative finite number when present";if(o.prevB64!==void 0&&typeof o.prevB64!="string")return"proof.commit.prevB64 must be a string when present";if(o.epochId!==void 0&&typeof o.epochId!="string")return"proof.commit.epochId must be a string when present";if(!en(e.signer))return"proof.signer is missing or not an object";let r=e.signer;if(typeof r.publicKeyB64!="string"||r.publicKeyB64.length===0)return"proof.signer.publicKeyB64 must be a non-empty string";if(typeof r.signatureB64!="string"||r.signatureB64.length===0)return"proof.signer.signatureB64 must be a non-empty string";if(!en(e.environment))return"proof.environment is missing or not an object";let i=e.environment;if(typeof i.enforcement!="string"||!hu.has(i.enforcement))return"proof.environment.enforcement must be one of: stub, hw-key, measured-tee";if(typeof i.measurement!="string"||i.measurement.length===0)return"proof.environment.measurement must be a non-empty string";if(i.attestation!==void 0){if(!en(i.attestation))return"proof.environment.attestation must be an object when present";let s=i.attestation;if(typeof s.format!="string"||s.format.length===0)return"proof.environment.attestation.format must be a non-empty string";if(typeof s.reportB64!="string"||s.reportB64.length===0)return"proof.environment.attestation.reportB64 must be a non-empty string"}return null}function pu(t,e){if(e.requireEnforcement!==void 0&&t.environment.enforcement!==e.requireEnforcement)return`enforcement tier "${t.environment.enforcement}" does not meet required tier "${e.requireEnforcement}"`;if(e.allowedMeasurements!==void 0&&e.allowedMeasurements.length>0&&!e.allowedMeasurements.includes(t.environment.measurement))return`measurement "${t.environment.measurement}" is not in the allowed set`;if(e.allowedPublicKeys!==void 0&&e.allowedPublicKeys.length>0&&!e.allowedPublicKeys.includes(t.signer.publicKeyB64))return"proof public key is not in the allowed set";if(e.requireAttestation===!0&&t.environment.attestation===void 0)return"policy requires attestation but proof has none";if(e.requireAttestationFormat!==void 0&&e.requireAttestationFormat.length>0){if(t.environment.attestation===void 0)return"policy requires attestation format but proof has no attestation";if(!e.requireAttestationFormat.includes(t.environment.attestation.format))return`attestation format "${t.environment.attestation.format}" is not in the required set`}if(e.minCounter!==void 0||e.maxCounter!==void 0){if(t.commit.counter===void 0)return"policy requires a counter but proof has none";let n;try{n=BigInt(t.commit.counter)}catch{return"could not parse proof counter value as integer"}if(e.minCounter!==void 0){let o;try{o=BigInt(e.minCounter)}catch{return"could not parse policy minCounter as integer"}if(n<o)return`counter ${t.commit.counter} is below minimum ${e.minCounter}`}if(e.maxCounter!==void 0){let o;try{o=BigInt(e.maxCounter)}catch{return"could not parse policy maxCounter as integer"}if(n>o)return`counter ${t.commit.counter} is above maximum ${e.maxCounter}`}}if(e.minTime!==void 0||e.maxTime!==void 0){if(t.commit.time===void 0)return"policy requires a time field but proof has none";if(e.minTime!==void 0&&t.commit.time<e.minTime)return`commit time ${t.commit.time} is before minimum ${e.minTime}`;if(e.maxTime!==void 0&&t.commit.time>e.maxTime)return`commit time ${t.commit.time} is after maximum ${e.maxTime}`}if(e.requireEpochId===!0&&(t.commit.epochId===void 0||t.commit.epochId.length===0))return"policy requires epochId but proof has none";if(e.requireActor===!0&&t.agency===void 0)return"policy requires actor (agency) but proof has none";if(e.allowedActorKeyIds!==void 0&&e.allowedActorKeyIds.length>0){if(t.agency===void 0)return"policy requires allowed actor key ID but proof has no agency";if(!e.allowedActorKeyIds.includes(t.agency.actor.keyId))return"actor key ID is not in the allowed set"}if(e.allowedActorProviders!==void 0&&e.allowedActorProviders.length>0){if(t.agency===void 0)return"policy requires allowed actor provider but proof has no agency";if(!e.allowedActorProviders.includes(t.agency.actor.provider))return`actor provider "${t.agency.actor.provider}" is not in the allowed set`}if(e.allowedOrigins!==void 0&&e.allowedOrigins.length>0){if(t.agency===void 0)return"policy requires an allowed origin but proof has no agency";let n=t.agency.authorization;if(!("format"in n)||n.format!=="webauthn")return"policy requires an allowed WebAuthn origin but the authorization is not WebAuthn";let o;try{o=JSON.parse(n.clientDataJSON).origin}catch{o=void 0}if(typeof o!="string"||!e.allowedOrigins.includes(o))return`WebAuthn origin "${o??"(none)"}" is not in the allowed set`}return e.requireSlot===!0&&t.slotAllocation===void 0?"policy requires slotAllocation (BitGraph causal slot) but proof has none":null}function mu(t,e){if(typeof t!="string"||t.length===0)return"agency: clientDataJSON missing origin field";let n;try{n=new URL(t).hostname.toLowerCase()}catch{return"agency: clientDataJSON origin is not a valid origin"}if(!n)return"agency: clientDataJSON origin has no host";let o=e.subarray(0,32).toString("hex"),r=n.split("."),i=[];for(let a=0;a<r.length;a++){let c=r.slice(a).join(".");if(a>0&&r.length-a<2)break;i.push(c)}return i.some(a=>Kn("sha256").update(a,"utf8").digest("hex")===o)?null:"agency: authenticatorData rpIdHash does not match the origin's domain"}function gu(t){let e=t.agency,{actor:n,authorization:o}=e,r="format"in o&&o.format==="webauthn";if(typeof n.keyId!="string"||n.keyId.length===0)return"agency.actor.keyId must be a non-empty string";if(typeof n.publicKeyB64!="string"||n.publicKeyB64.length===0)return"agency.actor.publicKeyB64 must be a non-empty string";if(n.algorithm!=="ES256")return`agency.actor.algorithm must be "ES256", got "${String(n.algorithm)}"`;if(typeof n.provider!="string"||n.provider.length===0)return"agency.actor.provider must be a non-empty string";if(o.purpose!=="bitgraph/commit-authorize/v1")return`agency.authorization.purpose must be "bitgraph/commit-authorize/v1", got "${String(o.purpose)}"`;if(typeof o.signatureB64!="string"||o.signatureB64.length===0)return"agency.authorization.signatureB64 must be a non-empty string";let i;try{i=B.Buffer.from(n.publicKeyB64,"base64")}catch{return"agency.actor.publicKeyB64 is not valid base64"}if(Kn("sha256").update(i).digest("hex")!==n.keyId)return"agency: actor.keyId does not match SHA-256 of public key";if(o.actorKeyId!==n.keyId)return"agency: authorization.actorKeyId does not match actor.keyId";if(o.artifactHash!==t.artifact.digestB64){let c=e.batchContext;if(!c||!Array.isArray(c.batchDigests)||!c.batchDigests.includes(t.artifact.digestB64)||c.batchDigests[0]!==o.artifactHash)return"agency: authorization.artifactHash does not match proof.artifact.digestB64"}let a;try{a=B.Buffer.from(o.signatureB64,"base64")}catch{return"agency.authorization.signatureB64 is not valid base64"}try{if(r){let c=o;if(typeof c.clientDataJSON!="string"||!c.clientDataJSON)return"agency: WebAuthn authorization missing clientDataJSON";if(typeof c.authenticatorDataB64!="string"||!c.authenticatorDataB64)return"agency: WebAuthn authorization missing authenticatorDataB64";let f;try{f=JSON.parse(c.clientDataJSON)}catch{return"agency: clientDataJSON is not valid JSON"}if(f.type!=="webauthn.get")return`agency: clientDataJSON.type must be "webauthn.get", got "${f.type}"`;if(!f.challenge)return"agency: clientDataJSON missing challenge field";let u=f.challenge.replace(/-/g,"+").replace(/_/g,"/");for(;u.length%4;)u+="=";if(u!==o.challenge)return"agency: clientDataJSON challenge does not match authorization.challenge";let d=B.Buffer.from(c.authenticatorDataB64,"base64");if(d.length<37)return"agency: authenticatorData too short";let h=d[32];if(!(h&1))return"agency: authenticatorData UP flag not set";if(!(h&4))return"agency: authenticatorData UV flag not set";let l=mu(f.origin,d);if(l!==null)return l;let m=Kn("sha256").update(B.Buffer.from(c.clientDataJSON,"utf8")).digest(),p=B.Buffer.concat([d,m]),w=nr("SHA256");if(w.update(p),!w.verify({key:i,format:"der",type:"spki"},a))return"agency: WebAuthn P-256 signature verification failed"}else{let c={purpose:o.purpose,actorKeyId:o.actorKeyId,artifactHash:o.artifactHash,challenge:o.challenge,timestamp:o.timestamp};"protocolVersion"in o&&o.protocolVersion!==void 0&&(c.protocolVersion=o.protocolVersion);let f=B.Buffer.from(JSON.stringify(c,Object.keys(c).sort()),"utf8"),u=nr("SHA256");if(u.update(f),!u.verify({key:i,format:"der",type:"spki"},a))return"agency: P-256 signature verification failed"}}catch(c){return`agency: P-256 signature verification error: ${c instanceof Error?c.message:String(c)}`}return null}async function bu(t){let e=t.slotAllocation;if(e.version!=="bitgraph/slot/1")return`slotAllocation.version must be "bitgraph/slot/1", got "${String(e.version)}"`;if(typeof e.nonceB64!="string"||e.nonceB64.length===0)return"slotAllocation.nonceB64 must be a non-empty string";if(typeof e.counter!="string"||e.counter.length===0)return"slotAllocation.counter must be a non-empty string";if(e.time!==void 0&&(typeof e.time!="number"||!Number.isFinite(e.time)||e.time<0))return"slotAllocation.time must be a non-negative finite number when present";if(typeof e.epochId!="string"||e.epochId.length===0)return"slotAllocation.epochId must be a non-empty string";if(typeof e.publicKeyB64!="string"||e.publicKeyB64.length===0)return"slotAllocation.publicKeyB64 must be a non-empty string";if(typeof e.signatureB64!="string"||e.signatureB64.length===0)return"slotAllocation.signatureB64 must be a non-empty string";let n={version:e.version,nonceB64:e.nonceB64,counter:e.counter,...e.time!==void 0?{time:e.time}:{},epochId:e.epochId,publicKeyB64:e.publicKeyB64,...e.chainId?{chainId:e.chainId}:{}},o=ge(n),r,i;try{r=Lt(e.signatureB64),i=Lt(e.publicKeyB64)}catch{return"slotAllocation contains invalid base64"}if(r.length!==64)return`slotAllocation.signatureB64 decodes to ${r.length} bytes; expected 64 (Ed25519)`;if(i.length!==32)return`slotAllocation.publicKeyB64 decodes to ${i.length} bytes; expected 32 (Ed25519)`;let s;try{s=await Ao(r,o,i)}catch(d){return`slotAllocation signature verification error: ${d instanceof Error?d.message:String(d)}`}if(!s)return"slotAllocation signature verification failed";let a=new Set(["digestB64","artifact","hashAlg","signatureB64"]),c=Object.keys(n);for(let d of c)if(a.has(d))return`slotAllocation body contains forbidden field '${d}' \u2014 causal independence violated`;if(typeof t.commit.slotHashB64!="string"||t.commit.slotHashB64.length===0)return"commit.slotHashB64 must be present when slotAllocation is present";let f=_(o),u;try{u=Lt(t.commit.slotHashB64)}catch{return"commit.slotHashB64 is not valid base64"}if(!Vn(f,u))return"commit.slotHashB64 does not match SHA-256 of canonical slot body \u2014 slot binding broken";if(e.nonceB64!==t.commit.nonceB64)return"slotAllocation.nonceB64 does not match commit.nonceB64";if(typeof t.commit.slotCounter!="string"||t.commit.slotCounter.length===0)return"commit.slotCounter must be present when slotAllocation is present";if(t.commit.slotCounter!==e.counter)return"commit.slotCounter does not match slotAllocation.counter";if(t.commit.counter===void 0)return"commit.counter must be present for slot ordering verification";try{let d=BigInt(e.counter),h=BigInt(t.commit.counter);if(d>=h)return`slotAllocation.counter (${e.counter}) must be less than commit.counter (${t.commit.counter})`}catch{return"could not parse slot or commit counter as integer"}return e.publicKeyB64!==t.signer.publicKeyB64?"slotAllocation.publicKeyB64 does not match signer.publicKeyB64 \u2014 different enclave":t.commit.epochId!==void 0&&e.epochId!==t.commit.epochId?"slotAllocation.epochId does not match commit.epochId \u2014 different lifecycle":null}var rr=new Map;function yu(t){let e=`${t.prevEpochId}|${t.prevCounter}|${t.prevProofHashB64}`,n=_(new TextEncoder().encode(e));return B.Buffer.from(n).toString("base64")}function wu(t){let e=t.commit.epochLink;if(typeof e.prevEpochId!="string"||e.prevEpochId.length===0)return"epochLink.prevEpochId must be a non-empty string";if(typeof e.prevPublicKeyB64!="string"||e.prevPublicKeyB64.length===0)return"epochLink.prevPublicKeyB64 must be a non-empty string";if(typeof e.prevCounter!="string"||e.prevCounter.length===0)return"epochLink.prevCounter must be a non-empty string";if(typeof e.prevProofHashB64!="string"||e.prevProofHashB64.length===0)return"epochLink.prevProofHashB64 must be a non-empty string";if(typeof e.toEpochId!="string"||e.toEpochId.length===0)return"epochLink.toEpochId must be a non-empty string";if(typeof e.toPublicKeyB64!="string"||e.toPublicKeyB64.length===0)return"epochLink.toPublicKeyB64 must be a non-empty string";try{BigInt(e.prevCounter)}catch{return"epochLink.prevCounter is not a valid decimal string"}if(t.commit.epochId!==void 0&&e.toEpochId!==t.commit.epochId)return`epochLink.toEpochId "${e.toEpochId}" does not match proof commit.epochId "${t.commit.epochId}" \u2014 successor binding broken`;if(e.toPublicKeyB64!==t.signer.publicKeyB64)return"epochLink.toPublicKeyB64 does not match proof signer.publicKeyB64 \u2014 successor binding broken";if(e.prevEpochId===e.toEpochId)return"epochLink.prevEpochId equals toEpochId \u2014 epoch link must cross epoch boundary";if(e.prevPublicKeyB64===e.toPublicKeyB64)return"epochLink.prevPublicKeyB64 equals toPublicKeyB64 \u2014 epochs must have different keys";let n=yu(e),o=rr.get(n);if(o!==void 0){if(o!==e.toEpochId)return`FORK DETECTED: predecessor (epoch=${e.prevEpochId.slice(0,12)}..., counter=${e.prevCounter}) already consumed by epoch ${o.slice(0,12)}..., but this proof claims consumption by epoch ${e.toEpochId.slice(0,12)}... \u2014 single-successor invariant violated`}else rr.set(n,e.toEpochId);return null}function Ke(){rr.clear()}function xu(t){return{valid:!1,reason:t}}function en(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Lt(t){let e=B.Buffer.from(t,"base64");if(e.toString("base64")!==t)throw new Error(`invalid base64 string: "${t}"`);return new Uint8Array(e)}y();function zn(t){let e=t,n=e.signer,o=e.environment,r={version:e.version,artifact:e.artifact,commit:e.commit,publicKeyB64:n?.publicKeyB64,enforcement:o?.enforcement,measurement:o?.measurement};e.attribution&&(r.attribution=e.attribution),o?.attestation&&(r.attestationFormat=o.attestation.format);let i=ge(r),s=_(i);return ar(s)}var Qs=["proofHash","ethereum"];function sr(t){let e=t,n=e;if(Qs.some(r=>Object.prototype.hasOwnProperty.call(e,r))){n={};for(let r of Object.keys(e))Qs.includes(r)||(n[r]=e[r])}let o=ge(n);return ar(_(o))}function ar(t){if(typeof B.Buffer<"u")return B.Buffer.from(t).toString("base64");let e="";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}function ea(t){let e=t,n=e.signer,o=e.environment,r={version:e.version,artifact:e.artifact,commit:e.commit,publicKeyB64:n?.publicKeyB64,enforcement:o?.enforcement,measurement:o?.measurement};o?.attestation!==void 0&&(r.attestationFormat=o.attestation.format);let i=e.agency;return i!==void 0&&(r.actor=i.actor),e.policy!==void 0&&(r.policy=e.policy),e.attribution!==void 0&&(r.attribution=e.attribution),r}function cr(t){return ar(_(ge(ea(t))))}y();var Ve="bitgraph-fuse/1",oa=(()=>{let t=new TextEncoder().encode(Ve),e=new Uint8Array(t.length+1);return e.set(t,0),e[t.length]=0,e})(),ra=Ve,fr="BGFUSE01",qn=48,dr="bitgraph-fuse/manifest.json",hr="bitgraph-fuse/original",Ot="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",tn={};for(let t=0;t<Ot.length;t++)tn[Ot[t]]=t;function ze(t){let e="";for(let n=0;n<t.length;n+=3){let o=t[n],r=n+1<t.length?t[n+1]:0,i=n+2<t.length?t[n+2]:0;e+=Ot[o>>2]+Ot[(o&3)<<4|r>>4],e+=n+1<t.length?Ot[(r&15)<<2|i>>6]:"=",e+=n+2<t.length?Ot[i&63]:"="}return e}function Ft(t){if(typeof t!="string"||t.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(t))return null;let e=t.endsWith("==")?2:t.endsWith("=")?1:0,n=new Uint8Array(t.length/4*3-e),o=0;for(let r=0;r<t.length;r+=4){let i=tn[t[r]]<<18|tn[t[r+1]]<<12|(t[r+2]==="="?0:tn[t[r+2]])<<6|(t[r+3]==="="?0:tn[t[r+3]]);n[o++]=i>>16&255,o<n.length&&(n[o++]=i>>8&255),o<n.length&&(n[o++]=i&255)}return ze(n)!==t?null:n}function Re(t){let e="";for(let n of t)e+=(n<16?"0":"")+n.toString(16);return e}function lr(t){if(typeof t!="string"||t.length%2!==0||!/^[0-9a-f]*$/.test(t))return null;let e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}function $e(t,e){if(t.length!==e.length)return!1;let n=0;for(let o=0;o<t.length;o++)n|=t[o]^e[o];return n===0}function pr(...t){let e=0;for(let r of t)e+=r.length;let n=new Uint8Array(e),o=0;for(let r of t)n.set(r,o),o+=r.length;return n}var be=t=>new TextEncoder().encode(t);function ia(t){return{version:t.version,nonceB64:t.nonceB64,counter:t.counter,...t.time!==void 0?{time:t.time}:{},epochId:t.epochId,publicKeyB64:t.publicKeyB64,...t.chainId?{chainId:t.chainId}:{}}}function sa(t){return _(ge(ia(t)))}function aa(t){let e=Ft(t.nonceB64);if(e===null||e.length!==32)throw new TypeError("slot.nonceB64 must decode to exactly 32 bytes");return pr(oa,sa(t),e)}function nn(t){return _(aa(t))}function Gn(t,e){if(t.length!==32)throw new TypeError("commitment must be 32 bytes");if(e!==void 0&&e.length!==32)throw new TypeError("originDigest must be 32 bytes");let n={type:Ve,...e!==void 0?{origin:{algorithm:"sha256",digest:Re(e)}}:{},slotCommitment:{algorithm:"sha256",digest:Re(t)}};return ge(n)}function st(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function bt(t){if(!st(t)||Object.keys(t).length!==2||t.algorithm!=="sha256"||typeof t.digest!="string")return null;let n=lr(t.digest);return n!==null&&n.length===32?n:null}function mr(t){let e;try{e=new TextDecoder("utf-8",{fatal:!0}).decode(t)}catch{return null}let n;try{n=JSON.parse(e)}catch{return null}if(!st(n))return null;let o=Object.keys(n).sort(),r=o.length===2?["slotCommitment","type"]:o.length===3?["origin","slotCommitment","type"]:null;if(r===null||o.join(",")!==r.join(",")||n.type!==Ve)return null;let i=bt(n.slotCommitment);if(i===null)return null;let s;if("origin"in n){let a=bt(n.origin);if(a===null)return null;s=a}return $e(Gn(i,s),t)?s!==void 0?{commitment:i,originDigest:s}:{commitment:i}:null}var ye=512,Eu=8589934591;function Bu(t,e){let n=t.toString(8).padStart(e-1,"0")+"\0";if(n.length!==e)throw new RangeError("field overflow");return be(n)}function ta(t,e){if(e>Eu)throw new RangeError("container/1 entries are limited to 8 GiB");let n=new Uint8Array(ye),o=be(t);if(o.length>100)throw new RangeError("ustar name too long");n.set(o,0),n.set(be("0000644\0"),100),n.set(be("0000000\0"),108),n.set(be("0000000\0"),116),n.set(Bu(e,12),124),n.set(be("00000000000\0"),136),n.set(be(" "),148),n[156]=48,n.set(be("ustar\0"),257),n.set(be("00"),263);let r=0;for(let i of n)r+=i;return n.set(be(r.toString(8).padStart(6,"0")+"\0 "),148),n}function ur(t){return(ye-t%ye)%ye}function na(t,e){return pr(ta(dr,e.length),e,new Uint8Array(ur(e.length)),ta(hr,t.length),t,new Uint8Array(ur(t.length)),new Uint8Array(ye*2))}function vu(t){let e=[],n=0;for(;n+ye<=t.length;){let o=t.subarray(n,n+ye);if(o.every(f=>f===0)){let f=t.subarray(n);return f.length!==ye*2||!f.every(u=>u===0)?null:e}let r=o.indexOf(0,0),i=new TextDecoder().decode(o.subarray(0,r<0||r>100?100:r)),s=new TextDecoder().decode(o.subarray(124,135));if(!/^[0-7]{11}$/.test(s))return null;let a=parseInt(s,8);if(n+ye+a>t.length)return null;let c=t.subarray(n+ye,n+ye+a);e.push({name:i,data:c,headerBytes:o}),n+=ye+a+ur(a)}return null}var Au={id:"trailer/1",form:"A",byteExact:!0,build({original:t,commitment:e}){if(t===void 0)throw new TypeError("trailer/1 requires the original bytes");if(e.length!==32)throw new TypeError("commitment must be 32 bytes");return pr(t,be(fr),new Uint8Array(8),e)},locate(t){if(t.length<qn)return null;let e=t.subarray(t.length-qn);return!$e(e.subarray(0,8),be(fr))||!e.subarray(8,16).every(n=>n===0)?null:{commitment:new Uint8Array(e.subarray(16,48)),originalBytes:t.subarray(0,t.length-qn)}}},Iu={id:"container/1",form:"B",byteExact:!0,build({original:t,originDigest:e,commitment:n}){if(t===void 0)throw new TypeError("container/1 requires the original bytes");let o=e??_(t);return na(t,Gn(n,o))},locate(t){let e=vu(t);if(e===null||e.length!==2)return null;let[n,o]=e;if(n.name!==dr||o.name!==hr)return null;let r=mr(n.data);if(r===null||r.originDigest===void 0)return null;let i=na(o.data,n.data);return $e(i,t)?{commitment:r.commitment,originDigest:r.originDigest,originalBytes:o.data}:null}},ku={id:"produced/1",form:"C",byteExact:!1,build({original:t,originDigest:e,commitment:n}){if(t!==void 0)throw new TypeError("produced/1 takes no original; pass originDigest for a source reference");return Gn(n,e)},locate(t){let e=mr(t);return e===null?null:e.originDigest!==void 0?{commitment:e.commitment,originDigest:e.originDigest}:{commitment:e.commitment}}},Ut=Object.freeze([Au,Iu,ku]),yt="set/1";var ca=/^[a-z0-9][a-z0-9-]*\/[1-9][0-9]*$/;function fa(t,e){if(t.length!==32)throw new TypeError("commitment must be 32 bytes");if(e.length===0)throw new TypeError("a set lists at least one member");let n=[],o=new Set;for(let i of e){if(i.artifact.length!==32)throw new TypeError("member artifact digest must be 32 bytes");if(i.origin.length!==32)throw new TypeError("member origin digest must be 32 bytes");if(!ca.test(i.placement))throw new TypeError(`member placement "${i.placement}" is not a placement id`);if(i.placement===yt)throw new TypeError("a set cannot list a set as a member");let s=Re(i.artifact);if(o.has(s))throw new TypeError(`duplicate member artifact digest ${s}`);o.add(s),n.push({artifact:{algorithm:"sha256",digest:s},origin:{algorithm:"sha256",digest:Re(i.origin)},placement:i.placement})}n.sort((i,s)=>i.artifact.digest<s.artifact.digest?-1:1);let r={members:n,placement:yt,slotCommitment:{algorithm:"sha256",digest:Re(t)},type:Ve};return ge(r)}function gr(t){let e;try{e=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(t)}catch{return null}let n;try{n=JSON.parse(e)}catch{return null}if(!st(n)||Object.keys(n).sort().join(",")!=="members,placement,slotCommitment,type"||n.type!==Ve||n.placement!==yt)return null;let o=bt(n.slotCommitment);if(o===null)return null;let r=n.members;if(!Array.isArray(r)||r.length===0)return null;let i=[];for(let a of r){if(!st(a)||Object.keys(a).sort().join(",")!=="artifact,origin,placement")return null;let c=bt(a.artifact),f=bt(a.origin),u=a.placement;if(c===null||f===null||typeof u!="string"||!ca.test(u)||u===yt)return null;i.push({artifact:c,origin:f,placement:u})}let s;try{s=fa(o,i)}catch{return null}return $e(s,t)?{commitment:o,members:i}:null}var Su={id:yt,form:"C",byteExact:!1,build(){throw new TypeError("set/1 is built with buildSetManifest(commitment, members)")},locate(t){let e=gr(t);return e===null?null:{commitment:e.commitment}}};function on(t){return[...Ut,Su].find(e=>e.id===t)}function wt(t){let e=t.attribution;if(e===void 0||e.name!==ra)return null;let n=typeof e.title=="string"&&e.title.length>0,o={placement:n?e.title:null,placementSource:n?"attribution":null,source:"attribution"};if(typeof e.message=="string"&&e.message.length>0){let r=Ft(e.message);r!==null&&r.length===32&&(o.originDigest=r,o.originSource="attribution")}return o}function br(t,e){if(t===null)return e;if(e===null)return t;let n={...t};return n.placement===null&&e.placement!==null&&(n.placement=e.placement,n.placementSource="manifest"),n.originDigest===void 0&&e.originDigest!==void 0&&(n.originDigest=e.originDigest,n.originSource="manifest"),n}function yr(t){let e=typeof t=="string"?(()=>{try{return JSON.parse(t)}catch{return null}})():t;if(!st(e)||e.type!==Ve)return null;let n=e.manifest;if(!st(n)||n.placement!==void 0&&typeof n.placement!="string"||bt(n.artifact)===null||n.origin!==void 0&&bt(n.origin)===null||n.fusedFile!==null&&typeof n.fusedFile!="string")return null;let r=e.proof;if(!st(r)||r.version!=="bitgraph/1")return null;let i={type:Ve,manifest:{placement:typeof n.placement=="string"?n.placement:"",...n.origin!==void 0?{origin:n.origin}:{},artifact:n.artifact,fusedFile:n.fusedFile},proof:r};if(e.fusePayload!==void 0){if(!st(e.fusePayload))return null;i.fusePayload=e.fusePayload}return i}function wr(t){let e=t.manifest.placement.length>0,n={placement:e?t.manifest.placement:null,placementSource:e?"manifest":null,source:"manifest"};if(t.manifest.origin!==void 0){let o=lr(t.manifest.origin.digest);o!==null&&o.length===32&&(n.originDigest=o,n.originSource="manifest")}return n}y();function ua(t){let e=t.commit;if(typeof e.counter!="string"||typeof e.slotCounter!="string"||typeof e.epochId!="string")return null;let n;try{n=(BigInt(e.counter)-BigInt(e.slotCounter)).toString()}catch{return null}return{slotCounter:e.slotCounter,commitCounter:e.counter,epochId:e.epochId,chainId:typeof e.chainId=="string"?e.chainId:null,positions:n}}function da(t){return`The exact fused bytes could not feasibly have been finalized before their signed slot allocation at position ${t.slotCounter}, and were committed no later than position ${t.commitCounter}.`}function xr(t,e,n){if(e===null)return[];let o=[];return t==="FUSED_FROM_ORIGIN"?o.push(`The supplied original rebuilds the committed fused artifact byte for byte, so these exact original bytes existed no later than commit position ${e.commitCounter}.`):t==="FUSED_DIRECT"&&n&&o.push("The fused bytes carry an origin digest that matches the signed marker; the original itself was not supplied and was not checked."),(t==="FUSED_DIRECT"||t==="FUSED_FROM_ORIGIN")&&o.push(da(e)),t==="RECORDED"&&o.push(`These exact bytes existed no later than commit position ${e.commitCounter}.`),o}async function Er(t){let{proof:e,bytes:n}=t,o=t.frame===void 0||t.frame===null?null:yr(t.frame)??null,r=_(n),i=ze(r),s=e?.artifact?.digestB64??"",a=(w,b,k)=>({category:w,proof:b.proof??{valid:!0},marker:b.marker??null,placement:b.placement??null,fileDigestB64:i,artifactDigestB64:s,originDigestB64:b.originDigestB64??null,slotCommitmentB64:b.slotCommitmentB64??null,span:b.span??null,policy:b.policy??{spanExceeded:!1,maxPositions:null},statements:b.statements??[],reason:k}),c=await it(t.trustAnchors!==void 0?{proof:e,trustAnchors:t.trustAnchors}:{proof:e});if(!c.valid){let w=c.reason??"proof failed verification";return a("INVALID_UNDERLYING_PROOF",{proof:{valid:!1,reason:w}},w)}let f=br(wt(e),o!==null?wr(o):null),u=f?.originDigest,d=u!==void 0?ze(u):null,h=ua(e),l=t.maxPositions===void 0?null:BigInt(t.maxPositions),m={spanExceeded:l!==null&&h!==null&&BigInt(h.positions)>l,maxPositions:l===null?null:l.toString()},p={proof:{valid:!0},marker:f,originDigestB64:d,span:h,policy:m};if(i===s){if(f===null)return a("RECORDED",{...p,statements:xr("RECORDED",h,!1)},null);let w=e.slotAllocation;if(w===void 0)return a("INVALID_SLOT_COMMITMENT",p,"the proof carries no slot record, so no commitment can be recomputed");let b;try{b=nn(w)}catch(S){return a("INVALID_SLOT_COMMITMENT",p,`commitment could not be recomputed: ${S instanceof Error?S.message:String(S)}`)}let k=ze(b),v=f.placement===null?void 0:on(f.placement),O=v===void 0?null:v.locate(n);if(f.placement===null){for(let S of Ut){let U=S.locate(n);if(U!==null){v=S,O=U;break}}if(v===void 0)return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:k},"no registered placement finds a commitment in the fused bytes")}else if(v===void 0)return a("UNDETERMINED_PLACEMENT",{...p,slotCommitmentB64:k},`placement "${f.placement}" is not registered; the commitment cannot be located`);if(O===null)return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:k,placement:v.id},`no ${v.id} commitment found in the fused bytes`);if(!$e(O.commitment,b))return a("INVALID_SLOT_COMMITMENT",{...p,slotCommitmentB64:k,placement:v.id},"the commitment in the fused bytes does not match the proof's slot record");let z=!1;if(u!==void 0){let S=O.originDigest??(O.originalBytes!==void 0?_(O.originalBytes):void 0);if(S!==void 0){if(!$e(S,u))return a("INVALID_ORIGIN_ATTRIBUTION",{...p,slotCommitmentB64:k,placement:v.id},f.originSource==="attribution"?"the origin digest in the signed attribution does not match the origin inside the fused bytes":"the origin digest in the manifest does not match the origin inside the fused bytes");z=!0}}return a("FUSED_DIRECT",{...p,slotCommitmentB64:k,placement:v.id,statements:xr("FUSED_DIRECT",h,z)},null)}if(u!==void 0&&$e(r,u)){let w=e.slotAllocation;if(w===void 0)return a("INVALID_SLOT_COMMITMENT",p,"the proof carries no slot record, so the fused bytes cannot be rebuilt");let b;try{b=nn(w)}catch(S){return a("INVALID_SLOT_COMMITMENT",p,`commitment could not be recomputed: ${S instanceof Error?S.message:String(S)}`)}let k=ze(b),v=f!==null&&f.placement!==null?on(f.placement):void 0;if(f!==null&&f.placement!==null&&v===void 0)return a("UNDETERMINED_PLACEMENT",{...p,slotCommitmentB64:k},`placement "${f.placement}" is not registered; the fused bytes cannot be rebuilt`);let O=v!==void 0?[v]:Ut.filter(S=>S.byteExact),z=e.artifact.digestB64;for(let S of O){if(!S.byteExact)continue;let U;try{U=S.build({original:n,originDigest:u,commitment:b})}catch{continue}if(ze(_(U))===z)return a("FUSED_FROM_ORIGIN",{...p,slotCommitmentB64:k,placement:S.id,statements:xr("FUSED_FROM_ORIGIN",h,!0)},null)}return a("RECONSTRUCTION_MISMATCH",{...p,slotCommitmentB64:k,placement:v?.id??null},v!==void 0?`rebuilding ${v.id} from this file and the proof's slot record does not reproduce the committed artifact digest`:"no registered byte-exact placement rebuilds the committed artifact digest from this file")}return a("NO_MATCH",p,"this file matches neither the committed artifact digest nor the origin digest; the proof proves nothing about it")}y();y();async function*la(t,e){let n=new vr(t,e?.maxTotalBytes),o=e?.maxEntryCount??Number.POSITIVE_INFINITY,r=e?.maxMetadataEntryBytes??Number.POSITIVE_INFINITY,i=null,s=null,a=null,c=0,f=(u,d)=>{if(u>r)throw new Error(`tar: ${d} metadata entry of ${u} bytes exceeds the ${r}-byte cap`)};for(;;){let u=await n.readExact(512);if(u===null||Pu(u))return;if(++c>o)throw new Error(`tar: archive exceeds the maximum of ${o} entries`);let d=Ru(u),h=d.typeflag;if(h==="x"||h==="g"){f(d.size,"PAX");let v=await ha(n,d.size);await n.skip(Wn(d.size));let O=Du(v);h==="x"?i=O:s=Nu(s,O);continue}if(h==="L"){f(d.size,"GNU long-name");let v=await ha(n,d.size);await n.skip(Wn(d.size)),a=xt(Mu(v));continue}if(h==="K"){await n.skip(d.size+Wn(d.size));continue}let l=d.name;s!==null&&s.has("path")&&(l=s.get("path")),a!==null&&(l=a),i!==null&&i.has("path")&&(l=i.get("path"));let m=d.size,p=i?.get("size")??s?.get("size");if(p!==void 0){let v=Number(p);if(!Number.isSafeInteger(v)||v<0)throw new Error("tar: invalid PAX size value");m=v}i=null,a=null;let w=h==="0"||h==="\0",b={remaining:m},k=Cu(n,b);yield{path:l,size:m,kind:w?"file":"other",typeflag:h,body:k},b.remaining>0&&(await n.skip(b.remaining),b.remaining=0),await n.skip(Wn(m))}}async function*Cu(t,e){for(;e.remaining>0;){let n=await t.readSome(e.remaining);if(n===null)throw new Error("tar: truncated archive (unexpected end of stream inside entry body)");e.remaining-=n.length,yield n}}async function ha(t,e){if(e===0)return new Uint8Array(0);let n=await t.readExact(e);if(n===null)throw new Error("tar: truncated archive (unexpected end of stream)");return n}function Ru(t){$u(t);let e=t[156],n=e===0?"\0":String.fromCharCode(e),o=xt(Br(t,0,100));if(xt(Br(t,257,6))==="ustar"){let s=xt(Br(t,345,155));s.length>0&&(o=`${s}/${o}`)}let i=pa(t.subarray(124,136));return{name:o,size:i,typeflag:n}}function Br(t,e,n){let o=t.subarray(e,e+n),r=o.indexOf(0);return r===-1&&(r=o.length),o.subarray(0,r)}function pa(t){if(t.length>0&&(t[0]&128)!==0){let o=0n;for(let r=0;r<t.length;r++){let i=r===0?t[0]&127:t[r];o=o<<8n|BigInt(i)}if(o>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("tar: numeric field exceeds the supported range");return Number(o)}let e=xt(t).trim().replace(/\0+$/,"").trim();if(e.length===0)return 0;let n=Number.parseInt(e,8);if(!Number.isSafeInteger(n)||n<0)throw new Error(`tar: invalid octal numeric field: "${e}"`);return n}function $u(t){let e=pa(t.subarray(148,156)),n=0;for(let o=0;o<512;o++)n+=o>=148&&o<156?32:t[o];if(n!==e)throw new Error("tar: header checksum mismatch (corrupt or not a tar archive)")}function Pu(t){for(let e=0;e<t.length;e++)if(t[e]!==0)return!1;return!0}function Du(t){let e=new Map,n=0;for(;n<t.length;){let o=n;for(;o<t.length&&t[o]!==32;)o++;if(o>=t.length)throw new Error("tar: malformed PAX record (no length delimiter)");let r=Number(xt(t.subarray(n,o)));if(!Number.isInteger(r)||r<=0||n+r>t.length)throw new Error("tar: malformed PAX record (bad length)");let i=t.subarray(o+1,n+r);if(i.length===0||i[i.length-1]!==10)throw new Error("tar: malformed PAX record (missing newline)");let s=xt(i.subarray(0,i.length-1)),a=s.indexOf("=");if(a===-1)throw new Error("tar: malformed PAX record (missing '=')");e.set(s.slice(0,a),s.slice(a+1)),n+=r}return e}function Nu(t,e){let n=new Map(t??[]);for(let[o,r]of e)n.set(o,r);return n}function xt(t){return new TextDecoder("utf-8").decode(t)}function Mu(t){let e=t.length;for(;e>0&&t[e-1]===0;)e--;return t.subarray(0,e)}var vr=class{iter;chunks=[];head=0;available=0;ended=!1;totalPulled=0;maxTotalBytes;constructor(e,n){this.iter=e[Symbol.asyncIterator](),this.maxTotalBytes=n??Number.POSITIVE_INFINITY}async fill(){if(this.ended)return!1;let e=await this.iter.next();if(e.done===!0)return this.ended=!0,!1;let n=e.value;if(n.length>0){if(this.totalPulled+=n.length,this.totalPulled>this.maxTotalBytes)throw new Error(`tar: archive exceeds the maximum decompressed size of ${this.maxTotalBytes} bytes`);this.chunks.push(n),this.available+=n.length}return!0}async readExact(e){for(;this.available<e;)if(!await this.fill()){if(this.available===0)return null;throw new Error("tar: truncated archive (unexpected end of stream)")}return this.take(e)}async readSome(e){for(;this.available===0;)if(!await this.fill())return null;let n=this.chunks[0],o=Math.min(e,n.length-this.head),r=n.subarray(this.head,this.head+o);return this.advance(o,n),r}async skip(e){let n=e;for(;n>0;){let o=await this.readSome(n);if(o===null)throw new Error("tar: truncated archive (unexpected end of stream)");n-=o.length}}take(e){let n=new Uint8Array(e),o=0;for(;o<e;){let r=this.chunks[0],i=Math.min(e-o,r.length-this.head);n.set(r.subarray(this.head,this.head+i),o),o+=i,this.advance(i,r)}return n}advance(e,n){this.head+=e,this.available-=e,this.head===n.length&&(this.chunks.shift(),this.head=0)}};function Wn(t){return(512-t%512)%512}y();var am=new Uint8Array([0]);function ma(t){let e=Array.from(t,o=>({pathBytes:Lu(o.path),entryDigest:o.entryDigest}));e.sort((o,r)=>Ou(o.pathBytes,r.pathBytes));let n=_.create();for(let o of e)n.update(o.entryDigest);return B.Buffer.from(n.digest()).toString("base64")}function Lu(t){if(t.includes("\0"))throw new TypeError("bitgraph-audit: bundle entry paths must not contain NUL bytes");return new TextEncoder().encode(t)}function Ou(t,e){let n=Math.min(t.length,e.length);for(let o=0;o<n;o++){let r=t[o]-e[o];if(r!==0)return r}return t.length-e.length}var ga=8*1024*1024,xa={maxTotalBytes:2*1024*1024*1024,maxEntryCount:1e6,maxMetadataEntryBytes:8*1024*1024},ba=new Uint8Array([0]),ya="manifest.json",Ar="bitgraph-bundle/1",Fu="bitgraph-anchor-witness/1";var Ea=new WeakMap;async function Ir(t,e){let n=[],o=0,r=0,i=[],s=new Map,a=Array.from(t).sort((f,u)=>f.path<u.path?-1:f.path>u.path?1:0);for(let f of a){r++;let u=Aa(f.path);if(u.unsafe){o++,n.push({code:"unsafe-path",path:f.path,message:`entry skipped: ${u.reason}`});continue}let d=await Ku(u.path,void 0,void 0,Ba(f.open()));i.push(Vu(u.path,d)),s.set(u.path,f)}let c=_u({bundlePath:e?.label??"",container:"memory",scanned:i,strippedRootPrefix:void 0,findings:n,entriesScanned:r,skippedUnsafePaths:o});return Ea.set(c,s),c}async function*Ba(t){let e=await Promise.resolve(t);if(e instanceof Uint8Array){yield e;return}for await(let n of t)yield n}async function Uu(t){let e=[],n=0;for await(let o of Ba(t.open()))e.push(o),n+=o.length;return Tr(e,n)}function _u(t){let{bundlePath:e,container:n,scanned:o,strippedRootPrefix:r,findings:i,entriesScanned:s,skippedUnsafePaths:a}=t,c=new Map;for(let S of o){let U=S.rawPath,F=S.entryDigestFull;r!==void 0&&(U=S.rawPath.slice(r.length+1),F=S.entryDigestStripped),c.has(U)&&i.push({code:"duplicate-path",path:U,message:"multiple archive entries normalized to the same path; the last entry wins"}),c.set(U,{path:U,sha256Hex:S.sha256Hex,byteLength:S.byteLength,entryDigest:F,...S.json!==void 0?{json:S.json}:{}})}let f=Array.from(c.values()),u=ma(f.filter(S=>S.path!==ya).map(S=>({path:S.path,entryDigest:S.entryDigest}))),d=[],h=new Map,l=[],m=[],p=new Map,w,b=0,k=0,v=0;for(let S of f){if(S.path===ya){w=Yu(S,u,i);continue}let F=qu(S.json)??S.json;if(F!==void 0&&Ia(F)){let G=F.version;if(G==="bitgraph/1"){b++;let q=Gu(S,F,h,d,i);q==="exact-duplicate"&&k++,q==="semantic-duplicate"&&v++;continue}l.push({code:"unsupported-version",path:S.path,version:G,fileSha256Hex:S.sha256Hex}),i.push({code:"unsupported-version",path:S.path,message:`proof-shaped file rejected: version "${G}" is not "bitgraph/1"`,details:{version:G}}),wa(S,p);continue}if(F!==void 0&&F.version===Fu){m.push({path:S.path,fileSha256Hex:S.sha256Hex,witness:F});continue}wa(S,p)}for(let S of d){let U=Zu(S.proof.artifact);if(U===null)continue;let F=p.get(U);F!==void 0&&F.matchedProofHashes.push(S.proofHash)}let O=Array.from(p.values()),z={observed:d.length,proofFiles:b,exactDuplicates:k,semanticDuplicates:v,unsupportedVersion:l.length,artifacts:O.length,witnesses:m.length,skippedUnsafePaths:a};return{bundlePath:e,container:n,...r!==void 0?{strippedRootPrefix:r}:{},entriesScanned:s,proofs:d,unsupportedVersions:l,artifacts:O,witnesses:m,...w!==void 0?{manifest:w}:{},computedContentsHashB64:u,findings:i,counts:z}}async function*kr(t){yield*va(t,t.artifacts.filter(e=>e.matchedProofHashes.length>0))}async function*Sr(t,e){let n=new Set(e);n.size!==0&&(yield*va(t,t.artifacts.filter(o=>n.has(o.sha256Hex))))}async function*va(t,e){if(e.length===0)return;if(t.container==="memory"){let s=Ea.get(t);if(s===void 0)return;for(let a of e)for(let c of a.paths){let f=s.get(c);if(f===void 0)continue;let u;try{u=await Uu(f)}catch{continue}if(Zn(_(u))===a.sha256Hex){yield{sha256Hex:a.sha256Hex,path:c,bytes:u};break}}return}if(t.container==="directory"){for(let s of e)for(let a of s.paths){let c;try{c=new Uint8Array(await rs(is(t.bundlePath,...a.split("/"))))}catch{continue}if(Zn(_(c))===s.sha256Hex){yield{sha256Hex:s.sha256Hex,path:a,bytes:c};break}}return}let n=new Map;for(let s of e)for(let a of s.paths)n.set(a,s);let o=new Set,{stream:r,close:i}=ju(t.bundlePath,t.container);try{for await(let s of la(r,xa)){if(o.size===e.length)break;if(s.kind!=="file")continue;let a=Aa(s.path);if(a.unsafe)continue;let c=a.path;if(t.strippedRootPrefix!==void 0){if(!c.startsWith(`${t.strippedRootPrefix}/`))continue;c=c.slice(t.strippedRootPrefix.length+1)}let f=n.get(c);if(f===void 0||o.has(f.sha256Hex))continue;let u=[],d=0;for await(let l of s.body)u.push(l.slice()),d+=l.length;let h=Tr(u,d);Zn(_(h))===f.sha256Hex&&(o.add(f.sha256Hex),yield{sha256Hex:f.sha256Hex,path:c,bytes:h})}}finally{i()}}function ju(t,e){let n=os(t);if(e==="tar-gz"){let o=ss();return n.pipe(o),n.on("error",r=>o.destroy(r)),{stream:o,close:()=>{o.destroy(),n.destroy()}}}return{stream:n,close:()=>n.destroy()}}async function Ku(t,e,n,o){let r=new TextEncoder,i=_.create(),s=_.create();s.update(r.encode(t)),s.update(ba);let a=e===void 0?void 0:_.create();a!==void 0&&(a.update(r.encode(e)),a.update(ba));let c=n===void 0||n<=ga,f=[],u=0;for await(let d of o)i.update(d),s.update(d),a?.update(d),u+=d.length,c&&(u>ga?(f.length=0,c=!1):f.push(d.slice()));return{sha256Hex:Zn(i.digest()),byteLength:u,entryDigestFull:s.digest(),...a!==void 0?{entryDigestStripped:a.digest()}:{},...c?{buffered:Tr(f,u)}:{}}}function Vu(t,e){let n=e.buffered===void 0?void 0:zu(e.buffered);return{rawPath:t,sha256Hex:e.sha256Hex,byteLength:e.byteLength,entryDigestFull:e.entryDigestFull,...e.entryDigestStripped!==void 0?{entryDigestStripped:e.entryDigestStripped}:{},...n!==void 0?{json:n}:{}}}function zu(t){let e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.subarray(3));let n;try{n=new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return}let o;try{o=JSON.parse(n)}catch{return}if(!(o===null||typeof o!="object"||Array.isArray(o)))return o}function Aa(t){if(t.includes("\0"))return{path:t,unsafe:!0,reason:"path contains a NUL byte"};let e=t.startsWith("/"),n=t.split("/").filter(r=>r!==""&&r!=="."),o=n.join("/");return e?{path:o,unsafe:!0,reason:"absolute path"}:n.some(r=>r==="..")?{path:o,unsafe:!0,reason:"path escapes the bundle root"}:o===""?{path:o,unsafe:!0,reason:"empty path"}:{path:o,unsafe:!1}}function re(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function qu(t){if(!re(t)||t.type!=="bitgraph-fuse/1")return;let e=t.proof;return Ia(e)?e:void 0}function Ia(t){return re(t)?typeof t.version=="string"&&re(t.artifact)&&re(t.commit)&&re(t.signer):!1}function Gu(t,e,n,o,r){let i=zn(e),s={path:t.path,fileSha256Hex:t.sha256Hex,byteLength:t.byteLength},a=Wu(e,i);a==="mismatch"&&r.push({code:"proofhash-mismatch",path:t.path,message:"embedded proofHash does not match the computed canonical proof hash",details:{embedded:e.proofHash,computed:i}});let c=n.get(i);if(c!==void 0){let w=c.sources.some(b=>b.fileSha256Hex===s.fileSha256Hex);return c.sources.push(s),a==="mismatch"&&(c.embeddedProofHash="mismatch"),r.push({code:w?"exact-duplicate":"semantic-duplicate",path:t.path,message:w?"byte-identical copy of an already observed proof":"different byte encoding of an already observed proof (same canonical identity)",details:{proofHash:i,firstObservedAt:c.sources[0].path}}),w?"exact-duplicate":"semantic-duplicate"}let f=re(e.commit)?e.commit:{},u=re(e.signer)?e.signer:{},d=re(e.environment)?e.environment:{},h=he(f.counter),l=he(f.epochId),m=he(f.chainId),p={proofHash:i,chainHash:sr(e),proof:e,sources:[s],version:"bitgraph/1",...h!==void 0?{counter:h}:{},...he(f.slotCounter)!==void 0?{slotCounter:he(f.slotCounter)}:{},...he(f.prevB64)!==void 0?{prevB64:he(f.prevB64)}:{},...l!==void 0?{epochId:l}:{},chainId:m!==void 0&&m.length>0?m:"global",...he(u.publicKeyB64)!==void 0?{publicKeyB64:he(u.publicKeyB64)}:{},...he(d.measurement)!==void 0?{measurement:he(d.measurement)}:{},...he(d.enforcement)!==void 0?{enforcement:he(d.enforcement)}:{},hasSlotAllocation:re(e.slotAllocation),hasAttestation:re(d.attestation),hasAgency:re(e.agency),hasEpochLink:re(f.epochLink),embeddedProofHash:a,chainless:h===void 0&&l===void 0};return n.set(i,p),o.push(p),"new"}function Wu(t,e){let n=t.proofHash;return n===void 0?"absent":typeof n=="string"&&n===e?"match":"mismatch"}function he(t){return typeof t=="string"?t:void 0}function wa(t,e){let n=e.get(t.sha256Hex);if(n!==void 0){n.paths.push(t.path);return}e.set(t.sha256Hex,{sha256Hex:t.sha256Hex,sha256B64:B.Buffer.from(t.sha256Hex,"hex").toString("base64"),byteLength:t.byteLength,paths:[t.path],matchedProofHashes:[]})}function Zu(t){if(!re(t))return null;let e=t.digestB64;if(typeof e!="string"||e.length===0)return null;let n=B.Buffer.from(e,"base64");return n.toString("base64")!==e||n.length!==32?null:n.toString("hex")}function Yu(t,e,n){if(t.json===void 0)return n.push({code:"manifest-unparseable",path:t.path,message:"root manifest.json did not parse as a single JSON object; proceeding as if no manifest were present"}),{path:t.path,parsed:!1,recognized:!1,problems:[]};let o=t.json,r=o.version;if(r!==Ar)return n.push({code:"manifest-unrecognized-version",path:t.path,message:`manifest version ${JSON.stringify(r)} is not "${Ar}"; the manifest was not interpreted`,...typeof r=="string"?{details:{version:r}}:{}}),{path:t.path,parsed:!0,...typeof r=="string"?{version:r}:{},recognized:!1,problems:[]};let i=Xu(o);for(let c of i)n.push({code:"manifest-field-invalid",path:t.path,message:c});let s={path:t.path,parsed:!0,version:Ar,recognized:!0,manifest:o,problems:i},a=o.contentsHashB64;if(typeof a=="string"&&a.length>0){let c=a===e;s.contentsHash={declaredB64:a,computedB64:e,match:c},c||n.push({code:"manifest-contents-hash-mismatch",path:t.path,message:"manifest contentsHashB64 does not match the computed contents hash; the bundle held is not byte-for-byte the bundle the manifest describes. Advisory: this does not fail any proof.",details:{declared:a,computed:e}})}return s}function Xu(t){let e=[],n=o=>Array.isArray(o)&&o.every(r=>typeof r=="string");if(t.epochIds!==void 0&&!n(t.epochIds)&&e.push("manifest.epochIds must be an array of strings when present"),t.chainIds!==void 0&&!n(t.chainIds)&&e.push("manifest.chainIds must be an array of strings when present"),t.proofCount!==void 0&&(typeof t.proofCount!="number"||!Number.isInteger(t.proofCount)||t.proofCount<0)&&e.push("manifest.proofCount must be a non-negative integer when present"),t.counterRanges!==void 0&&(Array.isArray(t.counterRanges)&&t.counterRanges.every(r=>re(r)&&typeof r.epochId=="string"&&typeof r.chainId=="string"&&typeof r.min=="string"&&typeof r.max=="string")||e.push("manifest.counterRanges must be an array of { epochId, chainId, min, max } string fields when present")),t.generatedAt!==void 0&&typeof t.generatedAt!="string"&&e.push("manifest.generatedAt must be a string when present"),t.contentsHashB64!==void 0){let o=t.contentsHashB64,r=typeof o=="string"&&o.length>0;if(r){let i=B.Buffer.from(o,"base64");r=i.toString("base64")===o&&i.length===32}r||e.push("manifest.contentsHashB64 must be standard base64 of 32 bytes when present")}return t.artifactsIncluded!==void 0&&typeof t.artifactsIncluded!="boolean"&&e.push("manifest.artifactsIncluded must be a boolean when present"),t.openEpochs!==void 0&&(Array.isArray(t.openEpochs)&&t.openEpochs.every(r=>re(r)&&typeof r.epochId=="string"&&typeof r.counterAtSnapshot=="string")||e.push("manifest.openEpochs must be an array of { epochId, counterAtSnapshot } string fields when present")),e}function Zn(t){return B.Buffer.from(t).toString("hex")}function Tr(t,e){let n=new Uint8Array(e),o=0;for(let r of t)n.set(r,o),o+=r.length;return n}y();async function Hr(t,e){Ke();let n=e?.trustAnchors,o=new Map(t.proofs.map(f=>[f.proofHash,f])),r=new Map;for(let f of t.artifacts){if(f.matchedProofHashes.length===0)continue;let u=f.matchedProofHashes.map(d=>o.get(d)).filter(d=>d!==void 0);r.set(f.sha256Hex,u)}for await(let f of kr(t)){let u=r.get(f.sha256Hex)??[];for(let d of u){if(d.verification!==void 0)continue;let h=await ir({proof:d.proof,bytes:f.bytes,...n!==void 0?{trustAnchors:n}:{}}),l={tier:"full",status:h.valid?"verified":"failed",...h.reason!==void 0?{reason:h.reason}:{},artifactPath:f.path};d.verification=l}}for(let f of t.proofs){if(f.verification!==void 0)continue;let u=await it({proof:f.proof,...n!==void 0?{trustAnchors:n}:{}}),d={tier:"integrity",status:u.valid?"artifact-unavailable":"failed",...u.reason!==void 0?{reason:u.reason}:{}};f.verification=d}let i=0,s=0,a=0,c=0;for(let f of t.proofs){let u=f.verification?.status;u==="verified"?i++:u==="failed"?s++:u==="artifact-unavailable"&&a++,f.chainless&&c++}return{total:t.proofs.length,verified:i,failed:s,artifactUnavailable:a,chainless:c}}y();y();var ka=new WeakMap;async function qe(t){let e=t.verification?.status;if(e==="verified"||e==="artifact-unavailable")return!0;let n=ka.get(t);if(n!==void 0)return n;Ke();let o=!1;try{o=(await it({proof:t.proof})).valid}catch{o=!1}return Ke(),ka.set(t,o),o}function Y(t){if(!(t===void 0||t.length===0||!/^[0-9]+$/.test(t)))return BigInt(t)}function Pe(t,e){let n=Y(t.counter),o=Y(e.counter);return n!==void 0&&o!==void 0&&n!==o?n<o?-1:1:n!==void 0&&o===void 0?-1:n===void 0&&o!==void 0?1:t.proofHash<e.proofHash?-1:t.proofHash>e.proofHash?1:0}function ue(t,e,n){let o=t.get(e);o===void 0?t.set(e,[n]):o.push(n)}async function Rr(t){let e=[],n=[],o=new Map;for(let f of t.proofs){if(f.chainless){e.push(f.proofHash);continue}if(f.publicKeyB64===void 0){n.push(f.proofHash);continue}let u={publicKeyB64:f.publicKeyB64,...f.epochId!==void 0?{epochId:f.epochId}:{},chainId:f.chainId},d=JSON.stringify([u.publicKeyB64,u.epochId??null,u.chainId]),h=o.get(d);h===void 0?o.set(d,{key:u,members:[f]}):h.members.push(f)}let r=[...o.values()].sort((f,u)=>Ju(f.key,u.key)),i=[],s=new Set,a=new Map;for(let f of r){let u=Qu(f.key,f.members,s);i.push(u);for(let d of u.memberProofHashes)a.set(d,f.key)}let c=await nd(t,i,s,a);return{partitions:i,unchainedProofHashes:e,unpartitionedProofHashes:n,epochRelationships:c}}function Ju(t,e){if(t.chainId!==e.chainId)return t.chainId<e.chainId?-1:1;let n=t.epochId??"",o=e.epochId??"";return n!==o?n<o?-1:1:t.publicKeyB64!==e.publicKeyB64?t.publicKeyB64<e.publicKeyB64?-1:1:0}function Qu(t,e,n){let o=new Map(e.map(h=>[h.chainHash,h])),r=new Map,i=new Set,s=new Map;for(let h of e)s.set(h.proofHash,h.proofHash);let a=h=>{let l=h;for(;s.get(l)!==l;)l=s.get(l);let m=h;for(;m!==l;){let p=s.get(m);s.set(m,l),m=p}return l},c=(h,l)=>{let m=a(h),p=a(l);m!==p&&s.set(m,p)};for(let h of e){if(h.prevB64===void 0)continue;let l=o.get(h.prevB64);l===void 0||l.proofHash===h.proofHash||(i.add(h.proofHash),ue(r,l.proofHash,h),n.add(l.proofHash),c(l.proofHash,h.proofHash))}let f=new Map;for(let h of e)ue(f,a(h.proofHash),h);let u=[];for(let h of f.values())u.push(ed(h,r,i));u.sort(td);let d=[...e].sort(Pe).map(h=>h.proofHash);return{key:t,memberProofHashes:d,components:u}}function ed(t,e,n){let o=[...t].sort(Pe),r=o.filter(h=>h.prevB64===void 0),i=o.filter(h=>h.prevB64!==void 0&&!n.has(h.proofHash)),s=o.filter(h=>(e.get(h.proofHash)??[]).length===0),a=new Set,c=[],f=h=>{let l=[h];for(;l.length>0;){let m=l.pop();if(a.has(m))continue;a.add(m),c.push(m);let p=[...e.get(m)??[]].sort(Pe);for(let w=p.length-1;w>=0;w--)l.push(p[w].proofHash)}};for(let h of[...r,...i])f(h.proofHash);for(let h of o)a.has(h.proofHash)||f(h.proofHash);let u,d;for(let h of t)for(let l of[h.counter,h.slotCounter]){let m=Y(l);m!==void 0&&((u===void 0||m<u)&&(u=m),(d===void 0||m>d)&&(d=m))}return{memberProofHashes:c,genesisProofHashes:r.map(h=>h.proofHash),brokenLinkProofHashes:i.map(h=>h.proofHash),terminalProofHashes:s.map(h=>h.proofHash),hasCounterEvidence:u!==void 0,...u!==void 0&&d!==void 0?{positionRange:{min:String(u),max:String(d)}}:{}}}function td(t,e){let n=t.positionRange?.min,o=e.positionRange?.min;if(n!==void 0&&o!==void 0&&n!==o)return BigInt(n)<BigInt(o)?-1:1;if(n!==void 0&&o===void 0)return-1;if(n===void 0&&o!==void 0)return 1;let r=t.memberProofHashes[0]??"",i=e.memberProofHashes[0]??"";return r<i?-1:r>i?1:0}async function nd(t,e,n,o){let r=new Map;for(let h of e){let l=h.key.epochId;if(l===void 0)continue;let m=r.get(l);m===void 0&&(m={chainIds:new Set,publicKeys:new Set,proofCount:0},r.set(l,m)),m.chainIds.add(h.key.chainId),m.publicKeys.add(h.key.publicKeyB64),m.proofCount+=h.memberProofHashes.length}let i=new Map(t.proofs.map(h=>[h.chainHash,h])),s=[];for(let h of t.proofs){if(!h.hasEpochLink)continue;let l=od(h);l!==null&&s.push(await rd(l,h,i,r,n,o))}let a=sd(s),c=new Set,f=new Map,u=new Map;for(let h of s)h.hardEdge&&(c.add(h.fromEpochId),c.add(h.toEpochId),Cr(f,h.toEpochId,h.fromEpochId),Cr(u,h.fromEpochId,h.toEpochId));return{epochs:[...r.entries()].sort(([h],[l])=>h<l?-1:h>l?1:0).map(([h,l])=>({epochId:h,chainIds:[...l.chainIds].sort(),publicKeysB64:[...l.publicKeys].sort(),proofCount:l.proofCount,ordering:c.has(h)?"linked":"observed-but-unordered",linkedPredecessorEpochIds:[...f.get(h)??[]].sort(),linkedSuccessorEpochIds:[...u.get(h)??[]].sort()})),edges:s,orderedPairs:a}}function od(t){let e=t.proof.commit;if(e===null||typeof e!="object")return null;let n=e.epochLink;if(n===null||typeof n!="object"||Array.isArray(n))return null;let o=n,r=["prevEpochId","prevPublicKeyB64","prevCounter","prevProofHashB64","toEpochId","toPublicKeyB64"],i={};for(let s of r){let a=o[s];if(typeof a!="string"||a.length===0)return null;i[s]=a}return i}async function rd(t,e,n,o,r,i){let s=await qe(e),a=n.get(t.prevProofHashB64);if(a===void 0){let h=o.has(t.prevEpochId);return{fromEpochId:t.prevEpochId,toEpochId:t.toEpochId,viaProofHash:e.proofHash,link:t,resolution:h?"terminal-missing":"dangling",viaProofValid:s,hardEdge:!1}}let c=[];a.epochId!==t.prevEpochId&&c.push(`the referenced proof's epochId (${a.epochId??"absent"}) does not match epochLink.prevEpochId (${t.prevEpochId})`),a.publicKeyB64!==t.prevPublicKeyB64&&c.push("the referenced proof's signer key does not match epochLink.prevPublicKeyB64"),id(a.counter,t.prevCounter)||c.push(`the referenced proof's counter (${a.counter??"absent"}) does not match epochLink.prevCounter (${t.prevCounter})`);let f=await qe(a),u=c.length===0,d=i.has(a.proofHash);return{fromEpochId:t.prevEpochId,toEpochId:t.toEpochId,viaProofHash:e.proofHash,link:t,resolution:"matched",predecessorProofHash:a.proofHash,metadataConsistent:u,...u?{}:{inconsistencies:c},...d?{referencedProofIsTerminal:!r.has(a.proofHash)}:{},viaProofValid:s,predecessorValid:f,hardEdge:u&&s&&f}}function id(t,e){if(t===void 0)return!1;if(t===e)return!0;let n=Y(t),o=Y(e);return n!==void 0&&o!==void 0&&n===o}function sd(t){let e=new Map,n=new Set;for(let i of t)i.hardEdge&&(Cr(e,i.fromEpochId,i.toEpochId),n.add(i.fromEpochId),n.add(i.toEpochId));let o=new Set;for(let i of n){let s=new Set,a=[...e.get(i)??[]];for(;a.length>0;){let c=a.pop();if(!s.has(c)){s.add(c);for(let f of e.get(c)??[])a.push(f)}}for(let c of s)c!==i&&o.add(`${i}\0${c}`)}let r=[];for(let i of o){let[s,a]=i.split("\0");o.has(`${a}\0${s}`)||r.push({beforeEpochId:s,afterEpochId:a})}return r.sort((i,s)=>i.beforeEpochId!==s.beforeEpochId?i.beforeEpochId<s.beforeEpochId?-1:1:i.afterEpochId<s.afterEpochId?-1:i.afterEpochId>s.afterEpochId?1:0),r}function Cr(t,e,n){let o=t.get(e);o===void 0?t.set(e,new Set([n])):o.add(n)}y();var ad=1e4;async function $r(t,e){let n=[],o=[],r=[],i=new Map(t.proofs.map(c=>[c.proofHash,c])),s=new Map(t.proofs.map(c=>[c.chainHash,c])),a=new Map;for(let c of e.partitions)for(let f of c.memberProofHashes)a.set(f,c.key);for(let c of e.partitions){let f=c.memberProofHashes.map(u=>i.get(u));cd(c,f,n),await Sa(c,f,"counter",n,o),await Sa(c,f,"slot",n,o),await fd(c,f,n,o),await ud(c,f,s,n,o),dd(c,f,s,a,n,r),await ld(c,f,n,o),pd(c,f,n)}return await md(e.epochRelationships.edges,i,n,o),{anomalies:n,divergences:o,boundaryEntryPoints:r}}function cd(t,e,n){let o=new Set;for(let d of e){let h=Y(d.counter);h!==void 0&&o.add(h);let l=Y(d.slotCounter);l!==void 0&&o.add(l)}if(o.size<2)return;let r=[...o].sort((d,h)=>d<h?-1:d>h?1:0),i=[],s=[],a=0n;for(let d=1;d<r.length;d++){let h=r[d-1]+1n,l=r[d]-1n;if(!(h>l)){i.push({start:String(h),end:String(l)}),a+=l-h+1n;for(let m=h;m<=l&&s.length<ad;m++)s.push(String(m))}}if(i.length===0)return;let c={count:String(a),ranges:i,positions:s,truncated:a>BigInt(s.length)},f=String(r[0]),u=String(r[r.length-1]);n.push({code:"unexplained-counter-positions",partition:t.key,proofHashes:[],message:`${a} counter position${a===1n?"":"s"} within the observed range [${f}, ${u}] of this partition ${a===1n?"is":"are"} neither a commit position nor a referenced slot position in the supplied bundle. Such ${a===1n?"a position":"positions"} may mean a proof is absent from the bundle, or a slot that was allocated but never committed (a routine, benign occurrence); this offline audit cannot distinguish the two. It does not, by itself, establish that the authority failed to create or withheld any proof.`,details:c})}async function Sa(t,e,n,o,r){let i=new Map;for(let s of e){let a=n==="counter"?s.counter:s.slotCounter;if(a===void 0)continue;let c=Y(a);ue(i,c!==void 0?String(c):`raw:${a}`,s)}for(let[s,a]of Pr(i)){if(a.length<2)continue;let{parties:c,context:f}=await Yn(a);if(c.length<2)continue;let u=s.startsWith("raw:")?s.slice(4):s,d=n==="counter"?"counter-collision":"slot-collision";o.push({code:d,partition:t.key,proofHashes:a.map(h=>h.proofHash),message:n==="counter"?`${c.length} distinct valid proofs claim commit counter ${u} in one partition. The audit does not choose between them; all parties are preserved for adjudication.`:`${c.length} distinct valid proofs reference slot counter ${u} in one partition. A slot position is consumed exactly once; all parties are preserved for adjudication.`,details:{position:u,validParties:c.map(h=>h.proofHash),invalidObserved:f.map(h=>h.proofHash)}}),r.push({kind:d,partition:t.key,contested:n==="counter"?{counter:u}:{slotCounter:u},parties:c.map(De),invalidContext:f.map(De),explanation:n==="counter"?`Two or more independently valid proof objects claim commit counter ${u} in the same signer, epoch, and chain partition. A commit counter position can be consumed only once, so at most one of these can belong to the authoritative sequence. The audit tool does not choose between them; every party and its predecessor relationship is preserved for adjudication.`:`Two or more independently valid proof objects reference slot counter ${u} in the same signer, epoch, and chain partition. A slot position is allocated once and consumed by one commit, so at most one of these can belong to the authoritative sequence. The audit tool does not choose between them.`})}}async function fd(t,e,n,o){let r=new Map,i=new Map;for(let a of e){let c=Y(a.counter);c!==void 0&&ue(r,String(c),a);let f=Y(a.slotCounter);f!==void 0&&ue(i,String(f),a)}let s=[...r.keys()].filter(a=>i.has(a)).sort((a,c)=>BigInt(a)<BigInt(c)?-1:BigInt(a)>BigInt(c)?1:0);for(let a of s){let c=r.get(a),f=i.get(a),u=[];for(let b of c)await qe(b)&&u.push(b);let d=[];for(let b of f)await qe(b)&&d.push(b);if(!u.some(b=>d.some(k=>k.proofHash!==b.proofHash)))continue;let l=new Map;for(let b of[...u,...d])l.set(b.proofHash,b);let m=[...l.values()],p=new Map;for(let b of[...c,...f])p.set(b.proofHash,b);let w=[...p.values()].filter(b=>!l.has(b.proofHash));n.push({code:"cross-kind-position-reuse",partition:t.key,proofHashes:[...p.keys()],message:`Counter position ${a} is committed by one proof and reserved as a slot by a different proof in the same partition. A single causal position is consumed once, as a slot or as a commit, never both across distinct proofs. The audit does not choose between them; all parties are preserved for adjudication.`,details:{position:a,commitParties:u.map(b=>b.proofHash),slotParties:d.map(b=>b.proofHash),validParties:m.map(b=>b.proofHash),invalidObserved:w.map(b=>b.proofHash)}}),o.push({kind:"cross-kind-position-reuse",partition:t.key,contested:{position:a},parties:m.map(De),invalidContext:w.map(De),explanation:`Two or more independently valid proof objects allocate counter position ${a} in the same signer, epoch, and chain partition through different roles: at least one commits at it and at least one reserves it as a slot. Each position in a chain is consumed exactly once, so at most one of these allocations can belong to the authoritative sequence. This pattern only arises through enclave malfunction, replay, or compromise. The audit tool does not choose between them; every party is preserved for adjudication.`})}}async function ud(t,e,n,o,r){let i=new Map;for(let s of e)s.prevB64!==void 0&&ue(i,s.prevB64,s);for(let[s,a]of Pr(i)){if(a.length<2)continue;let{parties:c,context:f}=await Yn(a);if(c.length<2)continue;let u=n.has(s);o.push({code:"predecessor-reuse",partition:t.key,proofHashes:a.map(d=>d.proofHash),message:`${c.length} distinct valid proofs claim the same predecessor hash: a detectable fork. All branches are preserved; the audit does not choose between them.`,details:{prevB64:s,predecessorObserved:u,validParties:c.map(d=>d.proofHash),invalidObserved:f.map(d=>d.proofHash)}}),r.push({kind:"predecessor-reuse",partition:t.key,contested:{prevB64:s},parties:c.map(De),invalidContext:f.map(De),explanation:`Two or more independently valid proof objects name the same predecessor proof in their prevB64 hash link. Each proof has exactly one successor in an intact chain, so this is a fork: the history diverges into multiple branches at that predecessor${u?", which is itself observed in the bundle":", which is absent from the bundle"}. All branches are shown; the audit tool does not select one.`})}}function dd(t,e,n,o,r,i){let s=new Set(e.map(c=>c.chainHash)),a;for(let c of e){let f=Y(c.counter);f!==void 0&&(a===void 0||f<a)&&(a=f)}for(let c of[...e].sort(Pe)){if(c.prevB64===void 0||s.has(c.prevB64))continue;if(!hd(c.prevB64)){r.push({code:"chain-break-malformed",partition:t.key,proofHashes:[c.proofHash],message:"commit.prevB64 is not standard base64 of 32 bytes, so it can never match a canonical proof hash. The predecessor link is unusable as reconstruction evidence.",details:{prevB64:c.prevB64}});continue}let f=n.get(c.prevB64);if(f!==void 0){let h=o.get(f.proofHash);r.push({code:"chain-break-cross-partition",partition:t.key,proofHashes:[c.proofHash,f.proofHash],message:"commit.prevB64 resolves to an observed proof outside this proof's own signer, epoch, and chain partition. prevB64 never bridges partitions (each epoch and chain keeps its own hash chain), so this link does not join the two.",details:{prevB64:c.prevB64,predecessorProofHash:f.proofHash,predecessorPartition:h!==void 0?{publicKeyB64:h.publicKeyB64,...h.epochId!==void 0?{epochId:h.epochId}:{},chainId:h.chainId}:"unchained-or-unpartitioned"}});continue}let u=Y(c.counter);if(u===void 0||a===void 0||u<=a){i.push({partition:t.key,proofHash:c.proofHash,prevB64:c.prevB64});continue}r.push({code:"chain-break-missing",partition:t.key,proofHashes:[c.proofHash],message:"commit.prevB64 references a predecessor proof that is absent from the supplied bundle, and a lower-positioned proof IS present, so this is an interior break (a hole), not the excerpt's starting boundary. The chain cannot be reconstructed across this link from the supplied evidence; this does not, by itself, establish that the predecessor never existed.",details:{prevB64:c.prevB64}})}}function hd(t){if(t.length===0)return!1;let e=B.Buffer.from(t,"base64");return e.length===32&&e.toString("base64")===t}async function ld(t,e,n,o){let r=[...e.filter(a=>a.prevB64===void 0)].sort(Pe);if(r.length<2)return;let{parties:i,context:s}=await Yn(r);n.push({code:"multiple-genesis",partition:t.key,proofHashes:r.map(a=>a.proofHash),message:`${r.length} proofs in one partition carry no prevB64 link. An epoch has exactly one first proof, so at most one of these can be the genesis of this partition's chain.`,details:{validParties:i.map(a=>a.proofHash),invalidObserved:s.map(a=>a.proofHash)}}),!(i.length<2)&&o.push({kind:"multiple-genesis",partition:t.key,contested:{...t.key.epochId!==void 0?{epochId:t.key.epochId}:{},chainId:t.key.chainId},parties:i.map(De),invalidContext:s.map(De),explanation:"Two or more independently valid proof objects in the same signer, epoch, and chain partition carry no predecessor link, each presenting itself as the first proof of the chain. An epoch has exactly one first proof, so at most one of these can be the genesis. The audit tool does not choose between them."})}function pd(t,e,n){for(let o of[...e].sort(Pe)){let r=Y(o.slotCounter),i=Y(o.counter);r===void 0||i===void 0||r<i||n.push({code:"slot-order-violation",partition:t.key,proofHashes:[o.proofHash],message:"commit.slotCounter is not strictly less than commit.counter. The slot must be allocated before the commit that consumes it, so this proof's declared positions contradict the nonce-first construction order.",details:{slotCounter:o.slotCounter,counter:o.counter}})}}async function md(t,e,n,o){for(let s of t)s.resolution==="terminal-missing"?n.push({code:"epochlink-terminal-missing",proofHashes:[s.viaProofHash],message:"commit.epochLink references a prior epoch that is observed in the bundle, but the referenced terminal proof is absent from the bundle. The lineage claim cannot be confirmed from the supplied evidence; this does not, by itself, establish that the terminal never existed.",details:{link:{...s.link}}}):s.resolution==="dangling"?n.push({code:"epochlink-dangling",proofHashes:[s.viaProofHash],message:"commit.epochLink references a prior epoch and terminal proof, neither of which is observed in the bundle. The lineage claim dangles into unobserved history; it cannot be confirmed from the supplied evidence.",details:{link:{...s.link}}}):s.metadataConsistent===!1&&n.push({code:"epochlink-mismatch",proofHashes:[s.viaProofHash,...s.predecessorProofHash!==void 0?[s.predecessorProofHash]:[]],message:"commit.epochLink's prevProofHashB64 matches an observed proof, but the link's declared epoch, signer key, or counter disagrees with that proof. The hash reference and the declared metadata cannot both be right.",details:{link:{...s.link},inconsistencies:s.inconsistencies??[]}});let r=new Map;for(let s of t)ue(r,`${s.link.prevEpochId}|${s.link.prevCounter}|${s.link.prevProofHashB64}`,s);for(let[,s]of Pr(r)){let a=new Set(s.map(h=>h.link.toEpochId));if(a.size<2)continue;let c=s.map(h=>e.get(h.viaProofHash)),{parties:f,context:u}=await Yn(c),d=s[0].link;n.push({code:"epochlink-fork",proofHashes:s.map(h=>h.viaProofHash),message:`The same predecessor terminal (epoch ${d.prevEpochId}, counter ${d.prevCounter}) is consumed by genesis proofs of ${a.size} distinct successor epochs. A predecessor may be consumed by at most one successor epoch, so this is a detectable fork at the epoch boundary. All branches are preserved.`,details:{prevEpochId:d.prevEpochId,prevCounter:d.prevCounter,prevProofHashB64:d.prevProofHashB64,successorEpochIds:[...a].sort(),validParties:f.map(h=>h.proofHash),invalidObserved:u.map(h=>h.proofHash)}}),!(f.length<2)&&o.push({kind:"epochlink-fork",contested:{prevEpochId:d.prevEpochId,prevCounter:d.prevCounter,prevProofHashB64:d.prevProofHashB64},parties:f.map(De),invalidContext:u.map(De),explanation:"Two or more independently valid epoch-genesis proofs consume the same terminal proof of a prior epoch through their epochLink. The single-successor rule allows a terminal to be consumed by exactly one successor epoch, so at most one of these lineages can be the authoritative continuation. Note that whichever party verified second in this run carries a fork-detection failure from the canonical verifier; that ordering is an artifact of verification order, not evidence of which branch is authoritative. The audit tool does not choose between them."})}let i=new Map;for(let s of t){if(s.resolution!=="matched")continue;let a=i.get(s.fromEpochId);a===void 0?i.set(s.fromEpochId,new Set([s.toEpochId])):a.add(s.toEpochId)}for(let s of gd(i)){let a=t.filter(c=>c.resolution==="matched"&&s.includes(c.fromEpochId)&&s.includes(c.toEpochId)).map(c=>c.viaProofHash);n.push({code:"epochlink-cycle",proofHashes:a,message:`Epoch lineage links form a cycle among ${s.length} epochs. Each link claims its successor epoch came after its predecessor, so a cycle means these ordering claims contradict each other; no ordering is asserted for the epochs involved.`,details:{epochIds:s}})}}function gd(t){let e=new Map,n=new Set,o=[...t.keys()].sort();for(let r of o){if(n.has(r))continue;let i=[],s=new Set,a=new Map,c=[r];for(;c.length>0;){let f=c[c.length-1];s.has(f)||(s.add(f),i.push(f),a.set(f,[...t.get(f)??[]].sort()));let d=a.get(f).shift();if(d===void 0){c.pop(),s.delete(f),i.pop(),n.add(f);continue}if(s.has(d)){let h=i.indexOf(d),l=i.slice(h),m=bd(l);e.set(m.join("|"),m);continue}n.has(d)||c.push(d)}}return[...e.values()].sort((r,i)=>{let s=r.join("|"),a=i.join("|");return s<a?-1:s>a?1:0})}function bd(t){let e=0;for(let n=1;n<t.length;n++)t[n]<t[e]&&(e=n);return[...t.slice(e),...t.slice(0,e)]}async function Yn(t){let e=[],n=[];for(let o of t)await qe(o)?e.push(o):n.push(o);return{parties:e,context:n}}function De(t){let e=t.verification;return{proofHash:t.proofHash,sourcePaths:t.sources.map(n=>n.path),...e!==void 0?{verificationTier:e.tier,verificationStatus:e.status,...e.reason!==void 0?{verificationReason:e.reason}:{}}:{},...t.counter!==void 0?{counter:t.counter}:{},...t.slotCounter!==void 0?{slotCounter:t.slotCounter}:{},...t.prevB64!==void 0?{prevB64:t.prevB64}:{},...t.publicKeyB64!==void 0?{publicKeyB64:t.publicKeyB64}:{},...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.measurement!==void 0?{measurement:t.measurement}:{}}}function Pr(t){return[...t.entries()].sort(([e],[n])=>{let o=/^[0-9]+$/.test(e)?BigInt(e):void 0,r=/^[0-9]+$/.test(n)?BigInt(n):void 0;return o!==void 0&&r!==void 0&&o!==r?o<r?-1:1:o!==void 0&&r===void 0?-1:o===void 0&&r!==void 0?1:e<n?-1:e>n?1:0})}y();function Dr(t){let e=new Map;for(let a of t.proofs){let c=JSON.stringify([a.measurement??null,a.publicKeyB64??null,a.epochId??null,a.chainId,a.hasAttestation]),f=e.get(c);if(f!==void 0){f.proofHashes.push(a.proofHash);continue}e.set(c,{...a.measurement!==void 0?{measurement:a.measurement}:{},...a.publicKeyB64!==void 0?{publicKeyB64:a.publicKeyB64}:{},...a.epochId!==void 0?{epochId:a.epochId}:{},chainId:a.chainId,attestationPresent:a.hasAttestation,proofHashes:[a.proofHash]})}let n=[...e.values()].sort(yd),o=new Map;for(let a of t.proofs)a.epochId!==void 0&&ue(o,a.epochId,a);let r=[];for(let[a,c]of[...o.entries()].sort(([f],[u])=>f<u?-1:f>u?1:0)){let f=new Set,u=new Set;for(let d of c)d.publicKeyB64!==void 0&&f.add(d.publicKeyB64),d.measurement!==void 0&&u.add(d.measurement);f.size>=2&&r.push({code:"mid-epoch-signer-change",proofHashes:c.map(d=>d.proofHash),message:`${f.size} distinct signer keys appear within epoch ${a}. A single enclave boot generates exactly one keypair per epoch, so multiple keys under one epochId cannot come from one healthy authority lifecycle. All key groups are preserved for adjudication.`,details:{epochId:a,publicKeysB64:[...f].sort()}}),u.size>=2&&r.push({code:"mid-epoch-measurement-change",proofHashes:c.map(d=>d.proofHash),message:`${u.size} distinct declared measurements appear within epoch ${a}. A single enclave boot has exactly one measurement, so multiple declared measurements under one epochId cannot come from one healthy authority lifecycle. Declared measurements are self-reported; attestation validation is reported separately.`,details:{epochId:a,measurements:[...u].sort()}})}let i=new Map;for(let a of t.proofs){if(a.publicKeyB64===void 0||a.epochId===void 0)continue;let c=i.get(a.publicKeyB64);c===void 0?i.set(a.publicKeyB64,new Set([a.epochId])):c.add(a.epochId)}let s=[...i.entries()].filter(([,a])=>a.size>=2).map(([a,c])=>({publicKeyB64:a,epochIds:[...c].sort()})).sort((a,c)=>a.publicKeyB64<c.publicKeyB64?-1:a.publicKeyB64>c.publicKeyB64?1:0);return{groups:n,anomalies:r,sharedSignersAcrossEpochs:s}}function yd(t,e){if(t.chainId!==e.chainId)return t.chainId<e.chainId?-1:1;let n=t.epochId??"",o=e.epochId??"";if(n!==o)return n<o?-1:1;let r=t.publicKeyB64??"",i=e.publicKeyB64??"";if(r!==i)return r<i?-1:1;let s=t.measurement??"",a=e.measurement??"";return s!==a?s<a?-1:1:t.attestationPresent!==e.attestationPresent?t.attestationPresent?-1:1:0}y();var wd="Ethereum Anchor",Ta="ethereum-anchor",xd=/^https:\/\/etherscan\.io\/block\/([0-9]+)$/;function Lr(t){let e=[],n=[],o=[];for(let r of t.proofs){let i=Nr(r,"name"),s=Ed(r);if(!(i===wd)){s===Ta&&(n.push(r.proofHash),o.push({code:"anchor-metadata-only-claim",...Mr(r),message:"unsigned metadata.type claims ethereum-anchor, but the signed attribution does not identify this proof as an anchor. Metadata is advisory and unsigned; the proof is not treated as an anchor.",details:{proofHash:r.proofHash}}));continue}let c=s===Ta?"agrees":s===void 0?"absent":"disagrees";c==="disagrees"&&o.push({code:"anchor-metadata-disagreement",...Mr(r),message:`signed attribution identifies an Ethereum anchor, but unsigned metadata.type is ${JSON.stringify(s)}. The signed field governs; the disagreement is recorded.`,details:{proofHash:r.proofHash,metadataType:s}});let f=Nr(r,"message"),u=Nr(r,"title"),d=u!==void 0?xd.exec(u)?.[1]??void 0:void 0;d===void 0&&o.push({code:"anchor-title-unparseable",...Mr(r),message:u===void 0?"anchor proof carries no signed attribution.title; the signed block number is absent":"anchor attribution.title does not parse as an Etherscan block URL; the signed block number is treated as absent",details:{proofHash:r.proofHash,...u!==void 0?{title:u}:{}}});let h=r.verification;e.push({proofHash:r.proofHash,...r.epochId!==void 0?{epochId:r.epochId}:{},chainId:r.chainId,...r.counter!==void 0?{counter:r.counter}:{},...r.slotCounter!==void 0?{slotCounter:r.slotCounter}:{},...f!==void 0?{blockHash:f}:{},...d!==void 0?{blockNumber:d}:{},metadataCorroboration:c,...h!==void 0?{verificationTier:h.tier,verificationStatus:h.status,...h.reason!==void 0?{verificationReason:h.reason}:{}}:{}})}return{anchors:e,metadataOnlyProofHashes:n,findings:o}}function Nr(t,e){let n=t.proof.attribution;if(n===null||typeof n!="object"||Array.isArray(n))return;let o=n[e];return typeof o=="string"?o:void 0}function Ed(t){let e=t.proof.metadata;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.type;return typeof n=="string"?n:void 0}function Mr(t){let e=t.sources[0]?.path;return e!==void 0?{path:e}:{}}y();y();var Bd=BigInt(0),rn=BigInt(1),vd=BigInt(2),Ad=BigInt(7),Id=BigInt(256),kd=BigInt(113),Ra=[],$a=[],Pa=[];for(let t=0,e=rn,n=1,o=0;t<24;t++){[n,o]=[o,(2*n+3*o)%5],Ra.push(2*(5*o+n)),$a.push((t+1)*(t+2)/2%64);let r=Bd;for(let i=0;i<7;i++)e=(e<<rn^(e>>Ad)*kd)%Id,e&vd&&(r^=rn<<(rn<<BigInt(i))-rn);Pa.push(r)}var Da=Bn(Pa,!0),Sd=Da[0],Td=Da[1],Ha=(t,e,n)=>n>32?Gi(t,e,n):zi(t,e,n),Ca=(t,e,n)=>n>32?Wi(t,e,n):qi(t,e,n);function Hd(t,e=24){let n=new Uint32Array(10);for(let o=24-e;o<24;o++){for(let s=0;s<10;s++)n[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let a=(s+8)%10,c=(s+2)%10,f=n[c],u=n[c+1],d=Ha(f,u,1)^n[a],h=Ca(f,u,1)^n[a+1];for(let l=0;l<50;l+=10)t[s+l]^=d,t[s+l+1]^=h}let r=t[2],i=t[3];for(let s=0;s<24;s++){let a=$a[s],c=Ha(r,i,a),f=Ca(r,i,a),u=Ra[s];r=t[u],i=t[u+1],t[u]=c,t[u+1]=f}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)n[a]=t[s+a];for(let a=0;a<10;a++)t[s+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=Sd[o],t[1]^=Td[o]}ke(n)}var Or=class t extends Ht{constructor(e,n,o,r=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=o,this.enableXOF=r,this.rounds=i,Io(o),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=_i(this.state)}clone(){return this._cloneInto()}keccak(){ko(this.state32),Hd(this.state32,this.rounds),ko(this.state32),this.posOut=0,this.pos=0}update(e){Ct(this),e=zt(e),ht(e);let{blockLen:n,state:o}=this,r=e.length;for(let i=0;i<r;){let s=Math.min(n-this.pos,r-i);for(let a=0;a<s;a++)o[this.pos++]^=e[i++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:o,blockLen:r}=this;e[o]^=n,(n&128)!==0&&o===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Ct(this,!1),ht(e),this.finish();let n=this.state,{blockLen:o}=this;for(let r=0,i=e.length;r<i;){this.posOut>=o&&this.keccak();let s=Math.min(o-this.posOut,i-r);e.set(n.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Io(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(wn(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ke(this.state)}_cloneInto(e){let{blockLen:n,suffix:o,outputLen:r,rounds:i,enableXOF:s}=this;return e||(e=new t(n,o,r,s,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=o,e.outputLen=r,e.enableXOF=s,e.destroyed=this.destroyed,e}},Cd=(t,e,n)=>qt(()=>new Or(e,t,n));var Na=Cd(1,136,256/8);y();function Oa(t){if(t.length===0)throw new Error("RLP: empty input");let{item:e,next:n}=Fa(t,0);if(n!==t.length)throw new Error(`RLP: ${t.length-n} trailing byte(s) after the top-level item`);if(!Array.isArray(e))throw new Error("RLP: top-level item is not a list");return e}function Fa(t,e){let n=Ua(t,e);if(n<128)return{item:t.subarray(e,e+1),next:e+1};if(n<=183){let a=n-128,c=Xn(t,e+1,a);return{item:t.subarray(e+1,c),next:c}}if(n<=191){let a=n-183,c=La(t,e+1,a),f=e+1+a,u=Xn(t,f,c);return{item:t.subarray(f,u),next:u}}if(n<=247){let a=n-192,c=Xn(t,e+1,a);return{item:Ma(t,e+1,c),next:c}}let o=n-247,r=La(t,e+1,o),i=e+1+o,s=Xn(t,i,r);return{item:Ma(t,i,s),next:s}}function Ma(t,e,n){let o=[],r=e;for(;r<n;){let i=Fa(t,r);if(i.next>n)throw new Error("RLP: list item overruns its list payload");o.push(i.item),r=i.next}return o}function La(t,e,n){if(n<1||n>8)throw new Error(`RLP: invalid length-of-length ${n}`);let o=0;for(let r=0;r<n;r++)o=o*256+Ua(t,e+r);if(o>t.length)throw new Error("RLP: declared length exceeds the input size");return o}function Xn(t,e,n){let o=e+n;if(o>t.length)throw new Error("RLP: item is truncated");return o}function Ua(t,e){let n=t[e];if(n===void 0)throw new Error("RLP: unexpected end of input");return n}function Fr(t){let e=0n;for(let n of t)e=e<<8n|BigInt(n);return e}function _a(t){if(!t.startsWith("0x"))return null;let e=t.slice(2);if(e.length%2!==0||!/^[0-9a-fA-F]*$/.test(e))return null;let n=new Uint8Array(e.length/2);for(let o=0;o<n.length;o++)n[o]=Number.parseInt(e.slice(o*2,o*2+2),16);return n}function ja(t){return`0x${B.Buffer.from(t).toString("hex")}`}var Ka=8,Va=11,Rd=/^0x[0-9a-fA-F]{64}$/,$d=/^https:\/\/etherscan\.io\/block\/([0-9]+)$/;async function _r(t,e){let n=[],o=[],r=new Map(t.proofs.map(i=>[i.proofHash,i]));for(let i of t.witnesses){let s=Pd(i);if(s.failure!==void 0){let u={witnessPath:i.path,verified:!1,reason:s.failure.reason,detail:s.failure.detail};n.push(u),o.push(Ur(u));continue}let a=s.computedHash,c=s.claimedHash.toLowerCase(),f=e.anchors.filter(u=>{let d=u.blockHash?.toLowerCase();return d!==void 0&&(d===a||d===c)});if(f.length===0){let u={witnessPath:i.path,verified:!1,reason:"witness-unmatched",detail:"neither the locally recomputed block hash nor the claimed blockHash matches any observed anchor's signed attribution.message",computedBlockHash:a};n.push(u),o.push(Ur(u));continue}for(let u of f){let d=r.get(u.proofHash),h=d!==void 0&&await qe(d),l=Dd(s,i.path,u.proofHash,d,h);n.push(l),l.verified||o.push(Ur(l))}}return{outcomes:n,findings:o}}function Pd(t){let e=t.witness,n=e.headerRlpHex;if(typeof n!="string")return Jn("headerRlpHex is missing or not a string");let o=e.blockNumber;if(typeof o!="number"||!Number.isInteger(o)||o<0)return Jn("blockNumber is missing or not a non-negative integer");let r=e.blockHash;if(typeof r!="string"||!Rd.test(r))return Jn("blockHash is missing or not 0x followed by 64 hex characters");let i=_a(n);if(i===null)return Jn("headerRlpHex is not 0x-prefixed even-length hex");let s;try{s=Oa(i)}catch(c){return{failure:{reason:"witness-rlp-invalid",detail:c instanceof Error?c.message:String(c)}}}return{computedHash:ja(Na(i)),items:s,claimedHash:r,claimedNumber:BigInt(o)}}function Jn(t){return{failure:{reason:"witness-malformed",detail:t}}}function Dd(t,e,n,o,r){let i=t.computedHash,s={witnessPath:e,anchorProofHash:n,computedBlockHash:i},a=(b,k,v)=>({...s,verified:!1,reason:b,detail:k,...v?.blockNumber!==void 0?{blockNumber:v.blockNumber}:{}});if(o===void 0||!r)return a("witness-anchor-invalid","the candidate anchor proof is not cryptographically valid; the witness confers nothing");let c=Nd(o);if(c===void 0||c.toLowerCase()!==i)return a("witness-hash-mismatch",c===void 0?"the anchor carries no signed attribution.message to compare against":"the locally recomputed block hash does not equal the anchor's signed attribution.message");let f=Od(Ld(o));if(f===null)return a("witness-digest-mismatch","the anchor's artifact.digestB64 does not strictly decode as base64 of 32 bytes");let u=_(new TextEncoder().encode(c));if(!Fd(u,f))return a("witness-digest-mismatch","SHA-256 of the exact signed attribution.message string does not equal the anchor's artifact digest");let d=t.items,h=d[Ka];if(h===void 0||!(h instanceof Uint8Array))return a("witness-header-shape",`header RLP item ${Ka} (block number) is missing or not a byte string`);let l=Fr(h);if(l!==t.claimedNumber)return a("witness-block-number-mismatch",`the witness claims blockNumber ${t.claimedNumber}, but the header's number field is ${l}`,{blockNumber:String(l)});let m=Md(o);if(m!==void 0){let b=$d.exec(m)?.[1];if(b!==void 0&&BigInt(b)!==l)return a("witness-block-number-mismatch",`the anchor's signed Etherscan URL names block ${b}, but the header's number field is ${l}`,{blockNumber:String(l)})}if(t.claimedHash.toLowerCase()!==i)return a("witness-claimed-hash-mismatch","the witness's claimed blockHash does not equal the locally recomputed block hash",{blockNumber:String(l)});let p=d[Va];if(p===void 0||!(p instanceof Uint8Array))return a("witness-header-shape",`header RLP item ${Va} (timestamp) is missing or not a byte string`,{blockNumber:String(l)});let w=Fr(p);return w>BigInt(Number.MAX_SAFE_INTEGER)?a("witness-header-shape","header timestamp does not fit a safe integer",{blockNumber:String(l)}):{...s,verified:!0,blockNumber:String(l),timestamp:Number(w)}}function Nd(t){return za(t,"message")}function Md(t){return za(t,"title")}function za(t,e){let n=t.proof.attribution;if(n===null||typeof n!="object"||Array.isArray(n))return;let o=n[e];return typeof o=="string"?o:void 0}function Ld(t){let e=t.proof.artifact;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.digestB64;return typeof n=="string"?n:void 0}function Od(t){if(t===void 0||t.length===0)return null;let e=B.Buffer.from(t,"base64");return e.length!==32||e.toString("base64")!==t?null:new Uint8Array(e)}function Fd(t,e){if(t.length!==e.length)return!1;let n=0;for(let o=0;o<t.length;o++)n|=t[o]^e[o];return n===0}function Ur(t){return{code:t.reason,path:t.witnessPath,message:`anchor witness rejected: ${t.detail??"verification failed"}. The witness confers nothing; the anchor proof's own standing is unchanged.`,details:{...t.anchorProofHash!==void 0?{anchorProofHash:t.anchorProofHash}:{},...t.computedBlockHash!==void 0?{computedBlockHash:t.computedBlockHash}:{}}}}y();function jr(t,e,n,o){let r=new Map(t.proofs.map(u=>[u.proofHash,u])),i=new Map;for(let u of o.outcomes)!u.verified||u.anchorProofHash===void 0||i.has(u.anchorProofHash)||i.set(u.anchorProofHash,{anchorProofHash:u.anchorProofHash,timestamp:u.timestamp,blockHash:u.computedBlockHash,...u.blockNumber!==void 0?{blockNumber:u.blockNumber}:{}});let s=[...i.keys()].sort(),a=n.anchors.map(u=>u.proofHash).filter(u=>!i.has(u)).sort(),c=[];for(let u of e.partitions)c.push(...Ud(u,r,i));let f=qd(e,c);return{segments:c,anchorOrderedPairs:f,verifiedAnchorProofHashes:s,unverifiedAnchorProofHashes:a}}function Ud(t,e,n){let o=t.memberProofHashes.map(h=>e.get(h)),r=new Map(o.map(h=>[h.chainHash,h])),i=o.filter(h=>n.has(h.proofHash)),s=new Map;for(let h of o){if(h.prevB64===void 0)continue;let l=r.get(h.prevB64);l===void 0||l.proofHash===h.proofHash||ue(s,l.proofHash,h)}let a=new Map,c=new Map;for(let h of i)a.set(h.proofHash,jd(h,s)),c.set(h.proofHash,Kd(h,r));let f=o.map(h=>{let l=new Map,m=new Map,p=Y(h.counter);for(let w of i){let b=w.proofHash,k=Y(w.counter);h.proofHash===b||a.get(b).has(h.proofHash)?l.set(b,"chain-link"):p!==void 0&&k!==void 0&&p>k&&(l.has(b)||l.set(b,"counter-order")),c.get(b).has(h.proofHash)?m.set(b,"chain-link"):h.proofHash!==b&&p!==void 0&&k!==void 0&&p<k&&(m.has(b)||m.set(b,"counter-order"))}return{member:h,lower:qa("not-before",l,n),upper:qa("not-after",m,n)}}),u=new Map;for(let h of f)ue(u,_d(h),h);let d=[];for(let h of u.values()){let l=h.map(v=>v.member).sort(Pe),m=h[0],p=m.lower,w=m.upper,b=p.length>0&&w.length>0?"lower-bounded-with-following-anchor":p.length>0?"lower-bounded":w.length>0?"upper-bounded":"ordered-but-unanchored",k=Vd(l);d.push({partition:t.key,memberProofHashes:l.map(v=>v.proofHash),...k!==void 0?{positionRange:k}:{},status:b,lowerBounds:p,upperBounds:w})}return d.sort(zd),d}function qa(t,e,n){if(e.size===0)return[];let o=[...e.entries()].map(([c,f])=>({anchorHash:c,evidenceKind:f,info:n.get(c)})),r=(c,f)=>f===void 0?!0:c.info.timestamp!==f.info.timestamp?t==="not-before"?c.info.timestamp>f.info.timestamp:c.info.timestamp<f.info.timestamp:c.evidenceKind!==f.evidenceKind?c.evidenceKind==="chain-link":c.anchorHash<f.anchorHash,i,s;for(let c of o)r(c,i)&&(i=c),c.evidenceKind==="chain-link"&&r(c,s)&&(s=c);let a=[Ga(t,i)];return s!==void 0&&(i.anchorHash!==s.anchorHash||i.evidenceKind!=="chain-link")&&a.push(Ga(t,s)),a}function Ga(t,e){let{info:n,evidenceKind:o}=e,r=new Date(n.timestamp*1e3).toISOString(),i=n.blockNumber!==void 0?`Ethereum block ${n.blockNumber}`:"an Ethereum block",s=o==="chain-link"?"Evidence: a verified hash-link path connects these proofs and the anchor.":"Evidence: commit-counter ordering within the partition only, which relies on the authority's counter discipline rather than verifiable hash links (weaker).",a=t==="not-before"?`These proofs were committed no earlier than ${r} (unix ${n.timestamp}), the timestamp of ${i}: the block hash was unpredictable before that time and the anchor commit consumed it. Reading this as a wall-clock floor additionally assumes the anchored header is a genuine, publicly published Ethereum block: this offline audit checks the header's structure and hash binding, not proof-of-work, consensus, or chain membership, so it cannot confirm the block is real. ${s}`:`These proofs existed before the anchor commit that consumed the hash of ${i} (block timestamp ${r}, unix ${n.timestamp}). The block timestamp proves the anchor commit came at or after it, not how promptly; reading it as a wall-clock ceiling additionally assumes the anchor consumed a recently published block. ${s}`;return{kind:t,anchorProofHash:e.anchorHash,...n.blockNumber!==void 0?{blockNumber:n.blockNumber}:{},blockHash:n.blockHash,timestamp:n.timestamp,evidence:o,weaker:o==="counter-order",basis:t==="not-before"?"block-hash-unpredictability":"causal-precedence",boundClass:t==="not-before"?"evidence":"assumption",claim:t==="not-before"?a:"NOT a proof-carried upper bound. "+a}}function _d(t){let e=n=>n.map(o=>`${o.anchorProofHash}:${o.evidence}`).join(",");return`${e(t.lower)}|${e(t.upper)}`}function jd(t,e){let n=new Set,o=[...e.get(t.proofHash)??[]];for(;o.length>0;){let r=o.pop();if(!n.has(r.proofHash)){n.add(r.proofHash);for(let i of e.get(r.proofHash)??[])o.push(i)}}return n}function Kd(t,e){let n=new Set,o=t;for(;o!==void 0&&o.prevB64!==void 0;){let r=e.get(o.prevB64);if(r===void 0||n.has(r.proofHash)||r.proofHash===t.proofHash)break;n.add(r.proofHash),o=r}return n}function Vd(t){let e,n;for(let o of t)for(let r of[o.counter,o.slotCounter]){let i=Y(r);i!==void 0&&((e===void 0||i<e)&&(e=i),(n===void 0||i>n)&&(n=i))}return e!==void 0&&n!==void 0?{min:String(e),max:String(n)}:void 0}function zd(t,e){let n=t.positionRange?.min,o=e.positionRange?.min;if(n!==void 0&&o!==void 0&&n!==o)return BigInt(n)<BigInt(o)?-1:1;if(n!==void 0&&o===void 0)return-1;if(n===void 0&&o!==void 0)return 1;let r=t.memberProofHashes[0]??"",i=e.memberProofHashes[0]??"";return r<i?-1:r>i?1:0}function Wa(t){return t?" The representative bound rests on commit-counter ordering rather than a verified hash-link path, which relies on the authority's counter discipline (weaker evidence).":""}function qd(t,e){let n=new Map;for(let i of t.epochRelationships.epochs)n.set(i.epochId,{totalProofCount:i.proofCount,lowerCovered:new Set,upperCovered:new Set});for(let i of e){let s=i.partition.epochId;if(s===void 0)continue;let a=n.get(s);if(a!==void 0){for(let c of i.lowerBounds){for(let f of i.memberProofHashes)a.lowerCovered.add(f);(a.lowerMin===void 0||c.timestamp<a.lowerMin.timestamp||c.timestamp===a.lowerMin.timestamp&&a.lowerMin.weaker&&!c.weaker)&&(a.lowerMin={timestamp:c.timestamp,anchorProofHash:c.anchorProofHash,blockHash:c.blockHash,...c.blockNumber!==void 0?{blockNumber:c.blockNumber}:{},evidence:c.evidence,weaker:c.weaker})}for(let c of i.upperBounds){for(let f of i.memberProofHashes)a.upperCovered.add(f);(a.upperMax===void 0||c.timestamp>a.upperMax.timestamp||c.timestamp===a.upperMax.timestamp&&a.upperMax.weaker&&!c.weaker)&&(a.upperMax={timestamp:c.timestamp,anchorProofHash:c.anchorProofHash,blockHash:c.blockHash,...c.blockNumber!==void 0?{blockNumber:c.blockNumber}:{},evidence:c.evidence,weaker:c.weaker})}}}for(let i of t.epochRelationships.epochs){let s=n.get(i.epochId),a=[];s.lowerMin!==void 0&&a.push({kind:"not-before",anchorProofHash:s.lowerMin.anchorProofHash,...s.lowerMin.blockNumber!==void 0?{blockNumber:s.lowerMin.blockNumber}:{},blockHash:s.lowerMin.blockHash,witnessTimestamp:s.lowerMin.timestamp,coverage:"members-after-anchor",coveredProofCount:s.lowerCovered.size,totalProofCount:s.totalProofCount,basis:"block-hash-unpredictability",evidence:s.lowerMin.evidence,weaker:s.lowerMin.weaker,claim:`${s.lowerCovered.size} of ${s.totalProofCount} observed proofs of this epoch were committed no earlier than unix ${s.lowerMin.timestamp}, grounded in block-hash unpredictability through verified anchor witnesses. This additionally assumes the anchored header is a genuine, publicly published Ethereum block, which this offline audit cannot confirm.`+Wa(s.lowerMin.weaker)+" The remaining proofs sit causally before the covering anchors and carry no lower bound from this evidence."}),s.upperMax!==void 0&&a.push({kind:"not-after",anchorProofHash:s.upperMax.anchorProofHash,...s.upperMax.blockNumber!==void 0?{blockNumber:s.upperMax.blockNumber}:{},blockHash:s.upperMax.blockHash,witnessTimestamp:s.upperMax.timestamp,coverage:"members-before-anchor",coveredProofCount:s.upperCovered.size,totalProofCount:s.totalProofCount,basis:"causal-precedence",evidence:s.upperMax.evidence,weaker:s.upperMax.weaker,claim:`${s.upperCovered.size} of ${s.totalProofCount} observed proofs of this epoch existed before an anchor commit that consumed a block published at unix ${s.upperMax.timestamp}. Reading that timestamp as a wall-clock ceiling additionally assumes the anchor consumed a recently published block; the causal precedence itself is verified.`+Wa(s.upperMax.weaker)+" Proofs after the covering anchors are not covered."}),a.length>0&&(i.anchorBounds=a)}let o=[],r=t.epochRelationships.epochs;for(let i of r){let s=n.get(i.epochId);if(s.upperMax!==void 0)for(let a of r){if(a.epochId===i.epochId)continue;let c=n.get(a.epochId);if(c.lowerMin===void 0||s.upperMax.timestamp>=c.lowerMin.timestamp)continue;let f=s.upperMax.evidence,u=c.lowerMin.evidence,d=s.upperMax.weaker||c.lowerMin.weaker;o.push({beforeEpochId:i.epochId,afterEpochId:a.epochId,upperAnchorProofHash:s.upperMax.anchorProofHash,upperBoundTimestamp:s.upperMax.timestamp,lowerAnchorProofHash:c.lowerMin.anchorProofHash,lowerBoundTimestamp:c.lowerMin.timestamp,basis:"anchor-bounds",assumptionDependent:!0,upperEvidence:f,lowerEvidence:u,weaker:d,beforeCoveredProofCount:s.upperCovered.size,beforeTotalProofCount:s.totalProofCount,afterCoveredProofCount:c.lowerCovered.size,afterTotalProofCount:c.totalProofCount,note:`The anchor-covered portion of epoch ${i.epochId} (${s.upperCovered.size} of ${s.totalProofCount} proofs) precedes the anchor-covered portion of epoch ${a.epochId} (${c.lowerCovered.size} of ${c.totalProofCount} proofs): the first is bounded not-after unix ${s.upperMax.timestamp} and the second not-before unix ${c.lowerMin.timestamp}. One-sided evidence about the covered portions only; the not-after side rests on the anchor-freshness assumption documented on its bound.`+(d?" At least one side rests on commit-counter ordering rather than a verified hash-link path (weaker evidence), which relies on the authority's counter discipline.":"")+" This is ordering evidence, never divergence."})}}return o.sort((i,s)=>i.beforeEpochId!==s.beforeEpochId?i.beforeEpochId<s.beforeEpochId?-1:1:i.afterEpochId<s.afterEpochId?-1:i.afterEpochId>s.afterEpochId?1:0),o}y();y();var Za=`-----BEGIN CERTIFICATE-----
140
140
  MIICETCCAZagAwIBAgIRAPkxdWgbkK/hHUbMtOTn+FYwCgYIKoZIzj0EAwMwSTEL
141
141
  MAkGA1UEBhMCVVMxDzANBgNVBAoMBkFtYXpvbjEMMAoGA1UECwwDQVdTMRswGQYD
142
142
  VQQDDBJhd3Mubml0cm8tZW5jbGF2ZXMwHhcNMTkxMDI4MTMyODA1WhcNNDkxMDI4
@@ -149,10 +149,10 @@ R+eWw5b6cp3PmanfS5YwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMDA2kAMGYC
149
149
  MQCjfy+Rocm9Xue4YnwWmNJVA44fA0P5W2OpYow9OYCVRaEevL8uO1XYru5xtMPW
150
150
  rfMCMQCi85sWBbJwKKXdS6BptQFuZbT73o/gBh1qUxl/nNr12UO8Yfwr6wPLb+6N
151
151
  IwLz3/Y=
152
- -----END CERTIFICATE-----`;function Ud(){return ja.replace(/-----BEGIN CERTIFICATE-----/,"").replace(/-----END CERTIFICATE-----/,"").replace(/\s+/g,"")}function Va(){return new Uint8Array(B.Buffer.from(Ud(),"base64"))}async function qa(t,e){let n=[],r={},o,i,s,a,c,f=()=>({documentValid:!1,checks:n,failure:[...n].reverse().find(u=>!u.pass)?.detail,...o!==void 0?{pcr0:o}:{},pcrs:r,...i!==void 0?{moduleId:i}:{},...s!==void 0?{timestamp:s}:{},...a!==void 0?{certChainLength:a}:{},...c!==void 0?{userDataB64:c}:{}});try{let u=jd(t);if(u===null)return n.push({name:"CBOR Decode",pass:!1,detail:"reportB64 is not valid base64"}),f();let d=je(u,0).value;if(!Array.isArray(d)||d.length<4)return n.push({name:"CBOR Decode",pass:!1,detail:"Not a valid COSE_Sign1 array"}),f();n.push({name:"CBOR Decode",pass:!0,detail:"COSE_Sign1 envelope parsed"});let h=d[0],l=d[2],m=d[3];if(!(h instanceof Uint8Array)||!(l instanceof Uint8Array)||!(m instanceof Uint8Array))return n.push({name:"COSE Structure",pass:!1,detail:"Missing protected/payload/signature"}),f();let p=je(l,0).value;if(!p||typeof p!="object"||Array.isArray(p))return n.push({name:"Payload Decode",pass:!1,detail:"Could not decode attestation payload"}),f();r=Zd(p),o=r[0],i=typeof p.module_id=="string"?p.module_id:void 0,s=typeof p.timestamp=="number"?p.timestamp:void 0;let y=p.user_data;c=y instanceof Uint8Array&&y.length>0?B.Buffer.from(y).toString("base64"):void 0;let b=p.cabundle,I=p.certificate;if(!(I instanceof Uint8Array))return n.push({name:"Leaf Certificate",pass:!1,detail:"No leaf certificate in attestation"}),f();a=(Array.isArray(b)?b.length:0)+1;let v=jo(I),M=qd(h,l),z=await Vo(m,M,v.publicKey);if(n.push({name:"ECDSA P-384 Signature",pass:z,detail:z?"Attestation signed by leaf certificate":"Signature verification failed against leaf certificate public key"}),!z)return f();if(!Array.isArray(b)||b.length===0||!b.every(A=>A instanceof Uint8Array))return n.push({name:"Certificate Chain",pass:!1,detail:"Empty cabundle"}),f();let H=[...b,I].map(jo),U=!0,F="";for(let A=1;A<H.length;A++){let C=H[A],D=H[A-1];if(!await Vo(C.signature,C.tbsCertificate,D.publicKey)){U=!1,F=`Certificate ${A} signature invalid (parent: ${A-1})`;break}}if(n.push({name:"Certificate Chain",pass:U,detail:U?`${H.length} certificates, each signed by parent`:F}),!U)return f();let G=e?.trustedRootCaDer===void 0,q=jo(e?.trustedRootCaDer??Va()),le=H[0],N=await Vo(le.signature,le.tbsCertificate,q.publicKey);if(n.push({name:"AWS Nitro Root CA",pass:N,detail:N?G?"Chain anchored to AWS Nitro Root G1 (CN=aws.nitro-enclaves)":"Chain anchored to the supplied trust root (non-default trust material)":G?"Top of chain not signed by AWS Nitro Root CA":"Top of chain not signed by the supplied trust root"}),!N)return f();let se=!0,re=`All ${H.length} certificate validity windows contain the document timestamp`;if(s===void 0)se=!1,re="Attestation document carries no timestamp; certificate validity cannot be evaluated offline";else for(let A=0;A<H.length;A++){let C=H[A];if(s<C.notBeforeMs||s>C.notAfterMs){se=!1,re=`Certificate ${A} validity window [${new Date(C.notBeforeMs).toISOString()}, ${new Date(C.notAfterMs).toISOString()}] does not contain the document timestamp ${new Date(s).toISOString()}`;break}}if(n.push({name:"Certificate Validity Window",pass:se,detail:re}),!se)return f();let L;e?.expectedPcr0!==void 0&&(L=o===e.expectedPcr0,n.push({name:"PCR0 Match",pass:L,detail:L?"PCR0 inside attestation matches declared measurement":`PCR0 mismatch: expected ${e.expectedPcr0.slice(0,16)}..., got ${(o??"").slice(0,16)}...`}));let E;return e?.expectedUserDataB64!==void 0&&(E=c!==void 0&&c===e.expectedUserDataB64,n.push({name:"Bound to this proof",pass:E,detail:E?"Attestation user_data matches this proof's canonical hash":c!==void 0?"Attestation user_data does not match this proof":"Attestation carries no user_data to bind"})),{documentValid:!0,checks:n,...o!==void 0?{pcr0:o}:{},pcrs:r,...i!==void 0?{moduleId:i}:{},...s!==void 0?{timestamp:s}:{},certChainLength:a,...c!==void 0?{userDataB64:c}:{},...L!==void 0?{pcr0Matches:L}:{},...E!==void 0?{userDataMatches:E}:{}}}catch(u){return n.push({name:"Verification Error",pass:!1,detail:u instanceof Error?u.message:String(u)}),f()}}async function zo(t,e,n){let r=[],o=[],i={proofsWithDeclaredMeasurement:0,proofsWithDocument:0,documentsValidated:0,documentsFailed:0,pcr0Matches:0,pcr0Mismatches:0,userDataBound:0,userDataUnbound:0};for(let s of t.proofs){let a=s.measurement!==void 0&&s.measurement.length>0?s.measurement:void 0;a!==void 0&&i.proofsWithDeclaredMeasurement++;let c=Kd(s),f={proofHash:s.proofHash,declaredMeasurementPresent:a!==void 0,...a!==void 0?{declaredMeasurement:a}:{},documentPresent:c!==void 0,...c?.format!==void 0?{attestationFormat:c.format}:{},documentValidated:!1,checks:[]};if(c!==void 0){i.proofsWithDocument++;let u=await qa(c.reportB64,{...a!==void 0?{expectedPcr0:a}:{},expectedUserDataB64:ao(s.proof),...n?.trustedRootCaDer!==void 0?{trustedRootCaDer:n.trustedRootCaDer}:{}});f.documentValidated=u.documentValid,f.checks=u.checks,u.pcr0!==void 0&&(f.attestedPcr0=u.pcr0),f.pcrs=u.pcrs,u.moduleId!==void 0&&(f.moduleId=u.moduleId),u.timestamp!==void 0&&(f.timestamp=u.timestamp),u.certChainLength!==void 0&&(f.certChainLength=u.certChainLength),u.userDataB64!==void 0&&(f.userDataB64=u.userDataB64),u.documentValid?(i.documentsValidated++,u.pcr0Matches!==void 0&&(f.pcr0MatchesDeclared=u.pcr0Matches,u.pcr0Matches?i.pcr0Matches++:(i.pcr0Mismatches++,o.push({code:"attestation-measurement-mismatch",..._o(s),message:"the validated attestation document's PCR0 does not equal the proof's declared environment.measurement. Declared and attested measurements are reported separately and disagree here.",details:{proofHash:s.proofHash,declared:a,...u.pcr0!==void 0?{attested:u.pcr0}:{}}}))),u.userDataMatches!==void 0&&(f.userDataBoundToProof=u.userDataMatches,u.userDataMatches?i.userDataBound++:(i.userDataUnbound++,o.push({code:"attestation-user-data-mismatch",..._o(s),message:"the validated attestation document's user_data is not bound to this proof's canonical hash. A genuine attestation lifted from another proof would look exactly like this.",details:{proofHash:s.proofHash,...u.userDataB64!==void 0?{userDataB64:u.userDataB64}:{}}})))):(i.documentsFailed++,u.failure!==void 0&&(f.validationFailure=u.failure),o.push({code:"attestation-invalid",..._o(s),message:`attestation document failed offline validation: ${u.failure??"unknown"}. Presence of a document is reported separately and proves nothing by itself.`,details:{proofHash:s.proofHash}}))}r.push(f)}return e!==void 0&&_d(e,r),{records:r,findings:o,counts:i}}function _d(t,e){let n=new Map(e.map(r=>[r.proofHash,r]));for(let r of t.groups){if(!r.attestationPresent)continue;let o=r.proofHashes.map(f=>n.get(f)).filter(f=>f!==void 0&&f.documentPresent);if(o.length===0)continue;let i=o.filter(f=>f.documentValidated),s=o.length-i.length,a=[...new Set(i.map(f=>f.attestedPcr0).filter(f=>f!==void 0))].sort(),c=a.length===1?a[0]:void 0;r.attested={status:s===0&&i.length>0?"validated":"validation-failed",...c!==void 0?{attestedMeasurement:c}:{},...c!==void 0&&r.measurement!==void 0?{matchesDeclared:c===r.measurement}:{},validatedProofCount:i.length,failedProofCount:s,...a.length>1?{attestedMeasurements:a}:{}}}}function Kd(t){let e=t.proof.environment;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.attestation;if(n===null||typeof n!="object"||Array.isArray(n))return;let r=n.reportB64;if(typeof r!="string"||r.length===0)return;let o=n.format;return{reportB64:r,...typeof o=="string"?{format:o}:{}}}function _o(t){let e=t.sources[0]?.path;return e!==void 0?{path:e}:{}}function jd(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4!==0;)e+="=";let n=B.Buffer.from(e,"base64");return n.toString("base64")!==e?null:new Uint8Array(n)}function qo(t){return t<24?new Uint8Array([t]):t<256?new Uint8Array([24,t]):t<65536?new Uint8Array([25,t>>8,t&255]):new Uint8Array([26,t>>>24&255,t>>>16&255,t>>>8&255,t&255])}function Ko(t){let e=qo(t.length);e[0]=e[0]&31|64;let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}function Vd(t){let e=new TextEncoder().encode(t),n=qo(e.length);n[0]=n[0]&31|96;let r=new Uint8Array(n.length+e.length);return r.set(n,0),r.set(e,n.length),r}function zd(t){let e=qo(t.length);e[0]=e[0]&31|128;let n=e.length+t.reduce((i,s)=>i+s.length,0),r=new Uint8Array(n),o=0;r.set(e,o),o+=e.length;for(let i of t)r.set(i,o),o+=i.length;return r}function qd(t,e){return zd([Vd("Signature1"),Ko(t),Ko(new Uint8Array(0)),Ko(e)])}function je(t,e=0){let n=t[e];if(n===void 0)throw new Error("CBOR: unexpected end of input");let r=n>>5,o=n&31;e++;let i=a=>{let c=t[a];if(c===void 0)throw new Error("CBOR: unexpected end of input");return c};function s(){if(o<24)return o;if(o===24){let a=i(e);return e+=1,a}if(o===25){let a=i(e)<<8|i(e+1);return e+=2,a}if(o===26){let a=(i(e)<<24|i(e+1)<<16|i(e+2)<<8|i(e+3))>>>0;return e+=4,a}if(o===27){let a=0;for(let c=0;c<8;c++)a=a*256+i(e+c);return e+=8,a}throw new Error(`Unsupported CBOR length info: ${o}`)}switch(r){case 0:return{value:s(),offset:e};case 1:return{value:-1-s(),offset:e};case 2:{let a=s();if(e+a>t.length)throw new Error("CBOR: byte string is truncated");return{value:t.slice(e,e+a),offset:e+a}}case 3:{let a=s();if(e+a>t.length)throw new Error("CBOR: text string is truncated");return{value:new TextDecoder().decode(t.slice(e,e+a)),offset:e+a}}case 4:{if(o===31){let f=[];for(;i(e)!==255;){let u=je(t,e);f.push(u.value),e=u.offset}return{value:f,offset:e+1}}let a=s(),c=[];for(let f=0;f<a;f++){let u=je(t,e);c.push(u.value),e=u.offset}return{value:c,offset:e}}case 5:{if(o===31){let f={};for(;i(e)!==255;){let u=je(t,e);e=u.offset;let d=je(t,e);e=d.offset,f[String(u.value)]=d.value}return{value:f,offset:e+1}}let a=s(),c={};for(let f=0;f<a;f++){let u=je(t,e);e=u.offset;let d=je(t,e);e=d.offset,c[String(u.value)]=d.value}return{value:c,offset:e}}case 6:return s(),je(t,e);case 7:{if(o===20)return{value:!1,offset:e};if(o===21)return{value:!0,offset:e};if(o===22)return{value:null,offset:e};if(o===23)return{value:void 0,offset:e};throw new Error(`Unsupported CBOR simple value: ${o}`)}default:throw new Error(`Unsupported CBOR major type: ${r}`)}}function jo(t){let n=nn(t,0).contentStart,r=ie(t,n),o=t.slice(n,r.end);n=r.end,n=ie(t,n).end;let s=ie(t,n),a=t.slice(s.contentStart+1,s.end),c=Wd(a,48),{publicKey:f,notBeforeMs:u,notAfterMs:d}=Gd(o);return{tbsCertificate:o,signature:c,publicKey:f,notBeforeMs:u,notAfterMs:d}}function ie(t,e){let n=t[e];if(n===void 0)throw new Error("DER: unexpected end of input");let r=e+1,o=t[r++];if(o===void 0)throw new Error("DER: unexpected end of input");if(o&128){let s=o&127;o=0;for(let a=0;a<s;a++){let c=t[r++];if(c===void 0)throw new Error("DER: unexpected end of input");o=o*256+c}}let i=r+o;if(i>t.length)throw new Error("DER: element is truncated");return{tag:n,contentStart:r,contentEnd:i,end:i}}function nn(t,e){let n=ie(t,e);if(n.tag!==48)throw new Error(`Expected SEQUENCE at offset ${e}, got tag 0x${n.tag.toString(16)}`);return n}function Gd(t){let n=nn(t,0).contentStart;t[n]===160&&(n=ie(t,n).end),n=ie(t,n).end,n=ie(t,n).end,n=ie(t,n).end;let r=nn(t,n),o=r.contentStart,i=ie(t,o);o=i.end;let s=ie(t,o),a=za(t,i),c=za(t,s);n=r.end,n=ie(t,n).end;let u=nn(t,n).contentStart;u=ie(t,u).end;let h=ie(t,u);return{publicKey:t.slice(h.contentStart+1,h.end),notBeforeMs:a,notAfterMs:c}}function za(t,e){let n=String.fromCharCode(...t.slice(e.contentStart,e.contentEnd)),r,o;if(e.tag===23){if(!/^\d{12}Z$/.test(n))throw new Error(`DER: malformed UTCTime "${n}"`);let u=Number.parseInt(n.slice(0,2),10);r=u<50?2e3+u:1900+u,o=n.slice(2)}else if(e.tag===24){if(!/^\d{14}Z$/.test(n))throw new Error(`DER: malformed GeneralizedTime "${n}"`);r=Number.parseInt(n.slice(0,4),10),o=n.slice(4)}else throw new Error(`DER: expected a Time value, got tag 0x${e.tag.toString(16)}`);let i=Number.parseInt(o.slice(0,2),10),s=Number.parseInt(o.slice(2,4),10),a=Number.parseInt(o.slice(4,6),10),c=Number.parseInt(o.slice(6,8),10),f=Number.parseInt(o.slice(8,10),10);return Date.UTC(r,i-1,s,a,c,f)}function Wd(t,e){let r=nn(t,0).contentStart,o=ie(t,r);if(o.tag!==2)throw new Error("Expected INTEGER for r");let i=t.slice(o.contentStart,o.end);r=o.end;let s=ie(t,r);if(s.tag!==2)throw new Error("Expected INTEGER for s");let a=t.slice(s.contentStart,s.end);if(i[0]===0&&i.length>e&&(i=i.slice(1)),a[0]===0&&a.length>e&&(a=a.slice(1)),i.length>e||a.length>e)throw new Error("ECDSA signature component longer than the curve coordinate size");let c=new Uint8Array(e*2);return c.set(i,e-i.length),c.set(a,e*2-a.length),c}async function Vo(t,e,n){if(n.length!==97||n[0]!==4||t.length!==96)return!1;try{let r=await eo.subtle.importKey("raw",n,{name:"ECDSA",namedCurve:"P-384"},!1,["verify"]);return await eo.subtle.verify({name:"ECDSA",hash:"SHA-384"},r,t,e)}catch{return!1}}function Zd(t){let e={},n=t.pcrs;if(!n||typeof n!="object")return e;for(let[r,o]of Object.entries(n))if(o instanceof Uint8Array){let i=B.Buffer.from(o).toString("hex");i.replace(/0/g,"").length>0&&(e[Number(r)]=i)}return e}w();var Qn="0.4.1";function Ga(){return Qn}async function Go(t,e){let n=e?.startedAt??new Date().toISOString(),r=await Ho(t,e?.trustAnchors!==void 0?{trustAnchors:e.trustAnchors}:void 0),o=await To(t),i=await Co(t,o),s=$o(t),a=No(t),c=await Fo(t,a),f=Uo(t,o,a,c),u=await zo(t,s,e?.trustedRootCaDer!==void 0?{trustedRootCaDer:e.trustedRootCaDer}:void 0);return{runMetadata:{toolVersion:Ga(),startedAt:n,bundlePath:t.bundlePath,container:t.container},ingest:t,verification:r,reconstruction:o,anomalies:i,authorities:s,anchors:a,witnesses:c,temporal:f,attestations:u}}w();w();w();w();w();var Wa=1048576;w();function er(t){let e=!1;for(let n of t){if(n==="FALSE")return"FALSE";n==="UNDETERMINED"&&(e=!0)}return e?"UNDETERMINED":"TRUE"}w();w();var Wo="0.8.1";var eh=[{pcr0:"8530a6399399c4f23d89f5a1faa2e8bf2e09a5959f117070fca08148377f92c902c695fc926c17f67f35f110327dca92",label:"genesis",period:"2026-05-15 to 2026-06-27"},{pcr0:"bb9dd158703603ec222fe565495ceaa7edc08f665da5c1cddad91442ac2211731390267036d79deb720d13fb704f648a",label:"enclave v2 (reproducible)",period:"2026-06-27 to 2026-07-05"},{pcr0:"e2fccbae77ee40aac4830e84f195e05d69eb4547bbd961f4d3459feba10807140424aca42ad03810354982598c86b9cb",label:"enclave v4 (reproducible)",period:"2026-07-05 to 2026-07-29"},{pcr0:"6483cedffed74680ffb287507744a398b288c3fb943eb3f2e4fe889f8b60b3d575ad8942350360b69a1bd7bf713df27f",label:"enclave v5 (reproducible)",period:"2026-07-29 onward"}],th=new Set(["unexplained-counter-positions","chain-break-missing","epochlink-terminal-missing","epochlink-dangling"]);async function Qa(t,e){let n=e;if(n?.from!==void 0&&n.sigEvidence===void 0){let o=new Map;for await(let i of en(t))i.bytes.length>Wa||o.has(i.sha256Hex)||o.set(i.sha256Hex,i.bytes);n={...n,sigEvidence:o}}let r=await Go(t,{startedAt:""});if(n?.fuseEvidence===void 0){let o=await nh(t);n={...n,fuseEvidence:o.evidence,fuseOriginHexes:o.originHexes}}return rh(r,n)}async function nh(t){let e=new Map,n=new Set,r=[],o=new Set;for(let s of t.proofs){let a=Ot(s.proof);if(a===null)continue;let c=Jt(s.proof.artifact.digestB64),f=c!==null?Nt(c):null,u=a.originDigest!==void 0?Nt(a.originDigest):null;r.push({proof:s,artifactHex:f,originHex:u}),f!==null&&o.add(f),u!==null&&o.add(u)}if(r.length===0)return{evidence:e,originHexes:n};let i=new Map;for await(let s of ko(t,o))i.has(s.sha256Hex)||i.set(s.sha256Hex,s.bytes);_e();try{for(let s of r){let a=s.artifactHex!==null?i.get(s.artifactHex):void 0,c=s.originHex!==null?i.get(s.originHex):void 0;c!==void 0&&s.originHex!==null&&n.add(s.originHex);let f=a??c;f!==void 0&&e.set(s.proof.proofHash,await xo({proof:s.proof.proof,bytes:f}))}}finally{_e()}return{evidence:e,originHexes:n}}function rh(t,e){let n=e?.webCryptoAvailable??!0,r=new Map(t.anchors.anchors.map(p=>[p.proofHash,p])),o=new Map(t.attestations.records.map(p=>[p.proofHash,p])),i=new Map;for(let p of t.temporal.segments)for(let y of p.memberProofHashes)i.set(y,p);let s=new Map;for(let p of t.witnesses.outcomes){if(p.anchorProofHash===void 0)continue;let y=s.get(p.anchorProofHash)??[];y.push(p),s.set(p.anchorProofHash,y)}let a=new Map;for(let p of t.ingest.artifacts)for(let y of p.matchedProofHashes)!a.has(y)&&p.paths[0]!==void 0&&a.set(y,p.paths[0]);let c=[],f=[];for(let p of t.ingest.proofs){let y=r.get(p.proofHash);y!==void 0?f.push(gh(p,y,s.get(p.proofHash)??[])):c.push(oh(p,o.get(p.proofHash),i.get(p.proofHash),a.get(p.proofHash),n,e?.from,e?.sigEvidence,e?.fuseEvidence,r))}Za(c),Za(f);let u=bh(t),d=yh(t,c,f,e?.fuseOriginHexes),h=wh(f.length>0,e?.from?.domain),l=[...c.map(p=>p.result),...f.map(p=>p.result),...u.map(p=>p.result)],m=l.length===0?"UNDETERMINED":er(l);return{check:e?.from!==void 0?"bitgraph-check/2":"bitgraph-check/1",...e?.from!==void 0?{from:{domain:e.from.domain,party:e.from.party}}:{},result:m,summary:xh(m,c,f,u),recordings:c,anchors:f,contradictions:u,notes:d,notChecked:h,evaluator:{name:"bitgraph-player",version:Wo,audit:Qn},network:"none"}}function Za(t){let e=n=>[n.epochId??"",n.counter!==void 0&&/^[0-9]+$/.test(n.counter)?BigInt(n.counter):void 0];t.sort((n,r)=>{let[o,i]=e(n),[s,a]=e(r);return o!==s?o<s?-1:1:i===void 0||a===void 0?i===void 0?a===void 0?0:1:-1:i<a?-1:i>a?1:0})}function oh(t,e,n,r,o,i,s,a,c){let f=[],u=t.verification,d=t.proof.artifact.digestB64;u?.tier==="full"?f.push({name:"file",result:u.status==="verified"||u.status==="failed"?"TRUE":"UNDETERMINED",detail:u.status==="verified"||u.status==="failed"?`${r??"the matched file"} hashes to the recorded digest ${d}`:`no file in this bundle hashes to the recorded digest ${d}`}):f.push({name:"file",result:"UNDETERMINED",detail:`no file in this bundle hashes to the recorded digest ${d}; the recording cannot be bound to bytes in hand`}),u===void 0?f.push({name:"signature",result:"UNDETERMINED",detail:"the proof was not verified"}):u.status==="failed"?f.push({name:"signature",result:"FALSE",detail:`the proof does not verify: ${u.reason??"unspecified failure"}`}):f.push({name:"signature",result:"TRUE",detail:`Ed25519 signature and slot binding verify under signer key ${Xo(t.publicKeyB64)}`});let h=ch(e,o);if(f.push(h.line),f.push(hh(h.attestedPcr0,h.line.result)),i!==void 0){let y=u!==void 0&&u.status!=="failed";f.push(uh(t,y,i,s??fh))}let l=Ot(t.proof),m;if(l!==null){let y=ih(n,c,t.slotCounter,t.chainId),b=ah(l.placement,l.originDigest!==void 0?t.proof.attribution?.message??null:null,a?.get(t.proofHash),y,t);f.push(b.line),m=b.fused}let p=er(f.map(y=>y.result));return{proofHash:t.proofHash,digestB64:d,...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.counter!==void 0?{counter:t.counter}:{},...t.slotCounter!==void 0?{slotCounter:t.slotCounter}:{},...t.publicKeyB64!==void 0?{publicKeyB64:t.publicKeyB64}:{},...r!==void 0&&u?.tier==="full"?{filePath:r}:{},lines:f,result:p,bounds:lh(n),...m!==void 0?{fused:m}:{}}}var Yo="bitgraph:main";function ih(t,e,n,r=Yo){if(r!==Yo||t===void 0||e===void 0||n===void 0||!/^[0-9]+$/.test(n))return null;let o=BigInt(n),i;for(let s of t.lowerBounds){if(s.kind!=="not-before")continue;let a=e.get(s.anchorProofHash);if(a===void 0||a.counter===void 0||!/^[0-9]+$/.test(a.counter)||BigInt(a.counter)>=o)continue;if(i===void 0){i=s;continue}let c=s.blockNumber!==void 0?BigInt(s.blockNumber):BigInt(s.timestamp),f=i.blockNumber!==void 0?BigInt(i.blockNumber):BigInt(i.timestamp);c>f&&(i=s)}return i===void 0?null:{...i.blockNumber!==void 0?{blockNumber:i.blockNumber}:{},blockHash:i.blockHash,timestamp:i.timestamp,anchorProofHash:i.anchorProofHash,evidence:"counter-order"}}var sh="floor undetermined: no anchor precedes this slot in its epoch";function Ya(t){return`anchored block ${t.blockNumber!==void 0?`#${t.blockNumber}`:t.blockHash} (${new Date(t.timestamp*1e3).toISOString()})`}function ah(t,e,n,r,o){let i=o.slotCounter??"?",s=t!==null?` (placement ${t})`:" (placement undeclared)",a=r!==null?`assembled after ${Ya(r)}, the last verified anchor preceding slot ${i} in this epoch`:o.chainId!==Yo?`floor undetermined: the slot is on chain "${o.chainId}", not the anchored chain`:sh,c=n?.span!==void 0&&n.span!==null?{slotCounter:n.span.slotCounter,commitCounter:n.span.commitCounter,positions:n.span.positions}:o.slotCounter!==void 0&&o.counter!==void 0?{slotCounter:o.slotCounter,commitCounter:o.counter,positions:(BigInt(o.counter)-BigInt(o.slotCounter)).toString()}:null,f=(n?.statements??[]).map(h=>r!==null?h.replace(`at position ${i},`,`at position ${i}, which followed ${Ya(r)},`):h),u=(h,l)=>({category:h,placement:n?.placement??t,originDigestB64:n?.originDigestB64??e,evidence:l,statements:f,floor:r,floorDetail:a,span:c});if(n===void 0)return{line:{name:"fused",result:"UNDETERMINED",detail:`marked fused${s}, but neither the fused bytes nor ${e!==null?"the original":"an original"} is in this bundle, so the commitment to slot ${i} cannot be checked`},fused:u("NO_EVIDENCE",null)};let d=n.category==="FUSED_FROM_ORIGIN"||n.fileDigestB64!==n.artifactDigestB64&&n.category!=="NO_MATCH"?"original":"fused-bytes";switch(n.category){case"FUSED_DIRECT":return{line:{name:"fused",result:"TRUE",detail:`the fused bytes carry the commitment to slot ${i}${s}`},fused:u(n.category,"fused-bytes")};case"FUSED_FROM_ORIGIN":return{line:{name:"fused",result:"TRUE",detail:`the original rebuilds the committed fused bytes${s}; they carry the commitment to slot ${i}`},fused:u(n.category,"original")};case"INVALID_SLOT_COMMITMENT":return{line:{name:"fused",result:"FALSE",detail:`the fused bytes do not carry the commitment to this proof's slot ${i}: ${n.reason??""}`},fused:u(n.category,d)};case"INVALID_ORIGIN_ATTRIBUTION":return{line:{name:"fused",result:"FALSE",detail:`the declared origin contradicts the origin inside the fused bytes: ${n.reason??""}`},fused:u(n.category,d)};case"RECONSTRUCTION_MISMATCH":return{line:{name:"fused",result:"FALSE",detail:`the file matching the declared origin does not rebuild the committed fused bytes: ${n.reason??""}`},fused:u(n.category,"original")};case"UNDETERMINED_PLACEMENT":return{line:{name:"fused",result:"UNDETERMINED",detail:`${n.reason??"the placement is not registered"}; this verifier cannot check the commitment`},fused:u(n.category,d)};case"INVALID_UNDERLYING_PROOF":return{line:{name:"fused",result:"UNDETERMINED",detail:"not checked: the proof itself does not verify (see the signature line)"},fused:u(n.category,d)};default:return{line:{name:"fused",result:"UNDETERMINED",detail:`the commitment could not be checked: ${n.reason??n.category}`},fused:u(n.category,d)}}}function ch(t,e){return t===void 0||!t.documentPresent?{line:{name:"attestation",result:"UNDETERMINED",detail:"no attestation document in this proof"}}:e?t.documentValidated?t.userDataBoundToProof!==!0?{line:{name:"attestation",result:"FALSE",detail:"attestation document validates but its user_data is not this proof: the document belongs to some other proof"},attestedPcr0:t.attestedPcr0}:t.pcr0MatchesDeclared!==!0?{line:{name:"attestation",result:"FALSE",detail:`attestation validates and binds this proof, but its PCR0 ${rn(t.attestedPcr0)} is not the measurement the signed body declares ${rn(t.declaredMeasurement)}`},attestedPcr0:t.attestedPcr0}:{line:{name:"attestation",result:"TRUE",detail:`AWS Nitro attestation validates to the AWS root, binds this exact proof (user_data), and attests PCR0 ${rn(t.attestedPcr0)}`},attestedPcr0:t.attestedPcr0}:{line:{name:"attestation",result:"FALSE",detail:`attestation document does not validate: ${t.validationFailure??"unspecified failure"}`}}:{line:{name:"attestation",result:"UNDETERMINED",detail:"attestation not checked: this environment cannot verify ECDSA P-384 (no WebCrypto); open the verifier from a file or https page, or run bitgraph-play check"}}}var fh=new Map;function uh(t,e,n,r){if(!e)return{name:"domain",result:"UNDETERMINED",detail:`the recording is not verified here, so nothing binds it to ${n.domain}`};let o=t.proof.agency?.actor?.keyId;if(o!==void 0){let s=n.actorKeyName(o);if(s!==void 0)return{name:"domain",result:"TRUE",detail:`actor key "${s}" \xB7 published by ${n.domain} (${n.party})`}}let i=dh(t.proof.artifact.digestB64);if(i!==void 0&&r.size>0){let s=n.signatureKeyName(i.toString("hex"),r);if(s!==void 0)return{name:"domain",result:"TRUE",detail:`signature by "${s}" \xB7 published by ${n.domain} (${n.party})`}}return o!==void 0?{name:"domain",result:"UNDETERMINED",detail:`actor key ${o.slice(0,12)}\u2026 is not among the ${n.keyCount} key(s) ${n.domain} publishes`}:{name:"domain",result:"UNDETERMINED",detail:`no evidence binds this recording to ${n.domain}`}}function dh(t){if(!/^[A-Za-z0-9+/]+=*$/.test(t))return;let e=B.Buffer.from(t,"base64");return e.toString("base64")===t?e:void 0}function hh(t,e){if(e!=="TRUE"||t===void 0)return{name:"enclave",result:"UNDETERMINED",detail:"enclave identity rests on a validated attestation, which this recording does not have here"};let n=eh.find(r=>r.pcr0===t.toLowerCase());return n===void 0?{name:"enclave",result:"UNDETERMINED",detail:`PCR0 ${rn(t)} is not among the BitGraph enclave measurements this verifier knows (player ${Wo}); compare it against the measurements published at bitgraph.ing/docs/self-host-tee`}:{name:"enclave",result:"TRUE",detail:`PCR0 ${rn(t)} is the published BitGraph ${n.label} measurement (${n.period})`}}function lh(t){if(t===void 0)return{status:"unanchored",detail:"no verified Ethereum anchor bounds this recording in this bundle"};let e=Xa(t.lowerBounds,"not-before"),n=Xa(t.upperBounds,"not-after"),r=e===void 0?void 0:Ja(e),o=n===void 0?void 0:Ja(n),i=r!==void 0&&o!==void 0?"lower-bounded-with-following-anchor":r!==void 0?"lower-bounded":o!==void 0?"upper-bounded":"unanchored",s=i==="unanchored"?"no verified Ethereum anchor bounds this recording in this bundle":`recorded ${ph(i,r,o)}`;return{status:i,...r!==void 0?{notBefore:r}:{},...o!==void 0?{notAfter:o}:{},detail:s}}function ph(t,e,n){switch(t){case"lower-bounded-with-following-anchor":return`after Ethereum block ${rt(e)} (header verified in this bundle); precedes an anchor that consumed block ${rt(n)} (header verified), an anchor-latency assumption rather than an upper bound on this recording`+Zo(e.weaker||n.weaker);case"lower-bounded":return`after Ethereum block ${rt(e)} (header verified in this bundle); no verified upper bound here`+Zo(e.weaker);case"upper-bounded":return`before Ethereum block ${rt(n)} (header verified in this bundle); no verified lower bound here`+Zo(n.weaker);default:return"with no verified Ethereum bound in this bundle"}}function Xa(t,e){let n=t.filter(o=>o.kind===e);return n.length===0?void 0:[...n].sort((o,i)=>{let s=o.blockNumber!==void 0?BigInt(o.blockNumber):BigInt(o.timestamp),a=i.blockNumber!==void 0?BigInt(i.blockNumber):BigInt(i.timestamp);return s!==a?e==="not-before"?s>a?-1:1:s<a?-1:1:o.weaker!==i.weaker?o.weaker?1:-1:0})[0]}function Ja(t){return{...t.blockNumber!==void 0?{blockNumber:t.blockNumber}:{},blockHash:t.blockHash,timestamp:t.timestamp,anchorProofHash:t.anchorProofHash,evidence:t.evidence,weaker:t.weaker}}function mh(t){switch(t.status){case"lower-bounded-with-following-anchor":return`after Ethereum block ${rt(t.notBefore)}, then an anchor at block ${rt(t.notAfter)}`;case"lower-bounded":return`after Ethereum block ${rt(t.notBefore)}`;case"upper-bounded":return`before Ethereum block ${rt(t.notAfter)}`;default:return"with no Ethereum bound in this bundle"}}function rt(t){return t.blockNumber!==void 0?t.blockNumber:t.blockHash}function Zo(t){return t?"; ordered by counter position within the epoch, since the recordings between are not in this bundle":""}function gh(t,e,n){let r=[],o=t.verification;o===void 0?r.push({name:"signature",result:"UNDETERMINED",detail:"the anchor proof was not verified"}):o.status==="failed"?r.push({name:"signature",result:"FALSE",detail:`the anchor proof does not verify: ${o.reason??"unspecified failure"}`}):r.push({name:"signature",result:"TRUE",detail:`anchor proof verifies under signer key ${Xo(t.publicKeyB64)}`});let i;if(n.length>0){let s=n.find(a=>a.verified);if(s!==void 0)i=s.witnessPath,r.push({name:"witness",result:"TRUE",detail:`block header ${s.witnessPath} hashes (keccak-256) to the anchored block hash${e.blockNumber!==void 0?` of block ${e.blockNumber}`:""}`});else{let a=n[0];i=a.witnessPath,r.push({name:"witness",result:"FALSE",detail:`block header ${a.witnessPath} contradicts this anchor: ${a.detail??a.reason??"witness verification failed"}`})}}return{proofHash:t.proofHash,...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.counter!==void 0?{counter:t.counter}:{},...e.blockNumber!==void 0?{blockNumber:e.blockNumber}:{},...e.blockHash!==void 0?{blockHash:e.blockHash}:{},...i!==void 0?{witnessPath:i}:{},lines:r,result:er(r.map(s=>s.result))}}function bh(t){let e=[],n=new Set,r=o=>{n.has(o)||(n.add(o),e.push({name:"contradiction",result:"FALSE",detail:o}))};for(let o of t.anomalies.anomalies)th.has(o.code)||r(`${o.code}: ${o.message}`);for(let o of t.anomalies.divergences)r(`${o.kind}: ${o.explanation}`);for(let o of t.authorities.anomalies)r(`${o.code}: ${o.message}`);for(let o of t.witnesses.findings)(o.code==="witness-unmatched"||o.code==="witness-malformed"||o.code==="witness-rlp-invalid")&&r(`${o.code}: ${o.message}`);for(let o of t.ingest.findings)o.code==="proofhash-mismatch"&&r(`${o.code}: ${o.message}${o.path!==void 0?` (${o.path})`:""}`);return e}function yh(t,e,n,r){let o=[],i=0n,s=0;for(let d of t.anomalies.anomalies)if(d.code==="unexplained-counter-positions"){let h=d.details?.count;h!==void 0&&/^[0-9]+$/.test(h)&&(i+=BigInt(h))}else d.code==="chain-break-missing"&&(s+=d.proofHashes.length);i>0n&&o.push(`${i} causal position${i===1n?"":"s"} between the earliest and latest recording here ${i===1n?"is":"are"} not in this bundle: normal for an export, which is an excerpt of the chain; a full-epoch audit checks them`),s>0&&o.push(`${s} recording${s===1?"":"s"} link${s===1?"s":""} to a predecessor that is not in this bundle: normal for an export`);let a=t.ingest.artifacts.filter(d=>d.matchedProofHashes.length===0&&r?.has(d.sha256Hex)===!0);a.length>0&&o.push(`${a.length} file${a.length===1?"":"s"} in this bundle ${a.length===1?"is":"are"} the original of a fused recording: ${a.slice(0,5).map(d=>d.paths[0]??"(unnamed)").join(", ")}${a.length>5?", \u2026":""}. The original itself receives only the ceiling (it existed no later than the commit); the fused bytes receive the interval`);let c=t.ingest.artifacts.filter(d=>d.matchedProofHashes.length===0&&r?.has(d.sha256Hex)!==!0);if(c.length>0&&e.length>0){let d=c.slice(0,5).map(h=>`${h.paths[0]??"(unnamed)"} (sha256:${h.sha256Hex.slice(0,16)}\u2026)`).join(", ");o.push(`${c.length} file${c.length===1?"":"s"} in this bundle match${c.length===1?"es":""} no recording here: ${d}${c.length>5?", \u2026":""}. If ${c.length===1?"it":"one of them"} was meant to be a recorded file, its bytes differ from what was recorded`)}let f=n.filter(d=>d.witnessPath===void 0);f.length>0&&o.push(`${f.length} Ethereum anchor${f.length===1?"":"s"} in this bundle ha${f.length===1?"s":"ve"} no block-header witness file, so ${f.length===1?"its":"their"} block hash${f.length===1?" is":"es are"} not verified here and no bound is derived from ${f.length===1?"it":"them"}`);for(let d of t.ingest.unsupportedVersions)o.push(`${d.path} is proof-shaped but its version "${d.version}" is not bitgraph/1; it was not checked`);let u=t.ingest.counts;if((u.exactDuplicates>0||u.semanticDuplicates>0)&&o.push(`${u.exactDuplicates+u.semanticDuplicates} duplicate proof file${u.exactDuplicates+u.semanticDuplicates===1?"":"s"} collapsed to one recording each`),t.ingest.manifest!==void 0)for(let d of t.ingest.findings)typeof d.code=="string"&&d.code.startsWith("manifest-")&&o.push(`${d.code}: ${d.message}`);return e.length===0&&n.length===0&&o.push("no BitGraph proofs were found in this bundle"),o}function wh(t,e){let n=[];return t&&n.push("whether the anchored Ethereum blocks are canonical: their headers are recomputed here, but canonicality needs an Ethereum node or a block explorer"),e!==void 0&&n.push(`whether ${e}'s published key file has changed since it was pinned: a pin is read as stored; pin the domain again to refresh it`),n.push("whether the public ledger holds these exact recordings at these positions: this is an offline check; drop the file on bitgraph.ing to compare against the ledger"),n.push("whether an epoch key was later quarantined: that is published outside any bundle"),n}function xh(t,e,n,r){if(e.length===0&&n.length===0)return"UNDETERMINED: no BitGraph proofs were found in this bundle.";let o=e.length,i=`${o} recording${o===1?"":"s"}`;if(t==="TRUE"){let a=e[0];return o===1&&a!==void 0?`TRUE: this file was recorded${a.counter!==void 0?` at position ${a.counter}${a.epochId!==void 0?` of epoch ${Xo(a.epochId)}`:""}`:""}, ${mh(a.bounds)}.`:`TRUE: ${i} verified: files match, signatures and attestations hold, enclave measurements published${n.length>0?", Ethereum bounds verified from block headers in the bundle":""}.`}if(t==="FALSE")return`FALSE: evidence in this bundle contradicts itself. ${[...e.flatMap(c=>c.lines.filter(f=>f.result==="FALSE").map(f=>`${f.name}: ${f.detail}`)),...n.flatMap(c=>c.lines.filter(f=>f.result==="FALSE").map(f=>`${f.name}: ${f.detail}`)),...r.map(c=>c.detail)][0]??""}`.trim();let s=[...e.flatMap(a=>a.lines.filter(c=>c.result==="UNDETERMINED").map(c=>c.detail)),...n.flatMap(a=>a.lines.filter(c=>c.result==="UNDETERMINED").map(c=>c.detail))];return`UNDETERMINED: nothing here contradicts the ${i}, but the evidence does not fully decide. ${s[0]??""}`.trim()}function Xo(t){return t===void 0?"(none)":t.length>12?`${t.slice(0,12)}\u2026`:t}function rn(t){return t===void 0?"(none)":t.length>16?`${t.slice(0,16)}\u2026`:t}mn.sha512Async=async(...t)=>En(mn.concatBytes(...t));var ic=typeof globalThis.crypto<"u"&&globalThis.crypto.subtle!==void 0;function sc(t){return new Promise((e,n)=>{let r=[],o=()=>{t.readEntries(i=>{if(i.length===0){e(r);return}r.push(...i),o()},n)};o()})}function Eh(t){return new Promise((e,n)=>t.file(e,n))}async function ti(t,e,n){if(t.isFile){let r=await Eh(t);n.push({path:e+t.name,file:r});return}if(t.isDirectory){let r=t.createReader(),o=await sc(r);for(let i of o)i.name!==".DS_Store"&&await ti(i,`${e}${t.name}/`,n)}}async function Bh(t){let n=Array.from(t.items??[]).map(o=>typeof o.webkitGetAsEntry=="function"?o.webkitGetAsEntry():null).filter(o=>o!==null);if(n.length===0)return Array.from(t.files??[]).map(o=>({path:o.name,file:o}));let r=[];if(n.length===1&&n[0]!==void 0&&n[0].isDirectory){let o=n[0];for(let i of await sc(o.createReader()))i.name!==".DS_Store"&&await ti(i,"",r)}else for(let o of n)await ti(o,"",r);return r.length===0?Array.from(t.files??[]).map(o=>({path:o.name,file:o})):r}function ec(t){let e=Array.from(t.files??[]),n=e.map(s=>s.webkitRelativePath||s.name),r=n.map(s=>s.indexOf("/")),o=n.length>0&&r.every(s=>s>0)?n[0].slice(0,r[0]):void 0,i=o!==void 0&&n.every(s=>s.startsWith(`${o}/`));return e.map((s,a)=>({path:i?n[a].slice(o.length+1):n[a],file:s})).filter(s=>!s.path.endsWith("/.DS_Store")&&s.path!==".DS_Store")}function vh(t){return t.map(e=>({path:e.path,open:()=>e.file.arrayBuffer().then(n=>new Uint8Array(n))}))}function $(t,e={},n=[]){let r=document.createElement(t);for(let[o,i]of Object.entries(e))o==="class"?r.className=i:r.setAttribute(o,i);for(let o of n)r.append(typeof o=="string"?document.createTextNode(o):o);return r}function ni(t){return t==="TRUE"?null:$("span",{class:t==="FALSE"?"mark false":"mark undet"},[t])}function sn(t,e,n={}){let r=$("div",{class:"field-head"},[$("span",{class:"field-label"},[t])]),o=n.mark!==void 0?ni(n.mark):null;return o!==null&&r.append(o),$("div",{class:"field"},[r,$("span",{class:n.mono?"field-value mono":"field-value"},[e])])}function ot(t,e,n={}){let r=n.open===!0,o=$("span",{class:"chev","aria-hidden":"true"});o.innerHTML='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="square" stroke-linejoin="miter"><path d="M9 6 L15 12 L9 18"/></svg>';let i=$("button",{class:`opener-head${n.tone==="danger"?" danger":""}`,type:"button","aria-expanded":String(r)},[$("span",{},[t]),o]),s=$("div",{class:"opener-body"},e),a=$("section",{class:"card"},[i,s]),c=()=>{i.classList.toggle("open",r),i.setAttribute("aria-expanded",String(r)),s.hidden=!r,o.classList.toggle("open",r)};return i.addEventListener("click",()=>{r=!r,c()}),c(),a}function Ah(t){return t==="TRUE"?"BitGraph Verified":t==="FALSE"?"Verification Failed":"Not Fully Verified"}function kh(t){return t===void 0?"":`#${Number(t).toLocaleString("en-US")}`}function Ih(t){return new Date(t*1e3).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"})}function on(t,e){return new Date(t*1e3).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",second:"2-digit",...e?{timeZoneName:"short"}:{}})}function Hh(t){return new Date(t*1e3).toLocaleString("en-US",{month:"numeric",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",timeZoneName:"short"})}function tc(t){let e=t.bounds,n=i=>$("span",{class:"when-grey"},[i]),r=i=>$("span",{class:"when-dark"},[i]),o=$("div",{class:"when"});if(e.notBefore!==void 0||e.notAfter!==void 0){let i=e.notBefore??e.notAfter;o.append($("div",{class:"when-date"},[Ih(i.timestamp)]));let s=$("div",{class:"when-line"});e.notBefore!==void 0&&e.notAfter!==void 0?s.append(n("after "),r(on(e.notBefore.timestamp,!0)),n(", then an anchor at "),r(on(e.notAfter.timestamp,!1)),n(" (not an upper bound)")):e.notBefore!==void 0?s.append(n("after "),r(on(e.notBefore.timestamp,!0))):e.notAfter!==void 0&&s.append(n("no lower bound in this bundle; an anchor followed at "),r(on(e.notAfter.timestamp,!0)),n(" (not an upper bound)")),o.append(s)}else o.append($("div",{class:"when-line"},[n("no verified Ethereum bound in this bundle")]));return o}function Jo(t){if(t.fused===void 0)return null;let e=i=>$("span",{class:"when-grey"},[i]),n=i=>$("span",{class:"when-dark"},[i]),r=$("div",{class:"when"}),o=$("div",{class:"when-line"});return t.fused.floor!==null?o.append(e("fused bytes assembled after "),n(on(t.fused.floor.timestamp,!0)),e(`, the last anchor before slot ${t.fused.span?.slotCounter??"?"}`)):o.append(e(t.fused.floorDetail)),r.append(o),r}var Sh=/\.(jpe?g|png|gif|webp|avif|bmp|svg)$/i,Th=/\.(mp4|m4v|mov|webm|ogv)$/i,Ch=/\.(mp3|wav|m4a|aac|flac|ogg|oga)$/i,Rh=/\.(txt|md|markdown|json|csv|tsv|log|xml|yaml|yml|html?|css|js|ts|py|sh|rtf)$/i;function $h(t){let e=t.subarray(0,Math.min(2048,t.length));if(!e.length)return!1;let n=0;for(let r of e){if(r===0)return!1;(r===9||r===10||r===13||r>=32)&&n++}return n/e.length>.97}function Ph(t,e){let n=t.toLowerCase();return n.endsWith(".pdf")?"pdf":Sh.test(n)?"image":Th.test(n)?"video":Ch.test(n)?"audio":Rh.test(n)||$h(e)?"text":"other"}function Dh(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t<10*1024?1:0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function Nh(t,e,n){if(n==="image"||n==="video"){let r=URL.createObjectURL(t),o=n==="image"?$("img",{src:r,alt:t.name,style:"display:block;max-width:100%;max-height:min(70vh,640px);width:auto;height:auto;object-fit:contain;border-radius:0"}):$("video",{src:r,controls:"",style:"display:block;max-width:100%;max-height:min(70vh,640px);border-radius:0"});return $("div",{style:"padding:20px;display:flex;align-items:center;justify-content:center"},[o])}if(n==="audio"){let r=URL.createObjectURL(t);return $("div",{style:"padding:20px 16px"},[$("audio",{src:r,controls:"",style:"display:block;width:100%"})])}if(n==="text")try{let r=new TextDecoder("utf-8",{fatal:!1}).decode(e.subarray(0,6e3)),o=r.split(`
153
- `),i=o.slice(0,24).join(`
154
- `).slice(0,3e3),s=o.length>24||r.length>i.length||e.byteLength>6e3;return $("pre",{class:"excerpt"},[i+(s?`
155
- \u2026`:"")])}catch{return null}return null}function nc(t,e,n,r){let o=t.lines.find(s=>s.name==="file"),i=$("div",{class:r?"file-row above":"file-row"});if(t.filePath!==void 0){let s=$("span",{class:"file-ident"},[$("span",{class:"file-name"},[t.filePath])]);e!==void 0&&s.append(document.createTextNode(` \xB7 ${Dh(e.size)}`)),i.append(s);let a=$("span",{class:"file-right"});e!==void 0&&n!==void 0&&(n==="image"||n==="text"||n==="pdf")&&a.append($("a",{class:"bg-arrow-link",href:URL.createObjectURL(e),target:"_blank",rel:"noopener"},["Open ",$("span",{class:"arrow","aria-hidden":"true"},["\u2192"])]));let c=o!==void 0?ni(o.result):null;c!==null&&a.append(c),a.childNodes.length>0&&i.append(a)}else{i.append($("span",{class:"file-missing"},["file not in this bundle"]));let s=o!==void 0?ni(o.result):null;s!==null&&i.append(s)}return i}function Ve(t,e,n=!1){return sn(t,e,{mono:n})}function rc(t,e){let n=document.getElementById("title-action");if(n===null)return;let r=$("a",{class:"bg-arrow-link",href:"#"},[t+" ",$("span",{class:"arrow","aria-hidden":"true"},["\u2192"])]);r.addEventListener("click",o=>{o.preventDefault(),e()}),n.replaceChildren(r)}function oc(t){let e={file:"File",signature:"Signature",attestation:"Hardware Enclave attestation",enclave:"Enclave identity",witness:"Block header",contradiction:"Contradiction",fused:"Fused artifact"};return t.lines.map(n=>sn(e[n.name]??n.name,n.detail,{mark:n.result}))}function Oh(t,e,n,r){let o=e==="before"?"Recorded after this block":e==="after"?"An anchor followed this recording (not an upper bound)":`Ethereum anchor ${n+1}`,i=[];if(t.blockNumber!==void 0&&i.push(Ve("Block",kh(t.blockNumber),!0)),r!==void 0&&i.push(Ve("Block Time",Hh(r))),t.blockHash!==void 0&&i.push(Ve("Block Hash",t.blockHash,!0)),t.counter!==void 0&&i.push(Ve("Anchor position",`#${t.counter}`,!0)),t.blockNumber!==void 0){let s=$("a",{class:"field-link",href:`https://etherscan.io/block/${t.blockNumber}`,target:"_blank",rel:"noopener"},[`https://etherscan.io/block/${t.blockNumber}`]);i.push($("div",{class:"field"},[$("span",{class:"field-label"},["Etherscan"]),s]))}for(let s of t.lines)i.push(sn(s.name==="witness"?"Block header":"Anchor signature",s.detail,{mark:s.result}));return t.witnessPath===void 0&&i.push(sn("Block header","no block-header witness in this bundle, so this anchor's block hash is not verified here and it bounds nothing")),ot(t.result==="TRUE"?o:`${o} [${t.result}]`,i)}async function Lh(t,e,n,r){e.replaceChildren();let o=()=>location.reload();if(t.recordings.length===0&&t.anchors.length===0){n.textContent="No BitGraph Found",e.append($("section",{class:"card primary"},[$("div",{class:"notice"},["No BitGraph proof was found in what you chose. A recording is a folder named for the file it holds, like BitGraph (photo.jpg). Inside it are proof.json, the file itself, and an ethereum-anchors folder."])])),rc("Choose a recording folder",o),e.append(ot("Report JSON",[$("pre",{class:"json"},[JSON.stringify(t,null,2)])]));let f=document.getElementById("more");f.replaceChildren(),f.hidden=!0;return}n.textContent=Ah(t.result);let i=t.recordings.length===1?t.recordings[0]:void 0,s=$("section",{class:"card primary"});if(t.result!=="TRUE"&&s.append($("div",{class:`notice ${t.result.toLowerCase()}`},[t.summary])),i!==void 0){s.append(tc(i));let f=Jo(i);f!==null&&s.append(f);let u=i.filePath!==void 0?r.get(i.filePath):void 0,d,h=null;if(u!==void 0){let l=new Uint8Array(await u.arrayBuffer());d=Ph(u.name,l),h=Nh(u,l,d)}h!==null&&s.append(h),s.append(nc(i,u,d,h!==null)),i.counter!==void 0&&s.append(Ve("Position",`#${i.counter}${i.epochId!==void 0?` \xB7 epoch ${i.epochId}`:""}`,!0)),s.append(Ve("File Hash",i.digestB64,!0))}else if(t.recordings.length>1)for(let f of t.recordings)s.append(nc(f,f.filePath!==void 0?r.get(f.filePath):void 0,void 0,!1));else s.append(Ve("Recordings","no recordings in this bundle"));if(e.append(s),rc("Check another BitGraph",o),i!==void 0){let f=i.lines.filter(u=>u.result!=="TRUE").length;e.append(ot(f===0?"Recording checks":`Recording checks ${f} not verified`,oc(i),{open:t.result!=="TRUE"}))}else t.recordings.forEach((f,u)=>{e.append(ot(`Recording ${u+1}: ${f.filePath??f.digestB64.slice(0,16)+"\u2026"} [${f.result}]`,[tc(f),...Jo(f)!==null?[Jo(f)]:[],...f.counter!==void 0?[Ve("Position",`#${f.counter}${f.epochId!==void 0?` \xB7 epoch ${f.epochId}`:""}`,!0)]:[],Ve("File Hash",f.digestB64,!0),...oc(f)],{open:f.result!=="TRUE"}))});let a=new Map;for(let f of t.recordings)f.bounds.notBefore&&a.set(f.bounds.notBefore.anchorProofHash,f.bounds.notBefore.timestamp),f.bounds.notAfter&&a.set(f.bounds.notAfter.anchorProofHash,f.bounds.notAfter.timestamp);t.anchors.forEach((f,u)=>{let d="other";i!==void 0&&(i.bounds.notBefore?.anchorProofHash===f.proofHash?d="before":i.bounds.notAfter?.anchorProofHash===f.proofHash&&(d="after")),e.append(Oh(f,d,u,a.get(f.proofHash)))}),t.contradictions.length>0&&e.append(ot(`Contradictions ${t.contradictions.length}`,t.contradictions.map(f=>sn("Contradiction",f.detail,{mark:"FALSE"})),{open:!0,tone:"danger"})),t.notes.length>0&&e.append(ot(`Notes ${t.notes.length}`,[$("ul",{class:"list"},t.notes.map(f=>$("li",{},[f])))])),e.append(ot("Not checked",[$("ul",{class:"list"},t.notChecked.map(f=>$("li",{},[f])))])),e.append(ot("Report JSON",[$("pre",{class:"json"},[JSON.stringify(t,null,2)])]));let c=document.getElementById("more");c.replaceChildren(),c.hidden=!0}async function Qo(t){let e=document.getElementById("drop"),n=document.getElementById("results"),r=document.getElementById("status");if(t.length===0){r.textContent="Nothing readable was dropped.";return}e.classList.add("busy"),r.textContent=`Checking ${t.length} file${t.length===1?"":"s"}\u2026`;try{let o=await Ao(vh(t),{label:"dropped"}),i=await Qa(o,{webCryptoAvailable:ic});document.getElementById("camera").hidden=!0,document.getElementById("deck").hidden=!0,document.querySelector(".bitgraph-wrap")?.classList.add("bitgraph-results"),document.querySelector(".bitgraph-hero")?.classList.add("results"),r.textContent="",n.hidden=!1;let s=new Map(t.map(a=>[a.path,a.file]));await Lh(i,n,document.getElementById("title"),s),document.title=`${i.result} \xB7 BitGraph verify`}catch(o){r.textContent=`The check could not run: ${o.message}`}finally{e.classList.remove("busy")}}function ei(){let t=document.querySelector(".bitgraph-wrap");t&&t.style.setProperty("--bg-wrap-min",`${Math.round(window.innerHeight)}px`)}function Mh(){let t=document.getElementById("drop"),e=document.getElementById("status"),n=document.getElementById("pick-files"),r=document.getElementById("pick-folder");ei(),window.addEventListener("resize",ei),window.addEventListener("orientationchange",ei),ic||(e.textContent="This browser context has no WebCrypto, so attestations will read UNDETERMINED here; open the file directly (file://) or over https, or run bitgraph-play check.");let o=!1,i=!1,s=!1,a=()=>{t.classList.toggle("hot",o||i||s),t.classList.toggle("over",s)};t.addEventListener("mouseenter",()=>{o=!0,a()}),t.addEventListener("mouseleave",()=>{o=!1,a()}),t.addEventListener("focusin",()=>{i=!0,a()}),t.addEventListener("focusout",()=>{i=!1,a()});let c=f=>{f.preventDefault(),f.stopPropagation()};for(let f of["dragenter","dragover"])t.addEventListener(f,u=>{c(u),s=!0,a()}),document.body.addEventListener(f,c);for(let f of["dragleave","drop"])t.addEventListener(f,u=>{c(u),s=!1,a()}),document.body.addEventListener(f,c);t.addEventListener("drop",f=>{let u=f.dataTransfer;u!==null&&(e.textContent="Reading the drop\u2026",Bh(u).then(d=>{if(d.length===0){e.textContent="Nothing readable was dropped. Click the box and choose the recording's folder instead.";return}return Qo(d)},d=>{e.textContent=`The drop could not be read here: ${d.message}. Click the box and choose the recording's folder instead.`}))}),t.addEventListener("click",()=>r.click()),t.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r.click())}),n.addEventListener("change",()=>void Qo(ec(n))),r.addEventListener("change",()=>void Qo(ec(r)))}document.addEventListener("DOMContentLoaded",Mh);})();
152
+ -----END CERTIFICATE-----`;function Gd(){return Za.replace(/-----BEGIN CERTIFICATE-----/,"").replace(/-----END CERTIFICATE-----/,"").replace(/\s+/g,"")}function Ya(){return new Uint8Array(B.Buffer.from(Gd(),"base64"))}async function Ja(t,e){let n=[],o={},r,i,s,a,c,f=()=>({documentValid:!1,checks:n,failure:[...n].reverse().find(u=>!u.pass)?.detail,...r!==void 0?{pcr0:r}:{},pcrs:o,...i!==void 0?{moduleId:i}:{},...s!==void 0?{timestamp:s}:{},...a!==void 0?{certChainLength:a}:{},...c!==void 0?{userDataB64:c}:{}});try{let u=Yd(t);if(u===null)return n.push({name:"CBOR Decode",pass:!1,detail:"reportB64 is not valid base64"}),f();let d=Ge(u,0).value;if(!Array.isArray(d)||d.length<4)return n.push({name:"CBOR Decode",pass:!1,detail:"Not a valid COSE_Sign1 array"}),f();n.push({name:"CBOR Decode",pass:!0,detail:"COSE_Sign1 envelope parsed"});let h=d[0],l=d[2],m=d[3];if(!(h instanceof Uint8Array)||!(l instanceof Uint8Array)||!(m instanceof Uint8Array))return n.push({name:"COSE Structure",pass:!1,detail:"Missing protected/payload/signature"}),f();let p=Ge(l,0).value;if(!p||typeof p!="object"||Array.isArray(p))return n.push({name:"Payload Decode",pass:!1,detail:"Could not decode attestation payload"}),f();o=nh(p),r=o[0],i=typeof p.module_id=="string"?p.module_id:void 0,s=typeof p.timestamp=="number"?p.timestamp:void 0;let w=p.user_data;c=w instanceof Uint8Array&&w.length>0?B.Buffer.from(w).toString("base64"):void 0;let b=p.cabundle,k=p.certificate;if(!(k instanceof Uint8Array))return n.push({name:"Leaf Certificate",pass:!1,detail:"No leaf certificate in attestation"}),f();a=(Array.isArray(b)?b.length:0)+1;let v=zr(k),O=Qd(h,l),z=await qr(m,O,v.publicKey);if(n.push({name:"ECDSA P-384 Signature",pass:z,detail:z?"Attestation signed by leaf certificate":"Signature verification failed against leaf certificate public key"}),!z)return f();if(!Array.isArray(b)||b.length===0||!b.every(A=>A instanceof Uint8Array))return n.push({name:"Certificate Chain",pass:!1,detail:"Empty cabundle"}),f();let S=[...b,k].map(zr),U=!0,F="";for(let A=1;A<S.length;A++){let C=S[A],D=S[A-1];if(!await qr(C.signature,C.tbsCertificate,D.publicKey)){U=!1,F=`Certificate ${A} signature invalid (parent: ${A-1})`;break}}if(n.push({name:"Certificate Chain",pass:U,detail:U?`${S.length} certificates, each signed by parent`:F}),!U)return f();let G=e?.trustedRootCaDer===void 0,q=zr(e?.trustedRootCaDer??Ya()),le=S[0],N=await qr(le.signature,le.tbsCertificate,q.publicKey);if(n.push({name:"AWS Nitro Root CA",pass:N,detail:N?G?"Chain anchored to AWS Nitro Root G1 (CN=aws.nitro-enclaves)":"Chain anchored to the supplied trust root (non-default trust material)":G?"Top of chain not signed by AWS Nitro Root CA":"Top of chain not signed by the supplied trust root"}),!N)return f();let se=!0,oe=`All ${S.length} certificate validity windows contain the document timestamp`;if(s===void 0)se=!1,oe="Attestation document carries no timestamp; certificate validity cannot be evaluated offline";else for(let A=0;A<S.length;A++){let C=S[A];if(s<C.notBeforeMs||s>C.notAfterMs){se=!1,oe=`Certificate ${A} validity window [${new Date(C.notBeforeMs).toISOString()}, ${new Date(C.notAfterMs).toISOString()}] does not contain the document timestamp ${new Date(s).toISOString()}`;break}}if(n.push({name:"Certificate Validity Window",pass:se,detail:oe}),!se)return f();let L;e?.expectedPcr0!==void 0&&(L=r===e.expectedPcr0,n.push({name:"PCR0 Match",pass:L,detail:L?"PCR0 inside attestation matches declared measurement":`PCR0 mismatch: expected ${e.expectedPcr0.slice(0,16)}..., got ${(r??"").slice(0,16)}...`}));let E;return e?.expectedUserDataB64!==void 0&&(E=c!==void 0&&c===e.expectedUserDataB64,n.push({name:"Bound to this proof",pass:E,detail:E?"Attestation user_data matches this proof's canonical hash":c!==void 0?"Attestation user_data does not match this proof":"Attestation carries no user_data to bind"})),{documentValid:!0,checks:n,...r!==void 0?{pcr0:r}:{},pcrs:o,...i!==void 0?{moduleId:i}:{},...s!==void 0?{timestamp:s}:{},certChainLength:a,...c!==void 0?{userDataB64:c}:{},...L!==void 0?{pcr0Matches:L}:{},...E!==void 0?{userDataMatches:E}:{}}}catch(u){return n.push({name:"Verification Error",pass:!1,detail:u instanceof Error?u.message:String(u)}),f()}}async function Gr(t,e,n){let o=[],r=[],i={proofsWithDeclaredMeasurement:0,proofsWithDocument:0,documentsValidated:0,documentsFailed:0,pcr0Matches:0,pcr0Mismatches:0,userDataBound:0,userDataUnbound:0};for(let s of t.proofs){let a=s.measurement!==void 0&&s.measurement.length>0?s.measurement:void 0;a!==void 0&&i.proofsWithDeclaredMeasurement++;let c=Zd(s),f={proofHash:s.proofHash,declaredMeasurementPresent:a!==void 0,...a!==void 0?{declaredMeasurement:a}:{},documentPresent:c!==void 0,...c?.format!==void 0?{attestationFormat:c.format}:{},documentValidated:!1,checks:[]};if(c!==void 0){i.proofsWithDocument++;let u=await Ja(c.reportB64,{...a!==void 0?{expectedPcr0:a}:{},expectedUserDataB64:cr(s.proof),...n?.trustedRootCaDer!==void 0?{trustedRootCaDer:n.trustedRootCaDer}:{}});f.documentValidated=u.documentValid,f.checks=u.checks,u.pcr0!==void 0&&(f.attestedPcr0=u.pcr0),f.pcrs=u.pcrs,u.moduleId!==void 0&&(f.moduleId=u.moduleId),u.timestamp!==void 0&&(f.timestamp=u.timestamp),u.certChainLength!==void 0&&(f.certChainLength=u.certChainLength),u.userDataB64!==void 0&&(f.userDataB64=u.userDataB64),u.documentValid?(i.documentsValidated++,u.pcr0Matches!==void 0&&(f.pcr0MatchesDeclared=u.pcr0Matches,u.pcr0Matches?i.pcr0Matches++:(i.pcr0Mismatches++,r.push({code:"attestation-measurement-mismatch",...Kr(s),message:"the validated attestation document's PCR0 does not equal the proof's declared environment.measurement. Declared and attested measurements are reported separately and disagree here.",details:{proofHash:s.proofHash,declared:a,...u.pcr0!==void 0?{attested:u.pcr0}:{}}}))),u.userDataMatches!==void 0&&(f.userDataBoundToProof=u.userDataMatches,u.userDataMatches?i.userDataBound++:(i.userDataUnbound++,r.push({code:"attestation-user-data-mismatch",...Kr(s),message:"the validated attestation document's user_data is not bound to this proof's canonical hash. A genuine attestation lifted from another proof would look exactly like this.",details:{proofHash:s.proofHash,...u.userDataB64!==void 0?{userDataB64:u.userDataB64}:{}}})))):(i.documentsFailed++,u.failure!==void 0&&(f.validationFailure=u.failure),r.push({code:"attestation-invalid",...Kr(s),message:`attestation document failed offline validation: ${u.failure??"unknown"}. Presence of a document is reported separately and proves nothing by itself.`,details:{proofHash:s.proofHash}}))}o.push(f)}return e!==void 0&&Wd(e,o),{records:o,findings:r,counts:i}}function Wd(t,e){let n=new Map(e.map(o=>[o.proofHash,o]));for(let o of t.groups){if(!o.attestationPresent)continue;let r=o.proofHashes.map(f=>n.get(f)).filter(f=>f!==void 0&&f.documentPresent);if(r.length===0)continue;let i=r.filter(f=>f.documentValidated),s=r.length-i.length,a=[...new Set(i.map(f=>f.attestedPcr0).filter(f=>f!==void 0))].sort(),c=a.length===1?a[0]:void 0;o.attested={status:s===0&&i.length>0?"validated":"validation-failed",...c!==void 0?{attestedMeasurement:c}:{},...c!==void 0&&o.measurement!==void 0?{matchesDeclared:c===o.measurement}:{},validatedProofCount:i.length,failedProofCount:s,...a.length>1?{attestedMeasurements:a}:{}}}}function Zd(t){let e=t.proof.environment;if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.attestation;if(n===null||typeof n!="object"||Array.isArray(n))return;let o=n.reportB64;if(typeof o!="string"||o.length===0)return;let r=n.format;return{reportB64:o,...typeof r=="string"?{format:r}:{}}}function Kr(t){let e=t.sources[0]?.path;return e!==void 0?{path:e}:{}}function Yd(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4!==0;)e+="=";let n=B.Buffer.from(e,"base64");return n.toString("base64")!==e?null:new Uint8Array(n)}function Wr(t){return t<24?new Uint8Array([t]):t<256?new Uint8Array([24,t]):t<65536?new Uint8Array([25,t>>8,t&255]):new Uint8Array([26,t>>>24&255,t>>>16&255,t>>>8&255,t&255])}function Vr(t){let e=Wr(t.length);e[0]=e[0]&31|64;let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}function Xd(t){let e=new TextEncoder().encode(t),n=Wr(e.length);n[0]=n[0]&31|96;let o=new Uint8Array(n.length+e.length);return o.set(n,0),o.set(e,n.length),o}function Jd(t){let e=Wr(t.length);e[0]=e[0]&31|128;let n=e.length+t.reduce((i,s)=>i+s.length,0),o=new Uint8Array(n),r=0;o.set(e,r),r+=e.length;for(let i of t)o.set(i,r),r+=i.length;return o}function Qd(t,e){return Jd([Xd("Signature1"),Vr(t),Vr(new Uint8Array(0)),Vr(e)])}function Ge(t,e=0){let n=t[e];if(n===void 0)throw new Error("CBOR: unexpected end of input");let o=n>>5,r=n&31;e++;let i=a=>{let c=t[a];if(c===void 0)throw new Error("CBOR: unexpected end of input");return c};function s(){if(r<24)return r;if(r===24){let a=i(e);return e+=1,a}if(r===25){let a=i(e)<<8|i(e+1);return e+=2,a}if(r===26){let a=(i(e)<<24|i(e+1)<<16|i(e+2)<<8|i(e+3))>>>0;return e+=4,a}if(r===27){let a=0;for(let c=0;c<8;c++)a=a*256+i(e+c);return e+=8,a}throw new Error(`Unsupported CBOR length info: ${r}`)}switch(o){case 0:return{value:s(),offset:e};case 1:return{value:-1-s(),offset:e};case 2:{let a=s();if(e+a>t.length)throw new Error("CBOR: byte string is truncated");return{value:t.slice(e,e+a),offset:e+a}}case 3:{let a=s();if(e+a>t.length)throw new Error("CBOR: text string is truncated");return{value:new TextDecoder().decode(t.slice(e,e+a)),offset:e+a}}case 4:{if(r===31){let f=[];for(;i(e)!==255;){let u=Ge(t,e);f.push(u.value),e=u.offset}return{value:f,offset:e+1}}let a=s(),c=[];for(let f=0;f<a;f++){let u=Ge(t,e);c.push(u.value),e=u.offset}return{value:c,offset:e}}case 5:{if(r===31){let f={};for(;i(e)!==255;){let u=Ge(t,e);e=u.offset;let d=Ge(t,e);e=d.offset,f[String(u.value)]=d.value}return{value:f,offset:e+1}}let a=s(),c={};for(let f=0;f<a;f++){let u=Ge(t,e);e=u.offset;let d=Ge(t,e);e=d.offset,c[String(u.value)]=d.value}return{value:c,offset:e}}case 6:return s(),Ge(t,e);case 7:{if(r===20)return{value:!1,offset:e};if(r===21)return{value:!0,offset:e};if(r===22)return{value:null,offset:e};if(r===23)return{value:void 0,offset:e};throw new Error(`Unsupported CBOR simple value: ${r}`)}default:throw new Error(`Unsupported CBOR major type: ${o}`)}}function zr(t){let n=sn(t,0).contentStart,o=ie(t,n),r=t.slice(n,o.end);n=o.end,n=ie(t,n).end;let s=ie(t,n),a=t.slice(s.contentStart+1,s.end),c=th(a,48),{publicKey:f,notBeforeMs:u,notAfterMs:d}=eh(r);return{tbsCertificate:r,signature:c,publicKey:f,notBeforeMs:u,notAfterMs:d}}function ie(t,e){let n=t[e];if(n===void 0)throw new Error("DER: unexpected end of input");let o=e+1,r=t[o++];if(r===void 0)throw new Error("DER: unexpected end of input");if(r&128){let s=r&127;r=0;for(let a=0;a<s;a++){let c=t[o++];if(c===void 0)throw new Error("DER: unexpected end of input");r=r*256+c}}let i=o+r;if(i>t.length)throw new Error("DER: element is truncated");return{tag:n,contentStart:o,contentEnd:i,end:i}}function sn(t,e){let n=ie(t,e);if(n.tag!==48)throw new Error(`Expected SEQUENCE at offset ${e}, got tag 0x${n.tag.toString(16)}`);return n}function eh(t){let n=sn(t,0).contentStart;t[n]===160&&(n=ie(t,n).end),n=ie(t,n).end,n=ie(t,n).end,n=ie(t,n).end;let o=sn(t,n),r=o.contentStart,i=ie(t,r);r=i.end;let s=ie(t,r),a=Xa(t,i),c=Xa(t,s);n=o.end,n=ie(t,n).end;let u=sn(t,n).contentStart;u=ie(t,u).end;let h=ie(t,u);return{publicKey:t.slice(h.contentStart+1,h.end),notBeforeMs:a,notAfterMs:c}}function Xa(t,e){let n=String.fromCharCode(...t.slice(e.contentStart,e.contentEnd)),o,r;if(e.tag===23){if(!/^\d{12}Z$/.test(n))throw new Error(`DER: malformed UTCTime "${n}"`);let u=Number.parseInt(n.slice(0,2),10);o=u<50?2e3+u:1900+u,r=n.slice(2)}else if(e.tag===24){if(!/^\d{14}Z$/.test(n))throw new Error(`DER: malformed GeneralizedTime "${n}"`);o=Number.parseInt(n.slice(0,4),10),r=n.slice(4)}else throw new Error(`DER: expected a Time value, got tag 0x${e.tag.toString(16)}`);let i=Number.parseInt(r.slice(0,2),10),s=Number.parseInt(r.slice(2,4),10),a=Number.parseInt(r.slice(4,6),10),c=Number.parseInt(r.slice(6,8),10),f=Number.parseInt(r.slice(8,10),10);return Date.UTC(o,i-1,s,a,c,f)}function th(t,e){let o=sn(t,0).contentStart,r=ie(t,o);if(r.tag!==2)throw new Error("Expected INTEGER for r");let i=t.slice(r.contentStart,r.end);o=r.end;let s=ie(t,o);if(s.tag!==2)throw new Error("Expected INTEGER for s");let a=t.slice(s.contentStart,s.end);if(i[0]===0&&i.length>e&&(i=i.slice(1)),a[0]===0&&a.length>e&&(a=a.slice(1)),i.length>e||a.length>e)throw new Error("ECDSA signature component longer than the curve coordinate size");let c=new Uint8Array(e*2);return c.set(i,e-i.length),c.set(a,e*2-a.length),c}async function qr(t,e,n){if(n.length!==97||n[0]!==4||t.length!==96)return!1;try{let o=await tr.subtle.importKey("raw",n,{name:"ECDSA",namedCurve:"P-384"},!1,["verify"]);return await tr.subtle.verify({name:"ECDSA",hash:"SHA-384"},o,t,e)}catch{return!1}}function nh(t){let e={},n=t.pcrs;if(!n||typeof n!="object")return e;for(let[o,r]of Object.entries(n))if(r instanceof Uint8Array){let i=B.Buffer.from(r).toString("hex");i.replace(/0/g,"").length>0&&(e[Number(o)]=i)}return e}y();var Qn="0.4.1";function Qa(){return Qn}async function Zr(t,e){let n=e?.startedAt??new Date().toISOString(),o=await Hr(t,e?.trustAnchors!==void 0?{trustAnchors:e.trustAnchors}:void 0),r=await Rr(t),i=await $r(t,r),s=Dr(t),a=Lr(t),c=await _r(t,a),f=jr(t,r,a,c),u=await Gr(t,s,e?.trustedRootCaDer!==void 0?{trustedRootCaDer:e.trustedRootCaDer}:void 0);return{runMetadata:{toolVersion:Qa(),startedAt:n,bundlePath:t.bundlePath,container:t.container},ingest:t,verification:o,reconstruction:r,anomalies:i,authorities:s,anchors:a,witnesses:c,temporal:f,attestations:u}}y();y();y();y();y();function eo(t){let e=!1;for(let n of t){if(n==="FALSE")return"FALSE";n==="UNDETERMINED"&&(e=!0)}return e?"UNDETERMINED":"TRUE"}y();y();var Yr="0.10.0";var ah=[{pcr0:"8530a6399399c4f23d89f5a1faa2e8bf2e09a5959f117070fca08148377f92c902c695fc926c17f67f35f110327dca92",label:"genesis",period:"2026-05-15 to 2026-06-27"},{pcr0:"bb9dd158703603ec222fe565495ceaa7edc08f665da5c1cddad91442ac2211731390267036d79deb720d13fb704f648a",label:"enclave v2 (reproducible)",period:"2026-06-27 to 2026-07-05"},{pcr0:"e2fccbae77ee40aac4830e84f195e05d69eb4547bbd961f4d3459feba10807140424aca42ad03810354982598c86b9cb",label:"enclave v4 (reproducible)",period:"2026-07-05 to 2026-07-29"},{pcr0:"6483cedffed74680ffb287507744a398b288c3fb943eb3f2e4fe889f8b60b3d575ad8942350360b69a1bd7bf713df27f",label:"enclave v5 (reproducible)",period:"2026-07-29 to 2026-09-05"},{pcr0:"cd8ba52d340fb1be78610b59953ded2ceca23be1cfcc7ab504a26b8fdcd7ba92090f49e28a32d008df046ec4212f77bf",label:"enclave v6 (reproducible)",period:"2026-09-05 onward"}],ch=new Set(["unexplained-counter-positions","chain-break-missing","epochlink-terminal-missing","epochlink-dangling"]);async function rc(t,e){let n=e,o=await Zr(t,{startedAt:""});if(n?.fuseEvidence===void 0){let r=await fh(t);n={...n,fuseEvidence:r.evidence,fuseOriginHexes:r.originHexes}}return uh(o,n)}async function fh(t){let e=new Map,n=new Set,o=[],r=new Set;for(let s of t.proofs){let a=wt(s.proof);if(a===null)continue;let c=Ft(s.proof.artifact.digestB64),f=c!==null?Re(c):null,u=a.originDigest!==void 0?Re(a.originDigest):null;o.push({proof:s,artifactHex:f,originHex:u}),f!==null&&r.add(f),u!==null&&r.add(u)}if(o.length===0)return{evidence:e,originHexes:n};let i=new Map;for await(let s of Sr(t,r))i.has(s.sha256Hex)||i.set(s.sha256Hex,s.bytes);Ke();try{for(let s of o){let a=s.artifactHex!==null?i.get(s.artifactHex):void 0,c=s.originHex!==null?i.get(s.originHex):void 0;c!==void 0&&s.originHex!==null&&n.add(s.originHex);let f=a??c;f!==void 0&&e.set(s.proof.proofHash,await Er({proof:s.proof.proof,bytes:f}))}}finally{Ke()}return{evidence:e,originHexes:n}}function uh(t,e){let n=e?.webCryptoAvailable??!0,o=new Map(t.anchors.anchors.map(p=>[p.proofHash,p])),r=new Map(t.attestations.records.map(p=>[p.proofHash,p])),i=new Map;for(let p of t.temporal.segments)for(let w of p.memberProofHashes)i.set(w,p);let s=new Map;for(let p of t.witnesses.outcomes){if(p.anchorProofHash===void 0)continue;let w=s.get(p.anchorProofHash)??[];w.push(p),s.set(p.anchorProofHash,w)}let a=new Map;for(let p of t.ingest.artifacts)for(let w of p.matchedProofHashes)!a.has(w)&&p.paths[0]!==void 0&&a.set(w,p.paths[0]);let c=[],f=[];for(let p of t.ingest.proofs){let w=o.get(p.proofHash);w!==void 0?f.push(xh(p,w,s.get(p.proofHash)??[])):c.push(dh(p,r.get(p.proofHash),i.get(p.proofHash),a.get(p.proofHash),n,e?.fuseEvidence,o))}ec(c),ec(f);let u=Eh(t),d=Bh(t,c,f,e?.fuseOriginHexes),h=vh(f.length>0),l=[...c.map(p=>p.result),...f.map(p=>p.result),...u.map(p=>p.result)],m=l.length===0?"UNDETERMINED":eo(l);return{check:"bitgraph-check/1",result:m,summary:Ah(m,c,f,u),recordings:c,anchors:f,contradictions:u,notes:d,notChecked:h,evaluator:{name:"bitgraph-player",version:Yr,audit:Qn},network:"none"}}function ec(t){let e=n=>[n.epochId??"",n.counter!==void 0&&/^[0-9]+$/.test(n.counter)?BigInt(n.counter):void 0];t.sort((n,o)=>{let[r,i]=e(n),[s,a]=e(o);return r!==s?r<s?-1:1:i===void 0||a===void 0?i===void 0?a===void 0?0:1:-1:i<a?-1:i>a?1:0})}function dh(t,e,n,o,r,i,s){let a=[],c=t.verification,f=t.proof.artifact.digestB64;c?.tier==="full"?a.push({name:"file",result:c.status==="verified"||c.status==="failed"?"TRUE":"UNDETERMINED",detail:c.status==="verified"||c.status==="failed"?`${o??"the matched file"} hashes to the recorded digest ${f}`:`no file in this bundle hashes to the recorded digest ${f}`}):a.push({name:"file",result:"UNDETERMINED",detail:`no file in this bundle hashes to the recorded digest ${f}; the recording cannot be bound to bytes in hand`}),c===void 0?a.push({name:"signature",result:"UNDETERMINED",detail:"the proof was not verified"}):c.status==="failed"?a.push({name:"signature",result:"FALSE",detail:`the proof does not verify: ${c.reason??"unspecified failure"}`}):a.push({name:"signature",result:"TRUE",detail:`Ed25519 signature and slot binding verify under signer key ${Qr(t.publicKeyB64)}`});let u=mh(e,r);a.push(u.line),a.push(gh(u.attestedPcr0,u.line.result));let d=wt(t.proof),h;if(d!==null){let m=hh(n,s,t.slotCounter,t.chainId),p=ph(d.placement,d.originDigest!==void 0?t.proof.attribution?.message??null:null,i?.get(t.proofHash),m,t);a.push(p.line),h=p.fused}let l=eo(a.map(m=>m.result));return{proofHash:t.proofHash,digestB64:f,...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.counter!==void 0?{counter:t.counter}:{},...t.slotCounter!==void 0?{slotCounter:t.slotCounter}:{},...t.publicKeyB64!==void 0?{publicKeyB64:t.publicKeyB64}:{},...o!==void 0&&c?.tier==="full"?{filePath:o}:{},lines:a,result:l,bounds:bh(n),...h!==void 0?{fused:h}:{}}}var Jr="bitgraph:main";function hh(t,e,n,o=Jr){if(o!==Jr||t===void 0||e===void 0||n===void 0||!/^[0-9]+$/.test(n))return null;let r=BigInt(n),i;for(let s of t.lowerBounds){if(s.kind!=="not-before")continue;let a=e.get(s.anchorProofHash);if(a===void 0||a.counter===void 0||!/^[0-9]+$/.test(a.counter)||BigInt(a.counter)>=r)continue;if(i===void 0){i=s;continue}let c=s.blockNumber!==void 0?BigInt(s.blockNumber):BigInt(s.timestamp),f=i.blockNumber!==void 0?BigInt(i.blockNumber):BigInt(i.timestamp);c>f&&(i=s)}return i===void 0?null:{...i.blockNumber!==void 0?{blockNumber:i.blockNumber}:{},blockHash:i.blockHash,timestamp:i.timestamp,anchorProofHash:i.anchorProofHash,evidence:"counter-order"}}var lh="floor undetermined: no anchor precedes this slot in its epoch";function tc(t){return`anchored block ${t.blockNumber!==void 0?`#${t.blockNumber}`:t.blockHash} (${new Date(t.timestamp*1e3).toISOString()})`}function ph(t,e,n,o,r){let i=r.slotCounter??"?",s=t!==null?` (placement ${t})`:" (placement undeclared)",a=o!==null?`assembled after ${tc(o)}, the last verified anchor preceding slot ${i} in this epoch`:r.chainId!==Jr?`floor undetermined: the slot is on chain "${r.chainId}", not the anchored chain`:lh,c=n?.span!==void 0&&n.span!==null?{slotCounter:n.span.slotCounter,commitCounter:n.span.commitCounter,positions:n.span.positions}:r.slotCounter!==void 0&&r.counter!==void 0?{slotCounter:r.slotCounter,commitCounter:r.counter,positions:(BigInt(r.counter)-BigInt(r.slotCounter)).toString()}:null,f=(n?.statements??[]).map(h=>o!==null?h.replace(`at position ${i},`,`at position ${i}, which followed ${tc(o)},`):h),u=(h,l)=>({category:h,placement:n?.placement??t,originDigestB64:n?.originDigestB64??e,evidence:l,statements:f,floor:o,floorDetail:a,span:c});if(n===void 0)return{line:{name:"fused",result:"UNDETERMINED",detail:`marked fused${s}, but neither the fused bytes nor ${e!==null?"the original":"an original"} is in this bundle, so the commitment to slot ${i} cannot be checked`},fused:u("NO_EVIDENCE",null)};let d=n.category==="FUSED_FROM_ORIGIN"||n.fileDigestB64!==n.artifactDigestB64&&n.category!=="NO_MATCH"?"original":"fused-bytes";switch(n.category){case"FUSED_DIRECT":return{line:{name:"fused",result:"TRUE",detail:`the fused bytes carry the commitment to slot ${i}${s}`},fused:u(n.category,"fused-bytes")};case"FUSED_FROM_ORIGIN":return{line:{name:"fused",result:"TRUE",detail:`the original rebuilds the committed fused bytes${s}; they carry the commitment to slot ${i}`},fused:u(n.category,"original")};case"INVALID_SLOT_COMMITMENT":return{line:{name:"fused",result:"FALSE",detail:`the fused bytes do not carry the commitment to this proof's slot ${i}: ${n.reason??""}`},fused:u(n.category,d)};case"INVALID_ORIGIN_ATTRIBUTION":return{line:{name:"fused",result:"FALSE",detail:`the declared origin contradicts the origin inside the fused bytes: ${n.reason??""}`},fused:u(n.category,d)};case"RECONSTRUCTION_MISMATCH":return{line:{name:"fused",result:"FALSE",detail:`the file matching the declared origin does not rebuild the committed fused bytes: ${n.reason??""}`},fused:u(n.category,"original")};case"UNDETERMINED_PLACEMENT":return{line:{name:"fused",result:"UNDETERMINED",detail:`${n.reason??"the placement is not registered"}; this verifier cannot check the commitment`},fused:u(n.category,d)};case"INVALID_UNDERLYING_PROOF":return{line:{name:"fused",result:"UNDETERMINED",detail:"not checked: the proof itself does not verify (see the signature line)"},fused:u(n.category,d)};default:return{line:{name:"fused",result:"UNDETERMINED",detail:`the commitment could not be checked: ${n.reason??n.category}`},fused:u(n.category,d)}}}function mh(t,e){return t===void 0||!t.documentPresent?{line:{name:"attestation",result:"UNDETERMINED",detail:"no attestation document in this proof"}}:e?t.documentValidated?t.userDataBoundToProof!==!0?{line:{name:"attestation",result:"FALSE",detail:"attestation document validates but its user_data is not this proof: the document belongs to some other proof"},attestedPcr0:t.attestedPcr0}:t.pcr0MatchesDeclared!==!0?{line:{name:"attestation",result:"FALSE",detail:`attestation validates and binds this proof, but its PCR0 ${an(t.attestedPcr0)} is not the measurement the signed body declares ${an(t.declaredMeasurement)}`},attestedPcr0:t.attestedPcr0}:{line:{name:"attestation",result:"TRUE",detail:`AWS Nitro attestation validates to the AWS root, binds this exact proof (user_data), and attests PCR0 ${an(t.attestedPcr0)}`},attestedPcr0:t.attestedPcr0}:{line:{name:"attestation",result:"FALSE",detail:`attestation document does not validate: ${t.validationFailure??"unspecified failure"}`}}:{line:{name:"attestation",result:"UNDETERMINED",detail:"attestation not checked: this environment cannot verify ECDSA P-384 (no WebCrypto); open the verifier from a file or https page, or run bitgraph-play check"}}}function gh(t,e){if(e!=="TRUE"||t===void 0)return{name:"enclave",result:"UNDETERMINED",detail:"enclave identity rests on a validated attestation, which this recording does not have here"};let n=ah.find(o=>o.pcr0===t.toLowerCase());return n===void 0?{name:"enclave",result:"UNDETERMINED",detail:`PCR0 ${an(t)} is not among the BitGraph enclave measurements this verifier knows (player ${Yr}); compare it against the measurements published at bitgraph.ing/docs/self-host-tee`}:{name:"enclave",result:"TRUE",detail:`PCR0 ${an(t)} is the published BitGraph ${n.label} measurement (${n.period})`}}function bh(t){if(t===void 0)return{status:"unanchored",detail:"no verified Ethereum anchor bounds this recording in this bundle"};let e=nc(t.lowerBounds,"not-before"),n=nc(t.upperBounds,"not-after"),o=e===void 0?void 0:oc(e),r=n===void 0?void 0:oc(n),i=o!==void 0&&r!==void 0?"lower-bounded-with-following-anchor":o!==void 0?"lower-bounded":r!==void 0?"upper-bounded":"unanchored",s=i==="unanchored"?"no verified Ethereum anchor bounds this recording in this bundle":`recorded ${yh(i,o,r)}`;return{status:i,...o!==void 0?{notBefore:o}:{},...r!==void 0?{notAfter:r}:{},detail:s}}function yh(t,e,n){switch(t){case"lower-bounded-with-following-anchor":return`after Ethereum block ${at(e)} (header verified in this bundle); precedes an anchor that consumed block ${at(n)} (header verified), an anchor-latency assumption rather than an upper bound on this recording`+Xr(e.weaker||n.weaker);case"lower-bounded":return`after Ethereum block ${at(e)} (header verified in this bundle); no verified upper bound here`+Xr(e.weaker);case"upper-bounded":return`before Ethereum block ${at(n)} (header verified in this bundle); no verified lower bound here`+Xr(n.weaker);default:return"with no verified Ethereum bound in this bundle"}}function nc(t,e){let n=t.filter(r=>r.kind===e);return n.length===0?void 0:[...n].sort((r,i)=>{let s=r.blockNumber!==void 0?BigInt(r.blockNumber):BigInt(r.timestamp),a=i.blockNumber!==void 0?BigInt(i.blockNumber):BigInt(i.timestamp);return s!==a?e==="not-before"?s>a?-1:1:s<a?-1:1:r.weaker!==i.weaker?r.weaker?1:-1:0})[0]}function oc(t){return{...t.blockNumber!==void 0?{blockNumber:t.blockNumber}:{},blockHash:t.blockHash,timestamp:t.timestamp,anchorProofHash:t.anchorProofHash,evidence:t.evidence,weaker:t.weaker}}function wh(t){switch(t.status){case"lower-bounded-with-following-anchor":return`after Ethereum block ${at(t.notBefore)}, then an anchor at block ${at(t.notAfter)}`;case"lower-bounded":return`after Ethereum block ${at(t.notBefore)}`;case"upper-bounded":return`before Ethereum block ${at(t.notAfter)}`;default:return"with no Ethereum bound in this bundle"}}function at(t){return t.blockNumber!==void 0?t.blockNumber:t.blockHash}function Xr(t){return t?"; ordered by counter position within the epoch, since the recordings between are not in this bundle":""}function xh(t,e,n){let o=[],r=t.verification;r===void 0?o.push({name:"signature",result:"UNDETERMINED",detail:"the anchor proof was not verified"}):r.status==="failed"?o.push({name:"signature",result:"FALSE",detail:`the anchor proof does not verify: ${r.reason??"unspecified failure"}`}):o.push({name:"signature",result:"TRUE",detail:`anchor proof verifies under signer key ${Qr(t.publicKeyB64)}`});let i;if(n.length>0){let s=n.find(a=>a.verified);if(s!==void 0)i=s.witnessPath,o.push({name:"witness",result:"TRUE",detail:`block header ${s.witnessPath} hashes (keccak-256) to the anchored block hash${e.blockNumber!==void 0?` of block ${e.blockNumber}`:""}`});else{let a=n[0];i=a.witnessPath,o.push({name:"witness",result:"FALSE",detail:`block header ${a.witnessPath} contradicts this anchor: ${a.detail??a.reason??"witness verification failed"}`})}}return{proofHash:t.proofHash,...t.epochId!==void 0?{epochId:t.epochId}:{},chainId:t.chainId,...t.counter!==void 0?{counter:t.counter}:{},...e.blockNumber!==void 0?{blockNumber:e.blockNumber}:{},...e.blockHash!==void 0?{blockHash:e.blockHash}:{},...i!==void 0?{witnessPath:i}:{},lines:o,result:eo(o.map(s=>s.result))}}function Eh(t){let e=[],n=new Set,o=r=>{n.has(r)||(n.add(r),e.push({name:"contradiction",result:"FALSE",detail:r}))};for(let r of t.anomalies.anomalies)ch.has(r.code)||o(`${r.code}: ${r.message}`);for(let r of t.anomalies.divergences)o(`${r.kind}: ${r.explanation}`);for(let r of t.authorities.anomalies)o(`${r.code}: ${r.message}`);for(let r of t.witnesses.findings)(r.code==="witness-unmatched"||r.code==="witness-malformed"||r.code==="witness-rlp-invalid")&&o(`${r.code}: ${r.message}`);for(let r of t.ingest.findings)r.code==="proofhash-mismatch"&&o(`${r.code}: ${r.message}${r.path!==void 0?` (${r.path})`:""}`);return e}function Bh(t,e,n,o){let r=[],i=0n,s=0;for(let d of t.anomalies.anomalies)if(d.code==="unexplained-counter-positions"){let h=d.details?.count;h!==void 0&&/^[0-9]+$/.test(h)&&(i+=BigInt(h))}else d.code==="chain-break-missing"&&(s+=d.proofHashes.length);i>0n&&r.push(`${i} causal position${i===1n?"":"s"} between the earliest and latest recording here ${i===1n?"is":"are"} not in this bundle: normal for an export, which is an excerpt of the chain; a full-epoch audit checks them`),s>0&&r.push(`${s} recording${s===1?"":"s"} link${s===1?"s":""} to a predecessor that is not in this bundle: normal for an export`);let a=t.ingest.artifacts.filter(d=>d.matchedProofHashes.length===0&&o?.has(d.sha256Hex)===!0);a.length>0&&r.push(`${a.length} file${a.length===1?"":"s"} in this bundle ${a.length===1?"is":"are"} the original of a fused recording: ${a.slice(0,5).map(d=>d.paths[0]??"(unnamed)").join(", ")}${a.length>5?", \u2026":""}. The original itself receives only the ceiling (it existed no later than the commit); the fused bytes receive the interval`);let c=t.ingest.artifacts.filter(d=>d.matchedProofHashes.length===0&&o?.has(d.sha256Hex)!==!0);if(c.length>0&&e.length>0){let d=c.slice(0,5).map(h=>`${h.paths[0]??"(unnamed)"} (sha256:${h.sha256Hex.slice(0,16)}\u2026)`).join(", ");r.push(`${c.length} file${c.length===1?"":"s"} in this bundle match${c.length===1?"es":""} no recording here: ${d}${c.length>5?", \u2026":""}. If ${c.length===1?"it":"one of them"} was meant to be a recorded file, its bytes differ from what was recorded`)}let f=n.filter(d=>d.witnessPath===void 0);f.length>0&&r.push(`${f.length} Ethereum anchor${f.length===1?"":"s"} in this bundle ha${f.length===1?"s":"ve"} no block-header witness file, so ${f.length===1?"its":"their"} block hash${f.length===1?" is":"es are"} not verified here and no bound is derived from ${f.length===1?"it":"them"}`);for(let d of t.ingest.unsupportedVersions)r.push(`${d.path} is proof-shaped but its version "${d.version}" is not bitgraph/1; it was not checked`);let u=t.ingest.counts;if((u.exactDuplicates>0||u.semanticDuplicates>0)&&r.push(`${u.exactDuplicates+u.semanticDuplicates} duplicate proof file${u.exactDuplicates+u.semanticDuplicates===1?"":"s"} collapsed to one recording each`),t.ingest.manifest!==void 0)for(let d of t.ingest.findings)typeof d.code=="string"&&d.code.startsWith("manifest-")&&r.push(`${d.code}: ${d.message}`);return e.length===0&&n.length===0&&r.push("no BitGraph proofs were found in this bundle"),r}function vh(t){let e=[];return t&&e.push("whether the anchored Ethereum blocks are canonical: their headers are recomputed here, but canonicality needs an Ethereum node or a block explorer"),e.push("whether the public ledger holds these exact recordings at these positions: this is an offline check; drop the file on bitgraph.ing to compare against the ledger"),e.push("whether an epoch key was later quarantined: that is published outside any bundle"),e}function Ah(t,e,n,o){if(e.length===0&&n.length===0)return"UNDETERMINED: no BitGraph proofs were found in this bundle.";let r=e.length,i=`${r} recording${r===1?"":"s"}`;if(t==="TRUE"){let a=e[0];return r===1&&a!==void 0?`TRUE: this file was recorded${a.counter!==void 0?` at position ${a.counter}${a.epochId!==void 0?` of epoch ${Qr(a.epochId)}`:""}`:""}, ${wh(a.bounds)}.`:`TRUE: ${i} verified: files match, signatures and attestations hold, enclave measurements published${n.length>0?", Ethereum bounds verified from block headers in the bundle":""}.`}if(t==="FALSE")return`FALSE: evidence in this bundle contradicts itself. ${[...e.flatMap(c=>c.lines.filter(f=>f.result==="FALSE").map(f=>`${f.name}: ${f.detail}`)),...n.flatMap(c=>c.lines.filter(f=>f.result==="FALSE").map(f=>`${f.name}: ${f.detail}`)),...o.map(c=>c.detail)][0]??""}`.trim();let s=[...e.flatMap(a=>a.lines.filter(c=>c.result==="UNDETERMINED").map(c=>c.detail)),...n.flatMap(a=>a.lines.filter(c=>c.result==="UNDETERMINED").map(c=>c.detail))];return`UNDETERMINED: nothing here contradicts the ${i}, but the evidence does not fully decide. ${s[0]??""}`.trim()}function Qr(t){return t===void 0?"(none)":t.length>12?`${t.slice(0,12)}\u2026`:t}function an(t){return t===void 0?"(none)":t.length>16?`${t.slice(0,16)}\u2026`:t}yn.sha512Async=async(...t)=>An(yn.concatBytes(...t));var uc=typeof globalThis.crypto<"u"&&globalThis.crypto.subtle!==void 0;function dc(t){return new Promise((e,n)=>{let o=[],r=()=>{t.readEntries(i=>{if(i.length===0){e(o);return}o.push(...i),r()},n)};r()})}function Ih(t){return new Promise((e,n)=>t.file(e,n))}async function oi(t,e,n){if(t.isFile){let o=await Ih(t);n.push({path:e+t.name,file:o});return}if(t.isDirectory){let o=t.createReader(),r=await dc(o);for(let i of r)i.name!==".DS_Store"&&await oi(i,`${e}${t.name}/`,n)}}async function kh(t){let n=Array.from(t.items??[]).map(r=>typeof r.webkitGetAsEntry=="function"?r.webkitGetAsEntry():null).filter(r=>r!==null);if(n.length===0)return Array.from(t.files??[]).map(r=>({path:r.name,file:r}));let o=[];if(n.length===1&&n[0]!==void 0&&n[0].isDirectory){let r=n[0];for(let i of await dc(r.createReader()))i.name!==".DS_Store"&&await oi(i,"",o)}else for(let r of n)await oi(r,"",o);return o.length===0?Array.from(t.files??[]).map(r=>({path:r.name,file:r})):o}function ic(t){let e=Array.from(t.files??[]),n=e.map(s=>s.webkitRelativePath||s.name),o=n.map(s=>s.indexOf("/")),r=n.length>0&&o.every(s=>s>0)?n[0].slice(0,o[0]):void 0,i=r!==void 0&&n.every(s=>s.startsWith(`${r}/`));return e.map((s,a)=>({path:i?n[a].slice(r.length+1):n[a],file:s})).filter(s=>!s.path.endsWith("/.DS_Store")&&s.path!==".DS_Store")}function Sh(t){return t.map(e=>({path:e.path,open:()=>e.file.arrayBuffer().then(n=>new Uint8Array(n))}))}function $(t,e={},n=[]){let o=document.createElement(t);for(let[r,i]of Object.entries(e))r==="class"?o.className=i:o.setAttribute(r,i);for(let r of n)o.append(typeof r=="string"?document.createTextNode(r):r);return o}function ri(t){return t==="TRUE"?null:$("span",{class:t==="FALSE"?"mark false":"mark undet"},[t])}function fn(t,e,n={}){let o=$("div",{class:"field-head"},[$("span",{class:"field-label"},[t])]),r=n.mark!==void 0?ri(n.mark):null;return r!==null&&o.append(r),$("div",{class:"field"},[o,$("span",{class:n.mono?"field-value mono":"field-value"},[e])])}function ct(t,e,n={}){let o=n.open===!0,r=$("span",{class:"chev","aria-hidden":"true"});r.innerHTML='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="square" stroke-linejoin="miter"><path d="M9 6 L15 12 L9 18"/></svg>';let i=$("button",{class:`opener-head${n.tone==="danger"?" danger":""}`,type:"button","aria-expanded":String(o)},[$("span",{},[t]),r]),s=$("div",{class:"opener-body"},e),a=$("section",{class:"card"},[i,s]),c=()=>{i.classList.toggle("open",o),i.setAttribute("aria-expanded",String(o)),s.hidden=!o,r.classList.toggle("open",o)};return i.addEventListener("click",()=>{o=!o,c()}),c(),a}function Th(t){return t==="TRUE"?"BitGraph Verified":t==="FALSE"?"Verification Failed":"Not Fully Verified"}function Hh(t){return t===void 0?"":`#${Number(t).toLocaleString("en-US")}`}function Ch(t){return new Date(t*1e3).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"})}function cn(t,e){return new Date(t*1e3).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",second:"2-digit",...e?{timeZoneName:"short"}:{}})}function Rh(t){return new Date(t*1e3).toLocaleString("en-US",{month:"numeric",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",timeZoneName:"short"})}function sc(t){let e=t.bounds,n=i=>$("span",{class:"when-grey"},[i]),o=i=>$("span",{class:"when-dark"},[i]),r=$("div",{class:"when"});if(e.notBefore!==void 0||e.notAfter!==void 0){let i=e.notBefore??e.notAfter;r.append($("div",{class:"when-date"},[Ch(i.timestamp)]));let s=$("div",{class:"when-line"});e.notBefore!==void 0&&e.notAfter!==void 0?s.append(n("after "),o(cn(e.notBefore.timestamp,!0)),n(", then an anchor at "),o(cn(e.notAfter.timestamp,!1)),n(" (not an upper bound)")):e.notBefore!==void 0?s.append(n("after "),o(cn(e.notBefore.timestamp,!0))):e.notAfter!==void 0&&s.append(n("no lower bound in this bundle; an anchor followed at "),o(cn(e.notAfter.timestamp,!0)),n(" (not an upper bound)")),r.append(s)}else r.append($("div",{class:"when-line"},[n("no verified Ethereum bound in this bundle")]));return r}function ei(t){if(t.fused===void 0)return null;let e=i=>$("span",{class:"when-grey"},[i]),n=i=>$("span",{class:"when-dark"},[i]),o=$("div",{class:"when"}),r=$("div",{class:"when-line"});return t.fused.floor!==null?r.append(e("fused bytes assembled after "),n(cn(t.fused.floor.timestamp,!0)),e(`, the last anchor before slot ${t.fused.span?.slotCounter??"?"}`)):r.append(e(t.fused.floorDetail)),o.append(r),o}var $h=/\.(jpe?g|png|gif|webp|avif|bmp|svg)$/i,Ph=/\.(mp4|m4v|mov|webm|ogv)$/i,Dh=/\.(mp3|wav|m4a|aac|flac|ogg|oga)$/i,Nh=/\.(txt|md|markdown|json|csv|tsv|log|xml|yaml|yml|html?|css|js|ts|py|sh|rtf)$/i;function Mh(t){let e=t.subarray(0,Math.min(2048,t.length));if(!e.length)return!1;let n=0;for(let o of e){if(o===0)return!1;(o===9||o===10||o===13||o>=32)&&n++}return n/e.length>.97}function Lh(t,e){let n=t.toLowerCase();return n.endsWith(".pdf")?"pdf":$h.test(n)?"image":Ph.test(n)?"video":Dh.test(n)?"audio":Nh.test(n)||Mh(e)?"text":"other"}function Oh(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t<10*1024?1:0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function Fh(t,e,n){if(n==="image"||n==="video"){let o=URL.createObjectURL(t),r=n==="image"?$("img",{src:o,alt:t.name,style:"display:block;max-width:100%;max-height:min(70vh,640px);width:auto;height:auto;object-fit:contain;border-radius:0"}):$("video",{src:o,controls:"",style:"display:block;max-width:100%;max-height:min(70vh,640px);border-radius:0"});return $("div",{style:"padding:20px;display:flex;align-items:center;justify-content:center"},[r])}if(n==="audio"){let o=URL.createObjectURL(t);return $("div",{style:"padding:20px 16px"},[$("audio",{src:o,controls:"",style:"display:block;width:100%"})])}if(n==="text")try{let o=new TextDecoder("utf-8",{fatal:!1}).decode(e.subarray(0,6e3)),r=o.split(`
153
+ `),i=r.slice(0,24).join(`
154
+ `).slice(0,3e3),s=r.length>24||o.length>i.length||e.byteLength>6e3;return $("pre",{class:"excerpt"},[i+(s?`
155
+ \u2026`:"")])}catch{return null}return null}function ac(t,e,n,o){let r=t.lines.find(s=>s.name==="file"),i=$("div",{class:o?"file-row above":"file-row"});if(t.filePath!==void 0){let s=$("span",{class:"file-ident"},[$("span",{class:"file-name"},[t.filePath])]);e!==void 0&&s.append(document.createTextNode(` \xB7 ${Oh(e.size)}`)),i.append(s);let a=$("span",{class:"file-right"});e!==void 0&&n!==void 0&&(n==="image"||n==="text"||n==="pdf")&&a.append($("a",{class:"bg-arrow-link",href:URL.createObjectURL(e),target:"_blank",rel:"noopener"},["Open ",$("span",{class:"arrow","aria-hidden":"true"},["\u2192"])]));let c=r!==void 0?ri(r.result):null;c!==null&&a.append(c),a.childNodes.length>0&&i.append(a)}else{i.append($("span",{class:"file-missing"},["file not in this bundle"]));let s=r!==void 0?ri(r.result):null;s!==null&&i.append(s)}return i}function We(t,e,n=!1){return fn(t,e,{mono:n})}function cc(t,e){let n=document.getElementById("title-action");if(n===null)return;let o=$("a",{class:"bg-arrow-link",href:"#"},[t+" ",$("span",{class:"arrow","aria-hidden":"true"},["\u2192"])]);o.addEventListener("click",r=>{r.preventDefault(),e()}),n.replaceChildren(o)}function fc(t){let e={file:"File",signature:"Signature",attestation:"Hardware Enclave attestation",enclave:"Enclave identity",witness:"Block header",contradiction:"Contradiction",fused:"Fused artifact"};return t.lines.map(n=>fn(e[n.name]??n.name,n.detail,{mark:n.result}))}function Uh(t,e,n,o){let r=e==="before"?"Recorded after this block":e==="after"?"An anchor followed this recording (not an upper bound)":`Ethereum anchor ${n+1}`,i=[];if(t.blockNumber!==void 0&&i.push(We("Block",Hh(t.blockNumber),!0)),o!==void 0&&i.push(We("Block Time",Rh(o))),t.blockHash!==void 0&&i.push(We("Block Hash",t.blockHash,!0)),t.counter!==void 0&&i.push(We("Anchor position",`#${t.counter}`,!0)),t.blockNumber!==void 0){let s=$("a",{class:"field-link",href:`https://etherscan.io/block/${t.blockNumber}`,target:"_blank",rel:"noopener"},[`https://etherscan.io/block/${t.blockNumber}`]);i.push($("div",{class:"field"},[$("span",{class:"field-label"},["Etherscan"]),s]))}for(let s of t.lines)i.push(fn(s.name==="witness"?"Block header":"Anchor signature",s.detail,{mark:s.result}));return t.witnessPath===void 0&&i.push(fn("Block header","no block-header witness in this bundle, so this anchor's block hash is not verified here and it bounds nothing")),ct(t.result==="TRUE"?r:`${r} [${t.result}]`,i)}async function _h(t,e,n,o){e.replaceChildren();let r=()=>location.reload();if(t.recordings.length===0&&t.anchors.length===0){n.textContent="No BitGraph Found",e.append($("section",{class:"card primary"},[$("div",{class:"notice"},["No BitGraph proof was found in what you chose. A recording is a folder named for the file it holds, like BitGraph (photo.jpg). Inside it are proof.json, the file itself, and an ethereum-anchors folder."])])),cc("Choose a recording folder",r),e.append(ct("Report JSON",[$("pre",{class:"json"},[JSON.stringify(t,null,2)])]));let f=document.getElementById("more");f.replaceChildren(),f.hidden=!0;return}n.textContent=Th(t.result);let i=t.recordings.length===1?t.recordings[0]:void 0,s=$("section",{class:"card primary"});if(t.result!=="TRUE"&&s.append($("div",{class:`notice ${t.result.toLowerCase()}`},[t.summary])),i!==void 0){s.append(sc(i));let f=ei(i);f!==null&&s.append(f);let u=i.filePath!==void 0?o.get(i.filePath):void 0,d,h=null;if(u!==void 0){let l=new Uint8Array(await u.arrayBuffer());d=Lh(u.name,l),h=Fh(u,l,d)}h!==null&&s.append(h),s.append(ac(i,u,d,h!==null)),i.counter!==void 0&&s.append(We("Position",`#${i.counter}${i.epochId!==void 0?` \xB7 epoch ${i.epochId}`:""}`,!0)),s.append(We("File Hash",i.digestB64,!0))}else if(t.recordings.length>1)for(let f of t.recordings)s.append(ac(f,f.filePath!==void 0?o.get(f.filePath):void 0,void 0,!1));else s.append(We("Recordings","no recordings in this bundle"));if(e.append(s),cc("Check another BitGraph",r),i!==void 0){let f=i.lines.filter(u=>u.result!=="TRUE").length;e.append(ct(f===0?"Recording checks":`Recording checks ${f} not verified`,fc(i),{open:t.result!=="TRUE"}))}else t.recordings.forEach((f,u)=>{e.append(ct(`Recording ${u+1}: ${f.filePath??f.digestB64.slice(0,16)+"\u2026"} [${f.result}]`,[sc(f),...ei(f)!==null?[ei(f)]:[],...f.counter!==void 0?[We("Position",`#${f.counter}${f.epochId!==void 0?` \xB7 epoch ${f.epochId}`:""}`,!0)]:[],We("File Hash",f.digestB64,!0),...fc(f)],{open:f.result!=="TRUE"}))});let a=new Map;for(let f of t.recordings)f.bounds.notBefore&&a.set(f.bounds.notBefore.anchorProofHash,f.bounds.notBefore.timestamp),f.bounds.notAfter&&a.set(f.bounds.notAfter.anchorProofHash,f.bounds.notAfter.timestamp);t.anchors.forEach((f,u)=>{let d="other";i!==void 0&&(i.bounds.notBefore?.anchorProofHash===f.proofHash?d="before":i.bounds.notAfter?.anchorProofHash===f.proofHash&&(d="after")),e.append(Uh(f,d,u,a.get(f.proofHash)))}),t.contradictions.length>0&&e.append(ct(`Contradictions ${t.contradictions.length}`,t.contradictions.map(f=>fn("Contradiction",f.detail,{mark:"FALSE"})),{open:!0,tone:"danger"})),t.notes.length>0&&e.append(ct(`Notes ${t.notes.length}`,[$("ul",{class:"list"},t.notes.map(f=>$("li",{},[f])))])),e.append(ct("Not checked",[$("ul",{class:"list"},t.notChecked.map(f=>$("li",{},[f])))])),e.append(ct("Report JSON",[$("pre",{class:"json"},[JSON.stringify(t,null,2)])]));let c=document.getElementById("more");c.replaceChildren(),c.hidden=!0}async function ti(t){let e=document.getElementById("drop"),n=document.getElementById("results"),o=document.getElementById("status");if(t.length===0){o.textContent="Nothing readable was dropped.";return}e.classList.add("busy"),o.textContent=`Checking ${t.length} file${t.length===1?"":"s"}\u2026`;try{let r=await Ir(Sh(t),{label:"dropped"}),i=await rc(r,{webCryptoAvailable:uc});document.getElementById("camera").hidden=!0,document.getElementById("deck").hidden=!0,document.querySelector(".bitgraph-wrap")?.classList.add("bitgraph-results"),document.querySelector(".bitgraph-hero")?.classList.add("results"),o.textContent="",n.hidden=!1;let s=new Map(t.map(a=>[a.path,a.file]));await _h(i,n,document.getElementById("title"),s),document.title=`${i.result} \xB7 BitGraph verify`}catch(r){o.textContent=`The check could not run: ${r.message}`}finally{e.classList.remove("busy")}}function ni(){let t=document.querySelector(".bitgraph-wrap");t&&t.style.setProperty("--bg-wrap-min",`${Math.round(window.innerHeight)}px`)}function jh(){let t=document.getElementById("drop"),e=document.getElementById("status"),n=document.getElementById("pick-files"),o=document.getElementById("pick-folder");ni(),window.addEventListener("resize",ni),window.addEventListener("orientationchange",ni),uc||(e.textContent="This browser context has no WebCrypto, so attestations will read UNDETERMINED here; open the file directly (file://) or over https, or run bitgraph-play check.");let r=!1,i=!1,s=!1,a=()=>{t.classList.toggle("hot",r||i||s),t.classList.toggle("over",s)};t.addEventListener("mouseenter",()=>{r=!0,a()}),t.addEventListener("mouseleave",()=>{r=!1,a()}),t.addEventListener("focusin",()=>{i=!0,a()}),t.addEventListener("focusout",()=>{i=!1,a()});let c=f=>{f.preventDefault(),f.stopPropagation()};for(let f of["dragenter","dragover"])t.addEventListener(f,u=>{c(u),s=!0,a()}),document.body.addEventListener(f,c);for(let f of["dragleave","drop"])t.addEventListener(f,u=>{c(u),s=!1,a()}),document.body.addEventListener(f,c);t.addEventListener("drop",f=>{let u=f.dataTransfer;u!==null&&(e.textContent="Reading the drop\u2026",kh(u).then(d=>{if(d.length===0){e.textContent="Nothing readable was dropped. Click the box and choose the recording's folder instead.";return}return ti(d)},d=>{e.textContent=`The drop could not be read here: ${d.message}. Click the box and choose the recording's folder instead.`}))}),t.addEventListener("click",()=>o.click()),t.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),o.click())}),n.addEventListener("change",()=>void ti(ic(n))),o.addEventListener("change",()=>void ti(ic(o)))}document.addEventListener("DOMContentLoaded",jh);})();
156
156
 
157
157
  </script>
158
158
  </body>