Skip to content

Instantly share code, notes, and snippets.

@asluchevskiy
Created January 12, 2025 18:17
Show Gist options
  • Save asluchevskiy/3ab66f65cc7f10ec25df7c32a17b4fab to your computer and use it in GitHub Desktop.
Save asluchevskiy/3ab66f65cc7f10ec25df7c32a17b4fab to your computer and use it in GitHub Desktop.
Pure python BIP39 seed generator
import os
import hashlib
def new_seed() -> list:
# https://raw.githubusercontent.com/bitcoin/bips/refs/heads/master/bip-0039/english.txt
with open(os.path.join(os.path.dirname(__file__), 'bip39', 'english.txt'), "r") as f:
wordlist = f.read().splitlines()
entropy = os.urandom(16) # 128 bit, 12 words
checksum = hashlib.sha256(entropy).digest()
entropy_with_checksum = entropy + checksum[:1]
bits = "".join(f"{byte:08b}" for byte in entropy_with_checksum)
words = [wordlist[int(bits[i:i + 11], 2)] for i in range(0, len(bits), 11)]
return words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment