@tempoxyz/auth 0.0.0-pr-62.sha-8ef1ef2 → 0.0.0-pr-62.sha-aff3324

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/README.md CHANGED
@@ -31,16 +31,15 @@ const result = await Actions.email.signIn(auth, {
31
31
  },
32
32
  })
33
33
 
34
- // 3. Send a transaction with the access key. An address that requires SSO
35
- // returns a `step` instead, which continues at its connection.
36
- if ('step' in result) Actions.provider.signIn(auth, { url: result.step.url })
37
- else
38
- await client.token.transferSync({
39
- account: result.account,
40
- amount: 10_000n,
41
- to: '0x…',
42
- token: ousd,
43
- })
34
+ if ('step' in result) throw new Error('This address signs in through SSO.')
35
+
36
+ // 3. Send a transaction with the access key.
37
+ await client.token.transferSync({
38
+ account: result.account,
39
+ amount: 10_000n,
40
+ to: '0x…',
41
+ token: ousd,
42
+ })
44
43
  ```
45
44
 
46
45
  Every sign-in returns the same `Authorization`. Its `account` sends transactions through Viem, and its `accessToken` calls Tempo APIs.
package/dist/Auth.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * // OUSD has its mainnet address on every Tempo chain.
14
14
  * const ousd = Tokens.ousd(tempo.id).address
15
15
  *
16
- * const auth = Auth.create({ clientId: 'client_…', testnet: true })
16
+ * const auth = Auth.create({ clientId: 'client_…', dev: true })
17
17
  *
18
18
  * const authorization = await Actions.authorize(auth, {
19
19
  * permissions: {
@@ -102,6 +102,6 @@ export declare namespace create {
102
102
  chainId?: number | undefined;
103
103
  } | {
104
104
  /** Whether the app's keys act on Tempo testnet instead of Tempo mainnet. Defaults to `false`. */
105
- testnet?: boolean | undefined;
105
+ dev?: boolean | undefined;
106
106
  }>;
107
107
  }
package/dist/Auth.js CHANGED
@@ -33,12 +33,12 @@ export class RequestError extends Error {
33
33
  * ```
34
34
  */
35
35
  export function create(options) {
36
- const { chainId, scope = 'offline_access', testnet, url, ...rest } = options;
36
+ const { chainId, dev, scope = 'offline_access', url, ...rest } = options;
37
37
  // Every authorization reads the user from the ID token, which needs `openid` and `email`.
38
38
  const scopes = scope.split(' ').filter(Boolean);
39
39
  return {
40
40
  ...rest,
41
- chainId: chainId ?? (testnet ? tempoTestnet.id : tempo.id),
41
+ chainId: chainId ?? (dev ? tempoTestnet.id : tempo.id),
42
42
  scope: [...new Set(['openid', 'email', ...scopes])].join(' '),
43
43
  url: url ?? defaultUrl,
44
44
  };
@@ -8,12 +8,12 @@ import type { Permissions } from '../Permissions.ts';
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const device = await Actions.device.authorize(auth, { device: Os.hostname() })
11
+ * const device = await Actions.device.authorize(auth)
12
12
  * console.log(`Open ${device.verificationUriComplete}`)
13
13
  * const authorization = await device.wait()
14
14
  * ```
15
15
  */
16
- export declare function authorize(auth: Auth, options: authorize.Options): Promise<authorize.ReturnType>;
16
+ export declare function authorize(auth: Auth, options?: authorize.Options): Promise<authorize.ReturnType>;
17
17
  export declare namespace authorize {
18
18
  type Options = {
19
19
  /**
@@ -21,8 +21,11 @@ export declare namespace authorize {
21
21
  * defaults to the user's first. Defaults to a new key.
22
22
  */
23
23
  accessKey?: Account.Account | undefined;
24
- /** The name the approval page shows, such as the machine's hostname. */
25
- device: string;
24
+ /**
25
+ * The name the approval page shows. Defaults to the machine's hostname in Node, Bun, and Deno,
26
+ * and to `Unknown device` elsewhere.
27
+ */
28
+ device?: string | undefined;
26
29
  /** What the CLI's key may do. The approval page shows it beside the device, and the headless ceiling fills what it leaves out. */
27
30
  permissions?: Permissions | undefined;
28
31
  };
@@ -8,16 +8,16 @@ import { request } from '../internal/request.js';
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const device = await Actions.device.authorize(auth, { device: Os.hostname() })
11
+ * const device = await Actions.device.authorize(auth)
12
12
  * console.log(`Open ${device.verificationUriComplete}`)
13
13
  * const authorization = await device.wait()
14
14
  * ```
15
15
  */
16
- export async function authorize(auth, options) {
16
+ export async function authorize(auth, options = {}) {
17
17
  const key = await AccessKey.resolve(options.accessKey);
18
18
  const code = await Api.json(await Api.post(auth, '/v1/device/authorize', {
19
19
  json: {
20
- device: options.device,
20
+ device: options.device ?? hostname(),
21
21
  key_authorization: request(auth, {
22
22
  accessKey: key.accessKey,
23
23
  permissions: options.permissions,
@@ -60,3 +60,12 @@ export async function authorize(auth, options) {
60
60
  wait,
61
61
  };
62
62
  }
63
+ /**
64
+ * The machine's hostname, within the 64 characters Tempo Auth accepts. `getBuiltinModule` loads
65
+ * `node:os` without an import, which browser and React Native bundlers would fail to resolve.
66
+ */
67
+ function hostname() {
68
+ const process = Reflect.get(globalThis, 'process');
69
+ const name = process?.getBuiltinModule?.('node:os')?.hostname().trim();
70
+ return name ? name.slice(0, 64) : 'Unknown device';
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-62.sha-8ef1ef2",
3
+ "version": "0.0.0-pr-62.sha-aff3324",
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": {