a tiny oauth browser client for atproto using a service worker
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up exports

+9 -10
+9 -10
atsw.js
··· 56 56 const enc = new TextEncoder(); 57 57 58 58 /** @param {ArrayBuffer | Uint8Array} buf */ 59 - export const b64url = (buf) => 59 + const b64url = (buf) => 60 60 btoa(String.fromCharCode(...new Uint8Array(buf))) 61 61 .replace(/\+/g, "-") 62 62 .replace(/\//g, "_") ··· 86 86 * @param {string} [nonce] 87 87 * @param {string} [ath] 88 88 */ 89 - export async function createDPoP(dpopKey, htm, htu, nonce, ath) { 89 + async function createDPoP(dpopKey, htm, htu, nonce, ath) { 90 90 const header = { alg: "ES256", typ: "dpop+jwt", jwk: dpopKey.jwk }; 91 91 92 92 const jti = b64url(crypto.getRandomValues(new Uint8Array(16)).buffer); ··· 111 111 } 112 112 113 113 /** 114 - * POST with a DPoP proof, retrying once if the server provides a nonce. 115 114 * @param {DPoPKey} dpopKey 116 115 * @param {string} url 117 116 * @param {URLSearchParams} body 118 117 * @param {string} [nonce] 119 118 * @returns {Promise<{ json: any, dpopNonce: string | undefined }>} 120 119 */ 121 - export async function dpopPost(dpopKey, url, body, nonce) { 120 + async function dpopPost(dpopKey, url, body, nonce) { 122 121 let dpopNonce = nonce; 123 122 for (let attempts = 0; attempts < 2; attempts++) { 124 123 const dpop = await createDPoP(dpopKey, "POST", url, dpopNonce); ··· 176 175 } 177 176 178 177 /** @param {AuthingSession} v */ 179 - export const putAuthing = (v) => idb("readwrite", "authing", (s) => s.put(v)); 178 + const putAuthing = (v) => idb("readwrite", "authing", (s) => s.put(v)); 180 179 181 180 /** @param {string} state @returns {Promise<AuthingSession | undefined>} */ 182 - export const getAuthing = (state) => idb("readonly", "authing", (s) => s.get(state)); 181 + const getAuthing = (state) => idb("readonly", "authing", (s) => s.get(state)); 183 182 184 183 /** @param {string} state */ 185 - export const deleteAuthing = (state) => idb("readwrite", "authing", (s) => s.delete(state)); 184 + const deleteAuthing = (state) => idb("readwrite", "authing", (s) => s.delete(state)); 186 185 187 186 /** @param {OAuthSession} v */ 188 - export const putSession = (v) => idb("readwrite", "sessions", (s) => s.put(v)); 187 + const putSession = (v) => idb("readwrite", "sessions", (s) => s.put(v)); 189 188 190 189 /** @returns {Promise<OAuthSession[]>} */ 191 190 export const listSessions = () => idb("readonly", "sessions", (s) => s.getAll()); ··· 229 228 } 230 229 231 230 /** @param {string} did */ 232 - export async function resolvePDS(did) { 231 + async function resolvePDS(did) { 233 232 const url = did.startsWith("did:web:") 234 233 ? `https://${did.split(":")[2]}/.well-known/did.json` 235 234 : `https://plc.directory/${did}`; ··· 245 244 * @param {string} pds 246 245 * @returns {Promise<AuthServerMetadata>} 247 246 */ 248 - export async function discoverAuthServer(pds) { 247 + async function discoverAuthServer(pds) { 249 248 const res = await (await fetch(`${pds}/.well-known/oauth-protected-resource`)).json(); 250 249 const issuer = /** @type {string} */ (res.authorization_servers[0]); 251 250 return (await fetch(`${issuer}/.well-known/oauth-authorization-server`)).json();