@authmoji/better-auth 0.0.0 → 0.1.0

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.
@@ -0,0 +1,494 @@
1
+ import * as z from "zod";
2
+ import type { AuthmojiMethod, AuthmojiOptions, UserWithAuthmoji } from "./types.js";
3
+ /**
4
+ * Authmoji plugin for Better Auth.
5
+ *
6
+ * Adds self-hosted emoji-based OTP and TOTP two-factor authentication,
7
+ * tap-grid challenges, recovery backup codes, trusted devices, and account
8
+ * lockout on top of Better Auth's adapter, session, and verification primitives.
9
+ */
10
+ export declare const authmoji: (options?: AuthmojiOptions) => {
11
+ id: "authmoji";
12
+ endpoints: {
13
+ /**
14
+ * POST `/authmoji/enable`
15
+ *
16
+ * Enables Authmoji 2FA for the authenticated user using either `"totp"`
17
+ * (returns a Base32 secret, `authmoji://totp/...` URI, and backup codes)
18
+ * or `"otp"` (enables out-of-band emoji OTP delivery immediately).
19
+ */
20
+ enableAuthmoji: import("better-auth").StrictEndpoint<"/authmoji/enable", {
21
+ method: "POST";
22
+ body: z.ZodObject<{
23
+ password: z.ZodOptional<z.ZodString>;
24
+ method: z.ZodDefault<z.ZodEnum<{
25
+ otp: "otp";
26
+ totp: "totp";
27
+ }>>;
28
+ issuer: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$strip> | z.ZodObject<{
30
+ password: z.ZodString;
31
+ method: z.ZodDefault<z.ZodEnum<{
32
+ otp: "otp";
33
+ totp: "totp";
34
+ }>>;
35
+ issuer: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strip>;
37
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
38
+ session: {
39
+ session: Record<string, any> & {
40
+ id: string;
41
+ createdAt: Date;
42
+ updatedAt: Date;
43
+ userId: string;
44
+ expiresAt: Date;
45
+ token: string;
46
+ ipAddress?: string | null | undefined;
47
+ userAgent?: string | null | undefined;
48
+ };
49
+ user: Record<string, any> & {
50
+ id: string;
51
+ createdAt: Date;
52
+ updatedAt: Date;
53
+ email: string;
54
+ emailVerified: boolean;
55
+ name: string;
56
+ image?: string | null | undefined;
57
+ };
58
+ };
59
+ }>>[];
60
+ metadata: {
61
+ openapi: {
62
+ summary: string;
63
+ description: string;
64
+ };
65
+ };
66
+ }, {
67
+ method: "otp";
68
+ } | {
69
+ method: "totp";
70
+ secret: string;
71
+ totpURI: string;
72
+ backupCodes: string[];
73
+ period: number;
74
+ length: number;
75
+ }>;
76
+ /**
77
+ * POST `/authmoji/disable`
78
+ *
79
+ * Disables Authmoji 2FA, removes stored TOTP/backup secrets, and revokes
80
+ * any trusted-device cookie for the user.
81
+ */
82
+ disableAuthmoji: import("better-auth").StrictEndpoint<"/authmoji/disable", {
83
+ method: "POST";
84
+ body: z.ZodObject<{
85
+ password: z.ZodOptional<z.ZodString>;
86
+ }, z.core.$strip> | z.ZodObject<{
87
+ password: z.ZodString;
88
+ }, z.core.$strip>;
89
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
90
+ session: {
91
+ session: Record<string, any> & {
92
+ id: string;
93
+ createdAt: Date;
94
+ updatedAt: Date;
95
+ userId: string;
96
+ expiresAt: Date;
97
+ token: string;
98
+ ipAddress?: string | null | undefined;
99
+ userAgent?: string | null | undefined;
100
+ };
101
+ user: Record<string, any> & {
102
+ id: string;
103
+ createdAt: Date;
104
+ updatedAt: Date;
105
+ email: string;
106
+ emailVerified: boolean;
107
+ name: string;
108
+ image?: string | null | undefined;
109
+ };
110
+ };
111
+ }>>[];
112
+ metadata: {
113
+ openapi: {
114
+ summary: string;
115
+ description: string;
116
+ };
117
+ };
118
+ }, {
119
+ status: boolean;
120
+ }>;
121
+ /**
122
+ * GET `/authmoji/status`
123
+ *
124
+ * Returns the current user's Authmoji 2FA enrollment state and available methods.
125
+ */
126
+ getAuthmojiStatus: import("better-auth").StrictEndpoint<"/authmoji/status", {
127
+ method: "GET";
128
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
129
+ session: {
130
+ session: Record<string, any> & {
131
+ id: string;
132
+ createdAt: Date;
133
+ updatedAt: Date;
134
+ userId: string;
135
+ expiresAt: Date;
136
+ token: string;
137
+ ipAddress?: string | null | undefined;
138
+ userAgent?: string | null | undefined;
139
+ };
140
+ user: Record<string, any> & {
141
+ id: string;
142
+ createdAt: Date;
143
+ updatedAt: Date;
144
+ email: string;
145
+ emailVerified: boolean;
146
+ name: string;
147
+ image?: string | null | undefined;
148
+ };
149
+ };
150
+ }>>[];
151
+ metadata: {
152
+ openapi: {
153
+ summary: string;
154
+ description: string;
155
+ };
156
+ };
157
+ }, {
158
+ enabled: boolean;
159
+ methods: AuthmojiMethod[];
160
+ totpVerified: boolean;
161
+ hasBackupCodes: boolean;
162
+ }>;
163
+ /**
164
+ * POST `/authmoji/send-otp`
165
+ *
166
+ * Generates a random emoji OTP sequence, delivers the answer via the
167
+ * developer's `otpOptions.sendOTP` callback, and returns the shuffled
168
+ * tap-grid `choices` (never the answer) to the client.
169
+ */
170
+ sendAuthmojiOTP: import("better-auth").StrictEndpoint<"/authmoji/send-otp", {
171
+ method: "POST";
172
+ body: z.ZodOptional<z.ZodObject<{
173
+ trustDevice: z.ZodOptional<z.ZodBoolean>;
174
+ }, z.core.$strip>>;
175
+ metadata: {
176
+ openapi: {
177
+ summary: string;
178
+ description: string;
179
+ };
180
+ };
181
+ }, {
182
+ status: boolean;
183
+ choices: string[];
184
+ length: number;
185
+ expiresAt: string;
186
+ }>;
187
+ /**
188
+ * POST `/authmoji/verify-otp`
189
+ *
190
+ * Verifies a submitted emoji OTP sequence (as `code` string or `emojis`
191
+ * array) against the active challenge.
192
+ */
193
+ verifyAuthmojiOTP: import("better-auth").StrictEndpoint<"/authmoji/verify-otp", {
194
+ method: "POST";
195
+ body: z.ZodObject<{
196
+ code: z.ZodOptional<z.ZodString>;
197
+ emojis: z.ZodOptional<z.ZodArray<z.ZodString>>;
198
+ trustDevice: z.ZodOptional<z.ZodBoolean>;
199
+ }, z.core.$strip>;
200
+ metadata: {
201
+ openapi: {
202
+ summary: string;
203
+ description: string;
204
+ };
205
+ };
206
+ }, {
207
+ token: string | undefined;
208
+ user: UserWithAuthmoji;
209
+ }>;
210
+ /**
211
+ * Server-only helper `auth.api.generateAuthmojiTOTP`
212
+ *
213
+ * Computes the current emoji TOTP sequence for a Base32 secret.
214
+ * Not exposed over HTTP.
215
+ */
216
+ generateAuthmojiTOTP: import("better-auth").StrictEndpoint<string, {
217
+ method: "POST";
218
+ body: z.ZodObject<{
219
+ secret: z.ZodString;
220
+ timestamp: z.ZodOptional<z.ZodNumber>;
221
+ }, z.core.$strip>;
222
+ }, import("./totp.js").EmojiTOTPResult>;
223
+ /**
224
+ * POST `/authmoji/get-totp-uri`
225
+ *
226
+ * Re-fetches the user's `authmoji://totp/...` setup URI and Base32 secret
227
+ * after verifying their password.
228
+ */
229
+ getAuthmojiTOTPURI: import("better-auth").StrictEndpoint<"/authmoji/get-totp-uri", {
230
+ method: "POST";
231
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
232
+ session: {
233
+ session: Record<string, any> & {
234
+ id: string;
235
+ createdAt: Date;
236
+ updatedAt: Date;
237
+ userId: string;
238
+ expiresAt: Date;
239
+ token: string;
240
+ ipAddress?: string | null | undefined;
241
+ userAgent?: string | null | undefined;
242
+ };
243
+ user: Record<string, any> & {
244
+ id: string;
245
+ createdAt: Date;
246
+ updatedAt: Date;
247
+ email: string;
248
+ emailVerified: boolean;
249
+ name: string;
250
+ image?: string | null | undefined;
251
+ };
252
+ };
253
+ }>>[];
254
+ body: z.ZodObject<{
255
+ password: z.ZodOptional<z.ZodString>;
256
+ }, z.core.$strip> | z.ZodObject<{
257
+ password: z.ZodString;
258
+ }, z.core.$strip>;
259
+ metadata: {
260
+ openapi: {
261
+ summary: string;
262
+ description: string;
263
+ };
264
+ };
265
+ }, {
266
+ totpURI: string;
267
+ secret: string;
268
+ period: number;
269
+ length: number;
270
+ }>;
271
+ /**
272
+ * POST `/authmoji/get-totp-challenge`
273
+ *
274
+ * Returns a deterministically shuffled emoji tap-grid (`choices`) for the
275
+ * current TOTP time step. Repeated calls within the same step yield the
276
+ * exact same grid to prevent set-intersection leakage.
277
+ */
278
+ getAuthmojiTOTPChallenge: import("better-auth").StrictEndpoint<"/authmoji/get-totp-challenge", {
279
+ method: "POST";
280
+ metadata: {
281
+ openapi: {
282
+ summary: string;
283
+ description: string;
284
+ };
285
+ };
286
+ }, {
287
+ choices: string[];
288
+ length: number;
289
+ period: number;
290
+ expiresAt: string;
291
+ }>;
292
+ /**
293
+ * POST `/authmoji/verify-totp`
294
+ *
295
+ * Verifies an emoji TOTP code (for initial enrollment confirmation,
296
+ * sign-in 2FA completion, or step-up verification).
297
+ */
298
+ verifyAuthmojiTOTP: import("better-auth").StrictEndpoint<"/authmoji/verify-totp", {
299
+ method: "POST";
300
+ body: z.ZodObject<{
301
+ code: z.ZodOptional<z.ZodString>;
302
+ emojis: z.ZodOptional<z.ZodArray<z.ZodString>>;
303
+ trustDevice: z.ZodOptional<z.ZodBoolean>;
304
+ }, z.core.$strip>;
305
+ metadata: {
306
+ openapi: {
307
+ summary: string;
308
+ description: string;
309
+ };
310
+ };
311
+ }, {
312
+ token: string | undefined;
313
+ user: UserWithAuthmoji;
314
+ }>;
315
+ /**
316
+ * POST `/authmoji/generate-backup-codes`
317
+ *
318
+ * Replaces the user's recovery backup codes and returns the plaintext codes once.
319
+ */
320
+ generateAuthmojiBackupCodes: import("better-auth").StrictEndpoint<"/authmoji/generate-backup-codes", {
321
+ method: "POST";
322
+ body: z.ZodObject<{
323
+ password: z.ZodOptional<z.ZodString>;
324
+ }, z.core.$strip> | z.ZodObject<{
325
+ password: z.ZodString;
326
+ }, z.core.$strip>;
327
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
328
+ session: {
329
+ session: Record<string, any> & {
330
+ id: string;
331
+ createdAt: Date;
332
+ updatedAt: Date;
333
+ userId: string;
334
+ expiresAt: Date;
335
+ token: string;
336
+ ipAddress?: string | null | undefined;
337
+ userAgent?: string | null | undefined;
338
+ };
339
+ user: Record<string, any> & {
340
+ id: string;
341
+ createdAt: Date;
342
+ updatedAt: Date;
343
+ email: string;
344
+ emailVerified: boolean;
345
+ name: string;
346
+ image?: string | null | undefined;
347
+ };
348
+ };
349
+ }>>[];
350
+ metadata: {
351
+ openapi: {
352
+ summary: string;
353
+ description: string;
354
+ };
355
+ };
356
+ }, {
357
+ status: boolean;
358
+ backupCodes: string[];
359
+ }>;
360
+ /**
361
+ * POST `/authmoji/verify-backup-code`
362
+ *
363
+ * Verifies and consumes a single-use recovery backup code.
364
+ */
365
+ verifyAuthmojiBackupCode: import("better-auth").StrictEndpoint<"/authmoji/verify-backup-code", {
366
+ method: "POST";
367
+ body: z.ZodObject<{
368
+ code: z.ZodString;
369
+ disableSession: z.ZodOptional<z.ZodBoolean>;
370
+ trustDevice: z.ZodOptional<z.ZodBoolean>;
371
+ }, z.core.$strip>;
372
+ metadata: {
373
+ openapi: {
374
+ summary: string;
375
+ description: string;
376
+ };
377
+ };
378
+ }, {
379
+ token: string | undefined;
380
+ user: UserWithAuthmoji;
381
+ }>;
382
+ /**
383
+ * Server-only helper `auth.api.viewAuthmojiBackupCodes`
384
+ *
385
+ * Returns decrypted backup codes for a user from trusted server code.
386
+ * Not exposed over HTTP.
387
+ */
388
+ viewAuthmojiBackupCodes: import("better-auth").StrictEndpoint<string, {
389
+ method: "POST";
390
+ body: z.ZodObject<{
391
+ userId: z.ZodCoercedString<unknown>;
392
+ }, z.core.$strip>;
393
+ }, {
394
+ status: boolean;
395
+ backupCodes: string[];
396
+ }>;
397
+ };
398
+ options: AuthmojiOptions | undefined;
399
+ hooks: {
400
+ after: {
401
+ matcher(context: import("better-auth").HookEndpointContext): boolean;
402
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
403
+ twoFactorRedirect: boolean;
404
+ authmojiRedirect: boolean;
405
+ twoFactorMethods: AuthmojiMethod[];
406
+ methods: AuthmojiMethod[];
407
+ } | undefined>>;
408
+ }[];
409
+ };
410
+ schema: {
411
+ user: {
412
+ fields: {
413
+ authmojiEnabled: {
414
+ type: "boolean";
415
+ required: false;
416
+ defaultValue: false;
417
+ input: false;
418
+ };
419
+ };
420
+ };
421
+ authmoji: {
422
+ fields: {
423
+ secret: {
424
+ type: "string";
425
+ required: true;
426
+ returned: false;
427
+ index: true;
428
+ };
429
+ backupCodes: {
430
+ type: "string";
431
+ required: true;
432
+ returned: false;
433
+ };
434
+ userId: {
435
+ type: "string";
436
+ required: true;
437
+ returned: false;
438
+ references: {
439
+ model: string;
440
+ field: string;
441
+ };
442
+ index: true;
443
+ };
444
+ verified: {
445
+ type: "boolean";
446
+ required: false;
447
+ defaultValue: false;
448
+ input: false;
449
+ };
450
+ lastTotpCounter: {
451
+ type: "number";
452
+ required: false;
453
+ input: false;
454
+ returned: false;
455
+ };
456
+ failedVerificationCount: {
457
+ type: "number";
458
+ required: false;
459
+ defaultValue: number;
460
+ input: false;
461
+ returned: false;
462
+ };
463
+ lockedUntil: {
464
+ type: "date";
465
+ required: false;
466
+ input: false;
467
+ returned: false;
468
+ };
469
+ };
470
+ };
471
+ };
472
+ rateLimit: {
473
+ pathMatcher(path: string): boolean;
474
+ window: number;
475
+ max: number;
476
+ }[];
477
+ $ERROR_CODES: {
478
+ ACCOUNT_TEMPORARILY_LOCKED: import("./error-codes.js").AuthmojiErrorEntry<"ACCOUNT_TEMPORARILY_LOCKED">;
479
+ AUTHMOJI_NOT_ENABLED: import("./error-codes.js").AuthmojiErrorEntry<"AUTHMOJI_NOT_ENABLED">;
480
+ BACKUP_CODES_NOT_ENABLED: import("./error-codes.js").AuthmojiErrorEntry<"BACKUP_CODES_NOT_ENABLED">;
481
+ INVALID_AUTHMOJI_COOKIE: import("./error-codes.js").AuthmojiErrorEntry<"INVALID_AUTHMOJI_COOKIE">;
482
+ INVALID_BACKUP_CODE: import("./error-codes.js").AuthmojiErrorEntry<"INVALID_BACKUP_CODE">;
483
+ INVALID_CODE: import("./error-codes.js").AuthmojiErrorEntry<"INVALID_CODE">;
484
+ INVALID_PASSWORD: import("./error-codes.js").AuthmojiErrorEntry<"INVALID_PASSWORD">;
485
+ OTP_HAS_EXPIRED: import("./error-codes.js").AuthmojiErrorEntry<"OTP_HAS_EXPIRED">;
486
+ OTP_NOT_CONFIGURED: import("./error-codes.js").AuthmojiErrorEntry<"OTP_NOT_CONFIGURED">;
487
+ TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE: import("./error-codes.js").AuthmojiErrorEntry<"TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE">;
488
+ TOTP_ALREADY_ENABLED: import("./error-codes.js").AuthmojiErrorEntry<"TOTP_ALREADY_ENABLED">;
489
+ TOTP_CHOICES_DISABLED: import("./error-codes.js").AuthmojiErrorEntry<"TOTP_CHOICES_DISABLED">;
490
+ TOTP_NOT_CONFIGURED: import("./error-codes.js").AuthmojiErrorEntry<"TOTP_NOT_CONFIGURED">;
491
+ TOTP_NOT_ENABLED: import("./error-codes.js").AuthmojiErrorEntry<"TOTP_NOT_ENABLED">;
492
+ UNAUTHORIZED: import("./error-codes.js").AuthmojiErrorEntry<"UNAUTHORIZED">;
493
+ };
494
+ };