libitx / bsv-ex

Elixir toolset for building Bitcoin applications
https://hexdocs.pm/bsv
Apache License 2.0
28 stars 8 forks source link

Error following README.md to create Addres on Erlang/OTP 24 / Elixir 1.14.3 #14

Closed cdesch closed 9 months ago

cdesch commented 1 year ago

I get this error when following the README.md process of:

keypair = BSV.KeyPair.new()
address = BSV.Address.from_pubkey(keypair.pubkey)
BSV.Address.to_string(address)

Which then results in this error:

iex(1)> keypair = BSV.KeyPair.new()
%BSV.KeyPair{
  privkey: %BSV.PrivKey{
    d: <<158, 191, 224, 206, 21, 116, 27, 141, 115, 132, 31, 244, 71, 175, 64,
      0, 160, 156, 48, 147, 215, 223, 38, 215, 252, 247, 114, 79, 217, 211, 61,
      61>>,
    compressed: true
  },
  pubkey: %BSV.PubKey{
    point: %Curvy.Point{
      x: 23400353067986869063376823280879136402258570127829863035970735548305686233723,
      y: 88034104316788125458394448345172674016127585335160421136966489172519954724842
    },
    compressed: true
  }
}
iex(2)> address = BSV.Address.from_pubkey(keypair.pubkey)
** (ErlangError) Erlang error: :notsup
    (crypto 5.0.5) crypto.erl:2147: :crypto.notsup_to_error/1
    (bsv 2.1.0) lib/bsv/hash.ex:156: BSV.Hash.hash/3
    (bsv 2.1.0) lib/bsv/address.ex:57: BSV.Address.from_pubkey/1
iex(2)> 

This is on Elixir and Erlang Version:

Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit]

Elixir 1.14.3 (compiled with Erlang/OTP 24)
libitx commented 1 year ago

A :notsup error comes from Erlang's crypto module when an algorithm isn't supported. In this case a pubkey is being hashed with :sha256 which causes the error.

This will be down to how Erlang is built on your machine. What OS are you working with and is OpenSSL installed on the machine?