nem-ruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a80d96a7c25cccb9215c5f05af2651ab5573a7f2f767a420a1a97cb156c4cbb
4
- data.tar.gz: 6ef2b946c1088bdf76828b4252e83f15d57a7489de035fca2cedbaa920ac3db8
3
+ metadata.gz: e104168b1b964bfe7781e60bd856c8c47810d49f58620423c297298f7bcd0155
4
+ data.tar.gz: 25a00eaf0970adb06568c3334a94be759983113ff9cc02d43503eac8a593e954
5
5
  SHA512:
6
- metadata.gz: fc780b27ec580dbe40ecd22de3972b98794fefa751f194012c49f7a15682ee68feb998e26c932e80dc0698037fe256532210c82abba5a501856c232b7a7e1a9c
7
- data.tar.gz: 6b01deeb6257603d93fd406ffe90ab54b97f33234cc2929e411ac8d6e3009c12112f709b1e52716f324c3ac2d44cfbc0d59726e368573f36c459ef781e38d639
6
+ metadata.gz: 229d81f04786aa310945ffd53a503786d7bf4f02b2551055ed24f751b64a923ede6377a092fcfe7508347ccff8c23e349fc92f8ff786bb42539c1851c174ba98
7
+ data.tar.gz: e3fb15751022dd9a99eeb3288544b91607711653b57a57487b6fab6f6de9dfa618e1d640b99dd872ca0340a89de0256dbc6ae89b7ac666d1d739f902cd0ed1da
@@ -3,7 +3,7 @@ require 'nem'
3
3
 
4
4
  Nem.logger.level = Logger::DEBUG
5
5
 
6
- FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
6
+ FIXTURES_PATH = File.expand_path('../../../spec/fixtures', __FILE__)
7
7
 
8
8
  node = Nem::Node.new(host: 'bigalice2.nem.ninja')
9
9
  tx_endpoint = Nem::Endpoint::Transaction.new(node)
@@ -3,7 +3,7 @@ require 'nem'
3
3
 
4
4
  Nem.logger.level = Logger::DEBUG
5
5
 
6
- FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
6
+ FIXTURES_PATH = File.expand_path('../../../spec/fixtures', __FILE__)
7
7
 
8
8
  # sender
9
9
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -13,9 +13,9 @@ node = Nem::Node.new(host: 'bigalice2.nem.ninja')
13
13
  tx_endpoint = Nem::Endpoint::Transaction.new(node)
14
14
 
15
15
  file = File.open("#{FIXTURES_PATH}/nemLogoV2.png")
16
- apo = Nem::Apostille.new(kp, file, :sha1,
16
+ apo = Nem::Apostille.new(kp, file, :sha256,
17
17
  multisig: false,
18
- private: false,
18
+ signed: false,
19
19
  network: :testnet
20
20
  )
21
21
  tx = apo.transaction
@@ -0,0 +1,33 @@
1
+ require 'pp'
2
+ require 'nem'
3
+
4
+ Nem.logger.level = Logger::DEBUG
5
+
6
+ FIXTURES_PATH = File.expand_path('../../../spec/fixtures', __FILE__)
7
+
8
+ # sender
9
+ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
10
+
11
+ kp = Nem::Keypair.new(A_PRIVATE_KEY)
12
+ node = Nem::Node.new(host: 'bigalice2.nem.ninja')
13
+ tx_endpoint = Nem::Endpoint::Transaction.new(node)
14
+
15
+ file = File.open("#{FIXTURES_PATH}/nemLogoV2.png")
16
+ apo = Nem::Apostille.new(kp, file, :sha256,
17
+ multisig: false,
18
+ signed: true,
19
+ network: :testnet
20
+ )
21
+ tx = apo.transaction
22
+ pp "Fee: #{tx.fee.to_i}"
23
+
24
+ req = Nem::Request::Announce.new(tx, kp)
25
+ res = tx_endpoint.announce(req)
26
+
27
+ pp "Message: #{res.message}"
28
+ pp "TransactionHash: #{res.transaction_hash}"
29
+ pp "ApostilleFormat: #{apo.apostille_format(res.transaction_hash)}"
30
+ pp "DedicatedPrivateKey: #{apo.dedicated_keypair.private}"
31
+
32
+ FileUtils.cp(file.path, apo.apostille_format(res.transaction_hash))
33
+ File.write('dedicatedPrivateKey.txt', apo.dedicated_keypair.private)
@@ -27,25 +27,12 @@ moa = Nem::Model::MosaicAttachment.new(
27
27
  )
28
28
  tx.mosaics << moa
29
29
 
30
- # define custom mosaic attachment
31
- class KonHeart < Nem::Model::MosaicAttachment
32
- def initialize(quantity)
33
- # set values what you defined
34
- mosaic_id = Nem::Model::MosaicId.new(
35
- namespace_id: 'kon',
36
- name: 'heart'
37
- )
38
- # set values what you defined
39
- properties = Nem::Model::MosaicProperties.new(
40
- divisibility: 3,
41
- initial_supply: 100_000_000
42
- )
43
- super(
44
- mosaic_id: mosaic_id,
45
- properties: properties,
46
- quantity: quantity
47
- )
48
- end
30
+ # define custom mosaic attachment if you already know definition.
31
+ class KonHeart < Nem::Mosaic::Base
32
+ namespace_id 'kon'
33
+ name 'heart'
34
+ divisibility 3
35
+ initial_supply 100_000_000
49
36
  end
50
37
  tx.mosaics << KonHeart.new(1)
51
38
 
data/lib/nem/apostille.rb CHANGED
@@ -6,22 +6,27 @@ require 'digest/sha3'
6
6
  class Nem::Apostille
7
7
  CHECKSUM = 'fe4e5459'.freeze
8
8
 
9
+ attr_reader :dedicated_keypair
10
+
9
11
  # @param [Nem::Keypair] keypair
10
- # @param [string] file - The file
11
- # @param [symbol] hashing - An hashing type (md5, sha1, sha256, sha3-256, sha3-512)
12
- # @param [boolean] multisig - true if transaction is multisig, false otherwise
13
- # @param [boolean] private - true if apostille is private / transferable / updateable, false if public
14
- def initialize(keypair, file, hashing = :sha256, multisig: false, private: false, network: nil)
12
+ # @param [String] file - The file
13
+ # @param [Symbol] hashing - An hashing type (md5, sha1, sha256, sha3-256, sha3-512)
14
+ # @param [Boolean] multisig - true if transaction is multisig, false otherwise
15
+ # @param [Symbol] signed - true if apostille is private / transferable / updateable, false if public
16
+ def initialize(keypair, file, hashing = :sha256, multisig: false, signed: false, network: nil)
15
17
  @keypair = keypair
16
18
  @file = file
17
19
  @hashing = hashing
18
20
  @multisig = multisig
19
- @private = private
21
+ @signed = signed
20
22
  @network = network || Nem.default_network
23
+
24
+ # TDOD: support multisig apostille
25
+ raise NotImplementedError, 'Sorry, Not yet multisig apostille' if multisig?
21
26
  end
22
27
 
23
- def private?
24
- @private
28
+ def signed?
29
+ @signed
25
30
  end
26
31
 
27
32
  def multisig?
@@ -29,13 +34,16 @@ class Nem::Apostille
29
34
  end
30
35
 
31
36
  def transaction
32
- if private?
33
- raise 'Not implemented private apostille.'
37
+ if signed?
38
+ @dedicated_keypair = generate_keypair
39
+ apostille_hash = header << @keypair.sign(calc_hash)
40
+ dedicated_address = Nem::Unit::Address.from_public_key(@dedicated_keypair.public, @network)
34
41
  else
42
+ apostille_hash = header << calc_hash
35
43
  dedicated_address = apostille[:sink]
36
- apostille_hash = calc_hash
37
44
  end
38
45
 
46
+ # TDOD: support multisig apostille
39
47
  Nem::Transaction::Transfer.new(dedicated_address, 0, apostille_hash)
40
48
  end
41
49
 
@@ -53,8 +61,18 @@ class Nem::Apostille
53
61
 
54
62
  private
55
63
 
64
+ def generate_keypair
65
+ filename = File.basename(@file.path)
66
+ signed_filename = @keypair.sign(Digest::SHA256.hexdigest(filename))
67
+ signed_filename = "#{'0' * 64}#{signed_filename.sub(/^00/i, '')}"[-64, 64]
68
+ Nem::Keypair.new(signed_filename)
69
+ end
70
+
71
+ def header
72
+ "#{CHECKSUM}#{hex_type}"
73
+ end
74
+
56
75
  def calc_hash
57
- checksum = "#{CHECKSUM}#{hex_type}"
58
76
  hashed = case @hashing
59
77
  when /\Amd5\z/ then Digest::MD5.file(@file)
60
78
  when /\Asha1\z/ then Digest::SHA1.file(@file)
@@ -62,7 +80,7 @@ class Nem::Apostille
62
80
  when /\Asha3-256\z/ then Digest::SHA3.file(@file, 256)
63
81
  else Digest::SHA3.file(@file, 512)
64
82
  end
65
- checksum << hashed.hexdigest
83
+ hashed.hexdigest
66
84
  end
67
85
 
68
86
  def algo
@@ -77,28 +95,21 @@ class Nem::Apostille
77
95
  end
78
96
 
79
97
  def version
80
- private? ? 0x80 : 0x00
98
+ signed? ? 0x80 : 0x00
81
99
  end
82
100
 
83
101
  def hex_type
84
- '%02x' % (algo | version)
102
+ '%02x' % (version | algo)
85
103
  end
86
104
 
87
105
  def apostille
106
+ raise 'No need SINK Address for private apostille.' if signed?
88
107
  if @network == :mainnet
89
- if private?
90
- raise 'Not implemented private apostille.'
91
- else
92
- { private_key: nil,
93
- sink: 'NCZSJHLTIMESERVBVKOW6US64YDZG2PFGQCSV23J' }
94
- end
108
+ { private_key: nil,
109
+ sink: 'NCZSJHLTIMESERVBVKOW6US64YDZG2PFGQCSV23J' }
95
110
  else
96
- if private?
97
- raise 'Not implemented private apostille.'
98
- else
99
- { private_key: nil,
100
- sink: 'TC7MCY5AGJQXZQ4BN3BOPNXUVIGDJCOHBPGUM2GE' }
101
- end
111
+ { private_key: nil,
112
+ sink: 'TC7MCY5AGJQXZQ4BN3BOPNXUVIGDJCOHBPGUM2GE' }
102
113
  end
103
114
  end
104
115
  end
@@ -8,19 +8,27 @@ class Nem::ApostilleAudit
8
8
 
9
9
  # @param [File] file
10
10
  # @param [apostille_hash] Apostille formatted hash
11
- def initialize(file, apostille_hash)
11
+ def initialize(file, apostille_hash, signer = nil)
12
+ @signer = signer
12
13
  @file = file
13
14
  @apostille_hash = apostille_hash
14
15
  @checksum, @version, @algo, @hash = split_apostille_hash
15
16
  end
16
17
 
17
18
  def valid?
18
- raise 'Not implemented private apostille' if private?
19
19
  raise "Invalid checksum: #{@checksum}" unless @checksum == CHECKSUM
20
- @hash == calc_hash
20
+ if signed? && @signer
21
+ KeyPair.verify_signature(
22
+ @signer,
23
+ @hash,
24
+ @apostille_hash
25
+ )
26
+ else
27
+ @hash == calc_hash
28
+ end
21
29
  end
22
30
 
23
- def private?
31
+ def signed?
24
32
  @version == 0x80
25
33
  end
26
34
 
@@ -2,16 +2,19 @@ module Nem
2
2
  module Endpoint
3
3
  class Chain < Nem::Endpoint::Base
4
4
  # @return [Nem::Model::Block]
5
+ # @see https://nemproject.github.io/#last-block-of-the-block-chain-score
5
6
  def last_block
6
7
  Nem::Model::Block.new_from_block request!(:get, '/chain/last-block')
7
8
  end
8
9
 
9
10
  # @return [Numeric]
11
+ # @see https://nemproject.github.io/#block-chain-height
10
12
  def height
11
13
  request!(:get, '/chain/height')[:height]
12
14
  end
13
15
 
14
16
  # @return [String]
17
+ # @see https://nemproject.github.io/#block-chain-score
15
18
  def score
16
19
  request!(:get, '/chain/score')[:score]
17
20
  end
@@ -1,6 +1,8 @@
1
1
  module Nem
2
2
  module Endpoint
3
3
  class Debug < Nem::Endpoint::Base
4
+ # @return [Nem::Model::Timesync]
5
+ # @see https://nemproject.github.io/#monitoring-the-network-time
4
6
  def time_syncronization
5
7
  request!(:get, '/debug/time-synchronization') do |res|
6
8
  res[:data].map do |sync|
@@ -9,6 +11,7 @@ module Nem
9
11
  end
10
12
  end
11
13
 
14
+ # @see https://nemproject.github.io/#monitoring-timers
12
15
  def timers
13
16
  request!(:get, '/debug/timers') do |res|
14
17
  res[:data].map do |timer|
@@ -18,6 +21,7 @@ module Nem
18
21
  end
19
22
 
20
23
  Connection = Struct.new(:outstanding, :most_recent)
24
+ # @see https://nemproject.github.io/#monitoring-incoming-and-outgoing-calls
21
25
  def connections_incoming
22
26
  request!(:get, '/debug/connections/incoming') do |res|
23
27
  outstanding = res[:outstanding].map do |con|
@@ -30,6 +34,7 @@ module Nem
30
34
  end
31
35
  end
32
36
 
37
+ # @see https://nemproject.github.io/#monitoring-incoming-and-outgoing-calls
33
38
  def connections_outgoing
34
39
  request!(:get, '/debug/connections/outgoing') do |res|
35
40
  outstanding = res[:outstanding].map do |con|
@@ -2,6 +2,7 @@ module Nem
2
2
  module Endpoint
3
3
  module Local
4
4
  class Account < Nem::Endpoint::Base
5
+ # @see https://nemproject.github.io/#transaction-data-with-decoded-messages
5
6
  def transfers_incoming(value, hash: nil, id: nil, page_size: nil)
6
7
  request!(:post, '/local/account/transfers/incoming',
7
8
  value: value,
@@ -15,6 +16,7 @@ module Nem
15
16
  end
16
17
  end
17
18
 
19
+ # @see https://nemproject.github.io/#transaction-data-with-decoded-messages
18
20
  def transfers_outgoing(value, hash: nil, id: nil, page_size: nil)
19
21
  request!(:post, '/local/account/transfers/outgoing',
20
22
  value: value,
@@ -28,6 +30,7 @@ module Nem
28
30
  end
29
31
  end
30
32
 
33
+ # @see https://nemproject.github.io/#transaction-data-with-decoded-messages
31
34
  def transfers_all(value, hash: nil, id: nil, page_size: nil)
32
35
  request!(:post, '/local/account/transfers/all',
33
36
  value: value,
@@ -1,6 +1,7 @@
1
1
  module Nem
2
2
  module Endpoint
3
3
  class Transaction < Nem::Endpoint::Base
4
+ # @param [String] hash
4
5
  # @return [Nem::Model::Transaction]
5
6
  def find(hash)
6
7
  request!(:get,
@@ -13,6 +14,7 @@ module Nem
13
14
 
14
15
  alias get find
15
16
 
17
+ # @return [Nem::Model::NemAnnounceResult]
16
18
  def announce(req)
17
19
  request!(:post,
18
20
  '/transaction/announce',
@@ -22,6 +24,7 @@ module Nem
22
24
  end
23
25
  end
24
26
 
27
+ # @return [Nem::Model::NemAnnounceResult]
25
28
  def prepare_announce(req)
26
29
  request!(:post,
27
30
  '/transaction/prepare-announce',
data/lib/nem/keypair.rb CHANGED
@@ -18,7 +18,12 @@ module Nem
18
18
  bin_signed.unpack('H*').first
19
19
  end
20
20
 
21
- # https://ryuta46.com/693
21
+ def verify_signature(signer, hash, apostille_hash)
22
+ # TDOD: support private apostille
23
+ raise NotImplementedError, 'Not implemented private apostille'
24
+ end
25
+
26
+ # @return [Nem::Keypair] new key pair
22
27
  def self.generate(seed = SecureRandom.hex(64))
23
28
  new(seed)
24
29
  end
@@ -0,0 +1,29 @@
1
+ module Nem
2
+ module Mixin
3
+ module MosaicDefinition
4
+ def namespace_id(value)
5
+ define_method "#{__method__}" do
6
+ value
7
+ end
8
+ end
9
+
10
+ def name(value)
11
+ define_method "#{__method__}" do
12
+ value
13
+ end
14
+ end
15
+
16
+ def divisibility(value)
17
+ define_method "#{__method__}" do
18
+ value
19
+ end
20
+ end
21
+
22
+ def initial_supply(value)
23
+ define_method "#{__method__}" do
24
+ value
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ module Nem
2
+ module Mosaic
3
+ class Base < Nem::Model::MosaicAttachment
4
+ extend Nem::Mixin::MosaicDefinition
5
+
6
+ def initialize(quantity)
7
+ mosaic_id = Nem::Model::MosaicId.new(
8
+ namespace_id: namespace_id,
9
+ name: name
10
+ )
11
+ properties = Nem::Model::MosaicProperties.new(
12
+ divisibility: divisibility,
13
+ initial_supply: initial_supply
14
+ )
15
+ super(
16
+ mosaic_id: mosaic_id,
17
+ properties: properties,
18
+ quantity: quantity
19
+ )
20
+ end
21
+
22
+ def namespace_id
23
+ raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
24
+ end
25
+
26
+ def name
27
+ raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
28
+ end
29
+
30
+ def divisibility
31
+ raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
32
+ end
33
+
34
+ def initial_supply
35
+ raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,21 +1,10 @@
1
1
  module Nem
2
2
  module Mosaic
3
- class DimCoin < Nem::Model::MosaicAttachment
4
- def initialize(quantity)
5
- mosaic_id = Nem::Model::MosaicId.new(
6
- namespace_id: 'dim',
7
- name: 'coin'
8
- )
9
- properties = Nem::Model::MosaicProperties.new(
10
- divisibility: 6,
11
- initial_supply: 900_000_000
12
- )
13
- super(
14
- mosaic_id: mosaic_id,
15
- properties: properties,
16
- quantity: quantity
17
- )
18
- end
3
+ class DimCoin < Base
4
+ namespace_id 'dim'
5
+ name 'coin'
6
+ divisibility 6
7
+ initial_supply 900_000_000
19
8
  end
20
9
  end
21
10
  end
@@ -1,21 +1,10 @@
1
1
  module Nem
2
2
  module Mosaic
3
- class DimToken < Nem::Model::MosaicAttachment
4
- def initialize(quantity)
5
- mosaic_id = Nem::Model::MosaicId.new(
6
- namespace_id: 'dim',
7
- name: 'token'
8
- )
9
- properties = Nem::Model::MosaicProperties.new(
10
- divisibility: 6,
11
- initial_supply: 1_000_000
12
- )
13
- super(
14
- mosaic_id: mosaic_id,
15
- properties: properties,
16
- quantity: quantity
17
- )
18
- end
3
+ class DimToken < Base
4
+ namespace_id 'dim'
5
+ name 'token'
6
+ divisibility 6
7
+ initial_supply 1_000_000
19
8
  end
20
9
  end
21
10
  end
@@ -1,21 +1,10 @@
1
1
  module Nem
2
2
  module Mosaic
3
- class EcobitEco < Nem::Model::MosaicAttachment
4
- def initialize(quantity)
5
- mosaic_id = Nem::Model::MosaicId.new(
6
- namespace_id: 'ecobit',
7
- name: 'eco'
8
- )
9
- properties = Nem::Model::MosaicProperties.new(
10
- divisibility: 0,
11
- initial_supply: 888_888_888
12
- )
13
- super(
14
- mosaic_id: mosaic_id,
15
- properties: properties,
16
- quantity: quantity
17
- )
18
- end
3
+ class EcobitEco < Base
4
+ namespace_id 'ecobit'
5
+ name 'eco'
6
+ divisibility 0
7
+ initial_supply 888_888_888
19
8
  end
20
9
  end
21
10
  end
@@ -1,21 +1,10 @@
1
1
  module Nem
2
2
  module Mosaic
3
- class Xem < Nem::Model::MosaicAttachment
4
- def initialize(quantity)
5
- mosaic_id = Nem::Model::MosaicId.new(
6
- namespace_id: 'nem',
7
- name: 'xem'
8
- )
9
- properties = Nem::Model::MosaicProperties.new(
10
- divisibility: 6,
11
- initial_supply: 8_999_999_999
12
- )
13
- super(
14
- mosaic_id: mosaic_id,
15
- properties: properties,
16
- quantity: quantity
17
- )
18
- end
3
+ class Xem < Base
4
+ namespace_id 'nem'
5
+ name 'xem'
6
+ divisibility 6
7
+ initial_supply 8_999_999_999
19
8
  end
20
9
  end
21
10
  end
@@ -45,7 +45,7 @@ module Nem
45
45
  end
46
46
 
47
47
  def to_hash
48
- raise 'it must be implemented by child class.'
48
+ raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
49
49
  end
50
50
  end
51
51
  end
@@ -3,7 +3,7 @@ module Nem
3
3
  # @attr [String] remote_account
4
4
  # @attr [Symbol] mode
5
5
  # @see https://nemproject.github.io/#importanceTransferTransaction
6
- class ImportanceTransfer < Nem::Transaction::Base
6
+ class ImportanceTransfer < Base
7
7
  TYPE = 0x0801 # 2049 (importance transfer transaction)
8
8
 
9
9
  ACTIVATE = 0x0001
@@ -4,7 +4,7 @@ module Nem
4
4
  # @attr [Integer] creation_fee
5
5
  # @attr [Integer] creation_fee_sink
6
6
  # @see https://nemproject.github.io/#mosaicDefinitionCreationTransaction
7
- class MosaicDefinitionCreation < Nem::Transaction::Base
7
+ class MosaicDefinitionCreation < Base
8
8
  TYPE = 0x4001 # 16385 (mosaic definition creation transaction)
9
9
 
10
10
  attr_reader :mosaic_definition, :creation_fee, :creation_fee_sink
@@ -4,7 +4,7 @@ module Nem
4
4
  # @attr [Symbol] supply_type
5
5
  # @attr [Integer] delta
6
6
  # @see https://nemproject.github.io/#mosaicSupplyChangeTransaction
7
- class MosaicSupplyChange < Nem::Transaction::Base
7
+ class MosaicSupplyChange < Base
8
8
  TYPE = 0x4002 # 16386 (mosaic supply change transaction)
9
9
 
10
10
  INCREASE = 0x0001
@@ -3,7 +3,7 @@ module Nem
3
3
  # @attr [Nem::Transaction::*] other_trans
4
4
  # @attr [String] signer
5
5
  # @see https://nemproject.github.io/#multisigTransaction
6
- class Multisig < Nem::Transaction::Base
6
+ class Multisig < Base
7
7
  TYPE = 0x1004 # 4100 (multisig transaction)
8
8
 
9
9
  attr_reader :other_trans, :signer
@@ -3,7 +3,7 @@ module Nem
3
3
  # @attr [Array <Nem::Model::MultisigCosignatoryModification>] modifications
4
4
  # @attr [Interger] relative_change
5
5
  # @attr [Interger] min_cosignatories
6
- class MultisigAggregateModification < Nem::Transaction::Base
6
+ class MultisigAggregateModification < Base
7
7
  TYPE = 0x1001 # 4097 (multisig aggregate modification transfer transaction)
8
8
 
9
9
  attr_reader :modifications, :relative_change, :min_cosignatories
@@ -3,7 +3,7 @@ module Nem
3
3
  # @attr [String] other_hash
4
4
  # @attr [String] other_account
5
5
  # @attr [String] signer
6
- class MultisigSignature < Nem::Transaction::Base
6
+ class MultisigSignature < Base
7
7
  TYPE = 0x1002 # 4098 (multisig signature transaction)
8
8
 
9
9
  attr_reader :other_hash, :other_account, :signer
@@ -4,7 +4,7 @@ module Nem
4
4
  # @attr [String] parent
5
5
  # @attr [String] rental_fee_sink
6
6
  # @attr [Integer] rental_fee
7
- class ProvisionNamespace < Nem::Transaction::Base
7
+ class ProvisionNamespace < Base
8
8
  TYPE = 0x2001 # 8193 (provision namespace transaction)
9
9
 
10
10
  attr_reader :new_part, :parent, :rental_fee_sink, :rental_fee
@@ -8,7 +8,7 @@ module Nem
8
8
  # @see https://nemproject.github.io/#initiating-a-transfer-transaction
9
9
  # @see https://nemproject.github.io/#version-1-transfer-transactions
10
10
  # @see https://nemproject.github.io/#version-2-transfer-transactions
11
- class Transfer < Nem::Transaction::Base
11
+ class Transfer < Base
12
12
  TYPE = 0x0101 # 257 (transfer transaction)
13
13
 
14
14
  attr_reader :amount, :recipient, :message, :mosaics
@@ -0,0 +1,70 @@
1
+ require 'openssl'
2
+ require 'base32'
3
+ require 'digest/sha3'
4
+
5
+ module Nem
6
+ module Unit
7
+ # @attr [String] value
8
+ class Address
9
+ attr_accessor :value
10
+
11
+ def initialize(value)
12
+ @value = value
13
+ @first_char = @value[0]
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def valid?
18
+ !!(@value =~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{40}/)
19
+ end
20
+
21
+ # @return [Boolean]
22
+ def mainnet?
23
+ @first_char == 'N'
24
+ end
25
+
26
+ # @return [Boolean]
27
+ def testnet?
28
+ @first_char == 'T'
29
+ end
30
+
31
+ # @return [Boolean]
32
+ def mijin?
33
+ @first_char == 'M'
34
+ end
35
+
36
+ # @return [String]
37
+ def to_s
38
+ @value
39
+ end
40
+
41
+ # @return [String]
42
+ def to_hexadecimal
43
+ @value.each_byte.inject('') { |memo, b| memo << b.to_s(16) }
44
+ end
45
+
46
+ # @return [Boolean]
47
+ def ==(other)
48
+ @value == other.value
49
+ end
50
+
51
+ def self.from_public_key(public_key, network = :testnet)
52
+ bin_public_key = Nem::Util::Convert.hex2bin(public_key)
53
+ public_key_hash = Digest::SHA3.digest(bin_public_key, 256)
54
+ ripe = OpenSSL::Digest::RIPEMD160.digest(public_key_hash)
55
+
56
+ if network == :testnet
57
+ version = "\x98".force_encoding('ASCII-8BIT') << ripe
58
+ elsif network == :mijin
59
+ version = "\x60" << ripe
60
+ else
61
+ version = "\x68" << ripe
62
+ end
63
+
64
+ checksum = Digest::SHA3.digest(version, 256)[0...4]
65
+ # self.new(Base32.encode(version + checksum))
66
+ Base32.encode(version + checksum)
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/nem/unit.rb ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ Dir.glob(File.expand_path('unit/*.rb', __dir__)).each { |f| require f }
data/lib/nem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nem
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/nem.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'nem/version'
2
2
  require 'nem/error'
3
3
  require 'nem/configuration'
4
+ require 'nem/unit'
4
5
  require 'nem/util'
5
6
  require 'nem/fee'
6
7
  require 'nem/mixin'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nem-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Ieyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-31 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -194,8 +194,9 @@ files:
194
194
  - LICENSE
195
195
  - README.md
196
196
  - Rakefile
197
- - examples/apostille_audit.rb
198
- - examples/apostille_create.rb
197
+ - examples/apostille/audit.rb
198
+ - examples/apostille/create.rb
199
+ - examples/apostille/create_private.rb
199
200
  - examples/endpoint/account.rb
200
201
  - examples/endpoint/account_local.rb
201
202
  - examples/endpoint/block.rb
@@ -255,6 +256,7 @@ files:
255
256
  - lib/nem/keypair.rb
256
257
  - lib/nem/mixin.rb
257
258
  - lib/nem/mixin/assignable.rb
259
+ - lib/nem/mixin/mosaic.rb
258
260
  - lib/nem/model.rb
259
261
  - lib/nem/model/account.rb
260
262
  - lib/nem/model/account_historical.rb
@@ -296,6 +298,7 @@ files:
296
298
  - lib/nem/model/transfer_transaction.rb
297
299
  - lib/nem/model/unlocked_info.rb
298
300
  - lib/nem/mosaic.rb
301
+ - lib/nem/mosaic/base.rb
299
302
  - lib/nem/mosaic/dim_coin.rb
300
303
  - lib/nem/mosaic/dim_token.rb
301
304
  - lib/nem/mosaic/ecobit_eco.rb
@@ -315,6 +318,8 @@ files:
315
318
  - lib/nem/transaction/multisig_signature.rb
316
319
  - lib/nem/transaction/provision_namespace.rb
317
320
  - lib/nem/transaction/transfer.rb
321
+ - lib/nem/unit.rb
322
+ - lib/nem/unit/address.rb
318
323
  - lib/nem/util.rb
319
324
  - lib/nem/util/convert.rb
320
325
  - lib/nem/util/deserializer.rb