Skip to content
LogoLogo

Identity.from

Verify your own identities

Creates a verifier from your identity lookup. It runs before issuing a payment Challenge or accepting a payment Credential, so identity failures stop payment processing.

Return an authenticated value to continue; undefined or null rejects the request with 401. The optional challenge headers accompany identity rejections, not the payment 402.

Usage

import * as  from 'mppx/identity'
import { ,  } from 'mppx/server'
 
declare const : <string, { : string }>
 
const  = .({
  : { 'WWW-Authenticate': 'ApiKey' },
  () {
    const  = ..('X-Api-Key')
    if (!) return 
    const  = .()
    if (!) throw new .('Unknown API key.', { : 403 })
    return 
  },
})
const  = .({ : [.()] })
 
export async function (: Request) {
  const  = await .({ : '0.05', : [] })()
  if (. === 402) return .
  return .(.(.?.()))
}

The verifier runs before the server issues a payment Challenge or settles a Credential. It doesn't authenticate a returned value for you—validate the API key, session, or provider response inside verify.

Return type

Identity.Verifier<value> with stage: 'request'. Read the returned identity with result.identity?.get(verifier) after a successful payment result.

Lookup outcomeVerifier outcomeHTTP response
Identity valuevalidContinue to payment
undefined or nullmissing401, with challenge headers
Identity.RejectioninvalidRejection's code and message, with challenge headers
Any other thrown errorPropagatesHandle as an application error

Other values, including false and 0, count as identities. Return undefined or null to signal no identity.

Parameters

challenge (optional)

  • Type: HeadersInit

Headers sent for missing and rejected identities. No headers by default. This is a static header set, not a payment-stage challenge hook.

verify

  • Type: (request: Request) => value | null | undefined | Promise<value | null | undefined>

Look up and authenticate the caller. Throw Identity.Rejection for a known rejection; let operational errors propagate.

Accept alternative identities

Use identity: [Identity.anyOf(email, customer)] to accept either an email verifier or your lookup. Every member runs; the first valid member in list order wins. If none succeeds, a presented but invalid identity takes precedence over a missing identity. The results lookup includes the winning member, so result.identity?.get(customer) works when it wins. A plain list such as identity: [email, customer] requires both.