Skip to content
This repository was archived by the owner on Jul 12, 2026. It is now read-only.

Introduce secret accessor flag and zeroize memory during cleanup#204

Open
HudsonGraeme wants to merge 4 commits into
RaoFoundation:stagingfrom
inference-labs-inc:restrict/secret-accessor-visibility
Open

Introduce secret accessor flag and zeroize memory during cleanup#204
HudsonGraeme wants to merge 4 commits into
RaoFoundation:stagingfrom
inference-labs-inc:restrict/secret-accessor-visibility

Conversation

@HudsonGraeme

Copy link
Copy Markdown
  • Adds a new compile flag that by default does not include getters for sensitive values. Downstream consumers who require access to sensitive fields can use the secret-access flag to opt-in if they need to access those values. This is useful, for example, in subnets where validator code never needs to directly access the private aspects of hotkeys but still requires the ability to sign transactions, read the ss58 and sign payloads.

Caution

This is a breaking change for downstream consumers if the build does not explicitly enable the flag. To avoid this, the flag can be added to defaults however it appears to be safer to leave it out.

  • Implements zeroize to explicitly clear RAM during cleanup, rather than leaving it up to the OS to clear sensitive information from memory.

Branch updated to the latest staging with conflicts resolved. Verified: cargo test (47 passing, default and secret-access features) and the Python suite (81 passing across keypair, keyfile, wallet, utils, legacy).

Keypair::private_key(), ::mnemonic(), ::seed_hex() gated behind the
"secret-access" cargo feature. Enabled: pub. Disabled (default): pub(crate).
External consumers opt in explicitly; internal serialization in keyfile.rs
and wallet.rs compiles unchanged via pub(crate) fallback.

Custom Drop impl overwrites private_key, seed_hex, and mnemonic fields
via zeroize before deallocation, preventing secret residue in freed heap
memory. sr25519::Pair is set to None on drop (does not implement Zeroize).

Struct update syntax (..Default::default()) replaced with explicit field
initialization to satisfy Rust's move-out restriction on Drop types.
The pair branch returned raw key bytes via to_raw_vec() while the
self.private_key branch returned UTF-8 bytes of the hex string via
as_bytes(). Downstream serialization in keyfile.rs hex-encodes the
result, producing double-encoded output in the fallback path.
Both branches now consistently return decoded raw bytes.
…essor-visibility

Resolve conflicts in src/keypair.rs by integrating ED25519 multi-crypto
support from staging with the zeroize-on-drop secret accessor restriction.
Replace ..Default::default() struct-update syntax with explicit field
initialization in create_from_mnemonic, create_from_seed,
create_from_private_key, create_from_uri, and the encrypted-JSON ED25519
branch to satisfy Rust's move-out restriction on the Drop-implementing
Keypair.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant