tapyrus 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/{.prettierrc.yaml → .prettierrc.yml} +0 -1
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -2
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/exe/tapyrus-script-debugger +5 -5
  9. data/exe/tapyrusrb-cli +1 -1
  10. data/exe/tapyrusrbd +18 -17
  11. data/lib/openassets/payload.rb +2 -2
  12. data/lib/openassets/util.rb +2 -2
  13. data/lib/openassets.rb +4 -4
  14. data/lib/schnorr/sign_to_contract.rb +4 -4
  15. data/lib/schnorr/signature.rb +5 -5
  16. data/lib/schnorr.rb +14 -14
  17. data/lib/tapyrus/base58.rb +8 -8
  18. data/lib/tapyrus/bip175.rb +5 -5
  19. data/lib/tapyrus/block_header.rb +2 -2
  20. data/lib/tapyrus/bloom_filter.rb +1 -1
  21. data/lib/tapyrus/chain_params.rb +5 -5
  22. data/lib/tapyrus/constants.rb +1 -1
  23. data/lib/tapyrus/errors.rb +9 -9
  24. data/lib/tapyrus/ext/ecdsa.rb +4 -4
  25. data/lib/tapyrus/ext/json_parser.rb +1 -1
  26. data/lib/tapyrus/ext.rb +3 -3
  27. data/lib/tapyrus/ext_key.rb +21 -21
  28. data/lib/tapyrus/jws.rb +76 -0
  29. data/lib/tapyrus/key.rb +48 -20
  30. data/lib/tapyrus/key_path.rb +3 -3
  31. data/lib/tapyrus/logger.rb +4 -11
  32. data/lib/tapyrus/merkle_tree.rb +1 -1
  33. data/lib/tapyrus/message/addr.rb +2 -2
  34. data/lib/tapyrus/message/base.rb +2 -2
  35. data/lib/tapyrus/message/block.rb +1 -1
  36. data/lib/tapyrus/message/block_txn.rb +1 -1
  37. data/lib/tapyrus/message/cmpct_block.rb +1 -1
  38. data/lib/tapyrus/message/fee_filter.rb +3 -3
  39. data/lib/tapyrus/message/filter_add.rb +1 -1
  40. data/lib/tapyrus/message/filter_clear.rb +2 -2
  41. data/lib/tapyrus/message/filter_load.rb +7 -7
  42. data/lib/tapyrus/message/get_addr.rb +2 -2
  43. data/lib/tapyrus/message/get_block_txn.rb +1 -1
  44. data/lib/tapyrus/message/get_blocks.rb +1 -1
  45. data/lib/tapyrus/message/get_data.rb +1 -1
  46. data/lib/tapyrus/message/get_headers.rb +1 -1
  47. data/lib/tapyrus/message/header_and_short_ids.rb +6 -6
  48. data/lib/tapyrus/message/headers.rb +1 -1
  49. data/lib/tapyrus/message/headers_parser.rb +2 -2
  50. data/lib/tapyrus/message/inv.rb +1 -1
  51. data/lib/tapyrus/message/inventory.rb +3 -3
  52. data/lib/tapyrus/message/mem_pool.rb +2 -2
  53. data/lib/tapyrus/message/merkle_block.rb +3 -3
  54. data/lib/tapyrus/message/network_addr.rb +9 -9
  55. data/lib/tapyrus/message/not_found.rb +1 -1
  56. data/lib/tapyrus/message/ping.rb +3 -3
  57. data/lib/tapyrus/message/pong.rb +3 -3
  58. data/lib/tapyrus/message/reject.rb +6 -6
  59. data/lib/tapyrus/message/send_cmpct.rb +4 -4
  60. data/lib/tapyrus/message/send_headers.rb +2 -2
  61. data/lib/tapyrus/message/tx.rb +1 -1
  62. data/lib/tapyrus/message/ver_ack.rb +2 -2
  63. data/lib/tapyrus/message/version.rb +7 -7
  64. data/lib/tapyrus/message.rb +37 -37
  65. data/lib/tapyrus/mnemonic.rb +18 -16
  66. data/lib/tapyrus/network/connection.rb +2 -2
  67. data/lib/tapyrus/network/message_handler.rb +11 -11
  68. data/lib/tapyrus/network/peer.rb +1 -1
  69. data/lib/tapyrus/network/peer_discovery.rb +1 -1
  70. data/lib/tapyrus/network/pool.rb +4 -4
  71. data/lib/tapyrus/network.rb +6 -6
  72. data/lib/tapyrus/node/cli.rb +34 -34
  73. data/lib/tapyrus/node/configuration.rb +3 -3
  74. data/lib/tapyrus/node/spv.rb +2 -2
  75. data/lib/tapyrus/node.rb +3 -3
  76. data/lib/tapyrus/opcodes.rb +7 -7
  77. data/lib/tapyrus/out_point.rb +2 -2
  78. data/lib/tapyrus/rpc/http_server.rb +6 -6
  79. data/lib/tapyrus/rpc/request_handler.rb +5 -5
  80. data/lib/tapyrus/rpc/tapyrus_core_client.rb +10 -10
  81. data/lib/tapyrus/rpc.rb +4 -4
  82. data/lib/tapyrus/script/color.rb +3 -3
  83. data/lib/tapyrus/script/debugger.rb +9 -9
  84. data/lib/tapyrus/script/multisig.rb +2 -2
  85. data/lib/tapyrus/script/script.rb +28 -28
  86. data/lib/tapyrus/script/script_error.rb +42 -42
  87. data/lib/tapyrus/script/script_interpreter.rb +9 -9
  88. data/lib/tapyrus/script/tx_checker.rb +2 -2
  89. data/lib/tapyrus/secp256k1/native.rb +23 -23
  90. data/lib/tapyrus/secp256k1/rfc6979.rb +7 -7
  91. data/lib/tapyrus/secp256k1/ruby.rb +2 -2
  92. data/lib/tapyrus/secp256k1.rb +3 -3
  93. data/lib/tapyrus/slip39/share.rb +7 -7
  94. data/lib/tapyrus/slip39/sss.rb +24 -24
  95. data/lib/tapyrus/slip39.rb +514 -37
  96. data/lib/tapyrus/store/db/level_db.rb +2 -2
  97. data/lib/tapyrus/store/db.rb +1 -1
  98. data/lib/tapyrus/store/spv_chain.rb +7 -7
  99. data/lib/tapyrus/store.rb +3 -3
  100. data/lib/tapyrus/tip0137.rb +201 -0
  101. data/lib/tapyrus/tx.rb +12 -12
  102. data/lib/tapyrus/tx_builder.rb +3 -3
  103. data/lib/tapyrus/tx_in.rb +3 -3
  104. data/lib/tapyrus/tx_out.rb +3 -3
  105. data/lib/tapyrus/util.rb +21 -21
  106. data/lib/tapyrus/validation.rb +9 -9
  107. data/lib/tapyrus/version.rb +1 -1
  108. data/lib/tapyrus/wallet/account.rb +12 -12
  109. data/lib/tapyrus/wallet/base.rb +9 -8
  110. data/lib/tapyrus/wallet/db.rb +11 -11
  111. data/lib/tapyrus/wallet/master_key.rb +13 -13
  112. data/lib/tapyrus/wallet.rb +4 -4
  113. data/lib/tapyrus.rb +62 -59
  114. data/tapyrusrb.gemspec +33 -31
  115. metadata +30 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b6715191d7f10eb9d2d6851660e71abcf1aa9866b2568d15774faa22af6e31d
