nis-ruby 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -13
- data/examples/block.rb +2 -4
- data/examples/local.rb +1 -1
- data/examples/transactions/mosaic_definition_creation.rb +1 -1
- data/examples/transactions/mosaic_supply_change.rb +1 -1
- data/examples/transactions/multisig.rb +8 -6
- data/examples/transactions/multisig_add_cosignatory.rb +11 -11
- data/examples/transactions/multisig_aggregate_modification.rb +5 -4
- data/examples/transactions/multisig_signature.rb +10 -10
- data/examples/transactions/provision_namespace.rb +2 -2
- data/examples/transactions/transfer.rb +4 -4
- data/examples/transactions/transfer_mosaic.rb +30 -26
- data/examples/transactions/transfer_remote.rb +4 -4
- data/examples/util/deserialize.rb +14 -0
- data/lib/nis/fee/provision_namespace.rb +2 -2
- data/lib/nis/request/announce.rb +21 -6
- data/lib/nis/request/prepare_announce.rb +19 -4
- data/lib/nis/util/deserializer.rb +134 -9
- data/lib/nis/util/serializer.rb +155 -96
- data/lib/nis/version.rb +1 -1
- data/nis.gemspec +8 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa8c49e0cd78c5bdde006099b1fcda37b2708a64
|
4
|
+
data.tar.gz: cb8a3175db3121d2f761265423b93407ae8013e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 563b492199ffbce3d85d8914eff9d166e60c3f2a6751082980ae2a8a722006a78c07cfd66271433bfbe9b09a42a883e1f493ddcdba52d331d5b48c5bb9c85cb6
|
7
|
+
data.tar.gz: 254df0dfe30be08e4bd7ec23241c181001db04d9d5ca005b7b74f72e636617fff7438a5816fb948a99bd8c27e96e8bcde0722bcc3d0664fc3d8ca1b286200028
|
data/README.md
CHANGED
@@ -35,11 +35,13 @@ gem 'nis-ruby'
|
|
35
35
|
|
36
36
|
### Examples
|
37
37
|
|
38
|
-
More specific example codes are in **examples
|
38
|
+
More specific example codes are in **[examples/](examples/)** directory.
|
39
39
|
|
40
40
|
### Methods
|
41
41
|
|
42
42
|
```ruby
|
43
|
+
require 'rubygems'
|
44
|
+
require 'nis'
|
43
45
|
nis = Nis.new
|
44
46
|
|
45
47
|
nis.heartbeat
|
@@ -53,7 +55,7 @@ nis.status
|
|
53
55
|
kp = Nis::Keypair.new(SENDER_PRIV_KEY)
|
54
56
|
tx = Nis::Transaction::Transfer.new(
|
55
57
|
RECIPIENT_ADDRESS,
|
56
|
-
|
58
|
+
1, # send 1xem
|
57
59
|
'Message'
|
58
60
|
)
|
59
61
|
req = Nis::Request::PrepareAnnounce.new(tx, kp)
|
@@ -63,12 +65,15 @@ nis.transaction_prepare_announce(req)
|
|
63
65
|
# => {innerTransactionHash: {}, code: 1, type: 1, message: "SUCCESS", transactionHash: {data: "9da41fd6c6886740ae6a15c869df0470015d78103e5b216971aa09fdbcce9cde"}}
|
64
66
|
|
65
67
|
# Request to remote node.
|
68
|
+
# nis = Nis.new(host: '104.128.226.60')
|
66
69
|
# nis.transaction_announce(req)
|
67
70
|
```
|
68
71
|
|
69
72
|
### Requesting
|
70
73
|
|
71
74
|
```ruby
|
75
|
+
require 'rubygems'
|
76
|
+
require 'nis'
|
72
77
|
nis = Nis.new
|
73
78
|
|
74
79
|
nis.request(:get, '/account/get',
|
@@ -102,22 +107,22 @@ $ nis request get account/harvests --params=address:TALICELCD3XPH4FFI5STGGNSNSWP
|
|
102
107
|
|
103
108
|
## Connection
|
104
109
|
|
105
|
-
You can
|
110
|
+
You can choose nodes from [NEM Node Rewards](https://supernodes.nem.io/).
|
106
111
|
|
107
112
|
### Hash
|
108
113
|
|
109
114
|
```ruby
|
110
115
|
# Passing hostname
|
111
|
-
Nis.new(host: '
|
116
|
+
Nis.new(host: '104.128.226.60')
|
112
117
|
|
113
118
|
# Passing url
|
114
|
-
Nis.new(url: 'http://
|
119
|
+
Nis.new(url: 'http://104.128.226.60:7890')
|
115
120
|
```
|
116
121
|
|
117
122
|
### Environment Variable
|
118
123
|
|
119
124
|
```bash
|
120
|
-
$ export NIS_URL=http://
|
125
|
+
$ export NIS_URL=http://104.128.226.60:7890
|
121
126
|
$ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
|
122
127
|
```
|
123
128
|
|
@@ -127,13 +132,6 @@ Environment variable used as default value.
|
|
127
132
|
|
128
133
|
* [Documentation for nis-ruby - rubydoc.info](http://www.rubydoc.info/gems/nis-ruby)
|
129
134
|
|
130
|
-
## TODO
|
131
|
-
|
132
|
-
* Do more improvements
|
133
|
-
* Encryption message
|
134
|
-
* Failover connection
|
135
|
-
* Be more easy to use
|
136
|
-
|
137
135
|
## Contact
|
138
136
|
|
139
137
|
Feel free to ask me if you have any questions.
|
data/examples/block.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'nis'
|
2
|
-
hr = '-' * 64
|
3
2
|
|
4
3
|
nis = Nis.new
|
5
4
|
|
6
|
-
block = nis.block_at_public(block_height:
|
5
|
+
block = nis.block_at_public(block_height: 890_761)
|
6
|
+
|
7
7
|
puts block.to_hash
|
8
|
-
puts hr
|
9
8
|
|
10
9
|
puts nis.block_get(block_hash: 'fb5e76bf137eb27451926d29fd2b308e672e5d9ec405d9cbcd47cc0f83492cd0')
|
11
|
-
puts hr
|
data/examples/local.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
3
|
# multisig
|
4
|
-
|
4
|
+
M_PUBLIC_KEY = '00f077782658ae91b77f238ba5fcd7ef110564b5c189072e4d4590d9b17f9d76f3'
|
5
5
|
|
6
6
|
# cosignatory
|
7
|
-
|
8
|
-
B_ADDRESS = 'TAWKJTUP4DWKLDKKS534TYP6G324CBNMXKBA4X7B'
|
7
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
9
8
|
|
10
|
-
|
9
|
+
# recipient
|
10
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
13
|
+
|
14
|
+
ttx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
15
|
+
tx = Nis::Transaction::Multisig.new(ttx, M_PUBLIC_KEY)
|
14
16
|
puts "Fee: #{tx.fee.to_i}"
|
15
17
|
|
16
18
|
nis = Nis.new
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# multisig
|
4
|
+
M_PUBLIC_KEY = '6d72b57d2bc199d328e7ea3e24775f7f614760bc18f3f8501cd3daa9870cc40c'
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# cosignatory1
|
7
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
8
8
|
|
9
|
-
#
|
10
|
-
|
9
|
+
# cosignatory2
|
10
|
+
B_PUBLIC_KEY = '9e7ab2924cd1a3482df784db190614cfc8a33671f5d80a5b15a9c9e8b4d13933'
|
11
11
|
|
12
|
-
kp = Nis::Keypair.new(
|
12
|
+
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
13
13
|
|
14
14
|
mcm = Nis::Struct::MultisigCosignatoryModification.new(
|
15
15
|
modificationType: 1,
|
16
|
-
cosignatoryAccount:
|
16
|
+
cosignatoryAccount: B_PUBLIC_KEY
|
17
17
|
)
|
18
|
-
min_cosigs =
|
19
|
-
mtx = Nis::Transaction::MultisigAggregateModification.new([mcm], min_cosigs)
|
18
|
+
min_cosigs = 1
|
20
19
|
|
21
|
-
|
20
|
+
mtx = Nis::Transaction::MultisigAggregateModification.new([mcm], min_cosigs)
|
21
|
+
tx = Nis::Transaction::Multisig.new(mtx, M_PUBLIC_KEY)
|
22
22
|
|
23
23
|
nis = Nis.new
|
24
24
|
req = Nis::Request::PrepareAnnounce.new(tx, kp)
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
3
|
# multisig
|
4
|
-
|
4
|
+
M_PRIVATE_KEY = '00f077782658ae91b77f238ba5fcd7ef110564b5c189072e4d4590d9b17f9d76f3'
|
5
5
|
|
6
6
|
# cosignatory
|
7
|
-
|
7
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
8
|
+
A_PUBLIC_KEY = 'cc63b4dcdec745417043c3fa0992ec3a1695461a26d90264744648abbd5caa0d'
|
8
9
|
|
9
|
-
kp = Nis::Keypair.new(
|
10
|
+
kp = Nis::Keypair.new(M_PRIVATE_KEY)
|
10
11
|
|
11
12
|
mcm = Nis::Struct::MultisigCosignatoryModification.new(
|
12
13
|
modificationType: 1,
|
13
|
-
cosignatoryAccount:
|
14
|
+
cosignatoryAccount: A_PUBLIC_KEY
|
14
15
|
)
|
15
16
|
min_cosigs = 1
|
16
17
|
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
3
|
# multisig
|
4
|
-
|
5
|
-
|
4
|
+
M_PUBLIC_KEY = '6d72b57d2bc199d328e7ea3e24775f7f614760bc18f3f8501cd3daa9870cc40c'
|
5
|
+
M_ADDRESS = 'TDJNDAQ7F7AQRXKP2YVTH67QYCWWKE6QLSJFWN64'
|
6
6
|
|
7
7
|
# cosignatory1
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
8
|
+
# A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
9
|
+
# A_PUBLIC_KEY = 'be2ba9cb15a547110d511a4d43c0482fbb584d78781abac01fb053d18f4a0033'
|
10
|
+
# A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
|
11
11
|
|
12
12
|
# cosignatory2
|
13
|
-
|
14
|
-
|
13
|
+
B_PRIVATE_KEY = '1d13af2c31ee6fb0c3c7aaaea818d9b305dcadba130ba663fc42d9f25b24ded1'
|
14
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
15
15
|
|
16
|
-
kp = Nis::Keypair.new(
|
16
|
+
kp = Nis::Keypair.new(B_PRIVATE_KEY)
|
17
17
|
|
18
18
|
nis = Nis.new
|
19
|
-
txes = nis.account_unconfirmed_transactions(address:
|
19
|
+
txes = nis.account_unconfirmed_transactions(address: B_ADDRESS)
|
20
20
|
|
21
21
|
unless txes.size > 0
|
22
22
|
puts 'There are no transactions to sign.'
|
@@ -26,7 +26,7 @@ end
|
|
26
26
|
hash = txes.first.meta.data
|
27
27
|
puts "Unconfirmed Transaction Hash: #{hash}"
|
28
28
|
|
29
|
-
tx = Nis::Transaction::MultisigSignature.new(hash,
|
29
|
+
tx = Nis::Transaction::MultisigSignature.new(hash, M_ADDRESS, B_PUBLIC_KEY)
|
30
30
|
|
31
31
|
req = Nis::Request::PrepareAnnounce.new(tx, kp)
|
32
32
|
res = nis.transaction_prepare_announce(req)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
3
|
# sender
|
4
|
-
A_PRIVATE_KEY = '
|
4
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
5
5
|
|
6
|
-
#
|
7
|
-
B_ADDRESS = '
|
6
|
+
# recipient
|
7
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
8
8
|
|
9
9
|
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
10
10
|
|
11
|
-
tx = Nis::Transaction::Transfer.new(B_ADDRESS,
|
11
|
+
tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
12
12
|
puts "Fee: #{tx.fee.to_i}"
|
13
13
|
|
14
14
|
nis = Nis.new
|
@@ -1,48 +1,52 @@
|
|
1
1
|
require 'nis'
|
2
|
-
require 'pp'
|
3
2
|
|
4
3
|
# sender
|
5
|
-
A_PRIVATE_KEY = '
|
4
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
6
5
|
|
7
|
-
#
|
8
|
-
B_ADDRESS = '
|
6
|
+
# recipient
|
7
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
9
8
|
|
10
9
|
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
11
10
|
|
12
|
-
# fetch mosaic
|
13
|
-
nis = Nis.new
|
14
|
-
mo_dmdps = nis.namespace_mosaic_definition_page(namespace: '
|
11
|
+
# fetch mosaic definition
|
12
|
+
nis = Nis.new
|
13
|
+
mo_dmdps = nis.namespace_mosaic_definition_page(namespace: 'kon')
|
15
14
|
mo_def = mo_dmdps.first.mosaic
|
16
15
|
|
17
|
-
#
|
18
|
-
|
16
|
+
# Or you can use built object if you already know mosaic definition.
|
19
17
|
# mosaic_id = Nis::Struct::MosaicId.new(
|
20
|
-
# namespaceId: '
|
21
|
-
# name: '
|
18
|
+
# namespaceId: 'kon',
|
19
|
+
# name: 'heart'
|
22
20
|
# )
|
23
|
-
|
24
21
|
# properties = Nis::Struct::MosaicProperties.new(
|
25
|
-
# divisibility:
|
26
|
-
# initialSupply:
|
27
|
-
# supplyMutable: true,
|
28
|
-
# transferable: true
|
22
|
+
# divisibility: 3,
|
23
|
+
# initialSupply: 100_000_000
|
29
24
|
# )
|
30
|
-
|
31
25
|
# mo_def = Nis::Struct::MosaicDefinition.new(
|
32
26
|
# id: mosaic_id,
|
33
27
|
# properties: properties,
|
34
28
|
# )
|
35
29
|
|
36
|
-
|
37
|
-
|
30
|
+
# sending 1xem as mosaic sample
|
31
|
+
# mosaic_id = Nis::Struct::MosaicId.new(
|
32
|
+
# namespaceId: 'nem',
|
33
|
+
# name: 'xem'
|
34
|
+
# )
|
35
|
+
# properties = Nis::Struct::MosaicProperties.new(
|
36
|
+
# divisibility: 6,
|
37
|
+
# initialSupply: 8_999_999_999
|
38
|
+
# )
|
39
|
+
# mo_def = Nis::Struct::MosaicDefinition.new(
|
40
|
+
# id: mosaic_id,
|
41
|
+
# properties: properties,
|
42
|
+
# )
|
43
|
+
# mosaic_attachment = Nis::Struct::MosaicAttachment.new(mo_def, 1_000_000)
|
38
44
|
|
39
|
-
|
45
|
+
tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
46
|
+
tx.mosaics << Nis::Struct::MosaicAttachment.new(mo_def, 1)
|
40
47
|
|
41
|
-
nis = Nis.new
|
42
48
|
req = Nis::Request::PrepareAnnounce.new(tx, kp)
|
43
|
-
|
44
|
-
# res = nis.transaction_prepare_announce(req)
|
49
|
+
res = nis.transaction_prepare_announce(req)
|
45
50
|
|
46
|
-
#
|
47
|
-
|
48
|
-
# puts "TransactionHash: #{res.transaction_hash}"
|
51
|
+
puts "Message: #{res.message}"
|
52
|
+
puts "TransactionHash: #{res.transaction_hash}"
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'nis'
|
2
2
|
|
3
3
|
# sender
|
4
|
-
A_PRIVATE_KEY = '
|
4
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
5
5
|
|
6
|
-
#
|
7
|
-
B_ADDRESS = '
|
6
|
+
# recipient
|
7
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
8
8
|
|
9
9
|
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
10
10
|
|
11
|
-
tx = Nis::Transaction::Transfer.new(B_ADDRESS,
|
11
|
+
tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
12
12
|
puts "Fee: #{tx.fee.to_i}"
|
13
13
|
|
14
14
|
nis = Nis.new(host: '104.128.226.60')
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'nis'
|
2
|
+
|
3
|
+
# sender
|
4
|
+
A_PRIVATE_KEY = '260206d683962350532408e8774fd14870a173b7fba17f6b504da3dbc5f1cc9f'
|
5
|
+
|
6
|
+
# receiver
|
7
|
+
B_ADDRESS = 'TAWKJTUP4DWKLDKKS534TYP6G324CBNMXKBA4X7B'
|
8
|
+
|
9
|
+
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
10
|
+
tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
11
|
+
req = Nis::Request::Announce.new(tx, kp)
|
12
|
+
|
13
|
+
puts req.to_hash[:data]
|
14
|
+
puts Nis::Util::Deserializer.deserialize_transaction(req.to_hash[:data])
|
data/lib/nis/request/announce.rb
CHANGED
@@ -16,18 +16,31 @@ class Nis::Request
|
|
16
16
|
|
17
17
|
# @return [Hash] Attribute and value pairs
|
18
18
|
def to_hash
|
19
|
-
|
20
|
-
|
19
|
+
entity = @transaction.clone
|
20
|
+
|
21
|
+
entity.amount *= 1_000_000 if entity.respond_to?(:amount)
|
22
|
+
|
23
|
+
if entity.respond_to?(:other_trans)
|
24
|
+
other_trans(entity)
|
21
25
|
end
|
22
26
|
|
23
|
-
|
27
|
+
entity.tap do |tx|
|
24
28
|
tx.timeStamp = Nis::Util.timestamp
|
25
29
|
tx.deadline = Nis::Util.deadline(DEADLINE)
|
26
30
|
tx.version = Nis::Util.parse_version(tx.network, version(tx))
|
27
31
|
tx.signer = @keypair.public
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
entity_hash = entity.to_hash
|
35
|
+
if entity.respond_to?(:has_mosaics?) && !entity.has_mosaics?
|
36
|
+
entity_hash.delete(:mosaics)
|
37
|
+
end
|
38
|
+
|
39
|
+
if entity.respond_to?(:other_trans) && !entity.other_trans.has_mosaics?
|
40
|
+
entity_hash[:otherTrans].delete(:mosaics)
|
41
|
+
end
|
42
|
+
|
43
|
+
serialized = serialize(entity_hash)
|
31
44
|
hex_serialized = Nis::Util::Convert.ua2hex(serialized)
|
32
45
|
|
33
46
|
{ data: Nis::Util::Convert.ua2hex(serialized),
|
@@ -36,8 +49,8 @@ class Nis::Request
|
|
36
49
|
|
37
50
|
private
|
38
51
|
|
39
|
-
def serialize(
|
40
|
-
Nis::Util::Serializer.serialize_transaction(
|
52
|
+
def serialize(transaction_hash)
|
53
|
+
Nis::Util::Serializer.serialize_transaction(transaction_hash)
|
41
54
|
end
|
42
55
|
|
43
56
|
def signature(serialized)
|
@@ -46,6 +59,8 @@ class Nis::Request
|
|
46
59
|
|
47
60
|
def other_trans(transaction)
|
48
61
|
transaction.other_trans.tap do |tx|
|
62
|
+
tx.amount *= 1_000_000 if tx.respond_to?(:amount)
|
63
|
+
|
49
64
|
tx.timeStamp = Nis::Util.timestamp
|
50
65
|
tx.deadline = Nis::Util.deadline(DEADLINE)
|
51
66
|
tx.version = Nis::Util.parse_version(tx.network, version(tx))
|
@@ -16,18 +16,31 @@ class Nis::Request
|
|
16
16
|
|
17
17
|
# @return [Hash] Attribute and value pairs
|
18
18
|
def to_hash
|
19
|
-
|
20
|
-
|
19
|
+
entity = @transaction.clone
|
20
|
+
|
21
|
+
entity.amount *= 1_000_000 if entity.respond_to?(:amount)
|
22
|
+
|
23
|
+
if entity.respond_to?(:other_trans)
|
24
|
+
other_trans(entity)
|
21
25
|
end
|
22
26
|
|
23
|
-
|
27
|
+
entity.tap do |tx|
|
24
28
|
tx.timeStamp = Nis::Util.timestamp
|
25
29
|
tx.deadline = Nis::Util.deadline(DEADLINE)
|
26
30
|
tx.version = Nis::Util.parse_version(tx.network, version(tx))
|
27
31
|
tx.signer = @keypair.public
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
entity_hash = entity.to_hash
|
35
|
+
if entity.respond_to?(:has_mosaics?) && !entity.has_mosaics?
|
36
|
+
entity_hash.delete(:mosaics)
|
37
|
+
end
|
38
|
+
|
39
|
+
if entity.respond_to?(:other_trans) && !entity.other_trans.has_mosaics?
|
40
|
+
entity_hash[:otherTrans].delete(:mosaics)
|
41
|
+
end
|
42
|
+
|
43
|
+
{ transaction: entity_hash,
|
31
44
|
privateKey: @keypair.private }
|
32
45
|
end
|
33
46
|
|
@@ -35,6 +48,8 @@ class Nis::Request
|
|
35
48
|
|
36
49
|
def other_trans(transaction)
|
37
50
|
transaction.other_trans.tap do |tx|
|
51
|
+
tx.amount *= 1_000_000 if tx.respond_to?(:amount)
|
52
|
+
|
38
53
|
tx.timeStamp = Nis::Util.timestamp
|
39
54
|
tx.deadline = Nis::Util.deadline(DEADLINE)
|
40
55
|
tx.version = Nis::Util.parse_version(tx.network, version(tx))
|
@@ -5,18 +5,31 @@ 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])
|
9
|
+
method = case type
|
10
|
+
when 0x0101 then method(:deserialize_transfer)
|
11
|
+
when 0x0801 then method(:deserialize_importance_transfer)
|
12
|
+
when 0x1001 then method(:deserialize_multisig_aggregate_modification)
|
13
|
+
when 0x1002 then method(:deserialize_multisig_signature)
|
14
|
+
when 0x1004 then method(:deserialize_multisig)
|
15
|
+
when 0x2001 then method(:deserialize_provision_namespace)
|
16
|
+
when 0x4001 then method(:deserialize_mosaic_definition_creation)
|
17
|
+
when 0x4002 then method(:deserialize_mosaic_supply_change)
|
18
|
+
else raise "Not implemented entity type: #{type}"
|
19
|
+
end
|
20
|
+
method.call(serialized)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Deserialize a transfer transaction object
|
24
|
+
# @param [String] serialized
|
25
|
+
# @return [Hash]
|
26
|
+
def self.deserialize_transfer(serialized)
|
27
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
28
|
+
common = deserialize_common(s)
|
8
29
|
tx = {}
|
9
|
-
tx[:type] = deserialize_int(s[0, 4])
|
10
|
-
tx[:version] = deserialize_int(s[4, 4])
|
11
|
-
tx[:timeStamp] = deserialize_int(s[8, 4])
|
12
|
-
# s[12,4] # length of public key
|
13
|
-
tx[:signer] = deserialize_hex(s[16, 32])
|
14
|
-
tx[:fee] = deserialize_int(s[48, 8])
|
15
|
-
tx[:deadline] = deserialize_int(s[56, 4])
|
16
30
|
# s[60,4] # length of address
|
17
31
|
tx[:recipient] = deserialize_a(s[64, 40])
|
18
32
|
tx[:amount] = deserialize_int(s[104, 8])
|
19
|
-
|
20
33
|
tx[:message] = {}
|
21
34
|
message_len = deserialize_int(s[112, 4])
|
22
35
|
if message_len > 0
|
@@ -26,11 +39,123 @@ module Nis::Util
|
|
26
39
|
else
|
27
40
|
tx[:message] = { type: 1, payload: '' }
|
28
41
|
end
|
29
|
-
tx
|
42
|
+
common.merge(tx)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Deserialize a importance transaction object
|
46
|
+
# @param [String] serialized
|
47
|
+
# @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)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Deserialize a multisig aggregate modification transaction object
|
59
|
+
# @param [String] serialized
|
60
|
+
# @return [Hash]
|
61
|
+
def self.deserialize_multisig_aggregate_modification(serialized)
|
62
|
+
raise 'Not yet implimented.'
|
63
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
64
|
+
common = deserialize_common(s)
|
65
|
+
tx = {}
|
66
|
+
# TODO: deserializing
|
67
|
+
common.merge(tx)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Deserialize a multisig signature transaction object
|
71
|
+
# @param [String] serialized
|
72
|
+
# @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)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Deserialize a multisig transfer transaction object
|
83
|
+
# @param [String] serialized
|
84
|
+
# @return [Hash]
|
85
|
+
def self.deserialize_multisig(serialized)
|
86
|
+
raise 'Not yet implimented.'
|
87
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
88
|
+
common = deserialize_common(s)
|
89
|
+
tx = {}
|
90
|
+
# TODO: deserializing
|
91
|
+
common.merge(tx)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Deserialize a provision namespace transaction object
|
95
|
+
# @param [String] serialized
|
96
|
+
# @return [Hash]
|
97
|
+
def self.deserialize_provision_namespace(serialized)
|
98
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
99
|
+
common = deserialize_common(s)
|
100
|
+
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]
|
108
|
+
unless parent.all? { |val| val == 0xff }
|
109
|
+
tx[:parent] = deserialize_a(parent) # Parent string: UTF8 encoded string
|
110
|
+
end
|
111
|
+
common.merge(tx)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Deserialize a mosaic definition creation transaction object
|
115
|
+
# @param [String] serialized
|
116
|
+
# @return [Hash]
|
117
|
+
def self.deserialize_mosaic_definition_creation(serialized)
|
118
|
+
raise 'Not yet implimented.'
|
119
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
120
|
+
common = deserialize_common(s)
|
121
|
+
tx = {}
|
122
|
+
# TODO: deserializing
|
123
|
+
common.merge(tx)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Deserialize a mosaic supply change transaction object
|
127
|
+
# @param [String] serialized
|
128
|
+
# @return [Hash]
|
129
|
+
def self.deserialize_mosaic_supply_change(serialized)
|
130
|
+
s = Nis::Util::Convert.hex2ua(serialized)
|
131
|
+
common = deserialize_common(s)
|
132
|
+
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
|
136
|
+
tx[:mosaicId] = {
|
137
|
+
namespaceId: deserialize_a(s[68, ns_len]),
|
138
|
+
name: deserialize_a(s[68 + ns_len + mo_len, mo_len])
|
139
|
+
}
|
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)
|
30
143
|
end
|
31
144
|
|
32
145
|
private
|
33
146
|
|
147
|
+
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
|
157
|
+
end
|
158
|
+
|
34
159
|
def self.deserialize_int(ua)
|
35
160
|
Nis::Util::Convert.ua2hex(ua.reverse).to_i(16)
|
36
161
|
end
|
data/lib/nis/util/serializer.rb
CHANGED
@@ -5,67 +5,163 @@ module Nis::Util
|
|
5
5
|
# @return [Array]
|
6
6
|
def self.serialize_transaction(entity)
|
7
7
|
method = case entity[:type]
|
8
|
-
when
|
9
|
-
when
|
8
|
+
when 0x0101 then method(:serialize_transfer)
|
9
|
+
when 0x0801 then method(:serialize_importance_transfer)
|
10
|
+
when 0x1001 then method(:serialize_multisig_aggregate_modification)
|
11
|
+
when 0x1002 then method(:serialize_multisig_signature)
|
12
|
+
when 0x1004 then method(:serialize_multisig)
|
13
|
+
when 0x2001 then method(:serialize_provision_namespace)
|
14
|
+
when 0x4001 then method(:serialize_mosaic_definition_creation)
|
15
|
+
when 0x4002 then method(:serialize_mosaic_supply_change)
|
10
16
|
else raise "Not implemented entity type: #{entity[:type]}"
|
11
17
|
end
|
12
18
|
method.call(entity)
|
13
19
|
end
|
14
20
|
|
15
|
-
def self.
|
21
|
+
def self.serialize_transfer(entity)
|
16
22
|
a = []
|
17
|
-
|
18
|
-
a +=
|
19
|
-
|
23
|
+
# Common transaction part
|
24
|
+
a += serialize_common(entity)
|
25
|
+
# Transfer transaction part
|
26
|
+
a += serialize_safe_string(entity[:recipient])
|
27
|
+
a += serialize_long(entity[:amount])
|
28
|
+
temp = hex2ua(entity[:message][:payload])
|
29
|
+
if temp.size == 0
|
30
|
+
a += [0, 0, 0, 0]
|
31
|
+
else
|
32
|
+
a += serialize_int(temp.size + 8)
|
33
|
+
a += serialize_int(entity[:message][:type])
|
34
|
+
a += serialize_int(temp.size)
|
35
|
+
a += temp
|
36
|
+
end
|
37
|
+
a
|
38
|
+
end
|
20
39
|
|
21
|
-
|
40
|
+
def self.serialize_importance_transfer(entity)
|
41
|
+
a = []
|
42
|
+
a += serialize_common(entity)
|
43
|
+
a += serialize_int(entity[:mode])
|
44
|
+
temp = hex2ua(entity[:remoteAccount])
|
22
45
|
a += serialize_int(temp.size)
|
23
46
|
a += temp
|
24
|
-
|
25
|
-
a += serialize_long(entity[:fee].to_i)
|
26
|
-
a += serialize_int(entity[:deadline])
|
27
47
|
a
|
28
48
|
end
|
29
49
|
|
30
|
-
def self.
|
50
|
+
def self.serialize_multisig_aggregate_modification(entity)
|
31
51
|
a = []
|
52
|
+
a += serialize_common(entity)
|
53
|
+
a += serialize_int(entity[:modifications].size)
|
54
|
+
a += entity[:modifications].map do |mod|
|
55
|
+
b = []
|
56
|
+
b += serialize_int(40)
|
57
|
+
b += serialize_int(mod[:modificationType])
|
58
|
+
b += serialize_int(32)
|
59
|
+
b += hex2ua(mod[:cosignatoryAccount])
|
60
|
+
b
|
61
|
+
end.flatten
|
32
62
|
|
33
|
-
#
|
63
|
+
# The following part describes the minimum cosignatories modification.
|
64
|
+
# The part is optional. Version 1 aggregate modification transactions should omit this part.
|
65
|
+
# Version 2 aggregate modification transactions with no minimum cosignatories modification
|
66
|
+
# should only write the length field with value 0x00, 0x00, 0x00, 0x00.
|
67
|
+
if true # only version2
|
68
|
+
if entity[:minCosignatories][:relativeChange] > 0
|
69
|
+
a += serialize_int(4)
|
70
|
+
a += serialize_int(entity[:minCosignatories][:relativeChange])
|
71
|
+
else
|
72
|
+
a += [0, 0, 0, 0]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
a
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.serialize_multisig_signature(entity)
|
79
|
+
a = []
|
34
80
|
a += serialize_common(entity)
|
81
|
+
temp = hex2ua(entity[:otherHash][:data])
|
82
|
+
a += serialize_int(4 + temp.size)
|
83
|
+
a += serialize_int(temp.size)
|
84
|
+
a += temp
|
85
|
+
a += serialize_safe_string(entity[:otherAccount])
|
86
|
+
end
|
35
87
|
|
36
|
-
|
37
|
-
|
88
|
+
def self.serialize_multisig(entity)
|
89
|
+
a = []
|
90
|
+
a += serialize_common(entity)
|
91
|
+
other_tx = entity[:otherTrans]
|
92
|
+
tx = case other_tx[:type]
|
93
|
+
when 0x0101 then serialize_transfer(other_tx)
|
94
|
+
when 0x0801 then serialize_importance_transfer(other_tx)
|
95
|
+
when 0x1001 then serialize_multisig_aggregate_modification(other_tx)
|
96
|
+
else raise "Unexpected type #{other_tx[:type]}"
|
97
|
+
end
|
38
98
|
a += serialize_int(tx.size)
|
39
99
|
a += tx
|
40
100
|
a
|
41
101
|
end
|
42
102
|
|
43
|
-
def self.
|
103
|
+
def self.serialize_provision_namespace(entity)
|
44
104
|
a = []
|
45
|
-
|
46
|
-
# Common transaction part
|
47
105
|
a += serialize_common(entity)
|
48
|
-
|
49
|
-
|
50
|
-
temp =
|
106
|
+
a += serialize_safe_string(entity[:rentalFeeSink])
|
107
|
+
a += serialize_long(entity[:rentalFee])
|
108
|
+
temp = hex2ua(utf8_to_hex(entity[:newPart]))
|
109
|
+
a += serialize_int(temp.size)
|
51
110
|
a += temp
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
temp = hex2ua(entity[:message][:payload])
|
56
|
-
if temp.size == 0
|
57
|
-
a += [0, 0, 0, 0]
|
58
|
-
else
|
59
|
-
a += serialize_int(temp.size + 8)
|
60
|
-
a += serialize_int(entity[:message][:type])
|
111
|
+
if entity[:parent]
|
112
|
+
temp = hex2ua(utf8_to_hex(entity[:parent]))
|
61
113
|
a += serialize_int(temp.size)
|
62
114
|
a += temp
|
115
|
+
else
|
116
|
+
a += [255, 255, 255, 255]
|
63
117
|
end
|
64
118
|
a
|
65
119
|
end
|
66
120
|
|
121
|
+
def self.serialize_mosaic_definition_creation(entity)
|
122
|
+
a = []
|
123
|
+
a += serialize_common(entity)
|
124
|
+
a += serialize_mosaic_definition(entity[:mosaicDefinition])
|
125
|
+
a += serialize_safe_string(entity[:creationFeeSink])
|
126
|
+
a += serialize_long(entity[:creationFee])
|
127
|
+
a
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.serialize_mosaic_supply_change(entity)
|
131
|
+
a = []
|
132
|
+
a += serialize_common(entity)
|
133
|
+
mo_id = entity[:mosaicId]
|
134
|
+
a_ns = hex2ua(utf8_to_hex(mo_id[:namespaceId]))
|
135
|
+
a_ns_len = serialize_int(a_ns.size)
|
136
|
+
a_mo = hex2ua(utf8_to_hex(mo_id[:name]))
|
137
|
+
a_mo_len = serialize_int(a_mo.size)
|
138
|
+
a += serialize_int((a_ns_len + a_ns + a_mo_len + a_mo).size)
|
139
|
+
a += a_ns_len
|
140
|
+
a += a_ns
|
141
|
+
a += a_mo_len
|
142
|
+
a += a_mo
|
143
|
+
a += serialize_int(entity[:supplyType])
|
144
|
+
a += serialize_long(entity[:delta])
|
145
|
+
a
|
146
|
+
end
|
147
|
+
|
67
148
|
private
|
68
149
|
|
150
|
+
def self.serialize_common(entity)
|
151
|
+
a = []
|
152
|
+
a += serialize_int(entity[:type])
|
153
|
+
a += serialize_int(entity[:version])
|
154
|
+
a += serialize_int(entity[:timeStamp])
|
155
|
+
|
156
|
+
temp = hex2ua(entity[:signer])
|
157
|
+
a += serialize_int(temp.size)
|
158
|
+
a += temp
|
159
|
+
|
160
|
+
a += serialize_long(entity[:fee].to_i)
|
161
|
+
a += serialize_int(entity[:deadline])
|
162
|
+
a
|
163
|
+
end
|
164
|
+
|
69
165
|
# Safe String - Each char is 8 bit
|
70
166
|
# @param [String] str
|
71
167
|
# @return [Array]
|
@@ -106,16 +202,6 @@ module Nis::Util
|
|
106
202
|
a
|
107
203
|
end
|
108
204
|
|
109
|
-
# @param [Nis::Struct::MosaicId] mosaic_id
|
110
|
-
# @return [Array]
|
111
|
-
def self.serialize_mosaic_id(mosaic_id)
|
112
|
-
serialized_namespace_id = serialize_safe_string(mosaic_id.namespace_id)
|
113
|
-
serialized_name = serialize_safe_string(mosaic_id.name)
|
114
|
-
[serialized_namespace_id.size + serialized_name.size, 0, 0, 0] +
|
115
|
-
serialized_namespace_id +
|
116
|
-
serialized_name
|
117
|
-
end
|
118
|
-
|
119
205
|
# @param [Nis::Struct::Mosaic] mosaic
|
120
206
|
# @return [Array]
|
121
207
|
def self.serialize_mosaic_and_quantity(mosaic)
|
@@ -145,74 +231,63 @@ module Nis::Util
|
|
145
231
|
end.flatten
|
146
232
|
end
|
147
233
|
|
234
|
+
# @param [Hash] entity
|
235
|
+
# @return [Array]
|
236
|
+
def self.serialize_mosaic_id(entity)
|
237
|
+
a = []
|
238
|
+
a += serialize_safe_string(entity[:namespaceId])
|
239
|
+
a += serialize_safe_string(entity[:name])
|
240
|
+
serialize_int(a.size) + a
|
241
|
+
end
|
242
|
+
|
148
243
|
# @param [Hash] entity
|
149
244
|
# @return [Array]
|
150
245
|
def self.serialize_property(entity)
|
151
|
-
a = []
|
152
|
-
|
153
|
-
|
154
|
-
a
|
155
|
-
a + serialized_name + serialized_value
|
246
|
+
a = []
|
247
|
+
a += serialize_safe_string(entity[:name])
|
248
|
+
a += serialize_safe_string(entity[:value])
|
249
|
+
serialize_int(a.size) + a
|
156
250
|
end
|
157
251
|
|
158
252
|
# @param [Array] entities
|
159
253
|
# @return [Array]
|
160
254
|
def self.serialize_properties(entities)
|
161
|
-
|
162
|
-
a[0] = entities.size
|
163
|
-
|
164
|
-
helper = {
|
255
|
+
order = {
|
165
256
|
'divisibility' => 1,
|
166
257
|
'initialSupply' => 2,
|
167
258
|
'supplyMutable' => 3,
|
168
259
|
'transferable' => 4
|
169
260
|
}
|
170
|
-
a
|
261
|
+
a = []
|
262
|
+
a = entities.sort_by { |ent| order[ent[:name]] }
|
171
263
|
.map { |ent| serialize_property(ent) }.flatten
|
264
|
+
serialize_int(entities.size) + a
|
172
265
|
end
|
173
266
|
|
174
267
|
# @param [Hash] entity
|
175
268
|
# @return [Array]
|
176
269
|
def self.serialize_levy(entity)
|
177
|
-
return [
|
178
|
-
a = []
|
179
|
-
a
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
a
|
184
|
-
a[0] = 4 + temp.size + serialized_mosaic_id.size + 8;
|
185
|
-
a
|
270
|
+
return [0, 0, 0, 0] if entity.nil?
|
271
|
+
a = []
|
272
|
+
a += serialize_int(entity[:type])
|
273
|
+
a += serialize_safe_string(entity[:recipient])
|
274
|
+
a += serialize_mosaic_id(entity[:mosaicId])
|
275
|
+
a += serialize_long(entity[:fee])
|
276
|
+
serialize_int(a.size) + a
|
186
277
|
end
|
187
278
|
|
188
279
|
# @param [Hash] entity
|
189
280
|
# @return [Array]
|
190
281
|
def self.serialize_mosaic_definition(entity)
|
191
|
-
a = []
|
282
|
+
a = []
|
192
283
|
temp = hex2ua(entity[:creator])
|
193
|
-
a
|
284
|
+
a += serialize_int(temp.size)
|
194
285
|
a += temp
|
195
286
|
a += serialize_mosaic_id(entity[:id])
|
196
|
-
|
197
|
-
a +=
|
198
|
-
a +=
|
199
|
-
a
|
200
|
-
a
|
201
|
-
end
|
202
|
-
|
203
|
-
# @param [String] hex
|
204
|
-
# @return [Array]
|
205
|
-
# def self.hex2ua(hex)
|
206
|
-
# hex.scan(/../).map(&:hex)
|
207
|
-
# end
|
208
|
-
#
|
209
|
-
def self.bin2words(bin, bin_size)
|
210
|
-
# temp = [];
|
211
|
-
# for (let i = 0; i < ua_size; i += 4) {
|
212
|
-
# let x = ua[i] * 0x1000000 + (ua[i + 1] || 0) * 0x10000 + (ua[i + 2] || 0) * 0x100 + (ua[i + 3] || 0);
|
213
|
-
# temp.push((x > 0x7fffffff) ? x - 0x100000000 : x);
|
214
|
-
# }
|
215
|
-
# CryptoJS.lib.WordArray.create(temp, ua_size);
|
287
|
+
a += serialize_bin_string(hex2ua(utf8_to_hex(entity[:description])))
|
288
|
+
a += serialize_properties(entity[:properties])
|
289
|
+
a += serialize_levy(entity[:levy])
|
290
|
+
serialize_int(a.size) + a
|
216
291
|
end
|
217
292
|
|
218
293
|
# @param [String] hex
|
@@ -253,21 +328,5 @@ module Nis::Util
|
|
253
328
|
end
|
254
329
|
end.flatten.map(&:chr).join
|
255
330
|
end
|
256
|
-
|
257
|
-
def encode(sender_privkey, recipient_pubkey, message)
|
258
|
-
# sk = hex2ua(sender_privkey)
|
259
|
-
# pk = hex2ua(recipient_pubkey)
|
260
|
-
# let shared = new Uint8Array(32);
|
261
|
-
# let r = key_derive(shared, salt, sk, pk);
|
262
|
-
# let encKey = r;
|
263
|
-
# let encIv = {
|
264
|
-
# iv: convert.bin2words(iv, 16)
|
265
|
-
# };
|
266
|
-
# let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Hex.parse(convert.utf8ToHex(msg)), encKey, encIv);
|
267
|
-
#
|
268
|
-
salt = RbNaCl::Random.random_bytes(32)
|
269
|
-
iv = RbNaCl::Random.random_bytes(16)
|
270
|
-
bin2hex(salt) + bin2hex(iv) # + CryptoJS.enc.Hex.stringify(encrypted.ciphertext)
|
271
|
-
end
|
272
331
|
end
|
273
332
|
end
|
data/lib/nis/version.rb
CHANGED
data/nis.gemspec
CHANGED
@@ -25,6 +25,14 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
+
spec.post_install_message = %q{
|
29
|
+
<nis-ruby>
|
30
|
+
Please see https://gitter.im/44uk/nis-ruby for the latest information.
|
31
|
+
The gem is under development. Incompatible changes can be made.
|
32
|
+
Feel free to ask and give feedback to https://twitter.com/44uk_i3
|
33
|
+
Good luck! NEM application development!
|
34
|
+
}
|
35
|
+
|
28
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
38
|
spec.add_development_dependency 'yard', '~> 0.9'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nis-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
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-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- examples/transactions/transfer.rb
|
216
216
|
- examples/transactions/transfer_mosaic.rb
|
217
217
|
- examples/transactions/transfer_remote.rb
|
218
|
+
- examples/util/deserialize.rb
|
218
219
|
- lib/nis.rb
|
219
220
|
- lib/nis/client.rb
|
220
221
|
- lib/nis/endpoint.rb
|
@@ -352,7 +353,10 @@ licenses:
|
|
352
353
|
- MIT
|
353
354
|
metadata:
|
354
355
|
yard.run: yri
|
355
|
-
post_install_message:
|
356
|
+
post_install_message: "\n <nis-ruby>\n Please see https://gitter.im/44uk/nis-ruby
|
357
|
+
for the latest information.\n The gem is under development. Incompatible changes
|
358
|
+
can be made.\n Feel free to ask and give feedback to https://twitter.com/44uk_i3\n
|
359
|
+
\ Good luck! NEM application development!\n "
|
356
360
|
rdoc_options: []
|
357
361
|
require_paths:
|
358
362
|
- lib
|