Skip to content

feat: add ECDSA signing to enclave for x402/EVM support #5

Description

@tiero

Problem

The x402 protocol requires EIP-3009 transferWithAuthorization — an off-chain ECDSA (secp256k1) signature on EIP-712 typed data. This lets a facilitator execute the USDC transfer on-chain on behalf of the client.

The clw.cash enclave currently only supports Schnorr signing for Bitcoin/Ark. The signMessage method in RemoteSignerIdentity explicitly throws on ECDSA:

// remote-signer-identity/src/remoteSignerIdentity.ts:107
if (signatureType === "ecdsa") {
  throw new Error("ECDSA signing is not supported by RemoteSignerIdentity");
}

What's needed

  1. Enclave: Add ECDSA signing endpoint (e.g. /sign-ecdsa) alongside the existing Schnorr endpoint. Same secp256k1 key, different signature scheme.
  2. API: Expose ECDSA signing via a new route or extend the existing /sign endpoint with a signatureType parameter.
  3. RemoteSignerIdentity: Remove the ECDSA throw, route ECDSA requests to the new endpoint.
  4. Derive Ethereum address: The existing compressed secp256k1 pubkey can derive an Ethereum address (keccak256(uncompressedPubKey[1:])[-20:]). Expose this so the agent knows its EVM address.

x402 flow once ECDSA is available

Agent requests URL → gets 402 Payment Required
  → parse PAYMENT-REQUIRED header (amount, token, chain, recipient)
  → swap BTC → USDC to agent's own EVM address (via existing LendaSwap infra)
  → construct EIP-712 typed data for EIP-3009 TransferWithAuthorization
  → hash client-side, send digest to enclave for ECDSA signing
  → retry request with PAYMENT-SIGNATURE header
  → facilitator settles the USDC transfer on-chain
  → agent gets the resource

New CLI command: cash pay <url>

Once ECDSA signing is available, implement:

  • cash pay <url> — fetch URL, handle 402 automatically, return response body
  • Uses @x402/fetch wrapper or custom implementation
  • Integrates with existing cash send swap infrastructure for the BTC→USDC funding step

Files affected

  • enclave/src/index.ts — new ECDSA signing route
  • api/src/index.ts — expose ECDSA signing
  • remote-signer-identity/src/remoteSignerIdentity.ts — support ECDSA
  • cli/src/commands/pay.ts — new command (after ECDSA is available)

Reference

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions