class Nis::Apostille
Constants
- CHECKSUM
Public Class Methods
new(keypair, file, hashing = :sha256, multisig: false, private: false, network: :testnet)
click to toggle source
@param [Nis::Keypair] keypair @param [string] file - The file @param [symbol] hashing - An hashing type (md5, sha1, sha256, sha3-256, sha3-512) @param [boolean] multisig - true if transaction is multisig, false otherwise @param [boolean] private - true if apostille is private / transferable / updateable, false if public
# File lib/nis/apostille.rb, line 14 def initialize(keypair, file, hashing = :sha256, multisig: false, private: false, network: :testnet) @keypair = keypair @file = file @hashing = hashing @multisig = multisig @private = private @network = network end
Public Instance Methods
apostille_format(transaction_hash)
click to toggle source
# File lib/nis/apostille.rb, line 42 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?()
click to toggle source
# File lib/nis/apostille.rb, line 27 def multisig? @multisig end
private?()
click to toggle source
# File lib/nis/apostille.rb, line 23 def private? @private end
transaction()
click to toggle source
# File lib/nis/apostille.rb, line 31 def transaction if private? raise 'Not implemented private apostille.' else dedicated_address = apostille[:sink] apostille_hash = calc_hash end Nis::Transaction::Transfer.new(dedicated_address, 0, apostille_hash) end
Private Instance Methods
algo()
click to toggle source
# File lib/nis/apostille.rb, line 68 def algo case @hashing when /\Amd5\z/ then 0x01 when /\Asha1\z/ then 0x02 when /\Asha256\z/ then 0x03 when /\Asha3-256\z/ then 0x08 when /\Asha3-512\z/ then 0x09 else raise "Undefined hashing: #{@hashing}" end end
apostille()
click to toggle source
# File lib/nis/apostille.rb, line 87 def apostille if @network == :testnet if private? raise 'Not implemented private apostille.' else { private_key: nil, sink: 'TC7MCY5AGJQXZQ4BN3BOPNXUVIGDJCOHBPGUM2GE' } end else if private? raise 'Not implemented private apostille.' else { private_key: nil, sink: 'NCZSJHLTIMESERVBVKOW6US64YDZG2PFGQCSV23J' } end end end
calc_hash()
click to toggle source
# File lib/nis/apostille.rb, line 56 def calc_hash checksum = "#{CHECKSUM}#{hex_type}" hashed = case @hashing when /\Amd5\z/ then Digest::MD5.file(@file) when /\Asha1\z/ then Digest::SHA1.file(@file) when /\Asha256\z/ then Digest::SHA256.file(@file) when /\Asha3-256\z/ then Digest::SHA3.file(@file, 256) else Digest::SHA3.file(@file, 512) end checksum << hashed.hexdigest end
hex_type()
click to toggle source
# File lib/nis/apostille.rb, line 83 def hex_type '%02x' % (algo | version) end
version()
click to toggle source
# File lib/nis/apostille.rb, line 79 def version private? ? 0x80 : 0x00 end