Skip to content

Create Codephrase struct and newtypes for it - #36

Merged
emilyalbini merged 10 commits into
omicron-integrationfrom
ea-codephrases
Aug 12, 2026
Merged

Create Codephrase struct and newtypes for it#36
emilyalbini merged 10 commits into
omicron-integrationfrom
ea-codephrases

Conversation

@emilyalbini

Copy link
Copy Markdown
Member

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 Codephrase struct, which wraps the raw U256. 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 Codephrase across 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.

@emilyalbini
emilyalbini requested a review from plotnick August 11, 2026 17:39
Also self-qualify the newtype macro's formatter types, so call sites
need no imports of their own.

@plotnick plotnick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@emilyalbini
emilyalbini merged commit 6943159 into omicron-integration Aug 12, 2026
5 checks passed
@emilyalbini
emilyalbini deleted the ea-codephrases branch August 12, 2026 07:53
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