@redcenterstudio/agent-tollbooth-edge 1.1.0 → 1.2.1

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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Zero-dependency dual-rail HTTP 402 middleware for Cloudflare Workers, Fetch APIs, Next.js, and Hono.
4
4
  *
5
5
  * Rail A: Open x402 V2 standard (`PAYMENT-REQUIRED`, `PAYMENT-SIGNATURE`, `PAYMENT-RESPONSE`)
6
- * Rail B: Red Center Fiat Agent Wallet (`rcs_receipt_...` verified <1ms via Web Crypto + NonceStore)
6
+ * Rail B: prepaid Red Center agent wallet receipts (`rcs_receipt_...`, Web Crypto + NonceStore), Red Center Studio routes only
7
7
  */
8
8
  export const DEFAULT_FACILITATOR_URL = 'https://tollbooth.redcenterstudio.com';
9
9
  export const DEFAULT_PAYMENT_URL = 'https://tollbooth.redcenterstudio.com';
@@ -441,7 +441,7 @@ function resolveErrorGuidance(errorReason, requiredMicros, expectedAudience) {
441
441
  case 'insufficient_payment_amount':
442
442
  return {
443
443
  code: 'INSUFFICIENT_FUNDS',
444
- fix_hint: `Payment amount is below the required ${priceStr}. Top up your agent wallet or authorize at least ${requiredMicros} atomic units.`,
444
+ fix_hint: `Payment amount is below the required ${priceStr}. Authorize at least ${requiredMicros} atomic units.`,
445
445
  };
446
446
  case 'RECEIPT_EXPIRED':
447
447
  case 'receipt_expired':
@@ -507,376 +507,376 @@ export function renderDefault402HtmlPage(challenge, request) {
507
507
  const payTo = accept?.payTo ?? DEFAULT_PAY_TO;
508
508
  const network = accept?.network ?? DEFAULT_NETWORK;
509
509
  const scheme = accept?.scheme ?? 'exact';
510
- const railsText = challenge.acceptedRails.includes('rcs-fiat-wallet')
511
- ? 'x402 V2 (USDC) + Red Center Fiat Wallet'
512
- : 'x402 V2 (USDC)';
513
- const safeCurl = `curl -H "PAYMENT-SIGNATURE: <base64_x402_v2>" "${request.url}"\ncurl -H "Authorization: Bearer rcs_receipt_..." "${request.url}"\n# payTo: ${payTo}`;
514
- return `<!DOCTYPE html>
515
- <html lang="en">
516
- <head>
517
- <meta charset="utf-8" />
518
- <meta name="viewport" content="width=device-width, initial-scale=1" />
519
- <meta name="theme-color" content="#24181a" />
520
- <title>402 Payment Required — Agent Tollbooth 402 | Red Center Studio</title>
521
- <link rel="preconnect" href="https://fonts.googleapis.com" />
522
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
523
- <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Archivo:wght@700;800&family=IBM+Plex+Mono:wght@500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" />
524
- <style>
525
- :root {
526
- --ironstone: #24181a;
527
- --ironstone-2: #32211f;
528
- --ochre: #d9622b;
529
- --ochre-deep: #a63d14;
530
- --oxide: #7a2e1d;
531
- --spinifex: #e3a23c;
532
- --gum: #4f7f63;
533
- --sand: #f5efe6;
534
- --card: #fffcf8;
535
- --line: #e3d7c8;
536
- --ink: #2a1a16;
537
- --muted: #6b5a52;
538
- --on-dark: #f3e9de;
539
- --on-dark-muted: #cbb9ab;
540
- --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
541
- --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
542
- --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
543
- }
544
- * { box-sizing: border-box; }
545
- html { -webkit-text-size-adjust: 100%; }
546
- body {
547
- margin: 0;
548
- min-height: 100vh;
549
- display: flex;
550
- flex-direction: column;
551
- background: var(--sand);
552
- color: var(--ink);
553
- font: 400 16px/1.6 var(--body);
554
- }
555
- a { color: var(--ochre-deep); }
556
- .site-head { background: var(--ironstone); color: var(--on-dark); }
557
- .head-wrap {
558
- max-width: 760px;
559
- margin: 0 auto;
560
- padding: 14px 20px;
561
- display: flex;
562
- align-items: center;
563
- justify-content: space-between;
564
- gap: 14px;
565
- flex-wrap: wrap;
566
- }
567
- .brand {
568
- display: inline-flex;
569
- align-items: center;
570
- gap: 10px;
571
- font: 500 12px/1 var(--mono);
572
- letter-spacing: 0.16em;
573
- text-transform: uppercase;
574
- color: var(--on-dark);
575
- text-decoration: none;
576
- }
577
- .brand::before {
578
- content: "";
579
- width: 22px;
580
- height: 22px;
581
- flex: none;
582
- background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3CclipPath id='s'%3E%3Ccircle cx='11' cy='11' r='11'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23s)'%3E%3Crect width='22' height='12.5' fill='%23d9622b'/%3E%3Crect y='14.5' width='22' height='2.5' fill='%23d9622b'/%3E%3Crect y='19' width='22' height='2.5' fill='%23a63d14'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
583
- }
584
- .head-link {
585
- font: 600 14px/1 var(--body);
586
- color: var(--spinifex);
587
- text-decoration: none;
588
- }
589
- .head-link:hover { text-decoration: underline; }
590
- .strata {
591
- display: block;
592
- height: 8px;
593
- background: linear-gradient(to bottom, var(--oxide) 0 25%, var(--ochre-deep) 25% 50%, var(--ochre) 50% 75%, var(--spinifex) 75% 100%);
594
- }
595
- .stage {
596
- flex: 1;
597
- display: flex;
598
- align-items: center;
599
- justify-content: center;
600
- padding: 18px 20px 24px;
601
- }
602
- @keyframes cardRise {
603
- from { opacity: 0; transform: translateY(10px); }
604
- to { opacity: 1; transform: translateY(0); }
605
- }
606
- @keyframes softPulse {
607
- 0%, 100% { box-shadow: 0 0 0 0 rgba(79, 127, 99, 0.35); }
608
- 50% { box-shadow: 0 0 0 5px rgba(79, 127, 99, 0); }
609
- }
610
- .card {
611
- width: 100%;
612
- max-width: 650px;
613
- background: var(--card);
614
- border: 1px solid var(--line);
615
- border-top: 3px solid var(--ochre);
616
- border-radius: 2px;
617
- padding: 20px 24px;
618
- box-shadow: 0 14px 36px rgba(36, 24, 26, 0.11);
619
- animation: cardRise 0.35s ease-out both;
620
- }
621
- .badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
622
- .badge {
623
- display: inline-flex;
624
- align-items: center;
625
- gap: 6px;
626
- padding: 4px 9px;
627
- border: 1px solid;
628
- border-radius: 2px;
629
- font: 500 11.5px/1.2 var(--mono);
630
- letter-spacing: 0.1em;
631
- text-transform: uppercase;
632
- }
633
- .badge-ochre { background: #fbeee4; color: var(--ochre-deep); border-color: var(--ochre-deep); }
634
- .badge-gum { background: #eaf2ec; color: #2f5a41; border-color: var(--gum); }
635
- .dot {
636
- width: 6px;
637
- height: 6px;
638
- border-radius: 50%;
639
- background: var(--gum);
640
- display: inline-block;
641
- animation: softPulse 2.2s ease-in-out infinite;
642
- }
643
- h1 {
644
- margin: 0 0 4px;
645
- font: 800 clamp(24px, 3.8vw, 31px)/1.08 var(--display);
646
- letter-spacing: -0.02em;
647
- color: var(--ink);
648
- }
649
- .desc { margin: 0 0 12px; color: var(--muted); font-size: 15px; line-height: 1.45; }
650
- .facts {
651
- display: grid;
652
- grid-template-columns: repeat(2, minmax(0, 1fr));
653
- gap: 8px 18px;
654
- margin-bottom: 11px;
655
- padding: 11px 14px;
656
- background: var(--sand);
657
- border: 1px solid var(--line);
658
- border-radius: 2px;
659
- }
660
- .fact-wide { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid var(--line); }
661
- .label {
662
- font: 500 11.5px/1.4 var(--mono);
663
- letter-spacing: 0.14em;
664
- text-transform: uppercase;
665
- color: var(--ochre-deep);
666
- }
667
- .val {
668
- font-size: 14.5px;
669
- font-weight: 600;
670
- color: var(--ink);
671
- overflow-wrap: anywhere;
672
- margin-top: 2px;
673
- font-variant-numeric: tabular-nums;
674
- }
675
- .price {
676
- font: 800 24px/1.1 var(--display);
677
- letter-spacing: -0.02em;
678
- color: var(--ink);
679
- font-variant-numeric: tabular-nums;
680
- }
681
- .hint {
682
- background: #fbeee4;
683
- border-left: 3px solid var(--ochre);
684
- padding: 9px 13px;
685
- border-radius: 2px;
686
- font-size: 13.5px;
687
- line-height: 1.45;
688
- color: var(--ink);
689
- margin-bottom: 11px;
690
- overflow-wrap: anywhere;
691
- }
692
- .rails {
693
- display: grid;
694
- grid-template-columns: repeat(2, minmax(0, 1fr));
695
- gap: 10px;
696
- margin-bottom: 11px;
697
- }
698
- .rail-box {
699
- padding: 11px 13px;
700
- background: #fff;
701
- border: 1px solid var(--line);
702
- border-left: 3px solid var(--spinifex);
703
- border-radius: 2px;
704
- transition: transform 0.15s ease, border-color 0.15s ease;
705
- }
706
- .rail-box:hover {
707
- transform: translateY(-1px);
708
- border-color: #d6c4b0;
709
- border-left-color: var(--ochre);
710
- }
711
- .rail-box h2 {
712
- margin: 0 0 3px;
713
- font: 700 14.5px/1.25 var(--body);
714
- color: var(--ink);
715
- }
716
- .rail-box p {
717
- margin: 0;
718
- font-size: 13px;
719
- line-height: 1.4;
720
- color: var(--muted);
721
- overflow-wrap: anywhere;
722
- }
723
- .code-shell {
724
- border: 1px solid #3c2a27;
725
- border-radius: 2px;
726
- overflow: hidden;
727
- margin-bottom: 13px;
728
- background: var(--ironstone);
729
- }
730
- .code-bar {
731
- display: flex;
732
- align-items: center;
733
- justify-content: space-between;
734
- gap: 10px;
735
- padding: 7px 12px;
736
- background: #1a1112;
737
- border-bottom: 1px solid rgba(243, 233, 222, 0.12);
738
- }
739
- .code-title {
740
- display: inline-flex;
741
- align-items: center;
742
- gap: 8px;
743
- font: 500 11px/1 var(--mono);
744
- letter-spacing: 0.12em;
745
- text-transform: uppercase;
746
- color: var(--on-dark-muted);
747
- }
748
- .term-dots { display: inline-flex; gap: 5px; }
749
- .term-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(243, 233, 222, 0.3); display: inline-block; }
750
- .term-dots i:first-child { background: var(--ochre); }
751
- .term-dots i:nth-child(2) { background: var(--spinifex); }
752
- .code {
753
- background: var(--ironstone);
754
- color: var(--on-dark);
755
- padding: 11px 13px;
756
- font: 500 12px/1.45 var(--mono);
757
- white-space: pre-wrap;
758
- overflow-wrap: anywhere;
759
- margin: 0;
760
- }
761
- .copy-btn {
762
- min-height: 26px;
763
- padding: 3px 11px;
764
- background: var(--card);
765
- color: var(--ink);
766
- border: 1px solid var(--line);
767
- border-radius: 2px;
768
- font: 600 12px/1 var(--body);
769
- cursor: pointer;
770
- }
771
- .copy-btn:hover { background: var(--spinifex); border-color: var(--spinifex); }
772
- .sim-banner {
773
- display: none;
774
- margin-bottom: 12px;
775
- padding: 10px 13px;
776
- background: #eaf2ec;
777
- border: 1px solid #b8d3c1;
778
- border-left: 3px solid var(--gum);
779
- border-radius: 2px;
780
- font: 500 12.5px/1.45 var(--mono);
781
- color: #214530;
782
- overflow-wrap: anywhere;
783
- animation: cardRise 0.25s ease-out both;
784
- }
785
- .sim-banner.show { display: block; }
786
- .actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
787
- .btn {
788
- display: inline-flex;
789
- align-items: center;
790
- justify-content: center;
791
- text-align: center;
792
- min-height: 44px;
793
- padding: 9px 18px;
794
- border: 1px solid transparent;
795
- border-radius: 2px;
796
- font: 600 14.5px/1.2 var(--body);
797
- text-decoration: none;
798
- cursor: pointer;
799
- transition: background 0.15s, color 0.15s, border-color 0.15s;
800
- }
801
- .btn-primary { background: var(--ochre); color: #1e1412; }
802
- .btn-primary:hover { background: var(--spinifex); }
803
- .btn-ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
804
- .btn-ghost:hover { background: var(--ink); color: var(--sand); }
805
- .btn-sand { background: var(--sand); color: var(--ink); border-color: #b9a898; }
806
- .btn-sand:hover { border-color: var(--ochre-deep); background: #fbeee4; }
807
- .meta-foot {
808
- margin-top: 11px;
809
- font: 400 12.5px/1.4 var(--body);
810
- color: var(--muted);
811
- }
812
- @media (prefers-reduced-motion: reduce) { .card, .dot, .sim-banner { animation: none; } }
813
- @media (max-width: 640px) {
814
- .stage { padding: 18px 14px 32px; align-items: flex-start; }
815
- .card { padding: 18px 16px; }
816
- .facts, .rails { grid-template-columns: 1fr; gap: 10px; }
817
- .actions { flex-direction: column; align-items: stretch; }
818
- .btn { width: 100%; min-height: 48px; }
819
- }
820
- </style>
821
- </head>
822
- <body>
823
- <header class="site-head">
824
- <div class="head-wrap">
825
- <a class="brand" href="https://redcenterstudio.com/" rel="noopener noreferrer">Red Center Studio</a>
826
- <a class="head-link" href="${escapeHtml(challenge.paymentUrl)}" rel="noopener noreferrer">Clearinghouse Portal</a>
827
- </div>
828
- <span class="strata" aria-hidden="true"></span>
829
- </header>
830
- <main class="stage">
831
- <article class="card">
832
- <div class="badges">
833
- <span class="badge badge-ochre">HTTP 402 &middot; ${escapeHtml(challenge.code)}</span>
834
- <span class="badge badge-gum"><span class="dot"></span>${escapeHtml(railsText)}</span>
835
- </div>
836
- <h1>402 Payment Required</h1>
837
- <p class="desc">${escapeHtml(challenge.resource.description)}</p>
838
- <div class="facts">
839
- <div>
840
- <div class="label">Endpoint</div>
841
- <div class="val">${escapeHtml(request.method.toUpperCase())} ${escapeHtml(url.pathname)}</div>
842
- </div>
843
- <div>
844
- <div class="label">Price (${escapeHtml(scheme)})</div>
845
- <div class="val price">$${escapeHtml(challenge.priceUsd)} USD</div>
846
- </div>
847
- <div class="fact-wide">
848
- <div class="label">x402 Settlement Destination</div>
849
- <div class="val">${escapeHtml(network)} &middot; ${escapeHtml(amountAtomic)} USDC &middot; payTo <code>${escapeHtml(payTo)}</code></div>
850
- </div>
851
- </div>
852
- <div class="rails">
853
- <div class="rail-box">
854
- <h2>Pay with Fiat Agent Wallet</h2>
855
- <p>Top up with Stripe on Red Center Studio and pass a prepaid <code>rcs_receipt_...</code> bearer token for &lt;1ms edge verification.</p>
856
- </div>
857
- <div class="rail-box">
858
- <h2>Pay with Crypto (x402 V2)</h2>
859
- <p>Sign a Base USDC payment payload on <code>${escapeHtml(network)}</code> to <code>${escapeHtml(payTo)}</code> and retry with <code>PAYMENT-SIGNATURE</code>.</p>
860
- </div>
861
- </div>
862
- <div class="hint"><strong>Next step:</strong> ${escapeHtml(challenge.fix_hint)}</div>
863
- <div class="code-shell">
864
- <div class="code-bar">
865
- <span class="code-title"><span class="term-dots"><i></i><i></i><i></i></span>HTTP 402 Retry Snippet &middot; x402 V2 &amp; Bearer Receipt</span>
866
- <button class="copy-btn" type="button" onclick="var b=this;navigator.clipboard&&navigator.clipboard.writeText(document.getElementById('curl-cmd').textContent).then(function(){b.textContent='Copied';b.style.borderColor='#4f7f63';b.style.color='#2f5a41';setTimeout(function(){b.textContent='Copy';b.style.borderColor='';b.style.color='';},1500);})">Copy</button>
867
- </div>
868
- <pre class="code" id="curl-cmd">${escapeHtml(safeCurl)}</pre>
869
- </div>
870
- <div id="retry-status" class="sim-banner" role="status" aria-live="polite"></div>
871
- <div class="actions">
872
- <a class="btn btn-primary" href="${escapeHtml(challenge.paymentUrl)}" rel="noopener noreferrer">Fund Agent Wallet</a>
873
- <button id="sim-retry-btn" class="btn btn-sand" type="button" onclick="var b=this,s=document.getElementById('retry-status');b.disabled=true;b.textContent='Verifying...';s.className='sim-banner show';s.textContent='Signing sandbox rcs_receipt_... via Web Crypto HMAC-SHA256...';setTimeout(function(){b.disabled=false;b.textContent='Verified (200 OK)';s.textContent='[200 SETTLED] Edge HMAC check passed in 0.4ms | PAYMENT-RESPONSE verified | ${escapeHtml(request.method.toUpperCase())} ${escapeHtml(url.pathname)} unlocked ($${escapeHtml(challenge.priceUsd)} USD)';},320);">Simulate &lt;1ms Receipt Retry</button>
874
- <a class="btn btn-ghost" href="https://redcenterstudio.com/services/ai-tollbooth-setup/" rel="noopener noreferrer">See AI Tollbooth Setup</a>
875
- </div>
876
- <p class="meta-foot">Powered by Agent Tollbooth 402 &middot; <a href="https://redcenterstudio.com/" rel="noopener noreferrer">Red Center Studio</a></p>
877
- </article>
878
- </main>
879
- </body>
510
+ const hasFiat = challenge.acceptedRails.includes('rcs-fiat-wallet');
511
+ const railsText = hasFiat ? 'x402 V2 (USDC) + prepaid agent wallet' : 'x402 V2 (USDC)';
512
+ const fiatCurl = `curl -H "PAYMENT-SIGNATURE: <base64_x402_v2>" "${request.url}"\ncurl -H "Authorization: Bearer rcs_receipt_..." "${request.url}"\n# payTo: ${payTo}`;
513
+ const x402Curl = `curl -H "PAYMENT-SIGNATURE: <base64_x402_v2>" "${request.url}"\n# payTo: ${payTo}`;
514
+ const safeCurl = hasFiat ? fiatCurl : x402Curl;
515
+ return `<!DOCTYPE html>
516
+ <html lang="en">
517
+ <head>
518
+ <meta charset="utf-8" />
519
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
520
+ <meta name="theme-color" content="#24181a" />
521
+ <title>402 Payment Required: Agent Tollbooth 402 | Red Center Studio</title>
522
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
523
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
524
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Archivo:wght@700;800&family=IBM+Plex+Mono:wght@500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" />
525
+ <style>
526
+ :root {
527
+ --ironstone: #24181a;
528
+ --ironstone-2: #32211f;
529
+ --ochre: #d9622b;
530
+ --ochre-deep: #a63d14;
531
+ --oxide: #7a2e1d;
532
+ --spinifex: #e3a23c;
533
+ --gum: #4f7f63;
534
+ --sand: #f5efe6;
535
+ --card: #fffcf8;
536
+ --line: #e3d7c8;
537
+ --ink: #2a1a16;
538
+ --muted: #6b5a52;
539
+ --on-dark: #f3e9de;
540
+ --on-dark-muted: #cbb9ab;
541
+ --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
542
+ --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
543
+ --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
544
+ }
545
+ * { box-sizing: border-box; }
546
+ html { -webkit-text-size-adjust: 100%; }
547
+ body {
548
+ margin: 0;
549
+ min-height: 100vh;
550
+ display: flex;
551
+ flex-direction: column;
552
+ background: var(--sand);
553
+ color: var(--ink);
554
+ font: 400 16px/1.6 var(--body);
555
+ }
556
+ a { color: var(--ochre-deep); }
557
+ .site-head { background: var(--ironstone); color: var(--on-dark); }
558
+ .head-wrap {
559
+ max-width: 760px;
560
+ margin: 0 auto;
561
+ padding: 14px 20px;
562
+ display: flex;
563
+ align-items: center;
564
+ justify-content: space-between;
565
+ gap: 14px;
566
+ flex-wrap: wrap;
567
+ }
568
+ .brand {
569
+ display: inline-flex;
570
+ align-items: center;
571
+ gap: 10px;
572
+ font: 500 12px/1 var(--mono);
573
+ letter-spacing: 0.16em;
574
+ text-transform: uppercase;
575
+ color: var(--on-dark);
576
+ text-decoration: none;
577
+ }
578
+ .brand::before {
579
+ content: "";
580
+ width: 22px;
581
+ height: 22px;
582
+ flex: none;
583
+ background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3CclipPath id='s'%3E%3Ccircle cx='11' cy='11' r='11'/%3E%3C/clipPath%3E%3Cg clip-path='url(%23s)'%3E%3Crect width='22' height='12.5' fill='%23d9622b'/%3E%3Crect y='14.5' width='22' height='2.5' fill='%23d9622b'/%3E%3Crect y='19' width='22' height='2.5' fill='%23a63d14'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
584
+ }
585
+ .head-link {
586
+ font: 600 14px/1 var(--body);
587
+ color: var(--spinifex);
588
+ text-decoration: none;
589
+ }
590
+ .head-link:hover { text-decoration: underline; }
591
+ .strata {
592
+ display: block;
593
+ height: 8px;
594
+ background: linear-gradient(to bottom, var(--oxide) 0 25%, var(--ochre-deep) 25% 50%, var(--ochre) 50% 75%, var(--spinifex) 75% 100%);
595
+ }
596
+ .stage {
597
+ flex: 1;
598
+ display: flex;
599
+ align-items: center;
600
+ justify-content: center;
601
+ padding: 18px 20px 24px;
602
+ }
603
+ @keyframes cardRise {
604
+ from { opacity: 0; transform: translateY(10px); }
605
+ to { opacity: 1; transform: translateY(0); }
606
+ }
607
+ @keyframes softPulse {
608
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(79, 127, 99, 0.35); }
609
+ 50% { box-shadow: 0 0 0 5px rgba(79, 127, 99, 0); }
610
+ }
611
+ .card {
612
+ width: 100%;
613
+ max-width: 650px;
614
+ background: var(--card);
615
+ border: 1px solid var(--line);
616
+ border-top: 3px solid var(--ochre);
617
+ border-radius: 2px;
618
+ padding: 20px 24px;
619
+ box-shadow: 0 14px 36px rgba(36, 24, 26, 0.11);
620
+ animation: cardRise 0.35s ease-out both;
621
+ }
622
+ .badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
623
+ .badge {
624
+ display: inline-flex;
625
+ align-items: center;
626
+ gap: 6px;
627
+ padding: 4px 9px;
628
+ border: 1px solid;
629
+ border-radius: 2px;
630
+ font: 500 11.5px/1.2 var(--mono);
631
+ letter-spacing: 0.1em;
632
+ text-transform: uppercase;
633
+ }
634
+ .badge-ochre { background: #fbeee4; color: var(--ochre-deep); border-color: var(--ochre-deep); }
635
+ .badge-gum { background: #eaf2ec; color: #2f5a41; border-color: var(--gum); }
636
+ .dot {
637
+ width: 6px;
638
+ height: 6px;
639
+ border-radius: 50%;
640
+ background: var(--gum);
641
+ display: inline-block;
642
+ animation: softPulse 2.2s ease-in-out infinite;
643
+ }
644
+ h1 {
645
+ margin: 0 0 4px;
646
+ font: 800 clamp(24px, 3.8vw, 31px)/1.08 var(--display);
647
+ letter-spacing: -0.02em;
648
+ color: var(--ink);
649
+ }
650
+ .desc { margin: 0 0 12px; color: var(--muted); font-size: 15px; line-height: 1.45; }
651
+ .facts {
652
+ display: grid;
653
+ grid-template-columns: repeat(2, minmax(0, 1fr));
654
+ gap: 8px 18px;
655
+ margin-bottom: 11px;
656
+ padding: 11px 14px;
657
+ background: var(--sand);
658
+ border: 1px solid var(--line);
659
+ border-radius: 2px;
660
+ }
661
+ .fact-wide { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid var(--line); }
662
+ .label {
663
+ font: 500 11.5px/1.4 var(--mono);
664
+ letter-spacing: 0.14em;
665
+ text-transform: uppercase;
666
+ color: var(--ochre-deep);
667
+ }
668
+ .val {
669
+ font-size: 14.5px;
670
+ font-weight: 600;
671
+ color: var(--ink);
672
+ overflow-wrap: anywhere;
673
+ margin-top: 2px;
674
+ font-variant-numeric: tabular-nums;
675
+ }
676
+ .price {
677
+ font: 800 24px/1.1 var(--display);
678
+ letter-spacing: -0.02em;
679
+ color: var(--ink);
680
+ font-variant-numeric: tabular-nums;
681
+ }
682
+ .hint {
683
+ background: #fbeee4;
684
+ border-left: 3px solid var(--ochre);
685
+ padding: 9px 13px;
686
+ border-radius: 2px;
687
+ font-size: 13.5px;
688
+ line-height: 1.45;
689
+ color: var(--ink);
690
+ margin-bottom: 11px;
691
+ overflow-wrap: anywhere;
692
+ }
693
+ .rails {
694
+ display: grid;
695
+ grid-template-columns: repeat(2, minmax(0, 1fr));
696
+ gap: 10px;
697
+ margin-bottom: 11px;
698
+ }
699
+ .rails.one { grid-template-columns: 1fr; }
700
+ .rail-box {
701
+ padding: 11px 13px;
702
+ background: #fff;
703
+ border: 1px solid var(--line);
704
+ border-left: 3px solid var(--spinifex);
705
+ border-radius: 2px;
706
+ transition: transform 0.15s ease, border-color 0.15s ease;
707
+ }
708
+ .rail-box:hover {
709
+ transform: translateY(-1px);
710
+ border-color: #d6c4b0;
711
+ border-left-color: var(--ochre);
712
+ }
713
+ .rail-box h2 {
714
+ margin: 0 0 3px;
715
+ font: 700 14.5px/1.25 var(--body);
716
+ color: var(--ink);
717
+ }
718
+ .rail-box p {
719
+ margin: 0;
720
+ font-size: 13px;
721
+ line-height: 1.4;
722
+ color: var(--muted);
723
+ overflow-wrap: anywhere;
724
+ }
725
+ .code-shell {
726
+ border: 1px solid #3c2a27;
727
+ border-radius: 2px;
728
+ overflow: hidden;
729
+ margin-bottom: 13px;
730
+ background: var(--ironstone);
731
+ }
732
+ .code-bar {
733
+ display: flex;
734
+ align-items: center;
735
+ justify-content: space-between;
736
+ gap: 10px;
737
+ padding: 7px 12px;
738
+ background: #1a1112;
739
+ border-bottom: 1px solid rgba(243, 233, 222, 0.12);
740
+ }
741
+ .code-title {
742
+ display: inline-flex;
743
+ align-items: center;
744
+ gap: 8px;
745
+ font: 500 11px/1 var(--mono);
746
+ letter-spacing: 0.12em;
747
+ text-transform: uppercase;
748
+ color: var(--on-dark-muted);
749
+ }
750
+ .term-dots { display: inline-flex; gap: 5px; }
751
+ .term-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(243, 233, 222, 0.3); display: inline-block; }
752
+ .term-dots i:first-child { background: var(--ochre); }
753
+ .term-dots i:nth-child(2) { background: var(--spinifex); }
754
+ .code {
755
+ background: var(--ironstone);
756
+ color: var(--on-dark);
757
+ padding: 11px 13px;
758
+ font: 500 12px/1.45 var(--mono);
759
+ white-space: pre-wrap;
760
+ overflow-wrap: anywhere;
761
+ margin: 0;
762
+ }
763
+ .copy-btn {
764
+ min-height: 26px;
765
+ padding: 3px 11px;
766
+ background: var(--card);
767
+ color: var(--ink);
768
+ border: 1px solid var(--line);
769
+ border-radius: 2px;
770
+ font: 600 12px/1 var(--body);
771
+ cursor: pointer;
772
+ }
773
+ .copy-btn:hover { background: var(--spinifex); border-color: var(--spinifex); }
774
+ .sim-banner {
775
+ display: none;
776
+ margin-bottom: 12px;
777
+ padding: 10px 13px;
778
+ background: #eaf2ec;
779
+ border: 1px solid #b8d3c1;
780
+ border-left: 3px solid var(--gum);
781
+ border-radius: 2px;
782
+ font: 500 12.5px/1.45 var(--mono);
783
+ color: #214530;
784
+ overflow-wrap: anywhere;
785
+ animation: cardRise 0.25s ease-out both;
786
+ }
787
+ .sim-banner.show { display: block; }
788
+ .actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
789
+ .btn {
790
+ display: inline-flex;
791
+ align-items: center;
792
+ justify-content: center;
793
+ text-align: center;
794
+ min-height: 44px;
795
+ padding: 9px 18px;
796
+ border: 1px solid transparent;
797
+ border-radius: 2px;
798
+ font: 600 14.5px/1.2 var(--body);
799
+ text-decoration: none;
800
+ cursor: pointer;
801
+ transition: background 0.15s, color 0.15s, border-color 0.15s;
802
+ }
803
+ .btn-primary { background: var(--ochre); color: #1e1412; }
804
+ .btn-primary:hover { background: var(--spinifex); }
805
+ .btn-ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
806
+ .btn-ghost:hover { background: var(--ink); color: var(--sand); }
807
+ .btn-sand { background: var(--sand); color: var(--ink); border-color: #b9a898; }
808
+ .btn-sand:hover { border-color: var(--ochre-deep); background: #fbeee4; }
809
+ .meta-foot {
810
+ margin-top: 11px;
811
+ font: 400 12.5px/1.4 var(--body);
812
+ color: var(--muted);
813
+ }
814
+ @media (prefers-reduced-motion: reduce) { .card, .dot, .sim-banner { animation: none; } }
815
+ @media (max-width: 640px) {
816
+ .stage { padding: 18px 14px 32px; align-items: flex-start; }
817
+ .card { padding: 18px 16px; }
818
+ .facts, .rails { grid-template-columns: 1fr; gap: 10px; }
819
+ .actions { flex-direction: column; align-items: stretch; }
820
+ .btn { width: 100%; min-height: 48px; }
821
+ }
822
+ </style>
823
+ </head>
824
+ <body>
825
+ <header class="site-head">
826
+ <div class="head-wrap">
827
+ <a class="brand" href="https://redcenterstudio.com/" rel="noopener noreferrer">Red Center Studio</a>
828
+ <a class="head-link" href="${escapeHtml(challenge.paymentUrl)}" rel="noopener noreferrer">Agent Tollbooth 402</a>
829
+ </div>
830
+ <span class="strata" aria-hidden="true"></span>
831
+ </header>
832
+ <main class="stage">
833
+ <article class="card">
834
+ <div class="badges">
835
+ <span class="badge badge-ochre">HTTP 402 &middot; ${escapeHtml(challenge.code)}</span>
836
+ <span class="badge badge-gum"><span class="dot"></span>${escapeHtml(railsText)}</span>
837
+ </div>
838
+ <h1>402 Payment Required</h1>
839
+ <p class="desc">${escapeHtml(challenge.resource.description)}</p>
840
+ <div class="facts">
841
+ <div>
842
+ <div class="label">Endpoint</div>
843
+ <div class="val">${escapeHtml(request.method.toUpperCase())} ${escapeHtml(url.pathname)}</div>
844
+ </div>
845
+ <div>
846
+ <div class="label">Price (${escapeHtml(scheme)})</div>
847
+ <div class="val price">$${escapeHtml(challenge.priceUsd)} USD</div>
848
+ </div>
849
+ <div class="fact-wide">
850
+ <div class="label">x402 Settlement Destination</div>
851
+ <div class="val">${escapeHtml(network)} &middot; ${escapeHtml(amountAtomic)} USDC &middot; payTo <code>${escapeHtml(payTo)}</code></div>
852
+ </div>
853
+ </div>
854
+ <div class="rails${hasFiat ? '' : ' one'}">${hasFiat ? `
855
+ <div class="rail-box">
856
+ <h2>Pay with a prepaid agent wallet</h2>
857
+ <p>Pass a prepaid <code>rcs_receipt_...</code> bearer token issued by Red Center Studio for this route.</p>
858
+ </div>` : ''}
859
+ <div class="rail-box">
860
+ <h2>Pay with Crypto (x402 V2)</h2>
861
+ <p>Sign a Base USDC payment payload on <code>${escapeHtml(network)}</code> to <code>${escapeHtml(payTo)}</code> and retry with <code>PAYMENT-SIGNATURE</code>.</p>
862
+ </div>
863
+ </div>
864
+ <div class="hint"><strong>Next step:</strong> ${escapeHtml(challenge.fix_hint)}</div>
865
+ <div class="code-shell">
866
+ <div class="code-bar">
867
+ <span class="code-title"><span class="term-dots"><i></i><i></i><i></i></span>HTTP 402 Retry Snippet &middot; x402 V2${hasFiat ? ' &amp; Bearer Receipt' : ''}</span>
868
+ <button class="copy-btn" type="button" onclick="var b=this;navigator.clipboard&&navigator.clipboard.writeText(document.getElementById('curl-cmd').textContent).then(function(){b.textContent='Copied';b.style.borderColor='#4f7f63';b.style.color='#2f5a41';setTimeout(function(){b.textContent='Copy';b.style.borderColor='';b.style.color='';},1500);})">Copy</button>
869
+ </div>
870
+ <pre class="code" id="curl-cmd">${escapeHtml(safeCurl)}</pre>
871
+ </div>
872
+ <div class="actions">
873
+ <a class="btn btn-primary" href="${escapeHtml(challenge.paymentUrl)}" rel="noopener noreferrer">How AI agents pay</a>
874
+ <a class="btn btn-ghost" href="https://redcenterstudio.com/services/ai-tollbooth-setup/" rel="noopener noreferrer">See AI Tollbooth Setup</a>
875
+ </div>
876
+ <p class="meta-foot">Powered by Agent Tollbooth 402 &middot; <a href="https://redcenterstudio.com/" rel="noopener noreferrer">Red Center Studio</a></p>
877
+ </article>
878
+ </main>
879
+ </body>
880
880
  </html>`;
881
881
  }
882
882
  function matchPathPattern(pattern, pathname) {