@aithos/sdk 0.1.0-alpha.33 → 0.1.0-alpha.34

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.
@@ -325,6 +325,42 @@ export declare class AithosAuth {
325
325
  * @internal
326
326
  */
327
327
  _findDelegateForSubject(did: string): DelegateActor | undefined;
328
+ /**
329
+ * Sign in with email + password, dispatching automatically between
330
+ * the legacy zero-knowledge flow ({@link signIn}) and the custodial
331
+ * flow ({@link signInCustodial}) based on which mode the account
332
+ * was provisioned with.
333
+ *
334
+ * Use this in apps that want a single sign-in form for users who
335
+ * may have been created under either mode (e.g. an app that's
336
+ * migrating from zk to custodial — pre-existing users stay zk
337
+ * forever, new ones go custodial, the SDK figures it out).
338
+ *
339
+ * Strategy: try {@link signInCustodial} first (the modern path).
340
+ * If the backend reports `auth_invalid_credentials` — which it
341
+ * uniformly returns for "wrong password", "unknown user", AND
342
+ * "user exists but not in custodial mode" (anti-enum) — fall
343
+ * back to {@link signIn} (zk).
344
+ *
345
+ * Other failure modes from the custodial path are NOT swallowed:
346
+ * - `auth_email_not_verified` → propagate (user is custodial but
347
+ * hasn't clicked the confirmation link yet; the app should
348
+ * surface a "resend mail" CTA rather than retrying as zk,
349
+ * which would also fail and mask the real cause)
350
+ * - server / network errors → propagate (don't double the
351
+ * incident by retrying through the other flow)
352
+ *
353
+ * Latency profile:
354
+ * - Pure custodial (success or wrong pwd) : 1 round-trip
355
+ * - Pure zk (any outcome) : 1 custodial probe + 2 zk
356
+ * - Unknown email : same as zk worst case
357
+ *
358
+ * Anti-enum note: timing slightly leaks the mode (custodial path is
359
+ * faster than zk). Acceptable for V1 — rate limiting + strong
360
+ * passwords are the real defenses. A future strict-anti-enum mode
361
+ * could race both paths in parallel and accept the 2x backend load.
362
+ */
363
+ signInAuto(input: SignInInput): Promise<AithosSession>;
328
364
  signIn(input: SignInInput): Promise<AithosSession>;
329
365
  signUp(input: SignUpInput): Promise<SignUpResult>;
330
366
  /**
package/dist/src/auth.js CHANGED
@@ -178,6 +178,63 @@ export class AithosAuth {
178
178
  return this.#delegates.findForSubject(did);
179
179
  }
180
180
  /* ------------------------------------------------------------------------ */
181
+ /* Unified email + password — signInAuto (zk / custodial dispatch) */
182
+ /* ------------------------------------------------------------------------ */
183
+ /**
184
+ * Sign in with email + password, dispatching automatically between
185
+ * the legacy zero-knowledge flow ({@link signIn}) and the custodial
186
+ * flow ({@link signInCustodial}) based on which mode the account
187
+ * was provisioned with.
188
+ *
189
+ * Use this in apps that want a single sign-in form for users who
190
+ * may have been created under either mode (e.g. an app that's
191
+ * migrating from zk to custodial — pre-existing users stay zk
192
+ * forever, new ones go custodial, the SDK figures it out).
193
+ *
194
+ * Strategy: try {@link signInCustodial} first (the modern path).
195
+ * If the backend reports `auth_invalid_credentials` — which it
196
+ * uniformly returns for "wrong password", "unknown user", AND
197
+ * "user exists but not in custodial mode" (anti-enum) — fall
198
+ * back to {@link signIn} (zk).
199
+ *
200
+ * Other failure modes from the custodial path are NOT swallowed:
201
+ * - `auth_email_not_verified` → propagate (user is custodial but
202
+ * hasn't clicked the confirmation link yet; the app should
203
+ * surface a "resend mail" CTA rather than retrying as zk,
204
+ * which would also fail and mask the real cause)
205
+ * - server / network errors → propagate (don't double the
206
+ * incident by retrying through the other flow)
207
+ *
208
+ * Latency profile:
209
+ * - Pure custodial (success or wrong pwd) : 1 round-trip
210
+ * - Pure zk (any outcome) : 1 custodial probe + 2 zk
211
+ * - Unknown email : same as zk worst case
212
+ *
213
+ * Anti-enum note: timing slightly leaks the mode (custodial path is
214
+ * faster than zk). Acceptable for V1 — rate limiting + strong
215
+ * passwords are the real defenses. A future strict-anti-enum mode
216
+ * could race both paths in parallel and accept the 2x backend load.
217
+ */
218
+ async signInAuto(input) {
219
+ if (!input.email || !input.password) {
220
+ throw new AithosSDKError("auth_invalid_input", "signInAuto: email and password are required");
221
+ }
222
+ try {
223
+ const r = await this.signInCustodial(input);
224
+ return r.session;
225
+ }
226
+ catch (e) {
227
+ // Only fall back on the specific anti-enum sentinel — preserve
228
+ // other error codes (notably auth_email_not_verified) so the
229
+ // caller can surface the right UI hint.
230
+ if (e instanceof AithosSDKError &&
231
+ e.code === "auth_invalid_credentials") {
232
+ return await this.signIn(input);
233
+ }
234
+ throw e;
235
+ }
236
+ }
237
+ /* ------------------------------------------------------------------------ */
181
238
  /* Email + password — signIn */
182
239
  /* ------------------------------------------------------------------------ */
183
240
  async signIn(input) {
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.1.0-alpha.33";
1
+ export declare const VERSION = "0.1.0-alpha.34";
2
2
  export { AithosSDK } from "./sdk.js";
3
3
  export type { AithosSDKConfig } from "./types.js";
4
4
  export { AithosSDKError } from "./types.js";
package/dist/src/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  // Public types specific to the SDK (`AithosSDKConfig`, `AithosSDKError`)
18
18
  // are exported from here. Endpoint config (`AithosSdkEndpoints`,
19
19
  // `DEFAULT_SDK_ENDPOINTS`) likewise.
20
- export const VERSION = "0.1.0-alpha.33";
20
+ export const VERSION = "0.1.0-alpha.34";
21
21
  export { AithosSDK } from "./sdk.js";
22
22
  export { AithosSDKError } from "./types.js";
23
23
  // Re-export protocol-client's JSON-RPC error type so consumers can
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithos/sdk",
3
- "version": "0.1.0-alpha.33",
3
+ "version": "0.1.0-alpha.34",
4
4
  "description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
5
5
  "keywords": [
6
6
  "aithos",