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

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
@@ -1,6 +1,6 @@
1
1
  # @tempoxyz/auth
2
2
 
3
- Signs users in to Tempo through [Tempo Auth](../../docs/README.md), and returns their tokens for Tempo APIs and a [viem](https://viem.sh) access key account on their Tempo Account.
3
+ Signs users in to Tempo through [Tempo Auth](../../docs/README.md), and returns their tokens for Tempo APIs and a [Viem](https://viem.sh) access key account on their Tempo Account.
4
4
 
5
5
  ## Overview
6
6
 
@@ -15,7 +15,6 @@ const ousd = Tokens.ousd(client.chain.id).address
15
15
  const auth = Auth.create({
16
16
  chainId: client.chain.id,
17
17
  clientId: 'client_…',
18
- url: 'https://auth.tempo.xyz',
19
18
  })
20
19
 
21
20
  // 1. Email the user a sign-in code.
@@ -44,7 +43,7 @@ else
44
43
  })
45
44
  ```
46
45
 
47
- Every sign-in returns the same `Authorization`. Its `account` sends transactions through viem, and its `accessToken` calls Tempo APIs.
46
+ Every sign-in returns the same `Authorization`. Its `account` sends transactions through Viem, and its `accessToken` calls Tempo APIs.
48
47
 
49
48
  ## Install
50
49
 
@@ -54,6 +53,6 @@ pnpm add @tempoxyz/auth viem
54
53
 
55
54
  ## Documentation
56
55
 
57
- - [Guides](docs/guides/README.md): each sign-in flow, access keys, sessions, errors, and viem.
56
+ - [Guides](docs/guides/README.md): each sign-in flow, access keys, sessions, errors, and Viem.
58
57
  - [API reference](docs/api/README.md): every action, function, and type.
59
58
  - [Tempo Auth](../../docs/README.md): the service the package calls, over HTTP.
package/dist/Actions.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare function authorize(auth: Auth, options?: authorize.Options): Prom
28
28
  export declare namespace authorize {
29
29
  type Options = {
30
30
  /**
31
- * The key to authorize, as a viem account. Its `access` names the Tempo Account, which
31
+ * The key to authorize, as a Viem account. Its `access` names the Tempo Account, which
32
32
  * defaults to the user's first. Defaults to a new key.
33
33
  */
34
34
  accessKey?: Account.Account | undefined;
package/dist/Auth.d.ts CHANGED
@@ -1,3 +1,31 @@
1
+ /**
2
+ * A Tempo Auth instance, which every action takes. Create one with {@link create}, then pass it
3
+ * to each action in `Actions`. Every sign-in returns an `Authorization`: the user's tokens and a
4
+ * Viem access key account.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { Actions, Auth } from '@tempoxyz/auth'
9
+ * import { Expiry, Scopes } from 'viem/tempo'
10
+ * import { tempo } from 'viem/tempo/chains'
11
+ * import * as Tokens from 'viem/tokens'
12
+ *
13
+ * // OUSD has its mainnet address on every Tempo chain.
14
+ * const ousd = Tokens.ousd(tempo.id).address
15
+ *
16
+ * const auth = Auth.create({ clientId: 'client_…', testnet: true })
17
+ *
18
+ * const authorization = await Actions.authorize(auth, {
19
+ * permissions: {
20
+ * expiry: Expiry.days(1),
21
+ * limits: [{ limit: 10_000_000n, token: ousd }],
22
+ * scopes: [Scopes.tip20(ousd).transfer()],
23
+ * },
24
+ * })
25
+ * ```
26
+ * @module
27
+ */
28
+ import type { OneOf } from 'viem';
1
29
  import type { Storage } from './Storage.ts';
2
30
  /** A Tempo Auth instance, which every action takes. */
