@peac/mappings-paymentauth 0.12.5 → 0.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +102 -20
  2. package/package.json +18 -5
package/README.md CHANGED
@@ -1,31 +1,113 @@
1
1
  # @peac/mappings-paymentauth
2
2
 
3
- HTTP Payment authentication scheme (paymentauth/MPP) mapping for PEAC.
3
+ HTTP Payment authentication scheme mapping for PEAC: envelope-first parsing of paymentauth challenges, credentials, and receipts into normalized types and PEAC evidence.
4
4
 
5
- Envelope-first parsing of paymentauth wire artifacts with raw + normalized types. Method-specific payloads are treated as `unknown` because each payment method (card, lightning, stripe, tempo) has its own specification.
5
+ ## Installation
6
6
 
7
- ## Status
7
+ ```bash
8
+ pnpm add @peac/mappings-paymentauth
9
+ ```
8
10
 
9
- Experimental. The paymentauth core spec (`draft-ryan-httpauth-payment-01`) is an active individual draft (not standards-track). Discovery and JSON-RPC/MCP transport drafts are at draft-00.
11
+ ## What It Does
10
12
 
11
- ## Features
13
+ `@peac/mappings-paymentauth` parses and normalizes HTTP Payment authentication scheme headers (aligned with `draft-ryan-httpauth-payment-01`) into structured types, then maps them to PEAC evidence in the Interaction Record format. It handles `WWW-Authenticate`, `Authorization`, and `Payment-Receipt` headers with envelope-first parsing: method-specific payloads are treated as `unknown` and preserved as raw bytes alongside normalized fields. No network I/O.
12
14
 
13
- - Parse `WWW-Authenticate: Payment` challenges (first challenge; separate header lines recommended for multiple challenges)
14
- - Parse `Authorization: Payment` credentials (base64url-encoded JSON)
15
- - Parse `Payment-Receipt` headers (base64url-encoded JSON)
16
- - Normalize to stable PEAC-facing types with `_raw` back-references
17
- - OpenAPI discovery extraction (`x-service-info`, `x-payment-info`)
18
- - JSON-RPC error detection (`-32042`, `-32043`)
19
- - MCP `_meta` key extraction (`org.paymentauth/credential`, `org.paymentauth/receipt`)
20
- - MCP capability advertisement typing (`experimental.payment`)
15
+ ## How Do I Use It?
21
16
 
22
- ## Security
17
+ ### Parse and normalize a payment challenge
23
18
 
24
- - Raw `Authorization: Payment` and `Payment-Receipt` values never appear in thrown errors
25
- - Parser limits enforced: header size, param count, payload size, JSON depth
26
- - Decoded bytes preserved alongside strings for non-UTF-8 safety
27
- - `redactPaymentauthHeader()` helper for safe logging
19
+ ```typescript
20
+ import { parsePaymentauthChallenges, normalizeChallenge } from '@peac/mappings-paymentauth';
28
21
 
29
- ## No Network I/O
22
+ const rawChallenges = parsePaymentauthChallenges(
23
+ 'Payment method="stripe", realm="api", request="eyJ..."'
24
+ );
30
25
 
31
- This package contains zero network calls. All functions are pure parsers and normalizers.
26
+ const normalized = normalizeChallenge(rawChallenges[0]);
27
+ console.log(normalized.method); // 'stripe'
28
+ console.log(normalized.realm); // 'api'
29
+ console.log(normalized.intent); // decoded from request parameter
30
+ ```
31
+
32
+ ### Map a paymentauth receipt to PEAC evidence
33
+
34
+ ```typescript
35
+ import {
36
+ parsePaymentauthReceipt,
37
+ normalizeReceipt,
38
+ fromPaymentauthReceipt,
39
+ toCommerceExtensionFields,
40
+ } from '@peac/mappings-paymentauth';
41
+
42
+ const raw = parsePaymentauthReceipt(headerValue);
43
+ const receipt = normalizeReceipt(raw);
44
+
45
+ // Map to PEAC PaymentEvidence
46
+ const evidence = fromPaymentauthReceipt(receipt);
47
+ console.log(evidence.rail); // 'paymentauth'
48
+ console.log(evidence.reference); // upstream reference
49
+
50
+ // Extract commerce extension fields (partial, only from upstream data)
51
+ const commerce = toCommerceExtensionFields(receipt);
52
+ ```
53
+
54
+ ### Extract evidence from HTTP response headers
55
+
56
+ ```typescript
57
+ import {
58
+ extractCarrierFromPaymentauthHeaders,
59
+ PaymentauthCarrierAdapter,
60
+ } from '@peac/mappings-paymentauth';
61
+
62
+ // Direct extraction
63
+ const result = extractCarrierFromPaymentauthHeaders(responseHeaders);
64
+ if (result) {
65
+ console.log(result.receiptJws);
66
+ console.log(result.receiptRef);
67
+ }
68
+
69
+ // Or use the CarrierAdapter for transport-agnostic integration
70
+ const adapter = new PaymentauthCarrierAdapter();
71
+ ```
72
+
73
+ ### JSON-RPC and MCP transport helpers
74
+
75
+ ```typescript
76
+ import {
77
+ isPaymentRequiredError,
78
+ parsePaymentauthFromJsonRpcError,
79
+ extractCredentialFromMcpMeta,
80
+ extractReceiptFromMcpMeta,
81
+ } from '@peac/mappings-paymentauth';
82
+
83
+ // Check if a JSON-RPC error is a payment-required response
84
+ if (isPaymentRequiredError(error)) {
85
+ const challenges = parsePaymentauthFromJsonRpcError(error);
86
+ // present payment challenge to user/agent
87
+ }
88
+
89
+ // Extract paymentauth artifacts from MCP tool _meta
90
+ const credential = extractCredentialFromMcpMeta(meta);
91
+ const receipt = extractReceiptFromMcpMeta(meta);
92
+ ```
93
+
94
+ ## Integrates With
95
+
96
+ - `@peac/kernel` (Layer 0): Core types and constants
97
+ - `@peac/schema` (Layer 1): Zod validators and commerce extension schemas
98
+ - `@peac/protocol` (Layer 3): Receipt issuance using mapped evidence
99
+ - `@peac/mcp-server` (Layer 5): MCP tool server with payment-required flow
100
+
101
+ ## For Agent Developers
102
+
103
+ If you are building an AI agent that interacts with paymentauth-enabled services: use `parsePaymentauthChallenges` to decode `WWW-Authenticate: Payment` headers, `fromPaymentauthReceipt` to produce PEAC evidence from upstream receipts, and `PaymentauthCarrierAdapter` to carry evidence across HTTP boundaries. The JSON-RPC and MCP helpers handle transport-specific encoding for agent-to-agent and MCP tool call flows. All parsing is offline with no network I/O.
104
+
105
+ ## License
106
+
107
+ Apache-2.0
108
+
109
+ ---
110
+
111
+ PEAC Protocol is an open source project stewarded by Originary and community contributors.
112
+
113
+ [Docs](https://www.peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac) | [Originary](https://www.originary.xyz)
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@peac/mappings-paymentauth",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "description": "HTTP Payment authentication scheme (paymentauth/MPP) mapping for PEAC",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/peacprotocol/peac.git",
9
+ "url": "git+https://github.com/peacprotocol/peac.git",
10
10
  "directory": "packages/mappings/paymentauth"
11
11
  },
12
- "author": "jithinraj <7850727+jithinraj@users.noreply.github.com>",
12
+ "author": "PEAC Protocol Contributors",
13
13
  "license": "Apache-2.0",
14
14
  "bugs": {
15
15
  "url": "https://github.com/peacprotocol/peac/issues"
@@ -23,14 +23,27 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@peac/kernel": "0.12.5",
27
- "@peac/schema": "0.12.5"
26
+ "@peac/schema": "0.12.7",
27
+ "@peac/kernel": "0.12.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^22.19.11",
31
31
  "typescript": "^5.3.3",
32
32
  "vitest": "^4.0.0"
33
33
  },
34
+ "keywords": [
35
+ "peac",
36
+ "peacprotocol",
37
+ "interaction-records",
38
+ "signed-records",
39
+ "receipts",
40
+ "originary",
41
+ "paymentauth",
42
+ "http-payment",
43
+ "authentication",
44
+ "internet-draft",
45
+ "402-payment"
46
+ ],
34
47
  "scripts": {
35
48
  "build": "tsc",
36
49
  "test": "vitest run",