btcruby 1.5.1 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bbec90a3ce39cd29196eafbbbfc18e884e8c514
4
- data.tar.gz: 05eb71dfff15d7b3f4949945623be1dfdebd8855
3
+ metadata.gz: 217d2c55943bb88f2a02a77774574a82f345845f
4
+ data.tar.gz: 9e74dfbf5e332e4fbda8cca3c3d6f1dd8962ac1a
5
5
  SHA512:
6
- metadata.gz: 9d658653097c2a101c5e42f03b287f2769070a379c6a6e2f1ec244f1782421f9cfcc10bad946e3d9e4a6721bb13f8ef4148a21dd6cc2baac6635115cc96b001d
7
- data.tar.gz: fc9c6d2bb51365065b558590f0f5a45b8bac0d1ac6df795fd3ce195ee5e4f8af241772d4e34a8634f66826747e08389cb34d497f4a8ccc7ed80194205f2e593f
6
+ metadata.gz: 509d5068a72d3e04ea612a92348bc7edd9929aed0acc87e55dc10866c24294e6d2f84fb26d0d54f2c18ab19ff09cd6cc0bc267735cb6694be6fbd5e3d757dda0
7
+ data.tar.gz: 39b60fbdd30baf9ffaa08005d07ac2d767c3f85a8e0c5761380e369ebeae96092bcf9d7d7f1406f4c5a30f63ef3694e1598980efacada1e23e9484aff6c2a40a
data/RELEASE_NOTES.md CHANGED
@@ -2,8 +2,15 @@
2
2
  BTCRuby Release Notes
3
3
  =====================
4
4
 
5
+ 1.6 (January 15, 2015)
6
+ -------------------------
7
+
8
+ * `BTC::Mnemonic` implements read-only part of BIP44.
9
+ * `BTC::Keychain` implements utility methods to derive BIP44 keys.
10
+
11
+
5
12
  1.5.1 (December 30, 2015)
6
- -----------------------
13
+ -------------------------
7
14
 
8
15
  * `BTC::TransactionSignatureChecker` accepts `version` and `amount` to support different hashing schemes (e.g. segwit) and passes them to `BTC::Transaction#signature_hash` function.
9
16
 
data/lib/btcruby.rb CHANGED
@@ -22,6 +22,7 @@ require_relative 'btcruby/address.rb'
22
22
  require_relative 'btcruby/wif.rb'
23
23
  require_relative 'btcruby/key.rb'
24
24
  require_relative 'btcruby/keychain.rb'
25
+ require_relative 'btcruby/mnemonic.rb'
25
26
  require_relative 'btcruby/wire_format.rb'
26
27
  require_relative 'btcruby/hash_id.rb'
27
28
  require_relative 'btcruby/outpoint.rb'
data/lib/btcruby/key.rb CHANGED
@@ -126,7 +126,7 @@ module BTC
126
126
 
127
127
  # Returns a PublicKeyAddress instance that encodes a public key hash.
128
128
  def address(network: nil)
129
- PublicKeyAddress.new(public_key: self.public_key, network: network)
129
+ PublicKeyAddress.new(public_key: self.public_key, network: network || self.network)
130
130
  end
131
131
 
132
132
  # Returns a WIF instance that encodes private key.
@@ -452,6 +452,25 @@ module BTC
452
452
  end
453
453
  end
454
454
  end
455
-
455
+
456
+ # BIP44 Support
457
+
458
+ def bip44_keychain(network: Network.mainnet)
459
+ network_index = network.mainnet? ? 0 : 1
460
+ derived_keychain(44, hardened: true).derived_keychain(network_index, hardened: true)
461
+ end
462
+
463
+ def bip44_account_keychain(account_index)
464
+ derived_keychain(account_index, hardened: true)
465
+ end
466
+
467
+ def bip44_external_keychain
468
+ derived_keychain(0, hardened: false)
469
+ end
470
+
471
+ def bip44_internal_keychain
472
+ derived_keychain(1, hardened: false)
473
+ end
474
+
456
475
  end # Keychain
457
476
  end # BTC
