1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Payment protocol implementations for Web Payment Auth (IETF draft-ietf-httpauth-payment).
//!
//! This module provides a layered architecture for the Web Payment Auth protocol:
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ Application Layer │
//! └────────────────────────────┬────────────────────────────────────┘
//! │
//! ┌────────────────────────────▼────────────────────────────────────┐
//! │ Methods Layer (feature-gated) │
//! │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
//! │ │ tempo │ │ base │ │ evm │ │ stripe │ │
//! │ │(42431) │ │(84532) │ │(shared) │ │(no evm) │ │
//! │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
//! └────────────────────────────┬────────────────────────────────────┘
//! │
//! ┌────────────────────────────▼────────────────────────────────────┐
//! │ Intents Layer (always available) │
//! │ ChargeRequest (string fields - no blockchain types) │
//! └────────────────────────────┬────────────────────────────────────┘
//! │
//! ┌────────────────────────────▼────────────────────────────────────┐
//! │ Core Layer (always available) │
//! │ PaymentChallenge, PaymentCredential, Receipt │
//! │ MethodName, IntentName, Base64UrlJson (newtypes) │
//! │ Header parsing/formatting (no regex) │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Module Structure
//!
//! - [`core`]: Core protocol types with zero heavy dependencies (always available)
//! - [`intents`]: Intent-specific request types (always available)
//! - [`methods`]: Method-specific implementations (feature-gated)
//!
//! # Examples
//!
//! ## Parse a challenge (core layer only)
//!
//! ```
//! use mpp_br::protocol::core::*;
//! use mpp_br::protocol::intents::ChargeRequest;
//!
//! let header = r#"Payment id="abc", realm="api", method="tempo", intent="charge", request="eyJhbW91bnQiOiIxMDAwIiwiY3VycmVuY3kiOiJVU0QifQ""#;
//! let challenge = parse_www_authenticate(header).unwrap();
//! if challenge.intent.is_charge() {
//! let req: ChargeRequest = challenge.request.decode().unwrap();
//! println!("Amount: {}", req.amount);
//! }
//! ```
//!
//! ## EVM-specific accessors (with "evm" feature)
//!
//! use mpp_br::protocol::core::parse_www_authenticate;
//! use mpp_br::protocol::intents::ChargeRequest;
//! use mpp_br::protocol::methods::tempo::TempoChargeExt;
//! use mpp_br::evm::U256;
//!
//! let header = r#"Payment id="abc", realm="api", method="tempo", intent="charge", request="eyJhbW91bnQiOiIxMDAwIiwiY3VycmVuY3kiOiIweDEyMyIsInJlY2lwaWVudCI6IjB4NDU2In0""#;
//! let challenge = parse_www_authenticate(header).unwrap();
//! let req: ChargeRequest = challenge.request.decode().unwrap();
//! let amount: U256 = req.amount_u256().unwrap();
//! ```
//!
//! ## Tempo-specific accessors (with "tempo" feature)
//!
//! use mpp_br::protocol::core::parse_www_authenticate;
//! use mpp_br::protocol::intents::ChargeRequest;
//! use mpp_br::protocol::methods::tempo::TempoChargeExt;
//!
//! let header = r#"Payment id="abc", realm="api", method="tempo", intent="charge", request="eyJhbW91bnQiOiIxMDAwIiwiY3VycmVuY3kiOiJVU0QifQ""#;
//! let challenge = parse_www_authenticate(header).unwrap();
//! let req: ChargeRequest = challenge.request.decode().unwrap();
//! assert!(!req.fee_payer());
//! ```