btcruby 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 668f16c886cfdceb4e178df2ae51b030dd1580d5
4
- data.tar.gz: a83d764d41c055fef97c824a46f91f372c5b0e57
3
+ metadata.gz: c08f34b042c6881e1117904400ed1fa066cf31f1
4
+ data.tar.gz: b4c4cf4fec603d4e9f04786fae3afefd46666bbe
5
5
  SHA512:
6
- metadata.gz: 58827f74191443b4d0da51fe2d156072888947081c9c58a56b991a6ecb2b6f6e2915e99da08b4837b96752e94311e4a80fc90ffa0545a418acec59264fd596ba
7
- data.tar.gz: 92c6cc676c97dafa2dd903ba24eb1a42e3061d890531c88e7fef096b9d57183e48866009a417cd5904eb167f709526e6dbf641dbaf333e635657998d0173eab8
6
+ metadata.gz: 406d2ecfc50fdc0d019188e12d56e0c9a1f286768220ae5bf5fce5a4a95702da91f79ebb816d0d2b4aca1c6a1c19d15afb0f4c452b94d61c657ac152ec13a227
7
+ data.tar.gz: 12d8493b58fb45a00e1cd115ad1904bfc13dbfa1e31d0ce938706a8d265df7f818486485c210102af0c9c2c03c0507d03580ce74fae1b28c18d25614aae82674
@@ -14,7 +14,7 @@ module BTC
14
14
  self.new(
15
15
  version: 1,
16
16
  previous_block_hash: ZERO_HASH256,
17
- merkle_root: BTC::Data.data_from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
17
+ merkle_root: BTC.from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
18
18
  timestamp: 1231006505,
19
19
  bits: 0x1d00ffff,
20
20
  nonce: 0x7c2bac1d,
@@ -22,7 +22,7 @@ module BTC
22
22
  version: 1,
23
23
  inputs: [
24
24
  BTC::TransactionInput.new(
25
- coinbase_data: BTC::Data.data_from_hex("04FFFF001D010445"+
25
+ coinbase_data: BTC.from_hex("04FFFF001D010445"+
26
26
  "5468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E2062" +
27
27
  "72696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73"),
28
28
  )
@@ -30,7 +30,7 @@ module BTC
30
30
  outputs: [
31
31
  BTC::TransactionOutput.new(
32
32
  value: 50*COIN,
33
- script: Script.new(data: BTC::Data.data_from_hex("4104678AFDB0FE5548271967F1"+
33
+ script: Script.new(data: BTC.from_hex("4104678AFDB0FE5548271967F1"+
34
34
  "A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38"+
35
35
  "C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC"))
36
36
  )
@@ -45,7 +45,7 @@ module BTC
45
45
  self.new(
46
46
  version: 1,
47
47
  previous_block_hash: ZERO_HASH256,
48
- merkle_root: BTC::Data.data_from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
48
+ merkle_root: BTC.from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
49
49
  timestamp: 1296688602,
50
50
  bits: 0x1d00ffff,
51
51
  nonce: 0x18aea41a,
@@ -53,7 +53,7 @@ module BTC
53
53
  version: 1,
54
54
  inputs: [
55
55
  BTC::TransactionInput.new(
56
- coinbase_data: BTC::Data.data_from_hex("04FFFF001D010445"+
56
+ coinbase_data: BTC.from_hex("04FFFF001D010445"+
57
57
  "5468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E2062" +
58
58
  "72696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73"),
59
59
  )
@@ -61,7 +61,7 @@ module BTC
61
61
  outputs: [
62
62
  BTC::TransactionOutput.new(
63
63
  value: 50*COIN,
64
- script: Script.new(data: BTC::Data.data_from_hex("4104678AFDB0FE5548271967F1"+
64
+ script: Script.new(data: BTC.from_hex("4104678AFDB0FE5548271967F1"+
65
65
  "A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38"+
66
66
  "C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC"))
67
67
  )
@@ -57,7 +57,7 @@ module BTC
57
57
  self.new(
58
58
  version: 1,
59
59
  previous_block_hash: ZERO_HASH256,
60
- merkle_root: BTC::Data.data_from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
60
+ merkle_root: BTC.from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
61
61
  timestamp: 1231006505,
62
62
  bits: 0x1d00ffff,
63
63
  nonce: 0x7c2bac1d,
@@ -69,7 +69,7 @@ module BTC
69
69
  self.new(
70
70
  version: 1,
71
71
  previous_block_hash: ZERO_HASH256,
72
- merkle_root: BTC::Data.data_from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
72
+ merkle_root: BTC.from_hex("3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a"),
73
73
  timestamp: 1296688602,
74
74
  bits: 0x1d00ffff,
75
75
  nonce: 0x18aea41a,
@@ -1,10 +1,15 @@
1
1
  require 'securerandom'
2
2
 
3
3
  module BTC
4
+
5
+ # This allows doing `BTC.to_hex(...)`
6
+ module Data; end
7
+ include Data
8
+ extend self
9
+
4
10
  module Data
5
11
  extend self
6
- include HashFunctions # obsolete, left for backwards compatibility
7
-
12
+
8
13
  HEX_PACK_CODE = "H*".freeze
9
14
  BYTE_PACK_CODE = "C*".freeze
10
15
 
@@ -29,6 +34,14 @@ module BTC
29
34
  raise ArgumentError, "Data is missing" if !data
30
35
  return data.unpack(HEX_PACK_CODE).first
31
36
  end
37
+
38
+ def to_hex(data)
39
+ hex_from_data(data)
40
+ end
41
+
42
+ def from_hex(hex)
43
+ data_from_hex(hex)
44
+ end
32
45
 
33
46
  # Converts a binary string to an array of bytes (list of integers).
34
47
  # Returns a much more efficient slice of bytes if offset/limit or
@@ -14,12 +14,12 @@ module BTC
14
14
 
15
15
  # Converts binary data into hex string
16
16
  def to_hex
17
- BTC::Data.hex_from_data(self)
17
+ BTC.to_hex(self)
18
18
  end
19
19
 
20
20
  # Converts hex string into a binary data
21
21
  def from_hex
22
- BTC::Data.data_from_hex(self)
22
+ BTC.from_hex(self)
23
23
  end
24
24
 
25
25
  # Various hash functions
@@ -6,13 +6,13 @@ module BTC
6
6
  # Converts string transaction or block ID into binary hash.
7
7
  def self.hash_from_id(identifier)
8
8
  return nil if !identifier # so we can convert optional ID into optional hash without extra headache
9
- BTC::Data.data_from_hex(identifier).reverse
9
+ BTC.from_hex(identifier).reverse
10
10
  end
11
11
 
12
12
  # Converts binary hash to hex identifier (as a big-endian 256-bit integer).
13
13
  def self.id_from_hash(hash)
14
14
  return nil if !hash # so we can convert optional hash into optional ID without extra headache
15
- BTC::Data.hex_from_data(hash.reverse)
15
+ BTC.to_hex(hash.reverse)
16
16
  end
17
17
 
18
18
  end
@@ -69,7 +69,7 @@ module BTC
69
69
  end
70
70
 
71
71
  def sha256
72
- BTC::Data.hex_from_data(BTC.sha256(json))
72
+ BTC.to_hex(BTC.sha256(json))
73
73
  end
74
74
  end
75
75
  end
@@ -25,7 +25,7 @@ module BTC
25
25
  data = BTC::Data.ensure_binary_encoding(data)
26
26
 
27
27
  raise ArgumentError, "Data must be at least 6 bytes long (4 bytes prefix and 2 bytes for varints)" if data.bytesize < 6
28
- raise ArgumentError, "Prefix is invalid. Expected #{BTC::Data.hex_from_data(PREFIX_V1)}" if data[0, PREFIX_V1.bytesize] != PREFIX_V1
28
+ raise ArgumentError, "Prefix is invalid. Expected #{BTC.to_hex(PREFIX_V1)}" if data[0, PREFIX_V1.bytesize] != PREFIX_V1
29
29
 
30
30
  offset = PREFIX_V1.bytesize
31
31
  count, bytesread = WireFormat.read_varint(data: data, offset: offset)
@@ -152,7 +152,7 @@ module BTC
152
152
  buf = FFI::MemoryPointer.from_string(pubkey)
153
153
  eckey = o2i_ECPublicKey(pointer_to_pointer(eckey), pointer_to_pointer(buf), buf.size-1)
154
154
  if eckey.null?
155
- raise BTCError, "OpenSSL failed to create EC_KEY with public key: #{BTC::Data.hex_from_data(pubkey).inspect}"
155
+ raise BTCError, "OpenSSL failed to create EC_KEY with public key: #{BTC.to_hex(pubkey).inspect}"
156
156
  end
157
157
 
158
158
  # 2. Extract re-compressed pubkey from EC_KEY
@@ -358,7 +358,7 @@ module BTC
358
358
  buf = FFI::MemoryPointer.from_string(signature)
359
359
  psig = d2i_ECDSA_SIG(nil, pointer_to_pointer(buf), buf.size-1)
360
360
  if psig.null?
361
- raise BTCError, "OpenSSL failed to read ECDSA signature with DER: #{BTC::Data.hex_from_data(signature).inspect}"
361
+ raise BTCError, "OpenSSL failed to read ECDSA signature with DER: #{BTC.to_hex(signature).inspect}"
362
362
  end
363
363
 
364
364
  sig = ECDSA_SIG.new(psig) # read sig from its pointer
@@ -400,7 +400,7 @@ module BTC
400
400
  buf = FFI::MemoryPointer.from_string(public_key)
401
401
  eckey = o2i_ECPublicKey(pointer_to_pointer(eckey), pointer_to_pointer(buf), buf.size - 1)
402
402
  if eckey.null?
403
- raise BTCError, "OpenSSL failed to create EC_KEY with public key: #{BTC::Data.hex_from_data(public_key).inspect}"
403
+ raise BTCError, "OpenSSL failed to create EC_KEY with public key: #{BTC.to_hex(public_key).inspect}"
404
404
  end
405
405
 
406
406
  # -1 = error, 0 = bad sig, 1 = good
@@ -413,9 +413,9 @@ module BTC
413
413
  end
414
414
 
415
415
  if result == 0
416
- Diagnostics.current.add_message("OpenSSL detected invalid ECDSA signature. Signature: #{BTC::Data.hex_from_data(signature).inspect}; Hash: #{BTC::Data.hex_from_data(hash).inspect}; Pubkey: #{BTC::Data.hex_from_data(public_key).inspect}")
416
+ Diagnostics.current.add_message("OpenSSL detected invalid ECDSA signature. Signature: #{BTC.to_hex(signature).inspect}; Hash: #{BTC.to_hex(hash).inspect}; Pubkey: #{BTC.to_hex(public_key).inspect}")
417
417
  else
418
- raise BTCError, "OpenSSL failed with error while verifying ECDSA signature. Signature: #{BTC::Data.hex_from_data(signature).inspect}; Hash: #{BTC::Data.hex_from_data(hash).inspect}; Pubkey: #{BTC::Data.hex_from_data(public_key).inspect}"
418
+ raise BTCError, "OpenSSL failed with error while verifying ECDSA signature. Signature: #{BTC.to_hex(signature).inspect}; Hash: #{BTC.to_hex(hash).inspect}; Pubkey: #{BTC.to_hex(public_key).inspect}"
419
419
  end
420
420
  return false
421
421
  end
@@ -20,7 +20,7 @@ module BTC
20
20
  public_keys: nil, signatures_required: nil # multisig
21
21
  )
22
22
  if data || hex
23
- data ||= BTC::Data.data_from_hex(hex)
23
+ data ||= BTC.from_hex(hex)
24
24
  data = BTC::Data.ensure_binary_encoding(data)
25
25
  @chunks = []
26
26
  offset = 0
@@ -266,7 +266,7 @@ module BTC
266
266
  end
267
267
 
268
268
  def to_hex
269
- BTC::Data.hex_from_data(self.data)
269
+ BTC.to_hex(self.data)
270
270
  end
271
271
 
272
272
  # Returns an array of opcodes or pushdata strings.
@@ -629,7 +629,7 @@ module BTC
629
629
  # Wrap in single quotes. Why not double? Because they are already used in JSON and we don't want to multiply the mess.
630
630
  string = "'#{string}'"
631
631
  else
632
- string = BTC::Data.hex_from_data(pushdata)
632
+ string = BTC.to_hex(pushdata)
633
633
  # Shorter than 128-bit chunks are wrapped in square brackets to avoid ambiguity with big all-decimal numbers.
634
634
  if (pushdata.bytesize < 16)
635
635
  string = "[#{string}]"
@@ -97,7 +97,7 @@ module BTC
97
97
  fee: nil,
98
98
  inputs_amount: nil)
99
99
 
100
- data = BTC::Data.data_from_hex(hex) if hex
100
+ data = BTC.from_hex(hex) if hex
101
101
  stream = StringIO.new(data) if data
102
102
  if stream
103
103
  init_with_stream(stream)
@@ -451,7 +451,7 @@ module BTC
451
451
 
452
452
  # Returns hex representation of the transaction.
453
453
  def to_hex
454
- BTC::Data.hex_from_data(self.data)
454
+ BTC.to_hex(self.data)
455
455
  end
456
456
 
457
457
  # Makes a deep copy of a transaction (all inputs and outputs are copied too).
@@ -147,7 +147,7 @@ module BTC
147
147
 
148
148
  if dict["prev_out"]
149
149
  if hashhex = dict["prev_out"]["hash"]
150
- prevhash = BTC::Data.data_from_hex(hashhex)
150
+ prevhash = BTC.from_hex(hashhex)
151
151
  if prevhash.bytesize != 32
152
152
  raise ArgumentError, "prev_out.hash is not 32 bytes long."
153
153
  end
@@ -165,11 +165,11 @@ module BTC
165
165
  coinbase_data = nil
166
166
  script = nil
167
167
  if hex = dict["coinbase"]
168
- coinbase_data = BTC::Data.data_from_hex(hex)
168
+ coinbase_data = BTC.from_hex(hex)
169
169
  elsif dict["scriptSig"]
170
170
  if dict["scriptSig"].is_a?(Hash)
171
171
  if hex = dict["scriptSig"]["hex"]
172
- script = BTC::Script.new(data: BTC::Data.data_from_hex(hex))
172
+ script = BTC::Script.new(data: BTC.from_hex(hex))
173
173
  end
174
174
  end
175
175
  end
@@ -224,16 +224,16 @@ module BTC
224
224
  dict = {}
225
225
 
226
226
  dict["prev_out"] = {
227
- "hash" => BTC::Data.hex_from_data(self.previous_hash),
227
+ "hash" => BTC.to_hex(self.previous_hash),
228
228
  "n" => self.previous_index
229
229
  }
230
230
 
231
231
  if self.coinbase?
232
- dict["coinbase"] = BTC::Data.hex_from_data(self.coinbase_data)
232
+ dict["coinbase"] = BTC.to_hex(self.coinbase_data)
233
233
  else
234
234
  dict["scriptSig"] = {
235
235
  "asm" => self.signature_script.to_s,
236
- "hex" => BTC::Data.hex_from_data(self.signature_script.data)
236
+ "hex" => BTC.to_hex(self.signature_script.data)
237
237
  }
238
238
  end
239
239
 
@@ -247,7 +247,7 @@ module BTC
247
247
  end
248
248
 
249
249
  def to_s
250
- BTC::Data.hex_from_data(self.data)
250
+ BTC.to_hex(self.data)
251
251
  end
252
252
 
253
253
  def ==(other)
@@ -142,7 +142,7 @@ module BTC
142
142
  @script = nil
143
143
  if dict["scriptPubKey"] && dict["scriptPubKey"].is_a?(Hash)
144
144
  if hex = dict["scriptPubKey"]["hex"]
145
- @script = Script.new(data: BTC::Data.data_from_hex(hex))
145
+ @script = Script.new(data: BTC.from_hex(hex))
146
146
  if !@script
147
147
  raise ArgumentError, "Failed to parse script from scriptPubKey.hex"
148
148
  end
@@ -162,7 +162,7 @@ module BTC
162
162
  "value" => CurrencyFormatter.btc_long_formatter.string_from_number(self.value),
163
163
  "scriptPubKey" => {
164
164
  "asm" => self.script.to_s,
165
- "hex" => BTC::Data.hex_from_data(self.script.data)
165
+ "hex" => BTC.to_hex(self.script.data)
166
166
  }
167
167
  }
168
168
  end
@@ -270,7 +270,7 @@ module BTC
270
270
  end
271
271
 
272
272
  def to_s
273
- BTC::Data.hex_from_data(self.data)
273
+ BTC.to_hex(self.data)
274
274
  end
275
275
 
276
276
  def ==(other)
@@ -1,3 +1,3 @@
1
1
  module BTC
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.0.3".freeze
3
3
  end
@@ -97,7 +97,7 @@ module BTC
97
97
  end
98
98
 
99
99
  def inspect
100
- %{#<#{self.class}:#{to_s} privkey:#{BTC::Data.hex_from_data(data)} (#{@public_key_compressed ? '' : 'un'}compressed pubkey)>}
100
+ %{#<#{self.class}:#{to_s} privkey:#{BTC.to_hex(data)} (#{@public_key_compressed ? '' : 'un'}compressed pubkey)>}
101
101
  end
102
102
 
103
103
  end
@@ -17,7 +17,7 @@ describe BTC::Address do
17
17
  address.script.to_s.must_equal "OP_DUP OP_HASH160 5a73e920b7836c74f9e740a5bb885e8580557038 OP_EQUALVERIFY OP_CHECKSIG"
18
18
 
19
19
  address.to_s.must_equal("19FGfswVqxNubJbh1NW8A4t51T9x9RDVWQ")
20
- address.data.must_equal(BTC::Data.data_from_hex("5a73e920b7836c74f9e740a5bb885e8580557038"))
20
+ address.data.must_equal(BTC.from_hex("5a73e920b7836c74f9e740a5bb885e8580557038"))
21
21
  end
22
22
 
23
23
  it "should decode/encode testnet pay-to-pubkey-hash address" do
@@ -11,18 +11,18 @@ describe BTC::Base58 do
11
11
 
12
12
  def check_valid_base58(hex_string, base58_string)
13
13
  # Convert to Base58
14
- Base58.base58_from_data(BTC::Data.data_from_hex(hex_string)).must_equal(base58_string)
14
+ Base58.base58_from_data(BTC.from_hex(hex_string)).must_equal(base58_string)
15
15
 
16
16
  # Convert from Base58
17
- BTC::Data.hex_from_data(Base58.data_from_base58(base58_string)).must_equal(hex_string)
17
+ BTC.to_hex(Base58.data_from_base58(base58_string)).must_equal(hex_string)
18
18
  end
19
19
 
20
20
  def check_valid_base58check(hex, string)
21
21
  # Convert to Base58Check
22
- Base58.base58check_from_data(BTC::Data.data_from_hex(hex)).must_equal(string)
22
+ Base58.base58check_from_data(BTC.from_hex(hex)).must_equal(string)
23
23
 
24
24
  # Convert from Base58Check
25
- BTC::Data.hex_from_data(Base58.data_from_base58check(string)).must_equal(hex)
25
+ BTC.to_hex(Base58.data_from_base58check(string)).must_equal(hex)
26
26
  end
27
27
 
28
28
  describe "Base58" do
@@ -3,48 +3,48 @@ require_relative 'spec_helper'
3
3
  describe BTC::Data do
4
4
 
5
5
  it "should decode valid hex" do
6
- lambda { BTC::Data.data_from_hex(nil) }.must_raise ArgumentError
7
- BTC::Data.data_from_hex("fe").bytes.must_equal "\xfe".bytes
8
- BTC::Data.data_from_hex("deadBEEF").bytes.must_equal "\xde\xad\xbe\xef".bytes
9
- BTC::Data.data_from_hex(" \r\n\tdeadBEEF \t \r \n").bytes.must_equal "\xde\xad\xbe\xef".bytes
10
- BTC::Data.data_from_hex("").bytes.must_equal "".bytes
11
- BTC::Data.data_from_hex(" \t ").bytes.must_equal "".bytes
6
+ lambda { BTC.from_hex(nil) }.must_raise ArgumentError
7
+ BTC.from_hex("fe").bytes.must_equal "\xfe".bytes
8
+ BTC.from_hex("deadBEEF").bytes.must_equal "\xde\xad\xbe\xef".bytes
9
+ BTC.from_hex(" \r\n\tdeadBEEF \t \r \n").bytes.must_equal "\xde\xad\xbe\xef".bytes
10
+ BTC.from_hex("").bytes.must_equal "".bytes
11
+ BTC.from_hex(" \t ").bytes.must_equal "".bytes
12
12
  end
13
13
 
14
14
  it "should not decode invalid hex" do
15
- lambda { BTC::Data.data_from_hex("f") }.must_raise FormatError
16
- lambda { BTC::Data.data_from_hex("dxadBEEF") }.must_raise FormatError
17
- lambda { BTC::Data.data_from_hex("-") }.must_raise FormatError
15
+ lambda { BTC.from_hex("f") }.must_raise FormatError
16
+ lambda { BTC.from_hex("dxadBEEF") }.must_raise FormatError
17
+ lambda { BTC.from_hex("-") }.must_raise FormatError
18
18
  end
19
19
 
20
20
  it "should encode valid hex" do
21
- lambda { BTC::Data.hex_from_data(nil) }.must_raise ArgumentError
22
- BTC::Data.hex_from_data("\xfe").bytes.must_equal "fe".bytes
23
- BTC::Data.hex_from_data("\xde\xad\xbe\xef").bytes.must_equal "deadbeef".bytes
24
- BTC::Data.hex_from_data("").bytes.must_equal "".bytes
21
+ lambda { BTC.to_hex(nil) }.must_raise ArgumentError
22
+ BTC.to_hex("\xfe").bytes.must_equal "fe".bytes
23
+ BTC.to_hex("\xde\xad\xbe\xef").bytes.must_equal "deadbeef".bytes
24
+ BTC.to_hex("").bytes.must_equal "".bytes
25
25
  end
26
26
 
27
27
  it "should encode bytes" do
28
- BTC::Data.bytes_from_data("Hello, world").must_equal "Hello, world".bytes
29
- BTC::Data.bytes_from_data("Hello, world").must_equal [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
30
- BTC::Data.data_from_bytes([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]).must_equal "Hello, world"
28
+ BTC.bytes_from_data("Hello, world").must_equal "Hello, world".bytes
29
+ BTC.bytes_from_data("Hello, world").must_equal [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
30
+ BTC.data_from_bytes([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]).must_equal "Hello, world"
31
31
  end
32
32
 
33
33
  it "should access ranges of bytes" do
34
- BTC::Data.bytes_from_data("Hello, world", offset: 1).must_equal "ello, world".bytes
35
- BTC::Data.bytes_from_data("Hello, world", offset: 0, limit: 3).must_equal "Hel".bytes
34
+ BTC.bytes_from_data("Hello, world", offset: 1).must_equal "ello, world".bytes
35
+ BTC.bytes_from_data("Hello, world", offset: 0, limit: 3).must_equal "Hel".bytes
36
36
 
37
37
  # Range takes precedence over offset/limit.
38
- BTC::Data.bytes_from_data("Hello, world", offset: 0, limit: 3, range: 1..2).must_equal "el".bytes
38
+ BTC.bytes_from_data("Hello, world", offset: 0, limit: 3, range: 1..2).must_equal "el".bytes
39
39
 
40
- BTC::Data.bytes_from_data("Hello, world", range: 1..3).must_equal "ell".bytes
41
- BTC::Data.bytes_from_data("Hello, world", range: 1...3).must_equal "el".bytes
40
+ BTC.bytes_from_data("Hello, world", range: 1..3).must_equal "ell".bytes
41
+ BTC.bytes_from_data("Hello, world", range: 1...3).must_equal "el".bytes
42
42
 
43
43
  # Outside bounds
44
- BTC::Data.bytes_from_data("Hello, world", offset: 110, limit: 3).must_equal []
45
- BTC::Data.bytes_from_data("Hello, world", offset: 0, limit: 0).must_equal []
46
- BTC::Data.bytes_from_data("Hello, world", range: 100..101).must_equal []
47
- BTC::Data.bytes_from_data("Hello, world", range: 0...0).must_equal []
44
+ BTC.bytes_from_data("Hello, world", offset: 110, limit: 3).must_equal []
45
+ BTC.bytes_from_data("Hello, world", offset: 0, limit: 0).must_equal []
46
+ BTC.bytes_from_data("Hello, world", range: 100..101).must_equal []
47
+ BTC.bytes_from_data("Hello, world", range: 0...0).must_equal []
48
48
  end
49
49
 
50
50
  end
@@ -3,7 +3,7 @@ require_relative 'spec_helper'
3
3
  describe BTC::Key do
4
4
 
5
5
  def verify_rfc6979_nonce(keyhex, msg, khex)
6
- keybin = BTC::Data.data_from_hex(keyhex)
6
+ keybin = BTC.from_hex(keyhex)
7
7
  hash = BTC.sha256(msg)
8
8
  k = BTC::OpenSSL.rfc6979_ecdsa_nonce(hash, keybin)
9
9
  k.to_hex.must_equal khex
@@ -86,7 +86,7 @@ describe BTC::Key do
86
86
  end
87
87
 
88
88
  it "should support uncompressed public keys" do
89
- k = BTC::Key.new(private_key: BTC::Data.data_from_hex("c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a"), public_key_compressed: false)
89
+ k = BTC::Key.new(private_key: BTC.from_hex("c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a"), public_key_compressed: false)
90
90
  k.private_key.to_hex.must_equal "c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a"
91
91
  k.public_key.to_hex.must_equal "0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455"
92
92
  k.address.to_s.must_equal "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T"
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Andreev