Skip to content

Add an OCR keystore service to libs/capability - #913

Merged
nolag merged 10 commits into
mainfrom
ocr-keystore
Nov 23, 2026
Merged

nolag merged 10 commits into
mainfrom
ocr-keystore

Conversation

@cedric-cordenier

@cedric-cordenier cedric-cordenier commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds libs/capability/keystore, which lets a capability process use the node's OCR2 key bundles without the private keys leaving the node. The process fetches the bundles it needs by ID, gets back libocr keyrings, and passes them to libocr.NewOracle.

This is the first of three PRs. smartcontractkit/chainlink#24212 serves the API from standard capabilities v2; after that, libs/ocr and consensus switch over to it.

Layout

Package Contents
keystore What every keystore shares: Keystores and RegisterServers, so future keystores (P2P and so on) can be added as sibling services on one server, and the run dependency under the keystore namespace (CL_KEYSTORE_URL)
keystore/ocr Keystore and KeyBundle for the node to implement; Client and KeyBundleClient for the process; StaticKeystore, NewLocalClient and NewSeededKeyBundle for keys in the process itself
keystore/ocr/remote RegisterServer and NewClient
keystore/ocr/remote/pb The OCRKeystore gRPC service

The OCRKeystore service

  • ListKeyBundles and GetKeyBundle return each bundle's ID, chain type and public keys. The client reads them once.
  • SignOnchain, VerifyOnchain, SignOffchain and ConfigDiffieHellman take a bundle ID and call that bundle on the node. Verification runs on the node too, so the client has no per-chain verification code.
  • The client returns each bundle as an ocrtypes.OnchainKeyring and an ocrtypes.OffchainKeyring. libocr's keyrings take no context, so each call to the node gets a 10s timeout.
  • Errors are gRPC status codes: NotFound for an unknown bundle, InvalidArgument for malformed input, Internal for keystore failures.

Embedded runs

Each instance of an embedded run gets an ocr.Client from EmbedInjector holding one bundle, EmbeddedKeyBundle(instance). Its ed25519 and X25519 keys are derived from the instance index, so every instance can compute every other's public keys. Anyone can derive them, so this is for local runs and tests only.

libs/capability also exports Dial and provides loop.GRPCOpts to the injector, matching what the OCR consensus branch needs.

Not included: the multichain onchain keyring builder. It needs ocr2key helpers that aren't released in chainlink-common yet.

Testing

  • go test -race ./capability/keystore/... serves a StaticKeystore of seeded bundles over an in-memory gRPC connection. It checks listing, filtering by chain type, getting by ID, and that signing, verifying and Diffie-Hellman give the same results as calling the bundle directly. It also checks every gRPC error code, that a failed verify call returns false, RegisterServers skipping nil keystores, the dependency with and without a URL, and that embedded instances get distinct, deterministic keys that verify each other's signatures.
  • go test ./capability/ passes.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

👋 cedric-cordenier, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Comment thread libs/capability/keystore/dependency.go Resolved
cedric-cordenier and others added 9 commits November 17, 2026 17:17
Adds libs/capability/keystore, which lets a capability process use the
node's OCR2 key bundles without the private keys leaving the node.

- OCRKeystore gRPC service: list and get bundles, then sign onchain,
  verify onchain, sign offchain and compute the config Diffie-Hellman
  by bundle ID.
- Server side: OCRKeyBundle/OCRKeystore interfaces for the node to
  implement, and Keystores/RegisterServers so further keystores can be
  added as sibling services.
- Client side: each bundle as an ocrtypes.OnchainKeyring and
  OffchainKeyring, plus a local client for embedded runs and tests.
- Run dependency under the keystore namespace (CL_KEYSTORE_URL).

Exports capability.Dial and provides loop.GRPCOpts to the injector so
the dependency can dial the node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- keystore/ocr: the Keystore and KeyBundle interfaces the node
  implements, the Client and KeyBundleClient a process uses, and the
  local client.
- keystore/ocr/remote: the gRPC server and client, with the proto in
  keystore/ocr/remote/pb.
- keystore/ocr/ocrtest: an in-memory Keystore for tests.
- keystore keeps what every keystore shares: Keystores,
  RegisterServers and the CL_KEYSTORE_URL run dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ocr.NewLocalClient had no caller. It goes back in with the embed
  support that will use it.
- The OCR keystore server never logged, so RegisterServer and
  RegisterServers no longer take a logger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each instance of an embedded run gets an ocr.Client holding a key bundle
derived from its index, so instances can compute each other's public keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NewSeededKeyBundle derives ed25519 signing keys and an X25519 config key
from a seed. The embedded keystore and ocrtest both build on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StaticKeystore replaces ocrtest.Keystore, and NewLocalClient turns any
Keystore into a Client, so the embedded client no longer repeats the
list and get logic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests build bundles with ocr.NewSeededKeyBundle and serve them from an
ocr.StaticKeystore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nolag
nolag enabled auto-merge November 23, 2026 14:40
@nolag
nolag added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit bbe3cd9 Nov 23, 2026
20 checks passed
@nolag
nolag deleted the ocr-keystore branch November 23, 2026 15:42
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.

3 participants