class Zold::Signature

A signature

Public Class Methods

new(network = 'test') click to toggle source
# File lib/zold/signature.rb, line 36
def initialize(network = 'test')
  @network = network
end

Public Instance Methods

sign(pvt, id, txn) click to toggle source

Sign the trasnsaction and return the signature.

pvt

Private RSA key

id

Paying wallet ID

txn

The transaction

# 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) click to toggle source

The transaction is valid? Returns true if it is.

pub

Public key of the wallet

id

Paying wallet ID

txn: Transaction to validate

# 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

Private Instance Methods

body(id, t) click to toggle source

Create the body for transaction signature.

id

The paying wallet ID

t

Transaction, instance of Txn

# File lib/zold/signature.rb, line 67
def body(id, t)
  [id, t.id, t.date.utc.iso8601, t.amount.to_i, t.prefix, t.bnf, t.details].join(' ')
end