@@ -0,0 +1,65 @@
1
+ # BTC::Mnemonic implements BIP44: mnemonic-based hierarchical deterministic wallets.
2
+ # Currently only supports restoring keychain from words. Generating sentence.
3
+ require 'openssl'
4
+ require 'openssl/digest'
5
+ module BTC
6
+ class Mnemonic
7
+
8
+ def initialize(words: nil, password: "")
9
+ if words.is_a?(String)
10
+ words = words.split(" ")
11
+ end
12
+ # TODO: check if number of words is correct (12, 15, 18, 21, 24)
13
+ @words = words
14
+ @password = password
15
+ end
16
+
17
+ def seed
18
+ @seed ||= make_seed(words: @words, password: @password)
19
+ end
20
+
21
+ def keychain
22
+ @keychain ||= Keychain.new(seed: seed)
23
+ end
24
+
25
+ private
26
+
27
+ def make_seed(words: nil, password: nil)
28
+ password ||= ""
29
+
30
+ mnemonic = @words.join(" ").b
31
+ salt = "mnemonic#{password}".b
32
+
33
+ digest = ::OpenSSL::Digest::SHA512.new
34
+ length = digest.digest_length
35
+
36
+ return ::OpenSSL::PKCS5.pbkdf2_hmac(
37
+ mnemonic,
38
+ salt,
39
+ 2048, # iterations
40
+ length,
41
+ digest
42
+ )
43
+ end
44
+
45
+ public
46
+
47
+ # For manual testing
48
+
49
+ def print_addresses(range: 0..100, network: BTC::Network.mainnet, account: 0)
50
+ kc = keychain.bip44_keychain(network: network).bip44_account_keychain(account)
51
+ puts "Addresses for account #{account} on #{network.name}"
52
+ puts "Account xpub: #{kc.xpub}"
53
+ puts "Account external xpub: #{kc.bip44_external_keychain.xpub}"
54
+ puts "Index".ljust(10) + "External Address".ljust(40) + "Internal Address".ljust(40)
55
+ range.each do |i|
56
+ s = ""
57
+ s << "#{i}".ljust(10)
58
+ s << kc.bip44_external_keychain.derived_key(i).address.to_s.ljust(40)
59
+ s << kc.bip44_internal_keychain.derived_key(i).address.to_s.ljust(40)
60
+ puts s
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module BTC
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.6".freeze
3
3
  end
