Class: Zold::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/signature.rb

Overview

A signature

Instance Method Summary collapse

Constructor Details

#initialize(network = 'test') ⇒ Signature

Returns a new instance of Signature.



36
37
38
# File 'lib/zold/signature.rb', line 36

def initialize(network = 'test')
  @network = network
end

Instance Method Details

#sign(pvt, id, txn) ⇒ Object

Sign the trasnsaction and return the signature.

pvt

Private RSA key

id

Paying wallet ID

txn

The transaction



44
45
46
47
48
49
# File 'lib/zold/signature.rb', line 44

def sign(pvt, id, txn)
  raise 'pvt must be of type Key' unless pvt.is_a?(Key)
  raise 'id must be of type Id' unless id.is_a?(Id)
  raise 'txn must be of type Txn' unless txn.is_a?(Txn)
  pvt.sign(body(id, txn))
end

#valid?(pub, id, txn) ⇒ Boolean

The transaction is valid? Returns true if it is.

pub

Public key of the wallet

id

Paying wallet ID

txn: Transaction to validate

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/zold/signature.rb', line 55

def valid?(pub, id, txn)
  raise 'pub must be of type Key' unless pub.is_a?(Key)
  raise 'id must be of type Id' unless id.is_a?(Id)
  raise 'txn must be of type Txn' unless txn.is_a?(Txn)
  pub.verify(txn.sign, body(id, txn)) && (@network != Wallet::MAINET || !id.root? || pub.root?)
end