@aithos/sdk 0.1.0-alpha.5 → 0.1.0-alpha.51

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.
Files changed (67) hide show
  1. package/README.md +245 -7
  2. package/dist/src/apps.d.ts +224 -0
  3. package/dist/src/apps.js +432 -0
  4. package/dist/src/assets.d.ts +209 -0
  5. package/dist/src/assets.js +534 -0
  6. package/dist/src/auth-api.d.ts +219 -0
  7. package/dist/src/auth-api.js +248 -0
  8. package/dist/src/auth.d.ts +543 -0
  9. package/dist/src/auth.js +937 -31
  10. package/dist/src/compute.d.ts +464 -6
  11. package/dist/src/compute.js +746 -20
  12. package/dist/src/data-schema-contacts-v1.d.ts +14 -0
  13. package/dist/src/data-schema-contacts-v1.js +28 -0
  14. package/dist/src/data.d.ts +342 -0
  15. package/dist/src/data.js +1002 -0
  16. package/dist/src/endpoints.d.ts +25 -0
  17. package/dist/src/endpoints.js +7 -0
  18. package/dist/src/ethos.d.ts +85 -0
  19. package/dist/src/ethos.js +463 -7
  20. package/dist/src/index.d.ts +17 -6
  21. package/dist/src/index.js +25 -3
  22. package/dist/src/internal/delegate-bundle.js +7 -2
  23. package/dist/src/internal/envelope.d.ts +93 -0
  24. package/dist/src/internal/envelope.js +59 -0
  25. package/dist/src/mandates.d.ts +111 -2
  26. package/dist/src/mandates.js +150 -7
  27. package/dist/src/react/AithosAsset.d.ts +66 -0
  28. package/dist/src/react/AithosAsset.js +67 -0
  29. package/dist/src/react/context.d.ts +29 -0
  30. package/dist/src/react/context.js +31 -0
  31. package/dist/src/react/index.d.ts +29 -0
  32. package/dist/src/react/index.js +31 -0
  33. package/dist/src/react/use-aithos-asset.d.ts +39 -0
  34. package/dist/src/react/use-aithos-asset.js +118 -0
  35. package/dist/src/react/use-transcribe-pending.d.ts +21 -0
  36. package/dist/src/react/use-transcribe-pending.js +47 -0
  37. package/dist/src/sdk.d.ts +10 -0
  38. package/dist/src/sdk.js +22 -0
  39. package/dist/src/transcribe-resilience.d.ts +57 -0
  40. package/dist/src/transcribe-resilience.js +203 -0
  41. package/dist/src/web.d.ts +279 -0
  42. package/dist/src/web.js +186 -0
  43. package/dist/test/auth-j3.test.js +32 -1
  44. package/dist/test/canonical-conformance.test.d.ts +2 -0
  45. package/dist/test/canonical-conformance.test.js +86 -0
  46. package/dist/test/compute-delegate-path.test.d.ts +2 -0
  47. package/dist/test/compute-delegate-path.test.js +183 -0
  48. package/dist/test/compute.test.js +4 -0
  49. package/dist/test/endpoints.test.js +30 -1
  50. package/dist/test/envelope-core-conformance.test.d.ts +2 -0
  51. package/dist/test/envelope-core-conformance.test.js +75 -0
  52. package/dist/test/envelope.test.d.ts +2 -0
  53. package/dist/test/envelope.test.js +318 -0
  54. package/dist/test/ethos-first-edition.test.d.ts +2 -0
  55. package/dist/test/ethos-first-edition.test.js +371 -0
  56. package/dist/test/mandates-compute.test.d.ts +2 -0
  57. package/dist/test/mandates-compute.test.js +256 -0
  58. package/dist/test/sdk.test.js +11 -2
  59. package/dist/test/signup-bootstrap.test.d.ts +2 -0
  60. package/dist/test/signup-bootstrap.test.js +311 -0
  61. package/dist/test/transcribe-invoke.test.d.ts +2 -0
  62. package/dist/test/transcribe-invoke.test.js +204 -0
  63. package/dist/test/transcribe.test.d.ts +2 -0
  64. package/dist/test/transcribe.test.js +186 -0
  65. package/dist/test/web.test.d.ts +2 -0
  66. package/dist/test/web.test.js +270 -0
  67. package/package.json +20 -3
@@ -1,17 +1,44 @@
1
1
  import { type AithosSessionStore } from "./session-store.js";
2
2
  import { type AithosKeyStore } from "./key-store.js";
3
3
  import { DelegateActor } from "./internal/delegate-state.js";
4
+ import { type SignedEnvelope } from "./internal/envelope.js";
4
5
  import { OwnerSigners } from "./internal/owner-signers.js";
5
6
  /** Default URL of the Aithos auth backend. */
6
7
  export declare const DEFAULT_AUTH_BASE_URL = "https://auth.aithos.be";
8
+ /** Default URL of the Aithos primitives API (publish_identity, publish_ethos_edition, etc.). */
9
+ export declare const DEFAULT_API_BASE_URL = "https://api.aithos.be";
7
10
  export interface AithosAuthConfig {
8
11
  readonly authBaseUrl?: string;
12
+ /**
13
+ * Base URL of the Aithos primitives API (`api.aithos.be`). Used by
14
+ * {@link AithosAuth.signUp} to bootstrap the user's Ethos via
15
+ * `aithos.publish_identity` after the auth account is created. Override
16
+ * for staging or self-hosted deployments. Defaults to
17
+ * {@link DEFAULT_API_BASE_URL}.
18
+ */
19
+ readonly apiBaseUrl?: string;
9
20
  readonly fetch?: typeof fetch;
10
21
  readonly window?: Pick<Window, "location" | "history">;
11
22
  /** Pluggable JWT-session storage. Defaults to {@link defaultSessionStore}. */
12
23
  readonly sessionStore?: AithosSessionStore;
13
24
  /** Pluggable key persistence. Defaults to {@link defaultKeyStore}. */
14
25
  readonly keyStore?: AithosKeyStore;
26
+ /**
27
+ * Public client key issued by Aithos for browser callers
28
+ * (`pk_<env>_<…>`). When set, the custodial endpoints (`signUpCustodial`,
29
+ * `verifyEmail`, `resendVerificationEmail`) authenticate as this app
30
+ * by default — the caller no longer has to repeat the key on every
31
+ * call. The corresponding `allowed_origins` allowlist must include the
32
+ * current page's origin.
33
+ *
34
+ * Safe to ship in the browser bundle: it grants nothing beyond what
35
+ * a visitor of the app can already do, is gated by Origin on every
36
+ * call, and is rate-limited per IP by the backend.
37
+ *
38
+ * If your app authenticates with a SECRET Bearer API key from a
39
+ * backend instead, leave this unset and pass `apiKey` per call.
40
+ */
41
+ readonly publicKey?: string;
15
42
  }
16
43
  /**
17
44
  * Active Aithos session. Returned by JWT-backed entry points
@@ -54,7 +81,31 @@ export interface DelegateInfo {
54
81
  readonly label?: string;
55
82
  }
56
83
  export interface SignInWithGoogleOptions {
84
+ /**
85
+ * Opaque state the consumer app wants to recover after the OAuth
86
+ * round-trip (e.g. a deep-link to resume on). Echoed back as
87
+ * `?app_state=` on the final redirect.
88
+ */
57
89
  readonly appState?: string;
90
+ /**
91
+ * App id registered in the Aithos `aithos-auth-apps` table. When set
92
+ * together with {@link returnTo}, the auth backend redirects the
93
+ * browser to {@link returnTo} (post Google + Aithos sign-in) instead
94
+ * of the legacy hard-coded `app.aithos.be/auth/callback`.
95
+ *
96
+ * The pair is required together: the backend rejects half-presence
97
+ * with `sso_app_redirect_pair_required`. Use it for any consumer app
98
+ * other than the canonical `app.aithos.be` (typically your own
99
+ * domain in prod, `http://localhost:<port>/auth/callback` in dev).
100
+ */
101
+ readonly appId?: string;
102
+ /**
103
+ * Where the auth backend should 302 the browser back to after a
104
+ * successful Google sign-in. MUST be on the app's
105
+ * `allowed_redirect_uris` allowlist (registered with Aithos out of
106
+ * band; see {@link appId}). Exact-match — wildcards rejected.
107
+ */
108
+ readonly returnTo?: string;
58
109
  }
