@tempoxyz/auth 0.0.0-pr-16.sha-bc51738 → 0.0.0-pr-17.sha-08e5136

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Sign users in to Tempo through Tempo Auth, and get back their tokens for Tempo APIs and a [viem](https://viem.sh) access key account on their Tempo Account.
4
4
 
5
- Every sign-in returns the same `Authorization`. Send transactions with its `account` through viem, and call Tempo APIs with its `tokens.accessToken`.
5
+ Every sign-in returns the same `Authorization`. Send transactions with its `account` through viem, and call Tempo APIs with its `accessToken`.
6
6
 
7
7
  ```ts
8
8
  import { Actions, Auth } from '@tempoxyz/auth'
@@ -193,11 +193,11 @@ if (Key.expired(saved.key)) signInAgain()
193
193
 
194
194
  const account = Key.toAccount(saved.key)
195
195
  const tokens = await Actions.refresh(auth, {
196
- refreshToken: saved.tokens.refreshToken,
196
+ refreshToken: saved.refreshToken,
197
197
  })
198
198
  ```
199
199
 
200
- Refresh tokens rotate, so store the new `tokens` after each refresh.
200
+ Refresh tokens rotate, so save the new tokens over the old ones after each refresh, such as `{ ...saved, ...tokens }`.
201
201
 
202
202
  ## Errors
203
203
 
@@ -247,12 +247,15 @@ try {
247
247
 
248
248
  ### `Authorization`
249
249
 
250
- | Field | Meaning |
251
- | --------- | ------------------------------------------------------------------------------- |
252
- | `account` | The app's key as a viem access key account, acting for the user's Tempo Account |
253
- | `key` | The same key as JSON, for `Key.toAccount` |
254
- | `tokens` | `accessToken`, `expiresAt`, and the optional `idToken` and `refreshToken` |
255
- | `user` | The user's `email` and `id`, the `sub` of every token |
250
+ | Field | Meaning |
251
+ | -------------- | -------------------------------------------------------------------------------- |
252
+ | `account` | The user's Tempo Account, as a viem account that signs with the app's access key |
253
+ | `key` | The same key as JSON, for `Key.toAccount` |
254
+ | `accessToken` | The Bearer token Tempo APIs accept |
255
+ | `expiresAt` | When the access token expires, in milliseconds |
256
+ | `idToken` | Optional: the OIDC ID token, which names the user |
257
+ | `refreshToken` | Optional: exchanges for new tokens through `refresh`. It rotates each time |
258
+ | `user` | The user's `email` and `id`, the `sub` of every token |
256
259
 
257
260
  ### `Key`
258
261
 
package/dist/Actions.d.ts CHANGED
@@ -187,7 +187,7 @@ export declare namespace redirect {
187
187
  * @example
188
188
  * ```ts
189
189
  * const tokens = await Actions.refresh(auth, {
190
- * refreshToken: saved.tokens.refreshToken,
190
+ * refreshToken: saved.refreshToken,
191
191
  * })
192
192
  * ```
193
193
  */
package/dist/Actions.js CHANGED
@@ -253,7 +253,7 @@ export async function redirect(auth, options) {
253
253
  * @example
254
254
  * ```ts
255
255
  * const tokens = await Actions.refresh(auth, {
256
- * refreshToken: saved.tokens.refreshToken,
256
+ * refreshToken: saved.refreshToken,
257
257
  * })
258
258
  * ```
259
259
  */
@@ -344,9 +344,9 @@ function authorization(body, options) {
344
344
  const tokens_ = 'accessToken' in body.tokens ? body.tokens : tokens(body.tokens);
345
345
  const claims = JSON.parse(Base64.toString(tokens_.idToken.split('.')[1]));
346
346
  return {
347
+ ...tokens_,
347
348
  account: Key.toAccount(key),
348
349
  key,
349
- tokens: tokens_,
350
350
  user: { email: claims.email, id: claims.sub },
351
351
  };
352
352
  }
package/dist/Auth.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A Tempo Auth instance, and the types its actions take and return. Create one with
3
3
  * {@link create}, then pass it to each action in `Actions`. Every sign-in returns an
4
- * {@link Authorization}: the user's tokens, and a viem access key account.
4
+ * {@link Authorization}: the user's tokens and a viem access key account.
5
5
  *
6
6
  * @example
7
7
  * ```ts
@@ -56,14 +56,12 @@ export type TempoAccount = {
56
56
  /** The account's address, the same on every Tempo chain. */
57
57
  address: `0x${string}`;
58
58
  };
59
- /** What every sign-in returns. */
60
- export type Authorization = {
61
- /** The app's access key, as a viem account acting for the user's Tempo Account. */
59
+ /** What every sign-in returns: the app's tokens for Tempo APIs, with its access key and the user. */
60
+ export type Authorization = Tokens & {
61
+ /** The user's Tempo Account, as a viem account that signs with the app's access key. */
62
62
  account: ReturnType<typeof Key.toAccount>;
63
63
  /** The same key as JSON, for apps that store it and rebuild it with `Key.toAccount`. */
64
64
  key: Key.Key;
65
- /** The app's tokens for Tempo APIs. */
66
- tokens: Tokens;
67
65
  /** The signed-in user, from the ID token. */
68
66
  user: User;
69
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempoxyz/auth",
3
- "version": "0.0.0-pr-16.sha-bc51738",
3
+ "version": "0.0.0-pr-17.sha-08e5136",
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": {