btcruby 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/documentation/extensions.md +0 -16
- data/documentation/index.md +3 -3
- data/documentation/keychain.md +5 -2
- data/lib/btcruby/address.rb +0 -30
- data/lib/btcruby/block_header.rb +0 -8
- data/lib/btcruby/extensions.rb +0 -10
- data/lib/btcruby/key.rb +0 -20
- data/lib/btcruby/keychain.rb +4 -11
- data/lib/btcruby/script.rb +0 -11
- data/lib/btcruby/transaction.rb +0 -12
- data/lib/btcruby/transaction_input.rb +0 -12
- data/lib/btcruby/transaction_output.rb +0 -12
- data/lib/btcruby/version.rb +1 -1
- data/lib/btcruby/wif.rb +0 -10
- data/sample_code/creating_a_transaction_manually.rb +2 -2
- data/sample_code/using_transaction_builder.rb +3 -3
- metadata +2 -3
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 668f16c886cfdceb4e178df2ae51b030dd1580d5
|
4
|
+
data.tar.gz: a83d764d41c055fef97c824a46f91f372c5b0e57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58827f74191443b4d0da51fe2d156072888947081c9c58a56b991a6ecb2b6f6e2915e99da08b4837b96752e94311e4a80fc90ffa0545a418acec59264fd596ba
|
7
|
+
data.tar.gz: 92c6cc676c97dafa2dd903ba24eb1a42e3061d890531c88e7fef096b9d57183e48866009a417cd5904eb167f709526e6dbf641dbaf333e635657998d0173eab8
|
data/documentation/extensions.md
CHANGED
@@ -58,19 +58,3 @@ Returns a binary string compressed using two passes of [SHA-256](http://en.wikip
|
|
58
58
|
#### hash160
|
59
59
|
|
60
60
|
Returns a binary string compressed using composition `ripemd160(sha256(string))`. Known in Bitcoin as *Hash160*.
|
61
|
-
|
62
|
-
#### hmac_sha256(key: *String*)
|
63
|
-
|
64
|
-
Returns a result of [HMAC](http://en.wikipedia.org/wiki/Hash-based_message_authentication_code) using [SHA-256](http://en.wikipedia.org/wiki/SHA-2) hash using `self` as data.
|
65
|
-
|
66
|
-
#### hmac_sha256(data: *String*)
|
67
|
-
|
68
|
-
Returns a result of [HMAC](http://en.wikipedia.org/wiki/Hash-based_message_authentication_code) using [SHA-256](http://en.wikipedia.org/wiki/SHA-2) hash using `self` as key.
|
69
|
-
|
70
|
-
#### hmac_sha512(key: *String*)
|
71
|
-
|
72
|
-
Returns a result of [HMAC](http://en.wikipedia.org/wiki/Hash-based_message_authentication_code) using [SHA-512](http://en.wikipedia.org/wiki/SHA-2) hash using `self` as data.
|
73
|
-
|
74
|
-
#### hmac_sha512(data: *String*, key: *String*)
|
75
|
-
|
76
|
-
Returns a result of [HMAC](http://en.wikipedia.org/wiki/Hash-based_message_authentication_code) using [SHA-512](http://en.wikipedia.org/wiki/SHA-2) hash using `self` as key.
|
data/documentation/index.md
CHANGED
@@ -11,7 +11,7 @@ Bitcoin Data Structures | Utilities
|
|
11
11
|
[Constants](constants.md) | [Base58](base58.md) | [HashFunctions](hash_functions.md)
|
12
12
|
[Address](address.md) | [Core Extensions](extensions.md) | [Key](key.md)
|
13
13
|
↳ [PublicKeyAddress](p2pkh.md) | [Data](data.md) | [Keychain](keychain.md)
|
14
|
-
↳ [ScriptHashAddress](
|
14
|
+
↳ [ScriptHashAddress](p2sh.md) | [Diagnostics](diagnostics.md) | [OpenSSL](openssl.md)
|
15
15
|
↳ [WIF](wif.md) | [Hash↔ID Conversions](hash_id.md) |
|
16
16
|
[Block](block.md) | [ProofOfWork](proof_of_work.md) |
|
17
17
|
[BlockHeader](block_header.md) | [WireFormat](wire_format.md) |
|
@@ -130,7 +130,7 @@ builder.input_addresses = [ "L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVw
|
|
130
130
|
builder.unspent_outputs_provider_block = lambda do |addresses, outputs_amount, outputs_size, fee_rate|
|
131
131
|
txout = BTC::TransactionOutput.new(
|
132
132
|
value: 50_000,
|
133
|
-
script: BTC::PublicKeyAddress.
|
133
|
+
script: BTC::PublicKeyAddress.parse("17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV").script,
|
134
134
|
transaction_id: "115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986",
|
135
135
|
index: 0
|
136
136
|
)
|
@@ -179,7 +179,7 @@ tx.add_input(TransactionInput.new(
|
|
179
179
|
# 2. Add a raw output with a script
|
180
180
|
tx.add_output(TransactionOutput.new(
|
181
181
|
value: 100_000,
|
182
|
-
script: PublicKeyAddress.
|
182
|
+
script: PublicKeyAddress.parse("1CBtcGivXmHQ8ZqdPgeMfcpQNJrqTrSAcG").script))
|
183
183
|
|
184
184
|
# 3. Get the private key from WIF
|
185
185
|
key = Key.new(wif: "L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")
|
data/documentation/keychain.md
CHANGED
@@ -99,6 +99,11 @@ Starts with `xprv` for mainnet and `tprv` for testnet.
|
|
99
99
|
|
100
100
|
An alias to `extended_private_key`.
|
101
101
|
|
102
|
+
#### to_s
|
103
|
+
|
104
|
+
A [Base58Check](base58.md)-encoded extended key.
|
105
|
+
Returns `extended_private_key` if private, and `extended_public_key` if public.
|
106
|
+
|
102
107
|
#### identifier
|
103
108
|
|
104
109
|
A 160-bit binary identifier (aka "hash") of the keychain.
|
@@ -176,5 +181,3 @@ Equivalent to `derived_keychain(...).key`
|
|
176
181
|
#### derived_key(*path*)
|
177
182
|
|
178
183
|
Equivalent to `derived_keychain(path).key`
|
179
|
-
|
180
|
-
|
data/lib/btcruby/address.rb
CHANGED
@@ -28,16 +28,6 @@
|
|
28
28
|
module BTC
|
29
29
|
class Address
|
30
30
|
|
31
|
-
# Converts base58-encoded string to a BTC::Address instance.
|
32
|
-
# If BTC::Address is already provided, returns it.
|
33
|
-
def self.with_address(string_or_address)
|
34
|
-
raise ArgumentError, "Use Address.parse(...) instead"
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.with_string(base58check_string)
|
38
|
-
raise ArgumentError, "Use #{self}.parse(...) instead"
|
39
|
-
end
|
40
|
-
|
41
31
|
# Decodes address from a Base58Check-encoded string
|
42
32
|
def self.parse(string_or_address)
|
43
33
|
raise ArgumentError, "Argument is missing" if !string_or_address
|
@@ -175,11 +165,6 @@ module BTC
|
|
175
165
|
|
176
166
|
HASH160_LENGTH = 20
|
177
167
|
|
178
|
-
# Instantiates addess with the 20-byte hash
|
179
|
-
def self.with_data(hash, network: nil)
|
180
|
-
raise ArgumentError, "Use #{self}.new(hash: ...) instead"
|
181
|
-
end
|
182
|
-
|
183
168
|
def initialize(string: nil, hash: nil, network: nil, _raw_data: nil)
|
184
169
|
if string || _raw_data
|
185
170
|
_raw_data ||= Base58.data_from_base58check(string)
|
@@ -240,11 +225,6 @@ module BTC
|
|
240
225
|
end
|
241
226
|
end
|
242
227
|
|
243
|
-
# Instantiates an address with a public key binary data
|
244
|
-
def self.with_public_key(public_key, network: nil)
|
245
|
-
raise ArgumentError, "Use #{self}.new(public_key: ...) instead"
|
246
|
-
end
|
247
|
-
|
248
228
|
# Returns BTC::Script with data 'OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG'
|
249
229
|
def script
|
250
230
|
raise ArgumentError, "BTC::PublicKeyAddress: invalid data length (must be 20 bytes)" if self.data.bytesize != 20
|
@@ -277,16 +257,6 @@ module BTC
|
|
277
257
|
end
|
278
258
|
end
|
279
259
|
|
280
|
-
# Instantiates address with a given redeem script.
|
281
|
-
def self.with_redeem_script(redeem_script, network: nil)
|
282
|
-
raise ArgumentError, "Use #{self}.new(redeem_script: ...) instead"
|
283
|
-
end
|
284
|
-
|
285
|
-
# Instantiates address with a given redeem script binary data.
|
286
|
-
def self.with_redeem_script_data(redeem_script_data, network: nil)
|
287
|
-
raise ArgumentError, "Use #{self}.new(hash: BTC.hash160(redeem_script.data)) instead"
|
288
|
-
end
|
289
|
-
|
290
260
|
# Returns BTC::Script with data 'OP_HASH160 <hash> OP_EQUAL'
|
291
261
|
def script
|
292
262
|
raise ArgumentError, "BTC::ScriptHashAddress: invalid data length (must be 20 bytes)" if self.data.bytesize != 20
|
data/lib/btcruby/block_header.rb
CHANGED
@@ -77,14 +77,6 @@ module BTC
|
|
77
77
|
)
|
78
78
|
end
|
79
79
|
|
80
|
-
def self.with_data(data)
|
81
|
-
raise ArgumentError, "Use #{self}.new(data: ...) instead"
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.with_stream(stream)
|
85
|
-
raise ArgumentError, "Use #{self}.new(stream: ...) instead"
|
86
|
-
end
|
87
|
-
|
88
80
|
def initialize(data: nil,
|
89
81
|
stream: nil,
|
90
82
|
version: CURRENT_VERSION,
|
data/lib/btcruby/extensions.rb
CHANGED
@@ -47,16 +47,6 @@ module BTC
|
|
47
47
|
BTC.sha512(self)
|
48
48
|
end
|
49
49
|
|
50
|
-
def hmac_sha256(data: nil, key: nil)
|
51
|
-
raise ArgumentError, "Either data or key must be specified" if !data && !key
|
52
|
-
BTC.hmac_sha256(data: data || self, key: key || self)
|
53
|
-
end
|
54
|
-
|
55
|
-
def hmac_sha512(data: nil, key: nil)
|
56
|
-
raise ArgumentError, "Either data or key must be specified" if !data && !key
|
57
|
-
BTC.hmac_sha512(data: data || self, key: key || self)
|
58
|
-
end
|
59
|
-
|
60
50
|
end
|
61
51
|
end
|
62
52
|
|
data/lib/btcruby/key.rb
CHANGED
@@ -87,26 +87,6 @@ module BTC
|
|
87
87
|
network: network)
|
88
88
|
end
|
89
89
|
|
90
|
-
# Creates an instance with public key data (compressed or not).
|
91
|
-
# You can verify signatures with that instance, but cannot sign messages.
|
92
|
-
# If the public key is compressed, public_key_compressed attribute will be set to true.
|
93
|
-
def self.with_public_key(public_key, network: nil)
|
94
|
-
raise ArgumentError, "Use Key.new(public_key: ...) instead"
|
95
|
-
end
|
96
|
-
|
97
|
-
# Creates an instance with private key data (32 bytes).
|
98
|
-
# You can sign messages and verify signatures with that instance.
|
99
|
-
# public_key_compressed is set to true as a default.
|
100
|
-
def self.with_private_key(private_key, public_key_compressed: true, network: nil)
|
101
|
-
raise ArgumentError, "Use Key.new(private_key: ...) instead"
|
102
|
-
end
|
103
|
-
|
104
|
-
# Creates an instance with a private key encoded in WIF format.
|
105
|
-
# Uses WIF internally.
|
106
|
-
def self.with_wif(wif_string)
|
107
|
-
raise ArgumentError, "Use Key.new(wif: ...) instead"
|
108
|
-
end
|
109
|
-
|
110
90
|
|
111
91
|
# Accessors
|
112
92
|
# ---------
|
data/lib/btcruby/keychain.rb
CHANGED
@@ -113,6 +113,10 @@ module BTC
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
def to_s
|
117
|
+
private? ? xprv : xpub
|
118
|
+
end
|
119
|
+
|
116
120
|
def xpub
|
117
121
|
extended_public_key
|
118
122
|
end
|
@@ -174,17 +178,6 @@ module BTC
|
|
174
178
|
@network])
|
175
179
|
end
|
176
180
|
|
177
|
-
# Initializes master keychain from a seed.
|
178
|
-
# This is the "root" keychain of the entire hierarchy.
|
179
|
-
def self.with_seed(seed, network: nil)
|
180
|
-
raise ArgumentError, "Use Keychain.new(seed: ...) instead"
|
181
|
-
end
|
182
|
-
|
183
|
-
# Initializes keychain from a Base58Check-encoded extended public or private key.
|
184
|
-
def self.with_extended_key(xkey)
|
185
|
-
raise ArgumentError, "Use Keychain.new(extended_key/xpub/xprv: ...) instead"
|
186
|
-
end
|
187
|
-
|
188
181
|
# Instantiates Keychain with a binary seed or a base58-encoded extended public/private key.
|
189
182
|
# Usage:
|
190
183
|
# * Keychain.new(seed: ...[, network: ...])
|
data/lib/btcruby/script.rb
CHANGED
@@ -60,17 +60,6 @@ module BTC
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
# Initializes a script with its binary representation.
|
64
|
-
# Returns nil if data is not a well-formed script.
|
65
|
-
def self.with_data(data)
|
66
|
-
raise ArgumentError, "Use Script.new(data: ...) instead"
|
67
|
-
end
|
68
|
-
|
69
|
-
# Initializes a script of form "OP_RETURN <data>"
|
70
|
-
def self.op_return_script(data)
|
71
|
-
raise ArgumentError, "Use Script.new(op_return:...) instead"
|
72
|
-
end
|
73
|
-
|
74
63
|
# Initializes a multisignature script "OP_<M> <pubkey1> ... <pubkeyN> OP_<N> OP_CHECKMULTISIG"
|
75
64
|
# N must be >= M, M and N should be from 1 to 16.
|
76
65
|
# If you need a more customized transaction with OP_CHECKMULTISIG, create it using other methods.
|
data/lib/btcruby/transaction.rb
CHANGED
@@ -174,18 +174,6 @@ module BTC
|
|
174
174
|
init_with_components(version: version, inputs: txins, outputs: txouts, lock_time: lock_time)
|
175
175
|
end
|
176
176
|
|
177
|
-
def self.with_data(data)
|
178
|
-
raise ArgumentError, "Use Transaction.new(data: ...) instead"
|
179
|
-
end
|
180
|
-
|
181
|
-
def self.with_stream(stream)
|
182
|
-
raise ArgumentError, "Use Transaction.new(stream: ...) instead"
|
183
|
-
end
|
184
|
-
|
185
|
-
def self.with_dictionary(dict)
|
186
|
-
raise ArgumentError, "Use Transaction.new(dictionary: ...)"
|
187
|
-
end
|
188
|
-
|
189
177
|
# Returns true if this transaction is a coinbase transaction.
|
190
178
|
def coinbase?
|
191
179
|
self.inputs.size == 1 && self.inputs[0].coinbase?
|
@@ -188,18 +188,6 @@ module BTC
|
|
188
188
|
@sequence = seq
|
189
189
|
end
|
190
190
|
|
191
|
-
def self.with_data(data)
|
192
|
-
raise ArgumentError, "Use TransactionInput.new(data: ...) instead"
|
193
|
-
end
|
194
|
-
|
195
|
-
def self.with_stream(stream)
|
196
|
-
raise ArgumentError, "Use TransactionInput.new(stream: ...) instead"
|
197
|
-
end
|
198
|
-
|
199
|
-
def self.with_dictionary(dict)
|
200
|
-
raise ArgumentError, "Use TransactionInput.new(dictionary: ...) instead"
|
201
|
-
end
|
202
|
-
|
203
191
|
# Returns true if this input is a coinbase input.
|
204
192
|
def coinbase?
|
205
193
|
return self.previous_index == INVALID_INDEX && self.previous_hash == ZERO_HASH256
|
@@ -150,18 +150,6 @@ module BTC
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
def self.with_data(data)
|
154
|
-
raise ArgumentError, "Use TransactionOutput.new(data: ...) instead"
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.with_stream(stream)
|
158
|
-
raise ArgumentError, "Use TransactionOutput.new(stream: ...) instead"
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.with_dictionary(dict)
|
162
|
-
raise ArgumentError, "Use TransactionOutput.new(dictionary: ...) instead"
|
163
|
-
end
|
164
|
-
|
165
153
|
def data
|
166
154
|
data = "".b
|
167
155
|
data << BTC::WireFormat.encode_int64le(self.value)
|
data/lib/btcruby/version.rb
CHANGED
data/lib/btcruby/wif.rb
CHANGED
@@ -38,16 +38,6 @@ module BTC
|
|
38
38
|
end
|
39
39
|
alias_method :eql?, :==
|
40
40
|
|
41
|
-
# private API
|
42
|
-
def self.with_string(base58check_string, raw_data = nil)
|
43
|
-
raise ArgumentError, "Use WIF.new(string: ...) instead"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Creates an address with private key data and non-compressed pubkey flag.
|
47
|
-
def self.with_data(data, public_key_compressed: false, network: nil)
|
48
|
-
raise ArgumentError, "Use WIF.new(private_key: ...) or WIF.new(key: ...) instead"
|
49
|
-
end
|
50
|
-
|
51
41
|
# Usage:
|
52
42
|
# * WIF.new(string: ...)
|
53
43
|
# * WIF.new(private_key: ..., public_key_compressed: true|false, network: ...)
|
@@ -19,7 +19,7 @@ tx.add_input(TransactionInput.new(
|
|
19
19
|
# 2. Add a raw output with a script
|
20
20
|
tx.add_output(TransactionOutput.new(
|
21
21
|
value: 100_000,
|
22
|
-
script: PublicKeyAddress.
|
22
|
+
script: PublicKeyAddress.parse("1CBtcGivXmHQ8ZqdPgeMfcpQNJrqTrSAcG").script))
|
23
23
|
|
24
24
|
# 3. Get the private key from WIF
|
25
25
|
key = Key.new(wif: "L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")
|
@@ -27,7 +27,7 @@ key = Key.new(wif: "L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")
|
|
27
27
|
# 4. Sign the input (assuming it links to an output with address 18oxCAnbuKHDjP7KzLBDj8mLjggDBjE1Q9)
|
28
28
|
hashtype = BTC::SIGHASH_ALL
|
29
29
|
sighash = tx.signature_hash(input_index: 0,
|
30
|
-
output_script: PublicKeyAddress.
|
30
|
+
output_script: PublicKeyAddress.parse("18oxCAnbuKHDjP7KzLBDj8mLjggDBjE1Q9").script,
|
31
31
|
hash_type: hashtype)
|
32
32
|
tx.inputs[0].signature_script = Script.new << (key.ecdsa_signature(sighash) + WireFormat.encode_uint8(hashtype)) << key.public_key
|
33
33
|
|
@@ -20,7 +20,7 @@ builder.input_addresses = [ BTC::Key.new(wif: "L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27
|
|
20
20
|
builder.unspent_outputs_provider_block = lambda do |addresses, outputs_amount, outputs_size, fee|
|
21
21
|
txout = BTC::TransactionOutput.new(
|
22
22
|
value: 50_000,
|
23
|
-
script: BTC::PublicKeyAddress.
|
23
|
+
script: BTC::PublicKeyAddress.parse("17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV").script,
|
24
24
|
transaction_id: "115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986",
|
25
25
|
index: 0
|
26
26
|
)
|
@@ -30,10 +30,10 @@ end
|
|
30
30
|
# 3. Specify payment address and amount
|
31
31
|
builder.outputs = [ BTC::TransactionOutput.new(
|
32
32
|
value: 10_000,
|
33
|
-
script: BTC::PublicKeyAddress.
|
33
|
+
script: BTC::PublicKeyAddress.parse("17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV").script) ]
|
34
34
|
|
35
35
|
# 4. Specify the change address
|
36
|
-
builder.change_address = BTC::PublicKeyAddress.
|
36
|
+
builder.change_address = BTC::PublicKeyAddress.parse("1CBtcGivXmHQ8ZqdPgeMfcpQNJrqTrSAcG")
|
37
37
|
|
38
38
|
# 5. Build the transaction and broadcast it.
|
39
39
|
result = builder.build
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: btcruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Andreev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -38,7 +38,6 @@ extensions: []
|
|
38
38
|
extra_rdoc_files: []
|
39
39
|
files:
|
40
40
|
- ".gitignore"
|
41
|
-
- ".travis.yml"
|
42
41
|
- FAQ.md
|
43
42
|
- Gemfile
|
44
43
|
- Gemfile.lock
|
data/.travis.yml
DELETED