3
31
  export type Auth = {
@@ -18,7 +46,7 @@ export type Auth = {
18
46
  * objects as they are, since a browser key is a `CryptoKey`. Defaults to IndexedDB.
19
47
  */
20
48
  storage?: Storage | undefined;
21
- /** Where Tempo Auth runs, such as `https://auth.tempo.xyz`. */
49
+ /** Where Tempo Auth runs, such as `https://auth.tech.dev`. */
22
50
  url: string;
23
51
  };
24
52
  /** A request Tempo Auth refused, with its status and message. */
@@ -56,18 +84,24 @@ export declare namespace RequestError {
56
84
  *
57
85
  * @example
58
86
  * ```ts
59
- * const auth = Auth.create({ clientId: 'client_…', url: 'https://auth.tempo.xyz' })
87
+ * const auth = Auth.create({ clientId: 'client_…' })
60
88
  * ```
61
89
  */
62
90
  export declare function create(options: create.Options): Auth;
63
91
  export declare namespace create {
64
- type Options = Omit<Auth, 'chainId' | 'scope'> & {
65
- /** The chain the app's keys act on, such as `tempoTestnet.id`. Defaults to Tempo mainnet. */
66
- chainId?: number | undefined;
92
+ type Options = Omit<Auth, 'chainId' | 'scope' | 'url'> & {
67
93
  /**
68
94
  * Scopes the app's tokens carry beyond `openid` and `email`, which every instance includes.
69
95
  * Defaults to `offline_access`, for a refresh token.
70
96
  */
71
97
  scope?: string | undefined;
72
- };
98
+ /** Where Tempo Auth runs. Defaults to `https://auth.tech.dev`. */
99
+ url?: string | undefined;
100
+ } & OneOf<{
101
+ /** The chain the app's keys act on, such as `client.chain.id`. Defaults to Tempo mainnet. */
102
+ chainId?: number | undefined;
103
+ } | {
104
+ /** Whether the app's keys act on Tempo testnet instead of Tempo mainnet. Defaults to `false`. */
105
+ testnet?: boolean | undefined;
106
+ }>;
73
107
  }
package/dist/Auth.js CHANGED
@@ -1,34 +1,4 @@
1
- /**
2
- * A Tempo Auth instance, which every action takes. Create one with {@link create}, then pass it
3
- * to each action in `Actions`. Every sign-in returns an `Authorization`: the user's tokens and a
4
- * viem access key account.
5
- *
6
- * @example
7
- * ```ts
8
- * import { Actions, Auth } from '@tempoxyz/auth'
9
- * import { Expiry, Scopes } from 'viem/tempo'
10
- * import { tempo, tempoTestnet } from 'viem/tempo/chains'
11
- * import * as Tokens from 'viem/tokens'
12
- *
13
- * const ousd = Tokens.ousd(tempo.id).address
14
- *
15
- * const auth = Auth.create({
16
- * chainId: tempoTestnet.id,
17
- * clientId: 'client_…',
18
- * url: 'https://auth.tempo.xyz',
19
- * })
20
- *
21
- * const authorization = await Actions.authorize(auth, {
22
- * permissions: {
23
- * expiry: Expiry.days(1),
24
- * limits: [{ limit: 10_000_000n, token: ousd }],
25
- * scopes: [Scopes.tip20(ousd).transfer()],
26
- * },
27
- * })
28
- * ```
29
- * @module
30
- */
31
- import { tempo } from 'viem/tempo/chains';
1
+ import { tempo, tempoTestnet } from 'viem/tempo/chains';
32
2
  /** A request Tempo Auth refused, with its status and message. */
33
3
  export class RequestError extends Error {
34
4
  name = 'Auth.RequestError';
@@ -59,15 +29,19 @@ export class RequestError extends Error {
59
29
  *
60
30
  * @example
61
31
  * ```ts
62
- * const auth = Auth.create({ clientId: 'client_…', url: 'https://auth.tempo.xyz' })
32
+ * const auth = Auth.create({ clientId: 'client_…' })
63
33
  * ```
64
34
  */
65
35
  export function create(options) {
36
+ const { chainId, scope = 'offline_access', testnet, url, ...rest } = options;
66
37
  // Every authorization reads the user from the ID token, which needs `openid` and `email`.
67
- const scopes = (options.scope ?? 'offline_access').split(' ').filter(Boolean);
38
+ const scopes = scope.split(' ').filter(Boolean);
68
39
  return {
69
- ...options,
70
- chainId: options.chainId ?? tempo.id,
40
+ ...rest,
41
+ chainId: chainId ?? (testnet ? tempoTestnet.id : tempo.id),
71
42
  scope: [...new Set(['openid', 'email', ...scopes])].join(' '),
43
+ url: url ?? defaultUrl,
72
44
  };
73
45
  }
46
+ /** Where Tempo Auth runs unless `create` receives a `url`. */
47
+ const defaultUrl = 'https://auth.tech.dev';
@@ -7,7 +7,7 @@ import type { Tokens } from './Tokens.ts';
7
7
  import type { User } from './User.ts';
8
8
  /** What every sign-in returns: the app's tokens for Tempo APIs, with its access key and the user. */
9
9
  export type Authorization = Tokens & {
10
- /** The user's Tempo Account, as a viem account that signs with the app's access key. */
10
+ /** The user's Tempo Account, as a Viem account that signs with the app's access key. */
11
11
  account: ReturnType<typeof Key.toAccount>;
12
12
  /** The same key as data, for apps that store it and rebuild it with `Key.toAccount`. */
13
13
  key: Key.Key;
package/dist/Key.d.ts CHANGED
@@ -50,7 +50,7 @@ export declare function expired(key: Key): boolean;
50
50
  */
51
51
  export declare function from(value: Key): Key;
52
52
  /**
53
- * Returns the key as a viem access key account acting for its Tempo Account. viem attaches the
53
+ * Returns the key as a Viem access key account acting for its Tempo Account. Viem attaches the
54
54
  * authorization to transactions until the chain registers the key. A key the app supplied signs
55
55
  * with that `accessKey`. Throws {@link AccessKeyRequiredError} when neither holds key material.
56
56
  *
package/dist/Key.js CHANGED
@@ -37,7 +37,7 @@ export function from(value) {
37
37
  return value;
38
38
  }
39
39
  /**
40
- * Returns the key as a viem access key account acting for its Tempo Account. viem attaches the
40
+ * Returns the key as a Viem access key account acting for its Tempo Account. Viem attaches the
41
41
  * authorization to transactions until the chain registers the key. A key the app supplied signs
42
42
  * with that `accessKey`. Throws {@link AccessKeyRequiredError} when neither holds key material.
43
43
  *
@@ -4,13 +4,13 @@
4
4
  */
5
5
  import type { KeyAuthorization } from 'ox/tempo';
6
6
  /**
7
- * What an app's access key may do, as viem's `accessKey.authorize` takes it. Tempo Auth fills what
7
+ * What an app's access key may do, as Viem's `accessKey.authorize` takes it. Tempo Auth fills what
8
8
  * it leaves out with the headless ceiling.
9
9
  */
10
10
  export type Permissions = {
11
11
  /** The chain the key acts on, such as `tempoTestnet.id`. Defaults to the instance's `chainId`. */
12
12
  chainId?: number | undefined;
13
- /** Unix seconds. viem's `Expiry` builds one, such as `Expiry.days(1)`. Defaults to a year from now. */
13
+ /** Unix seconds. Viem's `Expiry` builds one, such as `Expiry.days(1)`. Defaults to a year from now. */
14
14
  expiry?: number | undefined;
15
15
  /** How much of each token the key may spend. Defaults to about $1,000 of each token it calls, or of OUSD. */
16
16
  limits?: KeyAuthorization.KeyAuthorization['limits'];
@@ -17,7 +17,7 @@ export declare function authorize(auth: Auth, options: authorize.Options): Promi
17
17
  export declare namespace authorize {
18
18
  type Options = {
19
19
  /**
20
- * The key to authorize, as a viem account. Its `access` names the Tempo Account, which
20
+ * The key to authorize, as a Viem account. Its `access` names the Tempo Account, which
21
21
  * defaults to the user's first. Defaults to a new key.
22
22
  */
23
23
  accessKey?: Account.Account | undefined;
@@ -36,7 +36,7 @@ export declare function signIn(auth: Auth, options: signIn.Options): Promise<sig
36
36
  export declare namespace signIn {
37
37
  type Options = {
38
38
  /**
39
- * The key to authorize, as a viem account. Its `access` names the Tempo Account, which
39
+ * The key to authorize, as a Viem account. Its `access` names the Tempo Account, which
40
40
  * defaults to the user's first. Defaults to a new key.
41
41
  */
42
42
  accessKey?: Account.Account | undefined;
@@ -41,7 +41,7 @@ export declare function createUrl(auth: Auth, options?: createUrl.Options): Prom
41
41
  export declare namespace createUrl {
42
42
  type Options = {
43
43
  /**
44
- * The key to authorize, as a viem account. Its `access` names the Tempo Account, which
44
+ * The key to authorize, as a Viem account. Its `access` names the Tempo Account, which
45
45
  * defaults to the user's first. Defaults to a new key, whose material `pending` keeps.
46
46
  */
47
47
  accessKey?: Account.Account | undefined;
@@ -93,7 +93,7 @@ export declare function start(auth: Auth, options?: start.Options): Promise<void
93
93
  export declare namespace start {
94
94
  type Options = {
95
95
  /**
96
- * The key to authorize, as a viem account. Pass it to {@link complete} too. Defaults to a new
96
+ * The key to authorize, as a Viem account. Pass it to {@link complete} too. Defaults to a new
97
97
  * key, which `storage` keeps until the browser returns.
98
98
  */
99
99
  accessKey?: Account.Account | undefined;
@@ -7,7 +7,7 @@ import type * as Key from '../Key.ts';
7
7
  export declare function resolve(accessKey: Account.Account | undefined): Promise<resolve.ReturnType>;
8
8
  export declare namespace resolve {
9
9
  type ReturnType = {
10
- /** The key, as a viem account that signs with it. */
10
+ /** The key, as a Viem account that signs with it. */
11
11
  accessKey: Account.Account;
12
12
  /** What the authorization keeps to rebuild the key. Empty for a key the app supplied. */
13
13
  material: Key.Material;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-62.sha-55672b2",
4
- "description": "Signs users in to Tempo through Tempo Auth, and returns viem access key accounts on their Tempo Accounts.",
3
+ "version": "0.0.0-pr-62.sha-8ef1ef2",
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": {
7
7
  ".": {