Last active
April 15, 2025 15:21
-
-
Save kdmukai/1a666c945c46ada120fd2cd3c5a1f33c to your computer and use it in GitHub Desktop.
Revisions
-
kdmukai revised this gist
Apr 15, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def get_mnemonic_from_coin_flip_indices(coin_flips: str, wordlist_language_code: # convert bit string to bytes coin_flip_bytes = bytearray() for i in range(0, len(coin_flips), 8): # convert 8 bits to an integer index = int(coin_flips[i:i + 8], 2) # convert the index to a byte coin_flip_bytes.append(index) -
kdmukai created this gist
Apr 15, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ def get_mnemonic_from_coin_flip_indices(coin_flips: str, wordlist_language_code: str = SettingsConstants.WORDLIST_LANGUAGE__ENGLISH) -> list[str]: """ Interprets a string of 128 or 256 0s and 1s as 11-bit bip39 wordlist indices and returns the 12- or 24-word mnemonic. Indices are 0-based (i.e. b'00000000000' == 0000 == "abandon") Verify with iancoleman.io/bip39 using: * "Binary" mode * "Mnemonic Length" = "Use raw entropy" """ if len(coin_flips) not in [128, 256]: raise Exception("Coin flip string must be 128 or 256 bits") # convert bit string to bytes coin_flip_bytes = bytearray() for i in range(0, len(coin_flips), 8): # convert 11 bits to an integer index = int(coin_flips[i:i + 8], 2) # convert the index to a byte coin_flip_bytes.append(index) # Convert the indices to their associated words. The final word will consist of the # last bits of the provided entropy plus the checksum which will be automatically # added by the method below. return bip39.mnemonic_from_bytes(coin_flip_bytes, wordlist=Seed.get_wordlist(wordlist_language_code)).split()