Skip to content

Conversation

@vnprc
Copy link
Contributor

@vnprc vnprc commented Oct 10, 2025

Description

Hard coding currency units and their corresponding derivation paths for deterministic secrets is an unsustainable strategy because it forces us to update all cashu implementations for each new currency unit. We've gotten away with it this far because cashu only supports a limited set of currencies, with sats being the most popular by far.

Ehash will have very different requirements because each mining epoch (time in between mining rewards) will use a different currency unit. So we need a way to dynamically map currency units to derivation paths.

This PR introduces an algorithm to deterministically generate a derivation path based on the currency unit name.

First, some code cleanup. This PR moves the currency unit code from the nut00 crate to nut01 where it belongs. (The spec was updated after the initial cdk CurrencyUnit implementation.)

Now to business: we force all currency unit names to uppercase and calculate the derivation path in this way:

  • normalize unicode characters to NFC format
  • lowercase (probably change to uppercase)
  • trim
  • SHA256 hash
  • modulo 2^31 - 1

Opening this draft PR to get initial feedback on the implementation. I will also open a NUT PR to propose this new specification.


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

@vnprc vnprc marked this pull request as draft October 10, 2025 15:57
// canonical code point (e.g., "é") so visually/equivalently identical strings hash the same
// 2) lowercase: avoids case-induced divergence ("USD" vs "usd")
// 3) trim: removes accidental leading/trailing whitespace (" usd " vs "usd")
let norm = s.nfc().collect::<String>().to_lowercase();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to uppercase

@vnprc vnprc marked this pull request as ready for review November 17, 2025 19:13
@vnprc vnprc force-pushed the deterministic-cu-dp branch from ea05e76 to 4853efc Compare November 17, 2025 21:03
@thesimplekid
Copy link
Collaborator

think #1257 takes care of this

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.

2 participants