@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,250 @@
1
+ import type { GenericEndpointContext, InferOptionSchema, User } from "better-auth";
2
+ import type { GroupKey } from "emojibase";
3
+ import type { EmojiPoolInput } from "./emojis.js";
4
+ import type { authmojiSchema } from "./schema.js";
5
+ import type { TOTPAlgorithm } from "./totp.js";
6
+ export type Awaitable<T> = T | Promise<T>;
7
+ export type AuthmojiMethod = "otp" | "totp";
8
+ export interface UserWithAuthmoji extends User {
9
+ authmojiEnabled?: boolean | null;
10
+ }
11
+ export interface AuthmojiRecord {
12
+ id: string;
13
+ userId: string;
14
+ secret: string;
15
+ backupCodes: string;
16
+ verified: boolean;
17
+ lastTotpCounter?: number | null;
18
+ failedVerificationCount?: number | null;
19
+ lockedUntil?: Date | null;
20
+ }
21
+ export type StoreOTPOption = "plain" | "encrypted" | "hashed" | {
22
+ hash: (token: string) => Awaitable<string>;
23
+ } | {
24
+ encrypt: (token: string) => Awaitable<string>;
25
+ decrypt: (token: string) => Awaitable<string>;
26
+ };
27
+ export type StoreBackupCodesOption = "plain" | "encrypted" | {
28
+ encrypt: (data: string) => Awaitable<string>;
29
+ decrypt: (data: string) => Awaitable<string>;
30
+ };
31
+ export interface SendAuthmojiOTPData {
32
+ /** Authenticated or signing-in user receiving the OTP. */
33
+ user: UserWithAuthmoji;
34
+ /** Ordered emoji answer sequence (e.g. `["😍", "🀩", "🍣"]`). */
35
+ emojis: string[];
36
+ /** Concatenated emoji answer string (e.g. `"😍🀩🍣"`). */
37
+ code: string;
38
+ /** Shuffled tap-grid options returned to the client UI. */
39
+ choices: string[];
40
+ /** Timestamp when this OTP expires. */
41
+ expiresAt: Date;
42
+ }
43
+ export interface AuthmojiOTPOptions {
44
+ /**
45
+ * Deliver the generated emoji OTP to the user via SMS, email, push, Slack, etc.
46
+ * OTP is enabled whenever `sendOTP` is provided.
47
+ */
48
+ sendOTP?: (data: SendAuthmojiOTPData, ctx: GenericEndpointContext) => Awaitable<void>;
49
+ /**
50
+ * Number of emojis in the OTP answer sequence.
51
+ * @default 3
52
+ */
53
+ length?: number;
54
+ /**
55
+ * Number of shuffled emoji tiles returned as tap-grid choices.
56
+ * Set to `0` to disable returning choices.
57
+ * @default 8
58
+ */
59
+ choiceCount?: number;
60
+ /**
61
+ * Validity period of an OTP in minutes.
62
+ * @default 5
63
+ */
64
+ period?: number;
65
+ /**
66
+ * Maximum verification attempts per OTP before it is invalidated.
67
+ * @default 3
68
+ */
69
+ allowedAttempts?: number;
70
+ /**
71
+ * How OTP answers are stored in Better Auth's verification table.
72
+ * @default "hashed"
73
+ */
74
+ storeOTP?: StoreOTPOption;
75
+ }
76
+ export interface AuthmojiTOTPOptions {
77
+ /**
78
+ * Disable TOTP entirely (for OTP-only deployments).
79
+ * @default false
80
+ */
81
+ disable?: boolean;
82
+ /**
83
+ * Number of emojis in each TOTP code.
84
+ * @default 3
85
+ */
86
+ length?: number;
87
+ /**
88
+ * Number of shuffled emoji tiles returned by `get-totp-challenge`.
89
+ * Set to `0` to disable choice grids for TOTP.
90
+ * @default 8
91
+ */
92
+ choiceCount?: number;
93
+ /**
94
+ * Time step period in seconds.
95
+ * @default 30
96
+ */
97
+ period?: number;
98
+ /**
99
+ * Clock-skew window in time steps (`Β±window`).
100
+ * @default 1
101
+ */
102
+ window?: number;
103
+ /**
104
+ * HMAC hash algorithm for TOTP derivation.
105
+ * @default "SHA-256"
106
+ */
107
+ algorithm?: TOTPAlgorithm;
108
+ /**
109
+ * Reject re-use of a previously accepted TOTP counter.
110
+ * @default true
111
+ */
112
+ preventReplay?: boolean;
113
+ /**
114
+ * Maximum TOTP verification attempts per sign-in challenge.
115
+ * @default 5
116
+ */
117
+ allowedAttempts?: number;
118
+ /**
119
+ * Secret size in bytes when enrolling TOTP.
120
+ * @default 20
121
+ */
122
+ secretByteLength?: number;
123
+ }
124
+ export interface AuthmojiBackupCodeOptions {
125
+ /**
126
+ * Number of backup codes to generate.
127
+ * @default 10
128
+ */
129
+ amount?: number;
130
+ /**
131
+ * Character length of alphanumeric backup codes, or emoji count for `"emoji"` format.
132
+ * @default 10 (alphanumeric) or 6 (emoji)
133
+ */
134
+ length?: number;
135
+ /**
136
+ * Format of generated backup codes.
137
+ * @default "alphanumeric"
138
+ */
139
+ format?: "alphanumeric" | "emoji";
140
+ /**
141
+ * Custom backup code generator.
142
+ */
143
+ customBackupCodesGenerate?: () => string[];
144
+ /**
145
+ * How backup codes are stored in the database.
146
+ * @default "encrypted"
147
+ */
148
+ storeBackupCodes?: StoreBackupCodesOption;
149
+ }
150
+ export interface AuthmojiAccountLockoutOptions {
151
+ /**
152
+ * Whether consecutive failed verification attempts lock the account.
153
+ * @default true
154
+ */
155
+ enabled?: boolean;
156
+ /**
157
+ * Consecutive failed attempts across challenges before temporary lockout.
158
+ * @default 10
159
+ */
160
+ maxFailedAttempts?: number;
161
+ /**
162
+ * Lockout duration in seconds.
163
+ * @default 900 (15 minutes)
164
+ */
165
+ durationSeconds?: number;
166
+ }
167
+ export interface AuthmojiOptions {
168
+ /**
169
+ * Application / issuer name used in `authmoji://totp/...` URIs.
170
+ * Falls back to Better Auth's `appName`.
171
+ */
172
+ issuer?: string;
173
+ /**
174
+ * Custom emoji alphabet or Emojibase dataset (`CompactEmoji[]` / `Emoji[]`)
175
+ * shared by OTP and TOTP. Defaults to `emojibase-data/en/compact.json`.
176
+ */
177
+ emojis?: EmojiPoolInput;
178
+ /**
179
+ * Optional Emojibase group filter (e.g. `["smileys-emotion", "animals-nature", "food-drink"]`)
180
+ * applied to the emoji dataset.
181
+ */
182
+ emojiGroups?: readonly GroupKey[];
183
+ /**
184
+ * OTP (one-time emoji sequence) configuration.
185
+ */
186
+ otpOptions?: AuthmojiOTPOptions;
187
+ /**
188
+ * TOTP (time-based emoji sequence) configuration.
189
+ */
190
+ totpOptions?: AuthmojiTOTPOptions;
191
+ /**
192
+ * Recovery backup codes configuration.
193
+ */
194
+ backupCodeOptions?: AuthmojiBackupCodeOptions;
195
+ /**
196
+ * Skip initial TOTP verification when calling `/authmoji/enable`.
197
+ * @default false
198
+ */
199
+ skipVerificationOnEnable?: boolean;
200
+ /**
201
+ * Allow enabling, managing, and disabling Authmoji without a password when
202
+ * the user has no credential account (e.g. OAuth/passkey-only users).
203
+ * Users with a password still must verify it.
204
+ * @default false
205
+ */
206
+ allowPasswordless?: boolean;
207
+ /**
208
+ * Additional sign-in paths to intercept for Authmoji 2FA.
209
+ * By default intercepts `/sign-in/email`, `/sign-in/username`, and `/sign-in/phone-number`.
210
+ */
211
+ signInPaths?: string[];
212
+ /**
213
+ * Maximum age (in seconds) for the pending Authmoji challenge cookie.
214
+ * @default 600 (10 minutes)
215
+ */
216
+ authmojiCookieMaxAge?: number;
217
+ /**
218
+ * Maximum age (in seconds) for the trusted device cookie.
219
+ * @default 2592000 (30 days)
220
+ */
221
+ trustDeviceMaxAge?: number;
222
+ /**
223
+ * Account-level lockout for repeated failed verification attempts.
224
+ */
225
+ accountLockout?: AuthmojiAccountLockoutOptions;
226
+ /**
227
+ * Custom table name for Authmoji records.
228
+ * @default "authmoji"
229
+ */
230
+ authmojiTable?: string;
231
+ /**
232
+ * Custom schema overrides for the Authmoji plugin tables and fields.
233
+ */
234
+ schema?: InferOptionSchema<typeof authmojiSchema>;
235
+ }
236
+ export interface AuthmojiRedirectContext {
237
+ methods: AuthmojiMethod[];
238
+ twoFactorMethods: AuthmojiMethod[];
239
+ }
240
+ export interface AuthmojiClientOptions {
241
+ /**
242
+ * Callback invoked when sign-in requires an Authmoji second-factor challenge.
243
+ */
244
+ onTwoFactorRedirect?: (context: AuthmojiRedirectContext) => Awaitable<void>;
245
+ /**
246
+ * Page URL to redirect to when sign-in requires Authmoji verification
247
+ * (used when `onTwoFactorRedirect` is not provided).
248
+ */
249
+ twoFactorPage?: string;
250
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,14 +1,83 @@
1
1
  {
2
2
  "name": "@authmoji/better-auth",
3
- "version": "0.0.0",
4
- "description": "Initial placeholder for npm Trusted Publishing bootstrap",
3
+ "version": "0.1.0",
4
+ "description": "Authmoji plugin for Better Auth β€” emoji-based OTP and TOTP two-factor authentication",
5
+ "keywords": [
6
+ "authmoji",
7
+ "better-auth",
8
+ "better-auth-plugin",
9
+ "2fa",
10
+ "mfa",
11
+ "otp",
12
+ "totp",
13
+ "emoji",
14
+ "authentication"
15
+ ],
16
+ "homepage": "https://github.com/ShipWorthyAI/authmoji#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/ShipWorthyAI/authmoji/issues"
19
+ },
5
20
  "license": "MIT",
21
+ "author": "Chris Lott",
6
22
  "repository": {
7
23
  "type": "git",
8
24
  "url": "git+https://github.com/ShipWorthyAI/authmoji.git",
9
25
  "directory": "packages/better-auth"
10
26
  },
27
+ "files": [
28
+ "dist",
29
+ "LICENSE",
30
+ "package.json",
31
+ "README.md"
32
+ ],
33
+ "type": "module",
34
+ "main": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "./client": {
43
+ "types": "./dist/client.d.ts",
44
+ "import": "./dist/client.js",
45
+ "default": "./dist/client.js"
46
+ },
47
+ "./totp": {
48
+ "types": "./dist/totp.d.ts",
49
+ "import": "./dist/totp.js",
50
+ "default": "./dist/totp.js"
51
+ },
52
+ "./emojis": {
53
+ "types": "./dist/emojis.d.ts",
54
+ "import": "./dist/emojis.js",
55
+ "default": "./dist/emojis.js"
56
+ }
57
+ },
11
58
  "publishConfig": {
12
- "access": "public"
59
+ "access": "public",
60
+ "provenance": true
61
+ },
62
+ "scripts": {
63
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
64
+ "typecheck": "tsc --noEmit",
65
+ "check": "bun check",
66
+ "test": "bun test",
67
+ "clean": "rm -rf dist .turbo"
68
+ },
69
+ "peerDependencies": {
70
+ "better-auth": "^1.5.0"
71
+ },
72
+ "dependencies": {
73
+ "emojibase": "^18.0.0",
74
+ "emojibase-data": "^18.0.0",
75
+ "zod": "^4.5.4"
76
+ },
77
+ "devDependencies": {
78
+ "@shipworthy/tsconfig": "0.0.0",
79
+ "@types/bun": "^1.4.5",
80
+ "better-auth": "^1.7.28",
81
+ "typescript": "^7.0.2"
13
82
  }
14
83
  }