@junobuild/core-peer 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +3 -3
- package/dist/workers/_auth.worker.handler.js +2 -2
- package/dist/workers/_auth.worker.handler.js.map +1 -1
- package/dist/workers/auth.worker.js +2 -2
- package/dist/workers/auth.worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,14 +9,14 @@ ic-request`),be=class{getPrincipal(){return this._principal||(this._principal=vt
|
|
|
9
9
|
Retrying request.`),await Vt(this,Qr,"m",r).call(this,{request:e,backoff:n,tries:i+1});throw w}if(o.ok)return o;let c=await o.clone().text(),u=`Server returned an error:
|
|
10
10
|
Code: ${o.status} (${o.statusText})
|
|
11
11
|
Body: ${c}
|
|
12
|
-
`;if(o.status===404&&o.url.includes("api/v3"))throw new xr("v3 api not supported. Fall back to v2",{ok:o.ok,status:o.status,statusText:o.statusText,headers:zr(o.headers)});if(i<Vt(this,Pe,"f"))return await Vt(this,Qr,"m",r).call(this,{request:e,backoff:n,tries:i+1});throw new xr(u,{ok:o.ok,status:o.status,statusText:o.statusText,headers:zr(o.headers)})},B0=async function(){if(!this.rootKey)if(this.rootKey===null&&Vt(this,so,"f"))await this.fetchRootKey();else throw new zt(`Invalid root key detected. The root key for this agent is ${this.rootKey} and the shouldFetchRootKey value is set to ${Vt(this,so,"f")}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`)}});var Zc,Qc=L(()=>{Dt();(function(r){r.Error="err",r.GetPrincipal="gp",r.GetPrincipalResponse="gpr",r.Query="q",r.QueryResponse="qr",r.Call="c",r.CallResponse="cr",r.ReadState="rs",r.ReadStateResponse="rsr",r.Status="s",r.StatusResponse="sr"})(Zc||(Zc={}))});var Jr=L(()=>{Ni();ao();$n();Qc()});var F0=Te($o());Jr();ar();hr();Jr();vr();Gt();var si={};Xu(si,{backoff:()=>nu,chain:()=>iu,conditionalDelay:()=>eu,defaultStrategy:()=>co,maxAttempts:()=>N0,once:()=>tu,throttle:()=>R0,timeout:()=>ru});Gt();var I0=
|
|
12
|
+
`;if(o.status===404&&o.url.includes("api/v3"))throw new xr("v3 api not supported. Fall back to v2",{ok:o.ok,status:o.status,statusText:o.statusText,headers:zr(o.headers)});if(i<Vt(this,Pe,"f"))return await Vt(this,Qr,"m",r).call(this,{request:e,backoff:n,tries:i+1});throw new xr(u,{ok:o.ok,status:o.status,statusText:o.statusText,headers:zr(o.headers)})},B0=async function(){if(!this.rootKey)if(this.rootKey===null&&Vt(this,so,"f"))await this.fetchRootKey();else throw new zt(`Invalid root key detected. The root key for this agent is ${this.rootKey} and the shouldFetchRootKey value is set to ${Vt(this,so,"f")}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`)}});var Zc,Qc=L(()=>{Dt();(function(r){r.Error="err",r.GetPrincipal="gp",r.GetPrincipalResponse="gpr",r.Query="q",r.QueryResponse="qr",r.Call="c",r.CallResponse="cr",r.ReadState="rs",r.ReadStateResponse="rsr",r.Status="s",r.StatusResponse="sr"})(Zc||(Zc={}))});var Jr=L(()=>{Ni();ao();$n();Qc()});var F0=Te($o());Jr();ar();hr();Jr();vr();Gt();var si={};Xu(si,{backoff:()=>nu,chain:()=>iu,conditionalDelay:()=>eu,defaultStrategy:()=>co,maxAttempts:()=>N0,once:()=>tu,throttle:()=>R0,timeout:()=>ru});Gt();var I0=300*1e3;function co(){return iu(eu(tu(),1e3),nu(1e3,1.2),ru(I0))}function tu(){let r=!0;return async()=>r?(r=!1,!0):!1}function eu(r,t){return async(e,n,i)=>{if(await r(e,n,i))return new Promise(s=>setTimeout(s,t))}}function N0(r){let t=r;return async(e,n,i)=>{if(--t<=0)throw new Error(`Failed to retrieve a reply for request after ${r} attempts:
|
|
13
13
|
Request ID: ${bt(n)}
|
|
14
14
|
Request status: ${i}
|
|
15
15
|
`)}}function R0(r){return()=>new Promise(t=>setTimeout(t,r))}function ru(r){let t=Date.now()+r;return async(e,n,i)=>{if(Date.now()>t)throw new Error(`Request timed out after ${r} msec:
|
|
16
16
|
Request ID: ${bt(n)}
|
|
17
17
|
Request status: ${i}
|
|
18
18
|
`)}}function nu(r,t){let e=r;return()=>new Promise(n=>setTimeout(()=>{e*=t,n()},e))}function iu(...r){return async(t,e,n)=>{for(let i of r)await i(t,e,n)}}Dt();Gt();vr();var Tg=Symbol.for("ic-agent-metadata");var Sg={pollingStrategyFactory:si.defaultStrategy};Jr();Cn();Dr();Is();vr();ro();Dt();Ln();ao();io();no();Kr();Js();Gt();Vs();Ln();Wr();Hc();var ci=function(r,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!i:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,e):i?i.value=e:t.set(r,e),e},Me=function(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)},oi,ai,Br,Ir;function su(r){return r!==null&&typeof r=="object"}var Ye=class r{constructor(t){if(oi.set(this,void 0),ai.set(this,void 0),t.byteLength!==r.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");ci(this,oi,t,"f"),ci(this,ai,r.derEncode(t),"f")}static from(t){if(typeof t=="string"){let e=Kt(t);return this.fromRaw(e)}else if(su(t)){let e=t;if(su(e)&&Object.hasOwnProperty.call(e,"__derEncodedPublicKey__"))return this.fromDer(e);if(ArrayBuffer.isView(e)){let n=e;return this.fromRaw(xn(n.buffer))}else{if(e instanceof ArrayBuffer)return this.fromRaw(e);if("rawKey"in e)return this.fromRaw(e.rawKey);if("derKey"in e)return this.fromDer(e.derKey);if("toDer"in e)return this.fromDer(e.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}static fromRaw(t){return new r(t)}static fromDer(t){return new r(this.derDecode(t))}static derEncode(t){let e=Tr(t,ze).buffer;return e.__derEncodedPublicKey__=void 0,e}static derDecode(t){let e=Zr(t,ze);if(e.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return e}get rawKey(){return Me(this,oi,"f")}get derKey(){return Me(this,ai,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};oi=new WeakMap,ai=new WeakMap;Ye.RAW_KEY_LENGTH=32;var Xe=class r extends be{constructor(t,e){super(),Br.set(this,void 0),Ir.set(this,void 0),ci(this,Br,Ye.from(t),"f"),ci(this,Ir,new Uint8Array(e),"f")}static generate(t){if(t&&t.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");t||(t=Ar.utils.randomPrivateKey()),or(t,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let e=new Uint8Array(32);for(let i=0;i<32;i++)e[i]=new Uint8Array(t)[i];let n=Ar.getPublicKey(e);return r.fromKeyPair(n,e)}static fromParsedJson(t){let[e,n]=t;return new r(Ye.fromDer(Kt(e)),Kt(n))}static fromJSON(t){let e=JSON.parse(t);if(Array.isArray(e)){if(typeof e[0]=="string"&&typeof e[1]=="string")return this.fromParsedJson([e[0],e[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(t)}`)}static fromKeyPair(t,e){return new r(Ye.fromRaw(t),e)}static fromSecretKey(t){let e=Ar.getPublicKey(new Uint8Array(t));return r.fromKeyPair(e,t)}toJSON(){return[bt(Me(this,Br,"f").toDer()),bt(Me(this,Ir,"f"))]}getKeyPair(){return{secretKey:Me(this,Ir,"f"),publicKey:Me(this,Br,"f")}}getPublicKey(){return Me(this,Br,"f")}async sign(t){let e=new Uint8Array(t),n=Ke(Ar.sign(e,Me(this,Ir,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(t,e,n){let[i,s,o]=[t,e,n].map(c=>(typeof c=="string"&&(c=Kt(c)),c instanceof Uint8Array&&(c=c.buffer),new Uint8Array(c)));return Ar.verify(s,i,o)}};Br=new WeakMap,Ir=new WeakMap;var uo=class r extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,r.prototype)}};function ou(r){if(typeof global<"u"&&global.crypto&&global.crypto.subtle)return global.crypto.subtle;if(r)return r;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new uo("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var tn=class r extends be{constructor(t,e,n){super(),this._keyPair=t,this._derKey=e,this._subtleCrypto=n}static async generate(t){let{extractable:e=!1,keyUsages:n=["sign","verify"],subtleCrypto:i}=t??{},s=ou(i),o=await s.generateKey({name:"ECDSA",namedCurve:"P-256"},e,n),c=await s.exportKey("spki",o.publicKey);return new this(o,c,s)}static async fromKeyPair(t,e){let n=ou(e),i=await n.exportKey("spki",t.publicKey);return new r(t,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let t=this._derKey,e=Object.create(this._keyPair.publicKey);return e.toDer=function(){return t},e}async sign(t){let e={name:"ECDSA",hash:{name:"SHA-256"}};return await this._subtleCrypto.sign(e,this._keyPair.privateKey,t)}};Dt();var Nr=Te(Lr());Dt();var k0=function(r,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!i:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,e):i?i.value=e:t.set(r,e),e},en=function(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)},Ce,ui=class{constructor(t){Ce.set(this,void 0),k0(this,Ce,t,"f")}get rawKey(){return en(this,Ce,"f").rawKey}get derKey(){return en(this,Ce,"f").derKey}toDer(){return en(this,Ce,"f").toDer()}getPublicKey(){return en(this,Ce,"f")}getPrincipal(){return vt.from(en(this,Ce,"f").rawKey)}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}};Ce=new WeakMap;var P0=function(r,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!i:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,e):i?i.value=e:t.set(r,e),e},M0=function(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)},C0=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e},fi,$0=new TextEncoder().encode("ic-request-auth-delegation"),V0=new TextEncoder().encode(`
|
|
19
|
-
ic-request`);function fo(r){if(typeof r!="string"||r.length<64)throw new Error("Invalid public key.");return Kt(r)}var Rr=class{constructor(t,e,n){this.pubkey=t,this.expiration=e,this.targets=n}toCBOR(){return Nr.value.map(Object.assign({pubkey:Nr.value.bytes(this.pubkey),expiration:Nr.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:Nr.value.array(this.targets.map(t=>Nr.value.bytes(t.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:bt(this.pubkey)},this.targets&&{targets:this.targets.map(t=>t.toHex())})}};async function q0(r,t,e,n){let i=new Rr(t.toDer(),BigInt(+e)*BigInt(1e6),n),s=new Uint8Array([...$0,...new Uint8Array(gr(Object.assign({},i)))]),o=await r.sign(s);return{delegation:i,signature:o}}var Je=class r{constructor(t,e){this.delegations=t,this.publicKey=e}static async create(t,e,n=new Date(Date.now()+15*60*1e3),i={}){var s,o;let c=await q0(t,e,n,i.targets);return new r([...((s=i.previous)===null||s===void 0?void 0:s.delegations)||[],c],((o=i.previous)===null||o===void 0?void 0:o.publicKey)||t.getPublicKey().toDer())}static fromJSON(t){let{publicKey:e,delegations:n}=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(s=>{let{delegation:o,signature:c}=s,{pubkey:u,expiration:w,targets:y}=o;if(y!==void 0&&!Array.isArray(y))throw new Error("Invalid targets.");return{delegation:new Rr(fo(u),BigInt("0x"+w),y&&y.map(m=>{if(typeof m!="string")throw new Error("Invalid target.");return vt.fromHex(m)})),signature:fo(c)}});return new this(i,fo(e))}static fromDelegations(t,e){return new this(t,e)}toJSON(){return{delegations:this.delegations.map(t=>{let{delegation:e,signature:n}=t,{targets:i}=e;return{delegation:Object.assign({expiration:e.expiration.toString(16),pubkey:bt(e.pubkey)},i&&{targets:i.map(s=>s.toHex())}),signature:bt(n)}}),publicKey:bt(this.publicKey)}}},rn=class extends be{constructor(t,e){super(),this._inner=t,this._delegation=e}static fromDelegation(t,e){return new this(t,e)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(t){return this._inner.sign(t)}async transformRequest(t){let{body:e}=t,n=C0(t,["body"]),i=await gr(e);return Object.assign(Object.assign({},n),{body:{content:e,sender_sig:await this.sign(new Uint8Array([...V0,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},nn=class r extends ui{constructor(t,e){super(t),fi.set(this,void 0),P0(this,fi,e,"f")}get delegation(){return M0(this,fi,"f")}static fromDelegation(t,e){return new r(t,e)}};fi=new WeakMap;function li(r,t){for(let{delegation:i}of r.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let e=[],n=t?.scope;n&&(Array.isArray(n)?e.push(...n.map(i=>typeof i=="string"?vt.fromText(i):i)):e.push(typeof n=="string"?vt.fromText(n):n));for(let i of e){let s=i.toText();for(let{delegation:o}of r.delegations){if(o.targets===void 0)continue;let c=!0;for(let u of o.targets)if(u.toText()===s){c=!1;break}if(c)return!1}}return!0}var H0=Te(Nn());hr();var au;(function(r){r[r.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(au||(au={}));var cu=["mousedown","mousemove","keydown","touchstart","wheel"],sn=class{constructor(t={}){var e;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=10*60*1e3}=t||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let s=this._resetTimer.bind(this);window.addEventListener("load",s,!0),cu.forEach(function(c){document.addEventListener(c,s,!0)});let o=(c,u)=>{let w;return(...y)=>{let m=this,N=function(){w=void 0,c.apply(m,y)};clearTimeout(w),w=window.setTimeout(N,u)}};if(t?.captureScroll){let c=o(s,(e=t?.scrollDebounce)!==null&&e!==void 0?e:100);window.addEventListener("scroll",c,!0)}s()}static create(t={}){return new this(t)}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);cu.forEach(function(e){document.removeEventListener(e,t,!0)}),this.callbacks.forEach(e=>e())}_resetTimer(){let t=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(t,this.idleTimeout)}};var j0=(r,t)=>t.some(e=>r instanceof e),uu,fu;function K0(){return uu||(uu=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function G0(){return fu||(fu=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var lu=new WeakMap,ho=new WeakMap,hu=new WeakMap,lo=new WeakMap,yo=new WeakMap;function L0(r){let t=new Promise((e,n)=>{let i=()=>{r.removeEventListener("success",s),r.removeEventListener("error",o)},s=()=>{e(me(r.result)),i()},o=()=>{n(r.error),i()};r.addEventListener("success",s),r.addEventListener("error",o)});return t.then(e=>{e instanceof IDBCursor&&lu.set(e,r)}).catch(()=>{}),yo.set(t,r),t}function W0(r){if(ho.has(r))return;let t=new Promise((e,n)=>{let i=()=>{r.removeEventListener("complete",s),r.removeEventListener("error",o),r.removeEventListener("abort",o)},s=()=>{e(),i()},o=()=>{n(r.error||new DOMException("AbortError","AbortError")),i()};r.addEventListener("complete",s),r.addEventListener("error",o),r.addEventListener("abort",o)});ho.set(r,t)}var po={get(r,t,e){if(r instanceof IDBTransaction){if(t==="done")return ho.get(r);if(t==="objectStoreNames")return r.objectStoreNames||hu.get(r);if(t==="store")return e.objectStoreNames[1]?void 0:e.objectStore(e.objectStoreNames[0])}return me(r[t])},set(r,t,e){return r[t]=e,!0},has(r,t){return r instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in r}};function du(r){po=r(po)}function D0(r){return r===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...e){let n=r.call(hi(this),t,...e);return hu.set(n,t.sort?t.sort():[t]),me(n)}:G0().includes(r)?function(...t){return r.apply(hi(this),t),me(lu.get(this))}:function(...t){return me(r.apply(hi(this),t))}}function z0(r){return typeof r=="function"?D0(r):(r instanceof IDBTransaction&&W0(r),j0(r,K0())?new Proxy(r,po):r)}function me(r){if(r instanceof IDBRequest)return L0(r);if(lo.has(r))return lo.get(r);let t=z0(r);return t!==r&&(lo.set(r,t),yo.set(t,r)),t}var hi=r=>yo.get(r);function yu(r,t,{blocked:e,upgrade:n,blocking:i,terminated:s}={}){let o=indexedDB.open(r,t),c=me(o);return n&&o.addEventListener("upgradeneeded",u=>{n(me(o.result),u.oldVersion,u.newVersion,me(o.transaction),u)}),e&&o.addEventListener("blocked",u=>e(u.oldVersion,u.newVersion,u)),c.then(u=>{s&&u.addEventListener("close",()=>s()),i&&u.addEventListener("versionchange",w=>i(w.oldVersion,w.newVersion,w))}).catch(()=>{}),c}var Y0=["get","getKey","getAll","getAllKeys","count"],X0=["put","add","delete","clear"],wo=new Map;function pu(r,t){if(!(r instanceof IDBDatabase&&!(t in r)&&typeof t=="string"))return;if(wo.get(t))return wo.get(t);let e=t.replace(/FromIndex$/,""),n=t!==e,i=X0.includes(e);if(!(e in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Y0.includes(e)))return;let s=async function(o,...c){let u=this.transaction(o,i?"readwrite":"readonly"),w=u.store;return n&&(w=w.index(c.shift())),(await Promise.all([w[e](...c),i&&u.done]))[0]};return wo.set(t,s),s}du(r=>({...r,get:(t,e,n)=>pu(t,e)||r.get(t,e,n),has:(t,e)=>!!pu(t,e)||r.has(t,e)}));var wu="auth-client-db",gu="ic-keyval",J0=async(r=wu,t=gu,e)=>(di&&(localStorage!=null&&localStorage.getItem(Qt))&&(localStorage.removeItem(Qt),localStorage.removeItem(ue)),await yu(r,e,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function Z0(r,t,e){return await r.get(t,e)}async function Q0(r,t,e,n){return await r.put(t,n,e)}async function td(r,t,e){return await r.delete(t,e)}var on=class r{constructor(t,e){this._db=t,this._storeName=e}static async create(t){let{dbName:e=wu,storeName:n=gu,version:i=mu}=t??{},s=await J0(e,n,i);return new r(s,n)}async set(t,e){return await Q0(this._db,this._storeName,t,e)}async get(t){var e;return(e=await Z0(this._db,this._storeName,t))!==null&&e!==void 0?e:null}async remove(t){return await td(this._db,this._storeName,t)}};var ed=function(r,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!i:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,e):i?i.value=e:t.set(r,e),e},rd=function(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)},pi,ue="identity",Qt="delegation",xu="iv",mu=1,di=typeof window<"u",an=class{constructor(t="ic-",e){this.prefix=t,this._localStorage=e}get(t){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+t))}set(t,e){return this._getLocalStorage().setItem(this.prefix+t,e),Promise.resolve()}remove(t){return this._getLocalStorage().removeItem(this.prefix+t),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let t=typeof window>"u"?typeof global>"u"?typeof self>"u"?void 0:self.localStorage:global.localStorage:window.localStorage;if(!t)throw new Error("Could not find local storage.");return t}},Ze=class{constructor(t){pi.set(this,void 0),ed(this,pi,t??{},"f")}get _db(){return new Promise(t=>{if(this.initializedDb){t(this.initializedDb);return}on.create(rd(this,pi,"f")).then(e=>{this.initializedDb=e,t(e)})})}async get(t){return await(await this._db).get(t)}async set(t,e){await(await this._db).set(t,e)}async remove(t){await(await this._db).remove(t)}};pi=new WeakMap;var nd="https://identity.ic0.app",id="#authorize",go="ECDSA",mo="Ed25519",sd=500,od="UserInterrupt",yi=class{constructor(t,e,n,i,s,o,c,u){this._identity=t,this._key=e,this._chain=n,this._storage=i,this.idleManager=s,this._createOptions=o,this._idpWindow=c,this._eventHandler=u,this._registerDefaultIdleCallback()}static async create(t={}){var e,n,i;let s=(e=t.storage)!==null&&e!==void 0?e:new Ze,o=(n=t.keyType)!==null&&n!==void 0?n:go,c=null;if(t.identity)c=t.identity;else{let m=await s.get(ue);if(!m&&di)try{let N=new an,P=await N.get(Qt),O=await N.get(ue);P&&O&&o===go&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await s.set(Qt,P),await s.set(ue,O),m=P,await N.remove(Qt),await N.remove(ue))}catch(N){console.error("error while attempting to recover localstorage: "+N)}if(m)try{typeof m=="object"?o===mo&&typeof m=="string"?c=await Xe.fromJSON(m):c=await tn.fromKeyPair(m):typeof m=="string"&&(c=Xe.fromJSON(m))}catch{}}let u=new mr,w=null;if(c)try{let m=await s.get(Qt);if(typeof m=="object"&&m!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");t.identity?u=t.identity:m&&(w=Je.fromJSON(m),li(w)?"toDer"in c?u=nn.fromDelegation(c,w):u=rn.fromDelegation(c,w):(await xo(s),c=null))}catch(m){console.error(m),await xo(s),c=null}let y;return!((i=t.idleOptions)===null||i===void 0)&&i.disableIdle?y=void 0:(w||t.identity)&&(y=sn.create(t.idleOptions)),c||(o===mo?(c=await Xe.generate(),await s.set(ue,JSON.stringify(c.toJSON()))):(t.storage&&o===go&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${mo}' as the key type, as it can serialize to a string`),c=await tn.generate(),await s.set(ue,c.getKeyPair()))),new this(u,c,w,s,y,t)}_registerDefaultIdleCallback(){var t,e;let n=(t=this._createOptions)===null||t===void 0?void 0:t.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((e=this.idleManager)===null||e===void 0||e.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(t,e){var n,i;let s=t.delegations.map(w=>({delegation:new Rr(w.delegation.pubkey,w.delegation.expiration,w.delegation.targets),signature:w.signature.buffer})),o=Je.fromDelegations(s,t.userPublicKey.buffer),c=this._key;if(!c)return;this._chain=o,"toDer"in c?this._identity=nn.fromDelegation(c,this._chain):this._identity=rn.fromDelegation(c,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let u=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!u?.disableIdle&&(this.idleManager=sn.create(u),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(Qt,JSON.stringify(this._chain.toJSON())),e?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(t){var e,n,i,s;let o=BigInt(8)*BigInt(36e11),c=new URL(((e=t?.identityProvider)===null||e===void 0?void 0:e.toString())||nd);c.hash=id,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(c,Object.assign({maxTimeToLive:(i=t?.maxTimeToLive)!==null&&i!==void 0?i:o},t)),window.addEventListener("message",this._eventHandler),this._idpWindow=(s=window.open(c.toString(),"idpWindow",t?.windowOpenerFeatures))!==null&&s!==void 0?s:void 0;let u=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(od,t?.onError):setTimeout(u,sd))};u()}_getEventHandler(t,e){return async n=>{var i,s,o;if(n.origin!==t.origin)return;let c=n.data;switch(c.kind){case"authorize-ready":{let u=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:e?.maxTimeToLive,allowPinAuthentication:e?.allowPinAuthentication,derivationOrigin:(s=e?.derivationOrigin)===null||s===void 0?void 0:s.toString()},e?.customValues);(o=this._idpWindow)===null||o===void 0||o.postMessage(u,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(c,e?.onSuccess)}catch(u){this._handleFailure(u.message,e?.onError)}break;case"authorize-client-failure":this._handleFailure(c.text,e?.onError);break;default:break}}}_handleFailure(t,e){var n;(n=this._idpWindow)===null||n===void 0||n.close(),e?.(t),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(t={}){if(await xo(this._storage),this._identity=new mr,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function xo(r){await r.remove(ue),await r.remove(Qt),await r.remove(xu)}var jm=BigInt(144e11);var _u=1e3;var bu=()=>yi.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Eu=({data:r})=>{let{msg:t}=r;switch(t){case"junoStartAuthTimer":ad();return;case"junoStopAuthTimer":vu();return}},wi,ad=()=>wi=setInterval(async()=>await cd(),_u),vu=()=>{wi&&(clearInterval(wi),wi=void 0)},cd=async()=>{let[r,t]=await Promise.all([ud(),fd()]);if(r&&t.valid&&t.delegation!==null){hd(t.delegation);return}ld()},ud=async()=>(await bu()).isAuthenticated(),fd=async()=>{let t=await new Ze().get(Qt),e=t!==null?Je.fromJSON(t):null;return{valid:e!==null&&li(e),delegation:e}},ld=()=>{vu(),postMessage({msg:"junoSignOutAuthTimer"})},hd=r=>{let t=r.delegations[0]?.delegation.expiration;if(t===void 0)return;let e=new Date(Number(t/BigInt(1e6))).getTime()-Date.now();postMessage({msg:"junoDelegationRemainingTime",data:{authRemainingTime:e}})};onmessage=r=>{Eu(r)};})();
|
|
19
|
+
ic-request`);function fo(r){if(typeof r!="string"||r.length<64)throw new Error("Invalid public key.");return Kt(r)}var Rr=class{constructor(t,e,n){this.pubkey=t,this.expiration=e,this.targets=n}toCBOR(){return Nr.value.map(Object.assign({pubkey:Nr.value.bytes(this.pubkey),expiration:Nr.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:Nr.value.array(this.targets.map(t=>Nr.value.bytes(t.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:bt(this.pubkey)},this.targets&&{targets:this.targets.map(t=>t.toHex())})}};async function q0(r,t,e,n){let i=new Rr(t.toDer(),BigInt(+e)*BigInt(1e6),n),s=new Uint8Array([...$0,...new Uint8Array(gr(Object.assign({},i)))]),o=await r.sign(s);return{delegation:i,signature:o}}var Je=class r{constructor(t,e){this.delegations=t,this.publicKey=e}static async create(t,e,n=new Date(Date.now()+900*1e3),i={}){var s,o;let c=await q0(t,e,n,i.targets);return new r([...((s=i.previous)===null||s===void 0?void 0:s.delegations)||[],c],((o=i.previous)===null||o===void 0?void 0:o.publicKey)||t.getPublicKey().toDer())}static fromJSON(t){let{publicKey:e,delegations:n}=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(s=>{let{delegation:o,signature:c}=s,{pubkey:u,expiration:w,targets:y}=o;if(y!==void 0&&!Array.isArray(y))throw new Error("Invalid targets.");return{delegation:new Rr(fo(u),BigInt("0x"+w),y&&y.map(m=>{if(typeof m!="string")throw new Error("Invalid target.");return vt.fromHex(m)})),signature:fo(c)}});return new this(i,fo(e))}static fromDelegations(t,e){return new this(t,e)}toJSON(){return{delegations:this.delegations.map(t=>{let{delegation:e,signature:n}=t,{targets:i}=e;return{delegation:Object.assign({expiration:e.expiration.toString(16),pubkey:bt(e.pubkey)},i&&{targets:i.map(s=>s.toHex())}),signature:bt(n)}}),publicKey:bt(this.publicKey)}}},rn=class extends be{constructor(t,e){super(),this._inner=t,this._delegation=e}static fromDelegation(t,e){return new this(t,e)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(t){return this._inner.sign(t)}async transformRequest(t){let{body:e}=t,n=C0(t,["body"]),i=await gr(e);return Object.assign(Object.assign({},n),{body:{content:e,sender_sig:await this.sign(new Uint8Array([...V0,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},nn=class r extends ui{constructor(t,e){super(t),fi.set(this,void 0),P0(this,fi,e,"f")}get delegation(){return M0(this,fi,"f")}static fromDelegation(t,e){return new r(t,e)}};fi=new WeakMap;function li(r,t){for(let{delegation:i}of r.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let e=[],n=t?.scope;n&&(Array.isArray(n)?e.push(...n.map(i=>typeof i=="string"?vt.fromText(i):i)):e.push(typeof n=="string"?vt.fromText(n):n));for(let i of e){let s=i.toText();for(let{delegation:o}of r.delegations){if(o.targets===void 0)continue;let c=!0;for(let u of o.targets)if(u.toText()===s){c=!1;break}if(c)return!1}}return!0}var H0=Te(Nn());hr();var au;(function(r){r[r.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(au||(au={}));var cu=["mousedown","mousemove","keydown","touchstart","wheel"],sn=class{constructor(t={}){var e;this.callbacks=[],this.idleTimeout=600*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=600*1e3}=t||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let s=this._resetTimer.bind(this);window.addEventListener("load",s,!0),cu.forEach(function(c){document.addEventListener(c,s,!0)});let o=(c,u)=>{let w;return(...y)=>{let m=this,N=function(){w=void 0,c.apply(m,y)};clearTimeout(w),w=window.setTimeout(N,u)}};if(t?.captureScroll){let c=o(s,(e=t?.scrollDebounce)!==null&&e!==void 0?e:100);window.addEventListener("scroll",c,!0)}s()}static create(t={}){return new this(t)}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);cu.forEach(function(e){document.removeEventListener(e,t,!0)}),this.callbacks.forEach(e=>e())}_resetTimer(){let t=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(t,this.idleTimeout)}};var j0=(r,t)=>t.some(e=>r instanceof e),uu,fu;function K0(){return uu||(uu=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function G0(){return fu||(fu=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var lu=new WeakMap,ho=new WeakMap,hu=new WeakMap,lo=new WeakMap,yo=new WeakMap;function L0(r){let t=new Promise((e,n)=>{let i=()=>{r.removeEventListener("success",s),r.removeEventListener("error",o)},s=()=>{e(me(r.result)),i()},o=()=>{n(r.error),i()};r.addEventListener("success",s),r.addEventListener("error",o)});return t.then(e=>{e instanceof IDBCursor&&lu.set(e,r)}).catch(()=>{}),yo.set(t,r),t}function W0(r){if(ho.has(r))return;let t=new Promise((e,n)=>{let i=()=>{r.removeEventListener("complete",s),r.removeEventListener("error",o),r.removeEventListener("abort",o)},s=()=>{e(),i()},o=()=>{n(r.error||new DOMException("AbortError","AbortError")),i()};r.addEventListener("complete",s),r.addEventListener("error",o),r.addEventListener("abort",o)});ho.set(r,t)}var po={get(r,t,e){if(r instanceof IDBTransaction){if(t==="done")return ho.get(r);if(t==="objectStoreNames")return r.objectStoreNames||hu.get(r);if(t==="store")return e.objectStoreNames[1]?void 0:e.objectStore(e.objectStoreNames[0])}return me(r[t])},set(r,t,e){return r[t]=e,!0},has(r,t){return r instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in r}};function du(r){po=r(po)}function D0(r){return r===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...e){let n=r.call(hi(this),t,...e);return hu.set(n,t.sort?t.sort():[t]),me(n)}:G0().includes(r)?function(...t){return r.apply(hi(this),t),me(lu.get(this))}:function(...t){return me(r.apply(hi(this),t))}}function z0(r){return typeof r=="function"?D0(r):(r instanceof IDBTransaction&&W0(r),j0(r,K0())?new Proxy(r,po):r)}function me(r){if(r instanceof IDBRequest)return L0(r);if(lo.has(r))return lo.get(r);let t=z0(r);return t!==r&&(lo.set(r,t),yo.set(t,r)),t}var hi=r=>yo.get(r);function yu(r,t,{blocked:e,upgrade:n,blocking:i,terminated:s}={}){let o=indexedDB.open(r,t),c=me(o);return n&&o.addEventListener("upgradeneeded",u=>{n(me(o.result),u.oldVersion,u.newVersion,me(o.transaction),u)}),e&&o.addEventListener("blocked",u=>e(u.oldVersion,u.newVersion,u)),c.then(u=>{s&&u.addEventListener("close",()=>s()),i&&u.addEventListener("versionchange",w=>i(w.oldVersion,w.newVersion,w))}).catch(()=>{}),c}var Y0=["get","getKey","getAll","getAllKeys","count"],X0=["put","add","delete","clear"],wo=new Map;function pu(r,t){if(!(r instanceof IDBDatabase&&!(t in r)&&typeof t=="string"))return;if(wo.get(t))return wo.get(t);let e=t.replace(/FromIndex$/,""),n=t!==e,i=X0.includes(e);if(!(e in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Y0.includes(e)))return;let s=async function(o,...c){let u=this.transaction(o,i?"readwrite":"readonly"),w=u.store;return n&&(w=w.index(c.shift())),(await Promise.all([w[e](...c),i&&u.done]))[0]};return wo.set(t,s),s}du(r=>({...r,get:(t,e,n)=>pu(t,e)||r.get(t,e,n),has:(t,e)=>!!pu(t,e)||r.has(t,e)}));var wu="auth-client-db",gu="ic-keyval",J0=async(r=wu,t=gu,e)=>(di&&(localStorage!=null&&localStorage.getItem(Qt))&&(localStorage.removeItem(Qt),localStorage.removeItem(ue)),await yu(r,e,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function Z0(r,t,e){return await r.get(t,e)}async function Q0(r,t,e,n){return await r.put(t,n,e)}async function td(r,t,e){return await r.delete(t,e)}var on=class r{constructor(t,e){this._db=t,this._storeName=e}static async create(t){let{dbName:e=wu,storeName:n=gu,version:i=mu}=t??{},s=await J0(e,n,i);return new r(s,n)}async set(t,e){return await Q0(this._db,this._storeName,t,e)}async get(t){var e;return(e=await Z0(this._db,this._storeName,t))!==null&&e!==void 0?e:null}async remove(t){return await td(this._db,this._storeName,t)}};var ed=function(r,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!i:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,e):i?i.value=e:t.set(r,e),e},rd=function(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)},pi,ue="identity",Qt="delegation",xu="iv",mu=1,di=typeof window<"u",an=class{constructor(t="ic-",e){this.prefix=t,this._localStorage=e}get(t){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+t))}set(t,e){return this._getLocalStorage().setItem(this.prefix+t,e),Promise.resolve()}remove(t){return this._getLocalStorage().removeItem(this.prefix+t),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let t=typeof window>"u"?typeof global>"u"?typeof self>"u"?void 0:self.localStorage:global.localStorage:window.localStorage;if(!t)throw new Error("Could not find local storage.");return t}},Ze=class{constructor(t){pi.set(this,void 0),ed(this,pi,t??{},"f")}get _db(){return new Promise(t=>{if(this.initializedDb){t(this.initializedDb);return}on.create(rd(this,pi,"f")).then(e=>{this.initializedDb=e,t(e)})})}async get(t){return await(await this._db).get(t)}async set(t,e){await(await this._db).set(t,e)}async remove(t){await(await this._db).remove(t)}};pi=new WeakMap;var nd="https://identity.ic0.app",id="#authorize",go="ECDSA",mo="Ed25519",sd=500,od="UserInterrupt",yi=class{constructor(t,e,n,i,s,o,c,u){this._identity=t,this._key=e,this._chain=n,this._storage=i,this.idleManager=s,this._createOptions=o,this._idpWindow=c,this._eventHandler=u,this._registerDefaultIdleCallback()}static async create(t={}){var e,n,i;let s=(e=t.storage)!==null&&e!==void 0?e:new Ze,o=(n=t.keyType)!==null&&n!==void 0?n:go,c=null;if(t.identity)c=t.identity;else{let m=await s.get(ue);if(!m&&di)try{let N=new an,P=await N.get(Qt),O=await N.get(ue);P&&O&&o===go&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await s.set(Qt,P),await s.set(ue,O),m=P,await N.remove(Qt),await N.remove(ue))}catch(N){console.error("error while attempting to recover localstorage: "+N)}if(m)try{typeof m=="object"?o===mo&&typeof m=="string"?c=await Xe.fromJSON(m):c=await tn.fromKeyPair(m):typeof m=="string"&&(c=Xe.fromJSON(m))}catch{}}let u=new mr,w=null;if(c)try{let m=await s.get(Qt);if(typeof m=="object"&&m!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");t.identity?u=t.identity:m&&(w=Je.fromJSON(m),li(w)?"toDer"in c?u=nn.fromDelegation(c,w):u=rn.fromDelegation(c,w):(await xo(s),c=null))}catch(m){console.error(m),await xo(s),c=null}let y;return!((i=t.idleOptions)===null||i===void 0)&&i.disableIdle?y=void 0:(w||t.identity)&&(y=sn.create(t.idleOptions)),c||(o===mo?(c=await Xe.generate(),await s.set(ue,JSON.stringify(c.toJSON()))):(t.storage&&o===go&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${mo}' as the key type, as it can serialize to a string`),c=await tn.generate(),await s.set(ue,c.getKeyPair()))),new this(u,c,w,s,y,t)}_registerDefaultIdleCallback(){var t,e;let n=(t=this._createOptions)===null||t===void 0?void 0:t.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((e=this.idleManager)===null||e===void 0||e.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(t,e){var n,i;let s=t.delegations.map(w=>({delegation:new Rr(w.delegation.pubkey,w.delegation.expiration,w.delegation.targets),signature:w.signature.buffer})),o=Je.fromDelegations(s,t.userPublicKey.buffer),c=this._key;if(!c)return;this._chain=o,"toDer"in c?this._identity=nn.fromDelegation(c,this._chain):this._identity=rn.fromDelegation(c,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let u=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!u?.disableIdle&&(this.idleManager=sn.create(u),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(Qt,JSON.stringify(this._chain.toJSON())),e?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(t){var e,n,i,s;let o=BigInt(8)*BigInt(36e11),c=new URL(((e=t?.identityProvider)===null||e===void 0?void 0:e.toString())||nd);c.hash=id,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(c,Object.assign({maxTimeToLive:(i=t?.maxTimeToLive)!==null&&i!==void 0?i:o},t)),window.addEventListener("message",this._eventHandler),this._idpWindow=(s=window.open(c.toString(),"idpWindow",t?.windowOpenerFeatures))!==null&&s!==void 0?s:void 0;let u=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(od,t?.onError):setTimeout(u,sd))};u()}_getEventHandler(t,e){return async n=>{var i,s,o;if(n.origin!==t.origin)return;let c=n.data;switch(c.kind){case"authorize-ready":{let u=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:e?.maxTimeToLive,allowPinAuthentication:e?.allowPinAuthentication,derivationOrigin:(s=e?.derivationOrigin)===null||s===void 0?void 0:s.toString()},e?.customValues);(o=this._idpWindow)===null||o===void 0||o.postMessage(u,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(c,e?.onSuccess)}catch(u){this._handleFailure(u.message,e?.onError)}break;case"authorize-client-failure":this._handleFailure(c.text,e?.onError);break;default:break}}}_handleFailure(t,e){var n;(n=this._idpWindow)===null||n===void 0||n.close(),e?.(t),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(t={}){if(await xo(this._storage),this._identity=new mr,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function xo(r){await r.remove(ue),await r.remove(Qt),await r.remove(xu)}var jm=BigInt(144e11);var _u=1e3;var bu=()=>yi.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Eu=({data:r})=>{let{msg:t}=r;switch(t){case"junoStartAuthTimer":ad();return;case"junoStopAuthTimer":vu();return}},wi,ad=()=>wi=setInterval(async()=>await cd(),_u),vu=()=>{wi&&(clearInterval(wi),wi=void 0)},cd=async()=>{let[r,t]=await Promise.all([ud(),fd()]);if(r&&t.valid&&t.delegation!==null){hd(t.delegation);return}ld()},ud=async()=>(await bu()).isAuthenticated(),fd=async()=>{let t=await new Ze().get(Qt),e=t!==null?Je.fromJSON(t):null;return{valid:e!==null&&li(e),delegation:e}},ld=()=>{vu(),postMessage({msg:"junoSignOutAuthTimer"})},hd=r=>{let t=r.delegations[0]?.delegation.expiration;if(t===void 0)return;let e=new Date(Number(t/BigInt(1e6))).getTime()-Date.now();postMessage({msg:"junoDelegationRemainingTime",data:{authRemainingTime:e}})};onmessage=r=>{Eu(r)};})();
|
|
20
20
|
/*! Bundled license information:
|
|
21
21
|
|
|
22
22
|
ieee754/index.js:
|