better-auth 1.3.1 → 1.3.2

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 (241) hide show
  1. package/dist/adapters/drizzle-adapter/index.d.cts +2 -2
  2. package/dist/adapters/drizzle-adapter/index.d.mts +2 -2
  3. package/dist/adapters/drizzle-adapter/index.d.ts +2 -2
  4. package/dist/adapters/index.d.cts +3 -3
  5. package/dist/adapters/index.d.mts +3 -3
  6. package/dist/adapters/index.d.ts +3 -3
  7. package/dist/adapters/kysely-adapter/index.d.cts +2 -2
  8. package/dist/adapters/kysely-adapter/index.d.mts +2 -2
  9. package/dist/adapters/kysely-adapter/index.d.ts +2 -2
  10. package/dist/adapters/memory-adapter/index.d.cts +2 -2
  11. package/dist/adapters/memory-adapter/index.d.mts +2 -2
  12. package/dist/adapters/memory-adapter/index.d.ts +2 -2
  13. package/dist/adapters/mongodb-adapter/index.d.cts +2 -2
  14. package/dist/adapters/mongodb-adapter/index.d.mts +2 -2
  15. package/dist/adapters/mongodb-adapter/index.d.ts +2 -2
  16. package/dist/adapters/prisma-adapter/index.d.cts +2 -2
  17. package/dist/adapters/prisma-adapter/index.d.mts +2 -2
  18. package/dist/adapters/prisma-adapter/index.d.ts +2 -2
  19. package/dist/adapters/test.d.cts +2 -2
  20. package/dist/adapters/test.d.mts +2 -2
  21. package/dist/adapters/test.d.ts +2 -2
  22. package/dist/api/index.cjs +1 -1
  23. package/dist/api/index.d.cts +2 -2
  24. package/dist/api/index.d.mts +2 -2
  25. package/dist/api/index.d.ts +2 -2
  26. package/dist/api/index.mjs +2 -2
  27. package/dist/client/index.d.cts +4 -4
  28. package/dist/client/index.d.mts +4 -4
  29. package/dist/client/index.d.ts +4 -4
  30. package/dist/client/plugins/index.d.cts +4 -4
  31. package/dist/client/plugins/index.d.mts +4 -4
  32. package/dist/client/plugins/index.d.ts +4 -4
  33. package/dist/client/react/index.d.cts +4 -4
  34. package/dist/client/react/index.d.mts +4 -4
  35. package/dist/client/react/index.d.ts +4 -4
  36. package/dist/client/solid/index.d.cts +4 -4
  37. package/dist/client/solid/index.d.mts +4 -4
  38. package/dist/client/solid/index.d.ts +4 -4
  39. package/dist/client/svelte/index.d.cts +4 -4
  40. package/dist/client/svelte/index.d.mts +4 -4
  41. package/dist/client/svelte/index.d.ts +4 -4
  42. package/dist/client/vue/index.d.cts +4 -4
  43. package/dist/client/vue/index.d.mts +4 -4
  44. package/dist/client/vue/index.d.ts +4 -4
  45. package/dist/cookies/index.d.cts +2 -2
  46. package/dist/cookies/index.d.mts +2 -2
  47. package/dist/cookies/index.d.ts +2 -2
  48. package/dist/db/index.d.cts +12 -12
  49. package/dist/db/index.d.mts +12 -12
  50. package/dist/db/index.d.ts +12 -12
  51. package/dist/index.cjs +2 -2
  52. package/dist/index.d.cts +4 -4
  53. package/dist/index.d.mts +4 -4
  54. package/dist/index.d.ts +4 -4
  55. package/dist/index.mjs +2 -2
  56. package/dist/integrations/next-js.cjs +2 -2
  57. package/dist/integrations/next-js.d.cts +2 -2
  58. package/dist/integrations/next-js.d.mts +2 -2
  59. package/dist/integrations/next-js.d.ts +2 -2
  60. package/dist/integrations/next-js.mjs +2 -2
  61. package/dist/integrations/node.d.cts +2 -2
  62. package/dist/integrations/node.d.mts +2 -2
  63. package/dist/integrations/node.d.ts +2 -2
  64. package/dist/integrations/react-start.cjs +2 -2
  65. package/dist/integrations/react-start.d.cts +2 -2
  66. package/dist/integrations/react-start.d.mts +2 -2
  67. package/dist/integrations/react-start.d.ts +2 -2
  68. package/dist/integrations/react-start.mjs +2 -2
  69. package/dist/integrations/svelte-kit.cjs +1 -1
  70. package/dist/integrations/svelte-kit.d.cts +2 -2
  71. package/dist/integrations/svelte-kit.d.mts +2 -2
  72. package/dist/integrations/svelte-kit.d.ts +2 -2
  73. package/dist/integrations/svelte-kit.mjs +1 -1
  74. package/dist/oauth2/index.cjs +1 -1
  75. package/dist/oauth2/index.d.cts +4 -4
  76. package/dist/oauth2/index.d.mts +4 -4
  77. package/dist/oauth2/index.d.ts +4 -4
  78. package/dist/oauth2/index.mjs +1 -1
  79. package/dist/plugins/admin/index.cjs +2 -2
  80. package/dist/plugins/admin/index.d.cts +67 -67
  81. package/dist/plugins/admin/index.d.mts +67 -67
  82. package/dist/plugins/admin/index.d.ts +67 -67
  83. package/dist/plugins/admin/index.mjs +2 -2
  84. package/dist/plugins/anonymous/index.cjs +1 -1
  85. package/dist/plugins/anonymous/index.d.cts +2 -2
  86. package/dist/plugins/anonymous/index.d.mts +2 -2
  87. package/dist/plugins/anonymous/index.d.ts +2 -2
  88. package/dist/plugins/anonymous/index.mjs +1 -1
  89. package/dist/plugins/bearer/index.cjs +1 -1
  90. package/dist/plugins/bearer/index.d.cts +2 -2
  91. package/dist/plugins/bearer/index.d.mts +2 -2
  92. package/dist/plugins/bearer/index.d.ts +2 -2
  93. package/dist/plugins/bearer/index.mjs +1 -1
  94. package/dist/plugins/captcha/index.d.cts +2 -2
  95. package/dist/plugins/captcha/index.d.mts +2 -2
  96. package/dist/plugins/captcha/index.d.ts +2 -2
  97. package/dist/plugins/custom-session/index.cjs +1 -1
  98. package/dist/plugins/custom-session/index.d.cts +7 -7
  99. package/dist/plugins/custom-session/index.d.mts +7 -7
  100. package/dist/plugins/custom-session/index.d.ts +7 -7
  101. package/dist/plugins/custom-session/index.mjs +1 -1
  102. package/dist/plugins/email-otp/index.cjs +1 -1
  103. package/dist/plugins/email-otp/index.d.cts +31 -31
  104. package/dist/plugins/email-otp/index.d.mts +31 -31
  105. package/dist/plugins/email-otp/index.d.ts +31 -31
  106. package/dist/plugins/email-otp/index.mjs +1 -1
  107. package/dist/plugins/generic-oauth/index.cjs +1 -1
  108. package/dist/plugins/generic-oauth/index.d.cts +24 -24
  109. package/dist/plugins/generic-oauth/index.d.mts +24 -24
  110. package/dist/plugins/generic-oauth/index.d.ts +24 -24
  111. package/dist/plugins/generic-oauth/index.mjs +1 -1
  112. package/dist/plugins/haveibeenpwned/index.cjs +1 -1
  113. package/dist/plugins/haveibeenpwned/index.d.cts +2 -2
  114. package/dist/plugins/haveibeenpwned/index.d.mts +2 -2
  115. package/dist/plugins/haveibeenpwned/index.d.ts +2 -2
  116. package/dist/plugins/haveibeenpwned/index.mjs +1 -1
  117. package/dist/plugins/index.cjs +7 -7
  118. package/dist/plugins/index.d.cts +26 -26
  119. package/dist/plugins/index.d.mts +26 -26
  120. package/dist/plugins/index.d.ts +26 -26
  121. package/dist/plugins/index.mjs +9 -9
  122. package/dist/plugins/jwt/index.cjs +2 -2
  123. package/dist/plugins/jwt/index.d.cts +2 -2
  124. package/dist/plugins/jwt/index.d.mts +2 -2
  125. package/dist/plugins/jwt/index.d.ts +2 -2
  126. package/dist/plugins/jwt/index.mjs +2 -2
  127. package/dist/plugins/magic-link/index.cjs +1 -1
  128. package/dist/plugins/magic-link/index.d.cts +14 -14
  129. package/dist/plugins/magic-link/index.d.mts +14 -14
  130. package/dist/plugins/magic-link/index.d.ts +14 -14
  131. package/dist/plugins/magic-link/index.mjs +1 -1
  132. package/dist/plugins/multi-session/index.cjs +1 -1
  133. package/dist/plugins/multi-session/index.d.cts +9 -9
  134. package/dist/plugins/multi-session/index.d.mts +9 -9
  135. package/dist/plugins/multi-session/index.d.ts +9 -9
  136. package/dist/plugins/multi-session/index.mjs +1 -1
  137. package/dist/plugins/oauth-proxy/index.cjs +1 -1
  138. package/dist/plugins/oauth-proxy/index.d.cts +7 -7
  139. package/dist/plugins/oauth-proxy/index.d.mts +7 -7
  140. package/dist/plugins/oauth-proxy/index.d.ts +7 -7
  141. package/dist/plugins/oauth-proxy/index.mjs +1 -1
  142. package/dist/plugins/oidc-provider/index.cjs +3 -3
  143. package/dist/plugins/oidc-provider/index.d.cts +27 -27
  144. package/dist/plugins/oidc-provider/index.d.mts +27 -27
  145. package/dist/plugins/oidc-provider/index.d.ts +27 -27
  146. package/dist/plugins/oidc-provider/index.mjs +3 -3
  147. package/dist/plugins/one-tap/index.cjs +1 -1
  148. package/dist/plugins/one-tap/index.d.cts +4 -4
  149. package/dist/plugins/one-tap/index.d.mts +4 -4
  150. package/dist/plugins/one-tap/index.d.ts +4 -4
  151. package/dist/plugins/one-tap/index.mjs +1 -1
  152. package/dist/plugins/one-time-token/index.cjs +3 -3
  153. package/dist/plugins/one-time-token/index.d.cts +6 -6
  154. package/dist/plugins/one-time-token/index.d.mts +6 -6
  155. package/dist/plugins/one-time-token/index.d.ts +6 -6
  156. package/dist/plugins/one-time-token/index.mjs +3 -3
  157. package/dist/plugins/open-api/index.cjs +1 -1
  158. package/dist/plugins/open-api/index.d.cts +2 -2
  159. package/dist/plugins/open-api/index.d.mts +2 -2
  160. package/dist/plugins/open-api/index.d.ts +2 -2
  161. package/dist/plugins/open-api/index.mjs +1 -1
  162. package/dist/plugins/organization/index.cjs +3 -3
  163. package/dist/plugins/organization/index.d.cts +390 -390
  164. package/dist/plugins/organization/index.d.mts +390 -390
  165. package/dist/plugins/organization/index.d.ts +390 -390
  166. package/dist/plugins/organization/index.mjs +3 -3
  167. package/dist/plugins/passkey/index.cjs +1 -1
  168. package/dist/plugins/passkey/index.d.cts +23 -23
  169. package/dist/plugins/passkey/index.d.mts +23 -23
  170. package/dist/plugins/passkey/index.d.ts +23 -23
  171. package/dist/plugins/passkey/index.mjs +1 -1
  172. package/dist/plugins/phone-number/index.cjs +1 -1
  173. package/dist/plugins/phone-number/index.d.cts +28 -28
  174. package/dist/plugins/phone-number/index.d.mts +28 -28
  175. package/dist/plugins/phone-number/index.d.ts +28 -28
  176. package/dist/plugins/phone-number/index.mjs +1 -1
  177. package/dist/plugins/siwe/index.cjs +297 -0
  178. package/dist/plugins/siwe/index.d.cts +195 -0
  179. package/dist/plugins/siwe/index.d.mts +195 -0
  180. package/dist/plugins/siwe/index.d.ts +195 -0
  181. package/dist/plugins/siwe/index.mjs +295 -0
  182. package/dist/plugins/sso/index.cjs +1 -1
  183. package/dist/plugins/sso/index.d.cts +45 -45
  184. package/dist/plugins/sso/index.d.mts +45 -45
  185. package/dist/plugins/sso/index.d.ts +45 -45
  186. package/dist/plugins/sso/index.mjs +1 -1
  187. package/dist/plugins/two-factor/index.cjs +1 -1
  188. package/dist/plugins/two-factor/index.d.cts +38 -38
  189. package/dist/plugins/two-factor/index.d.mts +38 -38
  190. package/dist/plugins/two-factor/index.d.ts +38 -38
  191. package/dist/plugins/two-factor/index.mjs +1 -1
  192. package/dist/plugins/username/index.cjs +1 -1
  193. package/dist/plugins/username/index.d.cts +12 -12
  194. package/dist/plugins/username/index.d.mts +12 -12
  195. package/dist/plugins/username/index.d.ts +12 -12
  196. package/dist/plugins/username/index.mjs +1 -1
  197. package/dist/shared/{better-auth.C-oNfZPH.d.cts → better-auth.B0e3ZzlM.d.cts} +36 -36
  198. package/dist/shared/{better-auth.CE16lr3i.d.mts → better-auth.B1VHvePI.d.mts} +36 -36
  199. package/dist/shared/{better-auth.DoKaQIwy.d.mts → better-auth.BF0l18Af.d.mts} +1 -1
  200. package/dist/shared/{better-auth.CNTpFj_S.cjs → better-auth.BXW4aAiQ.cjs} +2 -2
  201. package/dist/shared/{better-auth.DdKZcMVt.d.ts → better-auth.B_G094Aj.d.ts} +1 -1
  202. package/dist/shared/{better-auth.DQfCK4Nb.mjs → better-auth.Bqt8-7ls.mjs} +2 -2
  203. package/dist/shared/{better-auth.DevRAmVV.d.ts → better-auth.Bwe61noi.d.ts} +1 -1
  204. package/dist/shared/{better-auth.B3K6UWYy.d.cts → better-auth.CF-FWRQL.d.cts} +1 -1
  205. package/dist/shared/{better-auth.D2QnAIyP.d.ts → better-auth.CHvHihjD.d.ts} +36 -36
  206. package/dist/shared/{better-auth.pnE8EkZO.cjs → better-auth.COsDmM8f.cjs} +1 -1
  207. package/dist/shared/{better-auth.B8mbk3HM.cjs → better-auth.CSftMZoM.cjs} +1 -1
  208. package/dist/shared/{better-auth.DG2FJeYI.cjs → better-auth.CU2ZnFFo.cjs} +4 -3
  209. package/dist/shared/{better-auth.KpzJUkxw.d.mts → better-auth.CePXeKag.d.mts} +515 -515
  210. package/dist/shared/{better-auth.CnqHgquB.cjs → better-auth.CeY8lCIq.cjs} +33 -11
  211. package/dist/shared/{better-auth.Cgjn2thr.d.cts → better-auth.CiGummYu.d.cts} +515 -515
  212. package/dist/shared/{better-auth.BP6KhZxK.mjs → better-auth.D1SaVuxk.mjs} +1 -1
  213. package/dist/shared/{better-auth.BOumacvv.mjs → better-auth.D4HhkCZJ.mjs} +4 -3
  214. package/dist/shared/{better-auth.PchrD52N.d.cts → better-auth.DEgvs2nh.d.cts} +1 -1
  215. package/dist/shared/{better-auth._di0pH6c.mjs → better-auth.DGaVMVAI.mjs} +1 -1
  216. package/dist/shared/{better-auth.PS9uuCnX.d.ts → better-auth.DPa2nz5L.d.ts} +3 -3
  217. package/dist/shared/{better-auth.VKKx-2JU.mjs → better-auth.DR6QsC6j.mjs} +33 -11
  218. package/dist/shared/{better-auth.ByEh_r9h.d.mts → better-auth.DbqVX6sp.d.mts} +1 -1
  219. package/dist/shared/{better-auth.2lcgvW_O.d.ts → better-auth.Dj2HyOmw.d.ts} +515 -515
  220. package/dist/shared/{better-auth.Bs90Z5lG.mjs → better-auth.DygEm6OX.mjs} +1 -1
  221. package/dist/shared/{better-auth.jZedDYFo.mjs → better-auth.HDgvLN7B.mjs} +2 -2
  222. package/dist/shared/{better-auth.KXK1cTP6.d.mts → better-auth.IegS6fw_.d.mts} +3 -3
  223. package/dist/shared/{better-auth.B448Gbxg.cjs → better-auth.PIkdXr0U.cjs} +2 -2
  224. package/dist/shared/{better-auth.DCdVWPIH.cjs → better-auth.TnpcdNJo.cjs} +1 -1
  225. package/dist/shared/{better-auth.hWM7ExMT.mjs → better-auth.VOBpdwFt.mjs} +1 -1
  226. package/dist/shared/{better-auth.CtknPsTc.cjs → better-auth.johXc5IC.cjs} +1 -1
  227. package/dist/shared/{better-auth.DVIqLF8t.d.cts → better-auth.npEvGVS_.d.cts} +3 -3
  228. package/dist/social-providers/index.cjs +1 -1
  229. package/dist/social-providers/index.d.cts +1 -1
  230. package/dist/social-providers/index.d.mts +1 -1
  231. package/dist/social-providers/index.d.ts +1 -1
  232. package/dist/social-providers/index.mjs +1 -1
  233. package/dist/test-utils/index.cjs +3 -3
  234. package/dist/test-utils/index.d.cts +732 -731
  235. package/dist/test-utils/index.d.mts +732 -731
  236. package/dist/test-utils/index.d.ts +732 -731
  237. package/dist/test-utils/index.mjs +3 -3
  238. package/dist/types/index.d.cts +3 -3
  239. package/dist/types/index.d.mts +3 -3
  240. package/dist/types/index.d.ts +3 -3
  241. package/package.json +14 -1
@@ -0,0 +1,195 @@
1
+ import * as better_call from 'better-call';
2
+ import { z } from 'zod';
3
+
4
+ interface CacaoHeader {
5
+ t: "caip122";
6
+ }
7
+ interface CacaoPayload {
8
+ domain: string;
9
+ aud: string;
10
+ nonce: string;
11
+ iss: string;
12
+ version?: string;
13
+ iat?: string;
14
+ nbf?: string;
15
+ exp?: string;
16
+ statement?: string;
17
+ requestId?: string;
18
+ resources?: string[];
19
+ type?: string;
20
+ }
21
+ interface Cacao {
22
+ h: CacaoHeader;
23
+ p: CacaoPayload;
24
+ s: {
25
+ t: "eip191" | "eip1271";
26
+ s: string;
27
+ m?: string;
28
+ };
29
+ }
30
+ interface SIWEVerifyMessageArgs {
31
+ message: string;
32
+ signature: string;
33
+ address: string;
34
+ chainId: number;
35
+ cacao?: Cacao;
36
+ }
37
+ interface ENSLookupArgs {
38
+ walletAddress: string;
39
+ }
40
+ interface ENSLookupResult {
41
+ name: string;
42
+ avatar: string;
43
+ }
44
+
45
+ interface SIWEPluginOptions {
46
+ domain: string;
47
+ emailDomainName?: string;
48
+ anonymous?: boolean;
49
+ getNonce: () => Promise<string>;
50
+ verifyMessage: (args: SIWEVerifyMessageArgs) => Promise<boolean>;
51
+ ensLookup?: (args: ENSLookupArgs) => Promise<ENSLookupResult>;
52
+ }
53
+ declare const siwe: (options: SIWEPluginOptions) => {
54
+ id: "siwe";
55
+ schema: {
56
+ walletAddress: {
57
+ fields: {
58
+ userId: {
59
+ type: "string";
60
+ references: {
61
+ model: string;
62
+ field: string;
63
+ };
64
+ required: true;
65
+ };
66
+ address: {
67
+ type: "string";
68
+ required: true;
69
+ };
70
+ chainId: {
71
+ type: "number";
72
+ required: true;
73
+ };
74
+ isPrimary: {
75
+ type: "boolean";
76
+ defaultValue: false;
77
+ };
78
+ createdAt: {
79
+ type: "date";
80
+ required: true;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ endpoints: {
86
+ getSiweNonce: {
87
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
88
+ body: {
89
+ walletAddress: string;
90
+ chainId?: number | undefined;
91
+ };
92
+ } & {
93
+ method?: "POST" | undefined;
94
+ } & {
95
+ query?: Record<string, any> | undefined;
96
+ } & {
97
+ params?: Record<string, any>;
98
+ } & {
99
+ request?: Request;
100
+ } & {
101
+ headers?: HeadersInit;
102
+ } & {
103
+ asResponse?: boolean;
104
+ returnHeaders?: boolean;
105
+ use?: better_call.Middleware[];
106
+ path?: string;
107
+ } & {
108
+ asResponse?: AsResponse | undefined;
109
+ returnHeaders?: ReturnHeaders | undefined;
110
+ }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
111
+ headers: Headers;
112
+ response: {
113
+ nonce: string;
114
+ };
115
+ } : {
116
+ nonce: string;
117
+ }>;
118
+ options: {
119
+ method: "POST";
120
+ body: z.ZodObject<{
121
+ walletAddress: z.ZodString;
122
+ chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
123
+ }, z.core.$strip>;
124
+ } & {
125
+ use: any[];
126
+ };
127
+ path: "/siwe/nonce";
128
+ };
129
+ verifySiweMessage: {
130
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
131
+ body: {
132
+ message: string;
133
+ signature: string;
134
+ walletAddress: string;
135
+ chainId?: number | undefined;
136
+ email?: string | undefined;
137
+ };
138
+ } & {
139
+ method?: "POST" | undefined;
140
+ } & {
141
+ query?: Record<string, any> | undefined;
142
+ } & {
143
+ params?: Record<string, any>;
144
+ } & {
145
+ request: Request;
146
+ } & {
147
+ headers?: HeadersInit;
148
+ } & {
149
+ asResponse?: boolean;
150
+ returnHeaders?: boolean;
151
+ use?: better_call.Middleware[];
152
+ path?: string;
153
+ } & {
154
+ asResponse?: AsResponse | undefined;
155
+ returnHeaders?: ReturnHeaders | undefined;
156
+ }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
157
+ headers: Headers;
158
+ response: {
159
+ token: string;
160
+ success: boolean;
161
+ user: {
162
+ id: string;
163
+ walletAddress: string;
164
+ chainId: number;
165
+ };
166
+ };
167
+ } : {
168
+ token: string;
169
+ success: boolean;
170
+ user: {
171
+ id: string;
172
+ walletAddress: string;
173
+ chainId: number;
174
+ };
175
+ }>;
176
+ options: {
177
+ method: "POST";
178
+ body: z.ZodObject<{
179
+ message: z.ZodString;
180
+ signature: z.ZodString;
181
+ walletAddress: z.ZodString;
182
+ chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
183
+ email: z.ZodOptional<z.ZodString>;
184
+ }, z.core.$strip>;
185
+ requireRequest: true;
186
+ } & {
187
+ use: any[];
188
+ };
189
+ path: "/siwe/verify";
190
+ };
191
+ };
192
+ };
193
+
194
+ export { siwe };
195
+ export type { SIWEPluginOptions };
@@ -0,0 +1,195 @@
1
+ import * as better_call from 'better-call';
2
+ import { z } from 'zod';
3
+
4
+ interface CacaoHeader {
5
+ t: "caip122";
6
+ }
7
+ interface CacaoPayload {
8
+ domain: string;
9
+ aud: string;
10
+ nonce: string;
11
+ iss: string;
12
+ version?: string;
13
+ iat?: string;
14
+ nbf?: string;
15
+ exp?: string;
16
+ statement?: string;
17
+ requestId?: string;
18
+ resources?: string[];
19
+ type?: string;
20
+ }
21
+ interface Cacao {
22
+ h: CacaoHeader;
23
+ p: CacaoPayload;
24
+ s: {
25
+ t: "eip191" | "eip1271";
26
+ s: string;
27
+ m?: string;
28
+ };
29
+ }
30
+ interface SIWEVerifyMessageArgs {
31
+ message: string;
32
+ signature: string;
33
+ address: string;
34
+ chainId: number;
35
+ cacao?: Cacao;
36
+ }
37
+ interface ENSLookupArgs {
38
+ walletAddress: string;
39
+ }
40
+ interface ENSLookupResult {
41
+ name: string;
42
+ avatar: string;
43
+ }
44
+
45
+ interface SIWEPluginOptions {
46
+ domain: string;
47
+ emailDomainName?: string;
48
+ anonymous?: boolean;
49
+ getNonce: () => Promise<string>;
50
+ verifyMessage: (args: SIWEVerifyMessageArgs) => Promise<boolean>;
51
+ ensLookup?: (args: ENSLookupArgs) => Promise<ENSLookupResult>;
52
+ }
53
+ declare const siwe: (options: SIWEPluginOptions) => {
54
+ id: "siwe";
55
+ schema: {
56
+ walletAddress: {
57
+ fields: {
58
+ userId: {
59
+ type: "string";
60
+ references: {
61
+ model: string;
62
+ field: string;
63
+ };
64
+ required: true;
65
+ };
66
+ address: {
67
+ type: "string";
68
+ required: true;
69
+ };
70
+ chainId: {
71
+ type: "number";
72
+ required: true;
73
+ };
74
+ isPrimary: {
75
+ type: "boolean";
76
+ defaultValue: false;
77
+ };
78
+ createdAt: {
79
+ type: "date";
80
+ required: true;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ endpoints: {
86
+ getSiweNonce: {
87
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
88
+ body: {
89
+ walletAddress: string;
90
+ chainId?: number | undefined;
91
+ };
92
+ } & {
93
+ method?: "POST" | undefined;
94
+ } & {
95
+ query?: Record<string, any> | undefined;
96
+ } & {
97
+ params?: Record<string, any>;
98
+ } & {
99
+ request?: Request;
100
+ } & {
101
+ headers?: HeadersInit;
102
+ } & {
103
+ asResponse?: boolean;
104
+ returnHeaders?: boolean;
105
+ use?: better_call.Middleware[];
106
+ path?: string;
107
+ } & {
108
+ asResponse?: AsResponse | undefined;
109
+ returnHeaders?: ReturnHeaders | undefined;
110
+ }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
111
+ headers: Headers;
112
+ response: {
113
+ nonce: string;
114
+ };
115
+ } : {
116
+ nonce: string;
117
+ }>;
118
+ options: {
119
+ method: "POST";
120
+ body: z.ZodObject<{
121
+ walletAddress: z.ZodString;
122
+ chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
123
+ }, z.core.$strip>;
124
+ } & {
125
+ use: any[];
126
+ };
127
+ path: "/siwe/nonce";
128
+ };
129
+ verifySiweMessage: {
130
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
131
+ body: {
132
+ message: string;
133
+ signature: string;
134
+ walletAddress: string;
135
+ chainId?: number | undefined;
136
+ email?: string | undefined;
137
+ };
138
+ } & {
139
+ method?: "POST" | undefined;
140
+ } & {
141
+ query?: Record<string, any> | undefined;
142
+ } & {
143
+ params?: Record<string, any>;
144
+ } & {
145
+ request: Request;
146
+ } & {
147
+ headers?: HeadersInit;
148
+ } & {
149
+ asResponse?: boolean;
150
+ returnHeaders?: boolean;
151
+ use?: better_call.Middleware[];
152
+ path?: string;
153
+ } & {
154
+ asResponse?: AsResponse | undefined;
155
+ returnHeaders?: ReturnHeaders | undefined;
156
+ }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
157
+ headers: Headers;
158
+ response: {
159
+ token: string;
160
+ success: boolean;
161
+ user: {
162
+ id: string;
163
+ walletAddress: string;
164
+ chainId: number;
165
+ };
166
+ };
167
+ } : {
168
+ token: string;
169
+ success: boolean;
170
+ user: {
171
+ id: string;
172
+ walletAddress: string;
173
+ chainId: number;
174
+ };
175
+ }>;
176
+ options: {
177
+ method: "POST";
178
+ body: z.ZodObject<{
179
+ message: z.ZodString;
180
+ signature: z.ZodString;
181
+ walletAddress: z.ZodString;
182
+ chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
183
+ email: z.ZodOptional<z.ZodString>;
184
+ }, z.core.$strip>;
185
+ requireRequest: true;
186
+ } & {
187
+ use: any[];
188
+ };
189
+ path: "/siwe/verify";
190
+ };
191
+ };
192
+ };
193
+
194
+ export { siwe };
195
+ export type { SIWEPluginOptions };
@@ -0,0 +1,295 @@
1
+ import { APIError } from 'better-call';
2
+ import { j as createAuthEndpoint } from '../../shared/better-auth.D4HhkCZJ.mjs';
3
+ import 'zod/v4';
4
+ import { setSessionCookie } from '../../cookies/index.mjs';
5
+ import '../../shared/better-auth.n2KFGwjY.mjs';
6
+ import '../../shared/better-auth.8zoxzg-F.mjs';
7
+ import '../../shared/better-auth.DBGfIDnh.mjs';
8
+ import 'defu';
9
+ import { z } from 'zod';
10
+ import { g as getOrigin } from '../../shared/better-auth.VTXNLFMT.mjs';
11
+ import { keccak_256 } from '@noble/hashes/sha3';
12
+ import '../../shared/better-auth.CW6D9eSx.mjs';
13
+ import '@better-auth/utils/hash';
14
+ import '@better-auth/utils/base64';
15
+ import '../../crypto/index.mjs';
16
+ import '@noble/ciphers/chacha';
17
+ import '@noble/ciphers/utils';
18
+ import '@noble/ciphers/webcrypto';
19
+ import 'jose';
20
+ import '@noble/hashes/scrypt';
21
+ import '@better-auth/utils';
22
+ import '@better-auth/utils/hex';
23
+ import '@noble/hashes/utils';
24
+ import '../../shared/better-auth.B4Qoxdgc.mjs';
25
+ import '@better-auth/utils/random';
26
+ import '@better-fetch/fetch';
27
+ import '../../shared/better-auth.tB5eU6EY.mjs';
28
+ import '@better-auth/utils/hmac';
29
+ import '@better-auth/utils/binary';
30
+ import 'jose/errors';
31
+ import '../../shared/better-auth.DdzSJf-n.mjs';
32
+
33
+ const schema = {
34
+ walletAddress: {
35
+ fields: {
36
+ userId: {
37
+ type: "string",
38
+ references: {
39
+ model: "user",
40
+ field: "id"
41
+ },
42
+ required: true
43
+ },
44
+ address: {
45
+ type: "string",
46
+ required: true
47
+ },
48
+ chainId: {
49
+ type: "number",
50
+ required: true
51
+ },
52
+ isPrimary: {
53
+ type: "boolean",
54
+ defaultValue: false
55
+ },
56
+ createdAt: {
57
+ type: "date",
58
+ required: true
59
+ }
60
+ }
61
+ }
62
+ };
63
+
64
+ function toChecksumAddress(address) {
65
+ address = address.toLowerCase().replace("0x", "");
66
+ const hash = [...keccak_256(address)].map((v) => v.toString(16).padStart(2, "0")).join("");
67
+ let ret = "0x";
68
+ for (let i = 0; i < 40; i++) {
69
+ if (parseInt(hash[i], 16) >= 8) {
70
+ ret += address[i].toUpperCase();
71
+ } else {
72
+ ret += address[i];
73
+ }
74
+ }
75
+ return ret;
76
+ }
77
+
78
+ const siwe = (options) => ({
79
+ id: "siwe",
80
+ schema,
81
+ endpoints: {
82
+ getSiweNonce: createAuthEndpoint(
83
+ "/siwe/nonce",
84
+ {
85
+ method: "POST",
86
+ body: z.object({
87
+ walletAddress: z.string().regex(/^0[xX][a-fA-F0-9]{40}$/i).length(42),
88
+ chainId: z.number().int().positive().max(2147483647).optional().default(1)
89
+ // Default to Ethereum mainnet
90
+ })
91
+ },
92
+ async (ctx) => {
93
+ const { walletAddress: rawWalletAddress, chainId } = ctx.body;
94
+ const walletAddress = toChecksumAddress(rawWalletAddress);
95
+ const nonce = await options.getNonce();
96
+ await ctx.context.internalAdapter.createVerificationValue({
97
+ identifier: `siwe:${walletAddress}:${chainId}`,
98
+ value: nonce,
99
+ expiresAt: new Date(Date.now() + 15 * 60 * 1e3)
100
+ });
101
+ return ctx.json({ nonce });
102
+ }
103
+ ),
104
+ verifySiweMessage: createAuthEndpoint(
105
+ "/siwe/verify",
106
+ {
107
+ method: "POST",
108
+ body: z.object({
109
+ message: z.string().min(1),
110
+ signature: z.string().min(1),
111
+ walletAddress: z.string().regex(/^0[xX][a-fA-F0-9]{40}$/i).length(42),
112
+ chainId: z.number().int().positive().max(2147483647).optional().default(1),
113
+ email: z.string().email().optional()
114
+ }).refine((data) => options.anonymous !== false || !!data.email, {
115
+ message: "Email is required when the anonymous plugin option is disabled.",
116
+ path: ["email"]
117
+ }),
118
+ requireRequest: true
119
+ },
120
+ async (ctx) => {
121
+ const {
122
+ message,
123
+ signature,
124
+ walletAddress: rawWalletAddress,
125
+ chainId,
126
+ email
127
+ } = ctx.body;
128
+ const walletAddress = toChecksumAddress(rawWalletAddress);
129
+ const isAnon = options.anonymous ?? true;
130
+ if (!isAnon && !email) {
131
+ throw new APIError("BAD_REQUEST", {
132
+ message: "Email is required when anonymous is disabled.",
133
+ status: 400
134
+ });
135
+ }
136
+ try {
137
+ const verification = await ctx.context.internalAdapter.findVerificationValue(
138
+ `siwe:${walletAddress}:${chainId}`
139
+ );
140
+ if (!verification || /* @__PURE__ */ new Date() > verification.expiresAt) {
141
+ throw new APIError("UNAUTHORIZED", {
142
+ message: "Unauthorized: Invalid or expired nonce",
143
+ status: 401,
144
+ code: "UNAUTHORIZED_INVALID_OR_EXPIRED_NONCE"
145
+ });
146
+ }
147
+ const { value: nonce } = verification;
148
+ const verified = await options.verifyMessage({
149
+ message,
150
+ signature,
151
+ address: walletAddress,
152
+ chainId,
153
+ cacao: {
154
+ h: { t: "caip122" },
155
+ p: {
156
+ domain: options.domain,
157
+ aud: options.domain,
158
+ nonce,
159
+ iss: options.domain,
160
+ version: "1"
161
+ },
162
+ s: { t: "eip191", s: signature }
163
+ }
164
+ });
165
+ if (!verified) {
166
+ throw new APIError("UNAUTHORIZED", {
167
+ message: "Unauthorized: Invalid SIWE signature",
168
+ status: 401
169
+ });
170
+ }
171
+ await ctx.context.internalAdapter.deleteVerificationValue(
172
+ verification.id
173
+ );
174
+ let user = null;
175
+ const existingWalletAddress = await ctx.context.adapter.findOne({
176
+ model: "walletAddress",
177
+ where: [
178
+ { field: "address", operator: "eq", value: walletAddress },
179
+ { field: "chainId", operator: "eq", value: chainId }
180
+ ]
181
+ });
182
+ if (existingWalletAddress) {
183
+ user = await ctx.context.adapter.findOne({
184
+ model: "user",
185
+ where: [
186
+ {
187
+ field: "id",
188
+ operator: "eq",
189
+ value: existingWalletAddress.userId
190
+ }
191
+ ]
192
+ });
193
+ } else {
194
+ const anyWalletAddress = await ctx.context.adapter.findOne({
195
+ model: "walletAddress",
196
+ where: [
197
+ { field: "address", operator: "eq", value: walletAddress }
198
+ ]
199
+ });
200
+ if (anyWalletAddress) {
201
+ user = await ctx.context.adapter.findOne({
202
+ model: "user",
203
+ where: [
204
+ {
205
+ field: "id",
206
+ operator: "eq",
207
+ value: anyWalletAddress.userId
208
+ }
209
+ ]
210
+ });
211
+ }
212
+ }
213
+ if (!user) {
214
+ const domain = options.emailDomainName ?? getOrigin(ctx.context.baseURL);
215
+ const userEmail = !isAnon && email ? email : `${walletAddress}@${domain}`;
216
+ const { name, avatar } = await options.ensLookup?.({ walletAddress }) ?? {};
217
+ user = await ctx.context.internalAdapter.createUser({
218
+ name: name ?? walletAddress,
219
+ email: userEmail,
220
+ image: avatar ?? ""
221
+ });
222
+ await ctx.context.adapter.create({
223
+ model: "walletAddress",
224
+ data: {
225
+ userId: user.id,
226
+ address: walletAddress,
227
+ chainId,
228
+ isPrimary: true,
229
+ // First address is primary
230
+ createdAt: /* @__PURE__ */ new Date()
231
+ }
232
+ });
233
+ await ctx.context.internalAdapter.createAccount({
234
+ userId: user.id,
235
+ providerId: "siwe",
236
+ accountId: `${walletAddress}:${chainId}`,
237
+ createdAt: /* @__PURE__ */ new Date(),
238
+ updatedAt: /* @__PURE__ */ new Date()
239
+ });
240
+ } else {
241
+ if (!existingWalletAddress) {
242
+ await ctx.context.adapter.create({
243
+ model: "walletAddress",
244
+ data: {
245
+ userId: user.id,
246
+ address: walletAddress,
247
+ chainId,
248
+ isPrimary: false,
249
+ // Additional addresses are not primary by default
250
+ createdAt: /* @__PURE__ */ new Date()
251
+ }
252
+ });
253
+ await ctx.context.internalAdapter.createAccount({
254
+ userId: user.id,
255
+ providerId: "siwe",
256
+ accountId: `${walletAddress}:${chainId}`,
257
+ createdAt: /* @__PURE__ */ new Date(),
258
+ updatedAt: /* @__PURE__ */ new Date()
259
+ });
260
+ }
261
+ }
262
+ const session = await ctx.context.internalAdapter.createSession(
263
+ user.id,
264
+ ctx
265
+ );
266
+ if (!session) {
267
+ throw new APIError("INTERNAL_SERVER_ERROR", {
268
+ message: "Internal Server Error",
269
+ status: 500
270
+ });
271
+ }
272
+ await setSessionCookie(ctx, { session, user });
273
+ return ctx.json({
274
+ token: session.token,
275
+ success: true,
276
+ user: {
277
+ id: user.id,
278
+ walletAddress,
279
+ chainId
280
+ }
281
+ });
282
+ } catch (error) {
283
+ if (error instanceof APIError) throw error;
284
+ throw new APIError("UNAUTHORIZED", {
285
+ message: "Something went wrong. Please try again later.",
286
+ error: error instanceof Error ? error.message : "Unknown error",
287
+ status: 401
288
+ });
289
+ }
290
+ }
291
+ )
292
+ }
293
+ });
294
+
295
+ export { siwe };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const z = require('zod/v4');
4
4
  const betterCall = require('better-call');
5
- const socialProviders_index = require('../../shared/better-auth.DG2FJeYI.cjs');
5
+ const socialProviders_index = require('../../shared/better-auth.CU2ZnFFo.cjs');
6
6
  const cookies_index = require('../../cookies/index.cjs');
7
7
  require('../../shared/better-auth.BIMq4RPW.cjs');
8
8
  require('../../shared/better-auth.DiSjtgs9.cjs');