class DbchainClient::KeyEscrow
Constants
- SUFFIX_PRIVATE
- SUFFIX_SECRET
Public Instance Methods
create_and_save_private_key_with_password(username, password, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 12 def create_and_save_private_key_with_password(username, password, key_store_obj) private_key = DbchainClient::Mnemonics.generate_private_key save_private_key(username, password, private_key, key_store_obj) end
load_private_key_by_recovery_phrase(username, recovery_phrase, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 25 def load_private_key_by_recovery_phrase(username, recovery_phrase, key_store_obj) load_private_key(username, recovery_phrase, key_store_obj) end
load_private_key_with_password(username, password, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 17 def load_private_key_with_password(username, password, key_store_obj) load_private_key(username, password, key_store_obj) end
reset_password_from_old(username, old_password, new_password, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 34 def reset_password_from_old(username, old_password, new_password, key_store_obj) private_key = load_private_key(username, old_password, key_store_obj) or raise "Failed to retrive private key" save_private_key(username, new_password, private_key, key_store_obj) end
reset_password_from_recovery_phrase(username, recovery_phrase, new_password, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 29 def reset_password_from_recovery_phrase(username, recovery_phrase, new_password, key_store_obj) private_key = load_private_key(username, recovery_phrase, key_store_obj) or raise "Failed to retrieve private key" save_private_key(username, new_password, private_key, key_store_obj) end
save_private_key_with_recovery_phrase(username, recovery_phrase, private_key, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 21 def save_private_key_with_recovery_phrase(username, recovery_phrase, private_key, key_store_obj) save_private_key(username, recovery_phrase, private_key, key_store_obj) end
Private Instance Methods
f1(str1, str2)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 62 def f1(str1, str2) Digest::SHA256.digest(str1 + str2) end
f2(str1, str2)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 66 def f2(str1, str2) f1(str1, str2) end
hash1(str1, str2)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 70 def hash1(str1, str2) Digest::SHA256.digest(str1 + str2 + SUFFIX_SECRET) end
hash2(str1, str2)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 74 def hash2(str1, str2) Digest::SHA256.digest(str1 + str2 + SUFFIX_PRIVATE) end
load_private_key(username, password_or_recovery_phrase, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 51 def load_private_key(username, password_or_recovery_phrase, key_store_obj) key_of_secret = hash1(username, password_or_recovery_phrase) key_of_private = hash2(username, password_or_recovery_phrase) secret = key_store_obj.load(key_of_secret) encrypted_private_key = key_store_obj.load(key_of_private) aes = DbchainClient::AESCrypt.new seed = aes.decrypt(f2(username, password_or_recovery_phrase), secret) aes.decrypt(f1(seed, password_or_recovery_phrase), encrypted_private_key) end
random_seed()
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 78 def random_seed() SecureRandom.random_bytes(32) end
save_private_key(username, password_or_recovery_phrase, private_key, key_store_obj)
click to toggle source
# File lib/dbchain_client/key_escrow.rb, line 41 def save_private_key(username, password_or_recovery_phrase, private_key, key_store_obj) seed = random_seed() aes = DbchainClient::AESCrypt.new encrypted_private_key = aes.encrypt(f1(seed, password_or_recovery_phrase), private_key) secret = aes.encrypt(f2(username, password_or_recovery_phrase), seed) key_of_secret = hash1(username, password_or_recovery_phrase) key_of_private = hash2(username, password_or_recovery_phrase) key_store_obj.save(key_of_private, encrypted_private_key) && key_store_obj.save(key_of_secret, secret) end