eocene-auth-sdk 0.2.2
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/CHANGELOG.md +51 -0
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.d.ts +437 -0
- package/dist/index.js +4187 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +534 -0
- package/package.json +69 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **Brand refresh.** The auth UI wordmark rendered a pre-rename brand name;
|
|
8
|
+
it now reads "Eocene". New molecule mark (inline SVG, transparent
|
|
9
|
+
background) and accent colors aligned to the eocene.io brand palette
|
|
10
|
+
(`--auth-sdk-accent: #3b82d6`).
|
|
11
|
+
|
|
12
|
+
## 0.2.0
|
|
13
|
+
|
|
14
|
+
### Breaking
|
|
15
|
+
|
|
16
|
+
- **Signing fails closed without an approval handler.** A provider created
|
|
17
|
+
without `requestApproval` now throws (EIP-1193 `4100`) instead of silently
|
|
18
|
+
auto-approving. Use `<AuthProvider>` (built-in confirm modal) or pass
|
|
19
|
+
`requestApproval`.
|
|
20
|
+
- **`eth_sendTransaction` rejects calldata it cannot represent.** Only native
|
|
21
|
+
transfers and ERC-20 `transfer()` are supported; any other `data` throws
|
|
22
|
+
(EIP-1193 `4200`) instead of being silently dropped and sent as a bare value
|
|
23
|
+
transfer.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **Session-expiry handling.** `AuthProvider` / `AuthClient` accept
|
|
28
|
+
`onSessionExpired`; a 401 clears local + persisted state and flips
|
|
29
|
+
`authenticated` to `false`. `WaasHttpError` now classifies `session_expired`
|
|
30
|
+
and `rate_limited` (previously a 401 was misread as a password error and drove
|
|
31
|
+
the password re-prompt loop).
|
|
32
|
+
- **Multi-chain.** EIP-1193 `wallet_switchEthereumChain` + `chainChanged`;
|
|
33
|
+
`AuthClient` / config `chainId` and `EOCENE_CHAIN_ID`; `WaasClient.getBalance`
|
|
34
|
+
takes a `chainId`.
|
|
35
|
+
- **Dynamic login methods.** `AuthClient.listAvailableMethods()` and the
|
|
36
|
+
provider's `availableMethods` expose which social methods a project has
|
|
37
|
+
enabled, so the login panel renders only working buttons.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- Redesigned the sign-confirm and set-password modals: Eocene app badge,
|
|
42
|
+
gradient address avatar, labeled message card, card-style "set password"
|
|
43
|
+
upsell, primary-button spinner, and entrance animation.
|
|
44
|
+
- New label keys (`signBrandEyebrow`, `signPayloadLabel*`, `signSigning`,
|
|
45
|
+
`sessionExpired`, `rateLimited`, `loginNoMethods`) with English defaults —
|
|
46
|
+
override via `config.labels` as before.
|
|
47
|
+
|
|
48
|
+
## 0.1.0
|
|
49
|
+
|
|
50
|
+
- Initial release: OAuth/session, EIP-1193 provider, sign-confirm and
|
|
51
|
+
set-password modals, optional wallet password.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eocene
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# eocene-auth-sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/eocene-auth-sdk)
|
|
4
|
+
|
|
5
|
+
Eocene custodial WaaS product layer: OAuth/session, EIP-1193, signature confirm (optional wallet password).
|
|
6
|
+
|
|
7
|
+
**Install:** [npmjs.com/package/eocene-auth-sdk](https://www.npmjs.com/package/eocene-auth-sdk)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install eocene-auth-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { AuthProvider, useAuth, authConfigFromViteEnv } from 'eocene-auth-sdk'
|
|
15
|
+
import 'eocene-auth-sdk/styles.css'
|
|
16
|
+
|
|
17
|
+
const config = authConfigFromViteEnv(import.meta.env)
|
|
18
|
+
const { login, getConnectorShim, openPasswordSettings, passwordEnabled } = useAuth()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Docs: [https://eocene.io/docs](https://eocene.io/docs)
|
|
22
|
+
|
|
23
|
+
Environment variables (Vite):
|
|
24
|
+
|
|
25
|
+
| Key | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `EOCENE_PROJECT_ID` | Public project id from the console (required for end-user OAuth) |
|
|
28
|
+
| `EOCENE_CONTROL_URL` | Optional. Default `https://api.eocene.io`. Use `/eocene` only when proxying a local worker |
|
|
29
|
+
| `EOCENE_OAUTH_RETURN_TO` | Optional. Default `{origin}/login/eocene-callback` |
|
|
30
|
+
| `EOCENE_CHAIN_ID` | Optional. Initial EVM chain for the EIP-1193 provider. Default `1` (Ethereum). Switch at runtime with `wallet_switchEthereumChain` |
|
|
31
|
+
| `EOCENE_OAUTH_FALLBACK_DEV` | Optional. Local mock when IdP is not configured (default off) |
|
|
32
|
+
|
|
33
|
+
Production control default: `https://api.eocene.io`
|
|
34
|
+
|
|
35
|
+
## Publishing
|
|
36
|
+
|
|
37
|
+
`npm run publish:token` verifies the token, checks the version isn't already on
|
|
38
|
+
npm, publishes, and cleans up the temporary auth file. Supply the token by env
|
|
39
|
+
var (keeps it out of shell history) or as a flag — the `--` is required so npm
|
|
40
|
+
forwards it to the script:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# token as a flag (note the --)
|
|
44
|
+
npm run publish:token -- --token=npm_xxxxxxxx
|
|
45
|
+
npm run publish:token -- --token=npm_xxxxxxxx --dry-run
|
|
46
|
+
|
|
47
|
+
# or via the environment, without echoing it
|
|
48
|
+
read -rs NPM_TOKEN && export NPM_TOKEN && npm run publish:token
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The token is only exported to the npm subprocess; the temp `.npmrc` references
|
|
52
|
+
`${NPM_TOKEN}`, never the literal value.
|
|
53
|
+
|
|
54
|
+
### Session expiry
|
|
55
|
+
|
|
56
|
+
Sessions are short-lived and cannot be refreshed. Route the user back to login
|
|
57
|
+
when one expires:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<AuthProvider config={config} onSessionExpired={() => nav('/login')}>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
By the time `onSessionExpired` fires, local state is already cleared and
|
|
64
|
+
`authenticated` has flipped to `false`.
|
|
65
|
+
|
|
66
|
+
### Multi-chain
|
|
67
|
+
|
|
68
|
+
The EIP-1193 provider defaults to Ethereum mainnet and supports
|
|
69
|
+
`wallet_switchEthereumChain` / `chainChanged`. The control plane validates the
|
|
70
|
+
target chain and rejects unknown ids. Read the supported set from
|
|
71
|
+
`GET {control}/chains`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType, ReactNode, SVGProps } from 'react';
|
|
3
|
+
|
|
4
|
+
type WaasErrorCode = 'password_invalid' | 'password_locked' | 'password_required' | 'password_too_short' | 'plan_user_limit' | 'plan_project_limit' | 'session_expired' | 'rate_limited' | 'unknown';
|
|
5
|
+
type Json = Record<string, unknown>;
|
|
6
|
+
declare class WaasHttpError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly code: WaasErrorCode;
|
|
9
|
+
readonly body: Json;
|
|
10
|
+
readonly attemptsRemaining?: number;
|
|
11
|
+
readonly lockedUntil?: string;
|
|
12
|
+
readonly retryAfterSec?: number;
|
|
13
|
+
constructor(status: number, url: string, body: Json);
|
|
14
|
+
get isPasswordError(): boolean;
|
|
15
|
+
/** The session is gone — the caller has to log in again; retrying will not help. */
|
|
16
|
+
get isSessionError(): boolean;
|
|
17
|
+
}
|
|
18
|
+
declare function isWaasHttpError(e: unknown): e is WaasHttpError;
|
|
19
|
+
|
|
20
|
+
type Eip1193RequestArgs = {
|
|
21
|
+
method: string;
|
|
22
|
+
params?: unknown[] | Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
type WaasEip1193Provider = {
|
|
25
|
+
request: (args: Eip1193RequestArgs) => Promise<unknown>;
|
|
26
|
+
on?: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
27
|
+
removeListener?: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
28
|
+
};
|
|
29
|
+
type WaasSignAuthError = {
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
attemptsRemaining?: number;
|
|
33
|
+
lockedUntil?: string;
|
|
34
|
+
retryAfterSec?: number;
|
|
35
|
+
};
|
|
36
|
+
type WaasSignApprovalRequest = {
|
|
37
|
+
method: 'personal_sign' | 'eth_signTypedData_v4' | 'eth_sendTransaction';
|
|
38
|
+
address: string;
|
|
39
|
+
message: string;
|
|
40
|
+
passwordEnabled: boolean;
|
|
41
|
+
/** Set when re-prompting after a failed password / lock. */
|
|
42
|
+
authError?: WaasSignAuthError;
|
|
43
|
+
};
|
|
44
|
+
/** `true` = approve; object may carry optional wallet password. */
|
|
45
|
+
type WaasSignApprovalResult = boolean | {
|
|
46
|
+
approved: boolean;
|
|
47
|
+
password?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type WaasClientOptions = {
|
|
51
|
+
controlBaseUrl: string;
|
|
52
|
+
/**
|
|
53
|
+
* Called when the control-plane rejects the session (401). Sessions expire
|
|
54
|
+
* after an hour and cannot be refreshed, so the host has to send the user
|
|
55
|
+
* through login again.
|
|
56
|
+
*/
|
|
57
|
+
onSessionExpired?: () => void;
|
|
58
|
+
};
|
|
59
|
+
type DeviceState = {
|
|
60
|
+
sessionToken: string;
|
|
61
|
+
principalId: string;
|
|
62
|
+
email?: string;
|
|
63
|
+
walletId?: string;
|
|
64
|
+
address?: string;
|
|
65
|
+
epoch?: number;
|
|
66
|
+
passwordEnabled?: boolean;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Browser/Node SDK for custodial eocene-worker.
|
|
70
|
+
* Private key never leaves the control-plane; client holds session + address only.
|
|
71
|
+
*/
|
|
72
|
+
declare class WaasClient {
|
|
73
|
+
readonly controlBaseUrl: string;
|
|
74
|
+
private state;
|
|
75
|
+
private onSessionExpired?;
|
|
76
|
+
constructor(opts: WaasClientOptions);
|
|
77
|
+
setOnSessionExpired(fn: (() => void) | undefined): void;
|
|
78
|
+
/**
|
|
79
|
+
* Authenticated request. A 401 means the session is unusable, so the local
|
|
80
|
+
* state is dropped immediately rather than left to fail every later call.
|
|
81
|
+
*/
|
|
82
|
+
private authed;
|
|
83
|
+
getState(): DeviceState | null;
|
|
84
|
+
clearAll(): void;
|
|
85
|
+
hydrate(state: DeviceState): void;
|
|
86
|
+
loginDev(email: string, provider?: string, opts?: {
|
|
87
|
+
projectId?: string;
|
|
88
|
+
asDeveloper?: boolean;
|
|
89
|
+
}): Promise<DeviceState>;
|
|
90
|
+
loginWithSessionToken(sessionToken: string): Promise<DeviceState>;
|
|
91
|
+
fetchMe(): Promise<{
|
|
92
|
+
principalId: string;
|
|
93
|
+
email?: string;
|
|
94
|
+
wallet: {
|
|
95
|
+
walletId: string;
|
|
96
|
+
address: string;
|
|
97
|
+
epoch: number;
|
|
98
|
+
passwordEnabled: boolean;
|
|
99
|
+
} | null;
|
|
100
|
+
}>;
|
|
101
|
+
ensureWallet(): Promise<{
|
|
102
|
+
walletId: string;
|
|
103
|
+
address: string;
|
|
104
|
+
passwordEnabled: boolean;
|
|
105
|
+
}>;
|
|
106
|
+
setPassword(password: string, currentPassword?: string): Promise<void>;
|
|
107
|
+
clearPassword(password: string): Promise<void>;
|
|
108
|
+
signMessage(message: string, opts?: {
|
|
109
|
+
password?: string;
|
|
110
|
+
}): Promise<{
|
|
111
|
+
signature: string;
|
|
112
|
+
address: string;
|
|
113
|
+
digestHex: string;
|
|
114
|
+
}>;
|
|
115
|
+
signDigestHex(digestHex: string, opts?: {
|
|
116
|
+
password?: string;
|
|
117
|
+
}): Promise<{
|
|
118
|
+
signature: string;
|
|
119
|
+
address: string;
|
|
120
|
+
digestHex: string;
|
|
121
|
+
}>;
|
|
122
|
+
signTypedData(payload: {
|
|
123
|
+
domain: Record<string, unknown>;
|
|
124
|
+
types: Record<string, Array<{
|
|
125
|
+
name: string;
|
|
126
|
+
type: string;
|
|
127
|
+
}>>;
|
|
128
|
+
primaryType?: string;
|
|
129
|
+
message: Record<string, unknown>;
|
|
130
|
+
}, opts?: {
|
|
131
|
+
password?: string;
|
|
132
|
+
}): Promise<{
|
|
133
|
+
signature: string;
|
|
134
|
+
address: string;
|
|
135
|
+
digestHex: string;
|
|
136
|
+
}>;
|
|
137
|
+
transfer(params: {
|
|
138
|
+
to: string;
|
|
139
|
+
amount?: string;
|
|
140
|
+
amountRaw?: string;
|
|
141
|
+
token?: string;
|
|
142
|
+
chainId?: number;
|
|
143
|
+
password?: string;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
txHash: string;
|
|
146
|
+
from: string;
|
|
147
|
+
to: string;
|
|
148
|
+
amount: string;
|
|
149
|
+
token: string;
|
|
150
|
+
chainId: number;
|
|
151
|
+
}>;
|
|
152
|
+
getBalance(token?: string, chainId?: number): Promise<{
|
|
153
|
+
address: string;
|
|
154
|
+
token: string;
|
|
155
|
+
balance: string;
|
|
156
|
+
decimals: number;
|
|
157
|
+
symbol?: string;
|
|
158
|
+
chainId: number;
|
|
159
|
+
chainName?: string;
|
|
160
|
+
}>;
|
|
161
|
+
private requireSession;
|
|
162
|
+
private authHeaders;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type AuthSdkLabels = {
|
|
166
|
+
signMessageTitle: string;
|
|
167
|
+
signTypedDataTitle: string;
|
|
168
|
+
signBrandEyebrow: string;
|
|
169
|
+
signPayloadLabel: string;
|
|
170
|
+
signPayloadLabelTyped: string;
|
|
171
|
+
signPayloadLabelTx: string;
|
|
172
|
+
signSigning: string;
|
|
173
|
+
signConfirm: string;
|
|
174
|
+
signReject: string;
|
|
175
|
+
signPasswordLabel: string;
|
|
176
|
+
signPasswordPlaceholder: string;
|
|
177
|
+
signSetPasswordOptional: string;
|
|
178
|
+
signSetPasswordButton: string;
|
|
179
|
+
signPasswordIncorrect: string;
|
|
180
|
+
signPasswordIncorrectRemaining: string;
|
|
181
|
+
signPasswordLocked: string;
|
|
182
|
+
signPasswordRequired: string;
|
|
183
|
+
signRejected: string;
|
|
184
|
+
sessionExpired: string;
|
|
185
|
+
rateLimited: string;
|
|
186
|
+
loginTitle: string;
|
|
187
|
+
loginGoogle: string;
|
|
188
|
+
loginTwitter: string;
|
|
189
|
+
loginGithub: string;
|
|
190
|
+
loginApple: string;
|
|
191
|
+
loginConnecting: string;
|
|
192
|
+
loginError: string;
|
|
193
|
+
loginNoMethods: string;
|
|
194
|
+
oauthWorking: string;
|
|
195
|
+
oauthFailed: string;
|
|
196
|
+
oauthBack: string;
|
|
197
|
+
passwordSettingsTitle: string;
|
|
198
|
+
passwordSettingsEnabledHint: string;
|
|
199
|
+
passwordSettingsDisabledHint: string;
|
|
200
|
+
passwordSettingsChange: string;
|
|
201
|
+
passwordSettingsClear: string;
|
|
202
|
+
passwordSettingsCurrentLabel: string;
|
|
203
|
+
passwordSettingsCurrentPlaceholder: string;
|
|
204
|
+
passwordSettingsNewLabel: string;
|
|
205
|
+
passwordSettingsNewPlaceholder: string;
|
|
206
|
+
passwordSettingsConfirmLabel: string;
|
|
207
|
+
passwordSettingsConfirmPlaceholder: string;
|
|
208
|
+
passwordSettingsMismatch: string;
|
|
209
|
+
passwordSettingsCancel: string;
|
|
210
|
+
passwordSettingsSave: string;
|
|
211
|
+
passwordSettingsSaving: string;
|
|
212
|
+
passwordSettingsClearConfirm: string;
|
|
213
|
+
passwordSettingsEntry: string;
|
|
214
|
+
passwordSettingsEntryOn: string;
|
|
215
|
+
passwordSettingsEntryOff: string;
|
|
216
|
+
};
|
|
217
|
+
declare const DEFAULT_LABELS: AuthSdkLabels;
|
|
218
|
+
type SignApprovalProps = {
|
|
219
|
+
open: boolean;
|
|
220
|
+
request: WaasSignApprovalRequest | null;
|
|
221
|
+
labels: AuthSdkLabels;
|
|
222
|
+
password: string;
|
|
223
|
+
busy: boolean;
|
|
224
|
+
error: string | null;
|
|
225
|
+
locked: boolean;
|
|
226
|
+
onPasswordChange: (value: string) => void;
|
|
227
|
+
onApprove: () => void;
|
|
228
|
+
onReject: () => void;
|
|
229
|
+
/** Shown when wallet has no password yet — opens SetPasswordModal. */
|
|
230
|
+
onOpenSetPassword?: () => void;
|
|
231
|
+
};
|
|
232
|
+
type PasswordSettingsProps = {
|
|
233
|
+
open: boolean;
|
|
234
|
+
passwordEnabled: boolean;
|
|
235
|
+
labels: AuthSdkLabels;
|
|
236
|
+
busy: boolean;
|
|
237
|
+
error: string | null;
|
|
238
|
+
onSubmitSet: (password: string, currentPassword?: string) => Promise<void>;
|
|
239
|
+
onSubmitClear: (password: string) => Promise<void>;
|
|
240
|
+
onClose: () => void;
|
|
241
|
+
};
|
|
242
|
+
type LoginPanelProps = {
|
|
243
|
+
labels: AuthSdkLabels;
|
|
244
|
+
methods?: AuthSocialMethod[];
|
|
245
|
+
loadingMethod: AuthSocialMethod | null;
|
|
246
|
+
/** True while the enabled-methods list is still being fetched. */
|
|
247
|
+
loadingMethods?: boolean;
|
|
248
|
+
error: string | null;
|
|
249
|
+
onLogin: (method: AuthSocialMethod) => void;
|
|
250
|
+
};
|
|
251
|
+
type AuthSdkComponents = {
|
|
252
|
+
SignApproval?: ComponentType<SignApprovalProps>;
|
|
253
|
+
PasswordSettings?: ComponentType<PasswordSettingsProps>;
|
|
254
|
+
LoginPanel?: ComponentType<LoginPanelProps>;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
type AuthSocialMethod = 'google' | 'twitter' | 'github' | 'apple';
|
|
258
|
+
type AuthSdkConfig = {
|
|
259
|
+
controlBaseUrl: string;
|
|
260
|
+
/** Full URL control-plane redirects to after OAuth (host route). */
|
|
261
|
+
oauthReturnTo: string;
|
|
262
|
+
/**
|
|
263
|
+
* When IdP credentials are missing on control-plane, allow `loginDev`
|
|
264
|
+
* mock `{provider}@waas.local`. Default false.
|
|
265
|
+
*/
|
|
266
|
+
allowDevLoginFallback?: boolean;
|
|
267
|
+
/** Scope end-user OAuth / wallets to this project. */
|
|
268
|
+
projectId?: string;
|
|
269
|
+
/** Initial EVM chain for the EIP-1193 provider. Default 1 (Ethereum). */
|
|
270
|
+
chainId?: number;
|
|
271
|
+
/** Developer console OAuth (registers developer on callback). */
|
|
272
|
+
asDeveloper?: boolean;
|
|
273
|
+
/** sessionStorage key for session + address. */
|
|
274
|
+
storageKey?: string;
|
|
275
|
+
/** sessionStorage key for pending OAuth return path. */
|
|
276
|
+
oauthPendingKey?: string;
|
|
277
|
+
/** Override copy for default modals. */
|
|
278
|
+
labels?: Partial<AuthSdkLabels>;
|
|
279
|
+
};
|
|
280
|
+
/** Official Eocene control plane (override with EOCENE_CONTROL_URL for local /eocene proxy). */
|
|
281
|
+
declare const DEFAULT_CONTROL_BASE_URL = "https://api.eocene.io";
|
|
282
|
+
declare const DEFAULT_STORAGE_KEY = "eocene:device-state";
|
|
283
|
+
declare const DEFAULT_OAUTH_PENDING_KEY = "eocene:oauth-pending";
|
|
284
|
+
declare function resolveControlAbsoluteUrl(controlBaseUrl: string): string;
|
|
285
|
+
|
|
286
|
+
type AuthUser = {
|
|
287
|
+
principalId: string;
|
|
288
|
+
email?: string;
|
|
289
|
+
address?: string;
|
|
290
|
+
walletId?: string;
|
|
291
|
+
passwordEnabled?: boolean;
|
|
292
|
+
};
|
|
293
|
+
type AuthLoginResult = {
|
|
294
|
+
address: string;
|
|
295
|
+
walletId: string;
|
|
296
|
+
passwordEnabled: boolean;
|
|
297
|
+
provider?: string;
|
|
298
|
+
};
|
|
299
|
+
type AuthConnectorShim = {
|
|
300
|
+
getProvider: () => Promise<WaasEip1193Provider>;
|
|
301
|
+
};
|
|
302
|
+
type AuthClientOptions = {
|
|
303
|
+
config: AuthSdkConfig;
|
|
304
|
+
requestApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>;
|
|
305
|
+
/**
|
|
306
|
+
* Called when the control-plane rejects the session (401). Sessions last one
|
|
307
|
+
* hour and cannot be refreshed, so hosts should route the user back to login.
|
|
308
|
+
*/
|
|
309
|
+
onSessionExpired?: () => void;
|
|
310
|
+
/** Initial EVM chain for the EIP-1193 provider. Default 1 (Ethereum). */
|
|
311
|
+
chainId?: number;
|
|
312
|
+
};
|
|
313
|
+
declare class AuthClient {
|
|
314
|
+
readonly config: AuthSdkConfig;
|
|
315
|
+
private readonly storageKey;
|
|
316
|
+
private readonly oauthPendingKey;
|
|
317
|
+
private client;
|
|
318
|
+
private provider;
|
|
319
|
+
private chainId;
|
|
320
|
+
private active;
|
|
321
|
+
private requestApproval?;
|
|
322
|
+
private onSessionExpired?;
|
|
323
|
+
constructor(options: AuthClientOptions);
|
|
324
|
+
setRequestApproval(fn: ((req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>) | undefined): void;
|
|
325
|
+
setOnSessionExpired(fn: (() => void) | undefined): void;
|
|
326
|
+
isAuthenticated(): boolean;
|
|
327
|
+
getUser(): AuthUser | null;
|
|
328
|
+
/** Current EIP-1193 chain. Changes via wallet_switchEthereumChain. */
|
|
329
|
+
getChainId(): number;
|
|
330
|
+
getAddress(): string | undefined;
|
|
331
|
+
getWaasClient(): WaasClient;
|
|
332
|
+
getProvider(): WaasEip1193Provider;
|
|
333
|
+
getConnectorShim(): AuthConnectorShim;
|
|
334
|
+
private persist;
|
|
335
|
+
private fetchOAuthProviders;
|
|
336
|
+
/**
|
|
337
|
+
* Social login methods actually enabled for this project, in display order.
|
|
338
|
+
* Used to render only the buttons that will work; falls back to all methods
|
|
339
|
+
* if the control-plane is unreachable (login will surface a clear error).
|
|
340
|
+
*/
|
|
341
|
+
listAvailableMethods(): Promise<AuthSocialMethod[]>;
|
|
342
|
+
login(method: AuthSocialMethod): Promise<AuthLoginResult>;
|
|
343
|
+
completeOAuthFromHash(hashOrSearch: string): Promise<AuthLoginResult>;
|
|
344
|
+
takeOAuthReturnPath(): string | null;
|
|
345
|
+
markActive(on: boolean): void;
|
|
346
|
+
restoreIfNeeded(): boolean;
|
|
347
|
+
logout(): void;
|
|
348
|
+
setPassword(password: string, currentPassword?: string): Promise<void>;
|
|
349
|
+
clearPassword(password: string): Promise<void>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Thin wrapper — prefer AuthClient.getProvider(); exported for advanced hosts. */
|
|
353
|
+
declare function createAuthEip1193Provider(client: WaasClient, requestApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>): WaasEip1193Provider;
|
|
354
|
+
|
|
355
|
+
declare function AuthLoginPanel({ labels, methods, loadingMethod, loadingMethods, error, onLogin, }: LoginPanelProps): react.JSX.Element;
|
|
356
|
+
|
|
357
|
+
type AuthContextValue = {
|
|
358
|
+
ready: boolean;
|
|
359
|
+
authenticated: boolean;
|
|
360
|
+
address: string | undefined;
|
|
361
|
+
user: AuthUser | null;
|
|
362
|
+
passwordEnabled: boolean;
|
|
363
|
+
login: (args: {
|
|
364
|
+
method: AuthSocialMethod;
|
|
365
|
+
}) => Promise<AuthLoginResult>;
|
|
366
|
+
logout: () => void;
|
|
367
|
+
markActive: (on: boolean) => void;
|
|
368
|
+
restoreIfNeeded: () => boolean;
|
|
369
|
+
completeOAuthFromHash: (hashOrSearch: string) => Promise<AuthLoginResult>;
|
|
370
|
+
takeOAuthReturnPath: () => string | null;
|
|
371
|
+
getProvider: () => WaasEip1193Provider;
|
|
372
|
+
getConnectorShim: () => AuthConnectorShim;
|
|
373
|
+
setPassword: (password: string, currentPassword?: string) => Promise<void>;
|
|
374
|
+
clearPassword: (password: string) => Promise<void>;
|
|
375
|
+
openPasswordSettings: () => void;
|
|
376
|
+
closePasswordSettings: () => void;
|
|
377
|
+
client: AuthClient;
|
|
378
|
+
labels: AuthSdkLabels;
|
|
379
|
+
LoginPanel: typeof AuthLoginPanel | NonNullable<AuthSdkComponents['LoginPanel']>;
|
|
380
|
+
/** Social methods enabled for this project; null while still loading. */
|
|
381
|
+
availableMethods: AuthSocialMethod[] | null;
|
|
382
|
+
};
|
|
383
|
+
type AuthProviderProps = {
|
|
384
|
+
config: AuthSdkConfig;
|
|
385
|
+
components?: AuthSdkComponents;
|
|
386
|
+
onRequestSignApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>;
|
|
387
|
+
/**
|
|
388
|
+
* Called when the session expires (1h, not refreshable). The provider has
|
|
389
|
+
* already cleared local state and `authenticated` has flipped to false; use
|
|
390
|
+
* this to route the user back to your login screen.
|
|
391
|
+
*/
|
|
392
|
+
onSessionExpired?: () => void;
|
|
393
|
+
children: ReactNode;
|
|
394
|
+
};
|
|
395
|
+
declare function AuthProvider({ config, components, onRequestSignApproval, onSessionExpired, children, }: AuthProviderProps): react.JSX.Element;
|
|
396
|
+
declare function useAuthContext(): AuthContextValue;
|
|
397
|
+
|
|
398
|
+
type AuthOAuthCallbackProps = {
|
|
399
|
+
/** Hash or search string; defaults to `location.hash || location.search`. */
|
|
400
|
+
hashOrSearch?: string;
|
|
401
|
+
/** Called after WaaS wallet is ready (host runs agent handshake here). */
|
|
402
|
+
onWalletReady: (session: AuthLoginResult) => void | Promise<void>;
|
|
403
|
+
/** Optional custom loading / error UI. */
|
|
404
|
+
children?: (state: {
|
|
405
|
+
phase: string;
|
|
406
|
+
error: string | null;
|
|
407
|
+
}) => ReactNode;
|
|
408
|
+
onBackHref?: string;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Drop-in OAuth return handler. Completes WaaS session then calls `onWalletReady`.
|
|
412
|
+
* Host is responsible for agent login / navigation.
|
|
413
|
+
*/
|
|
414
|
+
declare function AuthOAuthCallback({ hashOrSearch, onWalletReady, children, onBackHref, }: AuthOAuthCallbackProps): react.JSX.Element;
|
|
415
|
+
|
|
416
|
+
/** Build AuthSdkConfig from Vite `import.meta.env`. Defaults to official api.eocene.io. */
|
|
417
|
+
declare function authConfigFromViteEnv(env?: object): AuthSdkConfig;
|
|
418
|
+
|
|
419
|
+
declare function SignConfirmModal({ open, request, labels, password, busy, error, locked, onPasswordChange, onApprove, onReject, onOpenSetPassword, }: SignApprovalProps): react.JSX.Element | null;
|
|
420
|
+
|
|
421
|
+
declare function SetPasswordModal({ open, passwordEnabled, labels, busy, error, onSubmitSet, onSubmitClear, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Eocene molecule mark — three linked droplet chains + node, from the 2026
|
|
425
|
+
* brand refresh. Inline for npm consumers (no asset fetch); transparent
|
|
426
|
+
* background so it sits on either theme.
|
|
427
|
+
*/
|
|
428
|
+
declare function EoceneMark({ size, title, ...props }: SVGProps<SVGSVGElement> & {
|
|
429
|
+
size?: number;
|
|
430
|
+
title?: string;
|
|
431
|
+
}): react.JSX.Element;
|
|
432
|
+
declare function EoceneWordmark({ className, markSize, }: {
|
|
433
|
+
className?: string;
|
|
434
|
+
markSize?: number;
|
|
435
|
+
}): react.JSX.Element;
|
|
436
|
+
|
|
437
|
+
export { AuthClient, type AuthConnectorShim, type AuthContextValue, AuthLoginPanel, type AuthLoginResult, AuthOAuthCallback, type AuthOAuthCallbackProps, AuthProvider, type AuthProviderProps, type AuthSdkComponents, type AuthSdkConfig, type AuthSdkLabels, type AuthSocialMethod, type AuthUser, DEFAULT_CONTROL_BASE_URL, DEFAULT_LABELS, DEFAULT_OAUTH_PENDING_KEY, DEFAULT_STORAGE_KEY, EoceneMark, EoceneWordmark, type LoginPanelProps, type PasswordSettingsProps, SetPasswordModal, type SignApprovalProps, SignConfirmModal, type WaasEip1193Provider, WaasHttpError, type WaasSignApprovalRequest, type WaasSignApprovalResult, type WaasSignAuthError, authConfigFromViteEnv, createAuthEip1193Provider, isWaasHttpError, resolveControlAbsoluteUrl, useAuthContext as useAuth };
|