Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created June 3, 2024 09:45
Show Gist options
  • Save WietseWind/78c90534b866bb59d5d78cacf48400f9 to your computer and use it in GitHub Desktop.
Save WietseWind/78c90534b866bb59d5d78cacf48400f9 to your computer and use it in GitHub Desktop.
256 bits, ED25519 keypair & XRPL account using 10-face dice roll, numbers 0-9 (78 throws)
import accountlib from 'xrpl-accountlib'
import assert from 'assert'
const requiredBits = 256
const requiredThrows = Math.ceil(requiredBits / Math.log2(10))
// Adapted from validator keypair dice tool by RichardAH
// https://github.com/RichardAH/validator-keys-from-dice/blob/main/dice.js
// Random (BAD RANDOM! BAD BAD BAD RANDOM! DO NOT EVER USE THIS!! TESTING PURPOSES ONLY!)
const dicerolls = Array(requiredThrows).fill().map(r => Math.floor(Math.random() * 10))
// const dicerolls = [
// 1, 1, 0, 3, 0, 0, 7, 7, 0, 9, // 10
// 2, 1, 0, 3, 4, 5, 7, 7, 8, 9, // 20
// 3, 1, 0, 3, 4, 5, 7, 7, 8, 9, // 30
// 4, 1, 0, 3, 4, 5, 7, 7, 8, 9, // 40
// 5, 1, 0, 3, 4, 5, 7, 7, 8, 9, // 50
// 6, 1, 0, 3, 4, 5, 7, 7, 8, 9, // 60
// 7, 1, 0, 0, 4, 0, 7, 0, 8, 9, // 70
// 8, 9, 8, 1, 2, 3, 4, 9 // 78
// ]
assert(dicerolls.length >= requiredThrows, 'Invalid # of dice rolls, min. throws: ' + requiredThrows)
const bnumber = BigInt(dicerolls.join('')).toString(2 /* binary */).padStart(requiredBits, '0').slice(-requiredBits)
const bnumhex = BigInt(`0b${bnumber}`).toString(16 /* hex */).padStart(requiredBits / 4, '0').slice(-(requiredBits / 4))
const account = accountlib.derive.privatekey(`ED${bnumhex.toUpperCase()}`)
console.log(account.keypair.privateKey)
console.log(account.address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment