FirstProof.ts overview
The first proof of an address: before a flow verifies an unverified email identifier on a proof, it clears the account’s password and other credentials and revokes its sessions, so the prover alone holds the account. A verified phone stays, and issued JWTs expire on their own.
Exports Grouped by Category
utils
FirstProofCredentials (type alias)
The credential stores proveAddress sweeps on a first proof, each through its per-user delete (UserCredentials.ts, which deleting a user shares). Each is optional: an app without passkeys provides no CredentialStore, and its absence means the account cannot hold that kind of credential.
Signature
type FirstProofCredentials = Pick<
UserCredentialStores,
"oauthAccounts" | "passkeys" | "apiKeys" | "multiFactor" | "trustedDevices" | "oidcTokens" | "oidcConsents"
>
FirstProofServices (interface)
The services proveAddress writes through, resolved by the caller.
Signature
export interface FirstProofServices extends FirstProofCredentials {
readonly identifiers: typeof IdentifierStore.Service
readonly passwords: Pick<typeof EmailPasswordStore.Service, "clearPasswordHash">
readonly sessions: Pick<typeof SessionService.Service, "invalidateUserSessions" | "revokeOtherSessions">
}
firstProofServices
The FirstProofServices over the caller’s base services and the credential stores present in the context. A caller resolves it where it resolves its other stores (at layer construction) and passes it to every proveAddress it makes.
Signature
declare const firstProofServices: (
base: Omit<FirstProofServices, keyof FirstProofCredentials>
) => Effect.Effect<FirstProofServices>
proveAddress
Promote identifier to verified. When it is not verified yet, first clear its account’s password, remove its unverified phone identifiers and its other credentials (the FirstProofCredentials the caller passes, OIDC-provider tokens and consents included) and revoke its sessions, last, so a session minted with a credential before its removal goes too; the caller mints the prover’s session (and, for OAuth, creates the link being made now) afterwards. A prover who presented the proof over one of the account’s sessions (an invitation accepted while signed in) passes that session’s stored id (the token’s digest, as validateSession answers it) as proverSessionId, and it alone survives. An identifier that is already verified is promoted with nothing removed. Returns what setVerified returns (None when the identifier was deleted meanwhile).
Signature
declare const proveAddress: (
services: FirstProofServices,
identifier: Identifier,
proverSessionId?: string
) => Effect.Effect<Option.Option<Identifier>, Errors.AuthError>
userForProvenEmail
The user a proof of email signs in, given what findIdentifierOwner found for it. An owner is returned, its address first promoted through proveAddress when it is unverified. With no owner, create makes a user holding the address already verified, and taken is the flow’s error when another user claims the address meanwhile.
Signature
declare const userForProvenEmail: <E, R, E2>(
services: FirstProofServices,
found: Option.Option<{ readonly identifier: Identifier; readonly user: Types.User }>,
email: string,
create: (identifier: NewUserIdentifier) => Effect.Effect<CreateUserResult, E, R>,
taken: () => E2
) => Effect.Effect<Types.User, E | E2 | Errors.AuthError, R>