tapyrus 0.2.4 → 0.2.9
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 +37 -0
- data/.prettierignore +3 -0
- data/.prettierrc.yaml +3 -0
- data/CODE_OF_CONDUCT.md +7 -7
- data/README.md +14 -17
- data/Rakefile +3 -3
- data/lib/openassets.rb +0 -2
- data/lib/openassets/marker_output.rb +0 -4
- data/lib/openassets/payload.rb +4 -10
- data/lib/schnorr.rb +14 -9
- data/lib/schnorr/sign_to_contract.rb +51 -0
- data/lib/schnorr/signature.rb +3 -6
- data/lib/tapyrus.rb +8 -30
- data/lib/tapyrus/base58.rb +7 -6
- data/lib/tapyrus/bip175.rb +67 -0
- data/lib/tapyrus/block.rb +1 -2
- data/lib/tapyrus/block_header.rb +15 -9
- data/lib/tapyrus/bloom_filter.rb +5 -3
- data/lib/tapyrus/chain_params.rb +1 -4
- data/lib/tapyrus/chainparams/dev.yml +3 -2
- data/lib/tapyrus/chainparams/prod.yml +3 -2
- data/lib/tapyrus/constants.rb +29 -23
- data/lib/tapyrus/errors.rb +1 -3
- data/lib/tapyrus/ext.rb +1 -1
- data/lib/tapyrus/ext/ecdsa.rb +4 -4
- data/lib/tapyrus/ext/json_parser.rb +1 -4
- data/lib/tapyrus/ext_key.rb +44 -32
- data/lib/tapyrus/key.rb +31 -35
- data/lib/tapyrus/key_path.rb +15 -12
- data/lib/tapyrus/logger.rb +20 -16
- data/lib/tapyrus/merkle_tree.rb +19 -20
- data/lib/tapyrus/message.rb +14 -16
- data/lib/tapyrus/message/addr.rb +1 -7
- data/lib/tapyrus/message/base.rb +0 -3
- data/lib/tapyrus/message/block.rb +2 -9
- data/lib/tapyrus/message/block_transaction_request.rb +3 -6
- data/lib/tapyrus/message/block_transactions.rb +2 -6
- data/lib/tapyrus/message/block_txn.rb +0 -4
- data/lib/tapyrus/message/cmpct_block.rb +1 -7
- data/lib/tapyrus/message/error.rb +1 -4
- data/lib/tapyrus/message/fee_filter.rb +1 -4
- data/lib/tapyrus/message/filter_add.rb +0 -4
- data/lib/tapyrus/message/filter_clear.rb +0 -4
- data/lib/tapyrus/message/filter_load.rb +2 -5
- data/lib/tapyrus/message/get_addr.rb +0 -4
- data/lib/tapyrus/message/get_block_txn.rb +0 -4
- data/lib/tapyrus/message/get_blocks.rb +0 -3
- data/lib/tapyrus/message/get_data.rb +1 -4
- data/lib/tapyrus/message/get_headers.rb +1 -3
- data/lib/tapyrus/message/header_and_short_ids.rb +3 -9
- data/lib/tapyrus/message/headers.rb +0 -4
- data/lib/tapyrus/message/headers_parser.rb +3 -8
- data/lib/tapyrus/message/inv.rb +1 -4
- data/lib/tapyrus/message/inventories_parser.rb +2 -7
- data/lib/tapyrus/message/inventory.rb +12 -5
- data/lib/tapyrus/message/mem_pool.rb +0 -4
- data/lib/tapyrus/message/merkle_block.rb +4 -9
- data/lib/tapyrus/message/network_addr.rb +7 -6
- data/lib/tapyrus/message/not_found.rb +0 -3
- data/lib/tapyrus/message/ping.rb +0 -3
- data/lib/tapyrus/message/pong.rb +0 -3
- data/lib/tapyrus/message/prefilled_tx.rb +0 -4
- data/lib/tapyrus/message/reject.rb +0 -3
- data/lib/tapyrus/message/send_cmpct.rb +1 -3
- data/lib/tapyrus/message/send_headers.rb +0 -3
- data/lib/tapyrus/message/tx.rb +0 -4
- data/lib/tapyrus/message/ver_ack.rb +1 -5
- data/lib/tapyrus/message/version.rb +2 -5
- data/lib/tapyrus/mnemonic.rb +17 -15
- data/lib/tapyrus/network.rb +0 -2
- data/lib/tapyrus/network/connection.rb +0 -3
- data/lib/tapyrus/network/message_handler.rb +61 -60
- data/lib/tapyrus/network/peer.rb +13 -12
- data/lib/tapyrus/network/peer_discovery.rb +3 -5
- data/lib/tapyrus/network/pool.rb +12 -12
- data/lib/tapyrus/node.rb +1 -1
- data/lib/tapyrus/node/cli.rb +12 -14
- data/lib/tapyrus/node/configuration.rb +1 -3
- data/lib/tapyrus/node/spv.rb +2 -3
- data/lib/tapyrus/opcodes.rb +9 -7
- data/lib/tapyrus/out_point.rb +5 -5
- data/lib/tapyrus/rpc.rb +1 -0
- data/lib/tapyrus/rpc/http_server.rb +21 -22
- data/lib/tapyrus/rpc/request_handler.rb +42 -44
- data/lib/tapyrus/rpc/tapyrus_core_client.rb +67 -25
- data/lib/tapyrus/script/color.rb +20 -2
- data/lib/tapyrus/script/multisig.rb +13 -12
- data/lib/tapyrus/script/script.rb +104 -67
- data/lib/tapyrus/script/script_error.rb +1 -4
- data/lib/tapyrus/script/script_interpreter.rb +439 -399
- data/lib/tapyrus/script/tx_checker.rb +20 -10
- data/lib/tapyrus/secp256k1.rb +0 -4
- data/lib/tapyrus/secp256k1/native.rb +14 -15
- data/lib/tapyrus/secp256k1/rfc6979.rb +7 -4
- data/lib/tapyrus/secp256k1/ruby.rb +10 -12
- data/lib/tapyrus/slip39.rb +20 -5
- data/lib/tapyrus/slip39/share.rb +41 -29
- data/lib/tapyrus/slip39/sss.rb +101 -57
- data/lib/tapyrus/store.rb +1 -3
- data/lib/tapyrus/store/chain_entry.rb +0 -4
- data/lib/tapyrus/store/db.rb +0 -2
- data/lib/tapyrus/store/db/level_db.rb +5 -9
- data/lib/tapyrus/store/spv_chain.rb +11 -17
- data/lib/tapyrus/tx.rb +45 -37
- data/lib/tapyrus/tx_builder.rb +158 -0
- data/lib/tapyrus/tx_in.rb +1 -6
- data/lib/tapyrus/tx_out.rb +2 -7
- data/lib/tapyrus/util.rb +20 -7
- data/lib/tapyrus/validation.rb +12 -11
- data/lib/tapyrus/version.rb +1 -1
- data/lib/tapyrus/wallet/account.rb +22 -18
- data/lib/tapyrus/wallet/base.rb +12 -9
- data/lib/tapyrus/wallet/db.rb +6 -9
- data/lib/tapyrus/wallet/master_key.rb +2 -4
- data/tapyrusrb.gemspec +13 -16
- metadata +22 -31
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44f097dd931371e9cce458e44ff030d9ebedcd9372632339d274457bb3839a4c
|
4
|
+
data.tar.gz: c72dddb87aacb3f649cc4a542b0988eb54347da6203e0bcc2d430065fc3398b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc7fae61da930e3af35d17039dcd9bda45b6a9317d132dc5096e585ed3b00309a7fc4a3f3552928a57b5b46289bf3fe5be28000cffe666f0d0990480e88b31f3
|
7
|
+
data.tar.gz: b7d9c26524bda4fe26f4522b51b3328145a6e590a0099f2f72b0d9cbfb43c9a4e9b7ee4eb23907d8d8c8cf3daa239b0b7ad76caee82b5b00edffef63cb69d178
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [master]
|
13
|
+
pull_request:
|
14
|
+
branches: [master]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- run: sudo apt install libleveldb-dev
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run prettier
|
35
|
+
run: bundle exec rbprettier --check .
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/.prettierignore
ADDED
data/.prettierrc.yaml
ADDED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -12,13 +12,13 @@ body size, race, ethnicity, age, religion, or nationality.
|
|
12
12
|
|
13
13
|
Examples of unacceptable behavior by participants include:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
- The use of sexualized language or imagery
|
16
|
+
- Personal attacks
|
17
|
+
- Trolling or insulting/derogatory comments
|
18
|
+
- Public or private harassment
|
19
|
+
- Publishing other's private information, such as physical or electronic
|
20
20
|
addresses, without explicit permission
|
21
|
-
|
21
|
+
- Other unethical or unprofessional conduct
|
22
22
|
|
23
23
|
Project maintainers have the right and responsibility to remove, edit, or
|
24
24
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
@@ -46,4 +46,4 @@ version 1.3.0, available at
|
|
46
46
|
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
47
|
|
48
48
|
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
# Tapyrusrb [![Build Status](https://travis-ci.org/chaintope/tapyrusrb.svg?branch=master)](https://travis-ci.org/chaintope/tapyrusrb) [![Gem Version](https://badge.fury.io/rb/tapyrus.svg)](https://badge.fury.io/rb/tapyrus) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|
2
2
|
|
3
|
-
|
4
3
|
Tapyrusrb is a Ruby implementation of [Tapyrus](https://github.com/chaintope/tapyrus-core) Protocol.
|
5
4
|
|
6
|
-
NOTE: Tapyrusrb work in progress, and there is a possibility of incompatible change.
|
5
|
+
NOTE: Tapyrusrb work in progress, and there is a possibility of incompatible change.
|
7
6
|
|
8
7
|
## Features
|
9
8
|
|
10
9
|
Tapyrusrb supports following feature:
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
- Tapyrus script interpreter
|
12
|
+
- De/serialization of Tapyrus protocol network messages
|
13
|
+
- De/serialization of blocks and transactions
|
14
|
+
- Key generation and verification for Schnorr and ECDSA (including [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) supports).
|
15
|
+
- ECDSA signature(RFC6979 -Deterministic ECDSA, LOW-S, LOW-R support)
|
16
|
+
- [WIP] SPV node
|
17
|
+
- [WIP] 0ff-chain protocol
|
19
18
|
|
20
19
|
## Requirements
|
21
20
|
|
@@ -25,13 +24,13 @@ If you use node features, please install level DB as follows.
|
|
25
24
|
|
26
25
|
#### install LevelDB
|
27
26
|
|
28
|
-
|
27
|
+
- for Ubuntu
|
29
28
|
|
30
|
-
|
29
|
+
$ sudo apt-get install libleveldb-dev
|
31
30
|
|
32
|
-
|
31
|
+
* for Mac
|
33
32
|
|
34
|
-
|
33
|
+
$ brew install leveldb
|
35
34
|
|
36
35
|
and put `leveldb-native` in your Gemfile and run bundle install.
|
37
36
|
|
@@ -65,7 +64,7 @@ And then add to your .rb file:
|
|
65
64
|
|
66
65
|
The parameters of the blockchain are managed by `Tapyrus::ChainParams`. Switch chain parameters as follows:
|
67
66
|
|
68
|
-
|
67
|
+
- prod
|
69
68
|
|
70
69
|
```ruby
|
71
70
|
Tapyrus.chain_params = :prod
|
@@ -73,7 +72,7 @@ Tapyrus.chain_params = :prod
|
|
73
72
|
|
74
73
|
This parameter is described in https://github.com/chaintope/tapyrusrb/blob/master/lib/tapyrus/chainparams/prod.yml.
|
75
74
|
|
76
|
-
|
75
|
+
- dev
|
77
76
|
|
78
77
|
```ruby
|
79
78
|
Tapyrus.chain_params = :dev
|
@@ -85,8 +84,6 @@ This parameter is described in https://github.com/chaintope/tapyrusrb/blob/maste
|
|
85
84
|
|
86
85
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tapyrusrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
87
86
|
|
88
|
-
|
89
87
|
## License
|
90
88
|
|
91
89
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
92
|
-
|
data/Rakefile
CHANGED
data/lib/openassets.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module OpenAssets
|
2
|
-
|
3
2
|
module MarkerOutput
|
4
|
-
|
5
3
|
# whether this output is marker output for open assets.
|
6
4
|
def open_assets_marker?
|
7
5
|
return false unless script_pubkey.op_return?
|
@@ -14,7 +12,5 @@ module OpenAssets
|
|
14
12
|
return nil unless script_pubkey.op_return?
|
15
13
|
Payload.parse_from_payload(script_pubkey.op_return_data)
|
16
14
|
end
|
17
|
-
|
18
15
|
end
|
19
|
-
|
20
16
|
end
|
data/lib/openassets/payload.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OpenAssets
|
4
|
-
|
5
4
|
MARKER = "\x4f\x41"
|
6
5
|
VERSION = "\x01\x00"
|
7
6
|
|
8
7
|
# the open assets payload
|
9
8
|
class Payload
|
10
|
-
|
11
9
|
attr_accessor :quantities
|
12
10
|
attr_accessor :metadata
|
13
11
|
|
@@ -26,14 +24,12 @@ module OpenAssets
|
|
26
24
|
count = Tapyrus.unpack_var_int_from_io(buf)
|
27
25
|
return nil unless count
|
28
26
|
quantities = []
|
29
|
-
count.times
|
30
|
-
quantities << LEB128.decode_unsigned(buf, buf.pos)
|
31
|
-
end
|
27
|
+
count.times { quantities << LEB128.decode_unsigned(buf, buf.pos) }
|
32
28
|
metadata_length = Tapyrus.unpack_var_int_from_io(buf)
|
33
29
|
return nil if metadata_length.nil? || buf.length < metadata_length + buf.pos
|
34
30
|
metadata = buf.read(metadata_length).each_byte.map(&:chr).join
|
35
31
|
new(quantities, metadata)
|
36
|
-
rescue
|
32
|
+
rescue StandardError
|
37
33
|
# LEB128#decode_unsigned raise 'undefined method `unpack' for nil:NilClass'
|
38
34
|
# for invalid format such as "018f8f" (the most significant bit of the last byte should be 0)
|
39
35
|
nil
|
@@ -44,11 +40,9 @@ module OpenAssets
|
|
44
40
|
payload = String.new
|
45
41
|
payload << MARKER
|
46
42
|
payload << VERSION
|
47
|
-
payload << Tapyrus.pack_var_int(quantities.size) << quantities.map{|q| LEB128.encode_unsigned(q).read }.join
|
48
|
-
payload << Tapyrus.pack_var_int(metadata.length) << metadata.bytes.map{|b| sprintf(
|
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
|
49
45
|
payload
|
50
46
|
end
|
51
|
-
|
52
47
|
end
|
53
|
-
|
54
48
|
end
|
data/lib/schnorr.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Schnorr
|
2
2
|
autoload :Signature, 'schnorr/signature'
|
3
|
+
autoload :SignToContract, 'schnorr/sign_to_contract'
|
3
4
|
|
4
5
|
module_function
|
5
6
|
|
@@ -16,12 +17,7 @@ module Schnorr
|
|
16
17
|
raise 'private_key is zero or over the curve order.' if private_key == 0 || private_key >= GROUP.order
|
17
18
|
|
18
19
|
p = GROUP.new_point(private_key)
|
19
|
-
|
20
|
-
secret = secret + message + ALGO16
|
21
|
-
nonce = Tapyrus::Secp256k1::RFC6979.generate_rfc6979_nonce(secret, '')
|
22
|
-
|
23
|
-
k0 = nonce % GROUP.order
|
24
|
-
raise 'Creation of signature failed. k is zero' if k0.zero?
|
20
|
+
k0 = deterministic_nonce(message, private_key)
|
25
21
|
|
26
22
|
r = GROUP.new_point(k0)
|
27
23
|
k = ECDSA::PrimeField.jacobi(r.y, GROUP.field.prime) == 1 ? k0 : GROUP.order - k0
|
@@ -31,6 +27,16 @@ module Schnorr
|
|
31
27
|
Schnorr::Signature.new(r.x, (k + e * private_key) % GROUP.order)
|
32
28
|
end
|
33
29
|
|
30
|
+
def deterministic_nonce(message, private_key)
|
31
|
+
secret = ECDSA::Format::IntegerOctetString.encode(private_key, GROUP.byte_length)
|
32
|
+
secret = secret + message + ALGO16
|
33
|
+
nonce = Tapyrus::Secp256k1::RFC6979.generate_rfc6979_nonce(secret, '')
|
34
|
+
|
35
|
+
k0 = nonce % GROUP.order
|
36
|
+
raise 'Creation of signature failed. k is zero' if k0.zero?
|
37
|
+
k0
|
38
|
+
end
|
39
|
+
|
34
40
|
# Verifies the given {Signature} and returns true if it is valid.
|
35
41
|
# @param message (String) A message to be signed with binary format.
|
36
42
|
# @param public_key (String) The public key with binary format.
|
@@ -76,8 +82,7 @@ module Schnorr
|
|
76
82
|
# @return (Integer) digest e.
|
77
83
|
def create_challenge(x, p, message)
|
78
84
|
r_x = ECDSA::Format::IntegerOctetString.encode(x, GROUP.byte_length)
|
79
|
-
p_str= p.to_hex.htb
|
85
|
+
p_str = p.to_hex.htb
|
80
86
|
(ECDSA.normalize_digest(Digest::SHA256.digest(r_x + p_str + message), GROUP.bit_length)) % GROUP.order
|
81
87
|
end
|
82
|
-
|
83
|
-
end
|
88
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Schnorr
|
2
|
+
module SignToContract
|
3
|
+
module_function
|
4
|
+
|
5
|
+
GROUP = ECDSA::Group::Secp256k1
|
6
|
+
|
7
|
+
# Generate schnorr signature for sign-to-signature.
|
8
|
+
# @param message [String] A message to be signed with binary format.
|
9
|
+
# @param private_key [Integer] The private key.
|
10
|
+
# @param contract [String] A contract information with 32-bytes binary format.
|
11
|
+
# @return [(Schnorr::Signature, ECDSA::Point)] signature and point to prove the commitment to contract.
|
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
|
16
|
+
|
17
|
+
p = GROUP.new_point(private_key)
|
18
|
+
k0 = Schnorr.deterministic_nonce(message, private_key)
|
19
|
+
|
20
|
+
k1, r = tweak(k0, contract)
|
21
|
+
|
22
|
+
q = GROUP.new_point(k1)
|
23
|
+
k = ECDSA::PrimeField.jacobi(q.y, GROUP.field.prime) == 1 ? k1 : GROUP.order - k1
|
24
|
+
|
25
|
+
e = Schnorr.create_challenge(q.x, p, message)
|
26
|
+
|
27
|
+
[Schnorr::Signature.new(q.x, (k + e * private_key) % GROUP.order), r]
|
28
|
+
end
|
29
|
+
|
30
|
+
def tweak(k, contract)
|
31
|
+
r = GROUP.new_point(k)
|
32
|
+
rx = ECDSA::Format::IntegerOctetString.encode(r.x, GROUP.byte_length)
|
33
|
+
h = Tapyrus.sha256(rx + contract)
|
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?
|
36
|
+
[k1, r]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Validate contract
|
40
|
+
# @param r [ECDSA::Point] point to prove the commitment.
|
41
|
+
# @param signature [Schnorr::Signature] signature.
|
42
|
+
# @param contract [String] A contract information with 32-bytes binary format.
|
43
|
+
# @return true if commitment for contract is valid, otherwise false
|
44
|
+
def valid_contract?(r, signature, contract)
|
45
|
+
rx = ECDSA::Format::IntegerOctetString.encode(r.x, GROUP.byte_length)
|
46
|
+
commitment = Tapyrus.sha256(rx + contract).bth.to_i(16) % GROUP.order
|
47
|
+
point = r + GROUP.generator.multiply_by_scalar(commitment)
|
48
|
+
signature.r == point.x
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/schnorr/signature.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Schnorr
|
2
|
-
|
3
|
-
|
2
|
+
class InvalidSignatureError < StandardError
|
3
|
+
end
|
4
4
|
|
5
5
|
# Instances of this class represents Schnorr signatures,
|
6
6
|
# which are simply a pair of integers named `r` and `s`.
|
7
7
|
class Signature
|
8
|
-
|
9
8
|
attr_reader :r
|
10
9
|
attr_reader :s
|
11
10
|
|
@@ -32,7 +31,5 @@ module Schnorr
|
|
32
31
|
def encode
|
33
32
|
ECDSA::Format::IntegerOctetString.encode(r, 32) + ECDSA::Format::IntegerOctetString.encode(s, 32)
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
|
-
|
38
|
-
end
|
35
|
+
end
|
data/lib/tapyrus.rb
CHANGED
@@ -13,7 +13,6 @@ require_relative 'openassets'
|
|
13
13
|
require_relative 'schnorr'
|
14
14
|
|
15
15
|
module Tapyrus
|
16
|
-
|
17
16
|
autoload :Ext, 'tapyrus/ext'
|
18
17
|
autoload :Util, 'tapyrus/util'
|
19
18
|
autoload :ChainParams, 'tapyrus/chain_params'
|
@@ -49,6 +48,8 @@ module Tapyrus
|
|
49
48
|
autoload :SLIP39, 'tapyrus/slip39'
|
50
49
|
autoload :Color, 'tapyrus/script/color'
|
51
50
|
autoload :Errors, 'tapyrus/errors'
|
51
|
+
autoload :TxBuilder, 'tapyrus/tx_builder'
|
52
|
+
autoload :BIP175, 'tapyrus/bip175'
|
52
53
|
|
53
54
|
require_relative 'tapyrus/constants'
|
54
55
|
require_relative 'tapyrus/ext/ecdsa'
|
@@ -59,7 +60,7 @@ module Tapyrus
|
|
59
60
|
|
60
61
|
# set tapyrus network chain params
|
61
62
|
def self.chain_params=(name)
|
62
|
-
raise "chain params for #{name} is not defined." unless %i
|
63
|
+
raise "chain params for #{name} is not defined." unless %i[prod dev].include?(name.to_sym)
|
63
64
|
@current_chain = nil
|
64
65
|
@chain_param = name.to_sym
|
65
66
|
end
|
@@ -118,14 +119,7 @@ module Tapyrus
|
|
118
119
|
|
119
120
|
# get opcode
|
120
121
|
def opcode
|
121
|
-
|
122
|
-
when Encoding::ASCII_8BIT
|
123
|
-
each_byte.next
|
124
|
-
when Encoding::US_ASCII
|
125
|
-
ord
|
126
|
-
else
|
127
|
-
to_i
|
128
|
-
end
|
122
|
+
force_encoding(Encoding::ASCII_8BIT).ord
|
129
123
|
end
|
130
124
|
|
131
125
|
def opcode?
|
@@ -160,17 +154,11 @@ module Tapyrus
|
|
160
154
|
def valid_hex?
|
161
155
|
!self[/\H/]
|
162
156
|
end
|
163
|
-
|
164
157
|
end
|
165
158
|
|
166
159
|
class ::Object
|
167
|
-
|
168
160
|
def build_json
|
169
|
-
|
170
|
-
"[#{self.map{|o|o.to_h.to_json}.join(',')}]"
|
171
|
-
else
|
172
|
-
to_h.to_json
|
173
|
-
end
|
161
|
+
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(',')}]" : to_h.to_json
|
174
162
|
end
|
175
163
|
|
176
164
|
def to_h
|
@@ -179,14 +167,9 @@ module Tapyrus
|
|
179
167
|
key = var.to_s
|
180
168
|
key.slice!(0) if key.start_with?('@')
|
181
169
|
value = instance_variable_get(var)
|
182
|
-
|
183
|
-
result.update(key => value.map{|v|v.to_h})
|
184
|
-
else
|
185
|
-
result.update(key => value)
|
186
|
-
end
|
170
|
+
value.is_a?(Array) ? result.update(key => value.map { |v| v.to_h }) : result.update(key => value)
|
187
171
|
end
|
188
172
|
end
|
189
|
-
|
190
173
|
end
|
191
174
|
|
192
175
|
class ::Integer
|
@@ -200,13 +183,8 @@ module Tapyrus
|
|
200
183
|
end
|
201
184
|
|
202
185
|
# convert bit string
|
203
|
-
def to_bits(length = nil
|
204
|
-
|
205
|
-
to_s(2).rjust(length, '0')
|
206
|
-
else
|
207
|
-
to_s(2)
|
208
|
-
end
|
186
|
+
def to_bits(length = nil)
|
187
|
+
length ? to_s(2).rjust(length, '0') : to_s(2)
|
209
188
|
end
|
210
189
|
end
|
211
|
-
|
212
190
|
end
|