@tempoxyz/auth 0.0.0-pr-74.sha-74a7fa4 → 0.0.0-pr-74.sha-7c7ca79

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.
@@ -10,9 +10,10 @@ import type { Auth } from '../Auth.ts';
10
10
  import type { Authorization } from '../Authorization.ts';
11
11
  import type { Permissions } from '../Permissions.ts';
12
12
  /**
13
- * Signs the user in with a passkey, and authorizes the app in the same call. The passkey's one
14
- * assertion also signs the app's key when that passkey owns the Tempo Account, since the
15
- * ceremony's challenge is the key's digest. Returns the email step for a wallet.tempo passkey whose
13
+ * Signs the user in with a passkey, and authorizes the app in the same call. On a page, the
14
+ * passkey's one assertion also signs the app's key when that passkey owns the Tempo Account, since
15
+ * the ceremony's challenge is the key's digest. A native app, which sends no `Origin`, signs in
16
+ * with a random challenge and authorizes as a headless sign-in does. Returns the email step for a wallet.tempo passkey whose
16
17
  * account has no email: the app signs the user in with `Actions.email.signIn`, passing the step's
17
18
  * `link`, which links the passkey, and the same `accessKey` and `challenge`, which this call does
18
19
  * not authorize. Throws a `RequestError` with reason `webauthn_required` when another passkey owns
@@ -9,9 +9,10 @@ import * as AccessKey from '../internal/accessKey.js';
9
9
  import * as Api from '../internal/api.js';
10
10
  import { request } from '../internal/request.js';
11
11
  /**
12
- * Signs the user in with a passkey, and authorizes the app in the same call. The passkey's one
13
- * assertion also signs the app's key when that passkey owns the Tempo Account, since the
14
- * ceremony's challenge is the key's digest. Returns the email step for a wallet.tempo passkey whose
12
+ * Signs the user in with a passkey, and authorizes the app in the same call. On a page, the
13
+ * passkey's one assertion also signs the app's key when that passkey owns the Tempo Account, since
14
+ * the ceremony's challenge is the key's digest. A native app, which sends no `Origin`, signs in
15
+ * with a random challenge and authorizes as a headless sign-in does. Returns the email step for a wallet.tempo passkey whose
15
16
  * account has no email: the app signs the user in with `Actions.email.signIn`, passing the step's
16
17
  * `link`, which links the passkey, and the same `accessKey` and `challenge`, which this call does
17
18
  * not authorize. Throws a `RequestError` with reason `webauthn_required` when another passkey owns
@@ -27,21 +28,24 @@ import { request } from '../internal/request.js';
27
28
  export async function signIn(auth, options = {}) {
28
29
  const { challenge, getFn, permissions } = options;
29
30
  const key = await AccessKey.resolve(options.accessKey);
30
- // The request goes with the options, so the challenge is its key's digest.
31
+ const authorize = request(auth, {
32
+ accessKey: key.accessKey,
33
+ challenge,
34
+ permissions,
35
+ });
36
+ // A page sends the request with the options, so the challenge is its key's digest. A native app
37
+ // sends no `Origin` to bind one-tap to, so it sends the request with the assertion instead.
38
+ const native = !/^https?:/.test(authorize.redirect_uri);
31
39
  const requested = await Api.json(await Api.post(auth, '/v1/auth/passkey/options', {
32
- json: {
33
- authorize: request(auth, {
34
- accessKey: key.accessKey,
35
- challenge,
36
- permissions,
37
- }),
38
- },
40
+ json: native ? {} : { authorize },
39
41
  }));
40
42
  const deserialized = Authentication.deserializeOptions(requested.options);
41
43
  const assertion = Authentication.serializeResponse(await Authentication.sign(
42
44
  // ox reads `getFn` beside request options at runtime, which its types admit only beside a challenge.
43
45
  getFn ? { ...deserialized, getFn } : deserialized));
44
- const body = await Api.json(await Api.post(auth, '/v1/auth/passkey/verify', { json: { assertion } }));
46
+ const body = await Api.json(await Api.post(auth, '/v1/auth/passkey/verify', {
47
+ json: native ? { assertion, authorize } : { assertion },
48
+ }));
45
49
  if ('step' in body)
46
50
  return { step: body.step };
47
51
  return Api.authorization(body.authorization, key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-74.sha-74a7fa4",
3
+ "version": "0.0.0-pr-74.sha-7c7ca79",
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": {