import*as e from"worktop/base64";import*as r from"worktop/buffer";import*as t from"worktop/crypto";var a=new Error("Invalid token"),i=new Error("Expired token");function n(t){return e.base64url(r.toBinary(r.asUTF8(JSON.stringify(t))))}function o(t){return e.base64url(r.toBinary(t))}function s(e){return JSON.parse(r.toUTF8(r.asBinary(e)))}function p(r){let t=r.split(".");if(3!==t.length)throw a;try{let r=e.decode(t[1]);var i=s(e.decode(t[0])),n=s(r)}catch{throw a}return{header:i,payload:n,signature:t[2]}}function y(e,r,t){return r.iat=r.iat||Date.now()/1e3|0,null==r.exp&&null!=t&&(r.exp=r.iat+t),e+"."+n(r)}function u(e,r){let t=p(r),n=t.payload;if(!r.startsWith(e+"."))throw a;if(null!=n.exp&&n.exp