x402pp-core
Core protocol primitives, types, and cryptographic functions
Core Functions
createIntent()
import { createIntent } from 'x402pp-core';
const intent = createIntent({
capability: string,
maxPricePerRequest: number,
token: 'SOL' | 'USDC' | 'USDT' | 'BONK',
agentPubkey: string | PublicKey,
sla?: SLA,
metadata?: Record<string, any>
});createOffer()
import { createOffer } from 'x402pp-core';
const offer = createOffer({
intent: Intent,
providerPubkey: string | PublicKey,
pricePerRequest: number,
sla: SLA,
sessionDurationMs: number,
endpoint: string
}, providerKeypair); // Signs with Ed25519verifyOffer()
import { verifyOffer } from 'x402pp-core';
// Throws if invalid
verifyOffer(offer);
// Verifies:
// ✓ Signature is valid
// ✓ Offer hasn't expired
// ✓ All required fields presentcreateReceipt()
import { createReceipt } from 'x402pp-core';
const receipt = createReceipt({
session: Session,
requestNumber: number,
inputData: any,
outputData: any,
requestStartedAt: number,
requestCompletedAt: number,
amountCharged: number
}, providerKeypair); // Signs with Ed25519verifyReceipt()
import { verifyReceipt } from 'x402pp-core';
// Throws if invalid
verifyReceipt(receipt);
// Verifies:
// ✓ Ed25519 signature valid
// ✓ Signed by correct provider
// ✓ Timestamps validCryptographic Functions
import {
signMessage,
verifySignature,
hashObject,
hashString,
createSignableMessage
} from 'x402pp-core';
// Sign a message
const signature = signMessage(message, keypair);
// Verify signature
const valid = verifySignature(message, signature, publicKey);
// Hash an object (canonical JSON + SHA-256)
const hash = hashObject({ foo: 'bar' });
// Hash a string
const stringHash = hashString('hello world');
// Create signable message from object
const message = createSignableMessage(offer);Constants
import {
PROTOCOL_VERSION,
HTTP_STATUS,
HEADERS,
SUPPORTED_TOKENS,
TOKEN_MINTS
} from 'x402pp-core';
console.log(PROTOCOL_VERSION); // "0.1.0"
console.log(HTTP_STATUS.PAYMENT_REQUIRED); // 402
console.log(HTTP_STATUS.SESSION_STARTED); // 201
console.log(HEADERS.INTENT); // "X-402-Intent"
console.log(HEADERS.OFFER); // "X-402-Offer"
console.log(HEADERS.SESSION_ID); // "X-402-Session-Id"
console.log(HEADERS.RECEIPT); // "X-402-Receipt"
console.log(SUPPORTED_TOKENS); // ['SOL', 'USDC', 'USDT', 'BONK']
console.log(TOKEN_MINTS.USDC);
// "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"Network Configuration
import {
getNetworkConfig,
getRpcUrl,
getExplorerUrl
} from 'x402pp-core';
// Get network config
const config = getNetworkConfig('devnet');
console.log(config.rpcUrl);
// Get RPC URL
const rpc = getRpcUrl('mainnet-beta');
// Get explorer URL for transaction
const explorerUrl = getExplorerUrl(txSignature, 'devnet');
// https://explorer.solana.com/tx/ABC...?cluster=devnet