IF Commons GitHub

challenge

concept

Something a person is asked to prove, once: a reset link, a magic link, a code or a passkey challenge, kept as a hash

Model identity. Written in commons/data/models/identity/concepts.ts:212. Identified by challengeId.

Governance: attributes

attemptsintegerrequired

How many times it was tried

Becomes the column attempts of challenge.

Written at commons/data/models/identity/concepts.ts:218

challengeIdidentifierrequired

What identifies the challenge, made by the application

Becomes the column challenge_id of challenge.

Written at commons/data/models/identity/concepts.ts:215

consumedAtinstantoptional

When it was used

Becomes the column consumed_at of challenge.

Written at commons/data/models/identity/concepts.ts:221

expiresAtinstantrequired

When it stops being valid

Becomes the column expires_at of challenge.

Written at commons/data/models/identity/concepts.ts:220

maxAttemptsintegerrequired

How many times it may be

Becomes the column max_attempts of challenge.

Written at commons/data/models/identity/concepts.ts:219

purposecode of challengePurposerequired

What it is for

Becomes the column purpose of challenge.

Written at commons/data/models/identity/concepts.ts:216

secretHashtextrequired

The hash of what was sent

Becomes the column secret_hash of challenge.

Written at commons/data/models/identity/concepts.ts:217

Governance: relationships

destinationoptional

Where it was sent To electronicContact. Written at commons/data/models/identity/concepts.ts:226

principaloptional

Who it is for, where that is known To principal. Written at commons/data/models/identity/concepts.ts:225

Logical: the table

Projects to the table challenge with the primary key challenge_id.

ColumnTypeNullRoleFrom
attemptsintegerfalseattributechallenge.attempts
challenge_idtextfalseattributechallenge.challengeId
consumed_attimestamptrueattributechallenge.consumedAt
destination_electronic_contact_idtexttruereferencechallenge.destination
expires_attimestampfalseattributechallenge.expiresAt
max_attemptsintegerfalseattributechallenge.maxAttempts
principal_idtexttruereferencechallenge.principal
purposetextfalseattributechallenge.purpose
secret_hashtextfalseattributechallenge.secretHash

Physical: SQL

CREATE TABLE IF NOT EXISTS "challenge" (
    "challenge_id" VARCHAR NOT NULL PRIMARY KEY,
    "purpose" VARCHAR NOT NULL,
    "secret_hash" VARCHAR NOT NULL,
    "attempts" INTEGER NOT NULL,
    "max_attempts" INTEGER NOT NULL,
    "expires_at" TIMESTAMPTZ NOT NULL,
    "consumed_at" TIMESTAMPTZ,
    "principal_id" VARCHAR,
    "destination_electronic_contact_id" VARCHAR,
    CONSTRAINT "challenge_principal_id_fk" FOREIGN KEY ("principal_id") REFERENCES "principal" ("principal_id"),
    CONSTRAINT "challenge_destination_electronic_contact_id_fk" FOREIGN KEY ("destination_electronic_contact_id") REFERENCES "electronic_contact" ("electronic_contact_id"),
    CONSTRAINT "challenge_purpose_ck" CHECK ("purpose" IN ('login', 'email_verification', 'password_reset', 'magic_link', 'step_up', 'passkey_registration', 'passkey_authentication'))
);

Physical: the typed table

Read and written from TypeScript with the types the model gives: import { challenge } from "@intellectual-frontiers/data/sql/typed/models". Generated in commons/data/sql/typed/models/identity.auto.ts: do not edit.

import { from } from "@intellectual-frontiers/data/sql/typed";
import { challenge } from "@intellectual-frontiers/data/sql/typed/models";

const rows = await from(challenge).select((s) => ({ challengeId: s.challenge.challengeId, purpose: s.challenge.purpose })).run(runner);

Titles, headings, exports, tables, columns and requirements. Esc closes.