Private Chain with Authenticated RPC Middleware #34
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We want the chain to be private. That means outsiders should not be able to read the blocks directly. Additionally, we should validate some read operations of chain state.
One approach would be making each read call a full smart contract "change" call requiring auth, but this would bloat the chain a lot.
NEAR gives us a mechanism to work with: smart contracts can take an account id parameter and return specific data based on that. However, it's not actually authentication and the client can pass any account id.
So the idea here is to use middleware to block certain methods and provide a simple auth mechanism against smart contract reads, using the existing NEAR mechanism.
Summary
Implement an RPC middleware proxy that sits between clients and our private NEAR chain, enforcing authentication via request signing and blocking raw chain access methods that would bypass smart contract access control.
Background
Our NEAR-based chain stores data that is not universally public. Smart contracts are responsible for enforcing per-account data authorization. However, NEAR's RPC interface exposes methods that allow clients to read raw chain state directly, bypassing contract logic entirely. We need a middleware layer that:
account_id, allowing contracts to make authorization decisionsThe NEAR nodes themselves are not publicly accessible — all client access goes through this middleware.
Approach
Authentication
Clients sign each request using their NEAR private key. The signature covers the RPC call parameters plus a timestamp. The middleware verifies the signature against the account's public key (looked up via the node's
view_access_keyendpoint) and rejects requests where:Once verified, the middleware forwards the request with the authenticated
account_idinjected as the caller context. Smart contracts can then use this identity to decide what data to return.Blocked RPC Methods
The following methods are blocked entirely as they expose raw chain state that bypasses contract logic:
blockchunkEXPERIMENTAL_changesEXPERIMENTAL_changes_in_blockquery(view_state)query(view_access_key)query(view_access_key_list)txEXPERIMENTAL_tx_statusPermitted RPC Methods
query(call_function)broadcast_tx_asyncbroadcast_tx_commitgas_pricestatusnetwork_infoRequest Flow
Smart Contract Considerations
Contracts must treat the injected
account_idas the authoritative caller identity for view calls, since view calls have no native signature requirement at the NEAR protocol level. Since the middleware guarantees only authenticated, verifiedaccount_idvalues are forwarded, contracts can safely use this for access decisions.For particularly sensitive operations, contracts may additionally be designed as
changemethods to require on-chain signing — but this should be reserved for writes or high-sensitivity reads where the added cost and latency is acceptable.Acceptance Criteria
account_idis injected into forwardedcall_functionrequestscall_functionrequest is forwarded and returns dataview_staterequest is rejected regardless of authOut of Scope