4
- data.tar.gz: e224860705d15fe929011d56db6d1ea959f13eadb32dcb915c859db5751ddf00
3
+ metadata.gz: 8c3e18801368aaf5516fb7f0bf8e11825392554e558247abcbb945f295ff53b4
4
+ data.tar.gz: b30626c073853898c55a9f1d9077ee2cb80bfaf0eb7e9df060dfae141068740e
5
5
  SHA512:
6
- metadata.gz: b96b08953e986ad0db52c4885df2315ee0c69748e19e9486c80898886ec74f763158b71dc972881f7831a099f91f896ba21d3d04552d258dcbc6057d9d56f08a
7
- data.tar.gz: 84a9558443d75e15768d4f485dbff148fb8ac4014574e41a49050197f4d0eb18dfb5a3b5f0d3945d56a7da53c056c2db84a722ed9aed1b25df9da62be2f98aac
6
+ metadata.gz: 21f09656ba36239fc5cf0f95193d16927376b2146c2478e49f9d77f9fd04acc5fb4b9efa27fe94136e683776efbaa327570e92213aa6f7f3d793948379f990bc
7
+ data.tar.gz: 7e7b0457364aafc7f25395ebf523aaf95af29e2f0407b8df9bf3a0c02202ee0c5c9ea3ea247129f2f9e9ff9e7b6ce204b19f413c6a661aff7b1b8103968031f4
@@ -18,7 +18,7 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby-version: ["2.6", "2.7", "3.0", "3.1"]
21
+ ruby-version: ["3.0", "3.1", "3.2", "3.3"]
22
22
 
23
23
  steps:
24
24
  - run: sudo apt install libleveldb-dev
@@ -1,3 +1,2 @@
1
1
  printWidth: 120
2
2
  trailingComma: "none"
3
- rubyArrayLiteral: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.2
1
+ 3.3.0
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in tapyrusrb.gemspec
4
4
  gemspec
5
5
 
6
- gem 'parallel_tests'
6
+ gem "parallel_tests"
data/README.md CHANGED
@@ -43,7 +43,7 @@ gem leveldb-native
43
43
  Add this line to your application's Gemfile:
44
44
 
45
45
  ```ruby
46
- gem 'tapyrus'
46
+ gem "tapyrus"
47
47
  ```
48
48
 
49
49
  And then execute:
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'tapyrus'
4
- require 'terminal-table'
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
- tx = Tapyrus::Tx.parse_from_payload(tx_hex.htb)
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 = Tapyrus::ScriptDebugger.new(script_pubkey: script_pubkey, script_sig: script_sig, tx: tx, index: input_index)
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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'tapyrus'
3
+ require "tapyrus"
4
4
 
5
5
  Tapyrus::Node::CLI.start(ARGV)
data/exe/tapyrusrbd CHANGED
@@ -1,41 +1,42 @@
1
1
  #!/usr/bin/env ruby
2
- require 'thor'
3
- require 'tapyrus'
4
- require 'daemon_spawn'
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
- class_option :network, aliases: '-n', default: :prod
20
-
21
- desc 'start', 'start tapyrusrb daemon.'
18
+ desc "start", "start tapyrusrb daemon."
22
19
  def start
23
- network = options['network'] ? options['network'].to_sym : :prod
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(['start', network: network])
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!({working_dir: Tapyrus.base_dir,
33
- log_file: "#{Tapyrus.base_dir}/log/tapyrusrbd.log",
34
- pid_file: "#{Tapyrus.base_dir}/tapyrusrbd.pid",
35
- sync_log: true,
36
- singleton: true}, cmd_args)
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)
@@ -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('%02x', b) }.join.htb
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
@@ -3,8 +3,8 @@
3
3
  module OpenAssets
4
4
  module Util
5
5
  class << self
6
- OA_VERSION_BYTE = '17' # 0x23
7
- OA_VERSION_BYTE_TESTNET = '73' # 0x115
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 'leb128'
1
+ require "leb128"
2
2
 
3
3
  module OpenAssets
