{"version":3,"sources":["../../src/direct/escrow-payment.ts"],"sourcesContent":["/**\n * Escrow-backed payment authorization for the Direct Data Controller.\n *\n * @remarks\n * Builds on the DPv2 escrow surface added in `protocol/escrow`. When a Personal\n * Server read returns `402 Payment Required`, the controller settles the\n * challenged operation through the escrow gateway:\n *\n *  1. Sign the challenge's `GenericPayment` EIP-712 message with the app key.\n *  2. POST it to the gateway's `/v1/escrow/pay` via {@link EscrowGatewayClient}.\n *  3. Map the gateway's {@link EscrowPayResult} into a typed\n *     {@link DirectPaymentReceipt} for the caller to inspect.\n *\n * This module supports legacy `\"grant\"` operations and receipt-bound\n * `\"data_access\"` operations. It adapts the escrow `payForOp` flow to the\n * direct-read use case; it does not define its own payment scheme.\n *\n * @category Direct\n * @module direct/escrow-payment\n */\n\nimport {\n  GENERIC_PAYMENT_TYPES,\n  NATIVE_ASSET_ADDRESS,\n  genericPaymentDomain,\n  type EscrowAccessRecord,\n  type EscrowPaymentClient,\n  type EscrowPayResult,\n  type PaymentBreakdown,\n} from \"../protocol/escrow\";\nimport type {\n  DirectFeeBreakdown,\n  DirectPaymentReceipt,\n  DirectPaymentResponseMetadata,\n  PersonalServerPaymentOperation,\n  PersonalServerPaymentRequired,\n} from \"./types\";\n\n/** The escrow `GenericPayment.opType` used for grant-lifecycle payments. */\nexport const GRANT_OP_TYPE = \"grant\" as const;\n/** The escrow `GenericPayment.opType` used for receipt-bound data access. */\nexport const DATA_ACCESS_OP_TYPE = \"data_access\" as const;\n\n/**\n * EIP-712 typed-data signer (e.g. viem `account.signTypedData`).\n *\n * @remarks\n * Kept structurally minimal so any viem account/wallet client satisfies it\n * without the SDK depending on viem's exact `signTypedData` overload set.\n */\nexport type SignTypedDataFn = (args: {\n  domain: ReturnType<typeof genericPaymentDomain>;\n  types: typeof GENERIC_PAYMENT_TYPES;\n  primaryType: \"GenericPayment\";\n  message: {\n    payerAddress: `0x${string}`;\n    opType: string;\n    opId: `0x${string}`;\n    asset: `0x${string}`;\n    amount: bigint;\n    paymentNonce: bigint;\n  };\n}) => Promise<`0x${string}`>;\n\n/** Supplies a monotonically-increasing payment nonce per payer. */\nexport type PaymentNonceSource = (\n  payerAddress: string,\n) => Promise<bigint> | bigint;\n\ninterface EscrowPaymentMessage {\n  payerAddress: `0x${string}`;\n  opType: typeof GRANT_OP_TYPE | typeof DATA_ACCESS_OP_TYPE;\n  opId: `0x${string}`;\n  asset: `0x${string}`;\n  amount: string;\n  paymentNonce: string;\n}\n\ninterface SignedEscrowPayment {\n  message: EscrowPaymentMessage;\n  signature: `0x${string}`;\n  accessRecord?: EscrowAccessRecord;\n}\n\ninterface X402PaymentHeader {\n  x402Version: 1;\n  scheme: \"vana-escrow-grant\";\n  network: string;\n  payload: SignedEscrowPayment;\n}\n\n/** Configuration required to sign an escrow X-PAYMENT header. */\nexport interface EscrowPaymentHeaderConfig {\n  /** Deployed `DataPortabilityEscrow` contract address. */\n  escrowContract: `0x${string}`;\n  /** Chain id for the EIP-712 domain (1480 mainnet, 14800 moksha). */\n  chainId: number;\n  /** App EIP-712 signer. */\n  signTypedData: SignTypedDataFn;\n  /**\n   * Supplies the next payment nonce for a payer. Defaults to a process-local\n   * monotonic counter seeded at 1. Provide a durable source in production so\n   * nonces survive restarts (the gateway rejects reused (payer, nonce) pairs).\n   */\n  nonceSource?: PaymentNonceSource;\n}\n\n/**\n * Escrow settlement configuration for gateway authorization.\n *\n * @remarks\n * Extends the header-signing boundary with the gateway client used by\n * {@link authorizeEscrowPayment}. Existing controller and legacy wrapper\n * callers can continue to provide this full configuration.\n */\nexport interface EscrowPaymentConfig extends EscrowPaymentHeaderConfig {\n  /** Client for the gateway escrow endpoints (`/v1/escrow/*`). */\n  client: EscrowPaymentClient;\n}\n\n/** Map the gateway {@link PaymentBreakdown} into the public {@link DirectFeeBreakdown}. */\nexport function toDirectFeeBreakdown(\n  breakdown: PaymentBreakdown,\n): DirectFeeBreakdown {\n  return {\n    registrationFee: breakdown.registrationFee,\n    dataAccessFee: breakdown.dataAccessFee,\n    registrationPaid: breakdown.registrationPaid,\n  };\n}\n\n/** Map a gateway {@link EscrowPayResult} into the public {@link DirectPaymentReceipt}. */\nexport function toDirectPaymentReceipt(\n  result: EscrowPayResult,\n): DirectPaymentReceipt {\n  return {\n    opType: result.opType,\n    opId: result.opId,\n    asset: result.asset,\n    amount: result.amount,\n    paymentNonce: result.paymentNonce,\n    breakdown: toDirectFeeBreakdown(result.breakdown),\n    paidAt: result.paidAt,\n  };\n}\n\n/** Default in-process monotonic nonce counter (seeded at 1 per payer). */\nexport function createDefaultNonceSource(): PaymentNonceSource {\n  const counters = new Map<string, bigint>();\n  return (payerAddress: string): bigint => {\n    const key = payerAddress.toLowerCase();\n    const next = (counters.get(key) ?? 0n) + 1n;\n    counters.set(key, next);\n    return next;\n  };\n}\n\nconst processLocalNonceSource = createDefaultNonceSource();\nconst UINT256_MAX = (1n << 256n) - 1n;\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\nconst BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;\nconst SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;\n\nfunction isUint256Decimal(value: string, allowZero: boolean): boolean {\n  const pattern = allowZero ? /^(0|[1-9]\\d*)$/ : /^[1-9]\\d*$/;\n  return (\n    value.length <= UINT256_MAX.toString().length &&\n    pattern.test(value) &&\n    BigInt(value) <= UINT256_MAX\n  );\n}\n\nfunction isValidAccessRecord(record: EscrowAccessRecord): boolean {\n  return (\n    BYTES32_RE.test(record.dataPointId) &&\n    isUint256Decimal(record.version, false) &&\n    ADDRESS_RE.test(record.accessor) &&\n    BYTES32_RE.test(record.recordId) &&\n    SIGNATURE_RE.test(record.signature)\n  );\n}\n\nfunction validateSigningOperation(\n  payerAddress: `0x${string}`,\n  required: PersonalServerPaymentOperation,\n): void {\n  if (!ADDRESS_RE.test(payerAddress)) {\n    throw new Error(\"Payment payer must be a 20-byte EVM address\");\n  }\n  if (!BYTES32_RE.test(required.opId)) {\n    throw new Error(\"Payment operation id must be a 32-byte hex value\");\n  }\n  if (!ADDRESS_RE.test(required.asset || NATIVE_ASSET_ADDRESS)) {\n    throw new Error(\"Payment asset must be a 20-byte EVM address\");\n  }\n  if (!isUint256Decimal(required.amount, true)) {\n    throw new Error(\"Payment amount must be a canonical uint256 decimal\");\n  }\n  if (\n    required.paymentNonce !== undefined &&\n    !isUint256Decimal(required.paymentNonce, false)\n  ) {\n    throw new Error(\"Payment nonce must be a positive uint256 decimal\");\n  }\n\n  const accessRecord = required.accessRecord;\n  if (required.opType === DATA_ACCESS_OP_TYPE) {\n    if (!accessRecord || !isValidAccessRecord(accessRecord)) {\n      throw new Error(\"Data-access payment requires a valid access record\");\n    }\n    if (required.opId.toLowerCase() !== accessRecord.recordId.toLowerCase()) {\n      throw new Error(\n        \"Data-access payment operation id must equal the access record id\",\n      );\n    }\n    if (accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {\n      throw new Error(\n        \"Data-access payment accessor must equal the payment payer address\",\n      );\n    }\n    return;\n  }\n\n  if (required.amount === \"0\") {\n    if (\n      !accessRecord ||\n      !isValidAccessRecord(accessRecord) ||\n      accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()\n    ) {\n      throw new Error(\n        \"Zero-amount grant payments require a valid access record for the payer\",\n      );\n    }\n  }\n}\n\nfunction base64EncodeJson(value: unknown): string {\n  const bytes = new TextEncoder().encode(JSON.stringify(value));\n  let binary = \"\";\n  for (const byte of bytes) binary += String.fromCharCode(byte);\n  return btoa(binary);\n}\n\nfunction base64DecodeJson(value: string): unknown {\n  const binary = atob(value);\n  const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));\n  return JSON.parse(new TextDecoder().decode(bytes));\n}\n\nasync function signEscrowPayment(params: {\n  payerAddress: `0x${string}`;\n  required: PersonalServerPaymentOperation;\n  config: EscrowPaymentHeaderConfig;\n}): Promise<SignedEscrowPayment> {\n  const { payerAddress, required, config } = params;\n  validateSigningOperation(payerAddress, required);\n  const nonceSource = config.nonceSource ?? processLocalNonceSource;\n  const paymentNonce = BigInt(\n    required.paymentNonce ?? (await nonceSource(payerAddress)),\n  );\n  const asset = (required.asset || NATIVE_ASSET_ADDRESS) as `0x${string}`;\n  const opId = required.opId as `0x${string}`;\n  const amount = BigInt(required.amount);\n  if (amount < 0n || amount > UINT256_MAX) {\n    throw new Error(\"Payment amount must be a uint256\");\n  }\n  if (paymentNonce <= 0n || paymentNonce > UINT256_MAX) {\n    throw new Error(\"Payment nonce must be a positive uint256\");\n  }\n\n  const message = {\n    payerAddress,\n    opType: required.opType,\n    opId,\n    asset,\n    amount,\n    paymentNonce,\n  };\n\n  const signature = await config.signTypedData({\n    domain: genericPaymentDomain(config.chainId, config.escrowContract),\n    types: GENERIC_PAYMENT_TYPES,\n    primaryType: \"GenericPayment\",\n    message,\n  });\n\n  return {\n    message: {\n      ...message,\n      amount: amount.toString(),\n      paymentNonce: paymentNonce.toString(),\n    },\n    signature,\n    ...(required.accessRecord ? { accessRecord: required.accessRecord } : {}),\n  };\n}\n\n/**\n * Build the canonical X-PAYMENT header for a validated escrow operation.\n *\n * @remarks\n * Supports both legacy grant payments and receipt-bound data-access payments.\n * Signing is injected through {@link EscrowPaymentHeaderConfig.signTypedData}.\n */\nexport async function buildEscrowPaymentHeader(params: {\n  /** Address whose escrow balance pays for the operation. */\n  payerAddress: `0x${string}`;\n  /** Validated operation parsed from the Personal Server challenge. */\n  required: PersonalServerPaymentOperation;\n  /** Escrow contract, chain, signer, and nonce configuration. */\n  config: EscrowPaymentHeaderConfig;\n}): Promise<string> {\n  const network = params.required.network ?? `vana:${params.config.chainId}`;\n  if (network !== `vana:${params.config.chainId}`) {\n    throw new Error(\"Payment network must match the configured chain\");\n  }\n\n  const signed = await signEscrowPayment(params);\n  const payment: X402PaymentHeader = {\n    x402Version: 1,\n    scheme: \"vana-escrow-grant\",\n    network,\n    payload: signed,\n  };\n  return base64EncodeJson(payment);\n}\n\n/** Build a legacy grant X-PAYMENT header. */\nexport async function buildGrantPaymentHeader(params: {\n  payerAddress: `0x${string}`;\n  required: PersonalServerPaymentRequired;\n  config: EscrowPaymentConfig;\n}): Promise<string> {\n  return buildEscrowPaymentHeader({\n    ...params,\n    required: {\n      ...params.required,\n      opType: GRANT_OP_TYPE,\n      opId: params.required.grantId,\n    },\n  });\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n  return value && typeof value === \"object\" && !Array.isArray(value)\n    ? (value as Record<string, unknown>)\n    : undefined;\n}\n\nfunction stringField(\n  value: Record<string, unknown> | undefined,\n  key: string,\n): string | undefined {\n  const field = value?.[key];\n  return typeof field === \"string\" ? field : undefined;\n}\n\nfunction isCanonicalIsoTimestamp(value: string): boolean {\n  try {\n    return new Date(value).toISOString() === value;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Parse shape-validated payment response metadata echoed by a Personal Server.\n *\n * @remarks\n * This metadata is not authenticated by the gateway. It is suitable for\n * display and debugging, not as proof that a payment occurred.\n */\nexport function paymentResponseMetadataFromHeader(\n  header: string | null | undefined,\n): DirectPaymentResponseMetadata | undefined {\n  if (!header) return undefined;\n  try {\n    const result = asRecord(base64DecodeJson(header));\n    const breakdown = asRecord(result?.breakdown);\n    const opType = stringField(result, \"opType\");\n    const opId = stringField(result, \"opId\");\n    const payerAddress = stringField(result, \"payerAddress\");\n    const asset = stringField(result, \"asset\");\n    const amount = stringField(result, \"amount\");\n    const paymentNonce = stringField(result, \"paymentNonce\");\n    const registrationFee = stringField(breakdown, \"registrationFee\");\n    const dataAccessFee = stringField(breakdown, \"dataAccessFee\");\n    const paidAt = stringField(result, \"paidAt\");\n    if (\n      result?.success !== true ||\n      !opType ||\n      !opId ||\n      !BYTES32_RE.test(opId) ||\n      !payerAddress ||\n      !ADDRESS_RE.test(payerAddress) ||\n      !asset ||\n      !ADDRESS_RE.test(asset) ||\n      !amount ||\n      !isUint256Decimal(amount, true) ||\n      !paymentNonce ||\n      !isUint256Decimal(paymentNonce, false) ||\n      !registrationFee ||\n      !isUint256Decimal(registrationFee, true) ||\n      !dataAccessFee ||\n      !isUint256Decimal(dataAccessFee, true) ||\n      typeof breakdown?.registrationPaid !== \"boolean\" ||\n      !paidAt ||\n      !isCanonicalIsoTimestamp(paidAt)\n    ) {\n      return undefined;\n    }\n    return {\n      opType,\n      opId,\n      asset,\n      amount,\n      paymentNonce,\n      breakdown: {\n        registrationFee,\n        dataAccessFee,\n        registrationPaid: breakdown.registrationPaid,\n      },\n      paidAt,\n    };\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * @deprecated Use {@link paymentResponseMetadataFromHeader}. A Personal\n * Server response header is untrusted metadata, not a gateway-authenticated\n * receipt.\n */\nexport function paymentReceiptFromHeader(\n  header: string | null | undefined,\n): DirectPaymentResponseMetadata | undefined {\n  return paymentResponseMetadataFromHeader(header);\n}\n\n/**\n * Authorize an escrow payment for a grant data-access fee.\n *\n * @param params - The payment requirement, the payer address, and escrow config.\n * @returns The gateway's {@link EscrowPayResult} as a typed\n * {@link DirectPaymentReceipt}.\n */\nexport async function authorizeGrantPayment(params: {\n  payerAddress: `0x${string}`;\n  required: PersonalServerPaymentRequired;\n  config: EscrowPaymentConfig;\n}): Promise<DirectPaymentReceipt> {\n  return authorizeEscrowPayment({\n    ...params,\n    required: {\n      ...params.required,\n      opType: GRANT_OP_TYPE,\n      opId: params.required.grantId,\n    },\n  });\n}\n\n/**\n * Authorize a validated grant or data-access operation through the escrow\n * gateway.\n */\nexport async function authorizeEscrowPayment(params: {\n  /** Address whose escrow balance pays for the operation. */\n  payerAddress: `0x${string}`;\n  /** Validated operation to authorize. */\n  required: PersonalServerPaymentOperation;\n  /** Escrow gateway and signing configuration. */\n  config: EscrowPaymentConfig;\n}): Promise<DirectPaymentReceipt> {\n  const { payerAddress, config } = params;\n  const signed = await signEscrowPayment(params);\n\n  const result = await config.client.payForOp({\n    payerAddress,\n    opType: signed.message.opType,\n    opId: signed.message.opId,\n    asset: signed.message.asset,\n    amount: signed.message.amount,\n    paymentNonce: signed.message.paymentNonce,\n    signature: signed.signature,\n    accessRecord: signed.accessRecord,\n  });\n\n  return toDirectPaymentReceipt(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,oBAQO;AAUA,MAAM,gBAAgB;AAEtB,MAAM,sBAAsB;AAgF5B,SAAS,qBACd,WACoB;AACpB,SAAO;AAAA,IACL,iBAAiB,UAAU;AAAA,IAC3B,eAAe,UAAU;AAAA,IACzB,kBAAkB,UAAU;AAAA,EAC9B;AACF;AAGO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,MAAM,OAAO;AAAA,IACb,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,WAAW,qBAAqB,OAAO,SAAS;AAAA,IAChD,QAAQ,OAAO;AAAA,EACjB;AACF;AAGO,SAAS,2BAA+C;AAC7D,QAAM,WAAW,oBAAI,IAAoB;AACzC,SAAO,CAAC,iBAAiC;AACvC,UAAM,MAAM,aAAa,YAAY;AACrC,UAAM,QAAQ,SAAS,IAAI,GAAG,KAAK,MAAM;AACzC,aAAS,IAAI,KAAK,IAAI;AACtB,WAAO;AAAA,EACT;AACF;AAEA,MAAM,0BAA0B,yBAAyB;AACzD,MAAM,eAAe,MAAM,QAAQ;AACnC,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,eAAe;AAErB,SAAS,iBAAiB,OAAe,WAA6B;AACpE,QAAM,UAAU,YAAY,mBAAmB;AAC/C,SACE,MAAM,UAAU,YAAY,SAAS,EAAE,UACvC,QAAQ,KAAK,KAAK,KAClB,OAAO,KAAK,KAAK;AAErB;AAEA,SAAS,oBAAoB,QAAqC;AAChE,SACE,WAAW,KAAK,OAAO,WAAW,KAClC,iBAAiB,OAAO,SAAS,KAAK,KACtC,WAAW,KAAK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