@muisit/simplejwt
Advanced tools
| import { CryptoKey } from '@muisit/cryptokey'; | ||
| interface StringKeyedObject { | ||
| [x: string]: any; | ||
| } | ||
| declare class JWT { | ||
| token: string; | ||
| headerPart: string; | ||
| payloadPart: string | Uint8Array; | ||
| signaturePart: string; | ||
| header: StringKeyedObject | null; | ||
| payload: StringKeyedObject | null; | ||
| constructor(); | ||
| static fromToken(token: string): JWT; | ||
| decode(): void; | ||
| verify(key: CryptoKey): Promise<boolean>; | ||
| findKey(): Promise<CryptoKey | null>; | ||
| sign(key: CryptoKey | Function, alg?: string): Promise<void>; | ||
| decodeFromBase64(payload: string): StringKeyedObject | null; | ||
| encodeToBase64(payload: StringKeyedObject): string; | ||
| } | ||
| export { JWT }; |
| import { CryptoKey } from '@muisit/cryptokey'; | ||
| interface StringKeyedObject { | ||
| [x: string]: any; | ||
| } | ||
| declare class JWT { | ||
| token: string; | ||
| headerPart: string; | ||
| payloadPart: string | Uint8Array; | ||
| signaturePart: string; | ||
| header: StringKeyedObject | null; | ||
| payload: StringKeyedObject | null; | ||
| constructor(); | ||
| static fromToken(token: string): JWT; | ||
| decode(): void; | ||
| verify(key: CryptoKey): Promise<boolean>; | ||
| findKey(): Promise<CryptoKey | null>; | ||
| sign(key: CryptoKey | Function, alg?: string): Promise<void>; | ||
| decodeFromBase64(payload: string): StringKeyedObject | null; | ||
| encodeToBase64(payload: StringKeyedObject): string; | ||
| } | ||
| export { JWT }; |
| "use strict";var Ke=Object.create;var $=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Je=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var t in e)$(r,t,{get:e[t],enumerable:!0})},Ee=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of qe(e))!Re.call(r,n)&&n!==t&&$(r,n,{get:()=>e[n],enumerable:!(o=$e(e,n))||o.enumerable});return r};var Xe=(r,e,t)=>(t=r!=null?Ke(Je(r)):{},Ee(e||!r||!r.__esModule?$(t,"default",{value:r,enumerable:!0}):t,r)),We=r=>Ee($({},"__esModule",{value:!0}),r);var nr={};h(nr,{JWT:()=>H});module.exports=We(nr);function U(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function q(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?U(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var re={};h(re,{identity:()=>_e});function Ze(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var n=0;n<r.length;n++){var u=r.charAt(n),s=u.charCodeAt(0);if(t[s]!==255)throw new TypeError(u+" is ambiguous");t[s]=n}var D=r.length,c=r.charAt(0),B=Math.log(D)/Math.log(256),d=Math.log(256)/Math.log(D);function S(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var f=0,v=0,m=0,C=i.length;m!==C&&i[m]===0;)m++,f++;for(var g=(C-m)*d+1>>>0,p=new Uint8Array(g);m!==C;){for(var E=i[m],x=0,b=g-1;(E!==0||x<v)&&b!==-1;b--,x++)E+=256*p[b]>>>0,p[b]=E%D>>>0,E=E/D>>>0;if(E!==0)throw new Error("Non-zero carry");v=x,m++}for(var w=g-v;w!==g&&p[w]===0;)w++;for(var K=c.repeat(f);w<g;++w)K+=r.charAt(p[w]);return K}function V(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var f=0;if(i[f]!==" "){for(var v=0,m=0;i[f]===c;)v++,f++;for(var C=(i.length-f)*B+1>>>0,g=new Uint8Array(C);i[f];){var p=t[i.charCodeAt(f)];if(p===255)return;for(var E=0,x=C-1;(p!==0||E<m)&&x!==-1;x--,E++)p+=D*g[x]>>>0,g[x]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");m=E,f++}if(i[f]!==" "){for(var b=C-m;b!==C&&g[b]===0;)b++;for(var w=new Uint8Array(v+(C-b)),K=v;b!==C;)w[K++]=g[b++];return w}}}function Ve(i){var f=V(i);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:S,decodeUnsafe:V,decode:Ve}}var Ge=Ze,Qe=Ge,ye=Qe;var lr=new Uint8Array(0);var we=(r,e)=>{if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0},l=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 xe=r=>new TextEncoder().encode(r),Ae=r=>new TextDecoder().decode(r);var Y=class{constructor(e,t,o){this.name=e,this.prefix=t,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},_=class{constructor(e,t,o){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Fe(this,e)}},ee=class{constructor(e){this.decoders=e}or(e){return Fe(this,e)}decode(e){let t=e[0],o=this.decoders[t];if(o)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Fe=(r,e)=>new ee({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),te=class{constructor(e,t,o,n){this.name=e,this.prefix=t,this.baseEncode=o,this.baseDecode=n,this.encoder=new Y(e,t,o),this.decoder=new _(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},P=({name:r,prefix:e,encode:t,decode:o})=>new te(r,e,t,o),A=({prefix:r,name:e,alphabet:t})=>{let{encode:o,decode:n}=ye(t,e);return P({prefix:r,name:e,encode:o,decode:u=>l(n(u))})},He=(r,e,t,o)=>{let n={};for(let d=0;d<e.length;++d)n[e[d]]=d;let u=r.length;for(;r[u-1]==="=";)--u;let s=new Uint8Array(u*t/8|0),D=0,c=0,B=0;for(let d=0;d<u;++d){let S=n[r[d]];if(S===void 0)throw new SyntaxError(`Non-${o} character`);c=c<<t|S,D+=t,D>=8&&(D-=8,s[B++]=255&c>>D)}if(D>=t||255&c<<8-D)throw new SyntaxError("Unexpected end of data");return s},Ye=(r,e,t)=>{let o=e[e.length-1]==="=",n=(1<<t)-1,u="",s=0,D=0;for(let c=0;c<r.length;++c)for(D=D<<8|r[c],s+=8;s>t;)s-=t,u+=e[n&D>>s];if(s&&(u+=e[n&D<<t-s]),o)for(;u.length*t&7;)u+="=";return u},a=({name:r,prefix:e,bitsPerChar:t,alphabet:o})=>P({prefix:e,name:r,encode(n){return Ye(n,o,t)},decode(n){return He(n,o,t,r)}});var _e=P({prefix:"\0",name:"identity",encode:r=>Ae(r),decode:r=>xe(r)});var oe={};h(oe,{base2:()=>et});var et=a({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ne={};h(ne,{base8:()=>tt});var tt=a({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ue={};h(ue,{base10:()=>rt});var rt=A({prefix:"9",name:"base10",alphabet:"0123456789"});var se={};h(se,{base16:()=>ot,base16upper:()=>nt});var ot=a({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),nt=a({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ie={};h(ie,{base32:()=>I,base32hex:()=>Dt,base32hexpad:()=>ct,base32hexpadupper:()=>ft,base32hexupper:()=>at,base32pad:()=>st,base32padupper:()=>it,base32upper:()=>ut,base32z:()=>ht});var I=a({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ut=a({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),st=a({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),it=a({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dt=a({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),at=a({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ct=a({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ft=a({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ht=a({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var De={};h(De,{base36:()=>dt,base36upper:()=>pt});var dt=A({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pt=A({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ae={};h(ae,{base58btc:()=>y,base58flickr:()=>lt});var y=A({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lt=A({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ce={};h(ce,{base64:()=>mt,base64pad:()=>bt,base64url:()=>Ct,base64urlpad:()=>gt});var mt=a({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bt=a({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ct=a({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),gt=a({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fe={};h(fe,{base256emoji:()=>At});var Be=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}"),Et=Be.reduce((r,e,t)=>(r[t]=e,r),[]),yt=Be.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function wt(r){return r.reduce((e,t)=>(e+=Et[t],e),"")}function xt(r){let e=[];for(let t of r){let o=yt[t.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var At=P({prefix:"\u{1F680}",name:"base256emoji",encode:wt,decode:xt});var me={};h(me,{sha256:()=>qt,sha512:()=>Jt});var le=Xe(require("crypto"),1);var vt=Pe,Se=128,Ft=127,Bt=~Ft,St=Math.pow(2,31);function Pe(r,e,t){e=e||[],t=t||0;for(var o=t;r>=St;)e[t++]=r&255|Se,r/=128;for(;r&Bt;)e[t++]=r&255|Se,r>>>=7;return e[t]=r|0,Pe.bytes=t-o+1,e}var Ut=he,Pt=128,Ue=127;function he(r,o){var t=0,o=o||0,n=0,u=o,s,D=r.length;do{if(u>=D)throw he.bytes=0,new RangeError("Could not decode varint");s=r[u++],t+=n<28?(s&Ue)<<n:(s&Ue)*Math.pow(2,n),n+=7}while(s>=Pt);return he.bytes=u-o,t}var It=Math.pow(2,7),Tt=Math.pow(2,14),Ot=Math.pow(2,21),zt=Math.pow(2,28),Lt=Math.pow(2,35),Nt=Math.pow(2,42),jt=Math.pow(2,49),Mt=Math.pow(2,56),kt=Math.pow(2,63),Vt=function(r){return r<It?1:r<Tt?2:r<Ot?3:r<zt?4:r<Lt?5:r<Nt?6:r<jt?7:r<Mt?8:r<kt?9:10},Kt={encode:vt,decode:Ut,encodingLength:Vt},$t=Kt,L=$t;var N=(r,e=0)=>[L.decode(r,e),L.decode.bytes],T=(r,e,t=0)=>(L.encode(r,e,t),e),O=r=>L.encodingLength(r);var F=(r,e)=>{let t=e.byteLength,o=O(r),n=o+O(t),u=new Uint8Array(n+t);return T(r,u,0),T(t,u,o),u.set(e,n),new z(r,t,e,u)},Ie=r=>{let e=l(r),[t,o]=N(e),[n,u]=N(e.subarray(o)),s=e.subarray(o+u);if(s.byteLength!==n)throw new Error("Incorrect length");return new z(t,n,s,e)},Te=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&we(r.bytes,e.bytes),z=class{constructor(e,t,o,n){this.code=e,this.size=t,this.digest=o,this.bytes=n}};var pe=({name:r,code:e,encode:t})=>new de(r,e,t),de=class{constructor(e,t,o){this.name=e,this.code=t,this.encode=o}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?F(this.code,t):t.then(o=>F(this.code,o))}else throw Error("Unknown type, must be binary type")}};var qt=pe({name:"sha2-256",code:18,encode:r=>l(le.default.createHash("sha256").update(r).digest())}),Jt=pe({name:"sha2-512",code:19,encode:r=>l(le.default.createHash("sha512").update(r).digest())});var be={};h(be,{identity:()=>Wt});var ze=0,Rt="identity",Le=l,Xt=r=>F(ze,Le(r)),Wt={code:ze,name:Rt,encode:Le,digest:Xt};var jr=new TextEncoder,Mr=new TextDecoder;var W=class r{constructor(e,t,o,n){this.code=t,this.version=e,this.multihash=o,this.bytes=n,this.byteOffset=n.byteOffset,this.byteLength=n.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:X,byteLength:X,code:R,version:R,multihash:R,bytes:R,_baseCache:X,asCID:X})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==M)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==_t)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,o=F(e,t);return r.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Te(this.multihash,e.multihash)}toString(e){let{bytes:t,version:o,_baseCache:n}=this;switch(o){case 0:return Ht(t,n,e||y.encoder);default:return Yt(t,n,e||I.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return tr(/^0\.0/,rr),!!(e&&(e[je]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:o,multihash:n,bytes:u}=e;return new r(t,o,n,u||Ne(t,o,n.bytes))}else if(e!=null&&e[je]===!0){let{version:t,multihash:o,code:n}=e,u=Ie(o);return r.create(t,n,u)}else return null}static create(e,t,o){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==M)throw new Error(`Version 0 CID must use dag-pb (code: ${M}) block encoding`);return new r(e,t,o,o.bytes)}case 1:{let n=Ne(e,t,o.bytes);return new r(e,t,o,n)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,M,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,o]=r.decodeFirst(e);if(o.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),o=t.size-t.multihashSize,n=l(e.subarray(o,o+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let u=n.subarray(t.multihashSize-t.digestSize),s=new z(t.multihashCode,t.digestSize,u,n);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,o=()=>{let[S,V]=N(e.subarray(t));return t+=V,S},n=o(),u=M;if(n===18?(n=0,t=0):n===1&&(u=o()),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=t,D=o(),c=o(),B=t+c,d=B-s;return{version:n,codec:u,multihashCode:D,digestSize:c,multihashSize:d,size:B}}static parse(e,t){let[o,n]=Qt(e,t),u=r.decode(n);return u._baseCache.set(o,e),u}},Qt=(r,e)=>{switch(r[0]){case"Q":{let t=e||y;return[y.prefix,t.decode(`${y.prefix}${r}`)]}case y.prefix:{let t=e||y;return[y.prefix,t.decode(r)]}case I.prefix:{let t=e||I;return[I.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}},Ht=(r,e,t)=>{let{prefix:o}=t;if(o!==y.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(o);if(n==null){let u=t.encode(r).slice(1);return e.set(o,u),u}else return n},Yt=(r,e,t)=>{let{prefix:o}=t,n=e.get(o);if(n==null){let u=t.encode(r);return e.set(o,u),u}else return n},M=112,_t=18,Ne=(r,e,t)=>{let o=O(r),n=o+O(e),u=new Uint8Array(n+t.byteLength);return T(r,u,0),T(e,u,o),u.set(t,n),u},je=Symbol.for("@ipld/js-cid/CID"),R={writable:!1,configurable:!1,enumerable:!0},X={writable:!1,enumerable:!1,configurable:!1},er="0.0.0-dev",tr=(r,e)=>{if(r.test(er))console.warn(e);else throw new Error(e)},rr=`CID.isCID(v) is deprecated and will be removed in the next major release. | ||
| Following code pattern: | ||
| if (CID.isCID(value)) { | ||
| doSomethingWithCID(value) | ||
| } | ||
| Is replaced with: | ||
| const cid = CID.asCID(value) | ||
| if (cid) { | ||
| // Make sure to use cid instead of value | ||
| doSomethingWithCID(cid) | ||
| } | ||
| `;var Ce={...re,...oe,...ne,...ue,...se,...ie,...De,...ae,...ce,...fe},Xr={...me,...be};function ke(r,e,t,o){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:o}}}var Me=ke("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ge=ke("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=q(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),or={utf8:Me,"utf-8":Me,hex:Ce.base16,latin1:ge,ascii:ge,binary:ge,...Ce},Z=or;function G(r,e="utf8"){let t=Z[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?U(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Q(r,e="utf8"){let t=Z[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var k=require("@muisit/cryptokey"),H=class r{token="";headerPart="";payloadPart="";signaturePart="";header={};payload={};constructor(){}static fromToken(e){let t=new r;t.token=e;let o=e.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(o&&o.length==4&&(t.headerPart=o[1],t.payloadPart=o[2],t.signaturePart=o[3],t.decode()),!t.header||!t.payload||!t.signaturePart||Object.keys(t.header).length==0||Object.keys(t.payload).length==0)throw new Error("Invalid JWT");return t}decode(){this.headerPart.length>0&&(this.header===null||Object.keys(this.header).length==0)&&(this.header=this.decodeFromBase64(this.headerPart)),this.payloadPart.length>0&&(this.payload===null||Object.keys(this.payload).length==0)&&(this.payload=this.decodeFromBase64(this.payloadPart))}async verify(e){let t=Buffer.from(this.headerPart+"."+this.payloadPart),o=this.header.alg||e.algorithms()[0];return await e.verify(o,G(this.signaturePart,"base64url"),t)}async findKey(){let e=null;if(this.header?.kid){let t=this.header.kid.split("#")[0].trim("=");e=await k.Factory.resolve(t)}return!e&&this.header?.jwk&&(e=await k.Factory.createFromJWK(this.header.jwk)),!e&&this.header?.iss&&(e=await k.Factory.resolve(this.header.iss)),!e&&this.payload?.iss&&(e=await k.Factory.resolve(this.payload.iss)),e}async sign(e,t){let o=t||this.header?.alg||"ES256";typeof e!="function"&&(this.header.alg=o),this.header?this.headerPart=this.encodeToBase64(this.header):this.headerPart||(this.headerPart=""),this.payload?this.payloadPart=this.encodeToBase64(this.payload):this.payloadPart||(this.payloadPart="");let n=Buffer.from(this.headerPart+"."+this.payloadPart);typeof e!="function"?this.signaturePart=await e.sign(o,n,"base64url"):this.signaturePart=await e(n),this.token=this.headerPart+"."+this.payloadPart+"."+this.signaturePart}decodeFromBase64(e){let t=G(e,"base64url"),o=Q(t);try{return JSON.parse(o)}catch{}return null}encodeToBase64(e){let t=Buffer.from(JSON.stringify(e));return Q(t,"base64url")}};0&&(module.exports={JWT}); |
| var ke=Object.defineProperty;var p=(r,e)=>{for(var t in e)ke(r,t,{get:e[t],enumerable:!0})};function U(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function K(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?U(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var ee={};p(ee,{identity:()=>Re});function Ve(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var n=0;n<r.length;n++){var u=r.charAt(n),s=u.charCodeAt(0);if(t[s]!==255)throw new TypeError(u+" is ambiguous");t[s]=n}var D=r.length,c=r.charAt(0),B=Math.log(D)/Math.log(256),h=Math.log(256)/Math.log(D);function S(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var f=0,v=0,m=0,C=i.length;m!==C&&i[m]===0;)m++,f++;for(var g=(C-m)*h+1>>>0,d=new Uint8Array(g);m!==C;){for(var E=i[m],x=0,b=g-1;(E!==0||x<v)&&b!==-1;b--,x++)E+=256*d[b]>>>0,d[b]=E%D>>>0,E=E/D>>>0;if(E!==0)throw new Error("Non-zero carry");v=x,m++}for(var w=g-v;w!==g&&d[w]===0;)w++;for(var V=c.repeat(f);w<g;++w)V+=r.charAt(d[w]);return V}function k(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var f=0;if(i[f]!==" "){for(var v=0,m=0;i[f]===c;)v++,f++;for(var C=(i.length-f)*B+1>>>0,g=new Uint8Array(C);i[f];){var d=t[i.charCodeAt(f)];if(d===255)return;for(var E=0,x=C-1;(d!==0||E<m)&&x!==-1;x--,E++)d+=D*g[x]>>>0,g[x]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");m=E,f++}if(i[f]!==" "){for(var b=C-m;b!==C&&g[b]===0;)b++;for(var w=new Uint8Array(v+(C-b)),V=v;b!==C;)w[V++]=g[b++];return w}}}function Me(i){var f=k(i);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:S,decodeUnsafe:k,decode:Me}}var Ke=Ve,$e=Ke,Ce=$e;var sr=new Uint8Array(0);var ge=(r,e)=>{if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0},l=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 Ee=r=>new TextEncoder().encode(r),ye=r=>new TextDecoder().decode(r);var Q=class{constructor(e,t,o){this.name=e,this.prefix=t,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},H=class{constructor(e,t,o){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return xe(this,e)}},Y=class{constructor(e){this.decoders=e}or(e){return xe(this,e)}decode(e){let t=e[0],o=this.decoders[t];if(o)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},xe=(r,e)=>new Y({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),_=class{constructor(e,t,o,n){this.name=e,this.prefix=t,this.baseEncode=o,this.baseDecode=n,this.encoder=new Q(e,t,o),this.decoder=new H(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},P=({name:r,prefix:e,encode:t,decode:o})=>new _(r,e,t,o),A=({prefix:r,name:e,alphabet:t})=>{let{encode:o,decode:n}=Ce(t,e);return P({prefix:r,name:e,encode:o,decode:u=>l(n(u))})},qe=(r,e,t,o)=>{let n={};for(let h=0;h<e.length;++h)n[e[h]]=h;let u=r.length;for(;r[u-1]==="=";)--u;let s=new Uint8Array(u*t/8|0),D=0,c=0,B=0;for(let h=0;h<u;++h){let S=n[r[h]];if(S===void 0)throw new SyntaxError(`Non-${o} character`);c=c<<t|S,D+=t,D>=8&&(D-=8,s[B++]=255&c>>D)}if(D>=t||255&c<<8-D)throw new SyntaxError("Unexpected end of data");return s},Je=(r,e,t)=>{let o=e[e.length-1]==="=",n=(1<<t)-1,u="",s=0,D=0;for(let c=0;c<r.length;++c)for(D=D<<8|r[c],s+=8;s>t;)s-=t,u+=e[n&D>>s];if(s&&(u+=e[n&D<<t-s]),o)for(;u.length*t&7;)u+="=";return u},a=({name:r,prefix:e,bitsPerChar:t,alphabet:o})=>P({prefix:e,name:r,encode(n){return Je(n,o,t)},decode(n){return qe(n,o,t,r)}});var Re=P({prefix:"\0",name:"identity",encode:r=>ye(r),decode:r=>Ee(r)});var te={};p(te,{base2:()=>Xe});var Xe=a({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var re={};p(re,{base8:()=>We});var We=a({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oe={};p(oe,{base10:()=>Ze});var Ze=A({prefix:"9",name:"base10",alphabet:"0123456789"});var ne={};p(ne,{base16:()=>Ge,base16upper:()=>Qe});var Ge=a({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Qe=a({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ue={};p(ue,{base32:()=>I,base32hex:()=>et,base32hexpad:()=>rt,base32hexpadupper:()=>ot,base32hexupper:()=>tt,base32pad:()=>Ye,base32padupper:()=>_e,base32upper:()=>He,base32z:()=>nt});var I=a({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),He=a({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ye=a({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_e=a({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),et=a({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),tt=a({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),rt=a({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ot=a({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),nt=a({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var se={};p(se,{base36:()=>ut,base36upper:()=>st});var ut=A({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),st=A({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ie={};p(ie,{base58btc:()=>y,base58flickr:()=>it});var y=A({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),it=A({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var De={};p(De,{base64:()=>Dt,base64pad:()=>at,base64url:()=>ct,base64urlpad:()=>ft});var Dt=a({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),at=a({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ct=a({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ft=a({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ae={};p(ae,{base256emoji:()=>mt});var Ae=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}"),ht=Ae.reduce((r,e,t)=>(r[t]=e,r),[]),dt=Ae.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function pt(r){return r.reduce((e,t)=>(e+=ht[t],e),"")}function lt(r){let e=[];for(let t of r){let o=dt[t.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var mt=P({prefix:"\u{1F680}",name:"base256emoji",encode:pt,decode:lt});var de={};p(de,{sha256:()=>Lt,sha512:()=>Nt});import Ie from"crypto";var bt=Be,ve=128,Ct=127,gt=~Ct,Et=Math.pow(2,31);function Be(r,e,t){e=e||[],t=t||0;for(var o=t;r>=Et;)e[t++]=r&255|ve,r/=128;for(;r>)e[t++]=r&255|ve,r>>>=7;return e[t]=r|0,Be.bytes=t-o+1,e}var yt=ce,wt=128,Fe=127;function ce(r,o){var t=0,o=o||0,n=0,u=o,s,D=r.length;do{if(u>=D)throw ce.bytes=0,new RangeError("Could not decode varint");s=r[u++],t+=n<28?(s&Fe)<<n:(s&Fe)*Math.pow(2,n),n+=7}while(s>=wt);return ce.bytes=u-o,t}var xt=Math.pow(2,7),At=Math.pow(2,14),vt=Math.pow(2,21),Ft=Math.pow(2,28),Bt=Math.pow(2,35),St=Math.pow(2,42),Ut=Math.pow(2,49),Pt=Math.pow(2,56),It=Math.pow(2,63),Tt=function(r){return r<xt?1:r<At?2:r<vt?3:r<Ft?4:r<Bt?5:r<St?6:r<Ut?7:r<Pt?8:r<It?9:10},Ot={encode:bt,decode:yt,encodingLength:Tt},zt=Ot,L=zt;var N=(r,e=0)=>[L.decode(r,e),L.decode.bytes],T=(r,e,t=0)=>(L.encode(r,e,t),e),O=r=>L.encodingLength(r);var F=(r,e)=>{let t=e.byteLength,o=O(r),n=o+O(t),u=new Uint8Array(n+t);return T(r,u,0),T(t,u,o),u.set(e,n),new z(r,t,e,u)},Se=r=>{let e=l(r),[t,o]=N(e),[n,u]=N(e.subarray(o)),s=e.subarray(o+u);if(s.byteLength!==n)throw new Error("Incorrect length");return new z(t,n,s,e)},Ue=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&ge(r.bytes,e.bytes),z=class{constructor(e,t,o,n){this.code=e,this.size=t,this.digest=o,this.bytes=n}};var he=({name:r,code:e,encode:t})=>new fe(r,e,t),fe=class{constructor(e,t,o){this.name=e,this.code=t,this.encode=o}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?F(this.code,t):t.then(o=>F(this.code,o))}else throw Error("Unknown type, must be binary type")}};var Lt=he({name:"sha2-256",code:18,encode:r=>l(Ie.createHash("sha256").update(r).digest())}),Nt=he({name:"sha2-512",code:19,encode:r=>l(Ie.createHash("sha512").update(r).digest())});var pe={};p(pe,{identity:()=>kt});var Te=0,jt="identity",Oe=l,Mt=r=>F(Te,Oe(r)),kt={code:Te,name:jt,encode:Oe,digest:Mt};var Ur=new TextEncoder,Pr=new TextDecoder;var R=class r{constructor(e,t,o,n){this.code=t,this.version=e,this.multihash=o,this.bytes=n,this.byteOffset=n.byteOffset,this.byteLength=n.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:J,byteLength:J,code:q,version:q,multihash:q,bytes:q,_baseCache:J,asCID:J})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==M)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Rt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,o=F(e,t);return r.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Ue(this.multihash,e.multihash)}toString(e){let{bytes:t,version:o,_baseCache:n}=this;switch(o){case 0:return qt(t,n,e||y.encoder);default:return Jt(t,n,e||I.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return Wt(/^0\.0/,Zt),!!(e&&(e[Le]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:o,multihash:n,bytes:u}=e;return new r(t,o,n,u||ze(t,o,n.bytes))}else if(e!=null&&e[Le]===!0){let{version:t,multihash:o,code:n}=e,u=Se(o);return r.create(t,n,u)}else return null}static create(e,t,o){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==M)throw new Error(`Version 0 CID must use dag-pb (code: ${M}) block encoding`);return new r(e,t,o,o.bytes)}case 1:{let n=ze(e,t,o.bytes);return new r(e,t,o,n)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,M,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,o]=r.decodeFirst(e);if(o.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),o=t.size-t.multihashSize,n=l(e.subarray(o,o+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");let u=n.subarray(t.multihashSize-t.digestSize),s=new z(t.multihashCode,t.digestSize,u,n);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,o=()=>{let[S,k]=N(e.subarray(t));return t+=k,S},n=o(),u=M;if(n===18?(n=0,t=0):n===1&&(u=o()),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=t,D=o(),c=o(),B=t+c,h=B-s;return{version:n,codec:u,multihashCode:D,digestSize:c,multihashSize:h,size:B}}static parse(e,t){let[o,n]=$t(e,t),u=r.decode(n);return u._baseCache.set(o,e),u}},$t=(r,e)=>{switch(r[0]){case"Q":{let t=e||y;return[y.prefix,t.decode(`${y.prefix}${r}`)]}case y.prefix:{let t=e||y;return[y.prefix,t.decode(r)]}case I.prefix:{let t=e||I;return[I.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}},qt=(r,e,t)=>{let{prefix:o}=t;if(o!==y.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let n=e.get(o);if(n==null){let u=t.encode(r).slice(1);return e.set(o,u),u}else return n},Jt=(r,e,t)=>{let{prefix:o}=t,n=e.get(o);if(n==null){let u=t.encode(r);return e.set(o,u),u}else return n},M=112,Rt=18,ze=(r,e,t)=>{let o=O(r),n=o+O(e),u=new Uint8Array(n+t.byteLength);return T(r,u,0),T(e,u,o),u.set(t,n),u},Le=Symbol.for("@ipld/js-cid/CID"),q={writable:!1,configurable:!1,enumerable:!0},J={writable:!1,enumerable:!1,configurable:!1},Xt="0.0.0-dev",Wt=(r,e)=>{if(r.test(Xt))console.warn(e);else throw new Error(e)},Zt=`CID.isCID(v) is deprecated and will be removed in the next major release. | ||
| Following code pattern: | ||
| if (CID.isCID(value)) { | ||
| doSomethingWithCID(value) | ||
| } | ||
| Is replaced with: | ||
| const cid = CID.asCID(value) | ||
| if (cid) { | ||
| // Make sure to use cid instead of value | ||
| doSomethingWithCID(cid) | ||
| } | ||
| `;var le={...ee,...te,...re,...oe,...ne,...ue,...se,...ie,...De,...ae},Mr={...de,...pe};function je(r,e,t,o){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:o}}}var Ne=je("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),me=je("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=K(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Gt={utf8:Ne,"utf-8":Ne,hex:le.base16,latin1:me,ascii:me,binary:me,...le},X=Gt;function W(r,e="utf8"){let t=X[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?U(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Z(r,e="utf8"){let t=X[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}import{Factory as G}from"@muisit/cryptokey";var be=class r{token="";headerPart="";payloadPart="";signaturePart="";header={};payload={};constructor(){}static fromToken(e){let t=new r;t.token=e;let o=e.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(o&&o.length==4&&(t.headerPart=o[1],t.payloadPart=o[2],t.signaturePart=o[3],t.decode()),!t.header||!t.payload||!t.signaturePart||Object.keys(t.header).length==0||Object.keys(t.payload).length==0)throw new Error("Invalid JWT");return t}decode(){this.headerPart.length>0&&(this.header===null||Object.keys(this.header).length==0)&&(this.header=this.decodeFromBase64(this.headerPart)),this.payloadPart.length>0&&(this.payload===null||Object.keys(this.payload).length==0)&&(this.payload=this.decodeFromBase64(this.payloadPart))}async verify(e){let t=Buffer.from(this.headerPart+"."+this.payloadPart),o=this.header.alg||e.algorithms()[0];return await e.verify(o,W(this.signaturePart,"base64url"),t)}async findKey(){let e=null;if(this.header?.kid){let t=this.header.kid.split("#")[0].trim("=");e=await G.resolve(t)}return!e&&this.header?.jwk&&(e=await G.createFromJWK(this.header.jwk)),!e&&this.header?.iss&&(e=await G.resolve(this.header.iss)),!e&&this.payload?.iss&&(e=await G.resolve(this.payload.iss)),e}async sign(e,t){let o=t||this.header?.alg||"ES256";typeof e!="function"&&(this.header.alg=o),this.header?this.headerPart=this.encodeToBase64(this.header):this.headerPart||(this.headerPart=""),this.payload?this.payloadPart=this.encodeToBase64(this.payload):this.payloadPart||(this.payloadPart="");let n=Buffer.from(this.headerPart+"."+this.payloadPart);typeof e!="function"?this.signaturePart=await e.sign(o,n,"base64url"):this.signaturePart=await e(n),this.token=this.headerPart+"."+this.payloadPart+"."+this.signaturePart}decodeFromBase64(e){let t=W(e,"base64url"),o=Z(t);try{return JSON.parse(o)}catch{}return null}encodeToBase64(e){let t=Buffer.from(JSON.stringify(e));return Z(t,"base64url")}};export{be as JWT}; |
+1
-1
| { | ||
| "name": "@muisit/simplejwt", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Implementation to read, create, sign and verify simple JWTs", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs", |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
57740
246.97%9
80%310
160.5%3
200%2
Infinity%