tapyrus 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/{.prettierrc.yaml → .prettierrc.yml} +0 -1
- data/.ruby-version +1 -1
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/exe/tapyrus-script-debugger +5 -5
- data/exe/tapyrusrb-cli +1 -1
- data/exe/tapyrusrbd +18 -17
- data/lib/openassets/payload.rb +2 -2
- data/lib/openassets/util.rb +2 -2
- data/lib/openassets.rb +4 -4
- data/lib/schnorr/sign_to_contract.rb +4 -4
- data/lib/schnorr/signature.rb +5 -5
- data/lib/schnorr.rb +14 -14
- data/lib/tapyrus/base58.rb +8 -8
- data/lib/tapyrus/bip175.rb +5 -5
- data/lib/tapyrus/block_header.rb +2 -2
- data/lib/tapyrus/bloom_filter.rb +1 -1
- data/lib/tapyrus/chain_params.rb +5 -5
- data/lib/tapyrus/constants.rb +1 -1
- data/lib/tapyrus/errors.rb +9 -9
- data/lib/tapyrus/ext/ecdsa.rb +4 -4
- data/lib/tapyrus/ext/json_parser.rb +1 -1
- data/lib/tapyrus/ext.rb +3 -3
- data/lib/tapyrus/ext_key.rb +21 -21
- data/lib/tapyrus/jws.rb +76 -0
- data/lib/tapyrus/key.rb +48 -20
- data/lib/tapyrus/key_path.rb +3 -3
- data/lib/tapyrus/logger.rb +4 -11
- data/lib/tapyrus/merkle_tree.rb +1 -1
- data/lib/tapyrus/message/addr.rb +2 -2
- data/lib/tapyrus/message/base.rb +2 -2
- data/lib/tapyrus/message/block.rb +1 -1
- data/lib/tapyrus/message/block_txn.rb +1 -1
- data/lib/tapyrus/message/cmpct_block.rb +1 -1
- data/lib/tapyrus/message/fee_filter.rb +3 -3
- data/lib/tapyrus/message/filter_add.rb +1 -1
- data/lib/tapyrus/message/filter_clear.rb +2 -2
- data/lib/tapyrus/message/filter_load.rb +7 -7
- data/lib/tapyrus/message/get_addr.rb +2 -2
- data/lib/tapyrus/message/get_block_txn.rb +1 -1
- data/lib/tapyrus/message/get_blocks.rb +1 -1
- data/lib/tapyrus/message/get_data.rb +1 -1
- data/lib/tapyrus/message/get_headers.rb +1 -1
- data/lib/tapyrus/message/header_and_short_ids.rb +6 -6
- data/lib/tapyrus/message/headers.rb +1 -1
- data/lib/tapyrus/message/headers_parser.rb +2 -2
- data/lib/tapyrus/message/inv.rb +1 -1
- data/lib/tapyrus/message/inventory.rb +3 -3
- data/lib/tapyrus/message/mem_pool.rb +2 -2
- data/lib/tapyrus/message/merkle_block.rb +3 -3
- data/lib/tapyrus/message/network_addr.rb +9 -9
- data/lib/tapyrus/message/not_found.rb +1 -1
- data/lib/tapyrus/message/ping.rb +3 -3
- data/lib/tapyrus/message/pong.rb +3 -3
- data/lib/tapyrus/message/reject.rb +6 -6
- data/lib/tapyrus/message/send_cmpct.rb +4 -4
- data/lib/tapyrus/message/send_headers.rb +2 -2
- data/lib/tapyrus/message/tx.rb +1 -1
- data/lib/tapyrus/message/ver_ack.rb +2 -2
- data/lib/tapyrus/message/version.rb +7 -7
- data/lib/tapyrus/message.rb +37 -37
- data/lib/tapyrus/mnemonic.rb +18 -16
- data/lib/tapyrus/network/connection.rb +2 -2
- data/lib/tapyrus/network/message_handler.rb +11 -11
- data/lib/tapyrus/network/peer.rb +1 -1
- data/lib/tapyrus/network/peer_discovery.rb +1 -1
- data/lib/tapyrus/network/pool.rb +4 -4
- data/lib/tapyrus/network.rb +6 -6
- data/lib/tapyrus/node/cli.rb +34 -34
- data/lib/tapyrus/node/configuration.rb +3 -3
- data/lib/tapyrus/node/spv.rb +2 -2
- data/lib/tapyrus/node.rb +3 -3
- data/lib/tapyrus/opcodes.rb +7 -7
- data/lib/tapyrus/out_point.rb +2 -2
- data/lib/tapyrus/rpc/http_server.rb +6 -6
- data/lib/tapyrus/rpc/request_handler.rb +5 -5
- data/lib/tapyrus/rpc/tapyrus_core_client.rb +10 -10
- data/lib/tapyrus/rpc.rb +4 -4
- data/lib/tapyrus/script/color.rb +3 -3
- data/lib/tapyrus/script/debugger.rb +9 -9
- data/lib/tapyrus/script/multisig.rb +2 -2
- data/lib/tapyrus/script/script.rb +28 -28
- data/lib/tapyrus/script/script_error.rb +42 -42
- data/lib/tapyrus/script/script_interpreter.rb +9 -9
- data/lib/tapyrus/script/tx_checker.rb +2 -2
- data/lib/tapyrus/secp256k1/native.rb +23 -23
- data/lib/tapyrus/secp256k1/rfc6979.rb +7 -7
- data/lib/tapyrus/secp256k1/ruby.rb +2 -2
- data/lib/tapyrus/secp256k1.rb +3 -3
- data/lib/tapyrus/slip39/share.rb +7 -7
- data/lib/tapyrus/slip39/sss.rb +24 -24
- data/lib/tapyrus/slip39.rb +514 -37
- data/lib/tapyrus/store/db/level_db.rb +2 -2
- data/lib/tapyrus/store/db.rb +1 -1
- data/lib/tapyrus/store/spv_chain.rb +7 -7
- data/lib/tapyrus/store.rb +3 -3
- data/lib/tapyrus/tip0137.rb +201 -0
- data/lib/tapyrus/tx.rb +12 -12
- data/lib/tapyrus/tx_builder.rb +3 -3
- data/lib/tapyrus/tx_in.rb +3 -3
- data/lib/tapyrus/tx_out.rb +3 -3
- data/lib/tapyrus/util.rb +21 -21
- data/lib/tapyrus/validation.rb +9 -9
- data/lib/tapyrus/version.rb +1 -1
- data/lib/tapyrus/wallet/account.rb +12 -12
- data/lib/tapyrus/wallet/base.rb +9 -8
- data/lib/tapyrus/wallet/db.rb +11 -11
- data/lib/tapyrus/wallet/master_key.rb +13 -13
- data/lib/tapyrus/wallet.rb +4 -4
- data/lib/tapyrus.rb +62 -59
- data/tapyrusrb.gemspec +33 -31
- metadata +30 -14
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "siphash"
|
2
2
|
module Tapyrus
|
3
3
|
module Message
|
4
4
|
# BIP-152 Compact Block's data format.
|
@@ -15,13 +15,13 @@ module Tapyrus
|
|
15
15
|
@nonce = nonce
|
16
16
|
@short_ids = short_ids
|
17
17
|
@prefilled_txn = prefilled_txn
|
18
|
-
@siphash_key = Tapyrus.sha256(header.to_payload << [nonce].pack(
|
18
|
+
@siphash_key = Tapyrus.sha256(header.to_payload << [nonce].pack("q*"))[0...16]
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.parse_from_payload(payload)
|
22
22
|
buf = StringIO.new(payload)
|
23
23
|
header = Tapyrus::BlockHeader.parse_from_payload(buf)
|
24
|
-
nonce = buf.read(8).unpack(
|
24
|
+
nonce = buf.read(8).unpack("q*").first
|
25
25
|
short_ids_len = Tapyrus.unpack_var_int_from_io(buf)
|
26
26
|
short_ids = short_ids_len.times.map { buf.read(6).reverse.bth.to_i(16) }
|
27
27
|
prefilled_txn_len = Tapyrus.unpack_var_int_from_io(buf)
|
@@ -31,9 +31,9 @@ module Tapyrus
|
|
31
31
|
|
32
32
|
def to_payload
|
33
33
|
p = header.to_payload
|
34
|
-
p << [nonce].pack(
|
34
|
+
p << [nonce].pack("q*")
|
35
35
|
p << Tapyrus.pack_var_int(short_ids.size)
|
36
|
-
p << short_ids.map { |id| sprintf(
|
36
|
+
p << short_ids.map { |id| sprintf("%12x", id).htb.reverse }.join
|
37
37
|
p << Tapyrus.pack_var_int(prefilled_txn.size)
|
38
38
|
p << prefilled_txn.map(&:to_payload).join
|
39
39
|
p
|
@@ -44,7 +44,7 @@ module Tapyrus
|
|
44
44
|
# @return [Integer] 6 bytes short transaction id.
|
45
45
|
def short_id(txid)
|
46
46
|
hash = SipHash.digest(siphash_key, txid.htb.reverse).to_even_length_hex
|
47
|
-
[hash].pack(
|
47
|
+
[hash].pack("H*")[2...8].bth.to_i(16)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -3,7 +3,7 @@ module Tapyrus
|
|
3
3
|
# Common message parser which handle multiple block headers as a payload.
|
4
4
|
module HeadersParser
|
5
5
|
def parse_from_payload(payload)
|
6
|
-
ver, payload = payload.unpack(
|
6
|
+
ver, payload = payload.unpack("Va*")
|
7
7
|
size, payload = Tapyrus.unpack_var_int(payload)
|
8
8
|
hashes = []
|
9
9
|
buf = StringIO.new(payload)
|
@@ -12,7 +12,7 @@ module Tapyrus
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_payload
|
15
|
-
[version].pack(
|
15
|
+
[version].pack("V") << Tapyrus.pack_var_int(hashes.length) << hashes.map { |h| h.htb }.join << stop_hash.htb
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/tapyrus/message/inv.rb
CHANGED
@@ -26,14 +26,14 @@ module Tapyrus
|
|
26
26
|
|
27
27
|
# parse inventory payload
|
28
28
|
def self.parse_from_payload(payload)
|
29
|
-
raise Error,
|
30
|
-
identifier = payload[0..4].unpack(
|
29
|
+
raise Error, "invalid inventory size." if payload.bytesize != 36
|
30
|
+
identifier = payload[0..4].unpack("V").first
|
31
31
|
hash = payload[4..-1].bth # internal byte order
|
32
32
|
new(identifier, hash)
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_payload
|
36
|
-
[identifier].pack(
|
36
|
+
[identifier].pack("V") << hash.htb
|
37
37
|
end
|
38
38
|
|
39
39
|
def block?
|
@@ -3,7 +3,7 @@ module Tapyrus
|
|
3
3
|
# merckleblock message
|
4
4
|
# https://bitcoin.org/en/developer-reference#merkleblock
|
5
5
|
class MerkleBlock < Base
|
6
|
-
COMMAND =
|
6
|
+
COMMAND = "merkleblock"
|
7
7
|
|
8
8
|
attr_accessor :header
|
9
9
|
attr_accessor :tx_count
|
@@ -18,7 +18,7 @@ module Tapyrus
|
|
18
18
|
m = new
|
19
19
|
buf = StringIO.new(payload)
|
20
20
|
m.header = Tapyrus::BlockHeader.parse_from_payload(buf)
|
21
|
-
m.tx_count = buf.read(4).unpack(
|
21
|
+
m.tx_count = buf.read(4).unpack("V").first
|
22
22
|
hash_count = Tapyrus.unpack_var_int_from_io(buf)
|
23
23
|
hash_count.times { m.hashes << buf.read(32).bth }
|
24
24
|
flag_count = Tapyrus.unpack_var_int_from_io(buf)
|
@@ -29,7 +29,7 @@ module Tapyrus
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_payload
|
32
|
-
header.to_payload << [tx_count].pack(
|
32
|
+
header.to_payload << [tx_count].pack("V") << Tapyrus.pack_var_int(hashes.size) << hashes.map(&:htb).join <<
|
33
33
|
Tapyrus.pack_var_int(flags.htb.bytesize) << flags.htb
|
34
34
|
end
|
35
35
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "ipaddr"
|
2
2
|
|
3
3
|
module Tapyrus
|
4
4
|
module Message
|
@@ -19,7 +19,7 @@ module Tapyrus
|
|
19
19
|
attr_reader :skip_time
|
20
20
|
|
21
21
|
def initialize(
|
22
|
-
ip:
|
22
|
+
ip: "127.0.0.1",
|
23
23
|
port: Tapyrus.chain_params.default_port,
|
24
24
|
services: DEFAULT_SERVICE_FLAGS,
|
25
25
|
time: Time.now.to_i
|
@@ -34,16 +34,16 @@ module Tapyrus
|
|
34
34
|
buf = payload.is_a?(String) ? StringIO.new(payload) : payload
|
35
35
|
has_time = buf.size > 26
|
36
36
|
addr = new(time: nil)
|
37
|
-
addr.time = buf.read(4).unpack(
|
38
|
-
addr.services = buf.read(8).unpack(
|
37
|
+
addr.time = buf.read(4).unpack("V").first if has_time
|
38
|
+
addr.services = buf.read(8).unpack("Q").first
|
39
39
|
addr.ip_addr = IPAddr.new_ntoh(buf.read(16))
|
40
|
-
addr.port = buf.read(2).unpack(
|
40
|
+
addr.port = buf.read(2).unpack("n").first
|
41
41
|
addr
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.local_addr
|
45
45
|
addr = new
|
46
|
-
addr.ip_addr = IPAddr.new(
|
46
|
+
addr.ip_addr = IPAddr.new("127.0.0.1")
|
47
47
|
addr.port = Tapyrus.chain_params.default_port
|
48
48
|
addr.services = DEFAULT_SERVICE_FLAGS
|
49
49
|
addr
|
@@ -54,10 +54,10 @@ module Tapyrus
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_payload(skip_time = false)
|
57
|
-
p =
|
58
|
-
p << [time].pack(
|
57
|
+
p = ""
|
58
|
+
p << [time].pack("V") unless skip_time
|
59
59
|
addr = ip_addr.ipv4? ? ip_addr.ipv4_mapped : ip_addr
|
60
|
-
p << [services].pack(
|
60
|
+
p << [services].pack("Q") << addr.hton << [port].pack("n")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
data/lib/tapyrus/message/ping.rb
CHANGED
@@ -3,7 +3,7 @@ module Tapyrus
|
|
3
3
|
# ping message class
|
4
4
|
# https://bitcoin.org/en/developer-reference#ping
|
5
5
|
class Ping < Base
|
6
|
-
COMMAND =
|
6
|
+
COMMAND = "ping"
|
7
7
|
|
8
8
|
attr_accessor :nonce
|
9
9
|
|
@@ -12,11 +12,11 @@ module Tapyrus
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.parse_from_payload(payload)
|
15
|
-
new(payload.unpack(
|
15
|
+
new(payload.unpack("Q").first)
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_payload
|
19
|
-
[nonce].pack(
|
19
|
+
[nonce].pack("Q")
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_response
|
data/lib/tapyrus/message/pong.rb
CHANGED
@@ -3,7 +3,7 @@ module Tapyrus
|
|
3
3
|
# pong message
|
4
4
|
# https://bitcoin.org/en/developer-reference#pong
|
5
5
|
class Pong < Base
|
6
|
-
COMMAND =
|
6
|
+
COMMAND = "pong"
|
7
7
|
|
8
8
|
attr_reader :nonce
|
9
9
|
|
@@ -12,11 +12,11 @@ module Tapyrus
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.parse_from_payload(payload)
|
15
|
-
new(payload.unpack(
|
15
|
+
new(payload.unpack("Q").first)
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_payload
|
19
|
-
[nonce].pack(
|
19
|
+
[nonce].pack("Q")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -8,7 +8,7 @@ module Tapyrus
|
|
8
8
|
attr_accessor :reason
|
9
9
|
attr_accessor :extra
|
10
10
|
|
11
|
-
COMMAND =
|
11
|
+
COMMAND = "reject"
|
12
12
|
|
13
13
|
CODE_MALFORMED = 0x01
|
14
14
|
CODE_INVALID = 0x10
|
@@ -19,7 +19,7 @@ module Tapyrus
|
|
19
19
|
CODE_INSUFFICIENT_FEE = 0x42
|
20
20
|
CODE_CHECKPOINT = 0x43
|
21
21
|
|
22
|
-
def initialize(message, code, reason =
|
22
|
+
def initialize(message, code, reason = "", extra = "")
|
23
23
|
@message = message
|
24
24
|
@code = code
|
25
25
|
@reason = reason
|
@@ -28,15 +28,15 @@ module Tapyrus
|
|
28
28
|
|
29
29
|
def self.parse_from_payload(payload)
|
30
30
|
message, payload = Tapyrus.unpack_var_string(payload)
|
31
|
-
code, payload = payload.unpack(
|
31
|
+
code, payload = payload.unpack("Ca*")
|
32
32
|
reason, payload = Tapyrus.unpack_var_string(payload)
|
33
|
-
extra = [
|
33
|
+
extra = %w[tx block].include?(message) ? payload.bth : payload
|
34
34
|
new(message, code, reason, extra)
|
35
35
|
end
|
36
36
|
|
37
37
|
def to_payload
|
38
|
-
e = [
|
39
|
-
Tapyrus.pack_var_string(message) << [code].pack(
|
38
|
+
e = %w[tx block].include?(message) ? extra.htb : extra
|
39
|
+
Tapyrus.pack_var_string(message) << [code].pack("C") << Tapyrus.pack_var_string(reason) << e
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -3,7 +3,7 @@ module Tapyrus
|
|
3
3
|
# sendcmpct message
|
4
4
|
# https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
|
5
5
|
class SendCmpct < Base
|
6
|
-
COMMAND =
|
6
|
+
COMMAND = "sendcmpct"
|
7
7
|
|
8
8
|
MODE_HIGH = 1
|
9
9
|
MODE_LOW = 0
|
@@ -20,13 +20,13 @@ module Tapyrus
|
|
20
20
|
|
21
21
|
def self.parse_from_payload(payload)
|
22
22
|
buf = StringIO.new(payload)
|
23
|
-
mode = buf.read(1).unpack(
|
24
|
-
version = buf.read(8).unpack(
|
23
|
+
mode = buf.read(1).unpack("c").first
|
24
|
+
version = buf.read(8).unpack("Q").first
|
25
25
|
new(mode, version)
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_payload
|
29
|
-
[mode, version].pack(
|
29
|
+
[mode, version].pack("cQ")
|
30
30
|
end
|
31
31
|
|
32
32
|
def high?
|
data/lib/tapyrus/message/tx.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: ascii-8bit
|
2
|
-
require
|
2
|
+
require "ipaddr"
|
3
3
|
module Tapyrus
|
4
4
|
module Message
|
5
5
|
# https://bitcoin.org/en/developer-reference#version
|
6
6
|
class Version < Base
|
7
|
-
COMMAND =
|
7
|
+
COMMAND = "version"
|
8
8
|
|
9
9
|
attr_accessor :version
|
10
10
|
attr_accessor :services
|
@@ -30,7 +30,7 @@ module Tapyrus
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.parse_from_payload(payload)
|
33
|
-
version, services, timestamp, local_addr, remote_addr, nonce, rest = payload.unpack(
|
33
|
+
version, services, timestamp, local_addr, remote_addr, nonce, rest = payload.unpack("VQQa26a26Qa*")
|
34
34
|
v = new
|
35
35
|
v.version = version
|
36
36
|
v.services = services
|
@@ -39,7 +39,7 @@ module Tapyrus
|
|
39
39
|
v.remote_addr = NetworkAddr.parse_from_payload(remote_addr)
|
40
40
|
v.nonce = nonce
|
41
41
|
user_agent, rest = unpack_var_string(rest)
|
42
|
-
start_height, rest = rest.unpack(
|
42
|
+
start_height, rest = rest.unpack("Va*")
|
43
43
|
v.user_agent = user_agent
|
44
44
|
v.start_height = start_height
|
45
45
|
v.relay = v.unpack_relay_field(rest).first
|
@@ -48,12 +48,12 @@ module Tapyrus
|
|
48
48
|
|
49
49
|
def to_payload
|
50
50
|
[
|
51
|
-
[version, services, timestamp].pack(
|
51
|
+
[version, services, timestamp].pack("VQQ"),
|
52
52
|
local_addr.to_payload(true),
|
53
53
|
remote_addr.to_payload(true),
|
54
|
-
[nonce].pack(
|
54
|
+
[nonce].pack("Q"),
|
55
55
|
pack_var_string(user_agent),
|
56
|
-
[start_height].pack(
|
56
|
+
[start_height].pack("V"),
|
57
57
|
pack_boolean(relay)
|
58
58
|
].join
|
59
59
|
end
|
data/lib/tapyrus/message.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
autoload :Base,
|
4
|
-
autoload :Inventory,
|
5
|
-
autoload :InventoriesParser,
|
6
|
-
autoload :HeadersParser,
|
7
|
-
autoload :Version,
|
8
|
-
autoload :VerAck,
|
9
|
-
autoload :Addr,
|
10
|
-
autoload :NetworkAddr,
|
11
|
-
autoload :Block,
|
12
|
-
autoload :FilterLoad,
|
13
|
-
autoload :FilterAdd,
|
14
|
-
autoload :FilterClear,
|
15
|
-
autoload :MerkleBlock,
|
16
|
-
autoload :Tx,
|
17
|
-
autoload :Ping,
|
18
|
-
autoload :Pong,
|
19
|
-
autoload :Inv,
|
20
|
-
autoload :GetBlocks,
|
21
|
-
autoload :GetHeaders,
|
22
|
-
autoload :Headers,
|
23
|
-
autoload :GetAddr,
|
24
|
-
autoload :GetData,
|
25
|
-
autoload :SendHeaders,
|
26
|
-
autoload :FeeFilter,
|
27
|
-
autoload :MemPool,
|
28
|
-
autoload :NotFound,
|
29
|
-
autoload :Error,
|
30
|
-
autoload :Reject,
|
31
|
-
autoload :SendCmpct,
|
32
|
-
autoload :CmpctBlock,
|
33
|
-
autoload :HeaderAndShortIDs,
|
34
|
-
autoload :PrefilledTx,
|
35
|
-
autoload :GetBlockTxn,
|
36
|
-
autoload :BlockTransactionRequest,
|
37
|
-
autoload :BlockTxn,
|
38
|
-
autoload :BlockTransactions,
|
3
|
+
autoload :Base, "tapyrus/message/base"
|
4
|
+
autoload :Inventory, "tapyrus/message/inventory"
|
5
|
+
autoload :InventoriesParser, "tapyrus/message/inventories_parser"
|
6
|
+
autoload :HeadersParser, "tapyrus/message/headers_parser"
|
7
|
+
autoload :Version, "tapyrus/message/version"
|
8
|
+
autoload :VerAck, "tapyrus/message/ver_ack"
|
9
|
+
autoload :Addr, "tapyrus/message/addr"
|
10
|
+
autoload :NetworkAddr, "tapyrus/message/network_addr"
|
11
|
+
autoload :Block, "tapyrus/message/block"
|
12
|
+
autoload :FilterLoad, "tapyrus/message/filter_load"
|
13
|
+
autoload :FilterAdd, "tapyrus/message/filter_add"
|
14
|
+
autoload :FilterClear, "tapyrus/message/filter_clear"
|
15
|
+
autoload :MerkleBlock, "tapyrus/message/merkle_block"
|
16
|
+
autoload :Tx, "tapyrus/message/tx"
|
17
|
+
autoload :Ping, "tapyrus/message/ping"
|
18
|
+
autoload :Pong, "tapyrus/message/pong"
|
19
|
+
autoload :Inv, "tapyrus/message/inv"
|
20
|
+
autoload :GetBlocks, "tapyrus/message/get_blocks"
|
21
|
+
autoload :GetHeaders, "tapyrus/message/get_headers"
|
22
|
+
autoload :Headers, "tapyrus/message/headers"
|
23
|
+
autoload :GetAddr, "tapyrus/message/get_addr"
|
24
|
+
autoload :GetData, "tapyrus/message/get_data"
|
25
|
+
autoload :SendHeaders, "tapyrus/message/send_headers"
|
26
|
+
autoload :FeeFilter, "tapyrus/message/fee_filter"
|
27
|
+
autoload :MemPool, "tapyrus/message/mem_pool"
|
28
|
+
autoload :NotFound, "tapyrus/message/not_found"
|
29
|
+
autoload :Error, "tapyrus/message/error"
|
30
|
+
autoload :Reject, "tapyrus/message/reject"
|
31
|
+
autoload :SendCmpct, "tapyrus/message/send_cmpct"
|
32
|
+
autoload :CmpctBlock, "tapyrus/message/cmpct_block"
|
33
|
+
autoload :HeaderAndShortIDs, "tapyrus/message/header_and_short_ids"
|
34
|
+
autoload :PrefilledTx, "tapyrus/message/prefilled_tx"
|
35
|
+
autoload :GetBlockTxn, "tapyrus/message/get_block_txn"
|
36
|
+
autoload :BlockTransactionRequest, "tapyrus/message/block_transaction_request"
|
37
|
+
autoload :BlockTxn, "tapyrus/message/block_txn"
|
38
|
+
autoload :BlockTransactions, "tapyrus/message/block_transactions"
|
39
39
|
|
40
40
|
USER_AGENT = "/tapyrusrb:#{Tapyrus::VERSION}/"
|
41
41
|
|
@@ -52,7 +52,7 @@ module Tapyrus
|
|
52
52
|
|
53
53
|
DEFAULT_SERVICE_FLAGS = SERVICE_FLAGS[:none]
|
54
54
|
|
55
|
-
DEFAULT_STOP_HASH =
|
55
|
+
DEFAULT_STOP_HASH = "00" * 32
|
56
56
|
|
57
57
|
# the protocol version.
|
58
58
|
VERSION = {
|
data/lib/tapyrus/mnemonic.rb
CHANGED
@@ -7,13 +7,13 @@ module Tapyrus
|
|
7
7
|
attr_reader :word_list
|
8
8
|
|
9
9
|
def initialize(word_list)
|
10
|
-
raise ArgumentError,
|
10
|
+
raise ArgumentError, "specified language is not supported." unless Mnemonic.word_lists.include?(word_list)
|
11
11
|
@word_list = word_list
|
12
12
|
end
|
13
13
|
|
14
14
|
# get support language list
|
15
15
|
def self.word_lists
|
16
|
-
Dir.glob("#{WORD_DIR}/**.txt").map { |f| f.gsub("#{WORD_DIR}/",
|
16
|
+
Dir.glob("#{WORD_DIR}/**.txt").map { |f| f.gsub("#{WORD_DIR}/", "").gsub(".txt", "") }
|
17
17
|
end
|
18
18
|
|
19
19
|
# generate entropy from mnemonic word
|
@@ -22,23 +22,25 @@ module Tapyrus
|
|
22
22
|
def to_entropy(words)
|
23
23
|
word_master = load_words
|
24
24
|
mnemonic =
|
25
|
-
words
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
words
|
26
|
+
.map do |w|
|
27
|
+
index = word_master.index(w.downcase)
|
28
|
+
raise IndexError, "word not found in words list." unless index
|
29
|
+
index.to_s(2).rjust(11, "0")
|
30
|
+
end
|
31
|
+
.join
|
30
32
|
entropy = mnemonic.slice(0, (mnemonic.length * 32) / 33)
|
31
|
-
checksum = mnemonic.gsub(entropy,
|
32
|
-
raise SecurityError,
|
33
|
-
[entropy].pack(
|
33
|
+
checksum = mnemonic.gsub(entropy, "")
|
34
|
+
raise SecurityError, "checksum mismatch." unless checksum == checksum(entropy)
|
35
|
+
[entropy].pack("B*").bth
|
34
36
|
end
|
35
37
|
|
36
38
|
# generate mnemonic words from entropy.
|
37
39
|
# @param [String] entropy an entropy with hex format.
|
38
40
|
# @return [Array] the array of mnemonic word.
|
39
41
|
def to_mnemonic(entropy)
|
40
|
-
raise ArgumentError,
|
41
|
-
e = entropy.htb.unpack(
|
42
|
+
raise ArgumentError, "entropy is empty." if entropy.nil? || entropy.empty?
|
43
|
+
e = entropy.htb.unpack("B*").first
|
42
44
|
seed = e + checksum(e)
|
43
45
|
mnemonic_index = seed.chars.each_slice(11).map { |i| i.join.to_i(2) }
|
44
46
|
word_master = load_words
|
@@ -50,11 +52,11 @@ module Tapyrus
|
|
50
52
|
# @param [Array] mnemonic a array of mnemonic word.
|
51
53
|
# @param [String] passphrase a passphrase which protects mnemonic. the default value is an empty string.
|
52
54
|
# @return [String] seed
|
53
|
-
def to_seed(mnemonic, passphrase:
|
55
|
+
def to_seed(mnemonic, passphrase: "")
|
54
56
|
to_entropy(mnemonic)
|
55
57
|
OpenSSL::PKCS5.pbkdf2_hmac(
|
56
|
-
mnemonic.join(
|
57
|
-
|
58
|
+
mnemonic.join(" ").downcase,
|
59
|
+
"mnemonic" + passphrase,
|
58
60
|
2048,
|
59
61
|
64,
|
60
62
|
OpenSSL::Digest::SHA512.new
|
@@ -65,7 +67,7 @@ module Tapyrus
|
|
65
67
|
# @param [String] entropy an entropy with bit string format
|
66
68
|
# @return [String] an entropy checksum with bit string format
|
67
69
|
def checksum(entropy)
|
68
|
-
b = Tapyrus.sha256([entropy].pack(
|
70
|
+
b = Tapyrus.sha256([entropy].pack("B*")).unpack("B*").first
|
69
71
|
b.slice(0, (entropy.length / 32))
|
70
72
|
end
|
71
73
|
|
@@ -20,7 +20,7 @@ module Tapyrus
|
|
20
20
|
@logger = peer.logger
|
21
21
|
@sendheaders = false
|
22
22
|
@attr_accessor = 0
|
23
|
-
@message =
|
23
|
+
@message = ""
|
24
24
|
self.pending_connect_timeout = 5.0
|
25
25
|
end
|
26
26
|
|
@@ -44,7 +44,7 @@ module Tapyrus
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# close network connection.
|
47
|
-
def close(msg =
|
47
|
+
def close(msg = "")
|
48
48
|
logger.info "close connection with #{addr}. #{msg}"
|
49
49
|
close_connection_after_writing
|
50
50
|
end
|