tapyrus 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/tapyrusrb-cli +5 -0
- data/exe/tapyrusrbd +41 -0
- data/lib/openassets/marker_output.rb +20 -0
- data/lib/openassets/payload.rb +54 -0
- data/lib/openassets/util.rb +28 -0
- data/lib/openassets.rb +9 -0
- data/lib/tapyrus/base58.rb +38 -0
- data/lib/tapyrus/block.rb +77 -0
- data/lib/tapyrus/block_header.rb +88 -0
- data/lib/tapyrus/bloom_filter.rb +78 -0
- data/lib/tapyrus/chain_params.rb +90 -0
- data/lib/tapyrus/chainparams/mainnet.yml +41 -0
- data/lib/tapyrus/chainparams/regtest.yml +38 -0
- data/lib/tapyrus/chainparams/testnet.yml +41 -0
- data/lib/tapyrus/constants.rb +195 -0
- data/lib/tapyrus/descriptor.rb +147 -0
- data/lib/tapyrus/ext_key.rb +337 -0
- data/lib/tapyrus/key.rb +296 -0
- data/lib/tapyrus/key_path.rb +26 -0
- data/lib/tapyrus/logger.rb +42 -0
- data/lib/tapyrus/merkle_tree.rb +149 -0
- data/lib/tapyrus/message/addr.rb +35 -0
- data/lib/tapyrus/message/base.rb +28 -0
- data/lib/tapyrus/message/block.rb +46 -0
- data/lib/tapyrus/message/block_transaction_request.rb +45 -0
- data/lib/tapyrus/message/block_transactions.rb +31 -0
- data/lib/tapyrus/message/block_txn.rb +27 -0
- data/lib/tapyrus/message/cmpct_block.rb +42 -0
- data/lib/tapyrus/message/error.rb +10 -0
- data/lib/tapyrus/message/fee_filter.rb +27 -0
- data/lib/tapyrus/message/filter_add.rb +28 -0
- data/lib/tapyrus/message/filter_clear.rb +17 -0
- data/lib/tapyrus/message/filter_load.rb +39 -0
- data/lib/tapyrus/message/get_addr.rb +17 -0
- data/lib/tapyrus/message/get_block_txn.rb +27 -0
- data/lib/tapyrus/message/get_blocks.rb +29 -0
- data/lib/tapyrus/message/get_data.rb +21 -0
- data/lib/tapyrus/message/get_headers.rb +28 -0
- data/lib/tapyrus/message/header_and_short_ids.rb +57 -0
- data/lib/tapyrus/message/headers.rb +35 -0
- data/lib/tapyrus/message/headers_parser.rb +24 -0
- data/lib/tapyrus/message/inv.rb +21 -0
- data/lib/tapyrus/message/inventories_parser.rb +23 -0
- data/lib/tapyrus/message/inventory.rb +51 -0
- data/lib/tapyrus/message/mem_pool.rb +17 -0
- data/lib/tapyrus/message/merkle_block.rb +42 -0
- data/lib/tapyrus/message/network_addr.rb +63 -0
- data/lib/tapyrus/message/not_found.rb +21 -0
- data/lib/tapyrus/message/ping.rb +30 -0
- data/lib/tapyrus/message/pong.rb +26 -0
- data/lib/tapyrus/message/prefilled_tx.rb +29 -0
- data/lib/tapyrus/message/reject.rb +46 -0
- data/lib/tapyrus/message/send_cmpct.rb +43 -0
- data/lib/tapyrus/message/send_headers.rb +16 -0
- data/lib/tapyrus/message/tx.rb +30 -0
- data/lib/tapyrus/message/ver_ack.rb +17 -0
- data/lib/tapyrus/message/version.rb +69 -0
- data/lib/tapyrus/message.rb +70 -0
- data/lib/tapyrus/mnemonic/wordlist/chinese_simplified.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/chinese_traditional.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/english.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/french.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/italian.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/japanese.txt +2048 -0
- data/lib/tapyrus/mnemonic/wordlist/spanish.txt +2048 -0
- data/lib/tapyrus/mnemonic.rb +77 -0
- data/lib/tapyrus/network/connection.rb +73 -0
- data/lib/tapyrus/network/message_handler.rb +241 -0
- data/lib/tapyrus/network/peer.rb +223 -0
- data/lib/tapyrus/network/peer_discovery.rb +42 -0
- data/lib/tapyrus/network/pool.rb +135 -0
- data/lib/tapyrus/network.rb +13 -0
- data/lib/tapyrus/node/cli.rb +112 -0
- data/lib/tapyrus/node/configuration.rb +38 -0
- data/lib/tapyrus/node/spv.rb +79 -0
- data/lib/tapyrus/node.rb +7 -0
- data/lib/tapyrus/opcodes.rb +178 -0
- data/lib/tapyrus/out_point.rb +44 -0
- data/lib/tapyrus/rpc/http_server.rb +65 -0
- data/lib/tapyrus/rpc/request_handler.rb +150 -0
- data/lib/tapyrus/rpc/tapyrus_core_client.rb +72 -0
- data/lib/tapyrus/rpc.rb +7 -0
- data/lib/tapyrus/script/multisig.rb +92 -0
- data/lib/tapyrus/script/script.rb +551 -0
- data/lib/tapyrus/script/script_error.rb +111 -0
- data/lib/tapyrus/script/script_interpreter.rb +668 -0
- data/lib/tapyrus/script/tx_checker.rb +81 -0
- data/lib/tapyrus/script_witness.rb +38 -0
- data/lib/tapyrus/secp256k1/native.rb +174 -0
- data/lib/tapyrus/secp256k1/ruby.rb +123 -0
- data/lib/tapyrus/secp256k1.rb +12 -0
- data/lib/tapyrus/slip39/share.rb +122 -0
- data/lib/tapyrus/slip39/sss.rb +245 -0
- data/lib/tapyrus/slip39/wordlist/english.txt +1024 -0
- data/lib/tapyrus/slip39.rb +93 -0
- data/lib/tapyrus/store/chain_entry.rb +67 -0
- data/lib/tapyrus/store/db/level_db.rb +98 -0
- data/lib/tapyrus/store/db.rb +9 -0
- data/lib/tapyrus/store/spv_chain.rb +101 -0
- data/lib/tapyrus/store.rb +9 -0
- data/lib/tapyrus/tx.rb +347 -0
- data/lib/tapyrus/tx_in.rb +89 -0
- data/lib/tapyrus/tx_out.rb +74 -0
- data/lib/tapyrus/util.rb +133 -0
- data/lib/tapyrus/validation.rb +115 -0
- data/lib/tapyrus/version.rb +3 -0
- data/lib/tapyrus/wallet/account.rb +151 -0
- data/lib/tapyrus/wallet/base.rb +162 -0
- data/lib/tapyrus/wallet/db.rb +81 -0
- data/lib/tapyrus/wallet/master_key.rb +110 -0
- data/lib/tapyrus/wallet.rb +8 -0
- data/lib/tapyrus.rb +219 -0
- data/tapyrusrb.conf.sample +0 -0
- data/tapyrusrb.gemspec +47 -0
- metadata +451 -0
data/lib/tapyrus.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
# Porting part of the code from bitcoin-ruby. see the license.
|
2
|
+
# https://github.com/lian/bitcoin-ruby/blob/master/COPYING
|
3
|
+
|
4
|
+
require 'tapyrus/version'
|
5
|
+
require 'eventmachine'
|
6
|
+
require 'ecdsa'
|
7
|
+
require 'securerandom'
|
8
|
+
require 'json'
|
9
|
+
require 'bech32'
|
10
|
+
require 'ffi'
|
11
|
+
require 'observer'
|
12
|
+
require 'tmpdir'
|
13
|
+
require_relative 'openassets'
|
14
|
+
|
15
|
+
module Tapyrus
|
16
|
+
|
17
|
+
autoload :Util, 'tapyrus/util'
|
18
|
+
autoload :ChainParams, 'tapyrus/chain_params'
|
19
|
+
autoload :Message, 'tapyrus/message'
|
20
|
+
autoload :Logger, 'tapyrus/logger'
|
21
|
+
autoload :Block, 'tapyrus/block'
|
22
|
+
autoload :BlockHeader, 'tapyrus/block_header'
|
23
|
+
autoload :Tx, 'tapyrus/tx'
|
24
|
+
autoload :Script, 'tapyrus/script/script'
|
25
|
+
autoload :Multisig, 'tapyrus/script/multisig'
|
26
|
+
autoload :ScriptInterpreter, 'tapyrus/script/script_interpreter'
|
27
|
+
autoload :ScriptError, 'tapyrus/script/script_error'
|
28
|
+
autoload :TxChecker, 'tapyrus/script/tx_checker'
|
29
|
+
autoload :TxIn, 'tapyrus/tx_in'
|
30
|
+
autoload :TxOut, 'tapyrus/tx_out'
|
31
|
+
autoload :OutPoint, 'tapyrus/out_point'
|
32
|
+
autoload :ScriptWitness, 'tapyrus/script_witness'
|
33
|
+
autoload :MerkleTree, 'tapyrus/merkle_tree'
|
34
|
+
autoload :Key, 'tapyrus/key'
|
35
|
+
autoload :ExtKey, 'tapyrus/ext_key'
|
36
|
+
autoload :ExtPubkey, 'tapyrus/ext_key'
|
37
|
+
autoload :Opcodes, 'tapyrus/opcodes'
|
38
|
+
autoload :Node, 'tapyrus/node'
|
39
|
+
autoload :Base58, 'tapyrus/base58'
|
40
|
+
autoload :Secp256k1, 'tapyrus/secp256k1'
|
41
|
+
autoload :Mnemonic, 'tapyrus/mnemonic'
|
42
|
+
autoload :ValidationState, 'tapyrus/validation'
|
43
|
+
autoload :Network, 'tapyrus/network'
|
44
|
+
autoload :Store, 'tapyrus/store'
|
45
|
+
autoload :RPC, 'tapyrus/rpc'
|
46
|
+
autoload :Wallet, 'tapyrus/wallet'
|
47
|
+
autoload :BloomFilter, 'tapyrus/bloom_filter'
|
48
|
+
autoload :KeyPath, 'tapyrus/key_path'
|
49
|
+
autoload :Descriptor, 'tapyrus/descriptor'
|
50
|
+
autoload :SLIP39, 'tapyrus/slip39'
|
51
|
+
|
52
|
+
require_relative 'tapyrus/constants'
|
53
|
+
|
54
|
+
extend Util
|
55
|
+
|
56
|
+
@chain_param = :mainnet
|
57
|
+
|
58
|
+
# set tapyrus network chain params
|
59
|
+
def self.chain_params=(name)
|
60
|
+
raise "chain params for #{name} is not defined." unless %i(mainnet testnet regtest).include?(name.to_sym)
|
61
|
+
@current_chain = nil
|
62
|
+
@chain_param = name.to_sym
|
63
|
+
end
|
64
|
+
|
65
|
+
# current tapyrus network chain params.
|
66
|
+
def self.chain_params
|
67
|
+
return @current_chain if @current_chain
|
68
|
+
case @chain_param
|
69
|
+
when :mainnet
|
70
|
+
@current_chain = Tapyrus::ChainParams.mainnet
|
71
|
+
when :testnet
|
72
|
+
@current_chain = Tapyrus::ChainParams.testnet
|
73
|
+
when :regtest
|
74
|
+
@current_chain = Tapyrus::ChainParams.regtest
|
75
|
+
end
|
76
|
+
@current_chain
|
77
|
+
end
|
78
|
+
|
79
|
+
# base dir path that store blockchain data and wallet data
|
80
|
+
def self.base_dir
|
81
|
+
"#{Dir.home}/.tapyrusrb/#{@chain_param}"
|
82
|
+
end
|
83
|
+
|
84
|
+
# get secp implementation module
|
85
|
+
def self.secp_impl
|
86
|
+
path = ENV['SECP256K1_LIB_PATH']
|
87
|
+
(path && File.exist?(path)) ? Tapyrus::Secp256k1::Native : Tapyrus::Secp256k1::Ruby
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.hmac_sha512(key, data)
|
91
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA512'), key, data)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.hmac_sha256(key, data)
|
95
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), key, data)
|
96
|
+
end
|
97
|
+
|
98
|
+
class ::String
|
99
|
+
# binary convert to hex string
|
100
|
+
def bth
|
101
|
+
unpack('H*').first
|
102
|
+
end
|
103
|
+
|
104
|
+
# hex string convert to binary
|
105
|
+
def htb
|
106
|
+
[self].pack('H*')
|
107
|
+
end
|
108
|
+
|
109
|
+
# binary convert to integer
|
110
|
+
def bti
|
111
|
+
bth.to_i(16)
|
112
|
+
end
|
113
|
+
|
114
|
+
# reverse hex string endian
|
115
|
+
def rhex
|
116
|
+
htb.reverse.bth
|
117
|
+
end
|
118
|
+
|
119
|
+
# get opcode
|
120
|
+
def opcode
|
121
|
+
case encoding
|
122
|
+
when Encoding::ASCII_8BIT
|
123
|
+
each_byte.next
|
124
|
+
when Encoding::US_ASCII
|
125
|
+
ord
|
126
|
+
else
|
127
|
+
to_i
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def opcode?
|
132
|
+
!pushdata?
|
133
|
+
end
|
134
|
+
|
135
|
+
def push_opcode?
|
136
|
+
[Tapyrus::Opcodes::OP_PUSHDATA1, Tapyrus::Opcodes::OP_PUSHDATA2, Tapyrus::Opcodes::OP_PUSHDATA4].include?(opcode)
|
137
|
+
end
|
138
|
+
|
139
|
+
# whether data push only?
|
140
|
+
def pushdata?
|
141
|
+
opcode <= Tapyrus::Opcodes::OP_PUSHDATA4 && opcode > Tapyrus::Opcodes::OP_0
|
142
|
+
end
|
143
|
+
|
144
|
+
def pushed_data
|
145
|
+
return nil unless pushdata?
|
146
|
+
offset = 1
|
147
|
+
case opcode
|
148
|
+
when Tapyrus::Opcodes::OP_PUSHDATA1
|
149
|
+
offset += 1
|
150
|
+
when Tapyrus::Opcodes::OP_PUSHDATA2
|
151
|
+
offset += 2
|
152
|
+
when Tapyrus::Opcodes::OP_PUSHDATA4
|
153
|
+
offset += 4
|
154
|
+
end
|
155
|
+
self[offset..-1]
|
156
|
+
end
|
157
|
+
|
158
|
+
# whether value is hex or not hex
|
159
|
+
# @return [Boolean] return true if data is hex
|
160
|
+
def valid_hex?
|
161
|
+
!self[/\H/]
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
class ::Object
|
167
|
+
|
168
|
+
def build_json
|
169
|
+
if self.is_a?(Array)
|
170
|
+
"[#{self.map{|o|o.to_h.to_json}.join(',')}]"
|
171
|
+
else
|
172
|
+
to_h.to_json
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_h
|
177
|
+
return self if self.is_a?(String)
|
178
|
+
instance_variables.inject({}) do |result, var|
|
179
|
+
key = var.to_s
|
180
|
+
key.slice!(0) if key.start_with?('@')
|
181
|
+
value = instance_variable_get(var)
|
182
|
+
if value.is_a?(Array)
|
183
|
+
result.update(key => value.map{|v|v.to_h})
|
184
|
+
else
|
185
|
+
result.update(key => value)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
class ::Integer
|
193
|
+
def to_even_length_hex
|
194
|
+
hex = to_s(16)
|
195
|
+
hex.rjust((hex.length / 2.0).ceil * 2, '0')
|
196
|
+
end
|
197
|
+
|
198
|
+
def itb
|
199
|
+
to_even_length_hex.htb
|
200
|
+
end
|
201
|
+
|
202
|
+
# convert bit string
|
203
|
+
def to_bits(length = nil )
|
204
|
+
if length
|
205
|
+
to_s(2).rjust(length, '0')
|
206
|
+
else
|
207
|
+
to_s(2)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class ::ECDSA::Signature
|
213
|
+
# convert signature to der string.
|
214
|
+
def to_der
|
215
|
+
ECDSA::Format::SignatureDerString.encode(self)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
File without changes
|
data/tapyrusrb.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tapyrus/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = "tapyrus"
|
9
|
+
spec.version = Tapyrus::VERSION
|
10
|
+
spec.authors = ["azuchi"]
|
11
|
+
spec.email = ["azuchi@chaintope.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{[WIP]The implementation of Tapyrus Protocol for Ruby.}
|
14
|
+
spec.description = %q{[WIP]The implementation of Tapyrus Protocol for Ruby.}
|
15
|
+
spec.homepage = 'https://github.com/chaintope/tapyrusrb'
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'ecdsa'
|
24
|
+
spec.add_runtime_dependency 'eventmachine'
|
25
|
+
spec.add_runtime_dependency 'murmurhash3'
|
26
|
+
spec.add_runtime_dependency 'bech32', '~> 1.0.3'
|
27
|
+
spec.add_runtime_dependency 'daemon-spawn'
|
28
|
+
spec.add_runtime_dependency 'thor'
|
29
|
+
spec.add_runtime_dependency 'ffi'
|
30
|
+
spec.add_runtime_dependency 'leb128', '~> 1.0.0'
|
31
|
+
spec.add_runtime_dependency 'eventmachine_httpserver'
|
32
|
+
spec.add_runtime_dependency 'rest-client'
|
33
|
+
spec.add_runtime_dependency 'iniparse'
|
34
|
+
spec.add_runtime_dependency 'siphash'
|
35
|
+
spec.add_runtime_dependency 'protobuf', '3.8.5'
|
36
|
+
spec.add_runtime_dependency 'scrypt'
|
37
|
+
spec.add_runtime_dependency 'activesupport', '>= 5.2.3'
|
38
|
+
|
39
|
+
# for options
|
40
|
+
spec.add_development_dependency 'leveldb-native'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'bundler'
|
43
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
44
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
+
spec.add_development_dependency 'timecop'
|
46
|
+
|
47
|
+
end
|