@tempoxyz/id 0.0.0-pr-986.sha-c2ced0f → 0.0.0-pr-985.sha-a4ce0a5

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.
@@ -2,9 +2,9 @@ import {
2
2
  attach,
3
3
  create,
4
4
  pending
5
- } from "./chunk-DHNGO76P.js";
5
+ } from "./chunk-L55QOJ7W.js";
6
6
  import "./chunk-FWGE6HXK.js";
7
- import "./chunk-KWKSUZOG.js";
7
+ import "./chunk-PGTIKJYS.js";
8
8
  import "./chunk-FHXDPKTL.js";
9
9
  import "./chunk-MLKGABMK.js";
10
10
  export {
@@ -72,21 +72,19 @@ function create(path) {
72
72
  const target = resolve();
73
73
  await Fs.mkdir(Path2.dirname(target), { mode: 448, recursive: true });
74
74
  return await locked(target, async (check) => {
75
- const [entries] = await Promise.all([read(), sweep(target)]);
75
+ const entries = await read();
76
76
  const result = fn(entries);
77
77
  for (const [key, entry] of Object.entries(entries))
78
78
  if (expired(entry)) delete entries[key];
79
79
  const temporary = `${target}.${crypto.randomUUID()}.tmp`;
80
- const text = stringify(entries);
81
- await (async () => {
82
- await Fs.writeFile(temporary, text, { mode: 384 });
83
- await check();
84
- await Fs.rename(temporary, target);
85
- })().catch(async (error) => {
86
- await Fs.rm(temporary, { force: true }).catch(() => void 0);
87
- await check();
80
+ await Fs.writeFile(temporary, stringify(entries), {
81
+ mode: 384
82
+ });
83
+ await check().catch(async (error) => {
84
+ await Fs.rm(temporary, { force: true });
88
85
  throw error;
89
86
  });
87
+ await Fs.rename(temporary, target);
90
88
  return await check().then(
91
89
  () => result,
92
90
  () => void 0
@@ -204,23 +202,6 @@ async function takeOver(lock, options) {
204
202
  await Fs.link(moved, lock).catch(() => void 0);
205
203
  await Fs.rm(moved, { force: true });
206
204
  }
207
- async function sweep(target) {
208
- const { Fs, Path } = node();
209
- const folder = Path.dirname(target);
210
- const names = await Fs.readdir(folder).catch(() => []);
211
- const prefix = `${Path.basename(target)}.`;
212
- await Promise.all(
213
- names.filter(
214
- (name) => name.startsWith(prefix) && temporaryName.test(name.slice(prefix.length))
215
- ).map(async (name) => {
216
- const file = Path.join(folder, name);
217
- const stat = await Fs.stat(file).catch(() => void 0);
218
- if (stat && Date.now() - stat.mtimeMs > staleLock)
219
- await Fs.rm(file, { force: true }).catch(() => void 0);
220
- })
221
- );
222
- }
223
- var temporaryName = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\.tmp$/;
224
205
  var staleLock = 1e4;
225
206
  export {
226
207
  InvalidFileError,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  InvalidError
3
3
  } from "./chunk-2T7V6ASK.js";
4
- import "./chunk-VNORMO3B.js";
4
+ import "./chunk-4GPVTVJG.js";
5
5
  import {
6
6
  authPath,
7
7
  basePath,
@@ -9,10 +9,8 @@ import {
9
9
  } from "./chunk-FWGE6HXK.js";
10
10
  import {
11
11
  PendingNotFoundError,
12
- RequestError,
13
- key,
14
- siwe
15
- } from "./chunk-KWKSUZOG.js";
12
+ RequestError
13
+ } from "./chunk-PGTIKJYS.js";
16
14
  import "./chunk-FHXDPKTL.js";
17
15
  import "./chunk-MLKGABMK.js";
18
16
 
@@ -51,13 +49,6 @@ function get(request, options) {
51
49
  }
52
50
  return void 0;
53
51
  }
54
- function bearer(request) {
55
- const [scheme, value] = (request.headers.get("authorization") ?? "").split(
56
- " "
57
- );
58
- if (scheme?.toLowerCase() !== "bearer" || !value) return void 0;
59
- return /^[\w-]{43}$/.test(value) ? value : void 0;
60
- }
61
52
  function list(request, options) {
62
53
  const header = request.headers.get("cookie");
63
54
  if (!header) return [];
@@ -111,15 +102,8 @@ var relayScript = `(() => {
111
102
  setTimeout(() => location.replace('/?error=invalid_request'), 500)
112
103
  })()`;
113
104
  function create(options) {
114
- const { backend, siwe: siwe2 } = options;
115
- const operations = backend[key];
105
+ const { backend, siwe } = options;
116
106
  const base = (options.basePath ?? "").replace(/\/+$/, "");
117
- const settings = siwe2?.[siwe];
118
- const token = settings?.token === true;
119
- const pageOrigins = token ? settings?.origins : void 0;
120
- function bearer2(request) {
121
- return token ? bearer(request) : void 0;
122
- }
123
107
  function redirectUri(request) {
124
108
  return options.redirectUri ?? `${new URL(request.url).origin}${base}/callback`;
125
109
  }
@@ -280,11 +264,7 @@ function create(options) {
280
264
  const { id } = options2;
281
265
  const session2 = await (async () => {
282
266
  try {
283
- return await operations.complete({
284
- id,
285
- replace: () => replace(request, { id }),
286
- url: options2.url
287
- });
267
+ return await backend.complete({ id, url: options2.url });
288
268
  } catch (error) {
289
269
  if (error instanceof PendingNotFoundError)
290
270
  return { stale: true };
@@ -293,6 +273,7 @@ function create(options) {
293
273
  }
294
274
  })();
295
275
  if ("refusal" in session2 || "stale" in session2) return session2;
276
+ await replace(request, { id });
296
277
  return { id, session: session2 };
297
278
  }
298
279
  async function replace(request, options2) {
@@ -305,11 +286,10 @@ function create(options) {
305
286
  ).catch(() => void 0);
306
287
  }
307
288
  async function siweChallenge(request, actions) {
308
- const refusal = foreign(request, { origins: pageOrigins });
289
+ const refusal = foreign(request);
309
290
  if (refusal) return refusal;
310
291
  const body = await request.json().catch(() => void 0);
311
292
  const address = body?.address;
312
- const chainId = body?.chainId;
313
293
  if (address !== void 0 && (typeof address !== "string" || !Address.validate(address, { strict: false })))
314
294
  return Response.json(
315
295
  {
@@ -318,32 +298,17 @@ function create(options) {
318
298
  },
319
299
  { status: 400 }
320
300
  );
321
- if (chainId !== void 0 && (typeof chainId !== "number" || !Number.isSafeInteger(chainId)))
322
- return Response.json(
323
- {
324
- error: "invalid_request",
325
- error_description: "Invalid body: `chainId` is not a chain ID. Send the ID of the chain to sign in on, or no `chainId`."
326
- },
327
- { status: 400 }
328
- );
329
- const started = await actions.start({ address, chainId, request }).catch((error) => {
301
+ const started = await actions.start({ address, request }).catch((error) => {
330
302
  if (invalid(error)) return error;
331
303
  throw error;
332
304
  });
333
- if ("reason" in started) {
334
- if (started.reason === "chain")
335
- return Response.json(
336
- { error: "invalid_request", error_description: started.message },
337
- { status: 400 }
338
- );
305
+ if ("reason" in started)
339
306
  return Response.json(
340
307
  { error: "forbidden", error_description: started.message },
341
308
  { status: 403 }
342
309
  );
343
- }
344
310
  const { id, message } = started;
345
311
  const headers = new Headers({ "cache-control": "no-store" });
346
- if (token) return Response.json({ id, message }, { headers });
347
312
  headers.append(
348
313
  "set-cookie",
349
314
  serialize({
@@ -355,39 +320,27 @@ function create(options) {
355
320
  return Response.json({ message }, { headers });
356
321
  }
357
322
  async function siweVerify(request, actions) {
358
- const refusal = foreign(request, { origins: pageOrigins });
323
+ const refusal = foreign(request);
359
324
  if (refusal) return refusal;
360
325
  const body = await request.json().catch(() => void 0);
361
- const { address, keyAuthorization, message, signature } = body ?? {};
362
- const proof = (() => {
363
- if (typeof signature === "string" && Hex.validate(signature))
364
- return { signature };
365
- if (typeof keyAuthorization === "object" && keyAuthorization !== null && !Array.isArray(keyAuthorization))
366
- return {
367
- keyAuthorization,
368
- request
369
- };
370
- return void 0;
371
- })();
372
- if (token && typeof body?.id !== "string" || typeof address !== "string" || typeof message !== "string" || !proof || !Address.validate(address, { strict: false }))
326
+ const { address, message, signature } = body ?? {};
327
+ if (typeof address !== "string" || typeof message !== "string" || typeof signature !== "string" || !Address.validate(address, { strict: false }) || !Hex.validate(signature))
373
328
  return Response.json(
374
329
  {
375
330
  error: "invalid_request",
376
- error_description: token ? "Invalid body: send the challenge\u2019s `id`, the signed message as `message`, its signature as `signature` or the key authorization that binds it as `keyAuthorization`, and the address of the account that signed as `address`." : "Invalid body: send the signed message as `message`, its signature as `signature` or the key authorization that binds it as `keyAuthorization`, and the address of the account that signed as `address`."
331
+ error_description: "Invalid body: send the signed message as `message`, its signature as `signature`, and the address of the account that signed as `address`."
377
332
  },
378
333
  { status: 400 }
379
334
  );
380
- const headers = new Headers({ "cache-control": "no-store" });
381
- if (!token)
382
- headers.set(
383
- "set-cookie",
384
- serialize({ name: names.siwe })
385
- );
386
- const id = token ? body?.id : get(request, { name: names.siwe });
335
+ const headers = new Headers({
336
+ "cache-control": "no-store",
337
+ "set-cookie": serialize({ name: names.siwe })
338
+ });
339
+ const id = get(request, { name: names.siwe });
387
340
  const session2 = await (async () => {
388
341
  if (!id) return void 0;
389
342
  try {
390
- return await actions.complete({ address, id, message, ...proof });
343
+ return await actions.complete({ address, id, message, signature });
391
344
  } catch (error) {
392
345
  if (invalid(error)) return error;
393
346
  throw error;
@@ -403,22 +356,14 @@ function create(options) {
403
356
  { headers, status: signer ? 403 : 400 }
404
357
  );
405
358
  }
406
- if (token)
407
- return Response.json(
408
- { session: pageSession(session2), token: session2.id },
409
- { headers }
410
- );
411
359
  await replace(request, { id: session2.id });
412
360
  headers.append("set-cookie", sessionCookie(session2));
413
361
  return Response.json({ session: pageSession(session2) }, { headers });
414
362
  }
415
363
  async function logout(request) {
416
- const held = bearer2(request);
417
- const refusal = foreign(request, {
418
- origins: held ? pageOrigins : void 0
419
- });
364
+ const refusal = foreign(request);
420
365
  if (refusal) return refusal;
421
- const id = get(request, { name: names.session }) ?? held;
366
+ const id = get(request, { name: names.session });
422
367
  const headers = new Headers({
423
368
  "set-cookie": serialize({
424
369
  name: names.session
@@ -474,25 +419,20 @@ function create(options) {
474
419
  return new Response(null, { headers, status: 200 });
475
420
  }
476
421
  async function session(request) {
477
- const cookie = get(request, {
478
- name: names.session
479
- });
480
- const held = cookie ? void 0 : bearer2(request);
481
- const id = cookie ?? held;
482
- const read2 = id ? await backend.get({ id }).catch((error) => {
422
+ const id = get(request, { name: names.session });
423
+ const current = id ? await backend.get({ id }).catch((error) => {
483
424
  if (error instanceof RequestError) return error;
484
425
  throw error;
485
426
  }) : void 0;
486
- const current = held && (read2 instanceof RequestError || read2?.method !== "siwe") ? void 0 : read2;
487
427
  const headers = new Headers({ "cache-control": "no-store" });
488
428
  if (current instanceof RequestError && transient(current))
489
429
  return Response.json(
490
430
  { error: "temporarily_unavailable" },
491
431
  { headers, status: 503 }
492
432
  );
493
- if (cookie && current instanceof RequestError)
494
- await backend.end({ id: cookie }).catch(() => void 0);
495
- if (cookie && (!current || current instanceof RequestError))
433
+ if (id && current instanceof RequestError)
434
+ await backend.end({ id }).catch(() => void 0);
435
+ if (id && (!current || current instanceof RequestError))
496
436
  headers.set(
497
437
  "set-cookie",
498
438
  serialize({ name: names.session })
@@ -510,53 +450,26 @@ function create(options) {
510
450
  [`${base}/login`]: { GET: login, POST: dialogLogin },
511
451
  [`${base}/logout`]: { POST: logout },
512
452
  [`${base}/session`]: { GET: session },
513
- ...siwe2 ? {
514
- // `siwe({ auth: '/api/auth/siwe' })` on the page posts its signature to the challenge
515
- // route's parent. `/siwe/verify` serves `dialog({ backend: true })` and earlier releases.
516
- [`${base}/siwe`]: {
517
- POST: (request) => siweVerify(request, siwe2)
518
- },
453
+ ...siwe ? {
519
454
  [`${base}/siwe/challenge`]: {
520
- POST: (request) => siweChallenge(request, siwe2)
455
+ POST: (request) => siweChallenge(request, siwe)
521
456
  },
522
457
  [`${base}/siwe/verify`]: {
523
- POST: (request) => siweVerify(request, siwe2)
458
+ POST: (request) => siweVerify(request, siwe)
524
459
  }
525
460
  } : {}
526
461
  };
527
- const shared = new Set(
528
- ["/logout", "/session", "/siwe", "/siwe/challenge", "/siwe/verify"].map(
529
- (path) => `${base}${path}`
530
- )
531
- );
532
462
  return from({
533
463
  async fetch(request) {
534
- const { pathname } = new URL(request.url);
535
- const route = routes[pathname];
464
+ const route = routes[new URL(request.url).pathname];
536
465
  if (!route) return Response.json({ error: "not_found" }, { status: 404 });
537
- const origin = request.headers.get("origin");
538
- const cors = origin && pageOrigins?.includes(origin) && shared.has(pathname) ? { "access-control-allow-origin": origin, vary: "origin" } : void 0;
539
- if (cors && request.method === "OPTIONS")
540
- return new Response(null, {
541
- headers: {
542
- ...cors,
543
- "access-control-allow-headers": "authorization, content-type, dpop",
544
- "access-control-allow-methods": Object.keys(route).join(", "),
545
- "access-control-max-age": "600"
546
- },
547
- status: 204
548
- });
549
466
  const fn = route[request.method];
550
467
  if (!fn)
551
468
  return Response.json(
552
469
  { error: "method_not_allowed" },
553
470
  { headers: { allow: Object.keys(route).join(", ") }, status: 405 }
554
471
  );
555
- const response = await fn(request);
556
- if (cors)
557
- for (const [name, value] of Object.entries(cors))
558
- response.headers.set(name, value);
559
- return response;
472
+ return fn(request);
560
473
  }
561
474
  });
562
475
  }
@@ -703,10 +616,9 @@ function decode(value) {
703
616
  return void 0;
704
617
  }
705
618
  }
706
- function foreign(request, options = {}) {
707
- const origin = request.headers.get("origin");
708
- if (origin === new URL(request.url).origin) return void 0;
709
- if (origin && options.origins?.includes(origin)) return void 0;
619
+ function foreign(request) {
620
+ if (request.headers.get("origin") === new URL(request.url).origin)
621
+ return void 0;
710
622
  return Response.json(
711
623
  {
712
624
  error: "forbidden",
@@ -836,7 +748,7 @@ function create2(options) {
836
748
  "/login",
837
749
  "/logout",
838
750
  "/session",
839
- ...options.siwe ? ["/siwe", "/siwe/challenge", "/siwe/verify"] : []
751
+ ...options.siwe ? ["/siwe/challenge", "/siwe/verify"] : []
840
752
  ].map((path) => `${auth}${path}`)
841
753
  );
842
754
  return from({
@@ -4,8 +4,8 @@ import {
4
4
  machines,
5
5
  prompt,
6
6
  waiting
7
- } from "./chunk-L3XL2S2D.js";
8
- import "./chunk-KWKSUZOG.js";
7
+ } from "./chunk-XQZWIEU4.js";
8
+ import "./chunk-PGTIKJYS.js";
9
9
  import "./chunk-FHXDPKTL.js";
10
10
  import "./chunk-MLKGABMK.js";
11
11
  export {
@@ -12,11 +12,10 @@ import {
12
12
  redemption,
13
13
  request,
14
14
  revoke,
15
- revoking,
16
15
  tempoAccount,
17
16
  tokens,
18
17
  user
19
- } from "./chunk-KWKSUZOG.js";
18
+ } from "./chunk-PGTIKJYS.js";
20
19
  import {
21
20
  __export
22
21
  } from "./chunk-MLKGABMK.js";
@@ -264,24 +263,16 @@ async function register(auth, options = {}) {
264
263
  if (!headless)
265
264
  return result;
266
265
  const signed = registered.authorization;
267
- if (!signed)
266
+ if (!signed?.account || !Address2.isEqual(signed.account, registered.address))
268
267
  throw new RequestError({
269
268
  code: "server_error",
270
- message: `Unsupported option: Tempo ID at ${auth.url} predates \`accessKey\` on passkey registration. The passkey is registered, so sign in with it, or update Tempo ID.`,
269
+ message: signed ? "Account mismatch: Tempo ID signed the access key for another account than the new passkey. The passkey is registered, so sign in with it." : `Unsupported option: Tempo ID at ${auth.url} predates \`accessKey\` on passkey registration. The passkey is registered, so sign in with it, or update Tempo ID.`,
271
270
  status: response.status
272
271
  });
273
- const authorization2 = await revoking(auth, {
274
- body: signed,
275
- fn: () => {
276
- if (!signed.account || !Address2.isEqual(signed.account, registered.address))
277
- throw new RequestError({
278
- code: "server_error",
279
- message: "Account mismatch: Tempo ID signed the access key for another account than the new passkey. The passkey is registered, so sign in with it.",
280
- status: response.status
281
- });
282
- return authorization(signed, headless.accessKey);
283
- }
284
- });
272
+ const authorization2 = authorization(
273
+ signed,
274
+ headless.accessKey
275
+ );
285
276
  const challenged = options.challenge === void 0 || authorization2.challengeSignature ? {} : await challenge2(
286
277
  { ...auth, chainId: Number(authorization2.accessKey.chainId) },
287
278
  {
@@ -303,14 +294,15 @@ async function register(auth, options = {}) {
303
294
  }
304
295
  async function challenge2(auth, options) {
305
296
  try {
306
- const { response } = await post2(auth, {
307
- getFn: options.getFn,
308
- json: request(auth, {
309
- account: options.account,
310
- challenge: options.challenge
297
+ const body = await json(
298
+ await post2(auth, {
299
+ getFn: options.getFn,
300
+ json: request(auth, {
301
+ account: options.account,
302
+ challenge: options.challenge
303
+ })
311
304
  })
312
- });
313
- const body = await json(response);
305
+ );
314
306
  const tokens2 = "accessToken" in body.tokens ? body.tokens : tokens(body.tokens);
315
307
  if (tokens2.refreshToken)
316
308
  await revoke(auth, { refreshToken: tokens2.refreshToken }).catch(
@@ -407,7 +399,6 @@ async function sign(prepared, options) {
407
399
  async function verify(auth, options) {
408
400
  const { assertion, getFn, prepared } = options;
409
401
  const chain = prepared.request.accessKey?.chainId ?? prepared.request.chainId;
410
- const sentAt = Date.now();
411
402
  const body = await read(
412
403
  await post(offline(auth), "/v1/auth/passkey/verify", {
413
404
  // The prepared authorization's code redeems in the same request.
@@ -424,8 +415,7 @@ async function verify(auth, options) {
424
415
  accessKey: prepared.accessKey,
425
416
  authorize: prepared.authorize,
426
417
  body,
427
- request: prepared.request,
428
- sentAt
418
+ request: prepared.request
429
419
  });
430
420
  if (!body.tempo) return authorization2;
431
421
  const [first] = body.tempo;
@@ -19,7 +19,7 @@ import {
19
19
  tokens,
20
20
  url,
21
21
  user
22
- } from "./chunk-KWKSUZOG.js";
22
+ } from "./chunk-PGTIKJYS.js";
23
23
  import {
24
24
  __export
25
25
  } from "./chunk-MLKGABMK.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  handleCallback,
3
3
  handleResult
4
- } from "./chunk-VNORMO3B.js";
4
+ } from "./chunk-4GPVTVJG.js";
5
5
  import {
6
6
  create,
7
7
  prompt,
8
8
  waiting
9
- } from "./chunk-L3XL2S2D.js";
9
+ } from "./chunk-XQZWIEU4.js";
10
10
  import {
11
11
  authPath,
12
12
  basePath
@@ -15,7 +15,6 @@ import {
15
15
  RequestError,
16
16
  activated,
17
17
  authorizeUrl,
18
- challengeParameters,
19
18
  challengeSignature,
20
19
  coinflow,
21
20
  error2 as error,
@@ -29,9 +28,8 @@ import {
29
28
  pushes,
30
29
  register,
31
30
  resources,
32
- revoke,
33
31
  watchPopup
34
- } from "./chunk-KWKSUZOG.js";
32
+ } from "./chunk-PGTIKJYS.js";
35
33
  import {
36
34
  __export
37
35
  } from "./chunk-MLKGABMK.js";
@@ -167,7 +165,7 @@ async function signInPage(auth, options) {
167
165
  redirectUri: options.redirectUri ?? auth.redirectUri ?? `${window.location.origin}/`,
168
166
  signal: options.signal
169
167
  }).catch(() => void 0);
170
- dropped(auth, { authorization, signal: options.signal });
168
+ options.signal?.throwIfAborted();
171
169
  return authorization;
172
170
  }
173
171
  async function signMessage(auth, options) {
@@ -205,7 +203,6 @@ async function authorize(auth, options) {
205
203
  backend,
206
204
  cancel,
207
205
  crossOriginOpenerPolicy,
208
- deferred: defers,
209
206
  mode: requested = "iframe",
210
207
  retried,
211
208
  settle,
@@ -332,24 +329,15 @@ async function authorize(auth, options) {
332
329
  let unwatch;
333
330
  let written;
334
331
  let sheet = reused;
335
- const deferred = defers === true && mode === "iframe" && typeof rest.challenge === "function";
336
- const message = deferred && typeof rest.challenge === "function" ? (async (challenge) => challenge(ending.signal))(rest.challenge) : void 0;
337
- message?.catch(() => {
338
- });
339
332
  try {
340
333
  const {
341
- pending: built,
334
+ pending,
342
335
  state,
343
336
  url: popupUrl
344
337
  } = await Promise.race([
345
338
  backend ? login(auth, backend) : (async () => authorizeUrl(auth, {
346
339
  ...rest,
347
- challenge: await (() => {
348
- if (deferred) return void 0;
349
- if (typeof rest.challenge === "function")
350
- return rest.challenge(ending.signal);
351
- return rest.challenge;
352
- })(),
340
+ challenge: typeof rest.challenge === "function" ? await rest.challenge(ending.signal) : rest.challenge,
353
341
  display: "popup",
354
342
  redirectUri,
355
343
  ...responseMode ? { responseMode } : {}
@@ -359,13 +347,11 @@ async function authorize(auth, options) {
359
347
  closed,
360
348
  replaced
361
349
  ]);
362
- const pending = deferred && built ? { ...built, challenge: true } : built;
363
- const toRequest = (url) => {
364
- const query = new URL(url).searchParams;
350
+ const request = (() => {
351
+ const query = new URL(popupUrl).searchParams;
365
352
  query.delete("display");
366
353
  return query.toString();
367
- };
368
- const request = toRequest(popupUrl);
354
+ })();
369
355
  if (mode === "iframe")
370
356
  sheet ??= create({ url: frameUrl(auth, { redirectUri }) });
371
357
  name = channel({ state });
@@ -389,29 +375,13 @@ async function authorize(auth, options) {
389
375
  onClosed: () => unblock?.(),
390
376
  origin: new URL(auth.url).origin
391
377
  });
392
- if (!sheet) return;
393
- const shown = sheet.show({
378
+ sheet?.show({
394
379
  onCallback: (callback3, funding2) => resolve({ callback: callback3, funding: funding2 }),
395
380
  onClose: () => close?.(),
396
- ...message ? { deferred: true } : { popupUrl },
381
+ popupUrl,
397
382
  request,
398
383
  timeout
399
384
  });
400
- message?.then((value) => {
401
- const url = new URL(popupUrl);
402
- for (const [name2, parameter] of Object.entries(
403
- challengeParameters(auth, {
404
- accessKey: Boolean(rest.accessKey),
405
- challenge: value
406
- })
407
- ))
408
- url.searchParams.set(name2, parameter);
409
- sheet?.challenge({
410
- id: shown,
411
- popupUrl: url.href,
412
- request: toRequest(url.href)
413
- });
414
- }, reject);
415
385
  });
416
386
  if (popup) popup.location.href = popupUrl;
417
387
  const { callback: callback2, funding } = await received;
@@ -435,27 +405,23 @@ async function authorize(auth, options) {
435
405
  closed,
436
406
  replaced
437
407
  ]);
438
- dropped(auth, { authorization: authorization2, signal });
408
+ signal?.throwIfAborted();
439
409
  return { authorization: authorization2, funding };
440
410
  }
441
411
  const callbackUrl = new URL(callback2.url);
442
412
  const ours = callbackUrl.searchParams.getAll("state").at(-1) === state;
443
413
  const denial = error(callbackUrl, { redirectUri });
444
414
  if (ours && denial) throw denial;
445
- const redemption = backend ? void 0 : handleCallback(auth, {
446
- accessKey: rest.accessKey,
447
- pending,
448
- url: callbackUrl
449
- });
450
415
  const authorization = await Promise.race([
451
- redemption ?? complete(auth, { ...backend, url: callbackUrl }),
416
+ backend ? complete(auth, { ...backend, url: callbackUrl }) : handleCallback(auth, {
417
+ accessKey: rest.accessKey,
418
+ pending,
419
+ url: callbackUrl
420
+ }),
452
421
  aborted,
453
422
  closed,
454
423
  replaced
455
- ]).catch((error2) => {
456
- if (redemption) void discard(auth, { redemption });
457
- throw error2;
458
- });
424
+ ]);
459
425
  if (settle)
460
426
  await Promise.race([
461
427
  settle(authorization, ending.signal),
@@ -463,7 +429,7 @@ async function authorize(auth, options) {
463
429
  closed,
464
430
  replaced
465
431
  ]);
466
- dropped(auth, { authorization, signal });
432
+ signal?.throwIfAborted();
467
433
  return { authorization, funding };
468
434
  } finally {
469
435
  ending.abort();
@@ -499,22 +465,6 @@ async function authorize(auth, options) {
499
465
  }
500
466
  }
501
467
  }
502
- async function discard(auth, options) {
503
- const authorization = await options.redemption.catch(() => void 0);
504
- const refreshToken = authorization?.refreshToken;
505
- if (refreshToken)
506
- await revoke(auth, { refreshToken }).catch(() => void 0);
507
- }
508
- function dropped(auth, options) {
509
- const { authorization, signal } = options;
510
- if (!signal?.aborted) return;
511
- void discard(auth, {
512
- redemption: Promise.resolve(
513
- authorization
514
- )
515
- });
516
- signal.throwIfAborted();
517
- }
518
468
  async function login(auth, options) {
519
469
  const response = await (auth.fetch ?? fetch)(
520
470
  new URL(`${options.basePath}/login`, window.location.origin),