Skip to content

feat(privacy-proxy): add JSON-RPC proxy with role-based access control#302

Draft
AnshuJalan wants to merge 3 commits into
mainfrom
feat/privacy-proxy
Draft

feat(privacy-proxy): add JSON-RPC proxy with role-based access control#302
AnshuJalan wants to merge 3 commits into
mainfrom
feat/privacy-proxy

Conversation

@AnshuJalan
Copy link
Copy Markdown

Summary

New Rust package packages/privacy-proxy/ — an EVM JSON-RPC proxy that sits between users and the upstream execution client and enforces role-based access control on contract calls and address-parameterized reads.

What it does

  • HTTP JSON-RPC proxy over the eth_ namespace. Drop-in replacement for the chain's RPC URL; the only addition is an Authorization: Bearer <token> header.
  • Wallet sign-in flow (EIP-191 challenge / verify) issues opaque bearer tokens bound to the signer's EOA. SQLite-backed; no external services.
  • Access registry keyed by (contract_address, function_selector). Rules are allow or deny with per-role entries and optional named in-build lambda predicates over caller context and function arguments. Contracts or selectors not in the registry are freely callable.
  • For call-bearing methods (eth_call, eth_sendRawTransaction, eth_estimateGas, eth_createAccessList) the proxy issues debug_traceCall and applies the registry to every CALL frame — top-level and internal. Any forbidden frame rejects the whole request before it reaches the chain.
  • Address-parameterized reads (eth_getBalance, eth_getProof, eth_getTransactionCount, eth_getCode, eth_getStorageAt) are gated via synthetic 4-byte selectors over the same registry. Default policy: an EOA can only query its own state; contracts are free unless an admin installs a rule.
  • Admin REST surface at /admin/* (18 capabilities) for managing rules, entries, roles, users, and listing in-build lambdas. Seed admins come from the ADMIN_EOAS env var and are reconciled on every boot.

Docs

All under packages/privacy-proxy/docs/:

  • system-design.md — architecture, request flow, schema, modules
  • wallet-integration.md — for wallet developers integrating the sign-in flow
  • admin-api.md — full admin endpoint reference for the future operator UI
  • operator-guide.md — deploying, ADMIN_EOAS, key rotation, restart semantics

The package README is the external front-door.

A new Rust package that sits between users and the upstream execution
client. Wallets target it like a normal Ethereum JSON-RPC endpoint
(adding an Authorization: Bearer <token> header); the proxy gates
contract calls and address-parameterized reads against an admin-managed
access registry.

- Wallet sign-in flow (EIP-191 challenge/verify) issues opaque bearer
  tokens bound to the signer's EOA. SQLite-backed.
- Access registry keyed by (contract_address, function_selector), with
  allow/deny rules and per-role entries. Optional named in-build lambda
  predicates over caller_info and function arguments. Contracts or
  selectors not in the registry are freely callable.
- For call-bearing methods (eth_call, eth_sendRawTransaction,
  eth_estimateGas, eth_createAccessList) the proxy issues debug_traceCall
  and validates every CALL frame, top-level and internal. Any forbidden
  frame rejects the whole request.
- Address-parameterized reads (eth_getBalance, eth_getProof,
  eth_getTransactionCount, eth_getCode, eth_getStorageAt) are gated via
  synthetic 4-byte selectors over the same registry. Default policy: an
  EOA can only query its own state; contracts are free unless an admin
  installs a rule.
- /admin/* REST surface (18 capabilities) for rules, entries, roles,
  users, and lambda listing. Seed admins from the ADMIN_EOAS env var,
  reconciled on every boot.
- Docs live under packages/privacy-proxy/docs/ (system-design,
  wallet-integration, admin-api, operator-guide); package README is the
  external front-door.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
@AnshuJalan AnshuJalan marked this pull request as draft May 15, 2026 10:08
Comment thread packages/privacy-proxy/src/admin/registry.rs Fixed
Comment thread packages/privacy-proxy/src/admin/registry.rs Fixed
Comment thread packages/privacy-proxy/src/upstream.rs Fixed
AnshuJalan and others added 2 commits May 17, 2026 14:04
Caller attributes are now typed per role instead of a generic
caller_info JSON blob. Roles are code-declared in src/roles.rs and
reconciled to the DB at boot; the previous role-mutation endpoints are
gone. Lambdas are organized by role under src/acl/lambdas/<role>/ and
receive the role's typed attribute struct directly.

- Schema: top-level identity table renamed users -> members (admins and
  users both live here). Per-user-role state moves to user_attributes
  (kyc, blacklisted). caller_info_json column dropped.
- Self-registration: /auth/verify seeds a members row with default
  kyc=false, blacklisted=false; admin-only thereafter.
- Lambda base in src/acl/lambdas/mod.rs is generic over the role's
  attribute type C. user-role lambdas (require_kyc, erc20_self_only)
  live under src/acl/lambdas/user/ and read UserCallerInfo directly.
- Admin API: routes moved to /admin/members; PUT takes
  { role, attributes? } typed by role; capability index renumbered to
  a clean 1-16 sequence with no gaps.
- Docs: system-design.md gains a Roles section with an explicit
  "Adding a role" procedure; admin-api.md rewritten as fresh spec.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tors

`LambdaSpec.expected_selector: Option<[u8;4]>` becomes
`expected_selectors: &'static [[u8;4]]` — empty means selector-agnostic.
`erc20_self_only` now correctly lists the two selectors it actually
handles (balanceOf 0x70a08231 and allowance 0xdd62ed3e); admins authoring
rules can see at a glance which selectors a lambda is built for.

- `GET /admin/registry/lambdas` returns `expected_selectors: string[]`.
- Docs updated (admin-api §9, system-design §5).
- Adds a package-local .gitignore for the runtime sqlite DB.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants