Skip to content

Marco Polo

@mapoca12

Skill iconSolidity
Skill iconTypeScript
Skill iconNodejs
Skill iconFlutter
Agent-based Modelling

Cali, Colombia

PayAgent HSK: Autonomous AI Micro-Payments & Escrow for Local Commerce

Technical Architecture & System Specification
Tracks: AI x Ethereum & Agent Economy | Local AI & User Privacy | HSK Chain Track
Ecosystem Target: HashKey Chain (HSK Testnet, Chain ID: 133) & ShanHaiWoo Builders


1. Executive Summary & Problem Statement

1.1 The Problem

In real-world physical retail (artisanal pizzerias, specialty coffee roasters, neighborhood merchants), traditional Web3 payment adoption hits three critical bottlenecks:

  1. Clunky User Experience: Point-of-sale crypto payments require opening mobile wallets (MetaMask, Rabby), approving network switches, calculating unpredictable gas fees, and manual transaction signing at the cash register.
  2. Privacy & PII Leakage: Conventional loyalty and payment flows demand phone numbers, credit card tokens, or cleartext identities, exposing daily consumption habits to centralized merchant databases.
  3. Physical Fulfillment Uncertainty: Merchants risk non-payment or abrupt chargebacks, while customers risk paying upfront for orders that may be out of stock or delayed.

1.2 The Solution

PayAgent HSK bridges the physical economy with an autonomous hybrid architecture combining Autonomous AI Agents + Account Abstraction (ERC-4337 Session Keys) + Smart Escrow on HashKey Chain (HSK):

  • MerchantEscrow.sol (Solidity v0.8.20+): Non-custodial escrow contract with reentrancy guards, conditional deposit locks, multi-party session key release, and automated timeout refunds.
  • Autonomous Agent Service (/agent): TypeScript/Viem runtime acting as an impartial micro-escrow arbiter via ephemeral session keys, eliminating manual gas confirmations for daily transactions.
  • Local Privacy Engine (privacyVerifier.ts): Client-side zero-knowledge-style credential verification using cryptographic commitment hashes (keccak256(zkProof)). Zero Personally Identifiable Information (PII) is exposed on-chain or shared with the merchant.
  • Full-Stack POS & Ordering Dashboard: Production-grade Next.js 14 / React 19 interface with dual viewports: a conversational natural language UI for customers and a live Point-of-Sale (POS) monitor for merchants with real-time RPC settlement tracing.

2. Core Architecture & System Workflows

[ Customer / Natural Language UI ]


[ Local Privacy Engine (Client Sandbox) ]
└── Generates keccak256(Commitment) (Zero PII leak)


[ MerchantEscrow.sol (HSK Testnet - Chain ID: 133) ]
└── Locks funds in conditional escrow


[ Autonomous PayAgent Runtime (Viem / TypeScript) ]
├── Verifies fulfillment & commitment criteria
└── Signs releasePayment() via delegated Session Key


[ Instant Settlement to Merchant POS ]

Use Case 1: Conversational Order & Escrow Locking

  • User Input: "Order a sourdough Margherita pizza and craft drink at local POS using my resident VIP pass."
  • Execution Flow:
    1. NLU Extraction: The agent parses merchant metadata, menu items, total cost in HSK, and the required privilege tier (LOCAL_LOYALTY_VIP).
    2. Local Credential Commitment: Client-side engine computes keccak256("user_commitment:tier:nonce:issuerKey"). Identity remains strictly confidential.
    3. Escrow Locking: Funds are deposited into MerchantEscrow.sol via:
      createOrder(orderId, merchantAddress, amount, credentialCommitment, metadataURI);
      
    4. Order switches to ESCROWED status on the merchant's real-time terminal.

Use Case 2: Zero-Knowledge Local Verification & Autonomous HSK Settlement

  • Fulfillment Trigger: Merchant confirms order preparation at physical POS.
  • Execution Flow:
    1. Agent Audit: Autonomous agent verifies credential anti-replay nonces and fulfillment criteria off-chain.
    2. On-Chain Settlement: Agent executes releasePayment(orderId) using an ephemeral ERC-4337 Session Key on HashKey Chain Testnet (https://hashkeychain-testnet-rpc.alt.technology).
    3. Final Settlement: Escrow releases funds directly to the merchant's wallet, emitting PaymentReleased with live transaction receipt links on the HSK block explorer.

3. Smart Contract Specifications (MerchantEscrow.sol)

  • Network: HashKey Chain (HSK) Testnet
  • Chain ID: 133
  • Core Functions:
    • createOrder(bytes32 orderId, address merchant, uint256 amount, bytes32 commitment, string metadataURI): Locks funds in escrow.
    • releasePayment(bytes32 orderId): Disburses payment to the merchant upon authorized AI agent signature.
    • refundOrder(bytes32 orderId): Automatic timeout refund if the merchant fails to fulfill the order.
    • cancelOrder(bytes32 orderId): Emergency governance fallback for disputed states.