nano-docs icon indicating copy to clipboard operation
nano-docs copied to clipboard

Incorrect wallet address in Key Management section

Open Cantido opened this issue 3 years ago • 0 comments

I'm writing a Nano library for Elixir, and I believe I have discovered an off-by-one error in whatever library produced the example wallet address in they Key Management section.

My first attempt at encoding the public key into a wallet address used the RFC 4648 base32 algorithm with a modified alphabet. That is, I would take five bits at a time, and use that five-bit integer as an index for a character array. Here was my first attempt:

for <<i::5 <- pubkey>>, into: <<>> do
  String.at("13456789abcdefghijkmnopqrstuwxyz", i)
end

However, this produced an incorrect wallet address.

After some toying around, I discovered that whatever library produced these examples is actually dropping the first bit of the public key. Here's the snippet that produces an address matching the example:

# Drop the first bit of the to-be-encoded value
<<_::1, rest::pubkey>> = bin

# Same RFC 4648 algorithm
for <<i::5 <- rest>>, into: <<>> do
  String.at("13456789abcdefghijkmnopqrstuwxyz", i)
end

I was following the reference implementation at https://github.com/numsu/nanocurrency-web-js/blob/master/lib/nano-address.ts, and I suspect the bug is in there.

Am I correct in saying this is also a bug in the Javascript implementation, or was the example wallet in these docs produced by another library?

Cantido avatar Mar 11 '21 20:03 Cantido