Class: Eth::Key::Encrypter
- Inherits:
-
Object
- Object
- Eth::Key::Encrypter
show all
- Includes:
- Utils
- Defined in:
- lib/eth/key/encrypter.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
#base256_to_int, #bin_to_hex, #bin_to_prefixed_hex, #format_address, #hash160, #hex_to_bin, #int_to_base256, #keccak256, #keccak256_rlp, #keccak512, #normalize_address, #prefix_hex, #prefix_message, #public_key_to_address, #remove_hex_prefix, #ripemd160, #sha256, #v_r_s_for, #valid_address?, #zpad, #zpad_hex, #zpad_int, #zunpad
Constructor Details
#initialize(key, options = {}) ⇒ Encrypter
Returns a new instance of Encrypter.
11
12
13
14
|
# File 'lib/eth/key/encrypter.rb', line 11
def initialize(key, options = {})
@key = key
@options = options
end
|
Class Method Details
7
8
9
|
# File 'lib/eth/key/encrypter.rb', line 7
def self.perform(key, password, options = {})
new(key, options).perform(password)
end
|
Instance Method Details
#data ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/eth/key/encrypter.rb', line 23
def data
{
crypto: {
cipher: cipher_name,
cipherparams: {
iv: bin_to_hex(iv),
},
ciphertext: bin_to_hex(encrypted_key),
kdf: "pbkdf2",
kdfparams: {
c: iterations,
dklen: 32,
prf: prf,
salt: bin_to_hex(salt),
},
mac: bin_to_hex(mac),
},
id: id,
version: 3,
}.tap do |data|
data[:address] = address unless options[:skip_address]
end
end
|
#id ⇒ Object
47
48
49
|
# File 'lib/eth/key/encrypter.rb', line 47
def id
@id ||= options[:id] || SecureRandom.uuid
end
|
16
17
18
19
20
21
|
# File 'lib/eth/key/encrypter.rb', line 16
def perform(password)
derive_key password
encrypt
data.to_json
end
|