protons-runtime
Advanced tools
Comparing version 5.0.5 to 5.1.0
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ProtonsRuntime = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var ProtonsRuntime=(()=>{var rt=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var u=(r,t)=>{for(var e in t)rt(r,e,{get:t[e],enumerable:!0})},Ae=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of we(t))!ye.call(r,i)&&i!==e&&rt(r,i,{get:()=>t[i],enumerable:!(n=ge(t,i))||n.enumerable});return r};var Be=r=>Ae(rt({},"__esModule",{value:!0}),r);var Vr={};u(Vr,{decodeMessage:()=>Gt,encodeMessage:()=>pe,enumeration:()=>me,message:()=>xe,reader:()=>K,writer:()=>tt});var nt=new Float32Array([-0]),D=new Uint8Array(nt.buffer);function kt(r,t,e){nt[0]=r,t[e]=D[0],t[e+1]=D[1],t[e+2]=D[2],t[e+3]=D[3]}function Vt(r,t){return D[0]=r[t],D[1]=r[t+1],D[2]=r[t+2],D[3]=r[t+3],nt[0]}var it=new Float64Array([-0]),f=new Uint8Array(it.buffer);function Rt(r,t,e){it[0]=r,t[e]=f[0],t[e+1]=f[1],t[e+2]=f[2],t[e+3]=f[3],t[e+4]=f[4],t[e+5]=f[5],t[e+6]=f[6],t[e+7]=f[7]}function Ot(r,t){return f[0]=r[t],f[1]=r[t+1],f[2]=r[t+2],f[3]=r[t+3],f[4]=r[t+4],f[5]=r[t+5],f[6]=r[t+6],f[7]=r[t+7],it[0]}var g=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return T;let e=t<0;e&&(t=-t);let n=Number(t>>32n),i=Number(t-(BigInt(n)<<32n));return e&&(n=~n>>>0,i=~i>>>0,++i>$t&&(i=0,++n>$t&&(n=0))),new r(i,n)}static fromNumber(t){if(t===0)return T;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):T}},T=new g(0,0);T.toBigInt=function(){return 0n};T.zzEncode=T.zzDecode=function(){return this};T.length=function(){return 1};var $t=4294967296n;function Pt(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function jt(r,t,e){if(e-t<1)return"";let i,o=[],s=0,a;for(;t<e;)a=r[t++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ot(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function w(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Q(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var st=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,w(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw w(this,4);return Q(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw w(this,4);return Q(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw w(this,4);let t=Vt(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw w(this,4);let t=Ot(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw w(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return jt(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw w(this,t);this.pos+=t}else do if(this.pos>=this.len)throw w(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new g(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw w(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw w(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw w(this,8);let t=Q(this.buf,this.pos+=4),e=Q(this.buf,this.pos+=4);return new g(t,e)}int64(){return this.readLongVarint().toBigInt()}uint64(){return this.readLongVarint().toBigInt(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}fixed64(){return this.readFixed64().toBigInt()}sfixed64(){return this.readFixed64().toBigInt()}};function K(r){return new st(r instanceof Uint8Array?r:r.subarray())}function Gt(r,t){let e=K(r);return t.decode(e)}function Z(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function L(r=0){return globalThis.Buffer?.allocUnsafe!=null?Z(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var lt={};u(lt,{base10:()=>Ue});function Ie(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var a=r.length,l=r.charAt(0),F=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function M(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var d=0,S=0,x=0,y=h.length;x!==y&&h[x]===0;)x++,d++;for(var A=(y-x)*p+1>>>0,m=new Uint8Array(A);x!==y;){for(var B=h[x],v=0,b=A-1;(B!==0||v<S)&&b!==-1;b--,v++)B+=256*m[b]>>>0,m[b]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");S=v,x++}for(var E=A-S;E!==A&&m[E]===0;)E++;for(var H=l.repeat(d);E<A;++E)H+=r.charAt(m[E]);return H}function X(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var d=0;if(h[d]!==" "){for(var S=0,x=0;h[d]===l;)S++,d++;for(var y=(h.length-d)*F+1>>>0,A=new Uint8Array(y);h[d];){var m=e[h.charCodeAt(d)];if(m===255)return;for(var B=0,v=y-1;(m!==0||B<x)&&v!==-1;v--,B++)m+=a*A[v]>>>0,A[v]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");x=B,d++}if(h[d]!==" "){for(var b=y-x;b!==y&&A[b]===0;)b++;for(var E=new Uint8Array(S+(y-b)),H=S;b!==y;)E[H++]=A[b++];return E}}}function be(h){var d=X(h);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:M,decodeUnsafe:X,decode:be}}var Ee=Ie,Ce=Ee,Jt=Ce;var Kr=new Uint8Array(0);var Wt=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},C=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var Xt=r=>new TextEncoder().encode(r),Ht=r=>new TextDecoder().decode(r);var at=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ht=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Kt(this,t)}},ct=class{constructor(t){this.decoders=t}or(t){return Kt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Kt=(r,t)=>new ct({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),ft=class{constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new at(t,e,n),this.decoder=new ht(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},k=({name:r,prefix:t,encode:e,decode:n})=>new ft(r,t,e,n),U=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:i}=Jt(e,t);return k({prefix:r,name:t,encode:n,decode:o=>C(i(o))})},ve=(r,t,e,n)=>{let i={};for(let p=0;p<t.length;++p)i[t[p]]=p;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,l=0,F=0;for(let p=0;p<o;++p){let M=i[r[p]];if(M===void 0)throw new SyntaxError(`Non-${n} character`);l=l<<e|M,a+=e,a>=8&&(a-=8,s[F++]=255&l>>a)}if(a>=e||255&l<<8-a)throw new SyntaxError("Unexpected end of data");return s},De=(r,t,e)=>{let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,a=0;for(let l=0;l<r.length;++l)for(a=a<<8|r[l],s+=8;s>e;)s-=e,o+=t[i&a>>s];if(s&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o},c=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>k({prefix:t,name:r,encode(i){return De(i,n,e)},decode(i){return ve(i,n,e,r)}});var Ue=U({prefix:"9",name:"base10",alphabet:"0123456789"});var dt={};u(dt,{base16:()=>Se,base16upper:()=>Te});var Se=c({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Te=c({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ut={};u(ut,{base2:()=>Le});var Le=c({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pt={};u(pt,{base256emoji:()=>ke});var Zt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ze=Zt.reduce((r,t,e)=>(r[e]=t,r),[]),Ne=Zt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Fe(r){return r.reduce((t,e)=>(t+=ze[e],t),"")}function Me(r){let t=[];for(let e of r){let n=Ne[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ke=k({prefix:"\u{1F680}",name:"base256emoji",encode:Fe,decode:Me});var mt={};u(mt,{base32:()=>V,base32hex:()=>$e,base32hexpad:()=>je,base32hexpadupper:()=>qe,base32hexupper:()=>Pe,base32pad:()=>Re,base32padupper:()=>Oe,base32upper:()=>Ve,base32z:()=>Ge});var V=c({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ve=c({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Re=c({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oe=c({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$e=c({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pe=c({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),je=c({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qe=c({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ge=c({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xt={};u(xt,{base36:()=>Je,base36upper:()=>We});var Je=U({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),We=U({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bt={};u(bt,{base58btc:()=>I,base58flickr:()=>Xe});var I=U({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xe=U({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gt={};u(gt,{base64:()=>He,base64pad:()=>Qe,base64url:()=>Ke,base64urlpad:()=>Ze});var He=c({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qe=c({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ke=c({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ze=c({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wt={};u(wt,{base8:()=>_e});var _e=c({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yt={};u(yt,{identity:()=>Ye});var Ye=k({prefix:"\0",name:"identity",encode:r=>Ht(r),decode:r=>Xt(r)});var dn=new TextEncoder,un=new TextDecoder;var Bt={};u(Bt,{identity:()=>Br});var rr=te,_t=128,nr=127,ir=~nr,or=Math.pow(2,31);function te(r,t,e){t=t||[],e=e||0;for(var n=e;r>=or;)t[e++]=r&255|_t,r/=128;for(;r&ir;)t[e++]=r&255|_t,r>>>=7;return t[e]=r|0,te.bytes=e-n+1,t}var sr=At,ar=128,Yt=127;function At(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw At.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Yt)<<i:(s&Yt)*Math.pow(2,i),i+=7}while(s>=ar);return At.bytes=o-n,e}var hr=Math.pow(2,7),cr=Math.pow(2,14),fr=Math.pow(2,21),lr=Math.pow(2,28),dr=Math.pow(2,35),ur=Math.pow(2,42),pr=Math.pow(2,49),mr=Math.pow(2,56),xr=Math.pow(2,63),br=function(r){return r<hr?1:r<cr?2:r<fr?3:r<lr?4:r<dr?5:r<ur?6:r<pr?7:r<mr?8:r<xr?9:10},gr={encode:rr,decode:sr,encodingLength:br},wr=gr,j=wr;var q=(r,t=0)=>[j.decode(r,t),j.decode.bytes],R=(r,t,e=0)=>(j.encode(r,t,e),t),O=r=>j.encodingLength(r);var z=(r,t)=>{let e=t.byteLength,n=O(r),i=n+O(e),o=new Uint8Array(i+e);return R(r,o,0),R(e,o,n),o.set(t,i),new $(r,e,t,o)},ee=r=>{let t=C(r),[e,n]=q(t),[i,o]=q(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new $(e,i,s,t)},re=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Wt(r.bytes,e.bytes)}},$=class{constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var ne=0,yr="identity",ie=C,Ar=r=>z(ne,ie(r)),Br={code:ne,name:yr,encode:ie,digest:Ar};var Ct={};u(Ct,{sha256:()=>Ir,sha512:()=>Er});var Et=({name:r,code:t,encode:e})=>new It(r,t,e),It=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?z(this.code,e):e.then(n=>z(this.code,n))}else throw Error("Unknown type, must be binary type")}};var se=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),Ir=Et({name:"sha2-256",code:18,encode:se("SHA-256")}),Er=Et({name:"sha2-512",code:19,encode:se("SHA-512")});var ae=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return vr(e,vt(r),t||I.encoder);default:return Dr(e,vt(r),t||V.encoder)}};var he=new WeakMap,vt=r=>{let t=he.get(r);if(t==null){let e=new Map;return he.set(r,e),e}return t},Y=class r{constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==J)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ur)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=z(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&re(t.multihash,n.multihash)}toString(t){return ae(this,t)}toJSON(){return{"/":ae(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s||ce(n,i,o.bytes))}else if(e[Sr]===!0){let{version:n,multihash:i,code:o}=e,s=ee(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==J)throw new Error(`Version 0 CID must use dag-pb (code: ${J}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=ce(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,J,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=C(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new $(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[M,X]=q(t.subarray(e));return e+=X,M},i=n(),o=J;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,a=n(),l=n(),F=e+l,p=F-s;return{version:i,codec:o,multihashCode:a,digestSize:l,multihashSize:p,size:F}}static parse(t,e){let[n,i]=Cr(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return vt(o).set(n,t),o}},Cr=(r,t)=>{switch(r[0]){case"Q":{let e=t||I;return[I.prefix,e.decode(`${I.prefix}${r}`)]}case I.prefix:{let e=t||I;return[I.prefix,e.decode(r)]}case V.prefix:{let e=t||V;return[V.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},vr=(r,t,e)=>{let{prefix:n}=e;if(n!==I.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i},Dr=(r,t,e)=>{let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i},J=112,Ur=18,ce=(r,t,e)=>{let n=O(r),i=n+O(t),o=new Uint8Array(i+e.byteLength);return R(r,o,0),R(t,o,n),o.set(e,i),o},Sr=Symbol.for("@ipld/js-cid/CID");var Dt={...yt,...ut,...wt,...lt,...dt,...mt,...xt,...bt,...gt,...pt},Sn={...Ct,...Bt};function le(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fe=le("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ut=le("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=L(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tr={utf8:fe,"utf-8":fe,hex:Dt.base16,latin1:Ut,ascii:Ut,binary:Ut,...Dt},de=Tr;function ue(r,t="utf8"){let e=de[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Z(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function St(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return L(s);i+s>t&&(n=L(t),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var N=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Tt(){}var Ft=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Lr=St();function zr(r){return globalThis.Buffer!=null?L(r):Lr(r)}var W=class{len;head;tail;states;constructor(){this.len=0,this.head=new N(Tt,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new N(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Mt((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(zt,10,g.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=g.fromBigInt(t);return this._push(zt,e.length(),e)}int64(t){return this.uint64(t)}sint64(t){let e=g.fromBigInt(t).zzEncode();return this._push(zt,e.length(),e)}bool(t){return this._push(Lt,1,t?1:0)}fixed32(t){return this._push(Nt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=g.fromBigInt(t);return this._push(Nt,4,e.lo)._push(Nt,4,e.hi)}sfixed64(t){return this.fixed64(t)}float(t){return this._push(kt,4,t)}double(t){return this._push(Rt,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Lt,1,0):this.uint32(e)._push(Fr,e,t)}string(t){let e=Pt(t);return e!==0?this.uint32(e)._push(ot,e,t):this._push(Lt,1,0)}fork(){return this.states=new Ft(this),this.head=this.tail=new N(Tt,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new N(Tt,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=zr(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Lt(r,t,e){t[e]=r&255}function Nr(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Mt=class extends N{next;constructor(t,e){super(Nr,t,e),this.next=void 0}};function zt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Nt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Fr(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(W.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Mr,t,r),this},W.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(kr,t,r),this});function Mr(r,t,e){t.set(r,e)}function kr(r,t,e){r.length<40?ot(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(ue(r),e)}function tt(){return new W}function pe(r,t){let e=tt();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var P;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(P||(P={}));function et(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function me(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let a=t(o);s.int32(a)},n=function(o){let s=o.int32();return t(s)};return et("enum",P.VARINT,e,n)}function xe(r,t){return et("message",P.LENGTH_DELIMITED,r,t)}return Be(Vr);})(); | ||
"use strict";var ProtonsRuntime=(()=>{var it=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var p=(r,t)=>{for(var e in t)it(r,e,{get:t[e],enumerable:!0})},Ae=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of we(t))!ye.call(r,i)&&i!==e&&it(r,i,{get:()=>t[i],enumerable:!(n=ge(t,i))||n.enumerable});return r};var Ee=r=>Ae(it({},"__esModule",{value:!0}),r);var Or={};p(Or,{decodeMessage:()=>jt,encodeMessage:()=>pe,enumeration:()=>me,message:()=>xe,reader:()=>Z,writer:()=>rt});var ot=new Float32Array([-0]),C=new Uint8Array(ot.buffer);function Vt(r,t,e){ot[0]=r,t[e]=C[0],t[e+1]=C[1],t[e+2]=C[2],t[e+3]=C[3]}function kt(r,t){return C[0]=r[t],C[1]=r[t+1],C[2]=r[t+2],C[3]=r[t+3],ot[0]}var st=new Float64Array([-0]),f=new Uint8Array(st.buffer);function Rt(r,t,e){st[0]=r,t[e]=f[0],t[e+1]=f[1],t[e+2]=f[2],t[e+3]=f[3],t[e+4]=f[4],t[e+5]=f[5],t[e+6]=f[6],t[e+7]=f[7]}function Ot(r,t){return f[0]=r[t],f[1]=r[t+1],f[2]=r[t+2],f[3]=r[t+3],f[4]=r[t+4],f[5]=r[t+5],f[6]=r[t+6],f[7]=r[t+7],st[0]}var Se=BigInt(Number.MAX_SAFE_INTEGER),Ie=BigInt(Number.MIN_SAFE_INTEGER),l=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return v;if(t<Se&&t>Ie)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>$t&&(i=0n,++n>$t&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return v;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):v}},v=new l(0,0);v.toBigInt=function(){return 0n};v.zzEncode=v.zzDecode=function(){return this};v.length=function(){return 1};var $t=4294967296n;function _t(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Gt(r,t,e){if(e-t<1)return"";let i,o=[],s=0,h;for(;t<e;)h=r[t++],h<128?o[s++]=h:h>191&&h<224?o[s++]=(h&31)<<6|r[t++]&63:h>239&&h<365?(h=((h&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(h>>10),o[s++]=56320+(h&1023)):o[s++]=(h&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ht(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function w(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function K(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var at=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,w(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw w(this,4);return K(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw w(this,4);return K(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw w(this,4);let t=kt(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw w(this,4);let t=Ot(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw w(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Gt(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw w(this,t);this.pos+=t}else do if(this.pos>=this.len)throw w(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new l(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw w(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw w(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw w(this,8);let t=K(this.buf,this.pos+=4),e=K(this.buf,this.pos+=4);return new l(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Z(r){return new at(r instanceof Uint8Array?r:r.subarray())}function jt(r,t){let e=Z(r);return t.decode(e)}function Y(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function T(r=0){return globalThis.Buffer?.allocUnsafe!=null?Y(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var lt={};p(lt,{base10:()=>ve});function Be(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var h=r.length,u=r.charAt(0),z=Math.log(h)/Math.log(256),m=Math.log(256)/Math.log(h);function M(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var d=0,U=0,b=0,y=a.length;b!==y&&a[b]===0;)b++,d++;for(var A=(y-b)*m+1>>>0,x=new Uint8Array(A);b!==y;){for(var E=a[b],N=0,g=A-1;(E!==0||N<U)&&g!==-1;g--,N++)E+=256*x[g]>>>0,x[g]=E%h>>>0,E=E/h>>>0;if(E!==0)throw new Error("Non-zero carry");U=N,b++}for(var I=A-U;I!==A&&x[I]===0;)I++;for(var Q=u.repeat(d);I<A;++I)Q+=r.charAt(x[I]);return Q}function H(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var d=0;if(a[d]!==" "){for(var U=0,b=0;a[d]===u;)U++,d++;for(var y=(a.length-d)*z+1>>>0,A=new Uint8Array(y);a[d];){var x=e[a.charCodeAt(d)];if(x===255)return;for(var E=0,N=y-1;(x!==0||E<b)&&N!==-1;N--,E++)x+=h*A[N]>>>0,A[N]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");b=E,d++}if(a[d]!==" "){for(var g=y-b;g!==y&&A[g]===0;)g++;for(var I=new Uint8Array(U+(y-g)),Q=U;g!==y;)I[Q++]=A[g++];return I}}}function be(a){var d=H(a);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:M,decodeUnsafe:H,decode:be}}var Ne=Be,Ce=Ne,qt=Ce;var Zr=new Uint8Array(0);var Jt=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},B=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var Xt=r=>new TextEncoder().encode(r),Wt=r=>new TextDecoder().decode(r);var ct=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ft=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Qt(this,t)}},ut=class{constructor(t){this.decoders=t}or(t){return Qt(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Qt=(r,t)=>new ut({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),dt=class{constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new ct(t,e,n),this.decoder=new ft(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},V=({name:r,prefix:t,encode:e,decode:n})=>new dt(r,t,e,n),D=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:i}=qt(e,t);return V({prefix:r,name:t,encode:n,decode:o=>B(i(o))})},De=(r,t,e,n)=>{let i={};for(let m=0;m<t.length;++m)i[t[m]]=m;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),h=0,u=0,z=0;for(let m=0;m<o;++m){let M=i[r[m]];if(M===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<e|M,h+=e,h>=8&&(h-=8,s[z++]=255&u>>h)}if(h>=e||255&u<<8-h)throw new SyntaxError("Unexpected end of data");return s},Ue=(r,t,e)=>{let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,h=0;for(let u=0;u<r.length;++u)for(h=h<<8|r[u],s+=8;s>e;)s-=e,o+=t[i&h>>s];if(s&&(o+=t[i&h<<e-s]),n)for(;o.length*e&7;)o+="=";return o},c=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>V({prefix:t,name:r,encode(i){return Ue(i,n,e)},decode(i){return De(i,n,e,r)}});var ve=D({prefix:"9",name:"base10",alphabet:"0123456789"});var pt={};p(pt,{base16:()=>Te,base16upper:()=>Le});var Te=c({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Le=c({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mt={};p(mt,{base2:()=>Fe});var Fe=c({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xt={};p(xt,{base256emoji:()=>Re});var Kt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ze=Kt.reduce((r,t,e)=>(r[e]=t,r),[]),Me=Kt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Ve(r){return r.reduce((t,e)=>(t+=ze[e],t),"")}function ke(r){let t=[];for(let e of r){let n=Me[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Re=V({prefix:"\u{1F680}",name:"base256emoji",encode:Ve,decode:ke});var bt={};p(bt,{base32:()=>k,base32hex:()=>Ge,base32hexpad:()=>je,base32hexpadupper:()=>qe,base32hexupper:()=>Pe,base32pad:()=>$e,base32padupper:()=>_e,base32upper:()=>Oe,base32z:()=>Je});var k=c({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oe=c({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$e=c({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_e=c({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ge=c({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pe=c({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),je=c({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qe=c({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Je=c({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gt={};p(gt,{base36:()=>Xe,base36upper:()=>We});var Xe=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),We=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wt={};p(wt,{base58btc:()=>S,base58flickr:()=>He});var S=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),He=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yt={};p(yt,{base64:()=>Qe,base64pad:()=>Ke,base64url:()=>Ze,base64urlpad:()=>Ye});var Qe=c({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ke=c({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ze=c({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ye=c({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var At={};p(At,{base8:()=>tr});var tr=c({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Et={};p(Et,{identity:()=>er});var er=V({prefix:"\0",name:"identity",encode:r=>Wt(r),decode:r=>Xt(r)});var pn=new TextEncoder,mn=new TextDecoder;var It={};p(It,{identity:()=>Ir});var ir=te,Zt=128,or=127,sr=~or,hr=Math.pow(2,31);function te(r,t,e){t=t||[],e=e||0;for(var n=e;r>=hr;)t[e++]=r&255|Zt,r/=128;for(;r&sr;)t[e++]=r&255|Zt,r>>>=7;return t[e]=r|0,te.bytes=e-n+1,t}var ar=St,cr=128,Yt=127;function St(r,n){var e=0,n=n||0,i=0,o=n,s,h=r.length;do{if(o>=h)throw St.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Yt)<<i:(s&Yt)*Math.pow(2,i),i+=7}while(s>=cr);return St.bytes=o-n,e}var fr=Math.pow(2,7),ur=Math.pow(2,14),dr=Math.pow(2,21),lr=Math.pow(2,28),pr=Math.pow(2,35),mr=Math.pow(2,42),xr=Math.pow(2,49),br=Math.pow(2,56),gr=Math.pow(2,63),wr=function(r){return r<fr?1:r<ur?2:r<dr?3:r<lr?4:r<pr?5:r<mr?6:r<xr?7:r<br?8:r<gr?9:10},yr={encode:ir,decode:ar,encodingLength:wr},Ar=yr,G=Ar;var P=(r,t=0)=>[G.decode(r,t),G.decode.bytes],R=(r,t,e=0)=>(G.encode(r,t,e),t),O=r=>G.encodingLength(r);var L=(r,t)=>{let e=t.byteLength,n=O(r),i=n+O(e),o=new Uint8Array(i+e);return R(r,o,0),R(e,o,n),o.set(t,i),new $(r,e,t,o)},ee=r=>{let t=B(r),[e,n]=P(t),[i,o]=P(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new $(e,i,s,t)},re=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Jt(r.bytes,e.bytes)}},$=class{constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var ne=0,Er="identity",ie=B,Sr=r=>L(ne,ie(r)),Ir={code:ne,name:Er,encode:ie,digest:Sr};var Ct={};p(Ct,{sha256:()=>Br,sha512:()=>Nr});var Nt=({name:r,code:t,encode:e})=>new Bt(r,t,e),Bt=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?L(this.code,e):e.then(n=>L(this.code,n))}else throw Error("Unknown type, must be binary type")}};var se=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),Br=Nt({name:"sha2-256",code:18,encode:se("SHA-256")}),Nr=Nt({name:"sha2-512",code:19,encode:se("SHA-512")});var he=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return Dr(e,Dt(r),t||S.encoder);default:return Ur(e,Dt(r),t||k.encoder)}};var ae=new WeakMap,Dt=r=>{let t=ae.get(r);if(t==null){let e=new Map;return ae.set(r,e),e}return t},et=class r{constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==q)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==vr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=L(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&re(t.multihash,n.multihash)}toString(t){return he(this,t)}toJSON(){return{"/":he(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s||ce(n,i,o.bytes))}else if(e[Tr]===!0){let{version:n,multihash:i,code:o}=e,s=ee(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==q)throw new Error(`Version 0 CID must use dag-pb (code: ${q}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=ce(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,q,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=B(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new $(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[M,H]=P(t.subarray(e));return e+=H,M},i=n(),o=q;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,h=n(),u=n(),z=e+u,m=z-s;return{version:i,codec:o,multihashCode:h,digestSize:u,multihashSize:m,size:z}}static parse(t,e){let[n,i]=Cr(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dt(o).set(n,t),o}},Cr=(r,t)=>{switch(r[0]){case"Q":{let e=t||S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t||S;return[S.prefix,e.decode(r)]}case k.prefix:{let e=t||k;return[k.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},Dr=(r,t,e)=>{let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i},Ur=(r,t,e)=>{let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i},q=112,vr=18,ce=(r,t,e)=>{let n=O(r),i=n+O(t),o=new Uint8Array(i+e.byteLength);return R(r,o,0),R(t,o,n),o.set(e,i),o},Tr=Symbol.for("@ipld/js-cid/CID");var Ut={...Et,...mt,...At,...lt,...pt,...bt,...gt,...wt,...yt,...xt},Tn={...Ct,...It};function ue(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fe=ue("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),vt=ue("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=T(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Lr={utf8:fe,"utf-8":fe,hex:Ut.base16,latin1:vt,ascii:vt,binary:vt,...Ut},de=Lr;function le(r,t="utf8"){let e=de[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Y(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Tt(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return T(s);i+s>t&&(n=T(t),i=0);let h=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),h}}var F=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Lt(){}var zt=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fr=Tt();function zr(r){return globalThis.Buffer!=null?T(r):Fr(r)}var W=class{len;head;tail;states;constructor(){this.len=0,this.head=new F(Lt,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new F(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Mt((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(J,10,l.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=l.fromBigInt(t);return this._push(J,e.length(),e)}uint64Number(t){let e=l.fromNumber(t);return this._push(J,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=l.fromBigInt(t).zzEncode();return this._push(J,e.length(),e)}sint64Number(t){let e=l.fromNumber(t).zzEncode();return this._push(J,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ft,1,t?1:0)}fixed32(t){return this._push(X,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=l.fromBigInt(t);return this._push(X,4,e.lo)._push(X,4,e.hi)}fixed64Number(t){let e=l.fromNumber(t);return this._push(X,4,e.lo)._push(X,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Vt,4,t)}double(t){return this._push(Rt,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ft,1,0):this.uint32(e)._push(Vr,e,t)}string(t){let e=_t(t);return e!==0?this.uint32(e)._push(ht,e,t):this._push(Ft,1,0)}fork(){return this.states=new zt(this),this.head=this.tail=new F(Lt,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new F(Lt,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=zr(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ft(r,t,e){t[e]=r&255}function Mr(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Mt=class extends F{next;constructor(t,e){super(Mr,t,e),this.next=void 0}};function J(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function X(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Vr(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(W.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(kr,t,r),this},W.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Rr,t,r),this});function kr(r,t,e){t.set(r,e)}function Rr(r,t,e){r.length<40?ht(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(le(r),e)}function rt(){return new W}function pe(r,t){let e=rt();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var _;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(_||(_={}));function nt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function me(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let h=t(o);s.int32(h)},n=function(o){let s=o.int32();return t(s)};return nt("enum",_.VARINT,e,n)}function xe(r,t){return nt("message",_.LENGTH_DELIMITED,r,t)}return Ee(Or);})(); | ||
return ProtonsRuntime})); |
@@ -38,2 +38,10 @@ import type { Codec } from './codec.js'; | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64Number(value: number): this; | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64String(value: string): this; | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
@@ -43,2 +51,10 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64Number(value: number): this; | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64String(value: string): this; | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
@@ -48,2 +64,10 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64Number(value: number): this; | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64String(value: string): this; | ||
/** | ||
* Writes a boolish value as a varint | ||
@@ -65,2 +89,10 @@ */ | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64Number(value: number): this; | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64String(value: string): this; | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
@@ -70,2 +102,10 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64Number(value: number): this; | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64String(value: string): this; | ||
/** | ||
* Writes a float (32 bit) | ||
@@ -170,2 +210,10 @@ */ | ||
/** | ||
* Reads a varint as a signed 64 bit value | ||
*/ | ||
int64Number(): number; | ||
/** | ||
* Reads a varint as a signed 64 bit value | ||
*/ | ||
int64String(): string; | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
@@ -175,2 +223,10 @@ */ | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
*/ | ||
uint64Number(): number; | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
*/ | ||
uint64String(): string; | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
@@ -180,2 +236,10 @@ */ | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
*/ | ||
sint64Number(): number; | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
*/ | ||
sint64String(): string; | ||
/** | ||
* Reads fixed 64 bits | ||
@@ -185,6 +249,22 @@ */ | ||
/** | ||
* Reads fixed 64 bits | ||
*/ | ||
fixed64Number(): number; | ||
/** | ||
* Reads fixed 64 bits | ||
*/ | ||
fixed64String(): string; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64(): bigint; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64Number(): number; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64String(): string; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,4 +17,12 @@ /** | ||
*/ | ||
toNumber(unsigned?: boolean): number; | ||
/** | ||
* Converts this long bits to a bigint | ||
*/ | ||
toBigInt(unsigned?: boolean): bigint; | ||
/** | ||
* Converts this long bits to a string | ||
*/ | ||
toString(unsigned?: boolean): string; | ||
/** | ||
* Zig-zag encodes this long bits | ||
@@ -21,0 +29,0 @@ */ |
@@ -0,1 +1,4 @@ | ||
// the largest BigInt we can safely downcast to a Number | ||
const MAX_SAFE_NUMBER_INTEGER = BigInt(Number.MAX_SAFE_INTEGER); | ||
const MIN_SAFE_NUMBER_INTEGER = BigInt(Number.MIN_SAFE_INTEGER); | ||
/** | ||
@@ -28,6 +31,19 @@ * Constructs new long bits. | ||
*/ | ||
toNumber(unsigned = false) { | ||
if (!unsigned && (this.hi >>> 31) > 0) { | ||
const lo = ~this.lo + 1 >>> 0; | ||
let hi = ~this.hi >>> 0; | ||
if (lo === 0) { | ||
hi = hi + 1 >>> 0; | ||
} | ||
return -(lo + hi * 4294967296); | ||
} | ||
return this.lo + this.hi * 4294967296; | ||
} | ||
/** | ||
* Converts this long bits to a bigint | ||
*/ | ||
toBigInt(unsigned = false) { | ||
if (unsigned) { | ||
const result = BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n); | ||
return result; | ||
return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n); | ||
} | ||
@@ -45,2 +61,8 @@ if ((this.hi >>> 31) !== 0) { | ||
/** | ||
* Converts this long bits to a string | ||
*/ | ||
toString(unsigned = false) { | ||
return this.toBigInt(unsigned).toString(); | ||
} | ||
/** | ||
* Zig-zag encodes this long bits | ||
@@ -87,19 +109,22 @@ */ | ||
} | ||
const negative = value < 0; | ||
if (value < MAX_SAFE_NUMBER_INTEGER && value > MIN_SAFE_NUMBER_INTEGER) { | ||
return this.fromNumber(Number(value)); | ||
} | ||
const negative = value < 0n; | ||
if (negative) { | ||
value = -value; | ||
} | ||
let hi = Number(value >> 32n); | ||
let lo = Number(value - (BigInt(hi) << 32n)); | ||
let hi = value >> 32n; | ||
let lo = value - (hi << 32n); | ||
if (negative) { | ||
hi = ~hi >>> 0; | ||
lo = ~lo >>> 0; | ||
hi = ~hi | 0n; | ||
lo = ~lo | 0n; | ||
if (++lo > TWO_32) { | ||
lo = 0; | ||
lo = 0n; | ||
if (++hi > TWO_32) { | ||
hi = 0; | ||
hi = 0n; | ||
} | ||
} | ||
} | ||
return new LongBits(lo, hi); | ||
return new LongBits(Number(lo), Number(hi)); | ||
} | ||
@@ -106,0 +131,0 @@ /** |
@@ -67,2 +67,11 @@ import type { Reader } from '../index.js'; | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
int64Number(): number; | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a string | ||
*/ | ||
int64String(): string; | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
@@ -72,2 +81,11 @@ */ | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
uint64Number(): number; | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a string | ||
*/ | ||
uint64String(): string; | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
@@ -77,2 +95,12 @@ */ | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* possibly unsafe JavaScript number | ||
*/ | ||
sint64Number(): number; | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* string | ||
*/ | ||
sint64String(): string; | ||
/** | ||
* Reads fixed 64 bits | ||
@@ -82,7 +110,24 @@ */ | ||
/** | ||
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number | ||
*/ | ||
fixed64Number(): number; | ||
/** | ||
* Reads fixed 64 bits returned as a string | ||
*/ | ||
fixed64String(): string; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64(): bigint; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
sfixed64Number(): number; | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a string | ||
*/ | ||
sfixed64String(): string; | ||
} | ||
export declare function createReader(buf: Uint8Array | Uint8ArrayList): Reader; | ||
//# sourceMappingURL=reader.d.ts.map |
@@ -270,2 +270,15 @@ import { readFloatLE, readDoubleLE } from './float.js'; | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
int64Number() { | ||
return this.readLongVarint().toNumber(); | ||
} | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a string | ||
*/ | ||
int64String() { | ||
return this.readLongVarint().toString(); | ||
} | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
@@ -277,2 +290,15 @@ */ | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
uint64Number() { | ||
return this.readLongVarint().toNumber(true); | ||
} | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a string | ||
*/ | ||
uint64String() { | ||
return this.readLongVarint().toString(true); | ||
} | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
@@ -284,2 +310,16 @@ */ | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* possibly unsafe JavaScript number | ||
*/ | ||
sint64Number() { | ||
return this.readLongVarint().zzDecode().toNumber(); | ||
} | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* string | ||
*/ | ||
sint64String() { | ||
return this.readLongVarint().zzDecode().toString(); | ||
} | ||
/** | ||
* Reads fixed 64 bits | ||
@@ -291,2 +331,14 @@ */ | ||
/** | ||
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number | ||
*/ | ||
fixed64Number() { | ||
return this.readFixed64().toNumber(); | ||
} | ||
/** | ||
* Reads fixed 64 bits returned as a string | ||
*/ | ||
fixed64String() { | ||
return this.readFixed64().toString(); | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
@@ -297,2 +349,15 @@ */ | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
sfixed64Number() { | ||
return this.readFixed64().toNumber(); | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a string | ||
*/ | ||
sfixed64String() { | ||
return this.readFixed64().toString(); | ||
} | ||
} | ||
@@ -299,0 +364,0 @@ export function createReader(buf) { |
@@ -153,2 +153,15 @@ import { allocUnsafe } from 'uint8arrays/alloc'; | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64Number(value) { | ||
const bits = LongBits.fromNumber(value); | ||
return this._push(writeVarint64, bits.length(), bits); | ||
} | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64String(value) { | ||
return this.uint64(BigInt(value)); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
@@ -160,2 +173,14 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64Number(value) { | ||
return this.uint64Number(value); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64String(value) { | ||
return this.uint64String(value); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
@@ -168,2 +193,15 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64Number(value) { | ||
const bits = LongBits.fromNumber(value).zzEncode(); | ||
return this._push(writeVarint64, bits.length(), bits); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64String(value) { | ||
return this.sint64(BigInt(value)); | ||
} | ||
/** | ||
* Writes a boolish value as a varint | ||
@@ -194,2 +232,15 @@ */ | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64Number(value) { | ||
const bits = LongBits.fromNumber(value); | ||
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi); | ||
} | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64String(value) { | ||
return this.fixed64(BigInt(value)); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
@@ -201,2 +252,14 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64Number(value) { | ||
return this.fixed64Number(value); | ||
} | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64String(value) { | ||
return this.fixed64String(value); | ||
} | ||
/** | ||
* Writes a float (32 bit) | ||
@@ -203,0 +266,0 @@ */ |
{ | ||
"name": "protons-runtime", | ||
"version": "5.0.5", | ||
"version": "5.1.0", | ||
"description": "Shared code to make your bundle smaller when running protons in your app", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
100
src/index.ts
@@ -52,2 +52,12 @@ import type { Codec } from './codec.js' | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64Number(value: number): this | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64String(value: string): this | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
@@ -58,2 +68,12 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64Number(value: number): this | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64String(value: string): this | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
@@ -64,2 +84,12 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64Number(value: number): this | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64String(value: string): this | ||
/** | ||
* Writes a boolish value as a varint | ||
@@ -85,2 +115,12 @@ */ | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64Number(value: number): this | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64String(value: string): this | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
@@ -91,2 +131,12 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64Number(value: number): this | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64String(value: string): this | ||
/** | ||
* Writes a float (32 bit) | ||
@@ -215,2 +265,12 @@ */ | ||
/** | ||
* Reads a varint as a signed 64 bit value | ||
*/ | ||
int64Number(): number | ||
/** | ||
* Reads a varint as a signed 64 bit value | ||
*/ | ||
int64String(): string | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
@@ -221,2 +281,12 @@ */ | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
*/ | ||
uint64Number(): number | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
*/ | ||
uint64String(): string | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
@@ -227,2 +297,12 @@ */ | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
*/ | ||
sint64Number(): number | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
*/ | ||
sint64String(): string | ||
/** | ||
* Reads fixed 64 bits | ||
@@ -233,5 +313,25 @@ */ | ||
/** | ||
* Reads fixed 64 bits | ||
*/ | ||
fixed64Number(): number | ||
/** | ||
* Reads fixed 64 bits | ||
*/ | ||
fixed64String(): string | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64(): bigint | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64Number(): number | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
*/ | ||
sfixed64String(): string | ||
} |
@@ -0,1 +1,5 @@ | ||
// the largest BigInt we can safely downcast to a Number | ||
const MAX_SAFE_NUMBER_INTEGER = BigInt(Number.MAX_SAFE_INTEGER) | ||
const MIN_SAFE_NUMBER_INTEGER = BigInt(Number.MIN_SAFE_INTEGER) | ||
/** | ||
@@ -32,6 +36,20 @@ * Constructs new long bits. | ||
*/ | ||
toNumber (unsigned: boolean = false): number { | ||
if (!unsigned && (this.hi >>> 31) > 0) { | ||
const lo = ~this.lo + 1 >>> 0 | ||
let hi = ~this.hi >>> 0 | ||
if (lo === 0) { | ||
hi = hi + 1 >>> 0 | ||
} | ||
return -(lo + hi * 4294967296) | ||
} | ||
return this.lo + this.hi * 4294967296 | ||
} | ||
/** | ||
* Converts this long bits to a bigint | ||
*/ | ||
toBigInt (unsigned: boolean = false): bigint { | ||
if (unsigned) { | ||
const result = BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n) | ||
return result | ||
return BigInt(this.lo >>> 0) + (BigInt(this.hi >>> 0) << 32n) | ||
} | ||
@@ -52,2 +70,9 @@ | ||
/** | ||
* Converts this long bits to a string | ||
*/ | ||
toString (unsigned: boolean = false): string { | ||
return this.toBigInt(unsigned).toString() | ||
} | ||
/** | ||
* Zig-zag encodes this long bits | ||
@@ -94,21 +119,30 @@ */ | ||
static fromBigInt (value: bigint): LongBits { | ||
if (value === 0n) { return zero } | ||
if (value === 0n) { | ||
return zero | ||
} | ||
const negative = value < 0 | ||
if (value < MAX_SAFE_NUMBER_INTEGER && value > MIN_SAFE_NUMBER_INTEGER) { | ||
return this.fromNumber(Number(value)) | ||
} | ||
const negative = value < 0n | ||
if (negative) { | ||
value = -value | ||
} | ||
let hi = Number(value >> 32n) | ||
let lo = Number(value - (BigInt(hi) << 32n)) | ||
let hi = value >> 32n | ||
let lo = value - (hi << 32n) | ||
if (negative) { | ||
hi = ~hi >>> 0 | ||
lo = ~lo >>> 0 | ||
hi = ~hi | 0n | ||
lo = ~lo | 0n | ||
if (++lo > TWO_32) { | ||
lo = 0 | ||
if (++hi > TWO_32) { hi = 0 } | ||
lo = 0n | ||
if (++hi > TWO_32) { hi = 0n } | ||
} | ||
} | ||
return new LongBits(lo, hi) | ||
return new LongBits(Number(lo), Number(hi)) | ||
} | ||
@@ -115,0 +149,0 @@ |
@@ -281,2 +281,17 @@ import { readFloatLE, readDoubleLE } from './float.js' | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
int64Number (): number { | ||
return this.readLongVarint().toNumber() | ||
} | ||
/** | ||
* Reads a varint as a signed 64 bit value returned as a string | ||
*/ | ||
int64String (): string { | ||
return this.readLongVarint().toString() | ||
} | ||
/** | ||
* Reads a varint as an unsigned 64 bit value | ||
@@ -289,2 +304,17 @@ */ | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
uint64Number (): number { | ||
return this.readLongVarint().toNumber(true) | ||
} | ||
/** | ||
* Reads a varint as an unsigned 64 bit value returned as a string | ||
*/ | ||
uint64String (): string { | ||
return this.readLongVarint().toString(true) | ||
} | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value | ||
@@ -297,2 +327,18 @@ */ | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* possibly unsafe JavaScript number | ||
*/ | ||
sint64Number (): number { | ||
return this.readLongVarint().zzDecode().toNumber() | ||
} | ||
/** | ||
* Reads a zig-zag encoded varint as a signed 64 bit value returned as a | ||
* string | ||
*/ | ||
sint64String (): string { | ||
return this.readLongVarint().zzDecode().toString() | ||
} | ||
/** | ||
* Reads fixed 64 bits | ||
@@ -305,2 +351,16 @@ */ | ||
/** | ||
* Reads fixed 64 bits returned as a possibly unsafe JavaScript number | ||
*/ | ||
fixed64Number (): number { | ||
return this.readFixed64().toNumber() | ||
} | ||
/** | ||
* Reads fixed 64 bits returned as a string | ||
*/ | ||
fixed64String (): string { | ||
return this.readFixed64().toString() | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits | ||
@@ -311,2 +371,17 @@ */ | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a possibly unsafe | ||
* JavaScript number | ||
*/ | ||
sfixed64Number (): number { | ||
return this.readFixed64().toNumber() | ||
} | ||
/** | ||
* Reads zig-zag encoded fixed 64 bits returned as a string | ||
*/ | ||
sfixed64String (): string { | ||
return this.readFixed64().toString() | ||
} | ||
} | ||
@@ -313,0 +388,0 @@ |
@@ -186,2 +186,17 @@ import { allocUnsafe } from 'uint8arrays/alloc' | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64Number (value: number): this { | ||
const bits = LongBits.fromNumber(value) | ||
return this._push(writeVarint64, bits.length(), bits) | ||
} | ||
/** | ||
* Writes an unsigned 64 bit value as a varint | ||
*/ | ||
uint64String (value: string): this { | ||
return this.uint64(BigInt(value)) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
@@ -194,2 +209,16 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64Number (value: number): this { | ||
return this.uint64Number(value) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint | ||
*/ | ||
int64String (value: string): this { | ||
return this.uint64String(value) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
@@ -203,2 +232,17 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64Number (value: number): this { | ||
const bits = LongBits.fromNumber(value).zzEncode() | ||
return this._push(writeVarint64, bits.length(), bits) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as a varint, zig-zag encoded | ||
*/ | ||
sint64String (value: string): this { | ||
return this.sint64(BigInt(value)) | ||
} | ||
/** | ||
* Writes a boolish value as a varint | ||
@@ -229,3 +273,10 @@ */ | ||
const bits = LongBits.fromBigInt(value) | ||
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi) | ||
} | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64Number (value: number): this { | ||
const bits = LongBits.fromNumber(value) | ||
return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi) | ||
@@ -235,2 +286,9 @@ } | ||
/** | ||
* Writes an unsigned 64 bit value as fixed 64 bits | ||
*/ | ||
fixed64String (value: string): this { | ||
return this.fixed64(BigInt(value)) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
@@ -243,2 +301,16 @@ */ | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64Number (value: number): this { | ||
return this.fixed64Number(value) | ||
} | ||
/** | ||
* Writes a signed 64 bit value as fixed 64 bits | ||
*/ | ||
sfixed64String (value: string): this { | ||
return this.fixed64String(value) | ||
} | ||
/** | ||
* Writes a float (32 bit) | ||
@@ -245,0 +317,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170463
3388