BSV.Wallet behaviour (bsv_sdk v1.1.0)

Copy Markdown View Source

The wallet behaviour — defines the interface for BSV wallet operations.

Core operations (implemented by ProtoWallet):

  • Key derivation (get_public_key)
  • Encryption/decryption
  • Signing/verification
  • HMAC creation/verification

Transaction and certificate operations are defined but return {:error, "not implemented"} by default.

Summary

Callbacks

create_hmac(wallet, enc, data)

@callback create_hmac(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  data :: binary()
) ::
  {:ok, binary()} | {:error, String.t()}

create_signature(wallet, enc, data, hash_to_sign)

@callback create_signature(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  data :: binary(),
  hash_to_sign :: binary() | nil
) :: {:ok, binary()} | {:error, String.t()}

decrypt(wallet, enc, ciphertext)

@callback decrypt(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  ciphertext :: binary()
) ::
  {:ok, binary()} | {:error, term()}

encrypt(wallet, enc, plaintext)

@callback encrypt(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  plaintext :: binary()
) ::
  {:ok, binary()} | {:error, term()}

get_public_key(wallet, opts)

@callback get_public_key(wallet :: struct(), opts :: keyword()) ::
  {:ok, BSV.PublicKey.t()} | {:error, String.t()}

verify_hmac(wallet, enc, data, hmac)

@callback verify_hmac(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  data :: binary(),
  hmac :: binary()
) :: {:ok, boolean()} | {:error, String.t()}

verify_signature(wallet, enc, data, hash_to_verify, signature, opts)

@callback verify_signature(
  wallet :: struct(),
  enc :: BSV.Wallet.Types.EncryptionArgs.t(),
  data :: binary() | nil,
  hash_to_verify :: binary() | nil,
  signature :: binary(),
  opts :: keyword()
) :: {:ok, boolean()} | {:error, String.t()}