@tempoxyz/auth 0.0.0-pr-23.sha-42df67a → 0.0.0-pr-27.sha-abd8f16
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 +10 -0
- package/dist/Actions.d.ts +4 -1
- package/dist/Auth.d.ts +1 -98
- package/dist/Auth.js +27 -0
- package/dist/Authorization.d.ts +25 -0
- package/dist/Authorization.js +11 -0
- package/dist/Key.d.ts +9 -0
- package/dist/Key.js +11 -0
- package/dist/Pending.d.ts +26 -0
- package/dist/Pending.js +11 -0
- package/dist/Permissions.d.ts +25 -0
- package/dist/Permissions.js +15 -0
- package/dist/Provider.d.ts +15 -0
- package/dist/Provider.js +11 -0
- package/dist/Step.d.ts +20 -0
- package/dist/Step.js +11 -0
- package/dist/Storage.d.ts +26 -0
- package/dist/Storage.js +15 -0
- package/dist/TempoAccount.d.ts +18 -0
- package/dist/TempoAccount.js +11 -0
- package/dist/Tokens.d.ts +24 -0
- package/dist/Tokens.js +11 -0
- package/dist/User.d.ts +20 -0
- package/dist/User.js +11 -0
- package/dist/actions/device.d.ts +3 -1
- package/dist/actions/device.js +1 -1
- package/dist/actions/email.d.ts +4 -1
- package/dist/actions/provider.d.ts +2 -1
- package/dist/actions/redirect.d.ts +7 -4
- package/dist/actions/redirect.js +5 -4
- package/dist/actions/tempoAccount.d.ts +4 -3
- package/dist/actions/tempoAccount.js +2 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/internal/api.d.ts +3 -1
- package/dist/internal/api.js +3 -3
- package/dist/internal/indexedDb.d.ts +1 -1
- package/dist/internal/request.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -275,6 +275,16 @@ Each sign-in flow has its own namespace. The actions every flow shares sit at th
|
|
|
275
275
|
| `refreshToken` | Optional: exchanges for new tokens through `refresh`. It rotates each time |
|
|
276
276
|
| `user` | The user's `email` and `id`, the `sub` of every token |
|
|
277
277
|
|
|
278
|
+
### Types
|
|
279
|
+
|
|
280
|
+
Each type an action takes or returns lives in its own module, exported beside `Actions`: `Authorization`, `Key`, `Pending`, `Permissions`, `Provider`, `Step`, `Storage`, `TempoAccount`, `Tokens`, and `User`. Each module's `from` builds a value of its type:
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
import { Permissions } from '@tempoxyz/auth'
|
|
284
|
+
|
|
285
|
+
const permissions = Permissions.from({ expiry: Expiry.days(1), limits, scopes })
|
|
286
|
+
```
|
|
287
|
+
|
|
278
288
|
### `Key`
|
|
279
289
|
|
|
280
290
|
| Function | Returns |
|
package/dist/Actions.d.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type { Account } from 'viem/tempo';
|
|
7
|
-
import type { Auth
|
|
7
|
+
import type { Auth } from './Auth.ts';
|
|
8
|
+
import type { Authorization } from './Authorization.ts';
|
|
9
|
+
import type { Permissions } from './Permissions.ts';
|
|
10
|
+
import type { Tokens } from './Tokens.ts';
|
|
8
11
|
export * as device from './actions/device.ts';
|
|
9
12
|
export * as email from './actions/email.ts';
|
|
10
13
|
export * as provider from './actions/provider.ts';
|
package/dist/Auth.d.ts
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* A Tempo Auth instance, and the types its actions take and return. Create one with
|
|
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.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { Actions, Auth } from '@tempoxyz/auth'
|
|
9
|
-
* import { Addresses, Expiry, Scopes } from 'viem/tempo'
|
|
10
|
-
* import { tempoTestnet } from 'viem/tempo/chains'
|
|
11
|
-
*
|
|
12
|
-
* const auth = Auth.create({
|
|
13
|
-
* chainId: tempoTestnet.id,
|
|
14
|
-
* clientId: 'client_…',
|
|
15
|
-
* url: 'https://auth.tempo.xyz',
|
|
16
|
-
* })
|
|
17
|
-
*
|
|
18
|
-
* const authorization = await Actions.authorize(auth, {
|
|
19
|
-
* permissions: {
|
|
20
|
-
* expiry: Expiry.days(1),
|
|
21
|
-
* limits: [{ limit: 10_000_000n, token: Addresses.pathUsd }],
|
|
22
|
-
* scopes: [Scopes.tip20(Addresses.pathUsd).transfer()],
|
|
23
|
-
* },
|
|
24
|
-
* })
|
|
25
|
-
* ```
|
|
26
|
-
* @module
|
|
27
|
-
*/
|
|
28
|
-
import type { KeyAuthorization } from 'ox/tempo';
|
|
29
|
-
import type * as Key from './Key.ts';
|
|
1
|
+
import type { Storage } from './Storage.ts';
|
|
30
2
|
/** A Tempo Auth instance, which every action takes. */
|
|
31
3
|
export type Auth = {
|
|
32
4
|
/** The chain the app's keys act on, unless an action's `permissions` names another. */
|
|
@@ -49,75 +21,6 @@ export type Auth = {
|
|
|
49
21
|
/** Where Tempo Auth runs, such as `https://auth.tempo.xyz`. */
|
|
50
22
|
url: string;
|
|
51
23
|
};
|
|
52
|
-
/** What an app's access key may do, as viem's `accessKey.authorize` takes it. */
|
|
53
|
-
export type Permissions = Pick<KeyAuthorization.KeyAuthorization, 'limits' | 'scopes'> & {
|
|
54
|
-
/** The chain the key acts on, such as `tempoTestnet.id`. Defaults to the instance's `chainId`. */
|
|
55
|
-
chainId?: number | undefined;
|
|
56
|
-
/** Unix seconds. viem's `Expiry` builds one, such as `Expiry.days(1)`. */
|
|
57
|
-
expiry: number;
|
|
58
|
-
};
|
|
59
|
-
/** Keeps a redirect's state, as structured-clone storage such as IndexedDB does. */
|
|
60
|
-
export type Storage = {
|
|
61
|
-
/** Reads the value at `key`, or `undefined`. */
|
|
62
|
-
getItem: (key: string) => Promise<unknown>;
|
|
63
|
-
/** Deletes the value at `key`. */
|
|
64
|
-
removeItem: (key: string) => Promise<void>;
|
|
65
|
-
/** Writes `value` at `key`, without serializing it. */
|
|
66
|
-
setItem: (key: string, value: unknown) => Promise<void>;
|
|
67
|
-
};
|
|
68
|
-
/** One of the user's Tempo Accounts. */
|
|
69
|
-
export type TempoAccount = {
|
|
70
|
-
/** The account's address, the same on every Tempo chain. */
|
|
71
|
-
address: `0x${string}`;
|
|
72
|
-
};
|
|
73
|
-
/** What every sign-in returns: the app's tokens for Tempo APIs, with its access key and the user. */
|
|
74
|
-
export type Authorization = Tokens & {
|
|
75
|
-
/** The user's Tempo Account, as a viem account that signs with the app's access key. */
|
|
76
|
-
account: ReturnType<typeof Key.toAccount>;
|
|
77
|
-
/** The same key as data, for apps that store it and rebuild it with `Key.toAccount`. */
|
|
78
|
-
key: Key.Key;
|
|
79
|
-
/** The signed-in user, from the ID token. */
|
|
80
|
-
user: User;
|
|
81
|
-
};
|
|
82
|
-
/** The app's tokens for Tempo APIs. */
|
|
83
|
-
export type Tokens = {
|
|
84
|
-
/** The Bearer token Tempo APIs accept. */
|
|
85
|
-
accessToken: string;
|
|
86
|
-
/** When the access token expires, in milliseconds. */
|
|
87
|
-
expiresAt: number;
|
|
88
|
-
/** The OIDC ID token, which names the user. A refresh may omit it. */
|
|
89
|
-
idToken?: string | undefined;
|
|
90
|
-
/** Exchanges for new tokens through `Actions.refresh`. It rotates on every refresh. */
|
|
91
|
-
refreshToken?: string | undefined;
|
|
92
|
-
};
|
|
93
|
-
/** The signed-in user. */
|
|
94
|
-
export type User = {
|
|
95
|
-
/** The user's verified email address. */
|
|
96
|
-
email: string;
|
|
97
|
-
/** The user's ID, the `sub` of every token. */
|
|
98
|
-
id: string;
|
|
99
|
-
};
|
|
100
|
-
/** An OAuth provider's short name, as `Actions.provider.list` lists them. */
|
|
101
|
-
export type Provider = 'apple' | 'bitbucket' | 'github' | 'gitlab' | 'google' | 'intuit' | 'linkedin' | 'microsoft' | 'salesforce' | 'slack' | 'xero';
|
|
102
|
-
/** A step a sign-in needs before it finishes, such as the SSO connection an address requires. */
|
|
103
|
-
export type Step = {
|
|
104
|
-
/** The kind of step. */
|
|
105
|
-
type: 'sso';
|
|
106
|
-
/** Where `Actions.provider.signIn` sends the browser to take the step. */
|
|
107
|
-
url: string;
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* A sign-in redirect in progress: what the app keeps until Tempo Auth redirects back, with the
|
|
111
|
-
* material of the new access key the callback authorizes.
|
|
112
|
-
*/
|
|
113
|
-
export type Pending = Key.Material & {
|
|
114
|
-
/** Where Tempo Auth redirects back to, which the code exchange repeats. */
|
|
115
|
-
redirectUri: string;
|
|
116
|
-
/** The value the callback must echo, so a forged callback is refused. */
|
|
117
|
-
state: string;
|
|
118
|
-
/** The PKCE verifier that redeems the code. */
|
|
119
|
-
verifier: string;
|
|
120
|
-
};
|
|
121
24
|
/** A request Tempo Auth refused, with its status and message. */
|
|
122
25
|
export declare class RequestError extends Error {
|
|
123
26
|
readonly name = "Auth.RequestError";
|
package/dist/Auth.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
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 { Addresses, Expiry, Scopes } from 'viem/tempo'
|
|
10
|
+
* import { tempoTestnet } from 'viem/tempo/chains'
|
|
11
|
+
*
|
|
12
|
+
* const auth = Auth.create({
|
|
13
|
+
* chainId: tempoTestnet.id,
|
|
14
|
+
* clientId: 'client_…',
|
|
15
|
+
* url: 'https://auth.tempo.xyz',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* const authorization = await Actions.authorize(auth, {
|
|
19
|
+
* permissions: {
|
|
20
|
+
* expiry: Expiry.days(1),
|
|
21
|
+
* limits: [{ limit: 10_000_000n, token: Addresses.pathUsd }],
|
|
22
|
+
* scopes: [Scopes.tip20(Addresses.pathUsd).transfer()],
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
1
28
|
import { tempo } from 'viem/tempo/chains';
|
|
2
29
|
/** A request Tempo Auth refused, with its status and message. */
|
|
3
30
|
export class RequestError extends Error {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every sign-in returns: the app's tokens for Tempo APIs, its access key, and the user.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type * as Key from './Key.ts';
|
|
6
|
+
import type { Tokens } from './Tokens.ts';
|
|
7
|
+
import type { User } from './User.ts';
|
|
8
|
+
/** What every sign-in returns: the app's tokens for Tempo APIs, with its access key and the user. */
|
|
9
|
+
export type Authorization = Tokens & {
|
|
10
|
+
/** The user's Tempo Account, as a viem account that signs with the app's access key. */
|
|
11
|
+
account: ReturnType<typeof Key.toAccount>;
|
|
12
|
+
/** The same key as data, for apps that store it and rebuild it with `Key.toAccount`. */
|
|
13
|
+
key: Key.Key;
|
|
14
|
+
/** The signed-in user, from the ID token. */
|
|
15
|
+
user: User;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Instantiates a {@link Authorization}.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const authorization = Authorization.from({ ...saved, account: Key.toAccount(saved.key) })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function from(value: Authorization): Authorization;
|
package/dist/Key.d.ts
CHANGED
|
@@ -40,6 +40,15 @@ export declare class AccessKeyRequiredError extends Error {
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export declare function expired(key: Key): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Instantiates a {@link Key}.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const key = Key.from(JSON.parse(saved).key)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function from(value: Key): Key;
|
|
43
52
|
/**
|
|
44
53
|
* Returns the key as a viem access key account acting for its Tempo Account. viem attaches the
|
|
45
54
|
* authorization to transactions until the chain registers the key. A key the app supplied signs
|
package/dist/Key.js
CHANGED
|
@@ -25,6 +25,17 @@ export function expired(key) {
|
|
|
25
25
|
const { expiry } = KeyAuthorization.fromRpc(key.keyAuthorization);
|
|
26
26
|
return Boolean(expiry) && expiry * 1000 <= Date.now();
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Instantiates a {@link Key}.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const key = Key.from(JSON.parse(saved).key)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function from(value) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
28
39
|
/**
|
|
29
40
|
* Returns the key as a viem access key account acting for its Tempo Account. viem attaches the
|
|
30
41
|
* authorization to transactions until the chain registers the key. A key the app supplied signs
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sign-in redirect in progress, which an app keeps until Tempo Auth redirects back.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type * as Key from './Key.ts';
|
|
6
|
+
/**
|
|
7
|
+
* A sign-in redirect in progress: what the app keeps until Tempo Auth redirects back, with the
|
|
8
|
+
* material of the new access key the callback authorizes.
|
|
9
|
+
*/
|
|
10
|
+
export type Pending = Key.Material & {
|
|
11
|
+
/** Where Tempo Auth redirects back to, which the code exchange repeats. */
|
|
12
|
+
redirectUri: string;
|
|
13
|
+
/** The value the callback must echo, so a forged callback is refused. */
|
|
14
|
+
state: string;
|
|
15
|
+
/** The PKCE verifier that redeems the code. */
|
|
16
|
+
verifier: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Instantiates a {@link Pending}.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const pending = Pending.from(await unseal(c, 'oauth'))
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function from(value: Pending): Pending;
|
package/dist/Pending.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an app's access key may do: its chain, expiry, spending limits, and call scopes.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { KeyAuthorization } from 'ox/tempo';
|
|
6
|
+
/** What an app's access key may do, as viem's `accessKey.authorize` takes it. */
|
|
7
|
+
export type Permissions = Pick<KeyAuthorization.KeyAuthorization, 'limits' | 'scopes'> & {
|
|
8
|
+
/** The chain the key acts on, such as `tempoTestnet.id`. Defaults to the instance's `chainId`. */
|
|
9
|
+
chainId?: number | undefined;
|
|
10
|
+
/** Unix seconds. viem's `Expiry` builds one, such as `Expiry.days(1)`. */
|
|
11
|
+
expiry: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Instantiates a {@link Permissions}.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const permissions = Permissions.from({
|
|
19
|
+
* expiry: Expiry.days(1),
|
|
20
|
+
* limits: [{ limit: 10_000_000n, token: Addresses.pathUsd }],
|
|
21
|
+
* scopes: [Scopes.tip20(Addresses.pathUsd).transfer()],
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function from(value: Permissions): Permissions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instantiates a {@link Permissions}.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const permissions = Permissions.from({
|
|
7
|
+
* expiry: Expiry.days(1),
|
|
8
|
+
* limits: [{ limit: 10_000_000n, token: Addresses.pathUsd }],
|
|
9
|
+
* scopes: [Scopes.tip20(Addresses.pathUsd).transfer()],
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function from(value) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OAuth providers Tempo Auth can offer.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** An OAuth provider's short name, as `Actions.provider.list` lists them. */
|
|
6
|
+
export type Provider = 'apple' | 'bitbucket' | 'github' | 'gitlab' | 'google' | 'intuit' | 'linkedin' | 'microsoft' | 'salesforce' | 'slack' | 'xero';
|
|
7
|
+
/**
|
|
8
|
+
* Instantiates a {@link Provider}.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const provider = Provider.from('google')
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function from(value: Provider): Provider;
|
package/dist/Provider.js
ADDED
package/dist/Step.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A step a sign-in needs before it finishes, such as the SSO connection an address requires.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** A step a sign-in needs before it finishes, such as the SSO connection an address requires. */
|
|
6
|
+
export type Step = {
|
|
7
|
+
/** The kind of step. */
|
|
8
|
+
type: 'sso';
|
|
9
|
+
/** Where `Actions.provider.signIn` sends the browser to take the step. */
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Instantiates a {@link Step}.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const step = Step.from({ type: 'sso', url })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function from(value: Step): Step;
|
package/dist/Step.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a redirect keeps its state until Tempo Auth redirects back.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** Keeps a redirect's state, as structured-clone storage such as IndexedDB does. */
|
|
6
|
+
export type Storage = {
|
|
7
|
+
/** Reads the value at `key`, or `undefined`. */
|
|
8
|
+
getItem: (key: string) => Promise<unknown>;
|
|
9
|
+
/** Deletes the value at `key`. */
|
|
10
|
+
removeItem: (key: string) => Promise<void>;
|
|
11
|
+
/** Writes `value` at `key`, without serializing it. */
|
|
12
|
+
setItem: (key: string, value: unknown) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Instantiates a {@link Storage}.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const storage = Storage.from({
|
|
20
|
+
* getItem: (key) => idb.get(key),
|
|
21
|
+
* removeItem: (key) => idb.del(key),
|
|
22
|
+
* setItem: (key, value) => idb.set(key, value),
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function from(value: Storage): Storage;
|
package/dist/Storage.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instantiates a {@link Storage}.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const storage = Storage.from({
|
|
7
|
+
* getItem: (key) => idb.get(key),
|
|
8
|
+
* removeItem: (key) => idb.del(key),
|
|
9
|
+
* setItem: (key, value) => idb.set(key, value),
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function from(value) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One of a user's Tempo Accounts.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** One of the user's Tempo Accounts. */
|
|
6
|
+
export type TempoAccount = {
|
|
7
|
+
/** The account's address, the same on every Tempo chain. */
|
|
8
|
+
address: `0x${string}`;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Instantiates a {@link TempoAccount}.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const tempoAccount = TempoAccount.from({ address: '0x…' })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function from(value: TempoAccount): TempoAccount;
|
package/dist/Tokens.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's tokens for Tempo APIs.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** The app's tokens for Tempo APIs. */
|
|
6
|
+
export type Tokens = {
|
|
7
|
+
/** The Bearer token Tempo APIs accept. */
|
|
8
|
+
accessToken: string;
|
|
9
|
+
/** When the access token expires, in milliseconds. */
|
|
10
|
+
expiresAt: number;
|
|
11
|
+
/** The OIDC ID token, which names the user. A refresh may omit it. */
|
|
12
|
+
idToken?: string | undefined;
|
|
13
|
+
/** Exchanges for new tokens through `Actions.refresh`. It rotates on every refresh. */
|
|
14
|
+
refreshToken?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Instantiates a {@link Tokens}.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const tokens = Tokens.from({ ...saved, ...(await Actions.refresh(auth, { refreshToken })) })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function from(value: Tokens): Tokens;
|
package/dist/Tokens.js
ADDED
package/dist/User.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in user.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** The signed-in user. */
|
|
6
|
+
export type User = {
|
|
7
|
+
/** The user's verified email address. */
|
|
8
|
+
email: string;
|
|
9
|
+
/** The user's ID, the `sub` of every token. */
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Instantiates a {@link User}.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const user = User.from({ email: claims.email, id: claims.sub })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function from(value: User): User;
|
package/dist/User.js
ADDED
package/dist/actions/device.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Account } from 'viem/tempo';
|
|
2
|
-
import { type Auth
|
|
2
|
+
import { type Auth } from '../Auth.ts';
|
|
3
|
+
import type { Authorization } from '../Authorization.ts';
|
|
4
|
+
import type { Permissions } from '../Permissions.ts';
|
|
3
5
|
/**
|
|
4
6
|
* Starts the device grant for a CLI: the user approves `userCode` at `verificationUri` from any
|
|
5
7
|
* browser, and `wait` resolves once they do.
|
package/dist/actions/device.js
CHANGED
package/dist/actions/email.d.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { Account } from 'viem/tempo';
|
|
6
|
-
import type { Auth
|
|
6
|
+
import type { Auth } from '../Auth.ts';
|
|
7
|
+
import type { Authorization } from '../Authorization.ts';
|
|
8
|
+
import type { Permissions } from '../Permissions.ts';
|
|
9
|
+
import type { Step } from '../Step.ts';
|
|
7
10
|
/**
|
|
8
11
|
* Emails the user a sign-in code. The response is the same for every address.
|
|
9
12
|
*
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* own sign-in buttons.
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Auth
|
|
6
|
+
import type { Auth } from '../Auth.ts';
|
|
7
|
+
import type { Provider } from '../Provider.ts';
|
|
7
8
|
/**
|
|
8
9
|
* Lists the OAuth providers Tempo Auth offers, for an app that shows its own sign-in buttons.
|
|
9
10
|
*
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Account } from 'viem/tempo';
|
|
2
|
-
import { type Auth
|
|
2
|
+
import { type Auth } from '../Auth.ts';
|
|
3
|
+
import type { Authorization } from '../Authorization.ts';
|
|
4
|
+
import * as Pending from '../Pending.ts';
|
|
5
|
+
import type { Permissions } from '../Permissions.ts';
|
|
3
6
|
/**
|
|
4
7
|
* Finishes a {@link start} when the page loads with Tempo Auth's callback, and returns `undefined`
|
|
5
8
|
* otherwise. The code is redeemed once, however often the page calls this.
|
|
@@ -22,7 +25,7 @@ export declare namespace complete {
|
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* Returns the URL that signs the user in on Tempo Auth's pages and redirects back with a code,
|
|
25
|
-
* and the
|
|
28
|
+
* and the `Pending` state to keep until then, such as in a sealed cookie.
|
|
26
29
|
* {@link handleCallback} redeems the code for the tokens and the key authorization.
|
|
27
30
|
*
|
|
28
31
|
* @example
|
|
@@ -50,7 +53,7 @@ export declare namespace createUrl {
|
|
|
50
53
|
};
|
|
51
54
|
type ReturnType = {
|
|
52
55
|
/** What to keep until the callback, such as in a sealed cookie. */
|
|
53
|
-
pending: Pending;
|
|
56
|
+
pending: Pending.Pending;
|
|
54
57
|
/** Where to send the browser. */
|
|
55
58
|
url: string;
|
|
56
59
|
};
|
|
@@ -73,7 +76,7 @@ export declare namespace handleCallback {
|
|
|
73
76
|
/** The key the app passed to `createUrl`, if it supplied one. */
|
|
74
77
|
accessKey?: Account.Account | undefined;
|
|
75
78
|
/** What `createUrl` returned to keep. */
|
|
76
|
-
pending: Pending;
|
|
79
|
+
pending: Pending.Pending;
|
|
77
80
|
/** The callback URL Tempo Auth redirected to. */
|
|
78
81
|
url: string | URL;
|
|
79
82
|
};
|
package/dist/actions/redirect.js
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
import { Base64, Bytes, Hash } from 'ox';
|
|
8
|
-
import { RequestError
|
|
8
|
+
import { RequestError } from '../Auth.js';
|
|
9
9
|
import * as AccessKey from '../internal/accessKey.js';
|
|
10
10
|
import * as Api from '../internal/api.js';
|
|
11
11
|
import * as IndexedDb from '../internal/indexedDb.js';
|
|
12
12
|
import { request } from '../internal/request.js';
|
|
13
|
+
import * as Pending from '../Pending.js';
|
|
13
14
|
/**
|
|
14
15
|
* Finishes a {@link start} when the page loads with Tempo Auth's callback, and returns `undefined`
|
|
15
16
|
* otherwise. The code is redeemed once, however often the page calls this.
|
|
@@ -46,7 +47,7 @@ export function complete(auth, options = {}) {
|
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* Returns the URL that signs the user in on Tempo Auth's pages and redirects back with a code,
|
|
49
|
-
* and the
|
|
50
|
+
* and the `Pending` state to keep until then, such as in a sealed cookie.
|
|
50
51
|
* {@link handleCallback} redeems the code for the tokens and the key authorization.
|
|
51
52
|
*
|
|
52
53
|
* @example
|
|
@@ -62,13 +63,13 @@ export function complete(auth, options = {}) {
|
|
|
62
63
|
export async function createUrl(auth, options) {
|
|
63
64
|
const redirectUri = options.redirectUri ?? auth.redirectUri ?? `${window.location.origin}/`;
|
|
64
65
|
const key = await AccessKey.resolve(options.accessKey);
|
|
65
|
-
const pending = {
|
|
66
|
+
const pending = Pending.from({
|
|
66
67
|
...key.material,
|
|
67
68
|
redirectUri,
|
|
68
69
|
// `Bytes.random` needs only `crypto.getRandomValues`, which React Native polyfills.
|
|
69
70
|
state: Base64.fromBytes(Bytes.random(16), base64url),
|
|
70
71
|
verifier: Base64.fromBytes(Bytes.random(32), base64url),
|
|
71
|
-
};
|
|
72
|
+
});
|
|
72
73
|
const { client_id, keyAuthorization, scope } = request(auth, {
|
|
73
74
|
accessKey: key.accessKey,
|
|
74
75
|
permissions: options.permissions,
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Manages the signed-in user's Tempo Accounts.
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import type { Auth
|
|
5
|
+
import type { Auth } from '../Auth.ts';
|
|
6
|
+
import type { TempoAccount } from '../TempoAccount.ts';
|
|
6
7
|
/**
|
|
7
|
-
* Creates another Tempo Account for the signed-in user, and returns it. Pass its `address` as
|
|
8
|
-
* access key
|
|
8
|
+
* Creates another Tempo Account for the signed-in user, and returns it. Pass its `address` as the
|
|
9
|
+
* `access` of an access key to authorize keys on it.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Api from '../internal/api.js';
|
|
2
2
|
/**
|
|
3
|
-
* Creates another Tempo Account for the signed-in user, and returns it. Pass its `address` as
|
|
4
|
-
* access key
|
|
3
|
+
* Creates another Tempo Account for the signed-in user, and returns it. Pass its `address` as the
|
|
4
|
+
* `access` of an access key to authorize keys on it.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export * as Actions from './Actions.ts';
|
|
2
2
|
export * as Auth from './Auth.ts';
|
|
3
|
+
export * as Authorization from './Authorization.ts';
|
|
3
4
|
export * as Key from './Key.ts';
|
|
5
|
+
export * as Pending from './Pending.ts';
|
|
6
|
+
export * as Permissions from './Permissions.ts';
|
|
7
|
+
export * as Provider from './Provider.ts';
|
|
8
|
+
export * as Step from './Step.ts';
|
|
9
|
+
export * as Storage from './Storage.ts';
|
|
10
|
+
export * as TempoAccount from './TempoAccount.ts';
|
|
11
|
+
export * as Tokens from './Tokens.ts';
|
|
12
|
+
export * as User from './User.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
// biome-ignore lint/performance/noBarrelFile: entrypoint module
|
|
2
2
|
export * as Actions from './Actions.js';
|
|
3
3
|
export * as Auth from './Auth.js';
|
|
4
|
+
export * as Authorization from './Authorization.js';
|
|
4
5
|
export * as Key from './Key.js';
|
|
6
|
+
export * as Pending from './Pending.js';
|
|
7
|
+
export * as Permissions from './Permissions.js';
|
|
8
|
+
export * as Provider from './Provider.js';
|
|
9
|
+
export * as Step from './Step.js';
|
|
10
|
+
export * as Storage from './Storage.js';
|
|
11
|
+
export * as TempoAccount from './TempoAccount.js';
|
|
12
|
+
export * as Tokens from './Tokens.js';
|
|
13
|
+
export * as User from './User.js';
|
package/dist/internal/api.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { KeyAuthorization } from 'ox/tempo';
|
|
2
2
|
import type { Account } from 'viem/tempo';
|
|
3
|
-
import { type Auth
|
|
3
|
+
import { type Auth } from '../Auth.ts';
|
|
4
|
+
import type { Authorization } from '../Authorization.ts';
|
|
4
5
|
import * as Key from '../Key.ts';
|
|
6
|
+
import type { Tokens } from '../Tokens.ts';
|
|
5
7
|
/**
|
|
6
8
|
* Builds an authorization from what Tempo Auth returned and the sign-in's key: the material the
|
|
7
9
|
* library generated, or the `accessKey` the app supplied.
|
package/dist/internal/api.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import { Base64 } from 'ox';
|
|
6
|
-
import { RequestError
|
|
6
|
+
import { RequestError } from '../Auth.js';
|
|
7
7
|
import * as Key from '../Key.js';
|
|
8
8
|
/**
|
|
9
9
|
* Builds an authorization from what Tempo Auth returned and the sign-in's key: the material the
|
|
@@ -11,11 +11,11 @@ import * as Key from '../Key.js';
|
|
|
11
11
|
*/
|
|
12
12
|
export function authorization(body, options) {
|
|
13
13
|
const { accessKey, material } = options;
|
|
14
|
-
const key = {
|
|
14
|
+
const key = Key.from({
|
|
15
15
|
...material,
|
|
16
16
|
account: body.account,
|
|
17
17
|
keyAuthorization: body.keyAuthorization,
|
|
18
|
-
};
|
|
18
|
+
});
|
|
19
19
|
const tokens_ = 'accessToken' in body.tokens ? body.tokens : tokens(body.tokens);
|
|
20
20
|
const claims = JSON.parse(Base64.toString(tokens_.idToken.split('.')[1]));
|
|
21
21
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Account } from 'viem/tempo';
|
|
2
|
-
import type { Auth
|
|
2
|
+
import type { Auth } from '../Auth.ts';
|
|
3
|
+
import type { Permissions } from '../Permissions.ts';
|
|
3
4
|
/**
|
|
4
5
|
* The authorization request and key authorization request, in Tempo Auth's wire format. An access
|
|
5
6
|
* key account names its Tempo Account through `access`, and a plain key leaves it to Tempo Auth.
|
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-27.sha-abd8f16",
|
|
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": {
|