Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 915 Bytes

README.md

File metadata and controls

38 lines (24 loc) · 915 Bytes

secp256k1-scala

An (almost) dependency-free scala implementation of ecc arithmetic for the curve used by bitcoin (secp256k1).

Usage

  1. install scala-cli (if using Nix this is as easy as nix-shell -p scala-cli)
  2. scala-cli repl .
import Secp256k1.*

// demonstrating ECDH whereby Alice and Bob calculate a shared secret

// a very secure private key chosen by Alice
// private keys are values in prime field Z_n
val a = Z_n(12345)

val pointA = a * G

// also a great choice of private key by Bob
val b = Z_n(54321)

val pointB = b * G

val sharedSecretB = b * pointA
val sharedSecretA = a * pointB

assert(sharedSecretB == sharedSecretA)
  1. or you can run the tests: scala-cli test .

Disclaimer - do not use with real funds

This implementation is for learning purposes. Use bitcoin-core/secp256k1 for any real-world needs.