Skip to content

Incorrect wallet address in Key Management section #481

Open
@Cantido

Description

@Cantido

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions