data.mnemonic #
BIP39 (mnemonic)
This is a pure v-lang implementation of BIP39.
WARNING: seed generation is not supported yet, only mnemonic to entropy and vice-versa is supported.
Wordlists
Only English
is supported right now and is embeded on compile time. Wordlist comes from official bitcoin/bip-0039/english.txt
.
Mnemonic
The module needs to be instanciated with:
m := mnemonic.new()!
Possible error are wordlist parsing issue.
Get entropy from mnemonic
words := "winter hire open opinion frown turtle this bulb mouse spell endorse thumb regret useless expand nerve improve impulse"
entropy := m.to_entropy(words)
Get mnemonic from entropy
entropy := m.generate_entropy(224)! // or your own entropy buffer
words := m.to_mnemonic(entropy)!
Tests
In order to validate implementation, tests vector from python-mnemonicvectors.json is included.
This is implemented via mnemonic_test.v
fn debug #
fn debug() !bool
small debug and example
fn dumps #
fn dumps(buffer []u8) string
fn new #
fn new() !BIP39
fn parse #
fn parse(mnemonic string) []u8
struct BIP39 #
struct BIP39 {
mut:
wordlist string
words []string
}
pure v implementation of BIP39 following specification from https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
fn (BIP39) to_entropy #
fn (b BIP39) to_entropy(mnemonics string) ![]u8
parse mnemonic
fn (BIP39) generate_entropy #
fn (b BIP39) generate_entropy(size int) ![]u8
create mnemonic
fn (BIP39) compute_checksum #
fn (b BIP39) compute_checksum(entropy []u8) string
fn (BIP39) generate_binary_from_entropy #
fn (b BIP39) generate_binary_from_entropy(entropy []u8) !string
fn (BIP39) to_mnemonic #
fn (b BIP39) to_mnemonic(source []u8) ![]string
fn (BIP39) generate #
fn (b BIP39) generate(size int) ![]string
fn (BIP39) to_seed #
fn (b BIP39) to_seed(words string, passphrase string) ![]u8
seed