Skip to content
LogoLogo

Core Types

Challenge, Credential, and Receipt primitives

These types map directly to HTTP headers—WWW-Authenticate, Authorization, and Payment-Receipt—and can be used independently of the higher-level client and server APIs.

require "mpp-rb"

Parse a Challenge

Parse a WWW-Authenticate header into a typed Challenge:

challenge = Mpp::Challenge.from_www_authenticate(
  'Payment id="...", realm="...", method="tempo", intent="charge", request="eyJ..."'
)
 
challenge.method  # => "tempo"
challenge.intent  # => "charge"

Create and serialize a Credential

Build a Credential and serialize it to an Authorization header:

credential = Mpp::Credential.new(
  id: "challenge-id",
  payload: { "type" => "transaction", "signature" => "0x..." },
  source: "did:pkh:eip155:42431:0xa726a1...",
)
 
header = credential.to_authorization
# header = "Payment eyJ..."

Parse and serialize a Receipt

Parse the Payment-Receipt response header:

receipt = Mpp::Receipt.from_payment_receipt(header_value)
header = receipt.to_payment_receipt

Type reference

TypeDescription
Mpp::ChallengeServer Challenge parsed from WWW-Authenticate
Mpp::ChallengeEchoEchoed Challenge fields in a Credential
Mpp::CredentialClient Credential for the Authorization header
Mpp::ReceiptServer Receipt parsed from Payment-Receipt