starkbank_ecdsa v1.0.0 EllipticCurve.Ecdsa View Source

Used to sign and verify signatures using the Elliptic Curve Digital Signature Algorithm (ECDSA)

Functions:

  • sign()
  • verify?()

Link to this section Summary

Functions

Generates a message signature based on a private key

Verifies a message signature based on a public key

Link to this section Functions

Link to this function

sign(message, privateKey, options \\ [])

View Source

Generates a message signature based on a private key

Parameters:

  • message [string]: message that will be signed
  • privateKey [%EllipticCurve.PrivateKey.Data]: private key data associated with the signer
  • options [keyword list]: refines request

    • hashfunc [:method]: defines the hash function applied to the message. Must be compatible with :crypto.hash. Default: :sha256;

Returns signature:

  • signature [string]: base-64 message signature;

Example:

iex> EllipticCurve.Ecdsa.sign("my message", privateKey)
"MEQCIFp2TrQ6RlThbEOeYin2t+Dz3TAebeK/kinZaU0Iltm4AiBXyvyCTwgjOBo5eZNssw/3shTqn8eHZyoRiToSttrRFw=="
Link to this function

verify?(message, signature, publicKey, options \\ [])

View Source

Verifies a message signature based on a public key

Parameters:

  • message [string]: message that will be signed
  • signature [%EllipticCurve.Signature.Data]: signature associated with the message
  • publicKey [%EllipticCurve.PublicKey.Data]: public key associated with the message signer
  • options [keyword list]: refines request

    • hashfunc [:method]: defines the hash function applied to the message. Must be compatible with :crypto.hash. Default: :sha256;

Returns:

  • verified [bool]: true if message, public key and signature are compatible, false otherwise;

Example:

iex> EllipticCurve.Ecdsa.verify?(message, signature, publicKey)
true
iex> EllipticCurve.Ecdsa.verify?(wrongMessage, signature, publicKey)
false
iex> EllipticCurve.Ecdsa.verify?(message, wrongSignature, publicKey)
false
iex> EllipticCurve.Ecdsa.verify?(message, signature, wrongPublicKey)
false