@aithos/sdk 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +159 -0
- package/dist/src/auth-api.d.ts +105 -0
- package/dist/src/auth-api.js +178 -0
- package/dist/src/auth.d.ts +359 -68
- package/dist/src/auth.js +1035 -69
- package/dist/src/compute.d.ts +221 -9
- package/dist/src/compute.js +293 -16
- package/dist/src/data-schema-contacts-v1.d.ts +14 -0
- package/dist/src/data-schema-contacts-v1.js +28 -0
- package/dist/src/data.d.ts +97 -0
- package/dist/src/data.js +634 -0
- package/dist/src/endpoints.d.ts +9 -0
- package/dist/src/endpoints.js +5 -0
- package/dist/src/ethos.d.ts +202 -1
- package/dist/src/ethos.js +821 -16
- package/dist/src/index.d.ts +15 -6
- package/dist/src/index.js +36 -9
- package/dist/src/internal/delegate-bundle.d.ts +18 -0
- package/dist/src/internal/delegate-bundle.js +94 -0
- package/dist/src/internal/delegate-state.d.ts +45 -0
- package/dist/src/internal/delegate-state.js +120 -0
- package/dist/src/internal/owner-signers.d.ts +78 -0
- package/dist/src/internal/owner-signers.js +179 -0
- package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
- package/dist/src/internal/protocol-client-bridge.js +20 -0
- package/dist/src/internal/recovery-file.d.ts +29 -0
- package/dist/src/internal/recovery-file.js +98 -0
- package/dist/src/internal/signer.d.ts +59 -0
- package/dist/src/internal/signer.js +86 -0
- package/dist/src/key-store.d.ts +128 -0
- package/dist/src/key-store.js +244 -0
- package/dist/src/mandates.d.ts +163 -1
- package/dist/src/mandates.js +286 -8
- package/dist/src/sdk.d.ts +39 -3
- package/dist/src/sdk.js +36 -23
- package/dist/src/session-store.d.ts +58 -0
- package/dist/src/session-store.js +158 -0
- package/dist/src/wallet.d.ts +4 -6
- package/dist/src/wallet.js +18 -8
- package/dist/src/web.d.ts +279 -0
- package/dist/src/web.js +186 -0
- package/dist/test/auth-j3.test.d.ts +2 -0
- package/dist/test/auth-j3.test.js +391 -0
- package/dist/test/compute-delegate-path.test.d.ts +2 -0
- package/dist/test/compute-delegate-path.test.js +183 -0
- package/dist/test/compute.test.js +26 -11
- package/dist/test/endpoints.test.js +20 -1
- package/dist/test/ethos-first-edition.test.d.ts +2 -0
- package/dist/test/ethos-first-edition.test.js +248 -0
- package/dist/test/ethos.test.d.ts +2 -0
- package/dist/test/ethos.test.js +219 -0
- package/dist/test/key-store.test.d.ts +2 -0
- package/dist/test/key-store.test.js +161 -0
- package/dist/test/mandates-compute.test.d.ts +2 -0
- package/dist/test/mandates-compute.test.js +256 -0
- package/dist/test/mandates.test.d.ts +2 -0
- package/dist/test/mandates.test.js +93 -0
- package/dist/test/sdk.test.js +70 -30
- package/dist/test/signer.test.d.ts +2 -0
- package/dist/test/signer.test.js +117 -0
- package/dist/test/signup-bootstrap.test.d.ts +2 -0
- package/dist/test/signup-bootstrap.test.js +222 -0
- package/dist/test/wallet.test.js +20 -9
- package/dist/test/web.test.d.ts +2 -0
- package/dist/test/web.test.js +270 -0
- package/package.json +5 -4
package/dist/src/auth.d.ts
CHANGED
|
@@ -1,116 +1,407 @@
|
|
|
1
|
+
import { type AithosSessionStore } from "./session-store.js";
|
|
2
|
+
import { type AithosKeyStore } from "./key-store.js";
|
|
3
|
+
import { DelegateActor } from "./internal/delegate-state.js";
|
|
4
|
+
import { OwnerSigners } from "./internal/owner-signers.js";
|
|
1
5
|
/** Default URL of the Aithos auth backend. */
|
|
2
6
|
export declare const DEFAULT_AUTH_BASE_URL = "https://auth.aithos.be";
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
*/
|
|
7
|
+
/** Default URL of the Aithos primitives API (publish_identity, publish_ethos_edition, etc.). */
|
|
8
|
+
export declare const DEFAULT_API_BASE_URL = "https://api.aithos.be";
|
|
6
9
|
export interface AithosAuthConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Base URL of the Aithos auth backend. Defaults to
|
|
9
|
-
* {@link DEFAULT_AUTH_BASE_URL}. Override for staging or self-hosted
|
|
10
|
-
* deployments.
|
|
11
|
-
*/
|
|
12
10
|
readonly authBaseUrl?: string;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* Base URL of the Aithos primitives API (`api.aithos.be`). Used by
|
|
13
|
+
* {@link AithosAuth.signUp} to bootstrap the user's Ethos via
|
|
14
|
+
* `aithos.publish_identity` after the auth account is created. Override
|
|
15
|
+
* for staging or self-hosted deployments. Defaults to
|
|
16
|
+
* {@link DEFAULT_API_BASE_URL}.
|
|
16
17
|
*/
|
|
18
|
+
readonly apiBaseUrl?: string;
|
|
17
19
|
readonly fetch?: typeof fetch;
|
|
18
|
-
/**
|
|
19
|
-
* Optional `window`-like object. Defaults to `globalThis.window` when
|
|
20
|
-
* available. Provided so node-side tests can assert redirect URLs without
|
|
21
|
-
* shimming jsdom.
|
|
22
|
-
*/
|
|
23
20
|
readonly window?: Pick<Window, "location" | "history">;
|
|
21
|
+
/** Pluggable JWT-session storage. Defaults to {@link defaultSessionStore}. */
|
|
22
|
+
readonly sessionStore?: AithosSessionStore;
|
|
23
|
+
/** Pluggable key persistence. Defaults to {@link defaultKeyStore}. */
|
|
24
|
+
readonly keyStore?: AithosKeyStore;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* mapping layer and keeps the SDK transparent if the user opens the
|
|
31
|
-
* Network panel.
|
|
27
|
+
* Active Aithos session. Returned by JWT-backed entry points
|
|
28
|
+
* (`signIn`, `signUp`, `handleCallback`). Recovery-file and mandate
|
|
29
|
+
* sign-ins do NOT return an `AithosSession` — they yield the lighter
|
|
30
|
+
* {@link OwnerInfo} / {@link DelegateInfo}.
|
|
32
31
|
*/
|
|
33
32
|
export interface AithosSession {
|
|
34
|
-
/** HS256 JWT — send in `Authorization: Bearer <session>` to auth/* and
|
|
35
|
-
* app endpoints that consume it. */
|
|
36
33
|
readonly session: string;
|
|
37
|
-
/** JWT expiry, Unix seconds. */
|
|
38
34
|
readonly exp: number;
|
|
39
|
-
/** Aithos DID — `did:aithos:z…`. Stable across all the user's devices. */
|
|
40
35
|
readonly did: string;
|
|
41
|
-
/** User-visible handle (rendered as `@handle`). */
|
|
42
36
|
readonly handle: string;
|
|
43
|
-
/** Encrypted vault, base64. Empty string + version 0 on first sign-in. */
|
|
44
37
|
readonly blob_b64: string;
|
|
45
|
-
/** AES-GCM nonce for the blob, base64 (12 bytes). Empty on first sign-in. */
|
|
46
38
|
readonly blob_nonce_b64: string;
|
|
47
|
-
/** Monotonic blob version. Bumped on every PUT /auth/blob. */
|
|
48
39
|
readonly blob_version: number;
|
|
49
|
-
/** 32-byte vault key, base64. Decrypts {@link blob_b64} via AES-GCM-256. */
|
|
50
40
|
readonly enc_key_b64: string;
|
|
51
|
-
/** True the first time this user signs in. The app should run its
|
|
52
|
-
* onboarding flow rather than mounting an empty blob. */
|
|
53
41
|
readonly is_first_login: boolean;
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
|
-
*
|
|
44
|
+
* Public information about the loaded owner identity. Available after
|
|
45
|
+
* any owner-side sign-in (password, Google, recovery), regardless of
|
|
46
|
+
* whether a JWT is also present.
|
|
57
47
|
*/
|
|
48
|
+
export interface OwnerInfo {
|
|
49
|
+
readonly did: string;
|
|
50
|
+
readonly handle: string;
|
|
51
|
+
readonly displayName: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Public information about a delegate session held by the SDK. Returned
|
|
55
|
+
* by `importMandate` and `getDelegates`.
|
|
56
|
+
*/
|
|
57
|
+
export interface DelegateInfo {
|
|
58
|
+
readonly mandateId: string;
|
|
59
|
+
readonly subjectDid: string;
|
|
60
|
+
readonly granteeId: string;
|
|
61
|
+
readonly scopes: readonly string[];
|
|
62
|
+
/** ISO-8601, or null when the mandate has no `not_after`. */
|
|
63
|
+
readonly expiresAt: string | null;
|
|
64
|
+
readonly label?: string;
|
|
65
|
+
}
|
|
58
66
|
export interface SignInWithGoogleOptions {
|
|
59
67
|
/**
|
|
60
|
-
* Opaque
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* can restore that route after the redirect chain.
|
|
64
|
-
*
|
|
65
|
-
* Maximum 1024 characters.
|
|
68
|
+
* Opaque state the consumer app wants to recover after the OAuth
|
|
69
|
+
* round-trip (e.g. a deep-link to resume on). Echoed back as
|
|
70
|
+
* `?app_state=` on the final redirect.
|
|
66
71
|
*/
|
|
67
72
|
readonly appState?: string;
|
|
73
|
+
/**
|
|
74
|
+
* App id registered in the Aithos `aithos-auth-apps` table. When set
|
|
75
|
+
* together with {@link returnTo}, the auth backend redirects the
|
|
76
|
+
* browser to {@link returnTo} (post Google + Aithos sign-in) instead
|
|
77
|
+
* of the legacy hard-coded `app.aithos.be/auth/callback`.
|
|
78
|
+
*
|
|
79
|
+
* The pair is required together: the backend rejects half-presence
|
|
80
|
+
* with `sso_app_redirect_pair_required`. Use it for any consumer app
|
|
81
|
+
* other than the canonical `app.aithos.be` (typically your own
|
|
82
|
+
* domain in prod, `http://localhost:<port>/auth/callback` in dev).
|
|
83
|
+
*/
|
|
84
|
+
readonly appId?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Where the auth backend should 302 the browser back to after a
|
|
87
|
+
* successful Google sign-in. MUST be on the app's
|
|
88
|
+
* `allowed_redirect_uris` allowlist (registered with Aithos out of
|
|
89
|
+
* band; see {@link appId}). Exact-match — wildcards rejected.
|
|
90
|
+
*/
|
|
91
|
+
readonly returnTo?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface SignInInput {
|
|
94
|
+
readonly email: string;
|
|
95
|
+
readonly password: string;
|
|
96
|
+
}
|
|
97
|
+
export interface SignUpInput {
|
|
98
|
+
readonly email: string;
|
|
99
|
+
readonly password: string;
|
|
100
|
+
readonly handle: string;
|
|
101
|
+
readonly displayName?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface SignUpResult {
|
|
104
|
+
readonly session: AithosSession;
|
|
105
|
+
readonly recoveryFile: Blob;
|
|
106
|
+
readonly recoveryFilename: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Input to {@link AithosAuth.completeSsoFirstLogin}. The handle is
|
|
110
|
+
* required (the auth backend pre-generated one from the user's email
|
|
111
|
+
* local-part, available on the session payload — we re-confirm it
|
|
112
|
+
* here so the user can edit before commit).
|
|
113
|
+
*/
|
|
114
|
+
export interface CompleteSsoFirstLoginInput {
|
|
115
|
+
readonly handle: string;
|
|
116
|
+
readonly displayName?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Result of {@link AithosAuth.completeSsoFirstLogin}. Returns a recovery
|
|
120
|
+
* file just like signUp — even though the user authenticated via Google,
|
|
121
|
+
* the freshly-generated Ed25519 seeds are the only material that can
|
|
122
|
+
* sign Aithos artifacts; without the recovery file, losing access to
|
|
123
|
+
* the Google account means losing the ethos forever.
|
|
124
|
+
*/
|
|
125
|
+
export interface CompleteSsoFirstLoginResult {
|
|
126
|
+
readonly session: AithosSession;
|
|
127
|
+
readonly recoveryFile: Blob;
|
|
128
|
+
readonly recoveryFilename: string;
|
|
129
|
+
}
|
|
130
|
+
export interface SignInWithRecoveryInput {
|
|
131
|
+
/** Recovery file as a Blob (browser File input) or already-decoded JSON string. */
|
|
132
|
+
readonly file: Blob | string;
|
|
133
|
+
}
|
|
134
|
+
export interface ImportMandateInput {
|
|
135
|
+
/** Delegate bundle as a Blob or already-decoded JSON string. */
|
|
136
|
+
readonly bundle: Blob | string;
|
|
68
137
|
}
|
|
69
138
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
139
|
+
* Input to {@link AithosAuth.signUpCustodial}. Server-side only — the
|
|
140
|
+
* API key MUST stay off the browser (it grants account-creation
|
|
141
|
+
* authority under your app's name). Typical use site: your app's
|
|
142
|
+
* backend in response to a sign-up form submission.
|
|
73
143
|
*/
|
|
144
|
+
export interface CustodialSignUpInput {
|
|
145
|
+
/** Bearer API key issued to your app (`aithos_<env>_<32b58>`). */
|
|
146
|
+
readonly apiKey: string;
|
|
147
|
+
/** Email address of the new user. Will receive the welcome mail. */
|
|
148
|
+
readonly email: string;
|
|
149
|
+
/** Optional display name. Capped at 200 chars by the backend. */
|
|
150
|
+
readonly displayName?: string;
|
|
151
|
+
/** Optional handle hint. Backend may sanitise or replace. */
|
|
152
|
+
readonly handleHint?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Result of {@link AithosAuth.signUpCustodial}. The raw password is
|
|
156
|
+
* NEVER returned in this response — it lives only in the welcome email
|
|
157
|
+
* sent to the user via SES. `mailSent: false` means the account row
|
|
158
|
+
* was created but the email handoff to SES failed; the operator can
|
|
159
|
+
* trigger a manual resend.
|
|
160
|
+
*/
|
|
161
|
+
export interface CustodialSignUpResult {
|
|
162
|
+
readonly userId: string;
|
|
163
|
+
readonly did: string;
|
|
164
|
+
readonly handle: string;
|
|
165
|
+
readonly email: string;
|
|
166
|
+
readonly mailSent: boolean;
|
|
167
|
+
readonly mailMessageId?: string;
|
|
168
|
+
}
|
|
169
|
+
export interface CustodialSignInInput {
|
|
170
|
+
readonly email: string;
|
|
171
|
+
readonly password: string;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Active custodial session. Same JWT-backed shape as {@link AithosSession}
|
|
175
|
+
* but adds a `passwordMustChange` flag the UI can honour to nudge the
|
|
176
|
+
* user toward a `requestPasswordReset` on first login.
|
|
177
|
+
*/
|
|
178
|
+
export interface CustodialSignInResult {
|
|
179
|
+
readonly session: AithosSession;
|
|
180
|
+
readonly passwordMustChange: boolean;
|
|
181
|
+
}
|
|
182
|
+
export interface RequestPasswordResetInput {
|
|
183
|
+
readonly email: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Input to {@link AithosAuth.applyPasswordReset}. Finalises a password
|
|
187
|
+
* reset started by {@link AithosAuth.requestPasswordReset}. The `email`
|
|
188
|
+
* and `token` come straight from the magic-link URL that landed in the
|
|
189
|
+
* user's inbox (`?email=…&token=…`); the `newPassword` is what the user
|
|
190
|
+
* just typed in the reset page.
|
|
191
|
+
*/
|
|
192
|
+
export interface ApplyPasswordResetInput {
|
|
193
|
+
/** Email address whose password is being reset. */
|
|
194
|
+
readonly email: string;
|
|
195
|
+
/** Raw reset token extracted from the magic-link URL query string. */
|
|
196
|
+
readonly token: string;
|
|
197
|
+
/** New password — must satisfy the backend's policy (≥ 10 chars). */
|
|
198
|
+
readonly newPassword: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Result of {@link AithosAuth.applyPasswordReset}. Carries a fresh JWT
|
|
202
|
+
* session so the UI can either redirect to a "you're now signed in"
|
|
203
|
+
* landing or prompt the user to sign in explicitly with their new
|
|
204
|
+
* credentials — same {@link CustodialSignInResult} shape as a normal
|
|
205
|
+
* sign-in.
|
|
206
|
+
*
|
|
207
|
+
* Note: unlike {@link signInCustodial}, this DOES NOT hydrate the local
|
|
208
|
+
* keystore. The reset path on the auth Lambda re-wraps the seed bundle
|
|
209
|
+
* with KMS but doesn't return it (the user just typed a password — they
|
|
210
|
+
* still need to sign in once to materialise the seeds locally). The
|
|
211
|
+
* {@link AithosSession} returned here lets the app store the JWT and
|
|
212
|
+
* call {@link signInCustodial} to complete hydration.
|
|
213
|
+
*/
|
|
214
|
+
export interface ApplyPasswordResetResult {
|
|
215
|
+
readonly session: AithosSession;
|
|
216
|
+
}
|
|
74
217
|
export declare class AithosAuth {
|
|
75
|
-
|
|
218
|
+
#private;
|
|
76
219
|
readonly authBaseUrl: string;
|
|
77
|
-
|
|
78
|
-
private readonly win;
|
|
220
|
+
readonly apiBaseUrl: string;
|
|
79
221
|
constructor(config?: AithosAuthConfig);
|
|
80
222
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
223
|
+
* Reload signing material and JWT session from the configured stores.
|
|
224
|
+
* Must be called once at app boot before relying on
|
|
225
|
+
* {@link getCurrentSession} / {@link getOwnerInfo} / {@link canSignAsOwner}
|
|
226
|
+
* — until then they reflect only what's been done in-memory in the
|
|
227
|
+
* current tab.
|
|
84
228
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
229
|
+
* Strict consistency: if the JWT and the stored owner disagree about
|
|
230
|
+
* who's signed in, both are wiped and the user re-auths. JWT-less
|
|
231
|
+
* owner state (loaded from keyStore but no JWT) is a valid resumed
|
|
232
|
+
* state — the user signed in via recovery or imported a mandate at
|
|
233
|
+
* some earlier moment and never went through the JWT flow.
|
|
87
234
|
*/
|
|
88
|
-
|
|
235
|
+
resume(): Promise<void>;
|
|
236
|
+
/** JWT-backed session. Null when signed in via recovery / mandate / not at all. */
|
|
237
|
+
getCurrentSession(): AithosSession | null;
|
|
238
|
+
/** Loaded owner identity. Independent of JWT presence. */
|
|
239
|
+
getOwnerInfo(): OwnerInfo | null;
|
|
240
|
+
getDelegates(): readonly DelegateInfo[];
|
|
241
|
+
canSignAsOwner(): boolean;
|
|
242
|
+
canSignAsDelegateFor(did: string): boolean;
|
|
89
243
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* `history.replaceState` so a page refresh doesn't replay the redeem
|
|
94
|
-
* (which would 410 anyway).
|
|
244
|
+
* Internal accessor used by sibling SDK namespaces (compute, wallet,
|
|
245
|
+
* ethos) when they need to sign on behalf of the owner. Returns null
|
|
246
|
+
* if no owner is loaded.
|
|
95
247
|
*
|
|
96
|
-
*
|
|
97
|
-
* page load. Throws {@link AithosSDKError} on backend errors or when
|
|
98
|
-
* the URL carries `aithos_error=…` (Google denial, token-exchange
|
|
99
|
-
* failure, etc.).
|
|
248
|
+
* @internal
|
|
100
249
|
*/
|
|
101
|
-
|
|
250
|
+
_getOwnerSigners(): OwnerSigners | null;
|
|
102
251
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* the code out of the URL via their own router.
|
|
252
|
+
* Internal accessor — looks up an active delegate by mandate id.
|
|
253
|
+
* @internal
|
|
106
254
|
*/
|
|
255
|
+
_getDelegateActor(mandateId: string): DelegateActor | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Internal accessor — finds the first active delegate whose subject
|
|
258
|
+
* matches `did`. Used by `sdk.ethos.of(did)` when the user holds a
|
|
259
|
+
* mandate for that subject.
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
_findDelegateForSubject(did: string): DelegateActor | undefined;
|
|
263
|
+
signIn(input: SignInInput): Promise<AithosSession>;
|
|
264
|
+
signUp(input: SignUpInput): Promise<SignUpResult>;
|
|
265
|
+
/**
|
|
266
|
+
* Sign in by uploading a recovery file. Hydrates the owner signers
|
|
267
|
+
* locally — no JWT is obtained on this path because the recovery
|
|
268
|
+
* file alone doesn't authenticate against the auth backend (no
|
|
269
|
+
* password, no Google session). Apps that need compute/wallet
|
|
270
|
+
* access should follow up with an email+password sign-in or with
|
|
271
|
+
* Google SSO.
|
|
272
|
+
*
|
|
273
|
+
* The recovery file is ALWAYS the file produced by `signUp` (or the
|
|
274
|
+
* equivalent one emitted by `protocol-client`'s `runOnboarding`).
|
|
275
|
+
* Both shapes are accepted.
|
|
276
|
+
*/
|
|
277
|
+
signInWithRecovery(input: SignInWithRecoveryInput): Promise<OwnerInfo>;
|
|
278
|
+
/**
|
|
279
|
+
* Import a delegate bundle (`.aithos-delegate.json`). Works in any
|
|
280
|
+
* state: with no owner loaded (delegate-only session), or alongside
|
|
281
|
+
* an existing owner (the user holds mandates for other people's
|
|
282
|
+
* ethoses while also being an owner themselves).
|
|
283
|
+
*/
|
|
284
|
+
importMandate(input: ImportMandateInput): Promise<DelegateInfo>;
|
|
285
|
+
removeMandate(mandateId: string): Promise<void>;
|
|
286
|
+
signInWithGoogle(opts?: SignInWithGoogleOptions): never;
|
|
287
|
+
/**
|
|
288
|
+
* Public entrypoint — dedupes concurrent calls (React StrictMode).
|
|
289
|
+
* The first call kicks off the actual exchange; subsequent calls
|
|
290
|
+
* before that promise resolves return the SAME promise so they all
|
|
291
|
+
* receive the same `AithosSession | null`. Otherwise StrictMode's
|
|
292
|
+
* second invocation would race against the URL clean done by the
|
|
293
|
+
* first call and resolve to `null`, robbing the AuthCallback page
|
|
294
|
+
* of the session it actually obtained.
|
|
295
|
+
*/
|
|
296
|
+
handleCallback(): Promise<AithosSession | null>;
|
|
107
297
|
exchange(aithosCode: string): Promise<AithosSession>;
|
|
108
298
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
299
|
+
* Finish the first-time Google SSO bootstrap. After
|
|
300
|
+
* `signInWithGoogle()` + `handleCallback()`, a brand-new SSO user has
|
|
301
|
+
* a session JWT and an `enc_key` released by the auth backend, but
|
|
302
|
+
* NO Aithos identity yet (no Ed25519 seeds, no published did.json,
|
|
303
|
+
* no blob in the auth vault). This method closes that gap:
|
|
304
|
+
*
|
|
305
|
+
* 1. Generates a fresh {@link BrowserIdentity} client-side (4
|
|
306
|
+
* Ed25519 keypairs, derived DID).
|
|
307
|
+
* 2. Calls `aithos.publish_identity` on api.aithos.be so reads
|
|
308
|
+
* and writes against the Aithos primitives have an ethos to
|
|
309
|
+
* anchor to.
|
|
310
|
+
* 3. AES-GCM-encrypts the seeds with the session's `enc_key`,
|
|
311
|
+
* PUTs the result to `/auth/blob`. From now on, every Google
|
|
312
|
+
* sign-in for this user will receive the encrypted blob and
|
|
313
|
+
* hydrate locally.
|
|
314
|
+
* 4. Hydrates `ownerSigners` + `keyStore` so `canSignAsOwner()`
|
|
315
|
+
* flips to true.
|
|
316
|
+
* 5. Returns a recovery-file Blob — the only material that can
|
|
317
|
+
* restore this ethos if Google access is lost.
|
|
318
|
+
*
|
|
319
|
+
* Preconditions:
|
|
320
|
+
* - `getCurrentSession()` returns a non-null session (caller went
|
|
321
|
+
* through `handleCallback()` already).
|
|
322
|
+
* - The session's `blob_version` is 0 (i.e. no blob yet).
|
|
323
|
+
* - The session's `enc_key_b64` is non-empty.
|
|
324
|
+
*
|
|
325
|
+
* Throws `AithosSDKError("auth_sso_no_pending_first_login", …)` if
|
|
326
|
+
* preconditions don't hold (e.g. blob_version > 0 means the user has
|
|
327
|
+
* already completed setup; nothing to do).
|
|
328
|
+
*/
|
|
329
|
+
completeSsoFirstLogin(input: CompleteSsoFirstLoginInput): Promise<CompleteSsoFirstLoginResult>;
|
|
330
|
+
/**
|
|
331
|
+
* Provision a custodial-mode account on behalf of a registered app.
|
|
332
|
+
*
|
|
333
|
+
* SERVER-ONLY — the API key MUST stay off the browser. The raw user
|
|
334
|
+
* password is generated server-side and sent to the user via the
|
|
335
|
+
* Aithos welcome email; it is NEVER returned in this response.
|
|
336
|
+
*
|
|
337
|
+
* Typical use site: your app's backend in response to a sign-up form
|
|
338
|
+
* submission. The frontend never sees the API key, only the resulting
|
|
339
|
+
* `{ userId, did, handle, email, mailSent }` it can show to the user
|
|
340
|
+
* ("we just sent you a mail with your credentials").
|
|
341
|
+
*
|
|
342
|
+
* Errors map to `AithosSDKError` codes:
|
|
343
|
+
* - `auth_missing_api_key` (your code passed empty apiKey)
|
|
344
|
+
* - `auth_invalid_api_key` (Bearer rejected by backend)
|
|
345
|
+
* - `auth_api_key_revoked` (backend marked the key revoked)
|
|
346
|
+
* - `auth_email_exists` (409 — email already registered)
|
|
347
|
+
* - `auth_email_invalid` (400 — bad email format)
|
|
348
|
+
* - `auth_mail_send_failed` (502 — DDB row exists but SES failed)
|
|
349
|
+
* - `auth_custodial_signup_failed` (catch-all)
|
|
350
|
+
*/
|
|
351
|
+
signUpCustodial(input: CustodialSignUpInput): Promise<CustodialSignUpResult>;
|
|
352
|
+
/**
|
|
353
|
+
* Authenticate a custodial-mode user with email + password. Single
|
|
354
|
+
* round-trip: returns a fresh JWT session AND hydrates the local
|
|
355
|
+
* KeyStore with the user's 4 Ed25519 seeds (KMS-unwrapped server-side
|
|
356
|
+
* after Argon2id verify).
|
|
357
|
+
*
|
|
358
|
+
* After this returns, the SDK is ready to publish ethos editions,
|
|
359
|
+
* invoke compute, mint mandates, etc. — exactly as if the user had
|
|
360
|
+
* signed in via {@link signIn} (zk) or {@link handleCallback} (SSO).
|
|
361
|
+
*
|
|
362
|
+
* Errors map to `AithosSDKError` codes:
|
|
363
|
+
* - `auth_invalid_input` (your code passed empty fields)
|
|
364
|
+
* - `auth_invalid_credentials` (401 — wrong email / wrong password)
|
|
365
|
+
* - `auth_wrong_auth_mode` (403 — user exists in another flow)
|
|
366
|
+
*/
|
|
367
|
+
signInCustodial(input: CustodialSignInInput): Promise<CustodialSignInResult>;
|
|
368
|
+
/**
|
|
369
|
+
* Trigger a password-reset email to the given address. Backend ALWAYS
|
|
370
|
+
* resolves silently (no enumeration) — caller cannot tell whether the
|
|
371
|
+
* email is registered or not. The mail itself, if sent, contains a
|
|
372
|
+
* magic-link URL of shape `<resetBaseUrl>?token=<raw>&email=<email>`.
|
|
373
|
+
*
|
|
374
|
+
* Per-email rate limits apply server-side (5 mails/day, 5 min cooldown
|
|
375
|
+
* between consecutive requests). Calls during cooldown silently no-op
|
|
376
|
+
* the mail send while still returning success here.
|
|
377
|
+
*/
|
|
378
|
+
requestPasswordReset(input: RequestPasswordResetInput): Promise<void>;
|
|
379
|
+
/**
|
|
380
|
+
* Finalise a password reset using the magic-link token sent to the
|
|
381
|
+
* user's inbox by {@link requestPasswordReset}.
|
|
382
|
+
*
|
|
383
|
+
* Typical use site: the page mounted on the reset URL declared in
|
|
384
|
+
* `aithos-auth-apps.reset_base_url`. The page reads `email` and
|
|
385
|
+
* `token` from `window.location.search`, prompts the user for a new
|
|
386
|
+
* password, then calls this method.
|
|
387
|
+
*
|
|
388
|
+
* On success, the returned {@link AithosSession} is persisted to the
|
|
389
|
+
* session store but the local keystore is NOT hydrated — the backend
|
|
390
|
+
* does not return the seed bundle on this endpoint. To get a fully
|
|
391
|
+
* usable session (one that can sign envelopes), follow up with
|
|
392
|
+
* {@link signInCustodial} using the email + new password. The two
|
|
393
|
+
* round-trips can be hidden inside a single UI action: reset → auto
|
|
394
|
+
* sign-in → redirect to dashboard.
|
|
395
|
+
*
|
|
396
|
+
* Errors map to `AithosSDKError` codes:
|
|
397
|
+
* - `auth_invalid_input` (your code passed empty fields)
|
|
398
|
+
* - `auth_reset_token_invalid` (400 — token forged / wrong email)
|
|
399
|
+
* - `auth_reset_token_expired` (410 — token TTL elapsed)
|
|
400
|
+
* - `auth_reset_token_consumed` (409 — already used)
|
|
401
|
+
* - `auth_password_too_short` (400 — < 10 chars)
|
|
402
|
+
* - `auth_custodial_reset_failed` (catch-all)
|
|
113
403
|
*/
|
|
404
|
+
applyPasswordReset(input: ApplyPasswordResetInput): Promise<ApplyPasswordResetResult>;
|
|
114
405
|
signOut(): Promise<void>;
|
|
115
406
|
}
|
|
116
407
|
//# sourceMappingURL=auth.d.ts.map
|