Class: IOTA::Crypto::PrivateKey
- Inherits:
-
Object
- Object
- IOTA::Crypto::PrivateKey
- Defined in:
- lib/iota/crypto/private_key.rb
Constant Summary collapse
- HASH_LENGTH =
Kerl::HASH_LENGTH
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #digests ⇒ Object
-
#initialize(seed, index, security) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
Constructor Details
#initialize(seed, index, security) ⇒ PrivateKey
Returns a new instance of PrivateKey.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/iota/crypto/private_key.rb', line 8 def initialize(seed, index, security) key = [] offset = 0 buffer = [] (0...index).step(1) do |i| # Treat ``seed`` like a really big number and add ``index``. # Note that addition works a little bit differently in balanced ternary. (0...seed.length).step(1) do |j| seed[j] += 1 if seed[j] > 1 seed[j] = -1 else break end end end kerl = Kerl.new kerl.absorb(seed, 0, seed.length) kerl.squeeze(seed, 0, seed.length) kerl.reset kerl.absorb(seed, 0, seed.length) security.times do (0...27).step(1) do |i| kerl.squeeze(buffer, 0, seed.length) (0...HASH_LENGTH).step(1) do |j| key[offset] = buffer[j] offset += 1 end end end @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/iota/crypto/private_key.rb', line 6 def key @key end |
Instance Method Details
#digests ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/iota/crypto/private_key.rb', line 46 def digests digestsArray = [] buffer = [] (0...(@key.length / 6561).floor).step(1) do |i| keyFragment = @key.slice(i * 6561, 6561) (0...27).step(1) do |j| buffer = keyFragment.slice(j * HASH_LENGTH, HASH_LENGTH); (0...26).step(1) do |k| kKerl = Kerl.new kKerl.absorb(buffer, 0, buffer.length) kKerl.squeeze(buffer, 0, HASH_LENGTH) end (0...HASH_LENGTH).step(1) do |k| keyFragment[j * HASH_LENGTH + k] = buffer[k] end end kerl = Kerl.new kerl.absorb(keyFragment, 0, keyFragment.length) kerl.squeeze(buffer, 0, HASH_LENGTH) (0...HASH_LENGTH).step(1) do |j| digestsArray[i * HASH_LENGTH + j] = buffer[j]; end end digestsArray end |