59
110
  export interface SignInInput {
60
111
  readonly email: string;
@@ -71,6 +122,28 @@ export interface SignUpResult {
71
122
  readonly recoveryFile: Blob;
72
123
  readonly recoveryFilename: string;
73
124
  }
125
+ /**
126
+ * Input to {@link AithosAuth.completeSsoFirstLogin}. The handle is
127
+ * required (the auth backend pre-generated one from the user's email
128
+ * local-part, available on the session payload — we re-confirm it
129
+ * here so the user can edit before commit).
130
+ */
131
+ export interface CompleteSsoFirstLoginInput {
132
+ readonly handle: string;
133
+ readonly displayName?: string;
134
+ }
135
+ /**
136
+ * Result of {@link AithosAuth.completeSsoFirstLogin}. Returns a recovery
137
+ * file just like signUp — even though the user authenticated via Google,
138
+ * the freshly-generated Ed25519 seeds are the only material that can
139
+ * sign Aithos artifacts; without the recovery file, losing access to
140
+ * the Google account means losing the ethos forever.
141
+ */
142
+ export interface CompleteSsoFirstLoginResult {
143
+ readonly session: AithosSession;
144
+ readonly recoveryFile: Blob;
145
+ readonly recoveryFilename: string;
146
+ }
74
147
  export interface SignInWithRecoveryInput {
75
148
  /** Recovery file as a Blob (browser File input) or already-decoded JSON string. */
76
149
  readonly file: Blob | string;
@@ -79,9 +152,196 @@ export interface ImportMandateInput {
79
152
  /** Delegate bundle as a Blob or already-decoded JSON string. */
80
153
  readonly bundle: Blob | string;
81
154
  }
155
+ /**
156
+ * Input to {@link AithosAuth.inviteCustodial}. Sends an invitation magic link
157
+ * that carries an opaque payload (typically a delegate bundle) to deliver to
158
+ * the invitee on accept. Mandate-agnostic: `mandateBundle` may be ANY mandate
159
+ * (read/write/append/ethos/compute…) — the auth backend stores it verbatim,
160
+ * bound to a single-use token, and never parses it.
161
+ *
162
+ * The app authenticates via `apiKey` (server-only secret) or `publicKey`
163
+ * (browser-safe, Origin-gated), or the constructor's default `publicKey`.
164
+ * No user password here — the invitee chooses it when they accept.
165
+ */
166
+ export interface InviteCustodialInput {
167
+ readonly apiKey?: string;
168
+ readonly publicKey?: string;
169
+ /** Invitee email — receives the magic link. */
170
+ readonly email: string;
171
+ /**
172
+ * The mandate to deliver. Accept the SDK's `MintedMandate.bundle` (Blob),
173
+ * a JSON string, or a plain bundle object — all normalized to a JSON string.
174
+ */
175
+ readonly mandateBundle: Blob | string | Record<string, unknown>;
176
+ /** Token TTL in seconds (backend clamps to its policy). */
177
+ readonly ttlSeconds?: number;
178
+ /** Optional display name pre-filled on the pending account. */
179
+ readonly displayName?: string;
180
+ }
181
+ /** Result of {@link AithosAuth.inviteCustodial}. */
182
+ export interface InviteCustodialResult {
183
+ readonly status: "invited";
184
+ readonly email: string;
185
+ readonly mailSent: boolean;
186
+ readonly mailMessageId?: string;
187
+ }
188
+ /**
189
+ * Input to {@link AithosAuth.acceptInvite}. `email` and `token` come from the
190
+ * `?email=&token=` query string of the invitation link. `password` is set by
191
+ * the invitee for a NEW account, or used to authenticate an EXISTING one — so
192
+ * it's required whenever the user isn't already signed in.
193
+ */
194
+ export interface AcceptInviteInput {
195
+ readonly email: string;
196
+ readonly token: string;
197
+ readonly password?: string;
198
+ }
199
+ /**
200
+ * Result of {@link AithosAuth.acceptInvite}. The token is consumed, the
201
+ * session is hydrated (account created or existing one signed in), and the
202
+ * invited mandate has been imported into the keystore — `delegate` describes
203
+ * it. Read `delegate.subjectDid` to identify the issuer (e.g. resolve their
204
+ * public Ethos via `sdk.ethos.of(delegate.subjectDid)`).
205
+ */
206
+ export interface AcceptInviteResult {
207
+ readonly status: "signed_in";
208
+ readonly session: AithosSession;
209
+ readonly delegate: DelegateInfo;
210
+ /** True when a new account was provisioned; false when an existing one signed in. */
211
+ readonly accountCreated: boolean;
212
+ }
213
+ /**
214
+ * Input to {@link AithosAuth.signUpCustodial}.
215
+ *
216
+ * The caller authenticates as an app via ONE of:
217
+ * - `apiKey` : server-only secret Bearer. Pass from your backend
218
+ * only — never ship it in browser code.
219
+ * - `publicKey` : browser-safe public client key. Safe to embed in
220
+ * the bundle; the backend gates it by Origin and
221
+ * rate-limits by IP.
222
+ *
223
+ * If you set `publicKey` on the {@link AithosAuth} constructor, omit
224
+ * both fields here — the default credential is used.
225
+ *
226
+ * The `password` is always required and is chosen by the user (sign-up
227
+ * no longer auto-generates one). The created account starts as
228
+ * **pending** (`email_verified=false`); the user must click the
229
+ * confirmation link sent by SES before {@link signInCustodial} works.
230
+ */
231
+ export interface CustodialSignUpInput {
232
+ /** Server-only Bearer secret. Mutually exclusive with `publicKey`. */
233
+ readonly apiKey?: string;
234
+ /** Browser-safe public client key. Mutually exclusive with `apiKey`.
235
+ * Overrides the constructor's default `publicKey` when provided. */
236
+ readonly publicKey?: string;
237
+ /** Email address of the new user. Will receive the verification mail. */
238
+ readonly email: string;
239
+ /** Raw password the user chose. ≥ 10 chars, mix of letters with
240
+ * ≥ 1 digit or symbol. Enforced server-side. */
241
+ readonly password: string;
242
+ /** Optional display name. Capped at 200 chars by the backend. */
243
+ readonly displayName?: string;
244
+ /** Optional handle hint. Backend may sanitise or replace. */
245
+ readonly handleHint?: string;
246
+ }
247
+ /**
248
+ * Result of {@link AithosAuth.signUpCustodial}. Always carries
249
+ * `status: "pending_verification"` — the user must click the link in
250
+ * their inbox before sign-in works. If `mailSent` is false the row
251
+ * exists in DDB anyway; trigger {@link AithosAuth.resendVerificationEmail}
252
+ * to retry the SES send.
253
+ */
254
+ export interface CustodialSignUpResult {
255
+ readonly status: "pending_verification";
256
+ readonly email: string;
257
+ readonly mailSent: boolean;
258
+ readonly mailMessageId?: string;
259
+ }
260
+ /** Input to {@link AithosAuth.verifyEmail}. Both fields come straight
261
+ * out of the `?email=&token=` query string of the confirmation URL. */
262
+ export interface VerifyEmailInput {
263
+ readonly email: string;
264
+ readonly token: string;
265
+ }
266
+ /**
267
+ * Result of {@link AithosAuth.verifyEmail}. Discriminated by `status`.
268
+ *
269
+ * - `"signed_in"` (magic-link mode): the user has been authenticated
270
+ * in this call. A JWT session is persisted to the session store and
271
+ * the local keystore is hydrated with the unwrapped seed bundle.
272
+ * The caller can navigate the user straight to a logged-in area.
273
+ * - `"already_verified"`: the verification link had already been
274
+ * consumed on a previous click. No session is minted (the token is
275
+ * spent). The caller should route the user to the sign-in form.
276
+ */
277
+ export type VerifyEmailResult = {
278
+ readonly status: "signed_in";
279
+ readonly session: AithosSession;
280
+ readonly passwordMustChange: false;
281
+ } | {
282
+ readonly status: "already_verified";
283
+ readonly email: string;
284
+ };
285
+ /** Input to {@link AithosAuth.resendVerificationEmail}. The `email` is
286
+ * required; credential overrides follow the same rules as
287
+ * {@link CustodialSignUpInput}. */
288
+ export interface ResendVerificationInput {
289
+ readonly email: string;
290
+ readonly apiKey?: string;
291
+ readonly publicKey?: string;
292
+ }
293
+ export interface CustodialSignInInput {
294
+ readonly email: string;
295
+ readonly password: string;
296
+ }
297
+ /**
298
+ * Active custodial session. Same JWT-backed shape as {@link AithosSession}
299
+ * but adds a `passwordMustChange` flag the UI can honour to nudge the
300
+ * user toward a `requestPasswordReset` on first login.
301
+ */
302
+ export interface CustodialSignInResult {
303
+ readonly session: AithosSession;
304
+ readonly passwordMustChange: boolean;
305
+ }
306
+ export interface RequestPasswordResetInput {
307
+ readonly email: string;
308
+ }
309
+ /**
310
+ * Input to {@link AithosAuth.applyPasswordReset}. Finalises a password
311
+ * reset started by {@link AithosAuth.requestPasswordReset}. The `email`
312
+ * and `token` come straight from the magic-link URL that landed in the
313
+ * user's inbox (`?email=…&token=…`); the `newPassword` is what the user
314
+ * just typed in the reset page.
315
+ */
316
+ export interface ApplyPasswordResetInput {
317
+ /** Email address whose password is being reset. */
318
+ readonly email: string;
319
+ /** Raw reset token extracted from the magic-link URL query string. */
320
+ readonly token: string;
321
+ /** New password — must satisfy the backend's policy (≥ 10 chars). */
322
+ readonly newPassword: string;
323
+ }
324
+ /**
325
+ * Result of {@link AithosAuth.applyPasswordReset}. Carries a fresh JWT
326
+ * session so the UI can either redirect to a "you're now signed in"
327
+ * landing or prompt the user to sign in explicitly with their new
328
+ * credentials — same {@link CustodialSignInResult} shape as a normal
329
+ * sign-in.
330
+ *
331
+ * Note: unlike {@link signInCustodial}, this DOES NOT hydrate the local
332
+ * keystore. The reset path on the auth Lambda re-wraps the seed bundle
333
+ * with KMS but doesn't return it (the user just typed a password — they
334
+ * still need to sign in once to materialise the seeds locally). The
335
+ * {@link AithosSession} returned here lets the app store the JWT and
336
+ * call {@link signInCustodial} to complete hydration.
337
+ */
338
+ export interface ApplyPasswordResetResult {
339
+ readonly session: AithosSession;
340
+ }
82
341
  export declare class AithosAuth {
83
342
  #private;
84
343
  readonly authBaseUrl: string;
344
+ readonly apiBaseUrl: string;
85
345
  constructor(config?: AithosAuthConfig);
86
346
  /**
87
347
  * Reload signing material and JWT session from the configured stores.
@@ -103,6 +363,70 @@ export declare class AithosAuth {
103
363
  getOwnerInfo(): OwnerInfo | null;
104
364
  getDelegates(): readonly DelegateInfo[];
105
365
  canSignAsOwner(): boolean;
366
+ /**
367
+ * Sign an envelope (spec §11.2) as the active owner, to authenticate
368
+ * a call to a third-party Aithos-aware backend.
369
+ *
370
+ * Same primitive that SDK namespaces (`sdk.data`, `sdk.ethos`,
371
+ * `sdk.mandates`, ...) use internally to sign their own writes to
372
+ * `api.aithos.be`. Exposed here so apps can sign envelopes for their
373
+ * own backends — any service that verifies a `SignedEnvelope` per
374
+ * spec §11.2 (typically using `@aithos/protocol-core/envelope`'s
375
+ * `verifyEnvelope`) accepts the resulting object.
376
+ *
377
+ * The envelope binds the signature to `(iss, aud, method,
378
+ * params_hash, nonce, iat, exp)`, so it cannot be replayed against a
379
+ * different endpoint, method, or payload, and expires after
380
+ * `ttlSeconds` (default 60s, server-side typically caps at 300s).
381
+ *
382
+ * Usage:
383
+ *
384
+ * ```ts
385
+ * const envelope = await sdk.auth.signEnvelope({
386
+ * aud: "https://api.example.com/v1/widgets",
387
+ * method: "myapp.widgets.create",
388
+ * params: { name: "Widget #1" },
389
+ * });
390
+ * await fetch("https://api.example.com/v1/widgets", {
391
+ * method: "POST",
392
+ * headers: { "content-type": "application/json" },
393
+ * body: JSON.stringify({ ...payload, _envelope: envelope }),
394
+ * });
395
+ * ```
396
+ *
397
+ * @throws {AithosSDKError} `auth_not_signed_in` if no owner identity
398
+ * is loaded (call `signIn` / `signUp` / `signInCustodial` first).
399
+ * @throws {AithosSDKError} `auth_invalid_sphere` if `sphere` is not
400
+ * one of `"root" | "public" | "circle" | "self"`.
401
+ */
402
+ signEnvelope(args: {
403
+ /**
404
+ * Absolute URL of the target endpoint (scheme + host + path, no
405
+ * query, no fragment). The receiving server rejects the envelope if
406
+ * `aud` does not match the actual request URL.
407
+ */
408
+ readonly aud: string;
409
+ /** Fully-qualified JSON-RPC method name. */
410
+ readonly method: string;
411
+ /**
412
+ * Tool payload — what `params_hash` commits to. Will be
413
+ * JCS-canonicalized (RFC 8785 subset) before hashing, so JS object
414
+ * key order does not affect the result.
415
+ */
416
+ readonly params: unknown;
417
+ /**
418
+ * Which of the owner's four sphere keys signs. Default: `"public"`,
419
+ * which matches what SDK namespaces use for everyday writes.
420
+ * Choose `"root"`, `"circle"`, or `"self"` only if the receiving
421
+ * server specifically expects one of those (rare).
422
+ */
423
+ readonly sphere?: "root" | "public" | "circle" | "self";
424
+ /**
425
+ * Envelope lifetime in seconds. Default 60. Aithos servers cap
426
+ * at 300; third-party servers may apply their own cap.
427
+ */
428
+ readonly ttlSeconds?: number;
429
+ }): Promise<SignedEnvelope>;
106
430
  canSignAsDelegateFor(did: string): boolean;
107
431
  /**
108
432
  * Internal accessor used by sibling SDK namespaces (compute, wallet,
@@ -124,6 +448,42 @@ export declare class AithosAuth {
124
448
  * @internal
125
449
  */
126
450
  _findDelegateForSubject(did: string): DelegateActor | undefined;
451
+ /**
452
+ * Sign in with email + password, dispatching automatically between
453
+ * the legacy zero-knowledge flow ({@link signIn}) and the custodial
454
+ * flow ({@link signInCustodial}) based on which mode the account
455
+ * was provisioned with.
456
+ *
457
+ * Use this in apps that want a single sign-in form for users who
458
+ * may have been created under either mode (e.g. an app that's
459
+ * migrating from zk to custodial — pre-existing users stay zk
460
+ * forever, new ones go custodial, the SDK figures it out).
461
+ *
462
+ * Strategy: try {@link signInCustodial} first (the modern path).
463
+ * If the backend reports `auth_invalid_credentials` — which it
464
+ * uniformly returns for "wrong password", "unknown user", AND
465
+ * "user exists but not in custodial mode" (anti-enum) — fall
466
+ * back to {@link signIn} (zk).
467
+ *
468
+ * Other failure modes from the custodial path are NOT swallowed:
469
+ * - `auth_email_not_verified` → propagate (user is custodial but
470
+ * hasn't clicked the confirmation link yet; the app should
471
+ * surface a "resend mail" CTA rather than retrying as zk,
472
+ * which would also fail and mask the real cause)
473
+ * - server / network errors → propagate (don't double the
474
+ * incident by retrying through the other flow)
475
+ *
476
+ * Latency profile:
477
+ * - Pure custodial (success or wrong pwd) : 1 round-trip
478
+ * - Pure zk (any outcome) : 1 custodial probe + 2 zk
479
+ * - Unknown email : same as zk worst case
480
+ *
481
+ * Anti-enum note: timing slightly leaks the mode (custodial path is
482
+ * faster than zk). Acceptable for V1 — rate limiting + strong
483
+ * passwords are the real defenses. A future strict-anti-enum mode
484
+ * could race both paths in parallel and accept the 2x backend load.
485
+ */
486
+ signInAuto(input: SignInInput): Promise<AithosSession>;
127
487
  signIn(input: SignInInput): Promise<AithosSession>;
128
488
  signUp(input: SignUpInput): Promise<SignUpResult>;
129
489
  /**
@@ -148,8 +508,191 @@ export declare class AithosAuth {
148
508
  importMandate(input: ImportMandateInput): Promise<DelegateInfo>;
149
509
  removeMandate(mandateId: string): Promise<void>;
150
510
  signInWithGoogle(opts?: SignInWithGoogleOptions): never;
511
+ /**
512
+ * Public entrypoint — dedupes concurrent calls (React StrictMode).
513
+ * The first call kicks off the actual exchange; subsequent calls
514
+ * before that promise resolves return the SAME promise so they all
515
+ * receive the same `AithosSession | null`. Otherwise StrictMode's
516
+ * second invocation would race against the URL clean done by the
517
+ * first call and resolve to `null`, robbing the AuthCallback page
518
+ * of the session it actually obtained.
519
+ */
151
520
  handleCallback(): Promise<AithosSession | null>;
152
521
  exchange(aithosCode: string): Promise<AithosSession>;
522
+ /**
523
+ * Finish the first-time Google SSO bootstrap. After
524
+ * `signInWithGoogle()` + `handleCallback()`, a brand-new SSO user has
525
+ * a session JWT and an `enc_key` released by the auth backend, but
526
+ * NO Aithos identity yet (no Ed25519 seeds, no published did.json,
527
+ * no blob in the auth vault). This method closes that gap:
528
+ *
529
+ * 1. Generates a fresh {@link BrowserIdentity} client-side (4
530
+ * Ed25519 keypairs, derived DID).
531
+ * 2. Calls `aithos.publish_identity` on api.aithos.be so reads
532
+ * and writes against the Aithos primitives have an ethos to
533
+ * anchor to.
534
+ * 3. AES-GCM-encrypts the seeds with the session's `enc_key`,
535
+ * PUTs the result to `/auth/blob`. From now on, every Google
536
+ * sign-in for this user will receive the encrypted blob and
537
+ * hydrate locally.
538
+ * 4. Hydrates `ownerSigners` + `keyStore` so `canSignAsOwner()`
539
+ * flips to true.
540
+ * 5. Returns a recovery-file Blob — the only material that can
541
+ * restore this ethos if Google access is lost.
542
+ *
543
+ * Preconditions:
544
+ * - `getCurrentSession()` returns a non-null session (caller went
545
+ * through `handleCallback()` already).
546
+ * - The session's `blob_version` is 0 (i.e. no blob yet).
547
+ * - The session's `enc_key_b64` is non-empty.
548
+ *
549
+ * Throws `AithosSDKError("auth_sso_no_pending_first_login", …)` if
550
+ * preconditions don't hold (e.g. blob_version > 0 means the user has
551
+ * already completed setup; nothing to do).
552
+ */
553
+ completeSsoFirstLogin(input: CompleteSsoFirstLoginInput): Promise<CompleteSsoFirstLoginResult>;
554
+ /**
555
+ * Provision a custodial-mode account on behalf of a registered app.
556
+ *
557
+ * Two integration patterns:
558
+ * - **Frontend-only** apps : set `publicKey` on the constructor
559
+ * (or on this call). Safe to ship in browser bundles — the
560
+ * backend gates each request by Origin + IP rate limit.
561
+ * - **Backend-fronted** apps : the backend passes `apiKey` (secret
562
+ * Bearer); the browser never sees the credential.
563
+ *
564
+ * The created account is in a *pending* state — sign-in stays blocked
565
+ * until the user clicks the confirmation link sent to their inbox.
566
+ * Call {@link verifyEmail} from the page mounted on
567
+ * `app.verify_base_url` to consume the token; afterwards
568
+ * {@link signInCustodial} works.
569
+ *
570
+ * Errors map to `AithosSDKError` codes:
571
+ * - `auth_missing_api_key` (no credential provided)
572
+ * - `auth_invalid_api_key` (Bearer rejected by backend)
573
+ * - `auth_invalid_public_key` (public key rejected by backend)
574
+ * - `auth_api_key_revoked` / `auth_public_key_revoked`
575
+ * - `auth_origin_not_allowed` (public key + Origin not in allowlist)
576
+ * - `auth_password_too_weak` (400 — server-side strength check)
577
+ * - `auth_email_exists` (409 — email already registered)
578
+ * - `auth_email_invalid` (400 — bad email format)
579
+ * - `auth_mail_send_failed` (502 — DDB row exists but SES failed)
580
+ * - `auth_custodial_signup_failed` (catch-all)
581
+ */
582
+ signUpCustodial(input: CustodialSignUpInput): Promise<CustodialSignUpResult>;
583
+ /**
584
+ * Magic-link auto-signin: consume the verification token from the
585
+ * confirmation link, KMS-unwrap the seed bundle server-side, and
586
+ * hydrate the local session + keystore in one round-trip.
587
+ *
588
+ * Outcome depends on the link's state:
589
+ * - First click on a fresh link → returns
590
+ * `{ status: "signed_in", session, … }`. The session store is
591
+ * populated, the owner signers are loaded — the user is signed
592
+ * in. The caller should navigate them to a logged-in route.
593
+ * - Click of an already-consumed link → returns
594
+ * `{ status: "already_verified", email }`. No session is minted;
595
+ * the user must sign in via {@link signInCustodial}.
596
+ *
597
+ * Mount this on the page declared as `verify_base_url` in your app's
598
+ * registration. Read `email` + `token` from `window.location.search`,
599
+ * call this, branch on `result.status`.
600
+ *
601
+ * Throws `auth_token_invalid_or_expired` if the token is wrong or
602
+ * past its 1h TTL — surface a "request a fresh link" CTA in that case.
603
+ */
604
+ verifyEmail(input: VerifyEmailInput): Promise<VerifyEmailResult>;
605
+ /**
606
+ * Send an invitation magic link carrying a mandate. The issuer (owner)
607
+ * mints any mandate via {@link AithosSDK.mandates} (read/write/append/…),
608
+ * then calls this with the bundle: the auth backend stores it bound to a
609
+ * single-use token and emails the magic link. The mandate (and its delegate
610
+ * seed) never ride the email URL. The invitee redeems it via
611
+ * {@link acceptInvite}.
612
+ *
613
+ * Generic — knows nothing about the mandate's scope. Authenticate with
614
+ * `apiKey` (server) or `publicKey` (browser, Origin-gated).
615
+ */
616
+ inviteCustodial(input: InviteCustodialInput): Promise<InviteCustodialResult>;
617
+ /**
618
+ * Redeem an invitation from the magic link: consume the token, sign in
619
+ * (create the account with `password`, or authenticate an existing one),
620
+ * and AUTO-IMPORT the mandate the inviter attached. Returns the session and
621
+ * the imported {@link DelegateInfo}.
622
+ *
623
+ * Mount this on the page declared as the invitation's verify/redirect URL;
624
+ * read `email` + `token` from `window.location.search`, collect the
625
+ * `password`, call this.
626
+ *
627
+ * Throws `auth_token_invalid_or_expired` (bad/consumed/expired token) or an
628
+ * auth error if an existing account's password is wrong / a new one is weak.
629
+ */
630
+ acceptInvite(input: AcceptInviteInput): Promise<AcceptInviteResult>;
631
+ /**
632
+ * Re-send the verification mail for a pending account. Use when the
633
+ * user reports never having received the welcome mail, or when their
634
+ * verification token expired (24h TTL).
635
+ *
636
+ * The backend is anti-enumeration (always 200) and rate-limited
637
+ * 1/h/account, so it's safe to call even when the state of `email`
638
+ * is unknown. Accepts the same credential families as
639
+ * {@link signUpCustodial}; falls back to the constructor's
640
+ * `publicKey` when neither override is set.
641
+ */
642
+ resendVerificationEmail(input: ResendVerificationInput): Promise<void>;
643
+ /**
644
+ * Authenticate a custodial-mode user with email + password. Single
645
+ * round-trip: returns a fresh JWT session AND hydrates the local
646
+ * KeyStore with the user's 4 Ed25519 seeds (KMS-unwrapped server-side
647
+ * after Argon2id verify).
648
+ *
649
+ * After this returns, the SDK is ready to publish ethos editions,
650
+ * invoke compute, mint mandates, etc. — exactly as if the user had
651
+ * signed in via {@link signIn} (zk) or {@link handleCallback} (SSO).
652
+ *
653
+ * Errors map to `AithosSDKError` codes:
654
+ * - `auth_invalid_input` (your code passed empty fields)
655
+ * - `auth_invalid_credentials` (401 — wrong email / wrong password)
656
+ * - `auth_wrong_auth_mode` (403 — user exists in another flow)
657
+ */
658
+ signInCustodial(input: CustodialSignInInput): Promise<CustodialSignInResult>;
659
+ /**
660
+ * Trigger a password-reset email to the given address. Backend ALWAYS
661
+ * resolves silently (no enumeration) — caller cannot tell whether the
662
+ * email is registered or not. The mail itself, if sent, contains a
663
+ * magic-link URL of shape `<resetBaseUrl>?token=<raw>&email=<email>`.
664
+ *
665
+ * Per-email rate limits apply server-side (5 mails/day, 5 min cooldown
666
+ * between consecutive requests). Calls during cooldown silently no-op
667
+ * the mail send while still returning success here.
668
+ */
669
+ requestPasswordReset(input: RequestPasswordResetInput): Promise<void>;
670
+ /**
671
+ * Finalise a password reset using the magic-link token sent to the
672
+ * user's inbox by {@link requestPasswordReset}.
673
+ *
674
+ * Typical use site: the page mounted on the reset URL declared in
675
+ * `aithos-auth-apps.reset_base_url`. The page reads `email` and
676
+ * `token` from `window.location.search`, prompts the user for a new
677
+ * password, then calls this method.
678
+ *
679
+ * On success, the returned {@link AithosSession} is persisted to the
680
+ * session store but the local keystore is NOT hydrated — the backend
681
+ * does not return the seed bundle on this endpoint. To get a fully
682
+ * usable session (one that can sign envelopes), follow up with
683
+ * {@link signInCustodial} using the email + new password. The two
684
+ * round-trips can be hidden inside a single UI action: reset → auto
685
+ * sign-in → redirect to dashboard.
686
+ *
687
+ * Errors map to `AithosSDKError` codes:
688
+ * - `auth_invalid_input` (your code passed empty fields)
689
+ * - `auth_reset_token_invalid` (400 — token forged / wrong email)
690
+ * - `auth_reset_token_expired` (410 — token TTL elapsed)
691
+ * - `auth_reset_token_consumed` (409 — already used)
692
+ * - `auth_password_too_short` (400 — < 10 chars)
693
+ * - `auth_custodial_reset_failed` (catch-all)
694
+ */
695
+ applyPasswordReset(input: ApplyPasswordResetInput): Promise<ApplyPasswordResetResult>;
153
696
  signOut(): Promise<void>;
154
697
  }
155
698
  //# sourceMappingURL=auth.d.ts.map