View Source Private keys

The private key is your identity. You can use it to receive and spend funds, as well as view how much is associated with it. Banks ask for documents to prove who you are. In Bitcoin, all that's required is a very very large number that you can issue by yourself. The more random the number, the more secure are your funds.

The way BitcoinLib deals with this is by creating entropy from dice rolls and then convert it into either a 12 or 24 words seed phrase.


Seed phrase from dice rolls

99 dices

BitcoinLib offers a way to generate very random entropy by rolling 50 or 99 dices, depending on the level of security you're after. These will introduce either 2¹³² or 2²⁶⁴ possibilities, based on the number of rolls.

To get to a private key creation, we first need a seed phrase. Dice rolls will thus be converted into words. These two notations are equivalent. Note here that every dice roll value has been reduced by 1 so that values range from 1 to 6.

alias BitcoinLib.Key.HD.SeedPhrase

|> SeedPhrase.from_dice_rolls()

This is the result

"blue involve cook print twist crystal razor february caution private slim medal"


Private key from seed phrase

This seed phrase can then be converted into a private key

alias BitcoinLib.Key.PrivateKey

private_key = 
  "blue involve cook print twist crystal razor february caution private slim medal"
  |> PrivateKey.from_seed_phrase()

To keep things simple, we won't bother about what's returned as a private key... just know that this thing has full access to the wallet that's about to be created in the next steps.



A private key can be serialized into an xprv

|> PrivateKey.serialize

which results in


and can then be imported in a wallet, which will have full access to the funds