BSV.Message (BSV v2.1.0) View Source
The Message module provides functions for encrypting, decrypting, signing and verifying arbitrary messages using Bitcoin keys.
Message encryption uses the Electrum-compatible BIE1 ECIES algorithm. Message signing uses the Bitcoin Signed Message algorithm. Both alorithms are broadly supported by popular BSV libraries in other languages.
Encryption
A sender encrypts the message using the recipient's PubKey. The recipient decrypts the message with their PrivKey.
iex> msg = "Secret test message"
iex> encrypted = Message.encrypt(msg, @bob_keypair.pubkey)
iex> Message.decrypt(encrypted, @bob_keypair.privkey)
{:ok, "Secret test message"}
Signing
A sender signs a message with their PrivKey. The recipient verifies the message using the sender's PubKey.
iex> msg = "Secret test message"
iex> sig = Message.sign(msg, @alice_keypair.privkey)
iex> Message.verify(sig, msg, @alice_keypair.pubkey)
true
Link to this section Summary
Functions
Decrypts the given message with the private key.
Encrypts the given message with the public key.
Signs the given message with the PrivKey.
Verifies the given signature against the given message using the PubKey.
Link to this section Functions
Specs
decrypt(binary(), BSV.PrivKey.t(), keyword()) :: {:ok, binary()} | {:error, term()}
Decrypts the given message with the private key.
Options
The accepted options are:
:encoding
- Optionally decode the binary with either the:base64
or:hex
encoding scheme.
Specs
encrypt(binary(), BSV.PubKey.t(), keyword()) :: binary()
Encrypts the given message with the public key.
Options
The accepted options are:
:encoding
- Optionally encode the binary with either the:base64
or:hex
encoding scheme.
Specs
sign(binary(), BSV.PrivKey.t(), keyword()) :: binary()
Signs the given message with the PrivKey.
By default signatures are returned base64
encoded. Use the encoding: :raw
option to return a raw binary signature.
Options
The accepted options are:
:encoding
- Encode the binary with either the:base64
,:hex
or:raw
encoding scheme.
Specs
verify(binary(), binary(), BSV.PubKey.t() | BSV.Address.t(), keyword()) :: boolean() | {:error, term()}
Verifies the given signature against the given message using the PubKey.
By default signatures are assumed to be base64
encoded. Use the :encoding
option to specify a different signature encoding.
Options
The accepted options are:
:encoding
- Decode the signature with either the:base64
,:hex
or:raw
encoding scheme.