@tempoxyz/auth 0.0.0-pr-97.sha-4799ea2 → 0.0.0-pr-95.sha-e7c03ef
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/Actions.js +10 -1
- package/dist/actions/passkey.js +6 -1
- package/dist/internal/link.d.ts +2 -0
- package/dist/internal/link.js +5 -2
- package/package.json +1 -1
package/dist/Actions.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { Authentication } from 'ox/webauthn';
|
|
8
8
|
import * as AccessKey from './internal/accessKey.js';
|
|
9
9
|
import * as Api from './internal/api.js';
|
|
10
|
+
import * as Link from './internal/link.js';
|
|
10
11
|
import { request } from './internal/request.js';
|
|
11
12
|
export * as account from './actions/account.js';
|
|
12
13
|
export * as device from './actions/device.js';
|
|
@@ -39,7 +40,12 @@ export async function authorize(auth, options = {}) {
|
|
|
39
40
|
}));
|
|
40
41
|
if (!session.user)
|
|
41
42
|
return undefined;
|
|
42
|
-
|
|
43
|
+
// A passkey sign-in's account step kept the key its assertion signed, which Tempo Auth
|
|
44
|
+
// authorizes with no second assertion when the passkey's account is chosen.
|
|
45
|
+
const kept = options.accessKey
|
|
46
|
+
? undefined
|
|
47
|
+
: await Link.get(auth, { link: Link.account });
|
|
48
|
+
const key = kept ?? (await AccessKey.resolve(options.accessKey));
|
|
43
49
|
const json = request(auth, {
|
|
44
50
|
accessKey: key.accessKey,
|
|
45
51
|
account: options.account,
|
|
@@ -49,6 +55,9 @@ export async function authorize(auth, options = {}) {
|
|
|
49
55
|
const response = await Api.post(auth, '/v1/authorize', { json });
|
|
50
56
|
if (response.status === 401)
|
|
51
57
|
return undefined;
|
|
58
|
+
// A failed removal keeps the stale key, which the next account step replaces.
|
|
59
|
+
if (kept)
|
|
60
|
+
await Link.release(auth, { link: Link.account }).catch(() => undefined);
|
|
52
61
|
const body = await Api.json(response);
|
|
53
62
|
if (!('step' in body))
|
|
54
63
|
return Api.authorization(body, key);
|
package/dist/actions/passkey.js
CHANGED
|
@@ -57,13 +57,18 @@ export async function signIn(auth, options = {}) {
|
|
|
57
57
|
json: native ? { assertion, authorize } : { assertion },
|
|
58
58
|
}));
|
|
59
59
|
if ('step' in body) {
|
|
60
|
-
if (body.step.type === 'account')
|
|
60
|
+
if (body.step.type === 'account') {
|
|
61
|
+
// Choosing the passkey's account authorizes the key its assertion already signed, once
|
|
62
|
+
// `Actions.authorize` sends that key again.
|
|
63
|
+
if (!native && !options.accessKey)
|
|
64
|
+
await Link.keep(auth, { link: Link.account, material: key.material });
|
|
61
65
|
return {
|
|
62
66
|
step: {
|
|
63
67
|
accounts: body.step.accounts.map(Api.tempoAccount),
|
|
64
68
|
type: 'account',
|
|
65
69
|
},
|
|
66
70
|
};
|
|
71
|
+
}
|
|
67
72
|
// The emailed-code sign-in that sends the link returns this key's authorization, so a key the
|
|
68
73
|
// library generated waits for it in `storage`.
|
|
69
74
|
if (body.step.signed && !options.accessKey)
|
package/dist/internal/link.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Auth } from '../Auth.ts';
|
|
2
2
|
import type * as Key from '../Key.ts';
|
|
3
3
|
import * as AccessKey from './accessKey.ts';
|
|
4
|
+
/** The `link` a key waits under after an account step, which names no link of its own. */
|
|
5
|
+
export declare const account = "account";
|
|
4
6
|
/**
|
|
5
7
|
* Keeps the key's material for `link`. Keeps nothing outside a browser without `storage`. Only the
|
|
6
8
|
* link's digest is stored, since the link links the passkey for whoever sends it with a code.
|
package/dist/internal/link.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Keeps a new key that a one-tap passkey sign-in signed, until the emailed-code sign-in that sends
|
|
3
|
-
* its email step's `link` returns the key's
|
|
3
|
+
* its email step's `link`, or the `Actions.authorize` after its account step, returns the key's
|
|
4
|
+
* authorization.
|
|
4
5
|
* @module
|
|
5
6
|
*/
|
|
6
7
|
import { Bytes, Hash } from 'ox';
|
|
7
8
|
import * as AccessKey from './accessKey.js';
|
|
8
9
|
import * as Store from './store.js';
|
|
9
|
-
/**
|
|
10
|
+
/** The `link` a key waits under after an account step, which names no link of its own. */
|
|
11
|
+
export const account = 'account';
|
|
12
|
+
/** Where the key waits in `storage`. A later email or account step replaces it. */
|
|
10
13
|
const storageKey = 'tempo-auth:passkey-link';
|
|
11
14
|
/**
|
|
12
15
|
* Keeps the key's material for `link`. Keeps nothing outside a browser without `storage`. Only the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempoxyz/auth",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-95.sha-e7c03ef",
|
|
4
4
|
"description": "Signs users in to Tempo through Tempo Auth, and returns Viem access key accounts on their Tempo Accounts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|