@@ -0,0 +1,89 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe BTC::Mnemonic, "standard test vectors" do
4
+
5
+ [
6
+ [
7
+ "00000000000000000000000000000000",
8
+ "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
9
+ "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04"
10
+ ],
11
+ ["7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
12
+ "legal winner thank year wave sausage worth useful legal winner thank yellow",
13
+ "2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607"],
14
+ ["80808080808080808080808080808080",
15
+ "letter advice cage absurd amount doctor acoustic avoid letter advice cage above",
16
+ "d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8"],
17
+ ["ffffffffffffffffffffffffffffffff",
18
+ "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",
19
+ "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069"],
20
+ ["000000000000000000000000000000000000000000000000",
21
+ "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent",
22
+ "035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa"],
23
+ ["7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
24
+ "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will",
25
+ "f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd"],
26
+ ["808080808080808080808080808080808080808080808080",
27
+ "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always",
28
+ "107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65"],
29
+ ["ffffffffffffffffffffffffffffffffffffffffffffffff",
30
+ "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when",
31
+ "0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528"],
32
+ ["0000000000000000000000000000000000000000000000000000000000000000",
33
+ "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
34
+ "bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8"],
35
+ ["7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
36
+ "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title",
37
+ "bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87"],
38
+ ["8080808080808080808080808080808080808080808080808080808080808080",
39
+ "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless",
40
+ "c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f"],
41
+ ["ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
42
+ "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote",
43
+ "dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad"],
44
+ ["77c2b00716cec7213839159e404db50d",
45
+ "jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge",
46
+ "b5b6d0127db1a9d2226af0c3346031d77af31e918dba64287a1b44b8ebf63cdd52676f672a290aae502472cf2d602c051f3e6f18055e84e4c43897fc4e51a6ff"],
47
+ ["b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b",
48
+ "renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap",
49
+ "9248d83e06f4cd98debf5b6f010542760df925ce46cf38a1bdb4e4de7d21f5c39366941c69e1bdbf2966e0f6e6dbece898a0e2f0a4c2b3e640953dfe8b7bbdc5"],
50
+ ["3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982",
51
+ "dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic",
52
+ "ff7f3184df8696d8bef94b6c03114dbee0ef89ff938712301d27ed8336ca89ef9635da20af07d4175f2bf5f3de130f39c9d9e8dd0472489c19b1a020a940da67"],
53
+ ["0460ef47585604c5660618db2e6a7e7f",
54
+ "afford alter spike radar gate glance object seek swamp infant panel yellow",
55
+ "65f93a9f36b6c85cbe634ffc1f99f2b82cbb10b31edc7f087b4f6cb9e976e9faf76ff41f8f27c99afdf38f7a303ba1136ee48a4c1e7fcd3dba7aa876113a36e4"],
56
+ ["72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f",
57
+ "indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left",
58
+ "3bbf9daa0dfad8229786ace5ddb4e00fa98a044ae4c4975ffd5e094dba9e0bb289349dbe2091761f30f382d4e35c4a670ee8ab50758d2c55881be69e327117ba"],
59
+ ["2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416",
60
+ "clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste",
61
+ "fe908f96f46668b2d5b37d82f558c77ed0d69dd0e7e043a5b0511c48c2f1064694a956f86360c93dd04052a8899497ce9e985ebe0c8c52b955e6ae86d4ff4449"],
62
+ ["eaebabb2383351fd31d703840b32e9e2",
63
+ "turtle front uncle idea crush write shrug there lottery flower risk shell",
64
+ "bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c"],
65
+ ["7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78",
66
+ "kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment",
67
+ "ed56ff6c833c07982eb7119a8f48fd363c4a9b1601cd2de736b01045c5eb8ab4f57b079403485d1c4924f0790dc10a971763337cb9f9c62226f64fff26397c79"],
68
+ ["4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef",
69
+ "exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top",
70
+ "095ee6f817b4c2cb30a5a797360a81a40ab0f9a4e25ecd672a3f58a0b5ba0687c096a6b14d2c0deb3bdefce4f61d01ae07417d502429352e27695163f7447a8c"],
71
+ ["18ab19a9f54a9274f03e5209a2ac8a91",
72
+ "board flee heavy tunnel powder denial science ski answer betray cargo cat",
73
+ "6eff1bb21562918509c73cb990260db07c0ce34ff0e3cc4a8cb3276129fbcb300bddfe005831350efd633909f476c45c88253276d9fd0df6ef48609e8bb7dca8"],
74
+ ["18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4",
75
+ "board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief",
76
+ "f84521c777a13b61564234bf8f8b62b3afce27fc4062b51bb5e62bdfecb23864ee6ecf07c1d5a97c0834307c5c852d8ceb88e7c97923c0a3b496bedd4e5f88a9"],
77
+ ["15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419",
78
+ "beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut",
79
+ "b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd"]
80
+ ].each do |vector|
81
+ it "should support test vector" do
82
+ entropy = vector[0].from_hex
83
+ words = vector[1]
84
+ seed = vector[2].from_hex
85
+ mnemonic = BTC::Mnemonic.new(words: words, password: "TREZOR")
86
+ mnemonic.seed.to_hex.must_equal seed.to_hex
87
+ end
88
+ end
89
+ end
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.5.1
4
+ version: '1.6'
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-12-30 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -84,6 +84,7 @@ files:
84
84
  - lib/btcruby/key.rb
85
85
  - lib/btcruby/keychain.rb
86
86
  - lib/btcruby/merkle_tree.rb
87
+ - lib/btcruby/mnemonic.rb
87
88
  - lib/btcruby/network.rb
88
89
  - lib/btcruby/open_assets.rb
89
90
  - lib/btcruby/open_assets/asset.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/key_spec.rb
148
149
  - spec/keychain_spec.rb
149
150
  - spec/merkle_tree_spec.rb
151
+ - spec/mnemonic_spec.rb
150
152
  - spec/network_spec.rb
151
153
  - spec/open_assets/asset_address_spec.rb
152
154
  - spec/open_assets/asset_id_spec.rb
@@ -200,6 +202,7 @@ test_files:
200
202
  - spec/key_spec.rb
201
203
  - spec/keychain_spec.rb
202
204
  - spec/merkle_tree_spec.rb
205
+ - spec/mnemonic_spec.rb
203
206
  - spec/network_spec.rb
204
207
  - spec/open_assets/asset_address_spec.rb
205
208
  - spec/open_assets/asset_id_spec.rb