@agenticprimitives/chain-state-viem
v0.0.0-alpha.3
Published
viem-backed ChainProvider adapter for @agenticprimitives/chain-state: readContract-only isRevoked / connection-agnostic signature validation / isAcceptedSessionDelegation reads, pinned to a block for evidence.
Downloads
186
Maintainers
Readme
@agenticprimitives/chain-state-viem
The viem-backed ChainProvider for @agenticprimitives/chain-state.
chain-state is pure — its resilient ChainAuthorityReader takes injected providers. This package is
the concrete provider: it performs the authority eth_calls (via viem) and reports the block each read was
pinned to, so every answer carries evidence. readContract / getCode / getBlock only — never
eth_getLogs (ADR-0012).
It mirrors the exact reads delegation/token.ts performs, so the chain-state port is behavior-equivalent
when the verify path is rewired through it (spec 289 §5).
Usage
import { createChainAuthorityReader } from '@agenticprimitives/chain-state';
import { createViemChainProvider } from '@agenticprimitives/chain-state-viem';
const reader = createChainAuthorityReader({
chainId: 8453,
providers: [
createViemChainProvider({ source: 'alchemy', rpcUrl: rpcA, delegationManager, universalSignatureValidator }),
createViemChainProvider({ source: 'infura', rpcUrl: rpcB, delegationManager, universalSignatureValidator }),
],
revocationFreshnessMs: 12_000,
});
const { revoked, evidence } = await reader.isDelegationRevoked(delegationHash);The reads:
readRevoked→DelegationManager.isRevoked(bytes32)readSignatureValid→ connection-agnostic: EOA → local ECDSA recover; contract →UniversalSignatureValidator.isValidSig(ERC-1271 / ERC-6492)readSessionAccepted→isAcceptedSessionDelegation(bytes32)on the principal account
The viem client is injectable (client) for tests; otherwise it's built from rpcUrl.
License
MIT
