Identity.anyOf
Accept one of several identities
Creates a verifier that accepts the request when any one of its members verifies.
Usage
import * as from 'mppx/extensions/identity/email-otp'
import * as from 'mppx/identity'
import { , } from 'mppx/server'
declare const : <string, { : string }>
const = .({
: () => .(..('X-Api-Key') ?? ''),
})
const = ..({
: 'https://api.example.com',
: 'https://identity.mpp.tempo.xyz',
})
const = .({ : [.()] })
export async function (: Request) {
const = await .({
: '0.05',
: [.(, )],
})()
if (. === 402) return .
const = .?.() ?? .?.()
return .(.())
}A plain list such as identity: [customer, email] requires both. See Combine verifiers.
Behavior
- Every member runs: in list order, even after one verifies, so each presented proof's replay nonce is consumed.
- At most once per request: a member also listed elsewhere in the route, or in another offer of a composed route, runs once.
- First valid member wins:
result.identity?.get(member)returns the winner's value, at any nesting depth. - All members reject: the status highest in
Identity.Status.precedencedecides the status and reason, and every member's headers are merged.
Grouped alternatives
Members' Identity-Attestation-Required values become one inner list of alternatives, so the client obtains one attestation, not all of them. A route accepting email from two issuers responds with:
Identity-Attestation-Required: (email;issuer="https://a.example" email;issuer="https://b.example")The client's attestation prover meets the group with the first alternative that succeeds, in listed order. If a member requires several attestations at once, the values are sent as they are, so the client asks for more than the route needs, never less. See Use attestations.
Return type
type ReturnType = Identity.Verifier<{
index: number // index of the first valid member
value: unknown // that member's value
}>Parameters
verifiers
- Type:
readonly [Identity.Verifier, Identity.Verifier, ...Identity.Verifier[]]
Two or more request verifiers, passed as arguments. A verifier with the removed stage: 'payment' throws a TypeError.