@tempoxyz/id 0.0.0-pr-780.sha-8d933df → 0.0.0-pr-740.sha-4fa2e39
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/{Connections-IG7BPSNM.js → Connections-HU7GNZSD.js} +2 -2
- package/dist/{Server-WJMGROFK.js → Server-QLCBHQES.js} +2 -4
- package/dist/{Sheet-DRJAUI5N.js → Sheet-LKGRD5TQ.js} +2 -2
- package/dist/{chunk-VOX2P6VX.js → chunk-AB6JTZTN.js} +387 -87
- package/dist/{chunk-RUVB2W7L.js → chunk-BEATKMKY.js} +1 -1
- package/dist/{chunk-QV32ZP3X.js → chunk-OWTBY7DI.js} +1 -1
- package/dist/{chunk-DE5X2NOS.js → chunk-RUQDOQMI.js} +27 -37
- package/dist/{chunk-BMVKOTQV.js → chunk-XGQAJVTC.js} +42 -87
- package/dist/commands/login.js +5 -6
- package/dist/commands/logout.js +5 -6
- package/dist/commands/whoami.js +5 -6
- package/dist/{dialog-FRMZDXSN.js → dialog-BFWWBKI6.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-S4BQDYD2.js +0 -386
- package/dist/passkey-GBHV7C5A.js +0 -14
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
PendingNotFoundError,
|
|
8
8
|
RequestError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XGQAJVTC.js";
|
|
10
10
|
import "./chunk-MLKGABMK.js";
|
|
11
11
|
|
|
12
12
|
// ../../accounts/src/internal/handlers/Backend.ts
|
|
@@ -198,9 +198,7 @@ function create(options) {
|
|
|
198
198
|
name: names.session
|
|
199
199
|
});
|
|
200
200
|
if (previous && previous !== options2.id)
|
|
201
|
-
await backend.end({ id: previous
|
|
202
|
-
(error) => error instanceof TypeError ? backend.end({ id: previous }) : void 0
|
|
203
|
-
).catch(() => void 0);
|
|
201
|
+
await backend.end({ id: previous }).catch(() => void 0);
|
|
204
202
|
}
|
|
205
203
|
async function siweChallenge(request, actions) {
|
|
206
204
|
const refusal = foreign(request);
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bind,
|
|
3
|
-
from,
|
|
4
|
-
passkey_exports
|
|
5
|
-
} from "./chunk-S4BQDYD2.js";
|
|
6
1
|
import {
|
|
7
2
|
dialog_exports,
|
|
8
3
|
redirect_exports
|
|
9
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RUQDOQMI.js";
|
|
10
5
|
import {
|
|
11
6
|
connections_exports
|
|
12
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-BEATKMKY.js";
|
|
13
8
|
import {
|
|
14
9
|
AccessKeyRequiredError,
|
|
15
10
|
AccessKey_exports,
|
|
@@ -29,16 +24,17 @@ import {
|
|
|
29
24
|
keyAuthorization,
|
|
30
25
|
own,
|
|
31
26
|
post,
|
|
27
|
+
post2,
|
|
32
28
|
prepare,
|
|
33
29
|
read,
|
|
34
30
|
redemption,
|
|
35
31
|
redirectRefused,
|
|
36
32
|
refresh,
|
|
33
|
+
request,
|
|
37
34
|
resolve,
|
|
38
35
|
resources,
|
|
39
|
-
|
|
36
|
+
revoke,
|
|
40
37
|
signOut,
|
|
41
|
-
signedIn,
|
|
42
38
|
steps,
|
|
43
39
|
tempoAccount,
|
|
44
40
|
token,
|
|
@@ -47,7 +43,7 @@ import {
|
|
|
47
43
|
unlisted,
|
|
48
44
|
user,
|
|
49
45
|
withoutKey
|
|
50
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-XGQAJVTC.js";
|
|
51
47
|
import {
|
|
52
48
|
__export
|
|
53
49
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -109,14 +105,14 @@ async function sendCode(auth2, options) {
|
|
|
109
105
|
);
|
|
110
106
|
}
|
|
111
107
|
async function signIn(auth2, options) {
|
|
112
|
-
const { challenge, code, email, userIp } = options;
|
|
108
|
+
const { challenge: challenge2, code, email, userIp } = options;
|
|
113
109
|
authenticated(auth2);
|
|
114
110
|
const { accessKey } = options;
|
|
115
111
|
const key = accessKey ? await resolve(accessKey) : void 0;
|
|
116
112
|
const body = await token(auth2, {
|
|
117
113
|
// A challenge without an access key names the instance's chain, whose view of the account signs it.
|
|
118
|
-
...
|
|
119
|
-
...
|
|
114
|
+
...challenge2 !== void 0 && !key ? { chain_id: String(auth2.chainId) } : {},
|
|
115
|
+
...challenge2 === void 0 ? {} : { challenge: challenge2 },
|
|
120
116
|
code,
|
|
121
117
|
email,
|
|
122
118
|
grant_type: grantType,
|
|
@@ -137,7 +133,7 @@ async function signIn(auth2, options) {
|
|
|
137
133
|
if (!key)
|
|
138
134
|
return {
|
|
139
135
|
...tokens2,
|
|
140
|
-
...challengeSignature(body, { challenged:
|
|
136
|
+
...challengeSignature(body, { challenged: challenge2 !== void 0 }),
|
|
141
137
|
user: user(tokens2)
|
|
142
138
|
};
|
|
143
139
|
return authorization(
|
|
@@ -147,7 +143,7 @@ async function signIn(auth2, options) {
|
|
|
147
143
|
key_authorization: body.key_authorization,
|
|
148
144
|
tokens: tokens2
|
|
149
145
|
},
|
|
150
|
-
{ ...key, challenged:
|
|
146
|
+
{ ...key, challenged: challenge2 !== void 0 }
|
|
151
147
|
);
|
|
152
148
|
}
|
|
153
149
|
function authenticated(auth2) {
|
|
@@ -206,47 +202,33 @@ async function authorize2(auth2, options) {
|
|
|
206
202
|
});
|
|
207
203
|
})
|
|
208
204
|
);
|
|
209
|
-
|
|
210
|
-
async function wait(options2 = {}) {
|
|
211
|
-
const { signal } = options2;
|
|
212
|
-
const aborted = () => signal?.reason ?? Object.assign(new Error("The wait was aborted."), { name: "AbortError" });
|
|
205
|
+
async function wait() {
|
|
213
206
|
let interval = code.interval;
|
|
214
207
|
let backoff = 1;
|
|
215
208
|
let failure;
|
|
216
209
|
const deadline = Date.now() + code.expires_in * 1e3;
|
|
217
210
|
const poll2 = answered2(auth2);
|
|
218
211
|
while (Date.now() < deadline) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
clearTimeout(timer);
|
|
223
|
-
reject(aborted());
|
|
224
|
-
};
|
|
225
|
-
const timer = setTimeout(
|
|
226
|
-
() => {
|
|
227
|
-
signal?.removeEventListener("abort", abort);
|
|
228
|
-
resolve2();
|
|
229
|
-
},
|
|
212
|
+
await new Promise(
|
|
213
|
+
(resolve2) => setTimeout(
|
|
214
|
+
resolve2,
|
|
230
215
|
Math.min(interval * backoff * 1e3, deadline - Date.now())
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
});
|
|
216
|
+
)
|
|
217
|
+
);
|
|
234
218
|
failure = void 0;
|
|
235
|
-
const result = await
|
|
236
|
-
challenged,
|
|
219
|
+
const result = await request2(poll2, {
|
|
220
|
+
challenged: options.challenge !== void 0,
|
|
237
221
|
deviceCode: code.device_code,
|
|
238
222
|
key
|
|
239
223
|
}).catch((error2) => {
|
|
240
|
-
if (signal?.aborted) throw aborted();
|
|
241
224
|
if (!transient(error2)) throw error2;
|
|
242
225
|
failure = error2;
|
|
243
226
|
backoff *= 2;
|
|
244
227
|
return void 0;
|
|
245
228
|
});
|
|
246
|
-
if (result?.status === "approved") return result.authorization;
|
|
247
|
-
if (signal?.aborted) throw aborted();
|
|
248
229
|
if (!result) continue;
|
|
249
230
|
backoff = 1;
|
|
231
|
+
if (result.status === "approved") return result.authorization;
|
|
250
232
|
if (result.slowDown) interval += 5;
|
|
251
233
|
}
|
|
252
234
|
throw new RequestError({
|
|
@@ -270,7 +252,7 @@ async function poll(auth2, options) {
|
|
|
270
252
|
const { deviceCode } = options;
|
|
271
253
|
const challenged = options.challenged ?? options.accessKey === false;
|
|
272
254
|
if (options.accessKey === false)
|
|
273
|
-
return
|
|
255
|
+
return request2(
|
|
274
256
|
answered2(auth2),
|
|
275
257
|
{
|
|
276
258
|
challenged,
|
|
@@ -280,7 +262,7 @@ async function poll(auth2, options) {
|
|
|
280
262
|
);
|
|
281
263
|
const accessKey = own(options.accessKey);
|
|
282
264
|
if (!accessKey) throw new AccessKeyRequiredError();
|
|
283
|
-
return
|
|
265
|
+
return request2(
|
|
284
266
|
answered2(auth2),
|
|
285
267
|
{
|
|
286
268
|
challenged,
|
|
@@ -289,7 +271,7 @@ async function poll(auth2, options) {
|
|
|
289
271
|
}
|
|
290
272
|
);
|
|
291
273
|
}
|
|
292
|
-
async function
|
|
274
|
+
async function request2(auth2, options) {
|
|
293
275
|
const { deviceCode, key } = options;
|
|
294
276
|
const body = await token(auth2, {
|
|
295
277
|
device_code: deviceCode,
|
|
@@ -360,22 +342,51 @@ __export(email_exports2, {
|
|
|
360
342
|
signIn: () => signIn2
|
|
361
343
|
});
|
|
362
344
|
import { Authentication } from "ox/webauthn";
|
|
345
|
+
|
|
346
|
+
// ../../accounts/src/internal/Registration.ts
|
|
347
|
+
var lifetime = 4 * 60 * 1e3;
|
|
348
|
+
function from(value, options) {
|
|
349
|
+
return {
|
|
350
|
+
expiresAt: options.requestedAt + lifetime,
|
|
351
|
+
options: value.options,
|
|
352
|
+
...value.proof ? { proof: value.proof } : {}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
var sent = /* @__PURE__ */ new WeakSet();
|
|
356
|
+
function send(registration) {
|
|
357
|
+
sent.add(registration);
|
|
358
|
+
}
|
|
359
|
+
function usable(registration) {
|
|
360
|
+
return registration !== void 0 && registration.expiresAt > Date.now() && !sent.has(registration);
|
|
361
|
+
}
|
|
362
|
+
async function request3(auth2, options = {}) {
|
|
363
|
+
const { authorize: authorize3 } = options;
|
|
364
|
+
const requestedAt = Date.now();
|
|
365
|
+
const requested = await json(
|
|
366
|
+
await post(auth2, "/v1/account/passkey/options", {
|
|
367
|
+
json: authorize3 ? { authorize: authorize3 } : {}
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
return from(requested, { requestedAt });
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// ../../accounts/src/actions/email.ts
|
|
363
374
|
async function sendCode2(auth2, options) {
|
|
364
|
-
const
|
|
375
|
+
const offline2 = answered(auth2, {
|
|
365
376
|
message: "The code request received no response. Check the connection, and request the code again."
|
|
366
377
|
});
|
|
367
|
-
await json(await post(
|
|
378
|
+
await json(await post(offline2, "/v1/auth/code", { json: options }));
|
|
368
379
|
}
|
|
369
380
|
async function signIn2(auth2, options) {
|
|
370
|
-
const { code,
|
|
381
|
+
const { code, email, getFn, link } = options;
|
|
371
382
|
const prepared = await prepare(auth2, options);
|
|
372
|
-
const
|
|
383
|
+
const offline2 = answered(auth2, {
|
|
373
384
|
message: "The sign-in received no response. Check the connection, and sign in again. If the code is refused, request a new code."
|
|
374
385
|
});
|
|
375
386
|
const assertion = await (async () => {
|
|
376
387
|
if (!link) return void 0;
|
|
377
388
|
const requested = await json(
|
|
378
|
-
await post(
|
|
389
|
+
await post(offline2, "/v1/auth/passkey/options", {
|
|
379
390
|
json: { authorize: prepared.authorize, client_id: auth2.clientId, link }
|
|
380
391
|
})
|
|
381
392
|
);
|
|
@@ -389,11 +400,11 @@ async function signIn2(auth2, options) {
|
|
|
389
400
|
})();
|
|
390
401
|
const requestedAt = Date.now();
|
|
391
402
|
const chain = options.accessKey?.chainId ?? options.chainId;
|
|
392
|
-
const
|
|
403
|
+
const send2 = async (withChain) => (
|
|
393
404
|
// The sign-in authorizes in the same request, after the code signed the user in. `key` decides
|
|
394
405
|
// both the type and the runtime value of the result.
|
|
395
406
|
read(
|
|
396
|
-
await post(
|
|
407
|
+
await post(offline2, "/v1/auth/code/verify", {
|
|
397
408
|
// The sign-in carries the authorization, whose code Tempo ID redeems in the same request.
|
|
398
409
|
headers: await redemption(auth2),
|
|
399
410
|
json: {
|
|
@@ -412,44 +423,13 @@ async function signIn2(auth2, options) {
|
|
|
412
423
|
);
|
|
413
424
|
const { body, unlisted: unlisted2 } = await (async () => {
|
|
414
425
|
try {
|
|
415
|
-
return { body: await
|
|
426
|
+
return { body: await send2(true), unlisted: false };
|
|
416
427
|
} catch (error2) {
|
|
417
428
|
if (!(error2 instanceof RequestError) || error2.signedIn || !unlisted(error2, { field: "account.chain" }))
|
|
418
429
|
throw error2;
|
|
419
|
-
return { body: await
|
|
430
|
+
return { body: await send2(false), unlisted: true };
|
|
420
431
|
}
|
|
421
432
|
})();
|
|
422
|
-
if (body.passkey_wallet && body.registration && prepared.key && options.accessKey) {
|
|
423
|
-
const { register } = await import("./passkey-GBHV7C5A.js");
|
|
424
|
-
const registered = await register(auth2, {
|
|
425
|
-
accessKey: { ...options.accessKey, account: prepared.key.accessKey },
|
|
426
|
-
challenge: options.challenge,
|
|
427
|
-
createFn,
|
|
428
|
-
getFn,
|
|
429
|
-
registration: bind(
|
|
430
|
-
from(body.registration, { requestedAt })
|
|
431
|
-
)
|
|
432
|
-
}).catch(
|
|
433
|
-
(error2) => (
|
|
434
|
-
// A dismissed or failed ceremony leaves the new user signed in without an account.
|
|
435
|
-
signedIn(error2, {
|
|
436
|
-
message: "Passkey wallet registration failed after the sign-in, such as a dismissed prompt. The user holds no account yet, so sign in again with a new code to create the passkey."
|
|
437
|
-
})
|
|
438
|
-
)
|
|
439
|
-
);
|
|
440
|
-
const { authorization: authorization3 } = registered;
|
|
441
|
-
if (authorization3.user.id !== body.user.id)
|
|
442
|
-
signedIn(sessionChanged());
|
|
443
|
-
return {
|
|
444
|
-
...authorization3,
|
|
445
|
-
// The registration received the generated access key by its account alone, so the key takes
|
|
446
|
-
// back that key's material, which the session stores to sign.
|
|
447
|
-
key: { ...authorization3.key, ...prepared.key.material },
|
|
448
|
-
account: void 0,
|
|
449
|
-
accounts: [],
|
|
450
|
-
...registered.challengeError ? { challengeError: registered.challengeError } : {}
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
433
|
const authorization2 = await complete(auth2, {
|
|
454
434
|
body,
|
|
455
435
|
authorize: prepared.authorize,
|
|
@@ -545,6 +525,326 @@ async function userInfo(auth2, options) {
|
|
|
545
525
|
return { email: claims.email, id: claims.sub };
|
|
546
526
|
}
|
|
547
527
|
|
|
528
|
+
// ../../accounts/src/actions/passkey.ts
|
|
529
|
+
var passkey_exports = {};
|
|
530
|
+
__export(passkey_exports, {
|
|
531
|
+
available: () => available,
|
|
532
|
+
prepare: () => prepare2,
|
|
533
|
+
register: () => register,
|
|
534
|
+
signIn: () => signIn3
|
|
535
|
+
});
|
|
536
|
+
import { Address } from "ox";
|
|
537
|
+
import {
|
|
538
|
+
Authentication as Authentication2,
|
|
539
|
+
Credential,
|
|
540
|
+
Registration
|
|
541
|
+
} from "ox/webauthn";
|
|
542
|
+
async function available(auth2) {
|
|
543
|
+
const response = await (auth2.fetch ?? fetch)(
|
|
544
|
+
new URL(
|
|
545
|
+
`/v1/realms?${new URLSearchParams({ client_id: auth2.clientId })}`,
|
|
546
|
+
auth2.url
|
|
547
|
+
)
|
|
548
|
+
).catch(() => void 0);
|
|
549
|
+
if (!response) return false;
|
|
550
|
+
const body = await json(
|
|
551
|
+
response
|
|
552
|
+
).catch(() => void 0);
|
|
553
|
+
return body?.passkeys === true;
|
|
554
|
+
}
|
|
555
|
+
var preparedLifetime = 4 * 60 * 1e3;
|
|
556
|
+
function prepare2(auth2, options = {}) {
|
|
557
|
+
const ready = options.available === void 0 ? available(auth2).catch(() => false) : Promise.resolve(options.available);
|
|
558
|
+
const ahead = () => ready.then(
|
|
559
|
+
(passkeys) => passkeys ? requestOptions(auth2, options) : void 0
|
|
560
|
+
).catch(() => void 0);
|
|
561
|
+
let pending = ahead();
|
|
562
|
+
return {
|
|
563
|
+
available: ready,
|
|
564
|
+
async signIn(signInOptions = {}) {
|
|
565
|
+
const taken = pending;
|
|
566
|
+
pending = void 0;
|
|
567
|
+
const entry = await taken;
|
|
568
|
+
const prepared = entry && entry.expiresAt > Date.now() ? entry : await requestOptions(auth2, options);
|
|
569
|
+
const assertion = await sign(prepared, signInOptions).catch(
|
|
570
|
+
(error2) => {
|
|
571
|
+
pending ??= Promise.resolve(prepared);
|
|
572
|
+
throw error2;
|
|
573
|
+
}
|
|
574
|
+
);
|
|
575
|
+
return await verify(auth2, {
|
|
576
|
+
assertion,
|
|
577
|
+
getFn: signInOptions.getFn,
|
|
578
|
+
prepared
|
|
579
|
+
}).catch((error2) => {
|
|
580
|
+
pending ??= ahead();
|
|
581
|
+
throw error2;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
async function register(auth2, options = {}) {
|
|
587
|
+
const { createFn, getFn, key } = options;
|
|
588
|
+
if (options.challenge !== void 0 && !options.accessKey)
|
|
589
|
+
throw new RequestError({
|
|
590
|
+
code: "invalid_request",
|
|
591
|
+
field: "challenge",
|
|
592
|
+
message: "Invalid options: `challenge` signs as the new passkey's account, which only a registration with `accessKey` selects. Pass `accessKey`, or sign in with the challenge.",
|
|
593
|
+
status: 0
|
|
594
|
+
});
|
|
595
|
+
const chain = options.chain ?? options.chainId;
|
|
596
|
+
if (options.accessKey && (key || options.account !== void 0 || chain !== void 0))
|
|
597
|
+
throw new RequestError({
|
|
598
|
+
code: "invalid_request",
|
|
599
|
+
field: "accessKey",
|
|
600
|
+
message: "Invalid options: `accessKey` signs for the account that the new passkey owns, which joins no account. Pass `accessKey` without `account`, `chain`, `chainId`, or `key`.",
|
|
601
|
+
status: 0
|
|
602
|
+
});
|
|
603
|
+
const headless = options.accessKey ? await prepare(auth2, { accessKey: options.accessKey }) : void 0;
|
|
604
|
+
const prepared = !headless && options.registration && usable(options.registration) ? options.registration : await request3(answered(auth2, unregistered), {
|
|
605
|
+
authorize: headless?.authorize
|
|
606
|
+
});
|
|
607
|
+
if (key && !prepared.proof && (options.account === void 0 || chain === void 0))
|
|
608
|
+
throw new RequestError({
|
|
609
|
+
code: "invalid_request",
|
|
610
|
+
field: "key",
|
|
611
|
+
message: `Unsupported option: Tempo ID at ${auth2.url} predates \`key\` on passkey registration. Pass \`account\` and \`chain\` in its place, or update Tempo ID.`,
|
|
612
|
+
status: 0
|
|
613
|
+
});
|
|
614
|
+
const deserialized = Registration.deserializeOptions(prepared.options);
|
|
615
|
+
const credential = Credential.serialize(
|
|
616
|
+
await Registration.create(
|
|
617
|
+
// ox reads `createFn` beside creation options at runtime, which its types admit only beside flat options.
|
|
618
|
+
createFn ? { ...deserialized, createFn } : deserialized
|
|
619
|
+
)
|
|
620
|
+
);
|
|
621
|
+
const created = {
|
|
622
|
+
credentialId: credential.id,
|
|
623
|
+
rpId: prepared.options.publicKey.rp.id
|
|
624
|
+
};
|
|
625
|
+
const assertion = await (async () => {
|
|
626
|
+
try {
|
|
627
|
+
const proof = await (async () => {
|
|
628
|
+
if (prepared.proof)
|
|
629
|
+
return Authentication2.deserializeOptions({
|
|
630
|
+
publicKey: {
|
|
631
|
+
...prepared.proof.options.publicKey,
|
|
632
|
+
allowCredentials: [{ id: credential.id, type: "public-key" }]
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
send(prepared);
|
|
636
|
+
const { step } = await json(
|
|
637
|
+
await post(
|
|
638
|
+
answered(auth2, unregistered),
|
|
639
|
+
"/v1/account/passkey",
|
|
640
|
+
{
|
|
641
|
+
json: { credential }
|
|
642
|
+
}
|
|
643
|
+
)
|
|
644
|
+
);
|
|
645
|
+
return Authentication2.deserializeOptions(step.options);
|
|
646
|
+
})();
|
|
647
|
+
return Authentication2.serializeResponse(
|
|
648
|
+
await Authentication2.sign(
|
|
649
|
+
// ox reads `getFn` beside request options at runtime, which its types admit only beside a challenge.
|
|
650
|
+
getFn ? { ...proof, getFn } : proof
|
|
651
|
+
)
|
|
652
|
+
);
|
|
653
|
+
} catch (error2) {
|
|
654
|
+
forget(created);
|
|
655
|
+
throw error2;
|
|
656
|
+
}
|
|
657
|
+
})();
|
|
658
|
+
if (prepared.proof) send(prepared);
|
|
659
|
+
const response = await post(
|
|
660
|
+
answered(auth2, {
|
|
661
|
+
message: "The registration received no response, and the passkey can be registered. Check the connection, then sign in with the passkey or register it again."
|
|
662
|
+
}),
|
|
663
|
+
"/v1/account/passkey/verify",
|
|
664
|
+
{
|
|
665
|
+
// The authorization's code redeems in the same request.
|
|
666
|
+
...headless ? { headers: await redemption(auth2) } : {},
|
|
667
|
+
json: {
|
|
668
|
+
...options.account ? { account: options.account } : {},
|
|
669
|
+
assertion,
|
|
670
|
+
...chain !== void 0 ? { chain } : {},
|
|
671
|
+
...prepared.proof ? { credential } : {},
|
|
672
|
+
...key ? { accessKey: { account: key.account, chainId: key.chainId } } : {}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
const registered = await (async () => {
|
|
677
|
+
try {
|
|
678
|
+
return await json(response);
|
|
679
|
+
} catch (error2) {
|
|
680
|
+
const dropped = prepared.proof ? response.headers.get(storedHeader) !== "true" && error2 instanceof RequestError && error2.reason !== void 0 : refused(error2);
|
|
681
|
+
if (dropped) forget(created);
|
|
682
|
+
throw error2;
|
|
683
|
+
}
|
|
684
|
+
})();
|
|
685
|
+
const result = { address: registered.address, id: registered.id };
|
|
686
|
+
if (!headless) return result;
|
|
687
|
+
const signed = registered.authorization;
|
|
688
|
+
if (!signed?.account || !Address.isEqual(signed.account, registered.address))
|
|
689
|
+
throw new RequestError({
|
|
690
|
+
code: "server_error",
|
|
691
|
+
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 ${auth2.url} predates \`accessKey\` on passkey registration. The passkey is registered, so sign in with it, or update Tempo ID.`,
|
|
692
|
+
status: response.status
|
|
693
|
+
});
|
|
694
|
+
const authorization2 = authorization(
|
|
695
|
+
signed,
|
|
696
|
+
headless.key
|
|
697
|
+
);
|
|
698
|
+
const challenged = options.challenge === void 0 ? {} : await challenge(
|
|
699
|
+
{ ...auth2, chainId: Number(authorization2.key.chainId) },
|
|
700
|
+
{
|
|
701
|
+
account: registered.address,
|
|
702
|
+
challenge: options.challenge,
|
|
703
|
+
getFn,
|
|
704
|
+
userId: authorization2.user.id
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
return {
|
|
708
|
+
...result,
|
|
709
|
+
authorization: {
|
|
710
|
+
...authorization2,
|
|
711
|
+
..."challengeError" in challenged ? {} : challenged,
|
|
712
|
+
upgradeAvailable: signed.upgrade_available === true
|
|
713
|
+
},
|
|
714
|
+
..."challengeError" in challenged ? { challengeError: challenged.challengeError } : {}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
async function challenge(auth2, options) {
|
|
718
|
+
try {
|
|
719
|
+
const body = await json(
|
|
720
|
+
await post2(auth2, {
|
|
721
|
+
getFn: options.getFn,
|
|
722
|
+
json: request(auth2, {
|
|
723
|
+
account: options.account,
|
|
724
|
+
challenge: options.challenge
|
|
725
|
+
})
|
|
726
|
+
})
|
|
727
|
+
);
|
|
728
|
+
const tokens2 = "accessToken" in body.tokens ? body.tokens : tokens(body.tokens);
|
|
729
|
+
if (tokens2.refreshToken)
|
|
730
|
+
await revoke(auth2, { refreshToken: tokens2.refreshToken }).catch(
|
|
731
|
+
() => void 0
|
|
732
|
+
);
|
|
733
|
+
const signed = challengeSignature(body, { challenged: true });
|
|
734
|
+
if (user(tokens2).id !== options.userId || !Address.isEqual(signed.address, options.account))
|
|
735
|
+
throw new RequestError({
|
|
736
|
+
code: "server_error",
|
|
737
|
+
message: "Account mismatch: Tempo ID signed the challenge as another account or user than the new passkey's. The passkey is registered, so sign in with it and the challenge.",
|
|
738
|
+
status: 200
|
|
739
|
+
});
|
|
740
|
+
return signed;
|
|
741
|
+
} catch (error2) {
|
|
742
|
+
return {
|
|
743
|
+
challengeError: error2 instanceof RequestError ? error2 : new RequestError({
|
|
744
|
+
cause: error2,
|
|
745
|
+
code: "server_error",
|
|
746
|
+
message: "Challenge signature failed after the registration, with no response from Tempo ID. The passkey is registered, so sign in with it and the challenge.",
|
|
747
|
+
status: 0
|
|
748
|
+
})
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async function signIn3(auth2, options = {}) {
|
|
753
|
+
const prepared = await requestOptions(auth2, options);
|
|
754
|
+
const assertion = await sign(prepared, options);
|
|
755
|
+
return await verify(auth2, {
|
|
756
|
+
assertion,
|
|
757
|
+
getFn: options.getFn,
|
|
758
|
+
prepared
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
function forget(options) {
|
|
762
|
+
if (typeof PublicKeyCredential === "undefined") return;
|
|
763
|
+
const signal = PublicKeyCredential.signalUnknownCredential;
|
|
764
|
+
void signal?.call(PublicKeyCredential, {
|
|
765
|
+
credentialId: options.credentialId,
|
|
766
|
+
rpId: options.rpId
|
|
767
|
+
}).catch(() => {
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
var unregistered = {
|
|
771
|
+
message: "The registration received no response. Check the connection, and register the passkey again."
|
|
772
|
+
};
|
|
773
|
+
function offline(auth2) {
|
|
774
|
+
return answered(auth2, {
|
|
775
|
+
message: "The sign-in received no response. Check the connection, and sign in again."
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
var storedHeader = "Tempo-Id-Passkey-Stored";
|
|
779
|
+
function refused(error2) {
|
|
780
|
+
return error2 instanceof RequestError && error2.reason !== void 0 && error2.reason !== "config_conflict" && error2.reason !== "rate_limited" && error2.status < 500;
|
|
781
|
+
}
|
|
782
|
+
async function requestOptions(auth2, options) {
|
|
783
|
+
const { credentialId, mediation, select } = options;
|
|
784
|
+
const { authorize: authorize3, key } = await prepare(auth2, options);
|
|
785
|
+
const requestedAt = Date.now();
|
|
786
|
+
const requested = await json(
|
|
787
|
+
await post(offline(auth2), "/v1/auth/passkey/options", {
|
|
788
|
+
json: {
|
|
789
|
+
authorize: authorize3,
|
|
790
|
+
// The app's realms decide the relying party, which must cover the page's origin.
|
|
791
|
+
client_id: auth2.clientId,
|
|
792
|
+
...credentialId === void 0 ? {} : { credentialId },
|
|
793
|
+
...mediation === void 0 ? {} : { mediation },
|
|
794
|
+
...select ? { select: true } : {}
|
|
795
|
+
}
|
|
796
|
+
})
|
|
797
|
+
);
|
|
798
|
+
return {
|
|
799
|
+
authorize: authorize3,
|
|
800
|
+
expiresAt: requestedAt + preparedLifetime,
|
|
801
|
+
key,
|
|
802
|
+
options: Authentication2.deserializeOptions(requested.options),
|
|
803
|
+
request: options
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
async function sign(prepared, options) {
|
|
807
|
+
const { getFn } = options;
|
|
808
|
+
return Authentication2.serializeResponse(
|
|
809
|
+
await Authentication2.sign(
|
|
810
|
+
// ox reads `getFn` beside request options at runtime, which its types admit only beside a challenge.
|
|
811
|
+
getFn ? { ...prepared.options, getFn } : prepared.options
|
|
812
|
+
)
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
async function verify(auth2, options) {
|
|
816
|
+
const { assertion, getFn, prepared } = options;
|
|
817
|
+
const chain = prepared.request.accessKey?.chainId ?? prepared.request.chainId;
|
|
818
|
+
const body = await read(
|
|
819
|
+
await post(offline(auth2), "/v1/auth/passkey/verify", {
|
|
820
|
+
// The prepared authorization's code redeems in the same request.
|
|
821
|
+
headers: await redemption(auth2),
|
|
822
|
+
json: {
|
|
823
|
+
assertion,
|
|
824
|
+
...prepared.request.account === false ? { tempo: false } : chain !== void 0 ? { account: { chain } } : {}
|
|
825
|
+
}
|
|
826
|
+
})
|
|
827
|
+
);
|
|
828
|
+
if ("step" in body)
|
|
829
|
+
return { step: { link: body.step.link, type: body.step.type } };
|
|
830
|
+
const authorization2 = await complete(auth2, {
|
|
831
|
+
authorize: prepared.authorize,
|
|
832
|
+
body,
|
|
833
|
+
key: prepared.key,
|
|
834
|
+
request: prepared.request
|
|
835
|
+
});
|
|
836
|
+
if (!body.tempo) return authorization2;
|
|
837
|
+
const [first] = body.tempo;
|
|
838
|
+
const account = (() => {
|
|
839
|
+
try {
|
|
840
|
+
return first ? tempoAccount(first, { getFn }) : void 0;
|
|
841
|
+
} catch {
|
|
842
|
+
return void 0;
|
|
843
|
+
}
|
|
844
|
+
})();
|
|
845
|
+
return { ...authorization2, account };
|
|
846
|
+
}
|
|
847
|
+
|
|
548
848
|
// ../../accounts/src/actions/realm.ts
|
|
549
849
|
var realm_exports = {};
|
|
550
850
|
__export(realm_exports, {
|
|
@@ -571,11 +871,11 @@ function auth(options) {
|
|
|
571
871
|
return Accounts_exports.from({ clientId, url: options.url });
|
|
572
872
|
}
|
|
573
873
|
async function get(options) {
|
|
574
|
-
const saved = await
|
|
874
|
+
const saved = await usable2(options);
|
|
575
875
|
if (!saved) return void 0;
|
|
576
876
|
if (saved.expiresAt - 3e4 > Date.now()) return saved;
|
|
577
877
|
return await locked(options, async () => {
|
|
578
|
-
const current = await
|
|
878
|
+
const current = await usable2(options);
|
|
579
879
|
if (!current) return void 0;
|
|
580
880
|
if (current.expiresAt - 3e4 > Date.now()) return current;
|
|
581
881
|
if (!current.refreshToken) return void 0;
|
|
@@ -602,7 +902,7 @@ async function login(options) {
|
|
|
602
902
|
session: { ...authorization2, url: new URL(client.url).origin }
|
|
603
903
|
});
|
|
604
904
|
if (replaced.status === "found" && replaced.session.refreshToken && replaced.session.url)
|
|
605
|
-
await
|
|
905
|
+
await revoke2({
|
|
606
906
|
token: replaced.session.refreshToken,
|
|
607
907
|
url: replaced.session.url
|
|
608
908
|
});
|
|
@@ -631,7 +931,7 @@ async function remove(options) {
|
|
|
631
931
|
const { refreshToken, url } = read2.session;
|
|
632
932
|
if (!refreshToken) return true;
|
|
633
933
|
if (!url) return false;
|
|
634
|
-
return await
|
|
934
|
+
return await revoke2({ token: refreshToken, url });
|
|
635
935
|
})();
|
|
636
936
|
await Fs.rm(file(options), { force: true });
|
|
637
937
|
return revoked;
|
|
@@ -712,14 +1012,14 @@ async function readSession(options) {
|
|
|
712
1012
|
}
|
|
713
1013
|
);
|
|
714
1014
|
}
|
|
715
|
-
async function
|
|
1015
|
+
async function usable2(options) {
|
|
716
1016
|
const read2 = await readSession(options);
|
|
717
1017
|
const saved = read2.status === "found" ? read2.session : void 0;
|
|
718
1018
|
if (saved?.url !== new URL(auth(options).url).origin || !saved.user || !saved.key?.keyAuthorization || !saved.accessToken || AccessKey_exports.expired(saved.key))
|
|
719
1019
|
return void 0;
|
|
720
1020
|
return saved;
|
|
721
1021
|
}
|
|
722
|
-
async function
|
|
1022
|
+
async function revoke2(options) {
|
|
723
1023
|
const response = await fetch(new URL("/oauth2/revoke", options.url), {
|
|
724
1024
|
body: new URLSearchParams({
|
|
725
1025
|
client_id: clientId,
|