H5: Use pubkey hash for storage paths (V3+) and zero sensitive bytes#915
Open
DavidGershony wants to merge 2 commits into
Open
H5: Use pubkey hash for storage paths (V3+) and zero sensitive bytes#915DavidGershony wants to merge 2 commits into
DavidGershony wants to merge 2 commits into
Conversation
DeriveLeadInvestorSecretHash: - V3+: hash only the derived public key (no private material needed) - V1/V2: zero the ExtKey byte array in a finally block after hashing DeriveNostrStoragePassword: - Zero the private key byte array in a finally block after hashing - Remove redundant .Replace/ToLower (Encoders.Hex already returns lowercase) These changes ensure sensitive key material doesn't linger in memory after use, reducing the window for memory-scraping attacks.
dangershony
reviewed
Jul 7, 2026
| if (projectVersion >= 3) | ||
| { | ||
| // V3+: Hash only the public key (deterministic, doesn't expose private key bytes) | ||
| var pubKeyBytes = extPubKey.PubKey.ToBytes(); |
Member
There was a problem hiding this comment.
this is deriving the secret hash, if we derive using the pubkey and the pubkey is leaked then anyone can derive the hash no?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Avoid exposing private key bytes in derivation paths and ensure all sensitive byte arrays are zeroed after use.
Changes
DeriveLeadInvestorSecretHash
finallyblockDeriveNostrStoragePassword
finallyblock after hashing.Replace("-", "").ToLower()(Encoders.Hex.EncodeDataalready returns lowercase hex without dashes)Rationale
Private key bytes left unzeroed in managed memory can be read by memory-scraping malware or appear in crash dumps. By zeroing them immediately after use and (for V3+) avoiding private key bytes entirely, we reduce the attack surface.
Testing
All 154 shared tests pass. V1/V2 derivation produces the same hash output as before (backward compatible).