Class: Nem::Keypair

Inherits:
Object
  • Object
show all
Defined in:
lib/nem/keypair.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key) ⇒ Keypair

Returns a new instance of Keypair.

Parameters:

  • Hex (String)

    Private Key



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

#privateObject (readonly)

Returns the value of attribute private.



5
6
7
# File 'lib/nem/keypair.rb', line 5

def private
  @private
end

#publicObject (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.

Returns:



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.

Parameters:

  • Hex (String)

    string

Returns:

  • (String)

    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

Raises:

  • (NotImplementedError)


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