4
- autoload :MarkerOutput, 'openassets/marker_output'
5
- autoload :Payload, 'openassets/payload'
6
- autoload :Util, 'openassets/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 '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
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 'Creation of signature failed. k + h(R || c) is zero' if k1.zero?
35
+ raise "Creation of signature failed. k + h(R || c) is zero" if k1.zero?
36
36
  [k1, r]
37
37
  end
38
38
 
@@ -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, 'r is not an integer.'
16
- s.is_a?(Integer) or raise ArgumentError, 's is not an integer.'
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, '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)
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, 'schnorr/signature'
3
- autoload :SignToContract, 'schnorr/sign_to_contract'
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 = 'SCHNORR + SHA256'
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 '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
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 'Creation of signature failed. k is zero' if k0.zero?
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, '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
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, 'signature verification failed.'
73
+ raise Schnorr::InvalidSignatureError, "signature verification failed."
74
74
  end
75
75
 
76
76
  true
@@ -4,19 +4,19 @@ module Tapyrus
4
4
  module Base58
5
5
  module_function
6
6
 
7
- ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
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 : '').size / 2
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
- ('1' * leading_zero_bytes) + base58_val
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, 'Value passed not a valid Base58 String.' if (char_index = ALPHABET.index(char)).nil?
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 = '' 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
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
@@ -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, 'key should be Tapyrus::ExtKey' unless key.is_a?(Tapyrus::ExtKey)
26
- raise ArgumentError, 'key should be master private extended key' unless key.master?
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, 'key should be Tapyrus::ExtPubkey' unless key.is_a?(Tapyrus::ExtPubkey)
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('S>*')
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('S>*')
70
+ paths = combined_hash.unpack("S>*")
71
71
  paths.inject(payment_base) { |key, p| key.derive(p) }
72
72
  end
73
73
 
@@ -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('Va32a32a32Vc')
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('Va32a32a32Vc')
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
@@ -1,4 +1,4 @@
1
- require 'murmurhash3'
1
+ require "murmurhash3"
2
2
  module Tapyrus
3
3
  class BloomFilter
4
4
  LN2_SQUARED = 0.4804530139182014246671025263266649717305529515945455 # log(2) ** 2
@@ -1,4 +1,4 @@
1
- require 'yaml'
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('prod')
40
+ init("prod")
41
41
  end
42
42
 
43
43
  # development genesis
44
44
  def self.dev
45
- init('dev')
45
+ init("dev")
46
46
  end
47
47
 
48
48
  def prod?
49
- network == 'prod'
49
+ network == "prod"
50
50
  end
51
51
 
52
52
  def dev?
53
- network == 'dev'
53
+ network == "dev"
54
54
  end
55
55
 
56
56
  def self.init(name)
@@ -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 = '00' * 32
160
+ COINBASE_WTXID = "00" * 32
161
161
 
162
162
  # for message
163
163
  MESSAGE_HEADER_SIZE = 24
@@ -1,16 +1,16 @@
1
1
  module Tapyrus
2
2
  module Errors
3
3
  module Messages
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.'
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 = 'Private key is not in range [1..n-1].'
12
- INVALID_CHECKSUM = 'Invalid checksum.'
13
- INVALID_PRIV_LENGTH = 'Private key must be 32 bytes.'
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
@@ -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('BINARY')
16
+ string = string.dup.force_encoding("BINARY")
17
17
 
18
- raise ECDSA::Format::DecodeError, 'Point octet string is empty.' if string.empty?
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, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord
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, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord
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
@@ -1,4 +1,4 @@
1
- require 'json/pure'
1
+ require "json/pure"
2
2
 
3
3
  module Tapyrus
4
4
  module Ext
data/lib/tapyrus/ext.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  module Tapyrus
2
2
  module Ext
3
- autoload :JsonParser, 'tapyrus/ext/json_parser'
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(',')}]" : to_h.to_json
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