Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 1.8 KB

base58.md

File metadata and controls

52 lines (31 loc) · 1.8 KB

Index

BTC::Base58

Base58 and Base58Check are two encodings invented by Satoshi for Bitcoin addresses to make sure they don't contain ambiguous characters and can be selected with a double click.

Note: you normally do not use Base58 directly. To encode/decode Bitcoin addresses, use BTC::Address class. To encode/decode private keys in WIF format, use BTC::WIF class.

Satoshi:

Why base-58 instead of standard base-64 encoding?

  • Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking account numbers.
  • A string with non-alphanumeric characters is not as easily accepted as an account number.
  • E-mail usually won't line-break if there's no punctuation to break at.
  • Double-clicking selects the whole number as one word if it's all alphanumeric.

Base58 treats a binary string as a big-endian integer and encodes it in Base58 alphabet:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

Leading zero bytes are encoded as repeated "1"s.

Base58Check appends a 4-byte portion of Hash256 of the binary string as a checksum, then encodes the resulting string in Base58.

Module Functions

base58_from_data(data)

Returns a Base58-encoded string for a given binary string data.

data_from_base58(string)

Returns a binary string decoded from Base58-encoded string.

Raises FormatError if encoding is not valid.

base58check_from_data(data)

Returns a Base58-encoded string with appended checksum for a given binary string data.

data_from_base58check(string)

Returns a binary string decoded from Base58Check-encoded string.

Raises FormatError if checksum is not valid or encoding is not valid.