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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3e18801368aaf5516fb7f0bf8e11825392554e558247abcbb945f295ff53b4
|
4
|
+
data.tar.gz: b30626c073853898c55a9f1d9077ee2cb80bfaf0eb7e9df060dfae141068740e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f09656ba36239fc5cf0f95193d16927376b2146c2478e49f9d77f9fd04acc5fb4b9efa27fe94136e683776efbaa327570e92213aa6f7f3d793948379f990bc
|
7
|
+
data.tar.gz: 7e7b0457364aafc7f25395ebf523aaf95af29e2f0407b8df9bf3a0c02202ee0c5c9ea3ea247129f2f9e9ff9e7b6ce204b19f413c6a661aff7b1b8103968031f4
|
data/.github/workflows/ruby.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/exe/tapyrus-script-debugger
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
3
|
+
require "tapyrus"
|
4
|
+
require "terminal-table"
|
6
5
|
|
7
6
|
print "Enter scriptPubkey: "
|
8
7
|
script_pubkey_hex = gets.chomp
|
@@ -32,7 +31,7 @@ unless tx_hex.length == 0
|
|
32
31
|
print "Enter index of the input: "
|
33
32
|
input_index = gets.chomp
|
34
33
|
begin
|
35
|
-
|
34
|
+
tx = Tapyrus::Tx.parse_from_payload(tx_hex.htb)
|
36
35
|
rescue StandardError
|
37
36
|
warn "Invalid tx data."
|
38
37
|
exit
|
@@ -45,7 +44,8 @@ unless tx_hex.length == 0
|
|
45
44
|
end
|
46
45
|
|
47
46
|
begin
|
48
|
-
debugger =
|
47
|
+
debugger =
|
48
|
+
Tapyrus::ScriptDebugger.new(script_pubkey: script_pubkey, script_sig: script_sig, tx: tx, index: input_index)
|
49
49
|
rescue ArgumentError => e
|
50
50
|
warn e.message
|
51
51
|
exit
|
data/exe/tapyrusrb-cli
CHANGED
data/exe/tapyrusrbd
CHANGED
@@ -1,41 +1,42 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "thor"
|
3
|
+
require "tapyrus"
|
4
|
+
require "daemon_spawn"
|
5
5
|
|
6
6
|
class TapyrusDaemon < DaemonSpawn::Base
|
7
|
-
|
8
7
|
def start(args)
|
9
8
|
puts "Tapyrusrb daemon start : #{Time.now}"
|
10
9
|
conf = Tapyrus::Node::Configuration.new(network: args.first[:network])
|
11
10
|
node = Tapyrus::Node::SPV.new(conf)
|
12
11
|
node.run
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
16
14
|
|
17
15
|
class Tapyrusrbd < Thor
|
16
|
+
class_option :network, aliases: "-n", default: :prod
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
desc 'start', 'start tapyrusrb daemon.'
|
18
|
+
desc "start", "start tapyrusrb daemon."
|
22
19
|
def start
|
23
|
-
network = options[
|
20
|
+
network = options["network"] ? options["network"].to_sym : :prod
|
24
21
|
Tapyrus.chain_params = network
|
25
22
|
FileUtils.mkdir_p(Tapyrus.base_dir)
|
26
|
-
execute_daemon([
|
23
|
+
execute_daemon(["start", network: network])
|
27
24
|
end
|
28
25
|
|
29
26
|
private
|
30
27
|
|
31
28
|
def execute_daemon(cmd_args)
|
32
|
-
TapyrusDaemon.spawn!(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
TapyrusDaemon.spawn!(
|
30
|
+
{
|
31
|
+
working_dir: Tapyrus.base_dir,
|
32
|
+
log_file: "#{Tapyrus.base_dir}/log/tapyrusrbd.log",
|
33
|
+
pid_file: "#{Tapyrus.base_dir}/tapyrusrbd.pid",
|
34
|
+
sync_log: true,
|
35
|
+
singleton: true
|
36
|
+
},
|
37
|
+
cmd_args
|
38
|
+
)
|
37
39
|
end
|
38
|
-
|
39
40
|
end
|
40
41
|
|
41
|
-
Tapyrusrbd.start(ARGV)
|
42
|
+
Tapyrusrbd.start(ARGV)
|
data/lib/openassets/payload.rb
CHANGED
@@ -9,7 +9,7 @@ module OpenAssets
|
|
9
9
|
attr_accessor :quantities
|
10
10
|
attr_accessor :metadata
|
11
11
|
|
12
|
-
def initialize(quantities = [], metadata =
|
12
|
+
def initialize(quantities = [], metadata = "")
|
13
13
|
@quantities = quantities
|
14
14
|
@metadata = metadata
|
15
15
|
end
|
@@ -41,7 +41,7 @@ module OpenAssets
|
|
41
41
|
payload << MARKER
|
42
42
|
payload << VERSION
|
43
43
|
payload << Tapyrus.pack_var_int(quantities.size) << quantities.map { |q| LEB128.encode_unsigned(q).read }.join
|
44
|
-
payload << Tapyrus.pack_var_int(metadata.length) << metadata.bytes.map { |b| sprintf(
|
44
|
+
payload << Tapyrus.pack_var_int(metadata.length) << metadata.bytes.map { |b| sprintf("%02x", b) }.join.htb
|
45
45
|
payload
|
46
46
|
end
|
47
47
|
end
|
data/lib/openassets/util.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
module OpenAssets
|
4
4
|
module Util
|
5
5
|
class << self
|
6
|
-
OA_VERSION_BYTE =
|
7
|
-
OA_VERSION_BYTE_TESTNET =
|
6
|
+
OA_VERSION_BYTE = "17" # 0x23
|
7
|
+
OA_VERSION_BYTE_TESTNET = "73" # 0x115
|
8
8
|
|
9
9
|
def script_to_asset_id(script)
|
10
10
|
hash_to_asset_id(Tapyrus.hash160(script))
|
data/lib/openassets.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "leb128"
|
2
2
|
|
3
3
|
module OpenAssets
|
4
|
-
autoload :MarkerOutput,
|
5
|
-
autoload :Payload,
|
6
|
-
autoload :Util,
|
4
|
+
autoload :MarkerOutput, "openassets/marker_output"
|
5
|
+
autoload :Payload, "openassets/payload"
|
6
|
+
autoload :Util, "openassets/util"
|
7
7
|
end
|
@@ -10,9 +10,9 @@ module Schnorr
|
|
10
10
|
# @param contract [String] A contract information with 32-bytes binary format.
|
11
11
|
# @return [(Schnorr::Signature, ECDSA::Point)] signature and point to prove the commitment to contract.
|
12
12
|
def sign(message, private_key, contract)
|
13
|
-
raise
|
14
|
-
raise
|
15
|
-
raise
|
13
|
+
raise "The message must be a 32-byte array." unless message.bytesize == 32
|
14
|
+
raise "private_key is zero or over the curve order." if private_key == 0 || private_key >= GROUP.order
|
15
|
+
raise "The contract must be a 32-byte binary string." unless contract.bytesize == 32
|
16
16
|
|
17
17
|
p = GROUP.new_point(private_key)
|
18
18
|
k0 = Schnorr.deterministic_nonce(message, private_key)
|
@@ -32,7 +32,7 @@ module Schnorr
|
|
32
32
|
rx = ECDSA::Format::IntegerOctetString.encode(r.x, GROUP.byte_length)
|
33
33
|
h = Tapyrus.sha256(rx + contract)
|
34
34
|
k1 = (k + h.bth.to_i(16)) % GROUP.order
|
35
|
-
raise
|
35
|
+
raise "Creation of signature failed. k + h(R || c) is zero" if k1.zero?
|
36
36
|
[k1, r]
|
37
37
|
end
|
38
38
|
|
data/lib/schnorr/signature.rb
CHANGED
@@ -12,17 +12,17 @@ module Schnorr
|
|
12
12
|
# @param s (Integer) the value of s.
|
13
13
|
def initialize(r, s)
|
14
14
|
@r, @s = r, s
|
15
|
-
r.is_a?(Integer) or raise ArgumentError,
|
16
|
-
s.is_a?(Integer) or raise ArgumentError,
|
15
|
+
r.is_a?(Integer) or raise ArgumentError, "r is not an integer."
|
16
|
+
s.is_a?(Integer) or raise ArgumentError, "s is not an integer."
|
17
17
|
end
|
18
18
|
|
19
19
|
# Parse a string to a {Signature}.
|
20
20
|
# @param string (String) signature string with binary format.
|
21
21
|
# @return (Signature) signature instance.
|
22
22
|
def self.decode(string)
|
23
|
-
raise InvalidSignatureError,
|
24
|
-
r = string[0...32].unpack(
|
25
|
-
s = string[32..-1].unpack(
|
23
|
+
raise InvalidSignatureError, "Invalid schnorr signature length." unless string.bytesize == 64
|
24
|
+
r = string[0...32].unpack("H*").first.to_i(16)
|
25
|
+
s = string[32..-1].unpack("H*").first.to_i(16)
|
26
26
|
new(r, s)
|
27
27
|
end
|
28
28
|
|
data/lib/schnorr.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Schnorr
|
2
|
-
autoload :Signature,
|
3
|
-
autoload :SignToContract,
|
2
|
+
autoload :Signature, "schnorr/signature"
|
3
|
+
autoload :SignToContract, "schnorr/sign_to_contract"
|
4
4
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
GROUP = ECDSA::Group::Secp256k1
|
8
|
-
ALGO16 =
|
8
|
+
ALGO16 = "SCHNORR + SHA256"
|
9
9
|
|
10
10
|
# Generate schnorr signature.
|
11
11
|
# @param message (String) A message to be signed with binary format.
|
@@ -13,8 +13,8 @@ module Schnorr
|
|
13
13
|
# (The number of times to add the generator point to itself to get the public key.)
|
14
14
|
# @return (Schnorr::Signature)
|
15
15
|
def sign(message, private_key)
|
16
|
-
raise
|
17
|
-
raise
|
16
|
+
raise "The message must be a 32-byte array." unless message.bytesize == 32
|
17
|
+
raise "private_key is zero or over the curve order." if private_key == 0 || private_key >= GROUP.order
|
18
18
|
|
19
19
|
p = GROUP.new_point(private_key)
|
20
20
|
k0 = deterministic_nonce(message, private_key)
|
@@ -30,10 +30,10 @@ module Schnorr
|
|
30
30
|
def deterministic_nonce(message, private_key)
|
31
31
|
secret = ECDSA::Format::IntegerOctetString.encode(private_key, GROUP.byte_length)
|
32
32
|
secret = secret + message + ALGO16
|
33
|
-
nonce = Tapyrus::Secp256k1::RFC6979.generate_rfc6979_nonce(secret,
|
33
|
+
nonce = Tapyrus::Secp256k1::RFC6979.generate_rfc6979_nonce(secret, "")
|
34
34
|
|
35
35
|
k0 = nonce % GROUP.order
|
36
|
-
raise
|
36
|
+
raise "Creation of signature failed. k is zero" if k0.zero?
|
37
37
|
k0
|
38
38
|
end
|
39
39
|
|
@@ -58,19 +58,19 @@ module Schnorr
|
|
58
58
|
pubkey = ECDSA::Format::PointOctetString.decode(public_key, GROUP)
|
59
59
|
field = GROUP.field
|
60
60
|
|
61
|
-
raise Schnorr::InvalidSignatureError,
|
62
|
-
raise Schnorr::InvalidSignatureError,
|
63
|
-
raise Schnorr::InvalidSignatureError,
|
64
|
-
raise Schnorr::InvalidSignatureError,
|
65
|
-
raise Schnorr::InvalidSignatureError,
|
66
|
-
raise Schnorr::InvalidSignatureError,
|
61
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: r is not in the field." unless field.include?(sig.r)
|
62
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: s is not in the field." unless field.include?(sig.s)
|
63
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: r is zero." if sig.r.zero?
|
64
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: s is zero." if sig.s.zero?
|
65
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: r is larger than field size." if sig.r >= field.prime
|
66
|
+
raise Schnorr::InvalidSignatureError, "Invalid signature: s is larger than group order." if sig.s >= GROUP.order
|
67
67
|
|
68
68
|
e = create_challenge(sig.r, pubkey, message)
|
69
69
|
|
70
70
|
r = GROUP.new_point(sig.s) + pubkey.multiply_by_scalar(e).negate
|
71
71
|
|
72
72
|
if r.infinity? || r.x != sig.r || ECDSA::PrimeField.jacobi(r.y, GROUP.field.prime) != 1
|
73
|
-
raise Schnorr::InvalidSignatureError,
|
73
|
+
raise Schnorr::InvalidSignatureError, "signature verification failed."
|
74
74
|
end
|
75
75
|
|
76
76
|
true
|
data/lib/tapyrus/base58.rb
CHANGED
@@ -4,19 +4,19 @@ module Tapyrus
|
|
4
4
|
module Base58
|
5
5
|
module_function
|
6
6
|
|
7
|
-
ALPHABET =
|
7
|
+
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
8
8
|
SIZE = ALPHABET.size
|
9
9
|
|
10
10
|
# encode hex value to base58 string.
|
11
11
|
def encode(hex)
|
12
|
-
leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 :
|
12
|
+
leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : "").size / 2
|
13
13
|
int_val = hex.to_i(16)
|
14
|
-
base58_val =
|
14
|
+
base58_val = ""
|
15
15
|
while int_val > 0
|
16
16
|
int_val, remainder = int_val.divmod(SIZE)
|
17
17
|
base58_val = ALPHABET[remainder] + base58_val
|
18
18
|
end
|
19
|
-
(
|
19
|
+
("1" * leading_zero_bytes) + base58_val
|
20
20
|
end
|
21
21
|
|
22
22
|
# decode base58 string to hex value.
|
@@ -26,13 +26,13 @@ module Tapyrus
|
|
26
26
|
.reverse
|
27
27
|
.split(//)
|
28
28
|
.each_with_index do |char, index|
|
29
|
-
raise ArgumentError,
|
29
|
+
raise ArgumentError, "Value passed not a valid Base58 String." if (char_index = ALPHABET.index(char)).nil?
|
30
30
|
int_val += char_index * (SIZE**index)
|
31
31
|
end
|
32
32
|
s = int_val.to_even_length_hex
|
33
|
-
s =
|
34
|
-
leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 :
|
35
|
-
s = (
|
33
|
+
s = "" if s == "00"
|
34
|
+
leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 : "").size
|
35
|
+
s = ("00" * leading_zero_bytes) + s if leading_zero_bytes > 0
|
36
36
|
s
|
37
37
|
end
|
38
38
|
end
|
data/lib/tapyrus/bip175.rb
CHANGED
@@ -22,8 +22,8 @@ module Tapyrus
|
|
22
22
|
|
23
23
|
# @param key [Tapyrus::ExtKey] master private extended key
|
24
24
|
def self.from_ext_key(key)
|
25
|
-
raise ArgumentError,
|
26
|
-
raise ArgumentError,
|
25
|
+
raise ArgumentError, "key should be Tapyrus::ExtKey" unless key.is_a?(Tapyrus::ExtKey)
|
26
|
+
raise ArgumentError, "key should be master private extended key" unless key.master?
|
27
27
|
new.tap do |bip175|
|
28
28
|
bip175.master_ext_key = key
|
29
29
|
bip175.payment_base =
|
@@ -33,7 +33,7 @@ module Tapyrus
|
|
33
33
|
|
34
34
|
# @param key [Tapyrus::ExtPubkey] contract base public key
|
35
35
|
def self.from_ext_pubkey(key)
|
36
|
-
raise ArgumentError,
|
36
|
+
raise ArgumentError, "key should be Tapyrus::ExtPubkey" unless key.is_a?(Tapyrus::ExtPubkey)
|
37
37
|
new.tap { |bip175| bip175.payment_base = key }
|
38
38
|
end
|
39
39
|
|
@@ -59,7 +59,7 @@ module Tapyrus
|
|
59
59
|
key = master_ext_key.derive(PURPOSE_TYPE, true).derive(Tapyrus.chain_params.bip44_coin_type, true)
|
60
60
|
|
61
61
|
# Split every 2 bytes
|
62
|
-
paths = combined_hash.unpack(
|
62
|
+
paths = combined_hash.unpack("S>*")
|
63
63
|
paths.inject(key) { |key, p| key.derive(p) }
|
64
64
|
end
|
65
65
|
|
@@ -67,7 +67,7 @@ module Tapyrus
|
|
67
67
|
# @return [Tapyrus::ExtPubkey] extended public key
|
68
68
|
def pubkey
|
69
69
|
# Split every 2 bytes
|
70
|
-
paths = combined_hash.unpack(
|
70
|
+
paths = combined_hash.unpack("S>*")
|
71
71
|
paths.inject(payment_base) { |key, p| key.derive(p) }
|
72
72
|
end
|
73
73
|
|
data/lib/tapyrus/block_header.rb
CHANGED
@@ -29,7 +29,7 @@ module Tapyrus
|
|
29
29
|
|
30
30
|
def self.parse_from_payload(payload)
|
31
31
|
buf = payload.is_a?(String) ? StringIO.new(payload) : payload
|
32
|
-
features, prev_hash, merkle_root, im_merkle_root, time, x_filed_type = buf.read(105).unpack(
|
32
|
+
features, prev_hash, merkle_root, im_merkle_root, time, x_filed_type = buf.read(105).unpack("Va32a32a32Vc")
|
33
33
|
x_field = buf.read(unpack_var_int_from_io(buf)) unless x_filed_type == X_FILED_TYPES[:none]
|
34
34
|
proof = buf.read(unpack_var_int_from_io(buf))
|
35
35
|
new(
|
@@ -45,7 +45,7 @@ module Tapyrus
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_payload(skip_proof = false)
|
48
|
-
payload = [features, prev_hash.htb, merkle_root.htb, im_merkle_root.htb, time, x_field_type].pack(
|
48
|
+
payload = [features, prev_hash.htb, merkle_root.htb, im_merkle_root.htb, time, x_field_type].pack("Va32a32a32Vc")
|
49
49
|
payload << pack_var_string(x_field.htb) unless x_field_type == X_FILED_TYPES[:none]
|
50
50
|
payload << pack_var_string(proof.htb) if proof && !skip_proof
|
51
51
|
payload
|
data/lib/tapyrus/bloom_filter.rb
CHANGED
data/lib/tapyrus/chain_params.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "yaml"
|
2
2
|
|
3
3
|
module Tapyrus
|
4
4
|
# Network parameter class
|
@@ -37,20 +37,20 @@ module Tapyrus
|
|
37
37
|
|
38
38
|
# production genesis
|
39
39
|
def self.prod
|
40
|
-
init(
|
40
|
+
init("prod")
|
41
41
|
end
|
42
42
|
|
43
43
|
# development genesis
|
44
44
|
def self.dev
|
45
|
-
init(
|
45
|
+
init("dev")
|
46
46
|
end
|
47
47
|
|
48
48
|
def prod?
|
49
|
-
network ==
|
49
|
+
network == "prod"
|
50
50
|
end
|
51
51
|
|
52
52
|
def dev?
|
53
|
-
network ==
|
53
|
+
network == "dev"
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.init(name)
|
data/lib/tapyrus/constants.rb
CHANGED
@@ -157,7 +157,7 @@ module Tapyrus
|
|
157
157
|
ERRCODES_MAP = Hash[*constants.grep(/^SCRIPT_ERR_/).map { |c| [const_get(c), c.to_s] }.flatten]
|
158
158
|
NAME_MAP = Hash[*constants.grep(/^SCRIPT_ERR_/).map { |c| [c.to_s, const_get(c)] }.flatten]
|
159
159
|
|
160
|
-
COINBASE_WTXID =
|
160
|
+
COINBASE_WTXID = "00" * 32
|
161
161
|
|
162
162
|
# for message
|
163
163
|
MESSAGE_HEADER_SIZE = 24
|
data/lib/tapyrus/errors.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Errors
|
3
3
|
module Messages
|
4
|
-
INVALID_PUBLIC_KEY =
|
5
|
-
INVALID_BIP32_PRIV_PREFIX =
|
6
|
-
INVALID_BIP32_FINGERPRINT =
|
7
|
-
INVALID_BIP32_ZERO_INDEX =
|
8
|
-
INVALID_BIP32_ZERO_DEPTH =
|
9
|
-
INVALID_BIP32_VERSION =
|
4
|
+
INVALID_PUBLIC_KEY = "Invalid public key."
|
5
|
+
INVALID_BIP32_PRIV_PREFIX = "Invalid BIP32 private key prefix. prefix must be 0x00."
|
6
|
+
INVALID_BIP32_FINGERPRINT = "Invalid parent fingerprint."
|
7
|
+
INVALID_BIP32_ZERO_INDEX = "Invalid index. Depth 0 must have 0 index."
|
8
|
+
INVALID_BIP32_ZERO_DEPTH = "Invalid depth. Master key must have 0 depth."
|
9
|
+
INVALID_BIP32_VERSION = "An unsupported version byte was specified."
|
10
10
|
|
11
|
-
INVALID_PRIV_KEY =
|
12
|
-
INVALID_CHECKSUM =
|
13
|
-
INVALID_PRIV_LENGTH =
|
11
|
+
INVALID_PRIV_KEY = "Private key is not in range [1..n-1]."
|
12
|
+
INVALID_CHECKSUM = "Invalid checksum."
|
13
|
+
INVALID_PRIV_LENGTH = "Private key must be 32 bytes."
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/tapyrus/ext/ecdsa.rb
CHANGED
@@ -13,9 +13,9 @@ end
|
|
13
13
|
|
14
14
|
module ::ECDSA::Format::PointOctetString
|
15
15
|
def self.decode(string, group, allow_hybrid: false)
|
16
|
-
string = string.dup.force_encoding(
|
16
|
+
string = string.dup.force_encoding("BINARY")
|
17
17
|
|
18
|
-
raise ECDSA::Format::DecodeError,
|
18
|
+
raise ECDSA::Format::DecodeError, "Point octet string is empty." if string.empty?
|
19
19
|
|
20
20
|
case string[0].ord
|
21
21
|
when 0
|
@@ -29,11 +29,11 @@ module ::ECDSA::Format::PointOctetString
|
|
29
29
|
decode_uncompressed string, group
|
30
30
|
when 6..7
|
31
31
|
unless allow_hybrid
|
32
|
-
raise ECDSA::Format::DecodeError,
|
32
|
+
raise ECDSA::Format::DecodeError, "Unrecognized start byte for point octet string: 0x%x" % string[0].ord
|
33
33
|
end
|
34
34
|
decode_uncompressed string, group if allow_hybrid
|
35
35
|
else
|
36
|
-
raise ECDSA::Format::DecodeError,
|
36
|
+
raise ECDSA::Format::DecodeError, "Unrecognized start byte for point octet string: 0x%x" % string[0].ord
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/tapyrus/ext.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Ext
|
3
|
-
autoload :JsonParser,
|
3
|
+
autoload :JsonParser, "tapyrus/ext/json_parser"
|
4
4
|
|
5
5
|
refine Object do
|
6
6
|
def build_json
|
7
|
-
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(
|
7
|
+
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(",")}]" : to_h.to_json
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_h
|
11
11
|
return self if self.is_a?(String)
|
12
12
|
instance_variables.inject({}) do |result, var|
|
13
13
|
key = var.to_s
|
14
|
-
key.slice!(0) if key.start_with?(
|
14
|
+
key.slice!(0) if key.start_with?("@")
|
15
15
|
value = instance_variable_get(var)
|
16
16
|
value.is_a?(Array) ? result.update(key => value.map { |v| v.to_h }) : result.update(key => value)
|
17
17
|
end
|