seeded-mnemonic
v0.1.0
Published
Seeding entropy in the creation of Mnemonic Phrases
Downloads
2
Readme
Seeded Mnemonic
Seeded Mnemonic is a simple library for seeding entropy in the creation of Mnemonic Phrases.
This library supports any non-empty string, or file, being passed as input, utilizing that input in place of entropy in the generation of mnemonic phrases for Ethereum, Bitcoin, and Solana, at lengths of 12, 18, and 24 words.
When the input is received, and prior to conversion to bits, a cryptographic hash of the input is generated. The hashing algorithm used is dependent on the blockchain selected when calling the seededMnemonic
function. This hash will act as entropy in the creation of the mnemonic phrase.
- For Ethereum, a Keccak-256 hash of the input is generated.
- For Bitcoin, a SHA-256 hash of the input is generated.
- For Solana, a SHA-512 hash of the input is generated.
After the entropy is generated, it is converted to binary and truncated to 128, 192, or 256 bits, depending on if a 12, 18, or 24-word mnemonic phrase is desired. The truncated entropy is then converted into a byte array, and hashed using SHA-256. A checksum is generated by extracting the first 4, 6, or 8 bits of the hash, which are appended to the end of the truncated entropy. Finally, the resulting string of bits is divided into segments of 11 bits each, with each segment corresponding to a word in the BIP39 wordlist, resulting in the mnemonic phrase.
Installation
npm install seeded-mnemonic
Usage
The following example demonstrates the use of the library to create a 12-word Ethereum mnemonic phrase using the string "Just be a rock." in place of entropy.
const { seededMnemonic } = require('seeded-mnemonic');
const input = "Just be a rock.";
const result = seededMnemonic.string(input, 12, 'ETH');
console.log(`Mnemonic Phrase:`, result.seedPhrase);
This next example utilizes seededMnemonic.fs()
to use a file as input in mnemonic phrase generation, in this case, a JSON file example.json
, to create an 18-word Solana mnemonic phrase.
const { seededMnemonic } = require('seeded-mnemonic');
const input = './example.json';
const result = seededMnemonic.fs(input, 18, 'SOL');
console.log(`Mnemonic Phrase:`, result.seedPhrase);
Finally, this last example demonstrates the use of the seededMnemonic.string()
to create a 24-word Bitcoin mnemonic phrase using text randomly generated by a simulated monkey using a typewriter, along with returning the bits obtained from the input/used for creating the mnemonic phrase.
const { seededMnemonic } = require('seeded-mnemonic');
const input = "IEINFULLXLLUKHHBFAGBLFLEHFWODUNGALDRQWHRAUL";
const result = seededMnemonic.string(input, 24, 'BTC', { returnBits: true });
console.log(`Mnemonic Phrase:`, result.seedPhrase);
console.log(`Bits:`, result.bits);