Lines 1-40javascript
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getResourceServer = getResourceServer;
4exports.getPaywall = getPaywall;
5const express_1 = require("@x402/express");
6const server_1 = require("@x402/core/server");
7const x402_1 = require("@coinbase/x402");
8const server_2 = require("@x402/evm/exact/server");
9const bazaar_1 = require("@x402/extensions/bazaar");
10const x402_bazaar_config_1 = require("../config/x402-bazaar-config");
11const logger_1 = require("./logger");
12const pem_1 = require("../utils/pem");
13const network_1 = require("../config/network");
14// Normalise CDP_API_KEY_SECRET once at module load:
15// 1. Replace literal \n (Railway env var storage) with real newlines
16// 2. Convert SEC1 PEM (BEGIN EC PRIVATE KEY) → PKCS#8 (BEGIN PRIVATE KEY)
17// because jose v6 / importPKCS8 rejects SEC1 format
19 let key = (process.env.CDP_API_KEY_SECRET || '').replace(/\\n/g, '\n');
20 if (key.includes('-----BEGIN EC PRIVATE KEY-----')) {
CriticalCritical Secret
Package contains a critical-looking secret pattern.
dist/middleware/x402-paywall.jsView on unpkg · L20 CriticalSecret Pattern
EC private key in dist/middleware/x402-paywall.js
dist/middleware/x402-paywall.jsView on unpkg · L20 21 key = (0, pem_1.sec1ToP256Pkcs8Pem)(key);
23 process.env.CDP_API_KEY_SECRET = key;
26 * Custom paywall provider that fixes the x402 library's display bug:
27 * the library's getDisplayAmount checks for `amount` but the V1 type
28 * field is `maxAmountRequired`, so it always falls back to 0 → "$0.00".
29 * This provider reads the correct field and formats sub-cent amounts properly.
31const aiscalePaywallProvider = {
32 generateHtml(paymentRequired, config) {
33 const firstReq = paymentRequired?.accepts?.[0];
34 const rawAmount = firstReq?.maxAmountRequired ?? firstReq?.amount ?? '0';
35 const usdAmount = parseFloat(rawAmount) / 1e6;
36 // Format with enough decimals to show sub-cent amounts (e.g. $0.002)
37 const displayAmount = usdAmount < 0.01
38 ? usdAmount.toFixed(4).replace(/0+$/, '')
39 : usdAmount.toFixed(2);
40 const appName = config?.appName ?? 'AiScale Agent Services';