Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature] Entropy-to-mnemonic CLI utility #404

Merged
merged 14 commits into from
Apr 12, 2024

Conversation

kdmukai
Copy link
Contributor

@kdmukai kdmukai commented Jul 17, 2023

  • Makes our existing mnemonic_generation.py accessible as an interactive CLI utility (in tools/mnemonic.py) for converting dice rolls or coin flips into 12- or 24-word mnemonics.
  • Also provides a UI for final word calculation.
  • Removes need to always specify wordlist_language_code.
  • Adds flexibility for calculate_checksum to accept mnemonic as list or string w/various delimiters.
  • python3.10 updates to typing.
  • Adds constants for number of dice rolls for each mnemonic phrase length (since 99 may become 100 soon).
  • Generates test dice rolls, coin flips, or word selections via its "rand12" and "rand24" option.
  • Adds support for coin flips, even though the SeedSigner UI does not support coin flips yet (and might not ever).
  • Updates dice_verification.md accordingly.
  • New test cases / streamlined test case.




if __name__ == "__main__":
Copy link

Choose a reason for hiding this comment

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

Besides another sole instance in settings_definitions.py, nowhere else in our codebase are we already using this convention -- of an executable cli/library. Would this entire if __name__ == "__main__": block be more at home in tools/???

I tried moving this "main" block into tools/mnemonic_generation.py. It makes importing seedsigner a strange hack... but if user installed seedsigner locally, it would just be adding a from seedsigner.helpers.mnemonic_generation import * and then we wouldn't have cli code that exists in the standard codebase except where users clone the repo.

It's just a thought, I'm still not sure. It's so common while prototyping, maybe less common in production unless users can normally use it (not the case for code in seedsigner-os).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the concern/goal is to keep the CLI code out of the standard release package, I think there are better ways to package it (e.g. its own dir outside of src that isn't included in a release or a dir in src that is explicitly excluded from the build process).

That being said, for now I like the directness of the organization here: this file does X for SeedSigner, run its CLI to play with X interactively yourself. No imports (aside from embit) or redirects or obfuscation. This code does X. Period.

Copy link

Choose a reason for hiding this comment

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

I hereby withdraw my comments above.

I too see the value in the way it is all-in-one. Can verify dice rolls with the exact file that seedsigner is using.

@jdlcdl jdlcdl mentioned this pull request Jul 21, 2023
@kdmukai kdmukai force-pushed the entropy_to_mnemonic_cli branch from babeebe to ca660a6 Compare August 7, 2023 15:06
@jdlcdl
Copy link

jdlcdl commented Aug 7, 2023

I've had no problems duplicating seedwords while doing so w/ dice labeled 1-6.


However for coins, when running for a 24w seed:

python3 mnemonic_generation.py coins 0101000101010011000101110110000111101100011110100111001110001001010001101110000010111001111101000110101110110001000100110010000010100110100101010100100101010100001100001110001101000101110000010100111100000001101011011000101100111011100010011000101001101101

I get:

welcome occur core ride below sock convince start song car alcohol question scorpion smart gloom doctor champion acoustic universe camera endorse goddess oyster prefer

while I was expecting:

eyebrow obvious such suggest poet seven breeze blame virtual frown dynamic donor harsh pigeon express broccoli easy apology scatter force recipe shadow claim radio

and similarly for a 12w made from coins:

python3 mnemonic_generation.py coins 01101100101100001001101011111000010101010000010100001101110011011110011011111110001010101101110000110001100000011100001001010000

I get:

wise forget cinnamon clump news shadow loan power portion insect lobster radar

while I was expecting:

hole luggage safe present express tragic orbit shed switch metal identify path

I'm also having a problem with the --zero-indexed-dice option

python3 mnemonic_generation.py dice --zero-indexed-dice 54404112020541021050022043333012505355332001042330

I get:

jealous inhale song chaos finger adult mutual tourist cash error broccoli lock

While I was expecting to get the same as above... because, I'm not sure, I was thinking that each roll would just be reduced by 1 and then they'd all be hashed at the end.

Ian Coleman gives me two different mnemonics depeding on interpretation; when I select "Base 10" I get:

