nis-ruby 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/account/mosaic.rb +1 -1
- data/examples/account/namespace.rb +1 -1
- data/examples/apostille_audit.rb +15 -0
- data/examples/apostille_create.rb +29 -0
- data/lib/nis.rb +2 -0
- data/lib/nis/apostille.rb +104 -0
- data/lib/nis/apostille_audit.rb +47 -0
- data/lib/nis/endpoint/account/transfers.rb +2 -2
- data/lib/nis/endpoint/debug/connections.rb +2 -2
- data/lib/nis/endpoint/local/account/transfers.rb +2 -2
- data/lib/nis/endpoint/node/peer_list.rb +2 -2
- data/lib/nis/struct/message.rb +1 -1
- data/lib/nis/struct/transaction_meta_data_pair.rb +8 -8
- data/lib/nis/util.rb +0 -5
- data/lib/nis/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02eded5cc96f4b7d764250ccb50ed847e86568ac
|
4
|
+
data.tar.gz: 8bba76f25a95ad6b7dd5ca5d72c4e2e325dae94a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c00ff152a4d0ebddb4d74045545afd2be1ee0d52f4d5304695214a4923d204a2c815059c3164d3c6f8de2ec428e04790d733aa6fcc4b76cecfc41860ab86eeee
|
7
|
+
data.tar.gz: ddf8898fa66aef0c3e6f17a870164a6ec4dbf4541a7dd0db4db19844109138b1362ff75071e8f7365bfdcd92018711d4c0d0586ce5f05e6b00246b5422275871
|
data/examples/account/mosaic.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
nis = Nis.new(host: '23.228.67.85')
|
5
|
+
|
6
|
+
FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
|
7
|
+
|
8
|
+
tx_hash = '3d7d8a88768ea35f35a4607252ea7bb71fd0951b92a12dfab41c98333b029c9f'
|
9
|
+
|
10
|
+
tx = nis.transaction_get(hash: tx_hash)
|
11
|
+
apostille_hash = tx.transaction.message[:payload] # 'fe4e545902cde315617a435ebfd5fe8875d699e2f2363262f5'
|
12
|
+
file = File.open("#{FIXTURES_PATH}/nemLogoV2 -- Apostille TX 3d7d8a88768ea35f35a4607252ea7bb71fd0951b92a12dfab41c98333b029c9f -- Date 2017-10-04.png")
|
13
|
+
|
14
|
+
apa = Nis::ApostilleAudit.new(file, apostille_hash)
|
15
|
+
p apa.valid?
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nis'
|
2
|
+
Nis.logger.level = Logger::DEBUG
|
3
|
+
|
4
|
+
nis = Nis.new(host: '23.228.67.85')
|
5
|
+
|
6
|
+
FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
|
7
|
+
|
8
|
+
# sender
|
9
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
10
|
+
|
11
|
+
kp = Nis::Keypair.new(A_PRIVATE_KEY)
|
12
|
+
|
13
|
+
file = File.open("#{FIXTURES_PATH}/nemLogoV2.png")
|
14
|
+
ap = Nis::Apostille.new(kp, file, :sha1,
|
15
|
+
multisig: false,
|
16
|
+
private: false,
|
17
|
+
network: :testnet
|
18
|
+
)
|
19
|
+
tx = ap.transaction
|
20
|
+
p "Fee: #{tx.fee.to_i}"
|
21
|
+
|
22
|
+
req = Nis::Request::Announce.new(tx, kp)
|
23
|
+
res = nis.transaction_announce(req)
|
24
|
+
|
25
|
+
p "Message: #{res.message}"
|
26
|
+
p "TransactionHash: #{res.transaction_hash}"
|
27
|
+
p "ApostilleFormat: #{ap.apostille_format(res.transaction_hash)}"
|
28
|
+
|
29
|
+
FileUtils.cp(file.path, ap.apostille_format(res.transaction_hash))
|
data/lib/nis.rb
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'digest/sha2'
|
4
|
+
require 'digest/sha3'
|
5
|
+
|
6
|
+
class Nis::Apostille
|
7
|
+
CHECKSUM = 'fe4e5459'.freeze
|
8
|
+
|
9
|
+
# @param [Nis::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: :testnet)
|
15
|
+
@keypair = keypair
|
16
|
+
@file = file
|
17
|
+
@hashing = hashing
|
18
|
+
@multisig = multisig
|
19
|
+
@private = private
|
20
|
+
@network = network
|
21
|
+
end
|
22
|
+
|
23
|
+
def private?
|
24
|
+
@private
|
25
|
+
end
|
26
|
+
|
27
|
+
def multisig?
|
28
|
+
@multisig
|
29
|
+
end
|
30
|
+
|
31
|
+
def transaction
|
32
|
+
if private?
|
33
|
+
raise 'Not implemented private apostille.'
|
34
|
+
else
|
35
|
+
dedicated_address = apostille[:sink]
|
36
|
+
apostille_hash = calc_hash
|
37
|
+
end
|
38
|
+
|
39
|
+
Nis::Transaction::Transfer.new(dedicated_address, 0, apostille_hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
def apostille_format(transaction_hash)
|
43
|
+
ext = File.extname(@file.path)
|
44
|
+
name = File.basename(@file.path, ext)
|
45
|
+
date = Date.today.strftime('%Y-%m-%d')
|
46
|
+
'%s -- Apostille TX %s -- Date %s%s' % [
|
47
|
+
name,
|
48
|
+
transaction_hash,
|
49
|
+
date,
|
50
|
+
ext
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def calc_hash
|
57
|
+
checksum = "#{CHECKSUM}#{hex_type}"
|
58
|
+
hashed = case @hashing
|
59
|
+
when /\Amd5\z/ then Digest::MD5.file(@file)
|
60
|
+
when /\Asha1\z/ then Digest::SHA1.file(@file)
|
61
|
+
when /\Asha256\z/ then Digest::SHA256.file(@file)
|
62
|
+
when /\Asha3-256\z/ then Digest::SHA3.file(@file, 256)
|
63
|
+
else Digest::SHA3.file(@file, 512)
|
64
|
+
end
|
65
|
+
checksum << hashed.hexdigest
|
66
|
+
end
|
67
|
+
|
68
|
+
def algo
|
69
|
+
case @hashing
|
70
|
+
when /\Amd5\z/ then 0x01
|
71
|
+
when /\Asha1\z/ then 0x02
|
72
|
+
when /\Asha256\z/ then 0x03
|
73
|
+
when /\Asha3-256\z/ then 0x08
|
74
|
+
when /\Asha3-512\z/ then 0x09
|
75
|
+
else raise "Undefined hashing: #{@hashing}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def version
|
80
|
+
private? ? 0x80 : 0x00
|
81
|
+
end
|
82
|
+
|
83
|
+
def hex_type
|
84
|
+
'%02x' % (algo | version)
|
85
|
+
end
|
86
|
+
|
87
|
+
def apostille
|
88
|
+
if @network == :testnet
|
89
|
+
if private?
|
90
|
+
raise 'Not implemented private apostille.'
|
91
|
+
else
|
92
|
+
{ private_key: nil,
|
93
|
+
sink: 'TC7MCY5AGJQXZQ4BN3BOPNXUVIGDJCOHBPGUM2GE' }
|
94
|
+
end
|
95
|
+
else
|
96
|
+
if private?
|
97
|
+
raise 'Not implemented private apostille.'
|
98
|
+
else
|
99
|
+
{ private_key: nil,
|
100
|
+
sink: 'NCZSJHLTIMESERVBVKOW6US64YDZG2PFGQCSV23J' }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'digest/sha2'
|
4
|
+
require 'digest/sha3'
|
5
|
+
|
6
|
+
class Nis::ApostilleAudit
|
7
|
+
CHECKSUM = 'fe4e5459'.freeze
|
8
|
+
|
9
|
+
# @param [File] file
|
10
|
+
# @param [apostille_hash] Apostille formatted hash
|
11
|
+
def initialize(file, apostille_hash)
|
12
|
+
@file = file
|
13
|
+
@apostille_hash = apostille_hash
|
14
|
+
@checksum, @version, @algo, @hash = split_apostille_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
raise 'Not implemented private apostille' if private?
|
19
|
+
raise "Invalid checksum: #{@checksum}" unless @checksum == CHECKSUM
|
20
|
+
@hash == calc_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def private?
|
24
|
+
@version == 0x80
|
25
|
+
end
|
26
|
+
|
27
|
+
def split_apostille_hash
|
28
|
+
[ @apostille_hash[0, 8],
|
29
|
+
@apostille_hash[8, 1].to_i,
|
30
|
+
@apostille_hash[9, 1].to_i,
|
31
|
+
@apostille_hash[10, @apostille_hash.size] ]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def calc_hash
|
37
|
+
hashed = case @algo
|
38
|
+
when 0x01 then Digest::MD5.file(@file)
|
39
|
+
when 0x02 then Digest::SHA1.file(@file)
|
40
|
+
when 0x03 then Digest::SHA256.file(@file)
|
41
|
+
when 0x08 then Digest::SHA3.file(@file, 256)
|
42
|
+
when 0x09 then Digest::SHA3.file(@file, 512)
|
43
|
+
else raise "Undefined alog #{@algo}"
|
44
|
+
end
|
45
|
+
hashed.hexdigest
|
46
|
+
end
|
47
|
+
end
|
data/lib/nis/struct/message.rb
CHANGED
@@ -16,14 +16,14 @@ class Nis::Struct
|
|
16
16
|
def self.build_transaction_struct(data)
|
17
17
|
type = data[:type]
|
18
18
|
klass = case type
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
when 0x0101 then Nis::Struct::TransferTransaction
|
20
|
+
when 0x0801 then Nis::Struct::ImportanceTransferTransaction
|
21
|
+
when 0x1001 then Nis::Struct::MultisigAggregationModificationTransaction
|
22
|
+
when 0x1002 then Nis::Struct::MultisigSignatureTransaction
|
23
|
+
when 0x1004 then Nis::Struct::MultisigTransaction
|
24
|
+
when 0x2001 then Nis::Struct::ProvisionNamespaceTransaction
|
25
|
+
when 0x4001 then Nis::Struct::MosaicDefinitionCreationTransaction
|
26
|
+
when 0x4002 then Nis::Struct::MosaicSupplyChangeTransaction
|
27
27
|
else raise "Not implemented entity type: #{type}"
|
28
28
|
end
|
29
29
|
klass.build(data)
|
data/lib/nis/util.rb
CHANGED
@@ -13,11 +13,6 @@ module Nis::Util
|
|
13
13
|
|
14
14
|
NEM_EPOCH = Time.utc(2015, 3, 29, 0, 6, 25, 0)
|
15
15
|
|
16
|
-
APOSTILLE_SINK = {
|
17
|
-
testnet: 'TC7MCY5AGJQXZQ4BN3BOPNXUVIGDJCOHBPGUM2GE',
|
18
|
-
mainnet: 'NCZSJHLTIMESERVBVKOW6US64YDZG2PFGQCSV23J'
|
19
|
-
}
|
20
|
-
|
21
16
|
def self.parse_version(network, version)
|
22
17
|
parse_network(network) | version
|
23
18
|
end
|
data/lib/nis/version.rb
CHANGED
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.18
|
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-10-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -193,6 +193,8 @@ files:
|
|
193
193
|
- examples/account/unconfirmed_transactions.rb
|
194
194
|
- examples/account/unlock.rb
|
195
195
|
- examples/account/unlocked.rb
|
196
|
+
- examples/apostille_audit.rb
|
197
|
+
- examples/apostille_create.rb
|
196
198
|
- examples/block/at_public.rb
|
197
199
|
- examples/block/get.rb
|
198
200
|
- examples/debug/connections.rb
|
@@ -221,6 +223,8 @@ files:
|
|
221
223
|
- examples/transactions/transfer_remote.rb
|
222
224
|
- examples/util/deserialize.rb
|
223
225
|
- lib/nis.rb
|
226
|
+
- lib/nis/apostille.rb
|
227
|
+
- lib/nis/apostille_audit.rb
|
224
228
|
- lib/nis/client.rb
|
225
229
|
- lib/nis/configuration.rb
|
226
230
|
- lib/nis/endpoint.rb
|