> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://mpp.dev/api/mcp` to find what you need.

# 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.

```go
import "github.com/tempoxyz/mpp-go/pkg/mpp"
```

## Parse a Challenge

Parse a `WWW-Authenticate` header into a typed `Challenge`:

```go
challenge, err := mpp.ParseChallenge(
	`Payment id="...", realm="...", method="tempo", intent="charge", request="eyJ..."`,
)
if err != nil {
	log.Fatal(err)
}

fmt.Println("Method:", challenge.Method)
fmt.Println("Intent:", challenge.Intent)
```

On the wire, `request` and optional `opaque` are base64url-encoded JSON strings in the `WWW-Authenticate` header. `ParseChallenge` decodes them into structured fields for application code.

## Create and serialize a Credential

Build a `Credential` from a Challenge echo and payment proof:

```go
credential := &mpp.Credential{
	Challenge: challenge.ToEcho(),
	Payload: map[string]any{
		"type":      "transaction",
		"signature": "0x...",
	},
	Source: "did:pkh:eip155:4217:0xa726a1...",
}

header := credential.ToAuthorization()
// header = "Payment eyJ..."
```

`challenge.ToEcho()` preserves the original wire values. In the serialized Credential, `challenge.request` and `challenge.opaque` remain base64url strings inside the `Authorization` payload.

## Parse and serialize a Receipt

Parse the `Payment-Receipt` response header:

```go
receipt, err := mpp.ParseReceipt(headerValue)
if err != nil {
	log.Fatal(err)
}

fmt.Println("Status:", receipt.Status)
fmt.Println("Reference:", receipt.Reference)
```

Serialize a Receipt back to a header value:

```go
header := receipt.ToPaymentReceipt()
```

## Type reference

| Type | Description |
|------|-------------|
| `Challenge` | Server Challenge parsed from `WWW-Authenticate` |
| `ChallengeEcho` | Echoed Challenge fields in a Credential |
| `Credential` | Client Credential for the `Authorization` header |
| `Receipt` | Server Receipt parsed from `Payment-Receipt` |
