MCPcopy Index your code
hub / github.com/codeaashu/claude-code / createPayment

Function createPayment

src/services/x402/client.ts:294–328  ·  view source on GitHub ↗
(
  requirement: PaymentRequirement,
  fromAddress: string,
  privateKeyHex: string,
)

Source from the content-addressed store, hash-verified

292 * Create a signed x402 payment payload for a given requirement.
293 */
294export function createPayment(
295 requirement: PaymentRequirement,
296 fromAddress: string,
297 privateKeyHex: string,
298): PaymentPayload {
299 const nonce = '0x' + randomBytes(32).toString('hex')
300 const validAfter = '0'
301 const validBefore = String(
302 Math.floor(Date.now() / 1000) + requirement.maxTimeoutSeconds,
303 )
304
305 const authorization = {
306 from: fromAddress,
307 to: requirement.payTo,
308 value: requirement.maxAmountRequired,
309 validAfter,
310 validBefore,
311 nonce,
312 }
313
314 const domain = getEIP712Domain(requirement)
315 const domainSeparator = computeDomainSeparator(domain)
316 const structHash = computeStructHash(authorization)
317 const signature = signEIP712(domainSeparator, structHash, privateKeyHex)
318
319 return {
320 x402Version: 1,
321 scheme: requirement.scheme,
322 network: requirement.network,
323 payload: {
324 signature,
325 authorization,
326 },
327 }
328}
329
330/**
331 * Encode a payment payload as a base64 string for the X-Payment header.

Callers 1

handlePaymentRequiredFunction · 0.85

Calls 5

getEIP712DomainFunction · 0.85
computeDomainSeparatorFunction · 0.85
computeStructHashFunction · 0.85
signEIP712Function · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected