nis-ruby 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -33
  3. data/examples/account/generate.rb +29 -0
  4. data/examples/account/get.rb +26 -0
  5. data/examples/account/harvests.rb +8 -0
  6. data/examples/account/historical.rb +13 -0
  7. data/examples/account/importances.rb +8 -0
  8. data/examples/account/lock.rb +8 -0
  9. data/examples/account/mosaic.rb +9 -0
  10. data/examples/account/namespace.rb +8 -0
  11. data/examples/account/status.rb +8 -0
  12. data/examples/account/transfers.rb +16 -0
  13. data/examples/account/unconfirmed_transactions.rb +8 -0
  14. data/examples/account/unlock.rb +8 -0
  15. data/examples/account/unlocked.rb +8 -0
  16. data/examples/block/at_public.rb +4 -0
  17. data/examples/block/get.rb +4 -0
  18. data/examples/debug/connections.rb +13 -0
  19. data/examples/debug/time_synchronization.rb +6 -0
  20. data/examples/local/account_transfers.rb +20 -0
  21. data/examples/local/chain_blocks_after.rb +8 -0
  22. data/examples/namespace/mosaic_definition.rb +6 -0
  23. data/examples/namespace/root.rb +6 -0
  24. data/examples/nis.rb +11 -7
  25. data/examples/node/active_peers.rb +6 -0
  26. data/examples/node/boot.rb +25 -0
  27. data/examples/node/info.rb +8 -0
  28. data/examples/node/peerlist.rb +14 -0
  29. data/examples/time_sync/network_time.rb +6 -0
  30. data/examples/transactions/get.rb +42 -0
  31. data/examples/transactions/importance_transfer.rb +6 -4
  32. data/examples/transactions/mosaic_definition_creation.rb +6 -4
  33. data/examples/transactions/mosaic_supply_change.rb +6 -4
  34. data/examples/transactions/multisig.rb +6 -4
  35. data/examples/transactions/multisig_add_cosignatory.rb +3 -1
  36. data/examples/transactions/multisig_aggregate_modification.rb +6 -4
  37. data/examples/transactions/multisig_signature.rb +6 -3
  38. data/examples/transactions/provision_namespace.rb +6 -4
  39. data/examples/transactions/transfer.rb +14 -7
  40. data/examples/transactions/transfer_mosaic.rb +5 -3
  41. data/examples/transactions/transfer_remote.rb +6 -4
  42. data/lib/nis.rb +6 -0
  43. data/lib/nis/client.rb +11 -0
  44. data/lib/nis/configuration.rb +23 -0
  45. data/lib/nis/endpoint/account/transfers.rb +24 -0
  46. data/lib/nis/endpoint/debug/connections.rb +17 -0
  47. data/lib/nis/endpoint/local/account/transfers.rb +14 -0
  48. data/lib/nis/endpoint/node/peer_list.rb +20 -0
  49. data/lib/nis/endpoint/time_sync.rb +4 -0
  50. data/lib/nis/endpoint/time_sync/network_time.rb +10 -0
  51. data/lib/nis/endpoint/transaction/get.rb +12 -0
  52. data/lib/nis/keypair.rb +13 -7
  53. data/lib/nis/struct.rb +1 -0
  54. data/lib/nis/struct/importance_transfer_transaction.rb +10 -0
  55. data/lib/nis/struct/message.rb +9 -2
  56. data/lib/nis/struct/mosaic_definition_creation_transaction.rb +15 -0
  57. data/lib/nis/struct/mosaic_supply_change_transaction.rb +12 -0
  58. data/lib/nis/struct/multisig_aggregate_modification_transaction.rb +10 -0
  59. data/lib/nis/struct/multisig_signature_transaction.rb +12 -0
  60. data/lib/nis/struct/multisig_transaction.rb +15 -0
  61. data/lib/nis/struct/network_time.rb +17 -0
  62. data/lib/nis/struct/provision_namespace_transaction.rb +16 -0
  63. data/lib/nis/struct/transaction.rb +4 -81
  64. data/lib/nis/struct/transaction_meta_data_pair.rb +17 -1
  65. data/lib/nis/struct/transfer_transaction.rb +11 -0
  66. data/lib/nis/unit/address.rb +11 -4
  67. data/lib/nis/util.rb +3 -1
  68. data/lib/nis/util/convert.rb +44 -51
  69. data/lib/nis/util/deserializer.rb +62 -77
  70. data/lib/nis/util/ed25519.rb +10 -12
  71. data/lib/nis/util/serializer.rb +117 -185
  72. data/lib/nis/version.rb +1 -1
  73. data/nis.gemspec +0 -3
  74. metadata +43 -26
  75. data/bin/nis +0 -60
  76. data/examples/account.rb +0 -44
  77. data/examples/block.rb +0 -9
  78. data/examples/debug.rb +0 -33
  79. data/examples/local.rb +0 -19
  80. data/examples/namespace.rb +0 -9
  81. data/examples/node.rb +0 -44
  82. data/examples/shutdown.rb +0 -6
@@ -0,0 +1,11 @@
1
+ class Nis::Struct
2
+ # @attr [String] recipient
3
+ # @attr [Integer] amount
4
+ # @attr [Nis::Struct::Message] message
5
+ # @attr [Array <Nis::Struct::MosaicId>] mosaics
6
+ # @see https://nemproject.github.io/#version-1-transfer-transactions
7
+ # @see https://nemproject.github.io/#version-2-transfer-transactions
8
+ class TransferTransaction < Transaction
9
+ attr_accessor :recipient, :amount, :message, :mosaics
10
+ end
11
+ end
@@ -27,6 +27,11 @@ module Nis::Unit
27
27
  @first_char == 'T'
28
28
  end
29
29
 
30
+ # @return [Boolean]
31
+ def mijin?
32
+ @first_char == 'M'
33
+ end
34
+
30
35
  # @return [String]
31
36
  def to_s
32
37
  @value
@@ -34,7 +39,7 @@ module Nis::Unit
34
39
 
35
40
  # @return [String]
36
41
  def to_hexadecimal
37
- @value.each_byte.map { |b| b.to_s(16) }.join
42
+ @value.each_byte.inject('') { |memo, b| memo << b.to_s(16) }
38
43
  end
39
44
 
40
45
  # @return [Boolean]
@@ -43,14 +48,16 @@ module Nis::Unit
43
48
  end
44
49
 
45
50
  def self.from_public_key(public_key, network = :testnet)
46
- bin_public_key = public_key.scan(/../).map(&:hex).pack('C*')
51
+ bin_public_key = Nis::Util::Convert.hex2bin(public_key)
47
52
  public_key_hash = Digest::SHA3.digest(bin_public_key, 256)
48
53
  ripe = OpenSSL::Digest::RIPEMD160.digest(public_key_hash)
49
54
 
50
55
  if network == :testnet
51
- version = "\x98".force_encoding('ASCII-8BIT') + ripe
56
+ version = "\x98".force_encoding('ASCII-8BIT') << ripe
57
+ elsif network == :mijin
58
+ version = "\x60" << ripe
52
59
  else
53
- version = "\x68" + ripe
60
+ version = "\x68" << ripe
54
61
  end
55
62
 
56
63
  checksum = Digest::SHA3.digest(version, 256)[0...4]
@@ -1,4 +1,5 @@
1
1
  module Nis::Util
2
+ MIJIN = 0x60000000
2
3
  TESTNET = 0x98000000 # -1744830464
3
4
  MAINNET = 0x68000000 # 1744830464
4
5
 
@@ -23,6 +24,7 @@ module Nis::Util
23
24
 
24
25
  def self.parse_network(network)
25
26
  case network
27
+ when :mijin then MIJIN
26
28
  when :mainnet then MAINNET
27
29
  when :testnet then TESTNET
28
30
  else TESTNET
@@ -38,7 +40,7 @@ module Nis::Util
38
40
  end
39
41
 
40
42
  def self.timestamp
41
- (Time.now - NEM_EPOCH).to_i
43
+ (Time.now.utc - NEM_EPOCH).to_i
42
44
  end
43
45
 
44
46
  def self.error_handling(hash)
@@ -16,37 +16,47 @@ module Nis::Util
16
16
  hex.scan(/../).map(&:hex)
17
17
  end
18
18
 
19
- # Convert an Uint8Array to hex
20
- # @param [Uint8Array] ua - An Uint8Array
21
- # @return [string]
22
- def self.ua2hex(ua)
23
- ua.map { |el| "#{HEX_ENCODE_ARRAY[el >> 4]}#{HEX_ENCODE_ARRAY[el & 0x0f]}" }.join
24
- end
25
-
26
19
  # Convert hex to string
27
20
  # @param [String] hex
28
21
  # @return [String]
29
22
  def self.hex2a(hex)
30
- hex.scan(/../).map { |el| el.to_i(16).chr }.join
23
+ hex.scan(/../).inject('') { |memo, el| memo << el.hex.chr }
24
+ end
25
+
26
+ # @param [Array] bin
27
+ # @return [String]
28
+ def self.hex2bin(hex)
29
+ hex2ua(hex).pack('C*')
30
+ end
31
+
32
+ # @param [Array] bin
33
+ # @return [String]
34
+ def self.hex2bin_rev(hex)
35
+ hex2ua_rev(hex).pack('C*')
36
+ end
37
+
38
+ # @param [Array] bin
39
+ # @return [String]
40
+ def self.bin2hex(bin)
41
+ bin.map { |v| '%02x' % v }.join
31
42
  end
32
43
 
33
44
  # Convert UTF-8 to hex
34
45
  # @param [string] str
35
46
  # @return [string]
36
47
  def self.utf8_to_hex(str)
37
- rstr2utf8(str).each_byte.map { |b| b.to_s(16) }.join
48
+ rstr2utf8(str).bytes.inject('') { |memo, b| memo << b.to_s(16) }
38
49
  end
39
50
 
40
- # // Padding helper for above function
41
- # let strlpad = function(str, pad, len) {
42
- # while (str.length < len) {
43
- # str = pad + str;
44
- # }
45
- # return str;
46
- # }
51
+ # Convert an Array to hex
52
+ # @param [Array] ua - An Uint8Array
53
+ # @return [string]
54
+ def self.ua2hex(ua)
55
+ ua.inject('') { |memo, el| memo << "#{HEX_ENCODE_ARRAY[el >> 4]}#{HEX_ENCODE_ARRAY[el & 0x0f]}" }
56
+ end
47
57
 
48
58
  # Convert an Uint8Array to WordArray
49
- # @param [Uint8Array] ua - An Uint8Array
59
+ # @param [Array] ua - An Uint8Array
50
60
  # @param [number] uaLength - The Uint8Array length
51
61
  # @return [WordArray]
52
62
  def self.ua2words(ua, ua_length)
@@ -60,58 +70,41 @@ module Nis::Util
60
70
  end
61
71
 
62
72
  # Convert a wordArray to Uint8Array
63
- # @param [Uint8Array] destUa - A destination Uint8Array
64
- # @param [WordArray] cryptowords - A wordArray
65
- # @return [Uint8Array]
73
+ # @param [Array] destUa - A destination Uint8Array
74
+ # @param [Array] cryptowords - A wordArray
75
+ # @return [Array]
66
76
  def self.words2ua(words)
67
- words.map do |v|
77
+ words.inject([]) do |memo, v|
68
78
  temp = []
69
79
  v += 0x100000000 if v < 0
70
80
  temp[0] = (v >> 24)
71
81
  temp[1] = (v >> 16) & 0xff
72
82
  temp[2] = (v >> 8) & 0xff
73
83
  temp[3] = (v) & 0xff
74
- temp
75
- end.flatten
84
+ memo + temp
85
+ end
76
86
  end
77
87
 
78
88
  # Converts a raw javascript string into a string of single byte characters using utf8 encoding.
79
89
  # This makes it easier to perform other encoding operations on the string.
80
90
  # @param [String] str
81
91
  # @return [String]
82
- def self.rstr2utf8(input)
83
- input.unpack('U*').map do |c|
84
- case
85
- when c < 128
86
- c
87
- when 128 < c && c < 2048
88
- [((c >> 6) | 192), ((c & 63) | 128)]
89
- else
90
- [((c >> 12) | 224), (((c >> 6) & 63) | 128), ((c & 63) | 128)]
92
+ def self.rstr2utf8(str)
93
+ str.unpack('U*').inject('') do |memo, c|
94
+ memo << case
95
+ when c < 128
96
+ c.chr
97
+ when 128 < c && c < 2048
98
+ (c >> 6 | 192).chr + (c & 63 | 128).chr
99
+ else
100
+ (c >> 12 | 224).chr + (c >> 6 & 63 | 128).chr + (c & 63 | 128).chr
91
101
  end
92
- end.flatten.map(&:chr).join
102
+ end
93
103
  end
94
104
 
95
105
  # Does the reverse of rstr2utf8.
96
106
  def utf82rstr(input)
97
- # let output = "", i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0;
98
- # while (i < input.length) {
99
- # c = input.charCodeAt(i);
100
- # if (c < 128) {
101
- # output += String.fromCharCode(c);
102
- # i++;
103
- # } else if ((c > 191) && (c < 224)) {
104
- # c2 = input.charCodeAt(i + 1);
105
- # output += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
106
- # i += 2;
107
- # } else {
108
- # c2 = input.charCodeAt(i + 1);
109
- # c3 = input.charCodeAt(i + 2);
110
- # output += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
111
- # i += 3;
112
- # }
113
- # }
114
- # return output;
107
+ raise 'Not implemented.'
115
108
  end
116
109
  end
117
110
  end
@@ -5,7 +5,9 @@ module Nis::Util
5
5
  # @return [Hash]
6
6
  def self.deserialize_transaction(serialized)
7
7
  s = Nis::Util::Convert.hex2ua(serialized)
8
- type = deserialize_int(s[0, 4])
8
+ common = s[0, 60]
9
+ specific = s[60, s.size]
10
+ type = deserialize_int(common[0, 4])
9
11
  method = case type
10
12
  when 0x0101 then method(:deserialize_transfer)
11
13
  when 0x0801 then method(:deserialize_importance_transfer)
@@ -17,143 +19,126 @@ module Nis::Util
17
19
  when 0x4002 then method(:deserialize_mosaic_supply_change)
18
20
  else raise "Not implemented entity type: #{type}"
19
21
  end
20
- method.call(serialized)
22
+ deserialize_common(common).merge(method.call(specific))
21
23
  end
22
24
 
25
+ private
26
+
23
27
  # Deserialize a transfer transaction object
24
28
  # @param [String] serialized
25
29
  # @return [Hash]
26
- def self.deserialize_transfer(serialized)
27
- s = Nis::Util::Convert.hex2ua(serialized)
28
- common = deserialize_common(s)
30
+ def self.deserialize_transfer(s)
29
31
  tx = {}
30
- # s[60,4] # length of address
31
- tx[:recipient] = deserialize_a(s[64, 40])
32
- tx[:amount] = deserialize_int(s[104, 8])
32
+ tx[:recipient] = deserialize_a(s[4, 40])
33
+ tx[:amount] = deserialize_int(s[44, 8])
33
34
  tx[:message] = {}
34
- message_len = deserialize_int(s[112, 4])
35
+ message_len = deserialize_int(s[52, 4])
35
36
  if message_len > 0
36
- tx[:message][:type] = deserialize_int(s[116, 4])
37
- # s[120, 4] # length of payload
38
- tx[:message][:payload] = deserialize_hex(s[124, s.size])
37
+ # s[60, 4] # length of payload
38
+ tx[:message] = {
39
+ type: deserialize_int(s[56, 4]),
40
+ payload: deserialize_hex(s[64, s.size])
41
+ }
39
42
  else
40
43
  tx[:message] = { type: 1, payload: '' }
41
44
  end
42
- common.merge(tx)
45
+ tx
43
46
  end
44
47
 
45
48
  # Deserialize a importance transaction object
46
49
  # @param [String] serialized
47
50
  # @return [Hash]
48
- def self.deserialize_importance_transfer(serialized)
49
- s = Nis::Util::Convert.hex2ua(serialized)
50
- common = deserialize_common(s)
51
- tx = {}
52
- tx[:mode] = deserialize_int(s[60, 4])
53
- # s[64, 4] # Length of remote account public key byte array
54
- tx[:remoteAccount] = deserialize_hex(s[68, 32])
55
- common.merge(tx)
51
+ def self.deserialize_importance_transfer(s)
52
+ {
53
+ mode: deserialize_int(s[0, 4]),
54
+ remoteAccount: deserialize_hex(s[8, 32])
55
+ }
56
56
  end
57
57
 
58
58
  # Deserialize a multisig aggregate modification transaction object
59
59
  # @param [String] serialized
60
60
  # @return [Hash]
61
- def self.deserialize_multisig_aggregate_modification(serialized)
61
+ def self.deserialize_multisig_aggregate_modification(s)
62
62
  raise 'Not yet implimented.'
63
- s = Nis::Util::Convert.hex2ua(serialized)
64
- common = deserialize_common(s)
65
- tx = {}
66
63
  # TODO: deserializing
67
- common.merge(tx)
64
+ tx = {}
65
+ tx
68
66
  end
69
67
 
70
68
  # Deserialize a multisig signature transaction object
71
69
  # @param [String] serialized
72
70
  # @return [Hash]
73
- def self.deserialize_multisig_signature(serialized)
74
- s = Nis::Util::Convert.hex2ua(serialized)
75
- common = deserialize_common(s)
76
- tx = {}
77
- tx[:otherHash] = { data: deserialize_hex(s[68, 32]) }
78
- tx[:otherAccount] = deserialize_a(s[104, 40])
79
- common.merge(tx)
71
+ def self.deserialize_multisig_signature(s)
72
+ {
73
+ otherHash: { data: deserialize_hex(s[8, 32]) },
74
+ otherAccount: deserialize_a(s[44, 40])
75
+ }
80
76
  end
81
77
 
82
78
  # Deserialize a multisig transfer transaction object
83
79
  # @param [String] serialized
84
80
  # @return [Hash]
85
- def self.deserialize_multisig(serialized)
81
+ def self.deserialize_multisig(s)
86
82
  raise 'Not yet implimented.'
87
- s = Nis::Util::Convert.hex2ua(serialized)
88
- common = deserialize_common(s)
89
- tx = {}
90
83
  # TODO: deserializing
91
- common.merge(tx)
84
+ tx = {}
85
+ tx
92
86
  end
93
87
 
94
88
  # Deserialize a provision namespace transaction object
95
89
  # @param [String] serialized
96
90
  # @return [Hash]
97
- def self.deserialize_provision_namespace(serialized)
98
- s = Nis::Util::Convert.hex2ua(serialized)
99
- common = deserialize_common(s)
91
+ def self.deserialize_provision_namespace(s)
100
92
  tx = {}
101
- # s[60, 4] # Length of rental fee sink's public key byte array (always 32): 4 bytes
102
- tx[:rentalFeeSink] = deserialize_a(s[64, 40]) # Public key bytes of rental fee sink
103
- tx[:rentalFee] = deserialize_int(s[104, 8]) # Fental fee: 8 bytes
104
- newpart_len = deserialize_int(s[112, 4]) # Length of new part string: 4 bytes
105
- tx[:newPart] = deserialize_a(s[116, newpart_len]) # New part string: UTF8 encoded string.
106
- parent_len = deserialize_int(s[116 + newpart_len, 4]) # Length of parent string: 4 bytes
107
- parent = s[116 + newpart_len, parent_len]
93
+ tx[:rentalFeeSink] = deserialize_a(s[4, 40])
94
+ tx[:rentalFee] = deserialize_int(s[44, 8])
95
+ newpart_len = deserialize_int(s[52, 4])
96
+ tx[:newPart] = deserialize_a(s[56, newpart_len])
97
+ parent_len = deserialize_int(s[56 + newpart_len, 4])
98
+ parent = s[56 + newpart_len, parent_len]
108
99
  unless parent.all? { |val| val == 0xff }
109
- tx[:parent] = deserialize_a(parent) # Parent string: UTF8 encoded string
100
+ tx[:parent] = deserialize_a(parent)
110
101
  end
111
- common.merge(tx)
102
+ tx
112
103
  end
113
104
 
114
105
  # Deserialize a mosaic definition creation transaction object
115
106
  # @param [String] serialized
116
107
  # @return [Hash]
117
- def self.deserialize_mosaic_definition_creation(serialized)
108
+ def self.deserialize_mosaic_definition_creation(s)
118
109
  raise 'Not yet implimented.'
119
- s = Nis::Util::Convert.hex2ua(serialized)
120
- common = deserialize_common(s)
121
- tx = {}
122
110
  # TODO: deserializing
123
- common.merge(tx)
111
+ tx = {}
112
+ tx
124
113
  end
125
114
 
126
115
  # Deserialize a mosaic supply change transaction object
127
116
  # @param [String] serialized
128
117
  # @return [Hash]
129
- def self.deserialize_mosaic_supply_change(serialized)
130
- s = Nis::Util::Convert.hex2ua(serialized)
131
- common = deserialize_common(s)
118
+ def self.deserialize_mosaic_supply_change(s)
132
119
  tx = {}
133
- # s[60, 4] # Length of mosaic id structure
134
- ns_len = deserialize_int(s[64, 4]) # Length of namespace id string
135
- mo_len = deserialize_int(s[68 + ns_len, 4]) # Length of mosaic name string
120
+ # s[0, 4] # Length of mosaic id structure
121
+ ns_len = deserialize_int(s[4, 4])
122
+ mo_len = deserialize_int(s[8 + ns_len, 4])
136
123
  tx[:mosaicId] = {
137
- namespaceId: deserialize_a(s[68, ns_len]),
138
- name: deserialize_a(s[68 + ns_len + mo_len, mo_len])
124
+ namespaceId: deserialize_a(s[8, ns_len]),
125
+ name: deserialize_a(s[8 + ns_len + mo_len, mo_len])
139
126
  }
140
- tx[:supplyType] = deserialize_int(s[68 + ns_len + 4 + mo_len, 4]) # Supply type
141
- tx[:delta] = deserialize_int(s[68 + ns_len + 4 + mo_len + 4, 8]) # Delta (change in supply)
142
- common.merge(tx)
127
+ tx[:supplyType] = deserialize_int(s[8 + ns_len + 4 + mo_len, 4])
128
+ tx[:delta] = deserialize_int(s[8 + ns_len + 4 + mo_len + 4, 8])
129
+ tx
143
130
  end
144
131
 
145
- private
146
-
147
132
  def self.deserialize_common(s)
148
- tx = {}
149
- tx[:type] = deserialize_int(s[0, 4])
150
- tx[:version] = deserialize_int(s[4, 4])
151
- tx[:timeStamp] = deserialize_int(s[8, 4])
152
- # s[12,4] # length of public key
153
- tx[:signer] = deserialize_hex(s[16, 32])
154
- tx[:fee] = deserialize_int(s[48, 8])
155
- tx[:deadline] = deserialize_int(s[56, 4])
156
- tx
133
+ {
134
+ type: deserialize_int(s[0, 4]),
135
+ version: deserialize_int(s[4, 4]),
136
+ timeStamp: deserialize_int(s[8, 4]),
137
+ # s[12,4] # length of public key,
138
+ signer: deserialize_hex(s[16, 32]),
139
+ fee: deserialize_int(s[48, 8]),
140
+ deadline: deserialize_int(s[56, 4])
141
+ }
157
142
  end
158
143
 
159
144
  def self.deserialize_int(ua)
@@ -15,7 +15,7 @@ module Nis::Util
15
15
  end
16
16
 
17
17
  def intlist2bytes(l)
18
- l.map { |c| c.chr }.join
18
+ l.inject('') { |memo, c| memo << c.chr }
19
19
  end
20
20
 
21
21
  # standard implement
@@ -29,7 +29,7 @@ module Nis::Util
29
29
 
30
30
  def pow2(x, p)
31
31
  while p > 0 do
32
- x = x * x % @@q
32
+ x = x.to_bn.mod_exp(2, @@q).to_i
33
33
  p -= 1
34
34
  end
35
35
  x
@@ -112,7 +112,7 @@ module Nis::Util
112
112
 
113
113
  def make_Bpow
114
114
  _P = @@B
115
- (0...253).each do |_|
115
+ 253.times do
116
116
  @@Bpow << _P
117
117
  _P = edwards_double(_P)
118
118
  end
@@ -123,7 +123,7 @@ module Nis::Util
123
123
  # scalarmult(B, l) is the identity
124
124
  e = e % @@l
125
125
  _P = @@ident
126
- (0...253).each do |i|
126
+ 253.times do |i|
127
127
  _P = edwards_add(_P, @@Bpow[i]) if e & 1 == 1
128
128
  e = e / 2
129
129
  end
@@ -132,7 +132,7 @@ module Nis::Util
132
132
 
133
133
  def encodeint(y)
134
134
  bits = (0...@@b).map { |i| (y >> i) & 1 }
135
- (0...@@b / 8).map { |i| int2byte((0...8).inject(0) { |sum, j| sum + (bits[i * 8 + j] << j) }) }.join
135
+ (0...@@b / 8).inject('') { |memo, i| memo << int2byte((0...8).inject(0) { |sum, j| sum + (bits[i * 8 + j] << j) }) }
136
136
  end
137
137
 
138
138
  def encodepoint(_P)
@@ -141,7 +141,7 @@ module Nis::Util
141
141
  x = (x * zi) % @@q
142
142
  y = (y * zi) % @@q
143
143
  bits = (0...@@b - 1).map { |i| (y >> i) & 1 } + [x & 1]
144
- (0...@@b / 8).map { |i| int2byte((0...8).inject(0) { |sum, j| sum + (bits[i * 8 + j] << j) }) }.join
144
+ (0...@@b / 8).inject('') { |memo, i| memo << int2byte((0...8).inject(0) { |sum, j| sum + (bits[i * 8 + j] << j) }) }
145
145
  end
146
146
 
147
147
  def bit(h, i)
@@ -169,15 +169,13 @@ module Nis::Util
169
169
  bin_g = encodepoint(scalarmult(_A, a))
170
170
 
171
171
  bin_iv = SecureRandom.random_bytes(16)
172
- # bin_iv = [133, 235, 90, 141, 29, 234, 234, 20, 115, 237, 164, 88, 224, 87, 29, 82].pack('C*')
173
- hex_iv = bin_iv.unpack('H*').join
172
+ hex_iv = bin_iv.unpack('H*').first
174
173
 
175
174
  bin_salt = SecureRandom.random_bytes(32)
176
- # bin_salt = [35, 150, 208, 176, 6, 179, 135, 220, 197, 253, 164, 147, 164, 177, 228, 43, 143, 146, 245, 255, 226, 71, 44, 94, 218, 169, 117, 88, 98, 241, 115, 79].pack('C*')
177
- hex_salt = bin_salt.unpack('H*').join
175
+ hex_salt = bin_salt.unpack('H*').first
178
176
 
179
177
  ua_salt = Nis::Util::Convert.hex2ua(hex_salt)
180
- ua_g = Nis::Util::Convert.hex2ua(bin_g.unpack('H*').join)
178
+ ua_g = Nis::Util::Convert.hex2ua(bin_g.unpack('H*').first)
181
179
 
182
180
  c = []
183
181
  ua_salt.each_with_index { |el, idx| c << (el ^ ua_g[idx]) }
@@ -188,7 +186,7 @@ module Nis::Util
188
186
  cipher.key = bin_key
189
187
  cipher.iv = bin_iv
190
188
  encrypted_data = cipher.update(data.bytes.pack('C*')) + cipher.final
191
- hex_salt + hex_iv + encrypted_data.unpack('H*').join
189
+ hex_salt + hex_iv + encrypted_data.unpack('H*').first
192
190
  end
193
191
 
194
192
  def decrypt(sk, pk, data)