solana-keychain library. By adding your
signer implementation, you’ll enable developers to use your service for secure
Solana transaction signing through a unified interface.
Keychain keeps its Rust, TypeScript, Python, and Go implementations at parity.
PRs that include all four are strongly preferred. If you can only contribute
one, that’s fine, but expect the others to be required before the signer ships
in a release.
Using Claude Code? The repo’s
add-signer-ci skill
wires up the CI workflows for a new signer contributed via a fork PR.
Architecture Overview
The library uses a trait-based architecture defined insrc/traits.rs. Every
signer implements the SolanaSigner base trait (pubkey, sign_message,
is_available) plus exactly one capability trait matching the provider’s shape:
TransactionSigner(sign_transaction): the provider signs the caller’s bytes and the caller broadcasts. Most backends.ModifyingSigner(modify_and_sign_transaction): the provider rewrites the transaction, then signs it without broadcasting.SendingSigner(sign_and_send_transaction): the provider signs and broadcasts server-side.
Signer enum that wraps all
implementations, allowing runtime selection of signing backends. It implements
only the base trait; capabilities are reached through as_transaction_signer(),
as_modifying_signer(), and as_sending_signer().
Quick Integration Checklist
- Create your signer module with implementation
- Implement the
SolanaSignerbase trait (pubkey,sign_message,is_available) plus the one capability trait matching your provider’s shape (usuallyTransactionSigner) - Add a feature flag in
Cargo.toml, including the internal_remotemarker if your signer uses reqwest - Update the
Signerenum insrc/lib.rs(variant,dispatch_signer!arm, and an arm in the capability accessor matching your shape) - Build HTTP clients from
HttpClientConfig(HTTPS only, timeouts, no redirects) - Sign the message bytes and verify the returned signature before attaching it
- Add comprehensive unit tests (wiremock-based, in your module)
- Add an integration test file and update
.env.example - Add the TypeScript, Python, and Go implementations
- Update documentation
- CI workflow updates (coordinate with maintainers, see CI Workflow Updates)
- Submit PR
Step 1: Create Your Signer Module
Create a new directory undersrc/ for your implementation:
Step 2: Define Your Signer Struct
Insrc/your_service/mod.rs, define your signer struct:
Step 3: Implement Constructor and Helper Methods
Remote signers must build their HTTP client from the sharedHttpClientConfig. Its build_client() returns a client that only speaks
HTTPS, applies the request and connect timeouts, and refuses every redirect. A
client that follows redirects resends provider credential headers to the
redirect target, so never start from reqwest::Client::builder(). If you need
more settings, start from client_builder() and add them.
Step 4: Implement the Signer Traits
TheSolanaSigner base trait has 2 async methods (sign_message,
is_available) plus pubkey(). Transaction signing goes in a capability trait;
most providers implement TransactionSigner, whose sign_transaction returns
SignTransactionResult (a tagged enum marking the transaction fully or
partially signed).
Sign the message bytes, never the whole wire transaction, and verify the
provider’s signature against them before attaching it. Use the shared
TransactionUtil helpers for signing and serialization.
ModifyingSigner instead and replace the caller’s transaction wholesale with
the provider’s bytes. If it broadcasts server-side, implement SendingSigner
and leave the caller’s transaction untouched. Never implement a capability your
provider cannot serve.
Step 5: Add API Types
Put the request and response types insrc/your_service/types.rs (declared
with mod types; in Step 2):
Step 6: Add Feature Flag
UpdateCargo.toml to add your signer as an optional feature. Remote backends
include the internal _remote marker, which gates the From<reqwest::Error>
impl in src/error.rs; without it, ? on reqwest calls won’t compile when only
your feature is enabled.
Step 7: Update the Signer Enum
Add your signer tosrc/lib.rs. The base SolanaSigner impl dispatches through
the dispatch_signer! macro, so add one arm there. Capability access lives in
the as_transaction_signer(), as_modifying_signer(), and as_sending_signer()
accessors: add a Some(s) arm to the one matching your capability trait (and,
for a sending or modifying backend, a None arm in as_transaction_signer()).
Step 8: Add Comprehensive Tests
Add tests to your module (at the bottom ofsrc/your_service/mod.rs):
Step 9: Add Integration Tests
Createrust/src/tests/test_<name>_integration.rs. Integration tests run
against the real service API (not wiremock) and are gated behind the
integration-tests feature. Each file needs:
pub constdeclarations for env var names- A
get_signer()helper that reads env vars viadotenvy - Three test functions:
test_<name>_sign_message,test_<name>_sign_transaction, andtest_<name>_is_available - Feature gates:
#[cfg(feature = "your_service")]on the module and#[cfg(feature = "integration-tests")]on each test
rust/src/tests/test_para_integration.rs for a complete reference, and
declare your module in rust/src/tests/mod.rs:
Step 10: Update Environment Variables
Update the root.env.example with your signer’s env vars, following the
existing pattern:
.env.example, and the TypeScript, Python and Go suites use the same names.
Step 11: Update Documentation
Add your signer to the supported backends table in README.md:| Backend | Use Case | Feature Flag |
|---|---|---|
| Memory | Local keypairs, development, testing | memory |
| Vault | Enterprise key management with HashiCorp Vault | vault |
| Privy | Embedded wallets with Privy infrastructure | privy |
| Turnkey | Non-custodial key management via Turnkey | turnkey |
| YourService | Brief description of your service | your_service |
Testing Your Integration
Use thejust recipes rather than raw cargo. The SDK features (sdk-v2,
sdk-v3, sdk-v4) are mutually exclusive, so cargo test --all-features
fails.
CI Workflow Updates (Fork PRs)
CI is a two-phase process. Coordinate with maintainers to preparemain before
your PR can be tested: they update fork-external-live-manual.yml, add env vars
to ci.yml, and configure GitHub Secrets.
Your PR must include these Phase 2 changes alongside your signer code:
ci.yml: add your Rust feature to thebackendmatrix (beforeall) and your integration test function to thetestmatrixtypescript-ci.yml: add your package to the unit and integration test matrices, and add env vars to the integration test steptypescript-publish.yml: add your package toPUBLISH_PACKAGES, the GitHub Releasepackagesarray, and the summary tablepython-ci.yml: add the backend to theCI_SIGNER_*gating inresolve-signersand to the integration matrixgo-ci.yml: add the backend to theCI_SIGNER_*gating and tomoduleBySigner
TypeScript Signer
If you’re also adding a TypeScript signer package, create it attypescript/packages/your-signer/. Key patterns:
- Factory function
createYourSigner()returnsSolanaTransactionSigner<TAddress> & SolanaMessageSigner<TAddress>; keep the signer class internal and export only the factory and its config type - Export config interface (
YourSignerConfig) - If your backend cannot sign messages, omit
SolanaMessageSignerand expose nosignMessagesmethod at all: Kit classifies signers by method presence, so a throwing stub would misclassify the signer - Enforce HTTPS on
apiBaseUrlconfig fields withassertHttpsUrl()from@solana/keychain-core - Make remote calls through
fetchSignerJson()from@solana/keychain-core, which owns error mapping, response sanitization, redirect rejection, and the default timeout - Sanitize any other remote API error text with
sanitizeRemoteErrorResponse()from@solana/keychain-core - Use
throwSignerError(SignerErrorCode.*, { cause, message })from@solana/keychain-core - Honor
config?.abortSignalin every signing method, threading it intofetchSignerJson()andsignBatchStaggered() - Validate
requestDelayMswithvalidateRequestDelayMs()and batch withsignBatchStaggered() - Add
@throwsJSDoc to factory functions listing error codes - Declare
@solana/*packages as peer dependencies at>=8.1.0 - Unit tests with vitest and mocked
fetch; integration tests withrunSignerIntegrationTestfrom@solana/keychain-test-utils
Sending Signers
If your provider rewrites the transaction or broadcasts server-side, its signature cannot be applied to the caller’s transaction, so it must be aSolanaSendingSigner instead of a SolanaTransactionSigner:
- Implement
signAndSendTransactions()and expose nosignTransactions(norsignMessages, unless the backend genuinely signs messages) - Honor
config?.abortSignal. Once the provider has accepted the create, report any failure (including an abort) asBROADCAST_UNCONFIRMEDcarrying the provider transaction id, with the abort reason kept ascause - Add a typed
createKeychainSigneroverload returning your sending-signer type - Exclude your backend from
KeychainKitPluginConfigintypescript/packages/kit-plugin/src/keychain-plugin.ts, since a sending signer cannot serve as a Kit clientpayeroridentity - Assert in unit tests that
isTransactionPartialSigner()is false andisTransactionSendingSigner()is true for your instances
Update Umbrella Package
Updatetypescript/packages/keychain/ (7 files to modify):
src/types.ts: AddYourSignerConfigto theKeychainSignerConfigdiscriminated unionsrc/create-keychain-signer.ts: Add the switch case (each backend package is loaded with a dynamicimport())src/resolve-address.ts: Add to the fast-path or fetch-path switch casesrc/index.ts: Add the config type, namespace, and factory function exportspackage.json: Add@solana/keychain-your-signer: "workspace:*"dependencytsconfig.json: Add{ "path": "../your-signer" }referencetypescript/scripts/test-treeshake-umbrella.mjs: Add your package toSIGNER_MARKERSand your factory toFACTORIES
never checks, so TypeScript will error
if you add to the union but miss a case. Run just ts-treeshake afterwards:
every package and the umbrella must stay tree-shakable.
Python Signer
Create the module atpython/src/solana_keychain/your_signer/ (__init__.py
plus signer.py). Key patterns:
- Subclass
SolanaSignerfromsolana_keychain.core(pubkeyproperty,async sign_message(),async is_available()) plus exactly one capability class:TransactionSigner(async sign_transaction()),ModifyingSigner(async modify_and_sign_transaction()) orSendingSigner(async sign_and_send_transaction()) - Export an
async create_your_signer()factory that awaitsinit()when the backend resolves its address remotely; before init, signing raisesSignerErrorCode.NOT_INITIALIZED - Export a config dataclass (
YourSignerConfig) with secrets markedfield(repr=False) - Enforce HTTPS on base-URL fields with
assert_https_url(), and route every request throughfetch_signer_json() - Verify the provider’s signature before returning it; use
signed_message_bytes()for the bytes a signature covers, never a hand-rolled version prefix - Register the backend in
_BACKENDSinpython/src/solana_keychain/keychain.py - If the backend needs a provider SDK, guard the import, raise an
ImportErrornamingpip install 'solana-keychain[your-signer]', declare the extra inpython/pyproject.toml, and never import the backend eagerly from the package root - Unit tests with pytest:
respxfor HTTP backends, stub clients for SDK backends, and a check that no secret appears instr()orrepr()of raised errors - Add a
make_your_signer()factory topython/tests/integration/test_live_signers.pyand register it in_MESSAGE_CAPABLE(or_TRANSACTION_ONLYfor backends withoutsign_message)
Go Signer
Each Go backend is its own module, atgo/signers/yoursigner/ with module path
github.com/solana-foundation/solana-keychain/go/signers/yoursigner/v2. See
go/signers/para/ for a reference. Key patterns:
- Implement
core.SolanaSigner(Pubkey(),SignMessage(ctx, message),IsAvailable(ctx)) plus exactly one capability interface:core.TransactionSigner,core.ModifyingSigner, orcore.SendingSigner. Capability is detected by type assertion, so a backend that cannot sign a transaction must carry noSignTransactionmethod at all - Export a
Configstruct and aNewconstructor (New(ctx, cfg)when the backend resolves its address remotely; before that, returncore.NewNotInitializedError) - Build HTTP clients with
core.NewHTTPClientorcore.ResolveHTTPClient, and validate base URLs withcore.NormalizeHTTPSBaseURL - Sign transactions with
core.SignTransactionWith, which signs the message bytes and attaches the signature; verify provider signatures withcore.VerifySignature - Return errors with
core.NewSignerError/core.WrapSignerErrorand stable codes such ascore.CodeSigningFailed - Unit tests with
httptest; integration tests inintegration_test.gobehind the//go:build integrationtag
Submission Checklist
Before submitting your PR:- Code compiles without warnings (
just build) - All tests pass (
just test) - Code is formatted/linting passes (
just fmt) - No hardcoded values or secrets in code
- Error messages are generic (no raw API response text)
- No
.expect()or.unwrap()on untrusted API responses - HTTP clients built from
HttpClientConfig(HTTPS enforced, timeouts set, redirects rejected) - Returned signatures verified against locally computed message bytes
- Follows naming conventions (snake_case for Rust and Python, camelCase for TypeScript)
- Integration tests added and
.env.exampleupdated - TypeScript, Python, and Go implementations included (or planned with maintainers)
- Umbrella packages updated (TypeScript umbrella, Python
_BACKENDS) - CI changes included
- Added to README.md supported backends and signer-capabilities tables
Implementation Tips
Error Handling
Always use the existingSignerError variants. Both Display and Debug on
SignerError are redacted, so keep messages generic and never include raw API
response data. Never use .expect() or .unwrap() on untrusted API responses:
Security Requirements
These are not suggestions: consumers pick a backend on the strength of them. If your provider makes one impossible, say so in the PR and in the repo’sdocs/SECURITY_MODEL.md.
- Verify what the provider signed. Compute the message bytes locally and verify the returned signature against them at your signer’s required position before attaching it. A signature that does not verify must fail, never be attached.
- Declare whether the provider broadcasts. If it executes server-side, implement the sending shape and return the signature that identifies the landed transaction. If the provider has no sign-only endpoint, make the backend sending-only rather than submitting behind the caller’s back.
- Never leave the caller holding a transaction the signature does not cover. A provider that rewrites the transaction signs its own bytes: either leave the caller’s transaction untouched (the broadcast-managed case), or take the modifying shape and replace it wholesale with the provider’s bytes.
- Report broadcast uncertainty as such. A failure after submission may still
have landed. Surface
BROADCAST_UNCONFIRMEDrather than a generic error, carry the provider transaction id whenever you have one, and send a message-derived idempotency key on every create so a byte-identical resend is safe. - Never sign before init. Use
Option<Pubkey>(notPubkey::default()) for the public key beforeinit(), and fail with a config error if signing is attempted first. - Never log sensitive data (private keys, API secrets, raw API responses), and
use a
Debugimpl that hides sensitive fields - Reject redirects. Build every HTTP client with
HttpClientConfig::build_client()(or start fromclient_builder()), neverreqwest::Client::builder(). It enforces HTTPS, sets request and connect timeouts (defaults: 30s/5s), and refuses redirects, so credential headers are never resent to a redirect target. In wiremock tests, replace the struct’s client with a plainreqwest::Client. - Zeroize intermediate key material with
zeroize::Zeroizing<Vec<u8>>
Testing with Mocks
Usewiremock for mocking HTTP APIs. Assert on error type only, not error
message text:
Getting Help
- Review existing signer implementations for patterns:
src/memory/mod.rs: Simple, synchronoussrc/privy/mod.rs: Requires initializationsrc/turnkey/mod.rs: Complex signature handlingsrc/vault/mod.rs: External client librarytypescript/packages/para/,python/src/solana_keychain/para/, andgo/signers/para/: complete references in the other languages
- Key files:
src/traits.rs(trait definitions),src/transaction_util.rsandsrc/signature_util.rs(shared helpers),src/http_client_config.rs(HTTP client builder: timeouts, HTTPS, no redirects) - The full repository guide: docs/ADDING_SIGNERS.md
- Open an issue for design discussions before starting work