Module: Tapyrus::KeyPath
- Included in:
- Wallet::MasterKey
- Defined in:
- lib/tapyrus/key_path.rb
Instance Method Summary collapse
-
#parse_key_path(path_string) ⇒ Array[Integer]
key path convert an array of derive number.
-
#to_key_path(numbers) ⇒ String
key path numbers convert to path string.
Instance Method Details
#parse_key_path(path_string) ⇒ Array[Integer]
key path convert an array of derive number
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tapyrus/key_path.rb', line 6 def parse_key_path(path_string) path_string .split("/") .map .with_index do |p, index| if index == 0 raise ArgumentError.new("#{path_string} is invalid format.") unless p == "m" next end raise ArgumentError.new("#{path_string} is invalid format.") unless p.delete("'") =~ /^[0-9]+$/ (p[-1] == "'" ? p.delete("'").to_i + Tapyrus::HARDENED_THRESHOLD : p.to_i) end[ 1..-1 ] end |
#to_key_path(numbers) ⇒ String
key path numbers convert to path string.
25 26 27 |
# File 'lib/tapyrus/key_path.rb', line 25 def to_key_path(numbers) "m/#{numbers.map { |p| p >= Tapyrus::HARDENED_THRESHOLD ? "#{p - Tapyrus::HARDENED_THRESHOLD}'" : p.to_s }.join("/")}" end |