casper-network / casper-java-sdk

Java library for interacting with a CSPR node
Apache License 2.0
9 stars 26 forks source link

Crypto: EIP-55 support #90

Open asladeofgreen opened 2 years ago

asladeofgreen commented 2 years ago

Hexadecimal representations of chain addresses + digests should be checksum encoded ala EIP-55. For reference purposes the python implementation of the checksum encode/decode functions is defined here.

asladeofgreen commented 2 years ago

The mechanics of the encode function are as follows:

If the length of the input bytes is > 75 then simply return lower case hexadecimal, otherwise:

  1. Map input bytes into an array of bits (see _bytes_to_bits_cycle function);
  2. Get 32 byte blake2b hash of output of above mapping function;
  3. Convert 32 byte hash into an array of 'nibbles', i.e. 4 bit numbers (see _bytes_to_nibbles function);
  4. Convert array of nibbles into array of hexadecimal characters mapped from here;
asladeofgreen commented 2 years ago

The checksummed should also expose a set of higher-level helper encoding functions: