Class: Nem::Keypair
- Inherits:
-
Object
- Object
- Nem::Keypair
- Defined in:
- lib/nem/keypair.rb
Instance Attribute Summary collapse
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
Class Method Summary collapse
-
.generate(seed = SecureRandom.hex(32)) ⇒ Nem::Keypair
New key pair.
Instance Method Summary collapse
-
#initialize(private_key) ⇒ Keypair
constructor
A new instance of Keypair.
-
#sign(data) ⇒ String
Signed hex string.
- #verify_signature(signer, hash, apostille_hash) ⇒ Object
Constructor Details
#initialize(private_key) ⇒ Keypair
Returns a new instance of Keypair.
8 9 10 11 |
# File 'lib/nem/keypair.rb', line 8 def initialize(private_key) @private = private_key @public = calc_public_key end |
Instance Attribute Details
#private ⇒ Object (readonly)
Returns the value of attribute private.
5 6 7 |
# File 'lib/nem/keypair.rb', line 5 def private @private end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
5 6 7 |
# File 'lib/nem/keypair.rb', line 5 def public @public end |
Class Method Details
.generate(seed = SecureRandom.hex(32)) ⇒ Nem::Keypair
Returns new key pair.
27 28 29 30 31 32 |
# File 'lib/nem/keypair.rb', line 27 def self.generate(seed = SecureRandom.hex(32)) unless seed =~ /\A\h{64}\z/ || seed =~ /\A\h{66}\z/ raise ArgumentError, 'PrivateKey is not valid!' end new(seed) end |
Instance Method Details
#sign(data) ⇒ String
Returns Signed hex string.
15 16 17 18 19 |
# File 'lib/nem/keypair.rb', line 15 def sign(data) bin_data = Nem::Util::Convert.hex2bin(data) bin_signed = Nem::Util::Ed25519.signature_hash_unsafe(bin_data, bin_secret, bin_public) bin_signed.unpack('H*').first end |
#verify_signature(signer, hash, apostille_hash) ⇒ Object
21 22 23 24 |
# File 'lib/nem/keypair.rb', line 21 def verify_signature(signer, hash, apostille_hash) # TODO: support private apostille raise NotImplementedError, 'Not implemented private apostille' end |