View Source BitcoinLib.Crypto.Secp256k1 (BitcoinLib v0.2.0-pre3)
Elliptic curve cryptography
Based on https://hexdocs.pm/curvy/Curvy.html
Link to this section Summary
Functions
Add two keys on the elliptic curve using Jacobian Point mathematics
Signs a message using a private key
Validates a signature
Link to this section Functions
Add two keys on the elliptic curve using Jacobian Point mathematics
examples
Examples
iex> key1 = <<0x2E65A9C40338B8D07D72CD82BF3C9DDD0375F362863BC0808E6AD194F19F5EBA0::264>> ...> key2 = <<0x2702DED1CCA9816FA1A94787FFC6F3ACE62CD3B63164F76D227D0935A33EE48C3::264>> ...> BitcoinLib.Crypto.Secp256k1.add_keys(key1, key2) <<0x2FC5BA55A539899D67EE66E99EE50AB59DCCBB122025D18C5EB9446D380A9EC0A::264>>
@spec sign(binary(), %BitcoinLib.Key.PrivateKey{ chain_code: term(), depth: term(), fingerprint: term(), index: term(), key: term(), parent_fingerprint: term() }) :: bitstring()
Signs a message using a private key
Below is an example of a signature... this doctest doesn't end with a value, because the signature is different on every call, and even can have different lengths.
examples
Examples
iex> message = "76a914c825a1ecf2a6830c4401620c3a16f1995057c2ab88ac" ...> private_key = %BitcoinLib.Key.PrivateKey{key: <<0xd6ead233e06c068585976b5c8373861d77e7f030ec452e65ee81c85fa6906970::256>>} ...> BitcoinLib.Crypto.Secp256k1.sign(message, private_key)
@spec validate( bitstring(), bitstring(), %BitcoinLib.Key.PublicKey{ chain_code: term(), depth: term(), fingerprint: term(), index: term(), key: term(), parent_fingerprint: term(), uncompressed_key: term() } | bitstring() ) :: boolean()
Validates a signature
examples
Examples
iex> signature = <<0x3044022048b3b0eb98ae5f2c997e41a2630a5e3512f24a1f5b6165e2867847a11b2b22350220032211844eec911dab6d91836a45c37ca1d498433d87b6b09e2f401025131a05::560>> ...> message = "76a914c825a1ecf2a6830c4401620c3a16f1995057c2ab88ac" ...> public_key = %BitcoinLib.Key.PublicKey{key: <<0x02702ded1cca9816fa1a94787ffc6f3ace62cd3b63164f76d227d0935a33ee48c3::264>>} ...> BitcoinLib.Crypto.Secp256k1.validate(signature, message, public_key) true