Secp256k1.Schnorr (secp256k1 v0.7.1)

View Source

Module implementing Schnorr signatures as defined in BIP340

Summary

Functions

Generate Schnorr signature of a hash (AUX is randomly generated)

Generate Schnorr signature of a hash and specify AUX - NOT RECOMMENDED

Generate Schnorr signature of message (can be hash or custom length message)

Generate Schnorr signature of arbitrary message (AUX is randomly generated)

Generate Schnorr signature of a arbitrary message and specify AUX - NOT RECOMMENDED

Validate Schnorr signature

Functions

sign32(msg_hash, seckey)

@spec sign32(msg_hash :: Secp256k1.hash(), seckey :: Secp256k1.seckey()) ::
  Secp256k1.schnorr_sig()

Generate Schnorr signature of a hash (AUX is randomly generated)

sign32(msg_hash, seckey, aux)

@spec sign32(
  msg_hash :: Secp256k1.hash(),
  seckey :: Secp256k1.seckey(),
  aux :: <<_::32, _::_*8>>
) :: Secp256k1.schnorr_sig()

Generate Schnorr signature of a hash and specify AUX - NOT RECOMMENDED

sign(message, seckey)

@spec sign(message :: binary(), seckey :: Secp256k1.seckey()) ::
  Secp256k1.schnorr_sig()

Generate Schnorr signature of message (can be hash or custom length message)

Examples

Sign a 32-byte hash

iex> {seckey, _} = Secp256k1.keypair(:xonly)
iex> msg_hash = :crypto.hash(:sha256, "hello")
iex> signature = Secp256k1.Schnorr.sign(msg_hash, seckey)
iex> byte_size(signature)
64

Sign an arbitrary message

iex> {seckey, _} = Secp256k1.keypair(:xonly)
iex> message = "This is a long message that is not 32 bytes"
iex> signature = Secp256k1.Schnorr.sign(message, seckey)
iex> byte_size(signature)
64

sign_custom(message, seckey)

@spec sign_custom(message :: binary(), seckey :: Secp256k1.seckey()) ::
  Secp256k1.schnorr_sig()

Generate Schnorr signature of arbitrary message (AUX is randomly generated)

sign_custom(message, seckey, aux)

@spec sign_custom(
  message :: binary(),
  seckey :: Secp256k1.seckey(),
  aux :: <<_::32, _::_*8>>
) ::
  Secp256k1.schnorr_sig()

Generate Schnorr signature of a arbitrary message and specify AUX - NOT RECOMMENDED

valid?(signature, message, pubkey)

@spec valid?(
  signature :: Secp256k1.schnorr_sig(),
  message :: binary(),
  pubkey :: Secp256k1.xonly_pubkey()
) :: boolean()

Validate Schnorr signature

Examples

iex> {seckey, pubkey} = Secp256k1.keypair(:xonly)
iex> msg_hash = :crypto.hash(:sha256, "hello")
iex> signature = Secp256k1.Schnorr.sign(msg_hash, seckey)
iex> Secp256k1.Schnorr.valid?(signature, msg_hash, pubkey)
true