Class: Nem::Apostille

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

Constant Summary collapse

CHECKSUM =
'fe4e5459'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keypair, file, hashing = :sha256, multisig: false, signed: false, network: nil) ⇒ Apostille

Returns a new instance of Apostille.

Parameters:

  • keypair (Nem::Keypair)
  • file (String)
    • The file

  • hashing (Symbol) (defaults to: :sha256)
    • An hashing type (md5, sha1, sha256, sha3-256, sha3-512)

  • multisig (Boolean) (defaults to: false)
    • true if transaction is multisig, false otherwise

  • signed (Symbol) (defaults to: false)
    • true if apostille is private / transferable / updateable, false if public

Raises:

  • (NotImplementedError)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nem/apostille.rb', line 16

def initialize(keypair, file, hashing = :sha256, multisig: false, signed: false, network: nil)
  @keypair = keypair
  @file = file
  @hashing = hashing
  @multisig = multisig
  @signed = signed
  @network = network || Nem.default_network

  # TDOD: support multisig apostille
  raise NotImplementedError, 'Sorry, Not yet multisig apostille' if multisig?
end

Instance Attribute Details

#dedicated_keypairObject (readonly)

Returns the value of attribute dedicated_keypair.



9
10
11
# File 'lib/nem/apostille.rb', line 9

def dedicated_keypair
  @dedicated_keypair
end

Instance Method Details

#apostille_format(transaction_hash) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nem/apostille.rb', line 50

def apostille_format(transaction_hash)
  ext = File.extname(@file.path)
  name = File.basename(@file.path, ext)
  date = Date.today.strftime('%Y-%m-%d')
  '%s -- Apostille TX %s -- Date %s%s' % [
    name,
    transaction_hash,
    date,
    ext
  ]
end

#multisig?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/nem/apostille.rb', line 32

def multisig?
  @multisig
end

#signed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/nem/apostille.rb', line 28

def signed?
  @signed
end

#transactionObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nem/apostille.rb', line 36

def transaction
  if signed?
    @dedicated_keypair = generate_keypair
    apostille_hash = header << @keypair.sign(calc_hash)
    dedicated_address = Nem::Unit::Address.from_public_key(@dedicated_keypair.public, @network)
  else
    apostille_hash = header << calc_hash
    dedicated_address = apostille[:sink]
  end

  # TDOD: support multisig apostille
  Nem::Transaction::Transfer.new(dedicated_address, 0, apostille_hash)
end