Create Codephrase struct and newtypes for it - #36
Merged
Conversation
emilyalbini
force-pushed
the
ea-codephrases
branch
from
August 11, 2026 17:40
e98cabd to
991ea72
Compare
Also self-qualify the newtype macro's formatter types, so call sites need no imports of their own.
plotnick
approved these changes
Aug 12, 2026
Collaborator
There was a problem hiding this comment.
This is fantastic work, thank you! I ❤️ the newtypes especially; I was just starting to worry about them, and now you've removed that worry.
I took the liberty of pushing two small commits that were so nitpicky I didn't even want to bother you with them, so I had the 🤖 do it instead. Please feel free to adjust as needed. I need to write a tiny house style guide so that at least my crazy is written down somewhere.
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.
Before this PR, codephrases were represented in the codebase as
Strings, and freestanding functions were used to generate and parse them. This was slightly unwieldy to work with, and for the integration in permslip I wanted to have stronger typing.This PR replaces all of that with a new
Codephrasestruct, which wraps the rawU256. Converting from and to the codephrase representation now happens at ser/de time transparently.To increase type safety, and to clearly delineate which codephrases are truncated and which are full, instead of using
Codephraseacross the codebase this also adds a macro to create newtypes of it, and creates a newtype for each use of it.The only functional change compared to the previous implementation is how truncated codephrases are actually truncated. Before, we were always including 8 words, regardless of how many bits of randomness they represent, while the new implementation truncates the randomness at 88 bits. In practice, this results in 8 words 99.95% of the time and 7 words 0.05% of the time (never 9 words). I don't think this is a problem, as 88 bits was the randomness we were targeting anyway.
This PR is best reviewed commit-by-commit.