@misofm/privy-auth 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +349 -2
- package/dist/account.d.ts +22 -0
- package/dist/account.js +27 -0
- package/dist/address.d.ts +6 -0
- package/dist/address.js +9 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +18 -0
- package/dist/failure.d.ts +92 -0
- package/dist/failure.js +98 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/oauth.d.ts +15 -0
- package/dist/oauth.js +22 -0
- package/dist/privy-actions.d.ts +58 -0
- package/dist/privy-actions.js +54 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.js +9 -0
- package/dist/server.d.ts +94 -0
- package/dist/server.js +196 -0
- package/dist/sign-in-flow.d.ts +77 -0
- package/dist/sign-in-flow.js +96 -0
- package/dist/sign-in.d.ts +66 -0
- package/dist/sign-in.js +91 -0
- package/dist/signer.d.ts +69 -0
- package/dist/signer.js +105 -0
- package/dist/token.d.ts +13 -0
- package/dist/token.js +29 -0
- package/dist/ui/class-name.d.ts +4 -0
- package/dist/ui/class-name.js +2 -0
- package/dist/ui/code-field.d.ts +31 -0
- package/dist/ui/code-field.js +17 -0
- package/dist/ui/consent-line.d.ts +24 -0
- package/dist/ui/consent-line.js +15 -0
- package/dist/ui/email-field.d.ts +39 -0
- package/dist/ui/email-field.js +18 -0
- package/dist/ui/marks.d.ts +5 -0
- package/dist/ui/marks.js +9 -0
- package/dist/ui/oauth-button.d.ts +28 -0
- package/dist/ui/oauth-button.js +17 -0
- package/dist/ui/or-separator.d.ts +12 -0
- package/dist/ui/or-separator.js +10 -0
- package/dist/ui.d.ts +12 -0
- package/dist/ui.js +12 -0
- package/package.json +85 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Effect, Option } from 'effect';
|
|
2
|
+
import type { OAuthProvider } from './oauth.js';
|
|
3
|
+
/** How many digits Privy's emailed sign-in code has. */
|
|
4
|
+
export declare const CODE_LENGTH = 6;
|
|
5
|
+
/** How long after each code sent before another can be asked for, in seconds. */
|
|
6
|
+
export declare const RESEND_SECONDS = 30;
|
|
7
|
+
/** Why an email was refused before anything was sent: none typed, or not an address. */
|
|
8
|
+
export type EmailProblem = 'Missing' | 'Malformed';
|
|
9
|
+
/** The sign-in screen's step: the email (and Google, Apple), or the code sent to it. */
|
|
10
|
+
export type SignInStep = 'email' | 'code';
|
|
11
|
+
/** What the flow is doing: sending a code, checking one, or leaving for a provider. */
|
|
12
|
+
export type SignInRunning = 'send' | 'code' | OAuthProvider;
|
|
13
|
+
/** Any tagged failure (`_tag`): the package's `PrivyFailure`s, or an app's own errors. */
|
|
14
|
+
export type TaggedFailure = {
|
|
15
|
+
readonly _tag: string;
|
|
16
|
+
};
|
|
17
|
+
/** A failure the code field shows itself: Privy refused the code (the package's `WrongCode`, or an app error of that tag). */
|
|
18
|
+
export type WrongCodeOf<E> = Extract<E, {
|
|
19
|
+
readonly _tag: 'WrongCode';
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* The app's own sign-in operations, as Effects: each app routes them its own way (the fan app
|
|
23
|
+
* through its `Session` service, Studio through its account context). Their failures are what the
|
|
24
|
+
* screen shows: a `WrongCode` on the code field, any other in the alert line.
|
|
25
|
+
*/
|
|
26
|
+
export interface SignInActions<E, R = never> {
|
|
27
|
+
/** Emails a sign-in code to `email` (already trimmed and checked). */
|
|
28
|
+
readonly sendCode: (email: string) => Effect.Effect<void, E, R>;
|
|
29
|
+
/** Signs in with the code last emailed. */
|
|
30
|
+
readonly signInWithCode: (code: string) => Effect.Effect<void, E, R>;
|
|
31
|
+
/** Leaves for Google's or Apple's sign-in: succeeds as the page goes (it stays busy until then). */
|
|
32
|
+
readonly signInWith: (provider: OAuthProvider) => Effect.Effect<void, E, R>;
|
|
33
|
+
}
|
|
34
|
+
/** The flow's state. */
|
|
35
|
+
export interface SignInFlowState<E> {
|
|
36
|
+
readonly step: SignInStep;
|
|
37
|
+
readonly email: string;
|
|
38
|
+
readonly emailProblem: Option.Option<EmailProblem>;
|
|
39
|
+
readonly code: string;
|
|
40
|
+
readonly running: Option.Option<SignInRunning>;
|
|
41
|
+
/** The last failure, and what failed: sending, the code, or Google or Apple. */
|
|
42
|
+
readonly failure: Option.Option<{
|
|
43
|
+
readonly from: 'send' | 'code' | 'oauth';
|
|
44
|
+
readonly error: E;
|
|
45
|
+
}>;
|
|
46
|
+
/** Seconds until a code can be sent again (`0`: now). */
|
|
47
|
+
readonly resendIn: number;
|
|
48
|
+
}
|
|
49
|
+
export declare const initialFlowState: <E>() => SignInFlowState<E>;
|
|
50
|
+
/**
|
|
51
|
+
* An email address as `<input type="email">` accepts one (the HTML standard's "valid email
|
|
52
|
+
* address"), so a screen relying on the browser's own check agrees with this one.
|
|
53
|
+
*/
|
|
54
|
+
export declare const isEmailAddress: (email: string) => boolean;
|
|
55
|
+
export interface SignInFlowOptions<E> {
|
|
56
|
+
/** Whether the trimmed email is an address (`isEmailAddress` by default). */
|
|
57
|
+
readonly isEmail?: (email: string) => boolean;
|
|
58
|
+
/** Privy refused the code: the field has been emptied (focus it). */
|
|
59
|
+
readonly onWrongCode?: () => void;
|
|
60
|
+
/** Every new state, as it happens (synchronously in the command that made it). */
|
|
61
|
+
readonly onChange?: (state: SignInFlowState<E>) => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The sign-in screen's state machine: the email, the code, which step, what runs, which failure
|
|
65
|
+
* shows where, and the resend countdown (by `Clock`). Commands are Effects that change the state
|
|
66
|
+
* synchronously and fork the app's actions into the flow's scope; closing it interrupts them.
|
|
67
|
+
*/
|
|
68
|
+
export declare const makeSignInFlow: <E extends TaggedFailure, R>(actions: SignInActions<E, R>, options?: SignInFlowOptions<E>, initial?: SignInFlowState<E>) => Effect.Effect<{
|
|
69
|
+
state: Effect.Effect<SignInFlowState<E>, never, never>;
|
|
70
|
+
setEmail: (email: string) => Effect.Effect<void | undefined, never, never>;
|
|
71
|
+
submitEmail: Effect.Effect<void, never, R>;
|
|
72
|
+
setCode: (code: string) => Effect.Effect<void | undefined, never, never>;
|
|
73
|
+
submitCode: (value?: string) => Effect.Effect<void, never, R>;
|
|
74
|
+
resend: Effect.Effect<void, never, R>;
|
|
75
|
+
differentEmail: Effect.Effect<void | undefined, never, never>;
|
|
76
|
+
continueWith: (provider: OAuthProvider) => Effect.Effect<void, never, R>;
|
|
77
|
+
}, never, import("effect/Scope").Scope>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Clock, Effect, FiberHandle, FiberSet, Option, Ref, Schedule } from 'effect';
|
|
2
|
+
/** How many digits Privy's emailed sign-in code has. */
|
|
3
|
+
export const CODE_LENGTH = 6;
|
|
4
|
+
/** How long after each code sent before another can be asked for, in seconds. */
|
|
5
|
+
export const RESEND_SECONDS = 30;
|
|
6
|
+
export const initialFlowState = () => ({
|
|
7
|
+
step: 'email',
|
|
8
|
+
email: '',
|
|
9
|
+
emailProblem: Option.none(),
|
|
10
|
+
code: '',
|
|
11
|
+
running: Option.none(),
|
|
12
|
+
failure: Option.none(),
|
|
13
|
+
resendIn: 0,
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* An email address as `<input type="email">` accepts one (the HTML standard's "valid email
|
|
17
|
+
* address"), so a screen relying on the browser's own check agrees with this one.
|
|
18
|
+
*/
|
|
19
|
+
export const isEmailAddress = (email) => /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(email);
|
|
20
|
+
/** The page came back from the back/forward cache: back from the provider's page unfinished. */
|
|
21
|
+
const pageRestored = Effect.callback((resume) => {
|
|
22
|
+
const target = globalThis.window;
|
|
23
|
+
if (!target)
|
|
24
|
+
return;
|
|
25
|
+
const onShow = (event) => event.persisted && resume(Effect.void);
|
|
26
|
+
target.addEventListener('pageshow', onShow);
|
|
27
|
+
return Effect.sync(() => target.removeEventListener('pageshow', onShow));
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* The sign-in screen's state machine: the email, the code, which step, what runs, which failure
|
|
31
|
+
* shows where, and the resend countdown (by `Clock`). Commands are Effects that change the state
|
|
32
|
+
* synchronously and fork the app's actions into the flow's scope; closing it interrupts them.
|
|
33
|
+
*/
|
|
34
|
+
export const makeSignInFlow = (actions, options = {}, initial = initialFlowState()) => Effect.gen(function* () {
|
|
35
|
+
const isEmail = options.isEmail ?? isEmailAddress;
|
|
36
|
+
const state = yield* Ref.make(initial);
|
|
37
|
+
const work = yield* FiberSet.make();
|
|
38
|
+
const countdown = yield* FiberHandle.make();
|
|
39
|
+
const update = (f) => Ref.updateAndGet(state, f).pipe(Effect.flatMap((next) => Effect.sync(() => options.onChange?.(next))));
|
|
40
|
+
/** `running` cleared if it is still `what` (a defect or an interruption ended it). */
|
|
41
|
+
const done = (what) => update((s) => (Option.contains(s.running, what) ? { ...s, running: Option.none() } : s));
|
|
42
|
+
const failed = (from, error) => (s) => ({ ...s, running: Option.none(), failure: Option.some({ from, error }) });
|
|
43
|
+
const tick = Effect.gen(function* () {
|
|
44
|
+
const start = yield* Clock.currentTimeMillis;
|
|
45
|
+
const left = Clock.currentTimeMillis.pipe(Effect.map((now) => Math.max(0, RESEND_SECONDS - Math.floor((now - start) / 1000))), Effect.tap((seconds) => update((s) => ({ ...s, resendIn: seconds }))));
|
|
46
|
+
yield* Effect.repeat(left, { schedule: Schedule.spaced('1 second'), until: (seconds) => seconds === 0 });
|
|
47
|
+
});
|
|
48
|
+
const send = (to) => update((s) => ({ ...s, running: Option.some('send'), failure: Option.none() })).pipe(Effect.andThen(FiberSet.run(work, actions.sendCode(to).pipe(Effect.matchEffect({
|
|
49
|
+
onFailure: (error) => update(failed('send', error)),
|
|
50
|
+
onSuccess: () => update((s) => ({ ...s, step: 'code', code: '', running: Option.none(), failure: Option.none(), resendIn: RESEND_SECONDS })).pipe(Effect.andThen(FiberHandle.run(countdown, tick))),
|
|
51
|
+
}), Effect.ensuring(done('send'))))), Effect.asVoid);
|
|
52
|
+
const idle = Ref.get(state).pipe(Effect.map((s) => (Option.isNone(s.running) ? Option.some(s) : Option.none())));
|
|
53
|
+
return {
|
|
54
|
+
state: Ref.get(state),
|
|
55
|
+
setEmail: (email) => update((s) => ({ ...s, email, emailProblem: Option.none(), failure: Option.filter(s.failure, (f) => f.from !== 'send') })),
|
|
56
|
+
submitEmail: idle.pipe(Effect.flatMap(Option.match({
|
|
57
|
+
onNone: () => Effect.void,
|
|
58
|
+
onSome: (s) => {
|
|
59
|
+
const to = s.email.trim();
|
|
60
|
+
const problem = to === '' ? Option.some('Missing') : isEmail(to) ? Option.none() : Option.some('Malformed');
|
|
61
|
+
return Option.isSome(problem) ? update((current) => ({ ...current, emailProblem: problem })) : send(to);
|
|
62
|
+
},
|
|
63
|
+
}))),
|
|
64
|
+
setCode: (code) => update((s) => ({ ...s, code, failure: Option.filter(s.failure, (f) => f.from === 'oauth') })),
|
|
65
|
+
submitCode: (value) => idle.pipe(Effect.flatMap(Option.match({
|
|
66
|
+
onNone: () => Effect.void,
|
|
67
|
+
onSome: (s) => {
|
|
68
|
+
const code = value ?? s.code;
|
|
69
|
+
if (code.length !== CODE_LENGTH)
|
|
70
|
+
return Effect.void;
|
|
71
|
+
return update((current) => ({ ...current, code, running: Option.some('code'), failure: Option.none() })).pipe(Effect.andThen(FiberSet.run(work, actions.signInWithCode(code).pipe(Effect.matchEffect({
|
|
72
|
+
onFailure: (error) => error._tag === 'WrongCode'
|
|
73
|
+
? update((current) => ({ ...failed('code', error)(current), code: '' })).pipe(Effect.andThen(Effect.sync(() => options.onWrongCode?.())))
|
|
74
|
+
: update(failed('code', error)),
|
|
75
|
+
onSuccess: () => Effect.void,
|
|
76
|
+
}), Effect.ensuring(done('code'))))), Effect.asVoid);
|
|
77
|
+
},
|
|
78
|
+
}))),
|
|
79
|
+
resend: idle.pipe(Effect.flatMap(Option.match({
|
|
80
|
+
onNone: () => Effect.void,
|
|
81
|
+
onSome: (s) => (s.step === 'code' && s.resendIn === 0 ? send(s.email.trim()) : Effect.void),
|
|
82
|
+
}))),
|
|
83
|
+
differentEmail: idle.pipe(Effect.flatMap(Option.match({
|
|
84
|
+
onNone: () => Effect.void,
|
|
85
|
+
onSome: () => update((s) => ({ ...s, step: 'email', code: '', failure: Option.none() })),
|
|
86
|
+
}))),
|
|
87
|
+
continueWith: (provider) => idle.pipe(Effect.flatMap(Option.match({
|
|
88
|
+
onNone: () => Effect.void,
|
|
89
|
+
onSome: () => update((s) => ({ ...s, running: Option.some(provider), failure: Option.none() })).pipe(Effect.andThen(FiberSet.run(work, actions.signInWith(provider).pipe(Effect.matchEffect({
|
|
90
|
+
onFailure: (error) => update(failed('oauth', error)),
|
|
91
|
+
// The page is leaving: busy until it has, or until it comes back from the cache.
|
|
92
|
+
onSuccess: () => pageRestored.pipe(Effect.andThen(done(provider))),
|
|
93
|
+
}), Effect.ensuring(done(provider))))), Effect.asVoid),
|
|
94
|
+
}))),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Effect, Fiber, Option } from 'effect';
|
|
2
|
+
import type { OAuthProvider } from './oauth.js';
|
|
3
|
+
import { type EmailProblem, type SignInActions, type SignInStep, type TaggedFailure, type WrongCodeOf } from './sign-in-flow.js';
|
|
4
|
+
/**
|
|
5
|
+
* Runs one of the screen's programs, started at once (synchronously up to its first wait), as
|
|
6
|
+
* `Effect.runFork` and `ManagedRuntime.runFork` do: the app's runtime, providing what its
|
|
7
|
+
* actions need (`R`).
|
|
8
|
+
*/
|
|
9
|
+
export type RunSignIn<R> = (effect: Effect.Effect<void, never, R>) => Fiber.Fiber<void, unknown>;
|
|
10
|
+
export interface UseSignInOptions<R> {
|
|
11
|
+
/** How the screen's programs run (`Effect.runFork`, or the app's runtime's `runFork`). */
|
|
12
|
+
readonly run: RunSignIn<R>;
|
|
13
|
+
/** Privy is finishing a return from this provider: its button busy, the rest of the screen still. */
|
|
14
|
+
readonly returning?: OAuthProvider | undefined;
|
|
15
|
+
/** Whether a trimmed email is an address (by default, as `<input type="email">` checks). */
|
|
16
|
+
readonly isEmail?: ((email: string) => boolean) | undefined;
|
|
17
|
+
/** Privy refused the code: the field has been emptied (focus it here). */
|
|
18
|
+
readonly onWrongCode?: (() => void) | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** The sign-in screen's state and what it can do, for one render. */
|
|
21
|
+
export interface SignIn<E> {
|
|
22
|
+
readonly step: SignInStep;
|
|
23
|
+
readonly email: string;
|
|
24
|
+
readonly setEmail: (email: string) => void;
|
|
25
|
+
/** Why the email was refused before anything was sent (shown on its field until it changes). */
|
|
26
|
+
readonly emailProblem: Option.Option<EmailProblem>;
|
|
27
|
+
/** Sends a code to the trimmed email, once it is an address. */
|
|
28
|
+
readonly submitEmail: () => void;
|
|
29
|
+
readonly code: string;
|
|
30
|
+
readonly setCode: (code: string) => void;
|
|
31
|
+
/** Signs in with `code` (by default the one typed), once it has `codeLength` digits. */
|
|
32
|
+
readonly submitCode: (code?: string) => void;
|
|
33
|
+
readonly codeLength: number;
|
|
34
|
+
/** Seconds until `resend` can send another code (`0`: now). */
|
|
35
|
+
readonly resendIn: number;
|
|
36
|
+
readonly resend: () => void;
|
|
37
|
+
/** Back to the email step. */
|
|
38
|
+
readonly differentEmail: () => void;
|
|
39
|
+
/** Leaves for Google's or Apple's sign-in. */
|
|
40
|
+
readonly continueWith: (provider: OAuthProvider) => void;
|
|
41
|
+
/** A code is being sent. */
|
|
42
|
+
readonly sending: boolean;
|
|
43
|
+
/** The code is being checked. */
|
|
44
|
+
readonly checking: boolean;
|
|
45
|
+
/** The provider whose button is busy: leaving for it, or (`returning`) back from it. */
|
|
46
|
+
readonly provider: Option.Option<OAuthProvider>;
|
|
47
|
+
/** Anything is running, or Privy is finishing a return: the screen's commands wait. */
|
|
48
|
+
readonly busy: boolean;
|
|
49
|
+
/** Privy refused the code: shown by the code field (which has been emptied). */
|
|
50
|
+
readonly codeFailure: Option.Option<WrongCodeOf<E>>;
|
|
51
|
+
/** Any other failure: shown in the screen's alert line. */
|
|
52
|
+
readonly alert: Option.Option<Exclude<E, {
|
|
53
|
+
readonly _tag: 'WrongCode';
|
|
54
|
+
}>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The sign-in screen's state machine, for an app's own screen over Privy's headless sign-in: an
|
|
58
|
+
* email and the code Privy sends it (`codeLength` digits; another after `RESEND_SECONDS`), or Google
|
|
59
|
+
* or Apple. `actions` are the app's own Effects, run with `options.run`. Each failure shows once:
|
|
60
|
+
* a `WrongCode` as the code field's (`codeFailure`), any other in the alert line (`alert`); an
|
|
61
|
+
* email missing or malformed is `emailProblem`, and nothing is sent. Starting anything clears the
|
|
62
|
+
* failure shown; editing the email clears a send's failure, editing the code a send's or the
|
|
63
|
+
* code's. A provider's button stays busy once its action succeeds (the page is leaving), until
|
|
64
|
+
* the page comes back from the back/forward cache. Programs stop when the screen unmounts.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useSignIn<E extends TaggedFailure, R = never>(actions: SignInActions<E, R>, options: UseSignInOptions<R>): SignIn<E>;
|
package/dist/sign-in.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Effect, Fiber, Option } from 'effect';
|
|
2
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { CODE_LENGTH, initialFlowState, isEmailAddress, makeSignInFlow, } from './sign-in-flow.js';
|
|
4
|
+
/** The flow behind one mounted screen, and React's view of its state. */
|
|
5
|
+
class FlowHost {
|
|
6
|
+
state = initialFlowState();
|
|
7
|
+
flow = Option.none();
|
|
8
|
+
mounts = 0;
|
|
9
|
+
listeners = new Set();
|
|
10
|
+
subscribe = (listener) => {
|
|
11
|
+
this.listeners.add(listener);
|
|
12
|
+
return () => void this.listeners.delete(listener);
|
|
13
|
+
};
|
|
14
|
+
snapshot = () => this.state;
|
|
15
|
+
/** Starts the flow for this mount (from the state it had), and answers how to stop it. */
|
|
16
|
+
mount(latest) {
|
|
17
|
+
const mount = ++this.mounts;
|
|
18
|
+
const actions = {
|
|
19
|
+
sendCode: (email) => Effect.suspend(() => latest.current.actions.sendCode(email)),
|
|
20
|
+
signInWithCode: (code) => Effect.suspend(() => latest.current.actions.signInWithCode(code)),
|
|
21
|
+
signInWith: (provider) => Effect.suspend(() => latest.current.actions.signInWith(provider)),
|
|
22
|
+
};
|
|
23
|
+
const publish = (state) => {
|
|
24
|
+
if (mount !== this.mounts)
|
|
25
|
+
return;
|
|
26
|
+
this.state = state;
|
|
27
|
+
for (const listener of this.listeners)
|
|
28
|
+
listener();
|
|
29
|
+
};
|
|
30
|
+
const host = this;
|
|
31
|
+
const fiber = latest.current.options.run(Effect.scoped(Effect.gen(function* () {
|
|
32
|
+
const flow = yield* makeSignInFlow(actions, { isEmail: (email) => (latest.current.options.isEmail ?? isEmailAddress)(email), onWrongCode: () => latest.current.options.onWrongCode?.(), onChange: publish }, host.state);
|
|
33
|
+
host.flow = Option.some(flow);
|
|
34
|
+
return yield* Effect.never;
|
|
35
|
+
})));
|
|
36
|
+
return () => {
|
|
37
|
+
this.mounts++;
|
|
38
|
+
this.flow = Option.none();
|
|
39
|
+
latest.current.options.run(Fiber.interrupt(fiber));
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The sign-in screen's state machine, for an app's own screen over Privy's headless sign-in: an
|
|
45
|
+
* email and the code Privy sends it (`codeLength` digits; another after `RESEND_SECONDS`), or Google
|
|
46
|
+
* or Apple. `actions` are the app's own Effects, run with `options.run`. Each failure shows once:
|
|
47
|
+
* a `WrongCode` as the code field's (`codeFailure`), any other in the alert line (`alert`); an
|
|
48
|
+
* email missing or malformed is `emailProblem`, and nothing is sent. Starting anything clears the
|
|
49
|
+
* failure shown; editing the email clears a send's failure, editing the code a send's or the
|
|
50
|
+
* code's. A provider's button stays busy once its action succeeds (the page is leaving), until
|
|
51
|
+
* the page comes back from the back/forward cache. Programs stop when the screen unmounts.
|
|
52
|
+
*/
|
|
53
|
+
export function useSignIn(actions, options) {
|
|
54
|
+
const latest = useRef({ actions, options });
|
|
55
|
+
latest.current = { actions, options };
|
|
56
|
+
const [host] = useState(() => new FlowHost());
|
|
57
|
+
const state = useSyncExternalStore(host.subscribe, host.snapshot, host.snapshot);
|
|
58
|
+
useEffect(() => host.mount(latest), [host]);
|
|
59
|
+
const returning = options.returning;
|
|
60
|
+
/** Runs a command of the flow, if it is mounted (and nothing is being returned from). */
|
|
61
|
+
const command = (pick, whileReturning = false) => (...args) => {
|
|
62
|
+
if (!whileReturning && latest.current.options.returning !== undefined)
|
|
63
|
+
return;
|
|
64
|
+
Option.map(host.flow, (flow) => latest.current.options.run(pick(flow)(...args)));
|
|
65
|
+
};
|
|
66
|
+
const running = Option.getOrUndefined(state.running);
|
|
67
|
+
const leaving = running === 'google' || running === 'apple' ? running : undefined;
|
|
68
|
+
const failure = Option.getOrUndefined(state.failure)?.error;
|
|
69
|
+
const wrongCode = failure !== undefined && failure._tag === 'WrongCode';
|
|
70
|
+
return {
|
|
71
|
+
step: state.step,
|
|
72
|
+
email: state.email,
|
|
73
|
+
setEmail: command((flow) => flow.setEmail, true),
|
|
74
|
+
emailProblem: state.emailProblem,
|
|
75
|
+
submitEmail: command((flow) => () => flow.submitEmail),
|
|
76
|
+
code: state.code,
|
|
77
|
+
setCode: command((flow) => flow.setCode, true),
|
|
78
|
+
submitCode: command((flow) => (code) => flow.submitCode(code)),
|
|
79
|
+
codeLength: CODE_LENGTH,
|
|
80
|
+
resendIn: state.resendIn,
|
|
81
|
+
resend: command((flow) => () => flow.resend),
|
|
82
|
+
differentEmail: command((flow) => () => flow.differentEmail),
|
|
83
|
+
continueWith: command((flow) => flow.continueWith),
|
|
84
|
+
sending: running === 'send',
|
|
85
|
+
checking: running === 'code',
|
|
86
|
+
provider: Option.fromUndefinedOr(returning ?? leaving),
|
|
87
|
+
busy: running !== undefined || returning !== undefined,
|
|
88
|
+
codeFailure: wrongCode ? Option.some(failure) : Option.none(),
|
|
89
|
+
alert: failure !== undefined && !wrongCode ? Option.some(failure) : Option.none(),
|
|
90
|
+
};
|
|
91
|
+
}
|
package/dist/signer.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@misofm/privy-auth/signer`: the account's Privy embedded Sui wallet as a `@mysten/sui`
|
|
3
|
+
* `Signer`. Its own entry because it loads `@mysten/sui` (Ed25519, BLAKE2b, base58): an app
|
|
4
|
+
* imports it lazily, when the wallet first signs or its key is first checked.
|
|
5
|
+
*
|
|
6
|
+
* Privy supports Sui as a "tier 2" chain: it makes the Ed25519 key and signs a raw 32-byte hash
|
|
7
|
+
* with it (`useSignRawHash`), nothing more. `PrivySigner.sign` hands that hash to Privy; the SDK
|
|
8
|
+
* builds the intent digest and the serialized signature exactly as for a local keypair.
|
|
9
|
+
*/
|
|
10
|
+
import { type SignatureScheme, Signer } from '@mysten/sui/cryptography';
|
|
11
|
+
import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
|
|
12
|
+
import { Option, Result, Schema } from 'effect';
|
|
13
|
+
/** The account's Sui wallet, its public key checked against its address. */
|
|
14
|
+
export type SuiWallet = {
|
|
15
|
+
/** The wallet's address, normalized (`0x`, 64 lowercase hex digits). */
|
|
16
|
+
readonly address: string;
|
|
17
|
+
readonly publicKey: Ed25519PublicKey;
|
|
18
|
+
};
|
|
19
|
+
declare const InvalidSuiWallet_base: Schema.Class<InvalidSuiWallet, Schema.TaggedStruct<"InvalidSuiWallet", {
|
|
20
|
+
readonly reason: Schema.Literals<readonly ["NoAddress", "NoPublicKey", "UnreadablePublicKey", "NotTheAddressKey"]>;
|
|
21
|
+
}>, import("effect/Cause").YieldableError>;
|
|
22
|
+
/**
|
|
23
|
+
* The account has a Privy Sui wallet it can't sign with. `reason`: `NoAddress`, `NoPublicKey`,
|
|
24
|
+
* `UnreadablePublicKey` (not one of Privy's encodings), `NotTheAddressKey` (a key, but not the
|
|
25
|
+
* address's).
|
|
26
|
+
*/
|
|
27
|
+
export declare class InvalidSuiWallet extends InvalidSuiWallet_base {
|
|
28
|
+
get message(): string;
|
|
29
|
+
}
|
|
30
|
+
declare const InvalidSignature_base: Schema.Class<InvalidSignature, Schema.TaggedStruct<"InvalidSignature", {
|
|
31
|
+
readonly length: Schema.Number;
|
|
32
|
+
}>, import("effect/Cause").YieldableError>;
|
|
33
|
+
/** Privy's wallet answered something other than a 64-byte Ed25519 signature (thrown by `PrivySigner.sign`). */
|
|
34
|
+
export declare class InvalidSignature extends InvalidSignature_base {
|
|
35
|
+
get message(): string;
|
|
36
|
+
}
|
|
37
|
+
/** Signs a 32-byte digest, hex in and out (`0x…`): Privy's `signRawHash` for the wallet. */
|
|
38
|
+
export type SignHash = (hash: `0x${string}`) => Promise<`0x${string}`>;
|
|
39
|
+
/**
|
|
40
|
+
* A tier-2 wallet's Ed25519 public key as Privy encodes it: hex (with or without `0x`, the
|
|
41
|
+
* 32-byte key, or 33 bytes led by Sui's Ed25519 flag `00`), or base58 of the 32-byte key. The two
|
|
42
|
+
* can't be confused: hex keys are 64 or 66 characters, base58 ones 43 or 44 and never contain
|
|
43
|
+
* `0`. Anything else is `None`.
|
|
44
|
+
*/
|
|
45
|
+
export declare const walletPublicKey: (encoded: string) => Option.Option<Ed25519PublicKey>;
|
|
46
|
+
/**
|
|
47
|
+
* The account's Privy embedded Sui wallet among `linkedAccounts` (Privy's `user.linkedAccounts`;
|
|
48
|
+
* the same wallet `suiWalletAccount` finds), its public key decoded and checked against its
|
|
49
|
+
* address. Succeeds with `None` when the account has no Privy Sui wallet, `Some` when it has one
|
|
50
|
+
* that can sign; fails with `InvalidSuiWallet` when it has one that can't. A `Result`, so it reads
|
|
51
|
+
* synchronously in render; in an Effect, `yield* Effect.fromResult(suiWallet(accounts))`.
|
|
52
|
+
*/
|
|
53
|
+
export declare const suiWallet: (linkedAccounts: ReadonlyArray<unknown>) => Result.Result<Option.Option<SuiWallet>, InvalidSuiWallet>;
|
|
54
|
+
/**
|
|
55
|
+
* The wallet as a Sui `Signer` (the SDK calls it with Promises): `signTransaction` and
|
|
56
|
+
* `signPersonalMessage` work unchanged. `PrivySigner.of(wallet, signHash)` makes one from
|
|
57
|
+
* `suiWallet`'s answer.
|
|
58
|
+
*/
|
|
59
|
+
export declare class PrivySigner extends Signer {
|
|
60
|
+
#private;
|
|
61
|
+
constructor(publicKey: Ed25519PublicKey, signHash: SignHash);
|
|
62
|
+
/** The signer of a wallet `suiWallet` found. */
|
|
63
|
+
static of(wallet: SuiWallet, signHash: SignHash): PrivySigner;
|
|
64
|
+
/** Ed25519 over `digest` by Privy's wallet; anything but 64 bytes back rejects with `InvalidSignature`. */
|
|
65
|
+
sign(digest: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
|
|
66
|
+
getKeyScheme(): SignatureScheme;
|
|
67
|
+
getPublicKey(): Ed25519PublicKey;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
package/dist/signer.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@misofm/privy-auth/signer`: the account's Privy embedded Sui wallet as a `@mysten/sui`
|
|
3
|
+
* `Signer`. Its own entry because it loads `@mysten/sui` (Ed25519, BLAKE2b, base58): an app
|
|
4
|
+
* imports it lazily, when the wallet first signs or its key is first checked.
|
|
5
|
+
*
|
|
6
|
+
* Privy supports Sui as a "tier 2" chain: it makes the Ed25519 key and signs a raw 32-byte hash
|
|
7
|
+
* with it (`useSignRawHash`), nothing more. `PrivySigner.sign` hands that hash to Privy; the SDK
|
|
8
|
+
* builds the intent digest and the serialized signature exactly as for a local keypair.
|
|
9
|
+
*/
|
|
10
|
+
import { Signer } from '@mysten/sui/cryptography';
|
|
11
|
+
import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
|
|
12
|
+
import { fromBase58, fromHex, normalizeSuiAddress, toHex } from '@mysten/sui/utils';
|
|
13
|
+
import { Option, Result, Schema } from 'effect';
|
|
14
|
+
import { findSuiWallet, walletFields } from './account.js';
|
|
15
|
+
/**
|
|
16
|
+
* The account has a Privy Sui wallet it can't sign with. `reason`: `NoAddress`, `NoPublicKey`,
|
|
17
|
+
* `UnreadablePublicKey` (not one of Privy's encodings), `NotTheAddressKey` (a key, but not the
|
|
18
|
+
* address's).
|
|
19
|
+
*/
|
|
20
|
+
export class InvalidSuiWallet extends Schema.TaggedError()('InvalidSuiWallet', {
|
|
21
|
+
reason: Schema.Literals(['NoAddress', 'NoPublicKey', 'UnreadablePublicKey', 'NotTheAddressKey']),
|
|
22
|
+
}) {
|
|
23
|
+
get message() {
|
|
24
|
+
return `The account's Sui wallet can't sign: ${this.reason}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Privy's wallet answered something other than a 64-byte Ed25519 signature (thrown by `PrivySigner.sign`). */
|
|
28
|
+
export class InvalidSignature extends Schema.TaggedError()('InvalidSignature', {
|
|
29
|
+
length: Schema.Number,
|
|
30
|
+
}) {
|
|
31
|
+
get message() {
|
|
32
|
+
return `Privy answered no Ed25519 signature (${this.length} bytes)`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const ED25519_FLAG = '00';
|
|
36
|
+
/**
|
|
37
|
+
* A tier-2 wallet's Ed25519 public key as Privy encodes it: hex (with or without `0x`, the
|
|
38
|
+
* 32-byte key, or 33 bytes led by Sui's Ed25519 flag `00`), or base58 of the 32-byte key. The two
|
|
39
|
+
* can't be confused: hex keys are 64 or 66 characters, base58 ones 43 or 44 and never contain
|
|
40
|
+
* `0`. Anything else is `None`.
|
|
41
|
+
*/
|
|
42
|
+
export const walletPublicKey = (encoded) => {
|
|
43
|
+
const hex = encoded.replace(/^0x/i, '');
|
|
44
|
+
if (/^[0-9a-f]{64}$/i.test(hex))
|
|
45
|
+
return Option.some(new Ed25519PublicKey(fromHex(hex)));
|
|
46
|
+
if (/^[0-9a-f]{66}$/i.test(hex) && hex.startsWith(ED25519_FLAG))
|
|
47
|
+
return Option.some(new Ed25519PublicKey(fromHex(hex.slice(2))));
|
|
48
|
+
return Option.flatMap(Option.liftThrowable(fromBase58)(encoded), Option.liftPredicate((bytes) => bytes.length === 32)).pipe(Option.map((bytes) => new Ed25519PublicKey(bytes)));
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The account's Privy embedded Sui wallet among `linkedAccounts` (Privy's `user.linkedAccounts`;
|
|
52
|
+
* the same wallet `suiWalletAccount` finds), its public key decoded and checked against its
|
|
53
|
+
* address. Succeeds with `None` when the account has no Privy Sui wallet, `Some` when it has one
|
|
54
|
+
* that can sign; fails with `InvalidSuiWallet` when it has one that can't. A `Result`, so it reads
|
|
55
|
+
* synchronously in render; in an Effect, `yield* Effect.fromResult(suiWallet(accounts))`.
|
|
56
|
+
*/
|
|
57
|
+
export const suiWallet = (linkedAccounts) => {
|
|
58
|
+
const found = findSuiWallet(linkedAccounts);
|
|
59
|
+
if (Option.isNone(found))
|
|
60
|
+
return Result.succeed(Option.none());
|
|
61
|
+
const fields = walletFields(found.value);
|
|
62
|
+
if (Option.isNone(fields))
|
|
63
|
+
return Result.fail(new InvalidSuiWallet({ reason: 'NoAddress' }));
|
|
64
|
+
const { address, publicKey: encoded } = fields.value;
|
|
65
|
+
if (Option.isNone(encoded))
|
|
66
|
+
return Result.fail(new InvalidSuiWallet({ reason: 'NoPublicKey' }));
|
|
67
|
+
const publicKey = walletPublicKey(encoded.value);
|
|
68
|
+
if (Option.isNone(publicKey))
|
|
69
|
+
return Result.fail(new InvalidSuiWallet({ reason: 'UnreadablePublicKey' }));
|
|
70
|
+
const keyAddress = publicKey.value.toSuiAddress();
|
|
71
|
+
if (keyAddress !== normalizeSuiAddress(address))
|
|
72
|
+
return Result.fail(new InvalidSuiWallet({ reason: 'NotTheAddressKey' }));
|
|
73
|
+
return Result.succeed(Option.some({ address: keyAddress, publicKey: publicKey.value }));
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The wallet as a Sui `Signer` (the SDK calls it with Promises): `signTransaction` and
|
|
77
|
+
* `signPersonalMessage` work unchanged. `PrivySigner.of(wallet, signHash)` makes one from
|
|
78
|
+
* `suiWallet`'s answer.
|
|
79
|
+
*/
|
|
80
|
+
export class PrivySigner extends Signer {
|
|
81
|
+
#publicKey;
|
|
82
|
+
#signHash;
|
|
83
|
+
constructor(publicKey, signHash) {
|
|
84
|
+
super();
|
|
85
|
+
this.#publicKey = publicKey;
|
|
86
|
+
this.#signHash = signHash;
|
|
87
|
+
}
|
|
88
|
+
/** The signer of a wallet `suiWallet` found. */
|
|
89
|
+
static of(wallet, signHash) {
|
|
90
|
+
return new PrivySigner(wallet.publicKey, signHash);
|
|
91
|
+
}
|
|
92
|
+
/** Ed25519 over `digest` by Privy's wallet; anything but 64 bytes back rejects with `InvalidSignature`. */
|
|
93
|
+
async sign(digest) {
|
|
94
|
+
const signature = fromHex((await this.#signHash(`0x${toHex(digest)}`)).replace(/^0x/i, ''));
|
|
95
|
+
if (signature.length !== 64)
|
|
96
|
+
throw new InvalidSignature({ length: signature.length });
|
|
97
|
+
return new Uint8Array(signature);
|
|
98
|
+
}
|
|
99
|
+
getKeyScheme() {
|
|
100
|
+
return 'ED25519';
|
|
101
|
+
}
|
|
102
|
+
getPublicKey() {
|
|
103
|
+
return this.#publicKey;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Option, Schema } from 'effect';
|
|
2
|
+
/** An identity token's `linked_accounts`: a JSON string of an array in Privy's tokens. */
|
|
3
|
+
export declare const LinkedAccountsJson: Schema.fromJsonString<Schema.$Array<Schema.Unknown>>;
|
|
4
|
+
/** A JWT part (base64url of JSON) decoded with `schema`. */
|
|
5
|
+
export declare const jwtPart: <S extends Schema.Top>(schema: S) => Schema.compose<Schema.fromJsonString<S>, Schema.StringFromBase64Url>;
|
|
6
|
+
/** When a JWT ends (`exp`, as ms since the epoch); `None` when it doesn't say or isn't a JWT. Unverified. */
|
|
7
|
+
export declare const jwtEnd: (jwt: string) => Option.Option<number>;
|
|
8
|
+
/**
|
|
9
|
+
* Whether Privy's identity token names the Sui wallet at `address` among its `linked_accounts`
|
|
10
|
+
* (the API reads the account's address there, so a token made before the wallet is of no use).
|
|
11
|
+
* Unverified.
|
|
12
|
+
*/
|
|
13
|
+
export declare const namesWallet: (identityToken: string, address: string) => boolean;
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Array as Arr, Option, Schema } from 'effect';
|
|
2
|
+
import { normalizeSuiAddress } from './address.js';
|
|
3
|
+
/** An identity token's `linked_accounts`: a JSON string of an array in Privy's tokens. */
|
|
4
|
+
export const LinkedAccountsJson = Schema.fromJsonString(Schema.Array(Schema.Unknown));
|
|
5
|
+
/** A JWT part (base64url of JSON) decoded with `schema`. */
|
|
6
|
+
export const jwtPart = (schema) => Schema.StringFromBase64Url.pipe(Schema.decodeTo(Schema.fromJsonString(schema)));
|
|
7
|
+
/** The claims of a JWT (its middle part) decoded with `schema`, unverified. */
|
|
8
|
+
const claims = (schema) => {
|
|
9
|
+
const decode = Schema.decodeUnknownOption(jwtPart(schema));
|
|
10
|
+
return (jwt) => decode(jwt.split('.')[1]);
|
|
11
|
+
};
|
|
12
|
+
const endOf = claims(Schema.Struct({ exp: Schema.Finite }));
|
|
13
|
+
/** When a JWT ends (`exp`, as ms since the epoch); `None` when it doesn't say or isn't a JWT. Unverified. */
|
|
14
|
+
export const jwtEnd = (jwt) => Option.map(endOf(jwt), ({ exp }) => exp * 1000);
|
|
15
|
+
const linkedOf = claims(Schema.Struct({ linked_accounts: LinkedAccountsJson }));
|
|
16
|
+
const TokenSuiWallet = Schema.Struct({ chain_type: Schema.Literal('sui'), address: Schema.String });
|
|
17
|
+
const decodeTokenSuiWallet = Schema.decodeUnknownOption(TokenSuiWallet);
|
|
18
|
+
/**
|
|
19
|
+
* Whether Privy's identity token names the Sui wallet at `address` among its `linked_accounts`
|
|
20
|
+
* (the API reads the account's address there, so a token made before the wallet is of no use).
|
|
21
|
+
* Unverified.
|
|
22
|
+
*/
|
|
23
|
+
export const namesWallet = (identityToken, address) => {
|
|
24
|
+
const wanted = normalizeSuiAddress(address);
|
|
25
|
+
return Option.match(linkedOf(identityToken), {
|
|
26
|
+
onNone: () => false,
|
|
27
|
+
onSome: ({ linked_accounts }) => Arr.some(linked_accounts, (account) => Option.exists(decodeTokenSuiWallet(account), (wallet) => normalizeSuiAddress(wallet.address) === wanted)),
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createOTPInputController, OTPInput } from '@ui-sdk/react/otp-input';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
/** A handle to focus a `CodeField` from elsewhere (`onWrongCode`); make one per field. */
|
|
4
|
+
export declare const createCodeFieldController: typeof createOTPInputController;
|
|
5
|
+
export interface CodeFieldProps extends Omit<ComponentProps<typeof OTPInput>, 'children' | 'maxLength' | 'pattern' | 'inputMode' | 'autoComplete' | 'className'> {
|
|
6
|
+
/** Digits (`CODE_LENGTH`, 6, by default). */
|
|
7
|
+
readonly length?: number | undefined;
|
|
8
|
+
/** Its name, for assistive technology ("Code" by default; hide it with the label's class). */
|
|
9
|
+
readonly label?: ReactNode;
|
|
10
|
+
/** What to type, read with the field (`FieldDescription`). */
|
|
11
|
+
readonly description?: ReactNode;
|
|
12
|
+
/** The code's problem (`useSignIn`'s `codeFailure`, in words): the field invalid, this its `FieldError`. */
|
|
13
|
+
readonly error?: ReactNode;
|
|
14
|
+
readonly classNames?: {
|
|
15
|
+
readonly root?: string | undefined;
|
|
16
|
+
readonly label?: string | undefined;
|
|
17
|
+
readonly description?: string | undefined;
|
|
18
|
+
/** ui-sdk's `OTPInput` (the native input inside, and its slots). */
|
|
19
|
+
readonly input?: string | undefined;
|
|
20
|
+
readonly group?: string | undefined;
|
|
21
|
+
readonly slot?: string | undefined;
|
|
22
|
+
readonly error?: string | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The emailed code (ui-sdk's `OTPInput` in a `Field`), unstyled: one native input
|
|
27
|
+
* (`autocomplete="one-time-code"`, a numeric keyboard, digits only) drawn as `length` slots, so a
|
|
28
|
+
* pasted or autofilled code fills them all. Controlled (`value` + `onValueChange`);
|
|
29
|
+
* `onValueCommit` runs once every slot is filled (`useSignIn`'s `submitCode`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function CodeField({ length, label, description, error, classNames, ...props }: CodeFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Field, FieldDescription, FieldError, FieldLabel } from '@ui-sdk/react/field';
|
|
3
|
+
import { createOTPInputController, OTPInput, OTPInputGroup, OTPInputSlot } from '@ui-sdk/react/otp-input';
|
|
4
|
+
import { classNameOf } from './class-name.js';
|
|
5
|
+
import { CODE_LENGTH } from '../sign-in-flow.js';
|
|
6
|
+
/** A handle to focus a `CodeField` from elsewhere (`onWrongCode`); make one per field. */
|
|
7
|
+
export const createCodeFieldController = createOTPInputController;
|
|
8
|
+
/**
|
|
9
|
+
* The emailed code (ui-sdk's `OTPInput` in a `Field`), unstyled: one native input
|
|
10
|
+
* (`autocomplete="one-time-code"`, a numeric keyboard, digits only) drawn as `length` slots, so a
|
|
11
|
+
* pasted or autofilled code fills them all. Controlled (`value` + `onValueChange`);
|
|
12
|
+
* `onValueCommit` runs once every slot is filled (`useSignIn`'s `submitCode`).
|
|
13
|
+
*/
|
|
14
|
+
export function CodeField({ length = CODE_LENGTH, label = 'Code', description, error, classNames, ...props }) {
|
|
15
|
+
const invalid = error !== undefined && error !== null && error !== false;
|
|
16
|
+
return (_jsxs(Field, { invalid: invalid, ...classNameOf(classNames?.root), children: [_jsx(FieldLabel, { ...classNameOf(classNames?.label), children: label }), description !== undefined && _jsx(FieldDescription, { ...classNameOf(classNames?.description), children: description }), _jsx(OTPInput, { maxLength: length, pattern: "digits", inputMode: "numeric", autoComplete: "one-time-code", ...classNameOf(classNames?.input), ...props, children: _jsx(OTPInputGroup, { ...classNameOf(classNames?.group), children: Array.from({ length }, (_, index) => (_jsx(OTPInputSlot, { index: index, ...classNameOf(classNames?.slot) }, index))) }) }), invalid && (_jsx(FieldError, { match: true, ...classNameOf(classNames?.error), children: error }))] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** Miso's Terms of Use. */
|
|
3
|
+
export declare const TERMS_OF_USE_URL = "https://miso.fm/terms-of-use/";
|
|
4
|
+
/** Miso's Privacy Policy. */
|
|
5
|
+
export declare const PRIVACY_POLICY_URL = "https://miso.fm/privacy-policy/";
|
|
6
|
+
/** The consent line's words, around its two links. */
|
|
7
|
+
export type ConsentCopy = {
|
|
8
|
+
readonly agree: ReactNode;
|
|
9
|
+
readonly terms: ReactNode;
|
|
10
|
+
readonly acknowledge: ReactNode;
|
|
11
|
+
readonly privacy: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The standard consent line under a sign-in: agree to the Terms of Use, acknowledge the Privacy
|
|
15
|
+
* Policy (a notice, not a contract), each a link to miso.fm in a new tab. Unstyled: `className`
|
|
16
|
+
* for the paragraph, `classNames.link` for both links.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ConsentLine({ className, classNames, copy }: {
|
|
19
|
+
readonly className?: string | undefined;
|
|
20
|
+
readonly classNames?: {
|
|
21
|
+
readonly link?: string | undefined;
|
|
22
|
+
} | undefined;
|
|
23
|
+
readonly copy?: Partial<ConsentCopy> | undefined;
|
|
24
|
+
}): import("react").JSX.Element;
|