NAME

App::FuguSeed::Mnemonic - the word checks and the BIP39 checksum

SYNOPSIS

use App::FuguSeed::Mnemonic;

my @words = split q{ }, $line;
my $fault = App::FuguSeed::Mnemonic->fault(\@words, 12);
die "$fault\n" if defined $fault;

my @index    = App::FuguSeed::Mnemonic->indexes(\@words);
my $checksum = App::FuguSeed::Mnemonic->checksum(@index);

DESCRIPTION

App::FuguSeed::Mnemonic holds the parts of the seed words that fuguseed-last and fuguseed-qr both call. It proves the count and the list membership of the words, it gives the index of each word, and it computes the BIP39 checksum.

Every method is a class method, and every method is pure: it takes values and it returns values. The module touches no stream, so a caller prints the failure message itself. A message names a count or a word position, never a word.

The module runs on core Perl v5.34 with Digest::SHA alone, because scripts/pack embeds it in fuguseed-last and fuguseed-qr.

fault

fault($words, $count) returns the failure message for the words of the array reference $words, or undef when the words pass the check. The input must hold exactly $count words, and each word must be in the list of App::FuguSeed::List.

indexes

indexes($words) returns the 0-based list index of each word, in word order.

checksum

checksum(@index) returns the 4 checksum bits of 12 indexes, as a number from 0 to 15. The 12 indexes give 132 bits, and the first 128 bits are the entropy. The checksum is the first 4 bits of the SHA-256 of the 16 entropy bytes. The low 4 bits of index 12 are no part of the entropy, so they do not change the result.

RETURN VALUES

fault() returns undef for $count words of the list. indexes() returns one number for each word, and checksum() returns one number.

ERRORS

indexes() and checksum() expect words of the list. With another input, the caller gets a warning of Perl and a result without meaning. Call fault() first.

SEE ALSO

App::FuguSeed::List, App::FuguSeed::Last, App::FuguSeed::QR, and the BIP39 specification.

AUTHORS

Dick Olsson <hi@senzilla.io>