Module: Base58
- Defined in:
- lib/base58-alphabets/base.rb,
lib/base58-alphabets/base58.rb,
lib/base58-alphabets/bitcoin.rb,
lib/base58-alphabets/version.rb
Overview
shared code for formats / variants with single char alphabets
e.g. Bitcoin, Flickr, ...
Defined Under Namespace
Classes: Base, Bitcoin, Configuration
Constant Summary collapse
- BASE =
ALPHABET.length == 58 ## 58 chars/letters/digits
58- MAJOR =
0- MINOR =
1- PATCH =
0- VERSION =
[MAJOR,MINOR,PATCH].join('.')
Class Method Summary collapse
-
._bytes(num) ⇒ Object
(private) helper - note: leading underscore in name e.g.
- ._pack(bytes) ⇒ Object
-
.alphabet(klass: configuration.format) ⇒ Object
encoding alphabet - letter-to-number by index / array.
- .banner ⇒ Object
-
.configuration ⇒ Object
lets you use Base58.configure do |config| config.format = :bitcoin end.
- .configure {|configuration| ... } ⇒ Object
- .decode(str_or_bytes, klass: configuration.format) ⇒ Object
- .encode(num_or_bytes, klass: configuration.format) ⇒ Object
-
.format ⇒ Object
add convenience helper for format.
- .format=(value) ⇒ Object
-
.number(klass: configuration.format) ⇒ Object
decoding letter-to-number mapping / hash.
- .root ⇒ Object
- .version ⇒ Object
Class Method Details
._bytes(num) ⇒ Object
(private) helper - note: leading underscore in name e.g. _bytes
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/base58-alphabets/base58.rb', line 60 def self._bytes( num ) b = [] while num >= BASE mod = num % BASE b << mod num = (num - mod) / BASE end b << num b = b.reverse b end |
._pack(bytes) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/base58-alphabets/base58.rb', line 72 def self._pack( bytes ) num = 0 bytes.reverse.each_with_index do |byte,index| num += byte * (BASE**(index)) end num end |
.alphabet(klass: configuration.format) ⇒ Object
encoding alphabet - letter-to-number by index / array
81 |
# File 'lib/base58-alphabets/base58.rb', line 81 def self.alphabet( klass: configuration.format ) klass.alphabet; end |
.banner ⇒ Object
13 14 15 |
# File 'lib/base58-alphabets/version.rb', line 13 def self. "base58-alphabets/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})" end |
.configuration ⇒ Object
lets you use
Base58.configure do |config|
config.format = :bitcoin
end
32 33 34 |
# File 'lib/base58-alphabets/base58.rb', line 32 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
36 37 38 |
# File 'lib/base58-alphabets/base58.rb', line 36 def self.configure yield( configuration ) end |
.decode(str_or_bytes, klass: configuration.format) ⇒ Object
51 52 53 |
# File 'lib/base58-alphabets/base58.rb', line 51 def self.decode( str_or_bytes, klass: configuration.format ) klass.decode( str_or_bytes ) end |
.encode(num_or_bytes, klass: configuration.format) ⇒ Object
47 48 49 |
# File 'lib/base58-alphabets/base58.rb', line 47 def self.encode( num_or_bytes, klass: configuration.format ) klass.encode( num_or_bytes ) end |
.format ⇒ Object
add convenience helper for format
41 |
# File 'lib/base58-alphabets/base58.rb', line 41 def self.format() configuration.format; end |
.format=(value) ⇒ Object
42 |
# File 'lib/base58-alphabets/base58.rb', line 42 def self.format=(value) self.configuration.format = value; end |
.number(klass: configuration.format) ⇒ Object
decoding letter-to-number mapping / hash
84 |
# File 'lib/base58-alphabets/base58.rb', line 84 def self.number( klass: configuration.format ) klass.number; end |
.root ⇒ Object
17 18 19 |
# File 'lib/base58-alphabets/version.rb', line 17 def self.root File.( File.dirname(File.dirname(File.dirname(__FILE__))) ) end |
.version ⇒ Object
9 10 11 |
# File 'lib/base58-alphabets/version.rb', line 9 def self.version VERSION end |