link rack captain doctor drama replace apple beyond strategy lens bachelor raise

and when I select "Hex" I get:

doctor ancient letter appear awake amused divorce dune drip office afraid pass crystal office length calm case love

@kdmukai
Copy link
Contributor Author

kdmukai commented Aug 8, 2023

@jdlcdl:

For your first example, to reproduce the same coin flips in iancoleman.io, you have to change "Mnemonic length" from "Use Raw Entropy (3 words per 32 bits)" to "24 Words".

I'm also having a problem with the --zero-indexed-dice option

For zero-indexed dice rolls, you can use Base6, Base10, or Hex and, again, specify "Mnemonic Length" as "12 Words".

I've updated the documentation with this info.

@jdlcdl
Copy link

jdlcdl commented Aug 8, 2023

ACK tested

Yes, I did test this, and yes, I did ACK this 3 days ago. But I have additional thoughts expressed below... so I take back my ACK. I'll try not to make this a habit.

@kdmukai kdmukai force-pushed the entropy_to_mnemonic_cli branch from 30da08a to 3bca811 Compare August 11, 2023 13:44
@jdlcdl
Copy link

jdlcdl commented Aug 11, 2023

In the meeting this morning, I shared the thought of waiting to merge this until after the next release.

It's about "Let's not over-feed the concern-trolls with code changes that include lots of refactoring just before release on a code file named 'mnemonic_generation.py'".

Also, after looking at the code, while I'm not concerned, I wonder... "Does import random and random.randint() belong anywhere in our codebase?". and I'm not sure that it really does... if for nothing other than to avoid the "concern trolling". We could just let the user generate their own less-than-ideal entropy instead of doing that for them.

Maybe this code deserves many-many ACKs before it's considered for merge?

@kdmukai
Copy link
Contributor Author

kdmukai commented Aug 11, 2023

@jdlcdl this is a great point about the random import. At a minimum it should be moved to the CLI-only section.

But for the CLI's stated use case (interactive testing, confirmation, etc) I think some way to generate new test seeds is useful. And note that the usage does include:

Entropy data. Enter "{ RAND_12 }" or "{ RAND_24 }" to create a random (not-secure) example seed.

@jdlcdl
Copy link

jdlcdl commented Sep 12, 2023

Now that Release 0.7.0 is out, so that peers will have plenty of time to review this otherwise sensitive code:

As of fe55ccd

ACK tested.

@newtonick
Copy link
Collaborator

@kdmukai can you resolve the conflict in this PR? Thanks!

@newtonick
Copy link
Collaborator

This PR is pending some slight refactoring to move the cli utility out of src and into tools.

@kdmukai
Copy link
Contributor Author

kdmukai commented Jan 28, 2024

Updated! Moved CLI functionality into tools/ and updated the docs and related impacted files.

kdmukai added 11 commits March 2, 2024 07:46
* Makes our existing mnemonic_generation.oy accessible as an interactive CLI utility for converting dice rolls or coin flips into 12- or 24-word mnemonics as well as the final word calculation.
* Reduces python dependencies in mnemonic_generation.py
* Removes need to always specify `wordlist_language_code`.
* Adds constants for number of dice rolls for each mnemonic phrase length (since 99 may become 100 soon).
* Generates test dice rolls, coin flips, or word selections via its "rand12" and "rand24" option.
* Adds support for coin flips, even though the SeedSigner UI does not support coin flips yet (and might not ever).
* Updates dice_verification.md accordingly.
@kdmukai kdmukai force-pushed the entropy_to_mnemonic_cli branch from 3addd5c to 1ed703b Compare March 2, 2024 13:46
@kdmukai
Copy link
Contributor Author

kdmukai commented Mar 2, 2024

@newtonick the "needs revision" tag can be removed.

PR has been updated to what I consider a "final" form (pending further feedback).

@newtonick
Copy link
Collaborator

Tested and LGTM

@newtonick newtonick merged commit c12f64e into SeedSigner:dev Apr 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged Not Yet Released
Development

Successfully merging this pull request may close these issues.

3 participants