Skip to content

Instantly share code, notes, and snippets.

@sstone
Created August 17, 2015 17:43
Show Gist options
  • Save sstone/d0dc7c0295d0bf3797a2 to your computer and use it in GitHub Desktop.
Save sstone/d0dc7c0295d0bf3797a2 to your computer and use it in GitHub Desktop.
creating keys and addresses
mvn scala:console
scala> import fr.acinq.bitcoin._
import fr.acinq.bitcoin._
scala> val random = new scala.util.Random
random: scala.util.Random = scala.util.Random@54d1608f
scala> val key:BinaryData = new Array[Byte](32)
key: fr.acinq.bitcoin.BinaryData = 0000000000000000000000000000000000000000000000000000000000000000
scala> random.nextBytes(key)
scala> key
res3: fr.acinq.bitcoin.BinaryData = 85692ba2b4574abaa9ddb151198e9f27077d85606e6037abebcb3c2ef008a62d
scala> val pub:BinaryData = Crypto.publicKeyFromPrivateKey(key)
pub: fr.acinq.bitcoin.BinaryData = 04b590151d0dd34637a08ecbeba06a94691e4a3e14cfcf1c5cffad668a788a91e352d0ba8077d8b6ca8b70bb4070076c24395686e6598ea7a3bf32227d131c32f7
scala> val pub:BinaryData = Crypto.publicKeyFromPrivateKey(key :+ 1.toByte)
pub: fr.acinq.bitcoin.BinaryData = 03b590151d0dd34637a08ecbeba06a94691e4a3e14cfcf1c5cffad668a788a91e3
scala> val address = Base58Check.encode(0x6f.toByte, Crypto.hash160(pub))
address: String = muy4AHZSohQfm55M4uQHe9XGdrfU8Lk5Q2
scala> Base58Check.encode(0xef.toByte, key :+ 1.toByte)
res4: String = cS42yUNDbLyV6MaFUK4D7JGGBvBwvqGq7Zcks8niGaMhckxXjWL8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment