Skip to content

Instantly share code, notes, and snippets.

@lukechilds
Last active August 7, 2026 08:09
Show Gist options
  • Select an option

  • Save lukechilds/410b932f33121d7594c2693bae1b94a5 to your computer and use it in GitHub Desktop.

Select an option

Save lukechilds/410b932f33121d7594c2693bae1b94a5 to your computer and use it in GitHub Desktop.

Verify Coldcard dice roll to seed logic

https://coldcardwallet.com/docs/verifying-dice-roll-math

const bip39 = require('bip39');
const crypto = require('crypto');

const diceRollsToMnemonic = diceRolls => {
  const entropy = crypto.createHash('sha256').update(diceRolls).digest();

  return bip39.entropyToMnemonic(entropy);
}

diceRollsToMnemonic('123456');
// 'mirror reject rookie talk pudding throw happy era myth already payment own sentence push head sting video explain letter bomb casual hotel rather garment'

Verify Coldcard dice roll seed extension logic

const bip39 = require('bip39');
const crypto = require('crypto');

const extendMnemonicWithDiceRolls = (initialMnemonic, diceRolls) => {
  const initialEntropy = Buffer.from(bip39.mnemonicToEntropy(initialMnemonic), 'hex');
  const resultingEntropy = crypto.createHash('sha256').update(initialEntropy).update(diceRolls).digest();
  
  return bip39.entropyToMnemonic(resultingEntropy);
};

extendMnemonicWithDiceRolls('choose charge drastic boring trip critic planet world ramp embrace oppose rate neck list since mimic faint will abandon shoulder broken crater arctic sure', '123456');
// 'floor awkward clarify ahead sketch income birth polar cushion inform wild cook mandate admit dentist outer abuse sunset online stable surprise ocean cruise pool'

Encode 256 bits from Node.js RNG as dice rolls

const crypto = require('crypto');
const baseX = require('base-x');

const DICE_ALPHABET = '123456';
const baseDice = baseX(DICE_ALPHABET);

const entropy = crypto.randomBytes(32);

baseDice.encode(entropy);
// '363465153645613463156564415631654136211656615513251335612354364323551534626422233324166225255413326'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment