@zerodev/wallet-react-ui 0.0.6 → 0.0.7

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 (53) hide show
  1. package/README.md +54 -10
  2. package/dist/_types/auth/authStoreSlice.d.ts +3 -4
  3. package/dist/_types/auth/authStoreSlice.d.ts.map +1 -1
  4. package/dist/_types/auth/hooks/useAuth.d.ts +0 -2
  5. package/dist/_types/auth/hooks/useAuth.d.ts.map +1 -1
  6. package/dist/_types/auth/index.d.ts +9 -1
  7. package/dist/_types/auth/index.d.ts.map +1 -1
  8. package/dist/_types/auth/pages/OtpInput.d.ts.map +1 -1
  9. package/dist/_types/auth/pages/SignUp/Email.d.ts +4 -0
  10. package/dist/_types/auth/pages/SignUp/Email.d.ts.map +1 -0
  11. package/dist/_types/auth/pages/SignUp/Google.d.ts +3 -0
  12. package/dist/_types/auth/pages/SignUp/Google.d.ts.map +1 -0
  13. package/dist/_types/auth/pages/SignUp/Passkey.d.ts +3 -0
  14. package/dist/_types/auth/pages/SignUp/Passkey.d.ts.map +1 -0
  15. package/dist/_types/auth/pages/SignUp/context.d.ts +25 -0
  16. package/dist/_types/auth/pages/SignUp/context.d.ts.map +1 -0
  17. package/dist/_types/auth/pages/SignUp/index.d.ts +31 -0
  18. package/dist/_types/auth/pages/SignUp/index.d.ts.map +1 -0
  19. package/dist/_types/auth/pages/Verifying.d.ts.map +1 -1
  20. package/dist/_types/auth/types.d.ts +0 -8
  21. package/dist/_types/auth/types.d.ts.map +1 -1
  22. package/dist/_types/auth/utils/isCancellationError.d.ts +2 -0
  23. package/dist/_types/auth/utils/isCancellationError.d.ts.map +1 -0
  24. package/dist/_types/connector.d.ts +3 -13
  25. package/dist/_types/connector.d.ts.map +1 -1
  26. package/dist/_types/index.d.ts +4 -3
  27. package/dist/_types/index.d.ts.map +1 -1
  28. package/dist/_types/store.d.ts +1 -6
  29. package/dist/_types/store.d.ts.map +1 -1
  30. package/dist/index.cjs +3 -3
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.mjs +555 -562
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/styles.css +1 -1
  35. package/package.json +3 -3
  36. package/src/auth/authStoreSlice.ts +7 -13
  37. package/src/auth/hooks/useAuth.ts +0 -5
  38. package/src/auth/index.tsx +19 -7
  39. package/src/auth/pages/OtpInput.tsx +1 -4
  40. package/src/auth/pages/SignUp/Email.tsx +86 -0
  41. package/src/auth/pages/SignUp/Google.tsx +43 -0
  42. package/src/auth/pages/SignUp/Passkey.tsx +56 -0
  43. package/src/auth/pages/SignUp/context.tsx +41 -0
  44. package/src/auth/pages/SignUp/index.tsx +138 -0
  45. package/src/auth/pages/Verifying.tsx +3 -10
  46. package/src/auth/types.ts +0 -9
  47. package/src/auth/utils/isCancellationError.ts +8 -0
  48. package/src/connector.ts +12 -28
  49. package/src/index.ts +3 -3
  50. package/src/store.ts +1 -8
  51. package/dist/_types/auth/pages/SignUp.d.ts +0 -2
  52. package/dist/_types/auth/pages/SignUp.d.ts.map +0 -1
  53. package/src/auth/pages/SignUp.tsx +0 -311
package/README.md CHANGED
@@ -35,11 +35,6 @@ export const config = createConfig({
35
35
  zeroDevWallet({
36
36
  projectId: 'your-project-id', // from https://dashboard.zerodev.app
37
37
  chains: [sepolia],
38
- config: {
39
- auth: {
40
- enabledMethods: ['email', 'google', 'passkey'],
41
- },
42
- },
43
38
  }),
44
39
  ],
45
40
  transports: { [sepolia.id]: http() },
@@ -74,11 +69,11 @@ function Root() {
74
69
 
75
70
  ## Usage
76
71
 
77
- Mount `<AuthFlow />` to render the active sign-in screen. Connecting via the
72
+ Mount `<ConnectWallet />` to render the active sign-in screen. Connecting via the
78
73
  `zeroDevWallet` connector is what opens the auth flow.
79
74
 
80
75
  ```tsx
81
- import { AuthFlow } from '@zerodev/wallet-react-ui'
76
+ import { ConnectWallet } from '@zerodev/wallet-react-ui'
82
77
  import { useAccount, useConnect } from 'wagmi'
83
78
 
84
79
  function App() {
@@ -91,7 +86,7 @@ function App() {
91
86
  <button onClick={() => connect({ connector: connectors[0] })}>
92
87
  Connect
93
88
  </button>
94
- <AuthFlow />
89
+ <ConnectWallet />
95
90
  </>
96
91
  )
97
92
  }
@@ -100,17 +95,66 @@ function App() {
100
95
  }
101
96
  ```
102
97
 
98
+ ### Customizing the sign-up page
99
+
100
+ Bare `<ConnectWallet />` renders the canonical sign-up page (passkey → Google →
101
+ email). Which methods appear — and how — is decided by composition, not
102
+ config.
103
+
104
+ Keep the default page and set its options:
105
+
106
+ ```tsx
107
+ <ConnectWallet
108
+ logo={<YourLogo />}
109
+ renderSignUp={() => (
110
+ <SignUp.Default
111
+ emailAuthMethod="otp" // 'magicLink' (default) | 'otp'
112
+ termsAndConditionsUrl="https://example.com/terms"
113
+ privacyPolicyUrl="https://example.com/privacy"
114
+ />
115
+ )}
116
+ />
117
+ ```
118
+
119
+ Or compose the page yourself from the `SignUp.*` units:
120
+
121
+ ```tsx
122
+ import { ConnectWallet, SignUp } from '@zerodev/wallet-react-ui'
123
+
124
+ <ConnectWallet
125
+ renderSignUp={() => (
126
+ <SignUp emailAuthMethod="otp" termsAndConditionsUrl="https://example.com/terms">
127
+ <SignUp.Google />
128
+ <SignUp.Divider />
129
+ <SignUp.Email />
130
+ </SignUp>
131
+ )}
132
+ />
133
+ ```
134
+
135
+ - `<SignUp>` (the root) owns the shared page state and the consent gate: when
136
+ either terms URL is set, a checkbox appears and every method is blocked
137
+ until the user agrees. `emailAuthMethod` picks the email verification flow.
138
+ - Units: `SignUp.Passkey`, `SignUp.Google`, `SignUp.Email`, `SignUp.Divider`.
139
+ Order and presence are yours; while one method is in flight, the others
140
+ disable themselves.
141
+ - `SignUp.Default` is the canonical composition; it accepts the same props as
142
+ the root and forwards them.
143
+ - Auth success/failure surfaces through wagmi — await `connect`, or watch
144
+ `useAccount()`.
145
+
103
146
  ## API
104
147
 
105
148
  | Export | Description |
106
149
  | --- | --- |
107
150
  | `zeroDevWallet` | wagmi connector with kit-specific auth extensions. |
108
- | `<AuthFlow />` | Renders the current auth step (sign-in, OTP, verifying, etc.). |
151
+ | `<ConnectWallet />` | Renders the current auth step (sign-in, OTP, verifying, etc.). Props: `logo`, `renderSignUp`, `size`, `onClose`. |
152
+ | `<SignUp />` | Compound sign-up page: `SignUp.Default` plus the composable units (`Passkey`, `Google`, `Email`, `Divider`). |
109
153
  | `useAuth` | Read / drive the auth flow state. |
110
154
 
111
155
  ### Types
112
156
 
113
- `AuthMethod`, `AuthStep`, `ZeroDevKitConfig`, `ZeroDevKitConnectorParams`.
157
+ `AuthMethod`, `AuthStep`, `EmailAuthMethod`, `ZeroDevKitConnectorParams`.
114
158
 
115
159
  ## Development
116
160
 
@@ -1,10 +1,9 @@
1
1
  import type { StateCreator } from 'zustand';
2
- import type { AuthConfig, AuthMethod, AuthStep } from './types';
2
+ import type { AuthStep } from './types';
3
3
  export interface AuthStoreSlice {
4
4
  auth: {
5
5
  step: AuthStep | null;
6
6
  stepHistory: AuthStep[];
7
- enabledMethods: AuthMethod[];
8
7
  email: string | null;
9
8
  setEmail: (email: string) => void;
10
9
  otpId: string | null;
@@ -20,8 +19,8 @@ export interface AuthStoreSlice {
20
19
  }) => void;
21
20
  /** Clear the persisted OTP session after a successful verify. */
22
21
  clearOtpSession: () => void;
23
- config: AuthConfig | null;
24
- initialize: (config: AuthConfig) => void;
22
+ /** Restore a persisted OTP session (survives reloads mid-email-flow). */
23
+ initialize: () => void;
25
24
  goToStep: (step: AuthStep | null) => void;
26
25
  goBack: () => void;
27
26
  reset: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"authStoreSlice.d.ts","sourceRoot":"","sources":["../../../src/auth/authStoreSlice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AA2C/D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QAEJ,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAA;QACrB,WAAW,EAAE,QAAQ,EAAE,CAAA;QACvB,cAAc,EAAE,UAAU,EAAE,CAAA;QAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;QACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QACpB;;;WAGG;QACH,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAA;QACxC,sDAAsD;QACtD,aAAa,EAAE,CAAC,KAAK,EAAE;YACrB,KAAK,EAAE,MAAM,CAAA;YACb,yBAAyB,EAAE,MAAM,CAAA;SAClC,KAAK,IAAI,CAAA;QACV,iEAAiE;QACjE,eAAe,EAAE,MAAM,IAAI,CAAA;QAC3B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;QAGzB,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAA;QACxC,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAA;QACzC,MAAM,EAAE,MAAM,IAAI,CAAA;QAClB,KAAK,EAAE,MAAM,IAAI,CAAA;KAClB,CAAA;CACF;AAED,eAAO,MAAM,oBAAoB,EAAE,YAAY,CAC7C,cAAc,EACd;CAAE,EACF;CAAE,EACF,cAAc,CAoGd,CAAA"}
1
+ {"version":3,"file":"authStoreSlice.d.ts","sourceRoot":"","sources":["../../../src/auth/authStoreSlice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AA2CvC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QAEJ,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAA;QACrB,WAAW,EAAE,QAAQ,EAAE,CAAA;QACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;QACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QACpB;;;WAGG;QACH,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAA;QACxC,sDAAsD;QACtD,aAAa,EAAE,CAAC,KAAK,EAAE;YACrB,KAAK,EAAE,MAAM,CAAA;YACb,yBAAyB,EAAE,MAAM,CAAA;SAClC,KAAK,IAAI,CAAA;QACV,iEAAiE;QACjE,eAAe,EAAE,MAAM,IAAI,CAAA;QAG3B,yEAAyE;QACzE,UAAU,EAAE,MAAM,IAAI,CAAA;QACtB,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAA;QACzC,MAAM,EAAE,MAAM,IAAI,CAAA;QAClB,KAAK,EAAE,MAAM,IAAI,CAAA;KAClB,CAAA;CACF;AAED,eAAO,MAAM,oBAAoB,EAAE,YAAY,CAC7C,cAAc,EACd;CAAE,EACF;CAAE,EACF,cAAc,CA+Fd,CAAA"}
@@ -3,8 +3,6 @@ export declare function useAuth(): {
3
3
  email: string | null;
4
4
  otpId: string | null;
5
5
  otpEncryptionTargetBundle: string | null;
6
- enabledMethods: import("../types").AuthMethod[];
7
- config: import("../types").AuthConfig | null;
8
6
  goToStep: (step: import("../types").AuthStep | null) => void;
9
7
  goBack: (() => void) | null;
10
8
  reset: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../../src/auth/hooks/useAuth.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO;;;;;;;;;;;;;;;;EA4BtB"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../../src/auth/hooks/useAuth.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO;;;;;;;;;;;;;;EAuBtB"}
@@ -1,5 +1,13 @@
1
- export declare function AuthFlow({ onClose: userOnClose, size, }?: {
1
+ import { type ReactNode } from 'react';
2
+ export declare function ConnectWallet({ onClose: userOnClose, size, renderSignUp, logo, }?: {
2
3
  onClose?: (() => void) | undefined;
3
4
  size?: 'sm' | 'md' | 'lg' | undefined;
5
+ /** Replace the default sign-up page: compose `SignUp.*` units inside
6
+ * `<SignUp>`. Omit to render the canonical page (`SignUp.Default`). */
7
+ renderSignUp?: (() => ReactNode) | undefined;
8
+ /** Optional brand logo for the top nav on the sign-up page. When omitted,
9
+ * no logo is shown. `PoweredBy` always shows the ZeroDev mark
10
+ * independently. */
11
+ logo?: ReactNode | undefined;
4
12
  }): import("react").JSX.Element | null;
5
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.tsx"],"names":[],"mappings":"AA8DA,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EAAE,WAAW,EACpB,IAAI,GACL,GAAE;IACD,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;CACjC,sCAyCL"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,OAAO,CAAA;AA8DjD,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EAAE,WAAW,EACpB,IAAI,EACJ,YAAY,EACZ,IAAI,GACL,GAAE;IACD,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;IACrC;2EACuE;IACvE,YAAY,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,SAAS,CAAA;IAC5C;;wBAEoB;IACpB,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CACxB,sCA2CL"}
@@ -1 +1 @@
1
- {"version":3,"file":"OtpInput.d.ts","sourceRoot":"","sources":["../../../../src/auth/pages/OtpInput.tsx"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,gCAoHvB"}
1
+ {"version":3,"file":"OtpInput.d.ts","sourceRoot":"","sources":["../../../../src/auth/pages/OtpInput.tsx"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,gCAiHvB"}
@@ -0,0 +1,4 @@
1
+ /** Email input row: sends an OTP or magic link depending on the root's
2
+ * `emailAuthMethod`, then advances to the matching verification step. */
3
+ export declare function SignUpEmail(): import("react").JSX.Element;
4
+ //# sourceMappingURL=Email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Email.d.ts","sourceRoot":"","sources":["../../../../../src/auth/pages/SignUp/Email.tsx"],"names":[],"mappings":"AAOA;yEACyE;AACzE,wBAAgB,WAAW,gCA4E1B"}
@@ -0,0 +1,3 @@
1
+ /** "Google" OAuth row. */
2
+ export declare function SignUpGoogle(): import("react").JSX.Element;
3
+ //# sourceMappingURL=Google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Google.d.ts","sourceRoot":"","sources":["../../../../../src/auth/pages/SignUp/Google.tsx"],"names":[],"mappings":"AAMA,0BAA0B;AAC1B,wBAAgB,YAAY,gCAmC3B"}
@@ -0,0 +1,3 @@
1
+ /** "Create a passkey" + "Log in with passkey" buttons. */
2
+ export declare function SignUpPasskey(): import("react").JSX.Element;
3
+ //# sourceMappingURL=Passkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Passkey.d.ts","sourceRoot":"","sources":["../../../../../src/auth/pages/SignUp/Passkey.tsx"],"names":[],"mappings":"AAMA,0DAA0D;AAC1D,wBAAgB,aAAa,gCAgD5B"}
@@ -0,0 +1,25 @@
1
+ import type { EmailAuthMethod } from '../../types';
2
+ export type SignUpContextValue = {
3
+ /** True while any method's auth attempt is in flight — used to disable
4
+ * sibling methods so two flows can't run at once. */
5
+ authPending: boolean;
6
+ setAuthPending: (pending: boolean) => void;
7
+ /** Which email verification flow the Email unit runs. Set on the root
8
+ * (`<SignUp emailAuthMethod=…>`); already resolved to its default here. */
9
+ emailAuthMethod: EmailAuthMethod;
10
+ /** True when the terms checkbox is required but unchecked. For passive
11
+ * disabled styling; use `guardAgreement` before starting an attempt. */
12
+ needsAgreement: boolean;
13
+ /** Call before starting an auth attempt: highlights the terms checkbox and
14
+ * returns false when agreement is required but missing. */
15
+ guardAgreement: () => boolean;
16
+ setError: (message: string | null) => void;
17
+ };
18
+ export declare const SignUpContext: import("react").Context<SignUpContextValue | null>;
19
+ export declare function useSignUpContext(): SignUpContextValue;
20
+ /** Mirror a method's in-flight state into the shared pending flag.
21
+ * Clears on unmount so a removed unit can't leave the page locked.
22
+ * One flag, not per-unit: methods are mutually exclusive, so at most one
23
+ * unit reports `true` at a time. */
24
+ export declare function useReportPending(pending: boolean): void;
25
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../src/auth/pages/SignUp/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;yDACqD;IACrD,WAAW,EAAE,OAAO,CAAA;IACpB,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1C;+EAC2E;IAC3E,eAAe,EAAE,eAAe,CAAA;IAChC;4EACwE;IACxE,cAAc,EAAE,OAAO,CAAA;IACvB;+DAC2D;IAC3D,cAAc,EAAE,MAAM,OAAO,CAAA;IAC7B,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;CAC3C,CAAA;AAED,eAAO,MAAM,aAAa,oDAAiD,CAAA;AAE3E,wBAAgB,gBAAgB,IAAI,kBAAkB,CAMrD;AAED;;;oCAGoC;AACpC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAMhD"}
@@ -0,0 +1,31 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { EmailAuthMethod } from '../../types';
3
+ import { SignUpEmail } from './Email';
4
+ import { SignUpGoogle } from './Google';
5
+ import { SignUpPasskey } from './Passkey';
6
+ type SignUpRootProps = {
7
+ children: ReactNode;
8
+ /** Enable the consent gate: linked from the footer checkbox, and every
9
+ * method is blocked until the user agrees when either URL is set. */
10
+ termsAndConditionsUrl?: string | undefined;
11
+ privacyPolicyUrl?: string | undefined;
12
+ /** Which email verification flow the Email unit runs. */
13
+ emailAuthMethod?: EmailAuthMethod | undefined;
14
+ };
15
+ declare function SignUpRoot({ children, termsAndConditionsUrl, privacyPolicyUrl, emailAuthMethod, }: SignUpRootProps): import("react").JSX.Element;
16
+ declare function SignUpDivider({ label }: {
17
+ label?: string;
18
+ }): import("react").JSX.Element;
19
+ /** The canonical sign-up page. Takes the root's own props (the consent-gate
20
+ * URLs) and forwards them — per-unit config (e.g. the email method) still
21
+ * means composing the units yourself. */
22
+ declare function SignUpDefault(props: Omit<SignUpRootProps, 'children'>): import("react").JSX.Element;
23
+ export declare const SignUp: typeof SignUpRoot & {
24
+ Default: typeof SignUpDefault;
25
+ Passkey: typeof SignUpPasskey;
26
+ Google: typeof SignUpGoogle;
27
+ Email: typeof SignUpEmail;
28
+ Divider: typeof SignUpDivider;
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/auth/pages/SignUp/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAA;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,SAAS,CAAA;IACnB;yEACqE;IACrE,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,yDAAyD;IACzD,eAAe,CAAC,EAAE,eAAe,GAAG,SAAS,CAAA;CAC9C,CAAA;AAED,iBAAS,UAAU,CAAC,EAClB,QAAQ,EACR,qBAAqB,EACrB,gBAAgB,EAChB,eAA6B,GAC9B,EAAE,eAAe,+BAgFjB;AAED,iBAAS,aAAa,CAAC,EAAE,KAAY,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,+BAQ1D;AAED;;yCAEyC;AACzC,iBAAS,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,+BAS9D;AAED,eAAO,MAAM,MAAM;;;;;;CAMjB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Verifying.d.ts","sourceRoot":"","sources":["../../../../src/auth/pages/Verifying.tsx"],"names":[],"mappings":"AAYA,wBAAgB,SAAS,gCA8FxB"}
1
+ {"version":3,"file":"Verifying.d.ts","sourceRoot":"","sources":["../../../../src/auth/pages/Verifying.tsx"],"names":[],"mappings":"AAYA,wBAAgB,SAAS,gCAuFxB"}
@@ -1,12 +1,4 @@
1
1
  export type AuthMethod = 'email' | 'google' | 'passkey';
2
2
  export type AuthStep = 'sign-up' | 'email-verification' | 'otp-input' | 'verifying-otp' | 'passkey-prompt' | 'oauth-in-progress' | 'wallet-selection' | 'authenticated' | 'error';
3
3
  export type EmailAuthMethod = 'magicLink' | 'otp';
4
- export interface AuthConfig {
5
- enabledMethods: AuthMethod[];
6
- emailAuthMethod?: EmailAuthMethod;
7
- termsAndConditionsUrl?: string;
8
- privacyPolicyUrl?: string;
9
- onSuccess?: () => void;
10
- onError?: (error: unknown) => void;
11
- }
12
4
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEvD,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,oBAAoB,GACpB,WAAW,GACX,eAAe,GACf,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,GAClB,eAAe,GACf,OAAO,CAAA;AAEX,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,KAAK,CAAA;AAEjD,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,UAAU,EAAE,CAAA;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEvD,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,oBAAoB,GACpB,WAAW,GACX,eAAe,GACf,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,GAClB,eAAe,GACf,OAAO,CAAA;AAEX,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,KAAK,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function isCancellationError(err: unknown): boolean;
2
+ //# sourceMappingURL=isCancellationError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isCancellationError.d.ts","sourceRoot":"","sources":["../../../../src/auth/utils/isCancellationError.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOzD"}
@@ -1,17 +1,7 @@
1
1
  import type { CreateConnectorFn } from '@wagmi/core';
2
2
  import type { ZeroDevWalletConnectorParams } from '@zerodev/wallet-react';
3
- import type { ReactNode } from 'react';
4
- import type { AuthConfig } from './auth/types';
5
- export type ZeroDevKitConfig = {
6
- auth?: AuthConfig;
7
- /**
8
- * Optional brand logo rendered in the auth flow's top nav. When omitted,
9
- * no logo is shown. `PoweredBy` always shows the ZeroDev mark independently.
10
- */
11
- logo?: ReactNode;
12
- };
13
- export type ZeroDevKitConnectorParams = ZeroDevWalletConnectorParams & {
14
- config?: ZeroDevKitConfig;
15
- };
3
+ /** The kit connector takes exactly the base connector's param
4
+ We alias it to leave room for expansion */
5
+ export type ZeroDevKitConnectorParams = ZeroDevWalletConnectorParams;
16
6
  export declare function zeroDevWallet(params: ZeroDevKitConnectorParams): CreateConnectorFn;
17
7
  //# sourceMappingURL=connector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAEV,4BAA4B,EAC7B,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAY9C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,4BAA4B,GAAG;IACrE,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAC1B,CAAA;AAuCD,wBAAgB,aAAa,CAC3B,MAAM,EAAE,yBAAyB,GAChC,iBAAiB,CA2GnB"}
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAEV,4BAA4B,EAC7B,MAAM,uBAAuB,CAAA;AAgB9B;2CAC2C;AAC3C,MAAM,MAAM,yBAAyB,GAAG,4BAA4B,CAAA;AAuCpE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,yBAAyB,GAChC,iBAAiB,CAsGnB"}
@@ -2,9 +2,10 @@
2
2
  * @zerodev/wallet-react-ui
3
3
  * React UI components and enhanced connector for ZeroDev Wallet SDK
4
4
  */
5
- export { AuthFlow } from './auth';
5
+ export { ConnectWallet } from './auth';
6
6
  export { useAuth } from './auth/hooks/useAuth';
7
- export type { AuthMethod, AuthStep } from './auth/types';
8
- export type { ZeroDevKitConfig, ZeroDevKitConnectorParams, } from './connector.js';
7
+ export { SignUp } from './auth/pages/SignUp';
8
+ export type { AuthMethod, AuthStep, EmailAuthMethod } from './auth/types';
9
+ export type { ZeroDevKitConnectorParams, } from './connector.js';
9
10
  export { zeroDevWallet } from './connector.js';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAGxD,YAAY,EAEV,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGzE,YAAY,EAEV,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,19 +1,14 @@
1
- import type { ReactNode } from 'react';
2
1
  import { type AuthStoreSlice } from './auth/authStoreSlice';
3
2
  import type { PendingRequest } from './types.js';
4
3
  export type State = {
5
4
  pendingRequests: PendingRequest[];
6
5
  userConfirmationListenerActive: boolean;
7
- logo: ReactNode | null;
8
6
  addPendingRequest: (request: PendingRequest) => void;
9
7
  removePendingRequest: (id: string) => void;
10
8
  clearPendingRequests: () => void;
11
9
  setUserConfirmationListenerActive: (active: boolean) => void;
12
10
  } & AuthStoreSlice;
13
- export type CreateStoreOptions = {
14
- logo?: ReactNode;
15
- };
16
- export declare const createStore: (options?: CreateStoreOptions) => import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<State>, "subscribe"> & {
11
+ export declare const createStore: () => import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<State>, "subscribe"> & {
17
12
  subscribe: {
18
13
  (listener: (selectedState: State, previousSelectedState: State) => void): () => void;
19
14
  <U>(selector: (state: State) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,MAAM,KAAK,GAAG;IAClB,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,8BAA8B,EAAE,OAAO,CAAA;IACvC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IACtB,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAA;IACpD,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,oBAAoB,EAAE,MAAM,IAAI,CAAA;IAChC,iCAAiC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;CAC7D,GAAG,cAAc,CAAA;AAElB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,UAAS,kBAAuB;;;;;;;;EAoBzD,CAAA"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,MAAM,KAAK,GAAG;IAClB,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,8BAA8B,EAAE,OAAO,CAAA;IACvC,iBAAiB,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAA;IACpD,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,oBAAoB,EAAE,MAAM,IAAI,CAAA;IAChC,iCAAiC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;CAC7D,GAAG,cAAc,CAAA;AAElB,eAAO,MAAM,WAAW;;;;;;;;EAmBrB,CAAA"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("@zerodev/react-ui"),m=require("react"),v=require("zustand"),_=require("wagmi"),S=require("@zerodev/wallet-react"),$=require("zustand/middleware"),K=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/error.webp").href:new URL("error.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),Y=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/loading.webp").href:new URL("loading.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),J=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/send.webp").href:new URL("send.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),X=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/success.webp").href:new URL("success.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),Q={error:K,loading:Y,send:J,success:X};function C({imageName:t,title:r,children:a,className:n}){return e.jsxs("div",{className:o.cn("zd:flex zd:flex-col zd:gap-8 zd:items-center",n),children:[e.jsx("img",{src:Q[t],alt:t,className:"zd:w-[118px] zd:h-[118px] zd:bg-transparent"}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:items-center",children:[e.jsx(o.Text,{className:"zd:text-h2 zd:text-center zd:whitespace-pre-wrap",children:r}),e.jsx(o.Text,{className:"zd:text-center zd:whitespace-pre-wrap",children:a})]})]})}function H(){const r=_.useConfig().connectors.find(a=>a.id==="zerodev-wallet");if(!r||!("getKitStore"in r))throw new Error("useKitStore must be used with the zeroDevWallet connector");return r.getKitStore()}function k(){const t=H(),r=v.useStore(t,c=>c.auth.step),a=v.useStore(t,c=>c.auth.stepHistory),n=v.useStore(t,c=>c.auth.email),s=v.useStore(t,c=>c.auth.otpId),l=v.useStore(t,c=>c.auth.otpEncryptionTargetBundle),i=v.useStore(t,c=>c.auth.enabledMethods),u=v.useStore(t,c=>c.auth.config);return{step:r,email:n,otpId:s,otpEncryptionTargetBundle:l,enabledMethods:i,config:u,goToStep:t.getState().auth.goToStep,goBack:a.length>0?t.getState().auth.goBack:null,reset:t.getState().auth.reset,setEmail:t.getState().auth.setEmail,setOtpSession:t.getState().auth.setOtpSession,clearOtpSession:t.getState().auth.clearOtpSession}}function Z(){const{email:t,setOtpSession:r}=k(),{mutateAsync:a,isPending:n}=S.useSendMagicLink(),[s,l]=m.useState(60),i=s<=0&&!n;m.useEffect(()=>{if(s<=0)return;const c=setInterval(()=>{l(p=>Math.max(0,p-1))},1e3);return()=>{clearInterval(c)}},[s]);const u=async()=>{if(!(!t||!i))try{const{otpId:c,otpEncryptionTargetBundle:p}=await a({email:t});r({otpId:c,otpEncryptionTargetBundle:p}),l(60)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsxs(C,{imageName:"send",title:`Check your email!
2
- An Email is On Its Way`,children:["We've sent a magic link to"," ",e.jsx(o.Text,{as:"span",className:"zd:text-solarOrange",children:t}),`
3
- `,"Please open the email and click the link to log in."]}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(o.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!i,onClick:u,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:i?"Resend":`Resend in ${s} ${s===1?"second":"seconds"}`})]})})]}),e.jsx(o.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function ee(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).has("code")}function P(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.has("code")&&(t.searchParams.delete("code"),window.history.replaceState(null,"",t.toString()))}function te({title:t="Oops, something went wrong",message:r="We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request.",showRetry:a=!1,showChooseAnother:n=!0}){const{goToStep:s,goBack:l,reset:i}=k(),u=l??(()=>s("sign-up"));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[e.jsx(C,{imageName:"error",title:t,children:r}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-1",children:[a&&e.jsx(o.Button,{action:"primary",text:"Try again",onClick:u}),n&&e.jsx(o.Button,{action:a?"secondary":"primary",onClick:()=>{P(),s("sign-up")},text:"Choose another sign-in method"}),!a&&!n&&e.jsx(o.Button,{action:"primary",text:"Start over",onClick:i})]})]}),e.jsx(o.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const ne=4,se=8,re=6;function ie(t){return Math.max(ne,Math.min(se,t))}function ae({char:t,isFocused:r}){return e.jsx(o.Wrapper,{"data-testid":"code-input-box","data-active":r||void 0,className:o.cn("zd:h-16 zd:w-14 zd:rounded-lg zd:flex zd:items-center zd:justify-center",r&&"zd:border-[1.5px] zd:border-greyScale"),children:e.jsx(o.Text,{className:"zd:text-h2",children:t})})}function oe({onChange:t,onComplete:r,disabled:a=!1,error:n=!1,autoFocus:s=!1,length:l=re,"data-testid":i}){const u=ie(l),c=m.useMemo(()=>Array.from({length:u},(h,z)=>({id:`char-${z}`,index:z})),[u]),[p,y]=m.useState(""),[f,j]=m.useState(!1),T=m.useRef(null);m.useEffect(()=>{var h;s&&!a&&((h=T.current)==null||h.focus())},[s,a]),m.useEffect(()=>{y(h=>h.slice(0,u))},[u]);const N=h=>{const z=h.slice(0,u).toUpperCase();y(z),t==null||t(z),z.length===u&&setTimeout(()=>{var I;r==null||r(z),(I=T.current)==null||I.blur()},0)};return e.jsxs("button",{type:"button",className:"zd:flex zd:flex-row zd:items-center zd:justify-between zd:gap-2 zd:w-full zd:cursor-text",onClick:()=>{var h;return(h=T.current)==null?void 0:h.focus()},disabled:a,"data-testid":i,children:[e.jsx("input",{ref:T,value:p,onChange:h=>N(h.target.value),onFocus:()=>j(!0),onBlur:()=>j(!1),maxLength:u,disabled:a,className:"zd:absolute zd:opacity-0 zd:pointer-events-none",style:{position:"absolute",opacity:0},"aria-label":"Verification code"}),c.map(h=>e.jsx(ae,{char:p[h.index]??"",isFocused:!n&&f&&h.index===p.length},h.id))]})}function de(){const{email:t,otpId:r,otpEncryptionTargetBundle:a,setOtpSession:n,clearOtpSession:s,goToStep:l,config:i}=k(),{mutateAsync:u,isPending:c}=S.useSendOTP(),{mutateAsync:p,isPending:y}=S.useVerifyOTP(),[f,j]=m.useState(""),[T,N]=m.useState(!1),[h,z]=m.useState(60);m.useEffect(()=>{if(h<=0)return;const w=setInterval(()=>{z(E=>Math.max(0,E-1))},1e3);return()=>clearInterval(w)},[h]);const I=async()=>{var w,E;if(!(!f.trim()||!r||!a)){N(!1);try{await p({otpId:r,code:f.trim(),otpEncryptionTargetBundle:a}),s(),l("authenticated"),(w=i==null?void 0:i.onSuccess)==null||w.call(i)}catch(O){N(!0),(E=i==null?void 0:i.onError)==null||E.call(i,O)}}},g=w=>{j(w)},B=async()=>{if(!(!t||h>0||c))try{const{otpId:w,otpEncryptionTargetBundle:E}=await u({email:t});n({otpId:w,otpEncryptionTargetBundle:E}),z(60),N(!1)}catch{N(!0)}},L=h<=0&&!c;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center zd:items-center",children:[e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4",children:[e.jsx(o.Text,{className:"zd:text-h2 zd:text-center",children:"Enter verification code"}),e.jsxs(o.Text,{className:"zd:text-center",children:["Enter the code from the email we sent to"," ",e.jsx(o.Text,{className:"zd:text-solarOrange",children:t})]})]}),e.jsx(oe,{onComplete:g,onChange:()=>N(!1),disabled:y,error:T,autoFocus:!0}),e.jsx(o.Button,{text:"Confirm code",onClick:I,disabled:!f.trim()||y}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(o.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!L,onClick:B,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:L?"Resend":`Resend in ${h} ${h===1?"second":"seconds"}`})]})})]}),e.jsx(o.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function ce({termsAndConditionsUrl:t,privacyPolicyUrl:r,agreedToTerms:a,setAgreedToTerms:n,highlight:s=!1}){const l=!!(t||r);return e.jsxs("div",{className:"zd:flex zd:flex-col zd:items-center zd:gap-5",children:[l&&e.jsxs("div",{className:`zd:flex zd:flex-row zd:items-center zd:gap-2 zd:rounded-md zd:p-2 zd:transition-colors ${s?"zd:border zd:border-negative":"zd:border zd:border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:a,onChange:i=>n(i.target.checked),className:"zd:cursor-pointer zd:[color-scheme:light]"}),e.jsxs(o.Text,{className:"zd:flex-1",children:["I agree to the"," ",t&&e.jsx(o.Text,{as:"a",href:t,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Terms & Conditions"}),t&&r&&" and ",r&&e.jsx(o.Text,{as:"a",href:r,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Privacy Policy"})]})]}),e.jsx(o.PoweredBy,{})]})}const le=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function A(t){return le.test(t.trim())}const ue=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/blob.webm").href:new URL("blob.webm",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href);function pe({className:t}){return e.jsx("video",{className:t,style:{aspectRatio:"1 / 1"},src:ue,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,"aria-hidden":"true",tabIndex:-1})}function U(t){return t instanceof Error?t.name==="AbortError"||t.name==="NotAllowedError"?!0:t.message.toLowerCase().includes("oauth popup was closed"):!1}function he(){const{goToStep:t,setEmail:r,setOtpSession:a,config:n,enabledMethods:s}=k(),[l,i]=m.useState(!1),[u,c]=m.useState(!1),[p,y]=m.useState(""),f=(n==null?void 0:n.emailAuthMethod)==="otp",{mutateAsync:j,isPending:T}=S.useSendOTP(),{mutateAsync:N,isPending:h}=S.useSendMagicLink(),z=T||h,[I,g]=m.useState(null),{mutateAsync:B,isPending:L}=S.useAuthenticateOAuth({mutation:{onSuccess:async()=>{var d;t("authenticated"),(d=n==null?void 0:n.onSuccess)==null||d.call(n)},onError:d=>{var x;(x=n==null?void 0:n.onError)==null||x.call(n,d)}}}),{mutate:w,isPending:E}=S.useRegisterPasskey({mutation:{onSuccess:()=>{var d;t("authenticated"),(d=n==null?void 0:n.onSuccess)==null||d.call(n)},onError:d=>{var x;U(d)||g(d instanceof Error?d.message:String(d)),(x=n==null?void 0:n.onError)==null||x.call(n,d)}}}),{mutate:O,isPending:W}=S.useLoginPasskey({mutation:{onSuccess:()=>{var d;t("authenticated"),(d=n==null?void 0:n.onSuccess)==null||d.call(n)},onError:d=>{var x;U(d)||g(d instanceof Error?d.message:String(d)),(x=n==null?void 0:n.onError)==null||x.call(n,d)}}}),b=L||z||E||W,R=!!(n!=null&&n.termsAndConditionsUrl||n!=null&&n.privacyPolicyUrl)&&!l,V=()=>{if(!b){if(R){c(!0);return}g(null),w()}},G=()=>{if(!b){if(R){c(!0);return}g(null),O()}},D=async()=>{if(R){c(!0);return}g(null);try{await B({provider:"google"})}catch(d){const x=d instanceof Error?d.message:String(d);U(d)||g(x)}},F=f?async()=>{if(!(!p||b)&&A(p)){if(R){c(!0);return}g(null);try{const{otpId:d,otpEncryptionTargetBundle:x}=await j({email:p});r(p),a({otpId:d,otpEncryptionTargetBundle:x}),t("otp-input")}catch(d){g(d instanceof Error?d.message:"Failed to send verification code")}}}:async()=>{if(!(!p||b)&&A(p)){if(R){c(!0);return}g(null);try{const{otpId:d,otpEncryptionTargetBundle:x}=await N({email:p});r(p),a({otpId:d,otpEncryptionTargetBundle:x}),t("email-verification")}catch(d){g(d instanceof Error?d.message:"Failed to send verification code")}}};return I?e.jsx("div",{className:"zd:flex zd:items-center zd:justify-center zd:h-full",children:e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:max-w-md",children:[e.jsx(o.Text,{className:"zd:text-h2 zd:text-center",children:"Error occurred"}),e.jsx(o.Text,{className:"zd:text-center zd:text-red-500",children:I}),e.jsx(o.Button,{action:"primary",text:"Try again",onClick:()=>g(null)})]})}):e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-between zd:pb-4 zd:overflow-y-auto zd:overflow-x-hidden",children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-center",children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:items-center",children:[e.jsx("div",{className:"zd:w-full zd:px-16 zd:py-4",children:e.jsx(pe,{className:"zd:w-full zd:pointer-events-none zd:select-none"})}),e.jsx(o.Text,{className:"zd:text-h2 zd:text-center",children:"Continue to your wallet"}),e.jsx(o.Text,{className:"zd:mt-2 zd:text-center zd:text-greyScale/50",children:"Choose a sign-in method to proceed"})]}),e.jsxs("div",{className:"zd:mt-6 zd:flex zd:flex-col zd:gap-4 zd:mb-4",children:[s.includes("passkey")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[e.jsx(o.Button,{action:"secondary",text:"Create a passkey",iconName:"key",trailIcon:!0,disabled:b,onClick:V}),e.jsx(o.Button,{action:"secondary",text:"Log in with passkey",iconName:"key",trailIcon:!0,disabled:b,onClick:G})]}),e.jsxs("div",{className:"zd:flex zd:items-center zd:gap-3",children:[e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"}),e.jsx(o.Text,{className:"zd:text-body3",children:"or"}),e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"})]})]}),e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[s.includes("google")&&e.jsx(o.ListItem,{icon:e.jsx(o.ListItemIcon,{name:"google"}),title:"Google",trailing:e.jsx(o.ListItemChevron,{}),className:"zd:rounded-3xl",disabled:b,onClick:D}),s.includes("email")&&e.jsx(o.Input,{iconName:"email",placeholder:"Enter your email",value:p,onChange:d=>y(d.target.value),type:"email",autoCapitalize:"none",autoComplete:"email",disabled:b,variant:"listItemStyle",containerClassName:"zd:rounded-3xl",onKeyDown:d=>{d.key==="Enter"&&p&&!b&&F()},children:z?e.jsx("div",{className:"zd:w-13 zd:h-13 zd:flex zd:items-center zd:justify-center",children:e.jsx("div",{className:"zd:w-5 zd:h-5 zd:border-2 zd:border-solarOrange zd:border-t-transparent zd:rounded-full zd:animate-spin"})}):e.jsx("button",{type:"button",disabled:!A(p)||R,className:`zd:w-13 zd:h-13 zd:rounded-2xl zd:flex zd:items-center zd:justify-center zd:transition-colors ${A(p)&&!R?"zd:cursor-pointer":"zd:cursor-not-allowed zd:opacity-50"}`,onClick:()=>F(),children:e.jsx(o.Icon,{name:"chevronRight",className:"zd:text-greyScale"})})})]})]})]}),e.jsx("div",{className:"zd:px-4",children:e.jsx(ce,{termsAndConditionsUrl:n==null?void 0:n.termsAndConditionsUrl,privacyPolicyUrl:n==null?void 0:n.privacyPolicyUrl,agreedToTerms:l,setAgreedToTerms:d=>{i(d),d&&c(!1)},highlight:u})})]})}function me(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("code")}function xe(){const{otpId:t,otpEncryptionTargetBundle:r,goToStep:a,clearOtpSession:n,config:s}=k(),[l]=m.useState(me),[i,u]=m.useState(null),c=m.useRef(!1),{mutate:p,isPending:y}=S.useVerifyMagicLink({mutation:{onSuccess:async()=>{var f;n(),a("authenticated"),(f=s==null?void 0:s.onSuccess)==null||f.call(s)},onError:f=>{var j;u(f),(j=s==null?void 0:s.onError)==null||j.call(s,f)}}});return m.useEffect(()=>{if(!(c.current||!l)){if(c.current=!0,!t||!r){P(),a(null);return}p({otpId:t,code:l,otpEncryptionTargetBundle:r})}},[t,r,l,p,a]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[!i&&y&&e.jsx(C,{imageName:"loading",title:"Verifying Your Email",children:"Please wait while we securely connect your wallet."}),!i&&!l&&!y&&e.jsxs(e.Fragment,{children:[e.jsxs(C,{imageName:"error",title:"Invalid Link",children:["This verification link is invalid or incomplete.",e.jsx("br",{}),"Please check your email and try again with the correct link."]}),e.jsx(o.Button,{action:"primary",onClick:()=>{P(),a("sign-up")},text:"Choose another sign-in method"})]}),i!=null&&e.jsxs(e.Fragment,{children:[e.jsx(C,{imageName:"error",title:"Oops, something went wrong",children:"We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request."}),e.jsx(o.Button,{action:"primary",onClick:()=>{P(),a("sign-up")},text:"Choose another sign-in method"})]})]}),e.jsx(o.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function fe(){const{goToStep:t}=k(),{connect:r,connectors:a,isPending:n}=_.useConnect(),s=a.filter(i=>i.id!=="zerodev-wallet"),l=i=>{r({connector:i},{onSuccess:()=>{t(null)}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsx(o.Text,{className:"zd:text-h2 zd:text-center",children:"Select your wallet"}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-2",children:s.length===0?e.jsx(o.Text,{className:"zd:text-center",children:"No wallets detected. Install a browser wallet extension to continue."}):s.map(i=>e.jsx(o.ListItem,{title:i.name,icon:i.icon?e.jsx("img",{src:i.icon,alt:"",className:"zd:w-6 zd:h-6"}):e.jsx(o.ListItemIcon,{name:"walletOutline"}),disabled:n,onClick:()=>l(i),className:"zd:rounded-3xl"},i.uid))})]}),e.jsx(o.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const ze={"wallet-selection":"Choose your wallet"};function ge(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(C,{imageName:"loading",title:"Authenticating...",children:"Please wait while we complete the OAuth authentication."})})}function ye(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(C,{imageName:"loading",title:"Passkey authentication",children:"Please authenticate with your passkey."})})}function Se(t){switch(t){case"sign-up":return e.jsx(he,{});case"email-verification":return e.jsx(Z,{});case"otp-input":return e.jsx(de,{});case"verifying-otp":return e.jsx(xe,{});case"oauth-in-progress":return e.jsx(ge,{});case"passkey-prompt":return e.jsx(ye,{});case"wallet-selection":return e.jsx(fe,{});case"error":return e.jsx(te,{});default:return null}}function we({onClose:t,size:r}={}){const{step:a,goToStep:n,goBack:s,reset:l}=k(),i=v.useStore(H(),y=>y.logo);m.useEffect(()=>{a===null&&ee()&&n("verifying-otp")},[a,n]);const u=Se(a);if(!u)return null;const c=()=>{P(),l(),t==null||t()},p=a?ze[a]:void 0;return e.jsx(o.Screen,{...r&&{size:r},contentClassName:a==="sign-up"?"zd:px-0":void 0,topNav:e.jsx(o.TopNav,{...s!==null&&{onLeftButtonClick:s},onRightButtonClick:c,...p&&{title:p},...a==="sign-up"&&{...i&&{logo:i},className:"zd:px-4"}}),children:u})}const M="zerodev:auth:otpSession";function je(){if(typeof window>"u")return null;try{const t=window.localStorage.getItem(M);if(!t)return null;const r=JSON.parse(t);return!(r!=null&&r.otpId)||!(r!=null&&r.otpEncryptionTargetBundle)?null:r}catch{return null}}function Ne(t){if(!(typeof window>"u"))try{window.localStorage.setItem(M,JSON.stringify(t))}catch{}}function q(){if(!(typeof window>"u"))try{window.localStorage.removeItem(M)}catch{}}const be=(t,r,a)=>({auth:{step:null,stepHistory:[],enabledMethods:[],email:null,otpId:null,otpEncryptionTargetBundle:null,config:null,initialize:n=>{const s=je();t(l=>({auth:{...l.auth,config:n,enabledMethods:n.enabledMethods,...s&&{otpId:s.otpId,otpEncryptionTargetBundle:s.otpEncryptionTargetBundle}}}))},goToStep:n=>{t(s=>({auth:{...s.auth,step:n,stepHistory:s.auth.step===null?s.auth.stepHistory:[...s.auth.stepHistory,s.auth.step]}}))},goBack:()=>{const{auth:n}=r();if(n.stepHistory.length===0)return;const s=[...n.stepHistory],l=s.pop();t(i=>({auth:{...i.auth,step:l,stepHistory:s}}))},reset:()=>{q(),t(n=>({auth:{...n.auth,step:null,stepHistory:[],email:null,otpId:null,otpEncryptionTargetBundle:null}}))},setEmail:n=>{t(s=>({auth:{...s.auth,email:n}}))},setOtpSession:({otpId:n,otpEncryptionTargetBundle:s})=>{Ne({otpId:n,otpEncryptionTargetBundle:s}),t(l=>({auth:{...l.auth,otpId:n,otpEncryptionTargetBundle:s}}))},clearOtpSession:()=>{q(),t(n=>({auth:{...n.auth,otpId:null,otpEncryptionTargetBundle:null}}))}}}),ve=(t={})=>v.create()($.subscribeWithSelector((r,a,n)=>({pendingRequests:[],userConfirmationListenerActive:!1,logo:t.logo??null,addPendingRequest:s=>r(l=>({pendingRequests:[...l.pendingRequests,s]})),removePendingRequest:s=>r(l=>({pendingRequests:l.pendingRequests.filter(i=>i.id!==s)})),clearPendingRequests:()=>r({pendingRequests:[]}),setUserConfirmationListenerActive:s=>r({userConfirmationListenerActive:s}),...be(r,a)})));function Te(t){return new Promise((r,a)=>{const n=t.subscribe(s=>s.auth.step,s=>{s==="authenticated"?(n(),r()):s===null&&(n(),a(new Error("Auth flow dismissed")))})})}function Ee(t){var n,s;const r=S.zeroDevWallet(t),a=ve({logo:(n=t.config)==null?void 0:n.logo});return(s=t.config)!=null&&s.auth&&a.getState().auth.initialize(t.config.auth),l=>{const i=r(l);return{...i,async connect(u){var c;try{return await i.connect(u)}catch(p){if(u!=null&&u.isReconnecting||!((c=t.config)!=null&&c.auth)||!(p instanceof S.NotAuthenticatedError))throw p;if(a.getState().auth.step!==null)throw new Error("Auth flow already in progress");return a.getState().auth.goToStep("sign-up"),await Te(a),i.connect(u)}},async disconnect(){var u,c;await((u=i.disconnect)==null?void 0:u.call(i)),(c=t.config)!=null&&c.auth&&a.getState().auth.reset()},async setup(){var u;await((u=i.setup)==null?void 0:u.call(i)),typeof window>"u"},getKitStore(){return a}}}}exports.AuthFlow=we;exports.useAuth=k;exports.zeroDevWallet=Ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("@zerodev/react-ui"),p=require("react"),b=require("zustand"),B=require("wagmi"),y=require("@zerodev/wallet-react"),D=require("zustand/middleware"),V=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/error.webp").href:new URL("error.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),G=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/loading.webp").href:new URL("loading.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),$=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/send.webp").href:new URL("send.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),K=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/success.webp").href:new URL("success.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),Y={error:V,loading:G,send:$,success:K};function N({imageName:t,title:s,children:i,className:r}){return e.jsxs("div",{className:c.cn("zd:flex zd:flex-col zd:gap-8 zd:items-center",r),children:[e.jsx("img",{src:Y[t],alt:t,className:"zd:w-[118px] zd:h-[118px] zd:bg-transparent"}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:items-center",children:[e.jsx(c.Text,{className:"zd:text-h2 zd:text-center zd:whitespace-pre-wrap",children:s}),e.jsx(c.Text,{className:"zd:text-center zd:whitespace-pre-wrap",children:i})]})]})}function J(){const s=B.useConfig().connectors.find(i=>i.id==="zerodev-wallet");if(!s||!("getKitStore"in s))throw new Error("useKitStore must be used with the zeroDevWallet connector");return s.getKitStore()}function S(){const t=J(),s=b.useStore(t,o=>o.auth.step),i=b.useStore(t,o=>o.auth.stepHistory),r=b.useStore(t,o=>o.auth.email),n=b.useStore(t,o=>o.auth.otpId),a=b.useStore(t,o=>o.auth.otpEncryptionTargetBundle);return{step:s,email:r,otpId:n,otpEncryptionTargetBundle:a,goToStep:t.getState().auth.goToStep,goBack:i.length>0?t.getState().auth.goBack:null,reset:t.getState().auth.reset,setEmail:t.getState().auth.setEmail,setOtpSession:t.getState().auth.setOtpSession,clearOtpSession:t.getState().auth.clearOtpSession}}function X(){const{email:t,setOtpSession:s}=S(),{mutateAsync:i,isPending:r}=y.useSendMagicLink(),[n,a]=p.useState(60),o=n<=0&&!r;p.useEffect(()=>{if(n<=0)return;const l=setInterval(()=>{a(m=>Math.max(0,m-1))},1e3);return()=>{clearInterval(l)}},[n]);const d=async()=>{if(!(!t||!o))try{const{otpId:l,otpEncryptionTargetBundle:m}=await i({email:t});s({otpId:l,otpEncryptionTargetBundle:m}),a(60)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsxs(N,{imageName:"send",title:`Check your email!
2
+ An Email is On Its Way`,children:["We've sent a magic link to"," ",e.jsx(c.Text,{as:"span",className:"zd:text-solarOrange",children:t}),`
3
+ `,"Please open the email and click the link to log in."]}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(c.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!o,onClick:d,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:o?"Resend":`Resend in ${n} ${n===1?"second":"seconds"}`})]})})]}),e.jsx(c.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function Q(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).has("code")}function T(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.has("code")&&(t.searchParams.delete("code"),window.history.replaceState(null,"",t.toString()))}function Z({title:t="Oops, something went wrong",message:s="We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request.",showRetry:i=!1,showChooseAnother:r=!0}){const{goToStep:n,goBack:a,reset:o}=S(),d=a??(()=>n("sign-up"));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[e.jsx(N,{imageName:"error",title:t,children:s}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-1",children:[i&&e.jsx(c.Button,{action:"primary",text:"Try again",onClick:d}),r&&e.jsx(c.Button,{action:i?"secondary":"primary",onClick:()=>{T(),n("sign-up")},text:"Choose another sign-in method"}),!i&&!r&&e.jsx(c.Button,{action:"primary",text:"Start over",onClick:o})]})]}),e.jsx(c.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const ee=4,te=8,ne=6;function se(t){return Math.max(ee,Math.min(te,t))}function re({char:t,isFocused:s}){return e.jsx(c.Wrapper,{"data-testid":"code-input-box","data-active":s||void 0,className:c.cn("zd:h-16 zd:w-14 zd:rounded-lg zd:flex zd:items-center zd:justify-center",s&&"zd:border-[1.5px] zd:border-greyScale"),children:e.jsx(c.Text,{className:"zd:text-h2",children:t})})}function ie({onChange:t,onComplete:s,disabled:i=!1,error:r=!1,autoFocus:n=!1,length:a=ne,"data-testid":o}){const d=se(a),l=p.useMemo(()=>Array.from({length:d},(u,z)=>({id:`char-${z}`,index:z})),[d]),[m,f]=p.useState(""),[w,j]=p.useState(!1),h=p.useRef(null);p.useEffect(()=>{var u;n&&!i&&((u=h.current)==null||u.focus())},[n,i]),p.useEffect(()=>{f(u=>u.slice(0,d))},[d]);const x=u=>{const z=u.slice(0,d).toUpperCase();f(z),t==null||t(z),z.length===d&&setTimeout(()=>{var g;s==null||s(z),(g=h.current)==null||g.blur()},0)};return e.jsxs("button",{type:"button",className:"zd:flex zd:flex-row zd:items-center zd:justify-between zd:gap-2 zd:w-full zd:cursor-text",onClick:()=>{var u;return(u=h.current)==null?void 0:u.focus()},disabled:i,"data-testid":o,children:[e.jsx("input",{ref:h,value:m,onChange:u=>x(u.target.value),onFocus:()=>j(!0),onBlur:()=>j(!1),maxLength:d,disabled:i,className:"zd:absolute zd:opacity-0 zd:pointer-events-none",style:{position:"absolute",opacity:0},"aria-label":"Verification code"}),l.map(u=>e.jsx(re,{char:m[u.index]??"",isFocused:!r&&w&&u.index===m.length},u.id))]})}function oe(){const{email:t,otpId:s,otpEncryptionTargetBundle:i,setOtpSession:r,clearOtpSession:n,goToStep:a}=S(),{mutateAsync:o,isPending:d}=y.useSendOTP(),{mutateAsync:l,isPending:m}=y.useVerifyOTP(),[f,w]=p.useState(""),[j,h]=p.useState(!1),[x,u]=p.useState(60);p.useEffect(()=>{if(x<=0)return;const v=setInterval(()=>{u(R=>Math.max(0,R-1))},1e3);return()=>clearInterval(v)},[x]);const z=async()=>{if(!(!f.trim()||!s||!i)){h(!1);try{await l({otpId:s,code:f.trim(),otpEncryptionTargetBundle:i}),n(),a("authenticated")}catch{h(!0)}}},g=v=>{w(v)},I=async()=>{if(!(!t||x>0||d))try{const{otpId:v,otpEncryptionTargetBundle:R}=await o({email:t});r({otpId:v,otpEncryptionTargetBundle:R}),u(60),h(!1)}catch{h(!0)}},E=x<=0&&!d;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center zd:items-center",children:[e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4",children:[e.jsx(c.Text,{className:"zd:text-h2 zd:text-center",children:"Enter verification code"}),e.jsxs(c.Text,{className:"zd:text-center",children:["Enter the code from the email we sent to"," ",e.jsx(c.Text,{className:"zd:text-solarOrange",children:t})]})]}),e.jsx(ie,{onComplete:g,onChange:()=>h(!1),disabled:m,error:j,autoFocus:!0}),e.jsx(c.Button,{text:"Confirm code",onClick:z,disabled:!f.trim()||m}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(c.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!E,onClick:I,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:E?"Resend":`Resend in ${x} ${x===1?"second":"seconds"}`})]})})]}),e.jsx(c.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function ae({termsAndConditionsUrl:t,privacyPolicyUrl:s,agreedToTerms:i,setAgreedToTerms:r,highlight:n=!1}){const a=!!(t||s);return e.jsxs("div",{className:"zd:flex zd:flex-col zd:items-center zd:gap-5",children:[a&&e.jsxs("div",{className:`zd:flex zd:flex-row zd:items-center zd:gap-2 zd:rounded-md zd:p-2 zd:transition-colors ${n?"zd:border zd:border-negative":"zd:border zd:border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:i,onChange:o=>r(o.target.checked),className:"zd:cursor-pointer zd:[color-scheme:light]"}),e.jsxs(c.Text,{className:"zd:flex-1",children:["I agree to the"," ",t&&e.jsx(c.Text,{as:"a",href:t,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Terms & Conditions"}),t&&s&&" and ",s&&e.jsx(c.Text,{as:"a",href:s,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Privacy Policy"})]})]}),e.jsx(c.PoweredBy,{})]})}const ce=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/blob.webm").href:new URL("blob.webm",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href);function de({className:t}){return e.jsx("video",{className:t,style:{aspectRatio:"1 / 1"},src:ce,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,"aria-hidden":"true",tabIndex:-1})}const O=p.createContext(null);function k(){const t=p.useContext(O);if(!t)throw new Error("SignUp.* components must be rendered inside <SignUp>");return t}function P(t){const{setAuthPending:s}=k();p.useEffect(()=>(s(t),()=>s(!1)),[t,s])}const le=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function C(t){return le.test(t.trim())}function U(){const{goToStep:t,setEmail:s,setOtpSession:i}=S(),{authPending:r,emailAuthMethod:n,needsAgreement:a,guardAgreement:o,setError:d}=k(),[l,m]=p.useState(""),f=n==="otp",{mutateAsync:w,isPending:j}=y.useSendOTP(),{mutateAsync:h,isPending:x}=y.useSendMagicLink(),u=j||x;P(u);const z=async()=>{if(!(!l||r)&&C(l)&&o()){d(null);try{const g=f?w:h,{otpId:I,otpEncryptionTargetBundle:E}=await g({email:l});s(l),i({otpId:I,otpEncryptionTargetBundle:E}),t(f?"otp-input":"email-verification")}catch(g){d(g instanceof Error?g.message:"Failed to send verification code")}}};return e.jsx(c.Input,{iconName:"email",placeholder:"Enter your email",value:l,onChange:g=>m(g.target.value),type:"email",autoCapitalize:"none",autoComplete:"email",disabled:r,variant:"listItemStyle",onKeyDown:g=>{g.key==="Enter"&&l&&!r&&z()},children:u?e.jsx("div",{className:"zd:w-13 zd:h-13 zd:flex zd:items-center zd:justify-center",children:e.jsx("div",{className:"zd:w-5 zd:h-5 zd:border-2 zd:border-solarOrange zd:border-t-transparent zd:rounded-full zd:animate-spin"})}):e.jsx("button",{type:"button",disabled:!C(l)||a,className:`zd:w-13 zd:h-13 zd:rounded-2xl zd:flex zd:items-center zd:justify-center zd:transition-colors ${C(l)&&!a?"zd:cursor-pointer":"zd:cursor-not-allowed zd:opacity-50"}`,onClick:()=>z(),children:e.jsx(c.Icon,{name:"chevronRight",className:"zd:text-greyScale"})})})}function q(t){return t instanceof Error?t.name==="AbortError"||t.name==="NotAllowedError"?!0:t.message.toLowerCase().includes("oauth popup was closed"):!1}function F(){const{goToStep:t}=S(),{authPending:s,guardAgreement:i,setError:r}=k(),{mutateAsync:n,isPending:a}=y.useAuthenticateOAuth({mutation:{onSuccess:()=>{t("authenticated")}}});P(a);const o=async()=>{if(!s&&i()){r(null);try{await n({provider:"google"})}catch(d){q(d)||r(d instanceof Error?d.message:String(d))}}};return e.jsx(c.ListItem,{icon:e.jsx(c.ListItemIcon,{name:"google"}),title:"Google",trailing:e.jsx(c.ListItemChevron,{}),disabled:s,onClick:o})}function _(){const{goToStep:t}=S(),{authPending:s,guardAgreement:i,setError:r}=k(),n={onSuccess:()=>{t("authenticated")},onError:f=>{q(f)||r(f instanceof Error?f.message:String(f))}},{mutate:a,isPending:o}=y.useRegisterPasskey({mutation:n}),{mutate:d,isPending:l}=y.useLoginPasskey({mutation:n});P(o||l);const m=f=>()=>{s||i()&&(r(null),f())};return e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{action:"secondary",text:"Create a passkey",iconName:"key",trailIcon:!0,disabled:s,onClick:m(()=>a())}),e.jsx(c.Button,{action:"secondary",text:"Log in with passkey",iconName:"key",trailIcon:!0,disabled:s,onClick:m(()=>d())})]})}function M({children:t,termsAndConditionsUrl:s,privacyPolicyUrl:i,emailAuthMethod:r="magicLink"}){const[n,a]=p.useState(!1),[o,d]=p.useState(!1),[l,m]=p.useState(null),[f,w]=p.useState(!1),h=!!(s||i)&&!n,x=()=>h?(d(!0),!1):!0;return e.jsxs(O.Provider,{value:{authPending:f,emailAuthMethod:r,setAuthPending:w,needsAgreement:h,guardAgreement:x,setError:m},children:[l!==null&&e.jsx("div",{className:"zd:flex zd:items-center zd:justify-center zd:h-full",children:e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:max-w-md",children:[e.jsx(c.Text,{className:"zd:text-h2 zd:text-center",children:"Error occurred"}),e.jsx(c.Text,{className:"zd:text-center zd:text-red-500",children:l}),e.jsx(c.Button,{action:"primary",text:"Try again",onClick:()=>m(null)})]})}),e.jsxs("div",{className:`zd:flex-1 zd:flex zd:flex-col zd:justify-between zd:pb-4 zd:overflow-y-auto zd:overflow-x-hidden${l!==null?" zd:hidden":""}`,children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-center",children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:items-center",children:[e.jsx("div",{className:"zd:w-full zd:px-16 zd:py-4",children:e.jsx(de,{className:"zd:w-full zd:pointer-events-none zd:select-none"})}),e.jsx(c.Text,{className:"zd:text-h2 zd:text-center",children:"Continue to your wallet"}),e.jsx(c.Text,{className:"zd:mt-2 zd:text-center zd:text-greyScale/50",children:"Choose a sign-in method to proceed"})]}),e.jsx("div",{className:"zd:mt-6 zd:mb-4 zd:px-4 zd:flex zd:flex-col zd:gap-2",children:t})]}),e.jsx("div",{className:"zd:px-4",children:e.jsx(ae,{termsAndConditionsUrl:s,privacyPolicyUrl:i,agreedToTerms:n,setAgreedToTerms:u=>{a(u),u&&d(!1)},highlight:o})})]})]})}function H({label:t="or"}){return e.jsxs("div",{className:"zd:-mx-4 zd:my-2 zd:flex zd:items-center zd:gap-3",children:[e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"}),e.jsx(c.Text,{className:"zd:text-body3",children:t}),e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"})]})}function ue(t){return e.jsxs(M,{...t,children:[e.jsx(_,{}),e.jsx(H,{}),e.jsx(F,{}),e.jsx(U,{})]})}const W=Object.assign(M,{Default:ue,Passkey:_,Google:F,Email:U,Divider:H});function pe(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("code")}function me(){const{otpId:t,otpEncryptionTargetBundle:s,goToStep:i,clearOtpSession:r}=S(),[n]=p.useState(pe),[a,o]=p.useState(null),d=p.useRef(!1),{mutate:l,isPending:m}=y.useVerifyMagicLink({mutation:{onSuccess:()=>{r(),i("authenticated")},onError:f=>{o(f)}}});return p.useEffect(()=>{if(!(d.current||!n)){if(d.current=!0,!t||!s){T(),i(null);return}l({otpId:t,code:n,otpEncryptionTargetBundle:s})}},[t,s,n,l,i]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[!a&&m&&e.jsx(N,{imageName:"loading",title:"Verifying Your Email",children:"Please wait while we securely connect your wallet."}),!a&&!n&&!m&&e.jsxs(e.Fragment,{children:[e.jsxs(N,{imageName:"error",title:"Invalid Link",children:["This verification link is invalid or incomplete.",e.jsx("br",{}),"Please check your email and try again with the correct link."]}),e.jsx(c.Button,{action:"primary",onClick:()=>{T(),i("sign-up")},text:"Choose another sign-in method"})]}),a!=null&&e.jsxs(e.Fragment,{children:[e.jsx(N,{imageName:"error",title:"Oops, something went wrong",children:"We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request."}),e.jsx(c.Button,{action:"primary",onClick:()=>{T(),i("sign-up")},text:"Choose another sign-in method"})]})]}),e.jsx(c.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function fe(){const{goToStep:t}=S(),{connect:s,connectors:i,isPending:r}=B.useConnect(),n=i.filter(o=>o.id!=="zerodev-wallet"),a=o=>{s({connector:o},{onSuccess:()=>{t(null)}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsx(c.Text,{className:"zd:text-h2 zd:text-center",children:"Select your wallet"}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-2",children:n.length===0?e.jsx(c.Text,{className:"zd:text-center",children:"No wallets detected. Install a browser wallet extension to continue."}):n.map(o=>e.jsx(c.ListItem,{title:o.name,icon:o.icon?e.jsx("img",{src:o.icon,alt:"",className:"zd:w-6 zd:h-6"}):e.jsx(c.ListItemIcon,{name:"walletOutline"}),disabled:r,onClick:()=>a(o),className:"zd:rounded-3xl"},o.uid))})]}),e.jsx(c.PoweredBy,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const he={"wallet-selection":"Choose your wallet"};function ge(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(N,{imageName:"loading",title:"Authenticating...",children:"Please wait while we complete the OAuth authentication."})})}function xe(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(N,{imageName:"loading",title:"Passkey authentication",children:"Please authenticate with your passkey."})})}function ze(t,s){switch(t){case"sign-up":return s?s():e.jsx(W.Default,{});case"email-verification":return e.jsx(X,{});case"otp-input":return e.jsx(oe,{});case"verifying-otp":return e.jsx(me,{});case"oauth-in-progress":return e.jsx(ge,{});case"passkey-prompt":return e.jsx(xe,{});case"wallet-selection":return e.jsx(fe,{});case"error":return e.jsx(Z,{});default:return null}}function ye({onClose:t,size:s,renderSignUp:i,logo:r}={}){const{step:n,goToStep:a,goBack:o,reset:d}=S();p.useEffect(()=>{n===null&&Q()&&a("verifying-otp")},[n,a]);const l=ze(n,i);if(!l)return null;const m=()=>{T(),d(),t==null||t()},f=n?he[n]:void 0;return e.jsx(c.Screen,{...s&&{size:s},className:n==="sign-up"?"zd:h-auto zd:max-h-202.5":void 0,contentClassName:n==="sign-up"?"zd:px-0":void 0,topNav:e.jsx(c.TopNav,{...o!==null&&{onLeftButtonClick:o},onRightButtonClick:m,...f&&{title:f},...n==="sign-up"&&{...r&&{logo:r},className:"zd:px-4"}}),children:l})}const L="zerodev:auth:otpSession";function Se(){if(typeof window>"u")return null;try{const t=window.localStorage.getItem(L);if(!t)return null;const s=JSON.parse(t);return!(s!=null&&s.otpId)||!(s!=null&&s.otpEncryptionTargetBundle)?null:s}catch{return null}}function we(t){if(!(typeof window>"u"))try{window.localStorage.setItem(L,JSON.stringify(t))}catch{}}function A(){if(!(typeof window>"u"))try{window.localStorage.removeItem(L)}catch{}}const je=(t,s,i)=>({auth:{step:null,stepHistory:[],email:null,otpId:null,otpEncryptionTargetBundle:null,initialize:()=>{const r=Se();r&&t(n=>({auth:{...n.auth,otpId:r.otpId,otpEncryptionTargetBundle:r.otpEncryptionTargetBundle}}))},goToStep:r=>{t(n=>({auth:{...n.auth,step:r,stepHistory:n.auth.step===null?n.auth.stepHistory:[...n.auth.stepHistory,n.auth.step]}}))},goBack:()=>{const{auth:r}=s();if(r.stepHistory.length===0)return;const n=[...r.stepHistory],a=n.pop();t(o=>({auth:{...o.auth,step:a,stepHistory:n}}))},reset:()=>{A(),t(r=>({auth:{...r.auth,step:null,stepHistory:[],email:null,otpId:null,otpEncryptionTargetBundle:null}}))},setEmail:r=>{t(n=>({auth:{...n.auth,email:r}}))},setOtpSession:({otpId:r,otpEncryptionTargetBundle:n})=>{we({otpId:r,otpEncryptionTargetBundle:n}),t(a=>({auth:{...a.auth,otpId:r,otpEncryptionTargetBundle:n}}))},clearOtpSession:()=>{A(),t(r=>({auth:{...r.auth,otpId:null,otpEncryptionTargetBundle:null}}))}}}),Ne=()=>b.create()(D.subscribeWithSelector((t,s,i)=>({pendingRequests:[],userConfirmationListenerActive:!1,addPendingRequest:r=>t(n=>({pendingRequests:[...n.pendingRequests,r]})),removePendingRequest:r=>t(n=>({pendingRequests:n.pendingRequests.filter(a=>a.id!==r)})),clearPendingRequests:()=>t({pendingRequests:[]}),setUserConfirmationListenerActive:r=>t({userConfirmationListenerActive:r}),...je(t,s)})));function be(t){return new Promise((s,i)=>{const r=t.subscribe(n=>n.auth.step,n=>{n==="authenticated"?(r(),s()):n===null&&(r(),i(new Error("Auth flow dismissed")))})})}function ve(t){const s=y.zeroDevWallet(t),i=Ne();return r=>{const n=s(r);return{...n,async connect(a){try{return await n.connect(a)}catch(o){if(a!=null&&a.isReconnecting||!(o instanceof y.NotAuthenticatedError))throw o;if(i.getState().auth.step!==null)throw new Error("Auth flow already in progress");return i.getState().auth.goToStep("sign-up"),await be(i),n.connect(a)}},async disconnect(){var a;await((a=n.disconnect)==null?void 0:a.call(n)),i.getState().auth.reset()},async setup(){var a;await((a=n.setup)==null?void 0:a.call(n)),!(typeof window>"u")&&i.getState().auth.initialize()},getKitStore(){return i}}}}exports.ConnectWallet=ye;exports.SignUp=W;exports.useAuth=S;exports.zeroDevWallet=ve;
4
4
  //# sourceMappingURL=index.cjs.map