bitcoin-ruby 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +46 -0
- data/.travis.yml +5 -1
- data/Gemfile +11 -9
- data/Gemfile.lock +64 -12
- data/README.rdoc +17 -4
- data/Rakefile +58 -83
- data/bitcoin-ruby.gemspec +5 -2
- data/lib/bitcoin.rb +31 -14
- data/lib/bitcoin/bech32.rb +126 -132
- data/lib/bitcoin/bloom_filter.rb +24 -21
- data/lib/bitcoin/builder.rb +168 -126
- data/lib/bitcoin/connection.rb +21 -24
- data/lib/bitcoin/contracthash.rb +20 -24
- data/lib/bitcoin/dogecoin.rb +79 -77
- data/lib/bitcoin/electrum/mnemonic.rb +28 -25
- data/lib/bitcoin/ext_key.rb +3 -3
- data/lib/bitcoin/ffi/bitcoinconsensus.rb +17 -13
- data/lib/bitcoin/ffi/openssl.rb +355 -338
- data/lib/bitcoin/ffi/secp256k1.rb +97 -64
- data/lib/bitcoin/protocol.rb +6 -3
- data/lib/bitcoin/protocol/address.rb +15 -13
- data/lib/bitcoin/protocol/aux_pow.rb +12 -15
- data/lib/bitcoin/protocol/block.rb +102 -76
- data/lib/bitcoin/protocol/handler.rb +2 -4
- data/lib/bitcoin/protocol/parser.rb +108 -92
- data/lib/bitcoin/protocol/partial_merkle_tree.rb +59 -47
- data/lib/bitcoin/protocol/reject.rb +26 -28
- data/lib/bitcoin/protocol/script_witness.rb +3 -8
- data/lib/bitcoin/protocol/tx.rb +250 -137
- data/lib/bitcoin/protocol/txin.rb +44 -38
- data/lib/bitcoin/protocol/txout.rb +27 -20
- data/lib/bitcoin/protocol/version.rb +47 -34
- data/lib/bitcoin/script.rb +18 -17
- data/lib/bitcoin/trezor/mnemonic.rb +113 -98
- data/lib/bitcoin/version.rb +1 -1
- data/spec/examples.txt +399 -0
- data/spec/{bitcoin/fixtures → fixtures}/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/base58_keys_invalid.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/base58_keys_valid.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/coinbase-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/coinbase.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/filteredblock-0.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-170.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-9.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-auxpow.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-1151351.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-265322.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-04.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-05.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/script_tests.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/sighash.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +0 -0
- data/spec/helpers/block_helpers.rb +58 -0
- data/spec/helpers/fixture_helpers.rb +20 -0
- data/spec/helpers/library_helpers.rb +15 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/unit/bitcoin/bech32_spec.rb +187 -0
- data/spec/unit/bitcoin/bitcoin_spec.rb +1079 -0
- data/spec/unit/bitcoin/bloom_filter_spec.rb +33 -0
- data/spec/unit/bitcoin/builder_spec.rb +559 -0
- data/spec/unit/bitcoin/contracthash_spec.rb +52 -0
- data/spec/unit/bitcoin/ext_key_spec.rb +281 -0
- data/spec/unit/bitcoin/key_spec.rb +457 -0
- data/spec/unit/bitcoin/network_spec.rb +71 -0
- data/spec/unit/bitcoin/protocol/addr_spec.rb +90 -0
- data/spec/unit/bitcoin/protocol/aux_pow_spec.rb +45 -0
- data/spec/unit/bitcoin/protocol/bip143_spec.rb +334 -0
- data/spec/unit/bitcoin/protocol/block_spec.rb +280 -0
- data/spec/unit/bitcoin/protocol/getblocks_spec.rb +44 -0
- data/spec/unit/bitcoin/protocol/inv_spec.rb +166 -0
- data/spec/unit/bitcoin/protocol/notfound_spec.rb +44 -0
- data/spec/unit/bitcoin/protocol/parser_spec.rb +69 -0
- data/spec/unit/bitcoin/protocol/partial_merkle_tree_spec.rb +47 -0
- data/spec/unit/bitcoin/protocol/ping_spec.rb +62 -0
- data/spec/unit/bitcoin/protocol/tx_spec.rb +1515 -0
- data/spec/unit/bitcoin/protocol/txin_spec.rb +47 -0
- data/spec/unit/bitcoin/protocol/txout_spec.rb +36 -0
- data/spec/unit/bitcoin/protocol/version_spec.rb +121 -0
- data/spec/unit/bitcoin/script/opcodes_spec.rb +864 -0
- data/spec/unit/bitcoin/script/script_spec.rb +1610 -0
- data/spec/unit/bitcoin/secp256k1_spec.rb +138 -0
- data/spec/unit/bitcoin/trezor/mnemonic_spec.rb +193 -0
- data/spec/unit/integrations/dogecoin_spec.rb +215 -0
- metadata +381 -372
- data/lib/bitcoin/logger.rb +0 -86
- data/lib/bitcoin/protocol/alert.rb +0 -46
- data/spec/bitcoin/bech32_spec.rb +0 -160
- data/spec/bitcoin/bitcoin_spec.rb +0 -666
- data/spec/bitcoin/bloom_filter_spec.rb +0 -23
- data/spec/bitcoin/builder_spec.rb +0 -375
- data/spec/bitcoin/contracthash_spec.rb +0 -45
- data/spec/bitcoin/dogecoin_spec.rb +0 -176
- data/spec/bitcoin/ext_key_spec.rb +0 -180
- data/spec/bitcoin/ffi_openssl.rb +0 -45
- data/spec/bitcoin/fixtures/rawblock-170.json +0 -68
- data/spec/bitcoin/fixtures/rawblock-9.json +0 -39
- data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
- data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
- data/spec/bitcoin/fixtures/txdp-1.txt +0 -32
- data/spec/bitcoin/fixtures/txdp-2-signed.txt +0 -19
- data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +0 -14
- data/spec/bitcoin/helpers/fake_blockchain.rb +0 -183
- data/spec/bitcoin/key_spec.rb +0 -326
- data/spec/bitcoin/network_spec.rb +0 -50
- data/spec/bitcoin/performance/storage_spec.rb +0 -41
- data/spec/bitcoin/protocol/addr_spec.rb +0 -82
- data/spec/bitcoin/protocol/alert_spec.rb +0 -22
- data/spec/bitcoin/protocol/aux_pow_spec.rb +0 -45
- data/spec/bitcoin/protocol/bip143_spec.rb +0 -116
- data/spec/bitcoin/protocol/block_spec.rb +0 -208
- data/spec/bitcoin/protocol/getblocks_spec.rb +0 -32
- data/spec/bitcoin/protocol/inv_spec.rb +0 -134
- data/spec/bitcoin/protocol/notfound_spec.rb +0 -31
- data/spec/bitcoin/protocol/parser_spec.rb +0 -50
- data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +0 -38
- data/spec/bitcoin/protocol/ping_spec.rb +0 -51
- data/spec/bitcoin/protocol/reject.rb +0 -17
- data/spec/bitcoin/protocol/tx_spec.rb +0 -894
- data/spec/bitcoin/protocol/txin_spec.rb +0 -45
- data/spec/bitcoin/protocol/txout_spec.rb +0 -33
- data/spec/bitcoin/protocol/version_spec.rb +0 -110
- data/spec/bitcoin/script/opcodes_spec.rb +0 -773
- data/spec/bitcoin/script/script_spec.rb +0 -977
- data/spec/bitcoin/secp256k1_spec.rb +0 -78
- data/spec/bitcoin/spec_helper.rb +0 -108
- data/spec/bitcoin/trezor/mnemonic_spec.rb +0 -161
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Bitcoin::Secp256k1 do
|
6
|
+
let(:fixture_text) { 'bitcoin-ruby-test-data' }
|
7
|
+
|
8
|
+
describe '#generate_key_pair' do
|
9
|
+
it 'generates a compressed key pair' do
|
10
|
+
private_key, public_key =
|
11
|
+
Bitcoin::Secp256k1.generate_key_pair(true)
|
12
|
+
|
13
|
+
expect(private_key.bytesize).to eq(32)
|
14
|
+
expect(public_key.bytesize).to eq(33)
|
15
|
+
expect(["\x03", "\x02"]).to include(public_key[0])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'generates an uncompressed key pair' do
|
19
|
+
private_key, public_key =
|
20
|
+
Bitcoin::Secp256k1.generate_key_pair(false)
|
21
|
+
|
22
|
+
expect(private_key.bytesize).to eq(32)
|
23
|
+
expect(public_key.bytesize).to eq(65)
|
24
|
+
expect(public_key[0]).to eq("\x04")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#generate_key' do
|
29
|
+
it 'generates a compressed key' do
|
30
|
+
key = Bitcoin::Secp256k1.generate_key(true)
|
31
|
+
expect(key.compressed).to be true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'generates an uncompressed key' do
|
35
|
+
key = Bitcoin::Secp256k1.generate_key(false)
|
36
|
+
expect(key.compressed).to be false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#sign' do
|
41
|
+
it 'successfully signs and verifies text' do
|
42
|
+
private_key, public_key = Bitcoin::Secp256k1.generate_key_pair
|
43
|
+
signature = Bitcoin::Secp256k1.sign(fixture_text, private_key)
|
44
|
+
|
45
|
+
expect(
|
46
|
+
Bitcoin::Secp256k1.verify(fixture_text, signature, public_key)
|
47
|
+
).to be true
|
48
|
+
expect(
|
49
|
+
Bitcoin::Secp256k1.verify(fixture_text.upcase, signature, public_key)
|
50
|
+
).to be false
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'supports RFC6979 deterministic signatures' do
|
54
|
+
private_key, = Bitcoin::Secp256k1.generate_key_pair
|
55
|
+
first = Bitcoin::Secp256k1.sign(fixture_text, private_key)
|
56
|
+
second = Bitcoin::Secp256k1.sign(fixture_text, private_key)
|
57
|
+
expect(first).to eq(second)
|
58
|
+
|
59
|
+
private_key, = Bitcoin::Secp256k1.generate_key_pair
|
60
|
+
second = Bitcoin::Secp256k1.sign(fixture_text, private_key)
|
61
|
+
expect(first).not_to eq(second)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#sign_compact' do
|
66
|
+
it 'signs and recovers with compressed keys' do
|
67
|
+
private_key, public_key = Bitcoin::Secp256k1.generate_key_pair(true)
|
68
|
+
|
69
|
+
signature = Bitcoin::Secp256k1.sign_compact(
|
70
|
+
fixture_text, private_key, true
|
71
|
+
)
|
72
|
+
expect(signature.bytesize).to eq(65)
|
73
|
+
|
74
|
+
recovered_public_key = Bitcoin::Secp256k1.recover_compact(
|
75
|
+
fixture_text, signature
|
76
|
+
)
|
77
|
+
expect(recovered_public_key.bytesize).to eq(33)
|
78
|
+
expect(recovered_public_key).to eq(public_key)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'signs and recovers with uncompressed keys' do
|
82
|
+
private_key, public_key = Bitcoin::Secp256k1.generate_key_pair(false)
|
83
|
+
signature = Bitcoin::Secp256k1.sign_compact(
|
84
|
+
fixture_text, private_key, false
|
85
|
+
)
|
86
|
+
expect(signature.bytesize).to eq(65)
|
87
|
+
|
88
|
+
recovered_public_key = Bitcoin::Secp256k1.recover_compact(
|
89
|
+
fixture_text, signature
|
90
|
+
)
|
91
|
+
|
92
|
+
expect(recovered_public_key.bytesize).to eq(65)
|
93
|
+
expect(recovered_public_key).to eq(public_key)
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when compared to OpenSSL' do
|
97
|
+
let(:message) { 'hello world' }
|
98
|
+
|
99
|
+
it 'has matching signing and recovery results' do
|
100
|
+
key = Bitcoin::Key.new(
|
101
|
+
'82a0c421a0f67c7a88a329b2c15f2849aa1c8cfa9c9a6513f056f80ee8eaacc4',
|
102
|
+
nil,
|
103
|
+
false
|
104
|
+
)
|
105
|
+
|
106
|
+
expect(key.pub)
|
107
|
+
.to eq('0490b0854581a291b83c1945775f156da22445df99e445581321ac3aa62' \
|
108
|
+
'535ff369334316dfd157acc7bb2e4d3eb85951f6d1b7f62f6f60a09e0db' \
|
109
|
+
'd5c87d3ffae9')
|
110
|
+
|
111
|
+
private_key_binary = [key.priv].pack('H*')
|
112
|
+
|
113
|
+
openssl_signature = Bitcoin::OpenSSL_EC.sign_compact(
|
114
|
+
message, private_key_binary, nil, false
|
115
|
+
)
|
116
|
+
libsecp_signature = Bitcoin::Secp256k1.sign_compact(
|
117
|
+
message, private_key_binary, false
|
118
|
+
)
|
119
|
+
|
120
|
+
expect(
|
121
|
+
Bitcoin::OpenSSL_EC.recover_compact(message, openssl_signature)
|
122
|
+
).to eq(key.pub)
|
123
|
+
expect(
|
124
|
+
Bitcoin::Secp256k1.recover_compact(message, openssl_signature)
|
125
|
+
.unpack('H*')[0]
|
126
|
+
).to eq(key.pub)
|
127
|
+
|
128
|
+
expect(
|
129
|
+
Bitcoin::OpenSSL_EC.recover_compact(message, libsecp_signature)
|
130
|
+
).to eq(key.pub)
|
131
|
+
expect(
|
132
|
+
Bitcoin::Secp256k1.recover_compact(message, libsecp_signature)
|
133
|
+
.unpack('H*')[0]
|
134
|
+
).to eq(key.pub)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe 'Bitcoin::Trezor::Mnemonic' do
|
7
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#Test_vectors
|
8
|
+
# https://github.com/trezor/python-mnemonic/blob/master/vectors.json
|
9
|
+
it 'test vectors' do
|
10
|
+
[
|
11
|
+
[
|
12
|
+
'00000000000000000000000000000000',
|
13
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon ' \
|
14
|
+
'abandon abandon abandon about',
|
15
|
+
'c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e5349553' \
|
16
|
+
'1f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04'
|
17
|
+
],
|
18
|
+
[
|
19
|
+
'7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f',
|
20
|
+
'legal winner thank year wave sausage worth useful legal winner ' \
|
21
|
+
'thank yellow',
|
22
|
+
'2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa4' \
|
23
|
+
'57fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607'
|
24
|
+
],
|
25
|
+
[
|
26
|
+
'80808080808080808080808080808080',
|
27
|
+
'letter advice cage absurd amount doctor acoustic avoid letter ' \
|
28
|
+
'advice cage above',
|
29
|
+
'd71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30f' \
|
30
|
+
'a280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8'
|
31
|
+
],
|
32
|
+
[
|
33
|
+
'ffffffffffffffffffffffffffffffff',
|
34
|
+
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
|
35
|
+
'ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a1333' \
|
36
|
+
'2572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069'
|
37
|
+
],
|
38
|
+
[
|
39
|
+
'000000000000000000000000000000000000000000000000',
|
40
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon ' \
|
41
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon ' \
|
42
|
+
'abandon agent',
|
43
|
+
'035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06' \
|
44
|
+
'da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa'
|
45
|
+
],
|
46
|
+
[
|
47
|
+
'7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f',
|
48
|
+
'legal winner thank year wave sausage worth useful legal winner ' \
|
49
|
+
'thank year wave sausage worth useful legal will',
|
50
|
+
'f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c' \
|
51
|
+
'7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd'
|
52
|
+
],
|
53
|
+
[
|
54
|
+
'808080808080808080808080808080808080808080808080',
|
55
|
+
'letter advice cage absurd amount doctor acoustic avoid letter ' \
|
56
|
+
'advice cage absurd amount doctor acoustic avoid letter always',
|
57
|
+
'107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27' \
|
58
|
+
'fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65'
|
59
|
+
],
|
60
|
+
[
|
61
|
+
'ffffffffffffffffffffffffffffffffffffffffffffffff',
|
62
|
+
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo ' \
|
63
|
+
'zoo when',
|
64
|
+
'0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76' \
|
65
|
+
'379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528'
|
66
|
+
],
|
67
|
+
[
|
68
|
+
'0000000000000000000000000000000000000000000000000000000000000000',
|
69
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon ' \
|
70
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon ' \
|
71
|
+
'abandon abandon abandon abandon abandon abandon abandon art',
|
72
|
+
'bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170' \
|
73
|
+
'af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8'
|
74
|
+
],
|
75
|
+
[
|
76
|
+
'7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f',
|
77
|
+
'legal winner thank year wave sausage worth useful legal winner ' \
|
78
|
+
'thank year wave sausage worth useful legal winner thank year wave ' \
|
79
|
+
'sausage worth title',
|
80
|
+
'bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021' \
|
81
|
+
'b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87'
|
82
|
+
],
|
83
|
+
[
|
84
|
+
'8080808080808080808080808080808080808080808080808080808080808080',
|
85
|
+
'letter advice cage absurd amount doctor acoustic avoid letter ' \
|
86
|
+
'advice cage absurd amount doctor acoustic avoid letter advice ' \
|
87
|
+
'cage absurd amount doctor acoustic bless',
|
88
|
+
'c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e' \
|
89
|
+
'2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f'
|
90
|
+
],
|
91
|
+
[
|
92
|
+
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
93
|
+
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo ' \
|
94
|
+
'zoo zoo zoo zoo zoo zoo zoo vote',
|
95
|
+
'dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613' \
|
96
|
+
'912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad'
|
97
|
+
],
|
98
|
+
[
|
99
|
+
'77c2b00716cec7213839159e404db50d',
|
100
|
+
'jelly better achieve collect unaware mountain thought cargo ' \
|
101
|
+
'oxygen act hood bridge',
|
102
|
+
'b5b6d0127db1a9d2226af0c3346031d77af31e918dba64287a1b44b8ebf63cdd52' \
|
103
|
+
'676f672a290aae502472cf2d602c051f3e6f18055e84e4c43897fc4e51a6ff'
|
104
|
+
],
|
105
|
+
[
|
106
|
+
'b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b',
|
107
|
+
'renew stay biology evidence goat welcome casual join adapt armor ' \
|
108
|
+
'shuffle fault little machine walk stumble urge swap',
|
109
|
+
'9248d83e06f4cd98debf5b6f010542760df925ce46cf38a1bdb4e4de7d21f5c393' \
|
110
|
+
'66941c69e1bdbf2966e0f6e6dbece898a0e2f0a4c2b3e640953dfe8b7bbdc5'
|
111
|
+
],
|
112
|
+
[
|
113
|
+
'3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982',
|
114
|
+
'dignity pass list indicate nasty swamp pool script soccer toe ' \
|
115
|
+
'leaf photo multiply desk host tomato cradle drill spread actor ' \
|
116
|
+
'shine dismiss champion exotic',
|
117
|
+
'ff7f3184df8696d8bef94b6c03114dbee0ef89ff938712301d27ed8336ca89ef9' \
|
118
|
+
'635da20af07d4175f2bf5f3de130f39c9d9e8dd0472489c19b1a020a940da67'
|
119
|
+
],
|
120
|
+
[
|
121
|
+
'0460ef47585604c5660618db2e6a7e7f',
|
122
|
+
'afford alter spike radar gate glance object seek swamp infant ' \
|
123
|
+
'panel yellow',
|
124
|
+
'65f93a9f36b6c85cbe634ffc1f99f2b82cbb10b31edc7f087b4f6cb9e976e9faf' \
|
125
|
+
'76ff41f8f27c99afdf38f7a303ba1136ee48a4c1e7fcd3dba7aa876113a36e4'
|
126
|
+
],
|
127
|
+
[
|
128
|
+
'72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f',
|
129
|
+
'indicate race push merry suffer human cruise dwarf pole review ' \
|
130
|
+
'arch keep canvas theme poem divorce alter left',
|
131
|
+
'3bbf9daa0dfad8229786ace5ddb4e00fa98a044ae4c4975ffd5e094dba9e0bb289' \
|
132
|
+
'349dbe2091761f30f382d4e35c4a670ee8ab50758d2c55881be69e327117ba'
|
133
|
+
],
|
134
|
+
[
|
135
|
+
'2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416',
|
136
|
+
'clutch control vehicle tonight unusual clog visa ice plunge ' \
|
137
|
+
'glimpse recipe series open hour vintage deposit universe tip ' \
|
138
|
+
'job dress radar refuse motion taste',
|
139
|
+
'fe908f96f46668b2d5b37d82f558c77ed0d69dd0e7e043a5b0511c48c2f106469' \
|
140
|
+
'4a956f86360c93dd04052a8899497ce9e985ebe0c8c52b955e6ae86d4ff4449'
|
141
|
+
],
|
142
|
+
[
|
143
|
+
'eaebabb2383351fd31d703840b32e9e2',
|
144
|
+
'turtle front uncle idea crush write shrug there lottery flower ' \
|
145
|
+
'risk shell',
|
146
|
+
'bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42' \
|
147
|
+
'a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c'
|
148
|
+
],
|
149
|
+
[
|
150
|
+
'7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78',
|
151
|
+
'kiss carry display unusual confirm curtain upgrade antique ' \
|
152
|
+
'rotate hello void custom frequent obey nut hole price segment',
|
153
|
+
'ed56ff6c833c07982eb7119a8f48fd363c4a9b1601cd2de736b01045c5eb8ab4' \
|
154
|
+
'f57b079403485d1c4924f0790dc10a971763337cb9f9c62226f64fff26397c79'
|
155
|
+
],
|
156
|
+
[
|
157
|
+
'4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef',
|
158
|
+
'exile ask congress lamp submit jacket era scheme attend cousin ' \
|
159
|
+
'alcohol catch course end lucky hurt sentence oven short ball ' \
|
160
|
+
'bird grab wing top',
|
161
|
+
'095ee6f817b4c2cb30a5a797360a81a40ab0f9a4e25ecd672a3f58a0b5ba0687c0' \
|
162
|
+
'96a6b14d2c0deb3bdefce4f61d01ae07417d502429352e27695163f7447a8c'
|
163
|
+
],
|
164
|
+
[
|
165
|
+
'18ab19a9f54a9274f03e5209a2ac8a91',
|
166
|
+
'board flee heavy tunnel powder denial science ski answer betray ' \
|
167
|
+
'cargo cat',
|
168
|
+
'6eff1bb21562918509c73cb990260db07c0ce34ff0e3cc4a8cb3276129fbcb300' \
|
169
|
+
'bddfe005831350efd633909f476c45c88253276d9fd0df6ef48609e8bb7dca8'
|
170
|
+
],
|
171
|
+
[
|
172
|
+
'18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4',
|
173
|
+
'board blade invite damage undo sun mimic interest slam gaze ' \
|
174
|
+
'truly inherit resist great inject rocket museum chief',
|
175
|
+
'f84521c777a13b61564234bf8f8b62b3afce27fc4062b51bb5e62bdfecb23864e' \
|
176
|
+
'e6ecf07c1d5a97c0834307c5c852d8ceb88e7c97923c0a3b496bedd4e5f88a9'
|
177
|
+
],
|
178
|
+
[
|
179
|
+
'15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419',
|
180
|
+
'beyond stage sleep clip because twist token leaf atom beauty ' \
|
181
|
+
'genius food business side grid unable middle armed observe pair ' \
|
182
|
+
'crouch tonight away coconut',
|
183
|
+
'b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65' \
|
184
|
+
'101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd'
|
185
|
+
]
|
186
|
+
].each do |data, expected_mnemonic, expected_seed|
|
187
|
+
mnemonic = Bitcoin::Trezor::Mnemonic.to_mnemonic([data].pack('H*'))
|
188
|
+
expect(mnemonic).to eq(expected_mnemonic)
|
189
|
+
expect(Bitcoin::Trezor::Mnemonic.to_seed(expected_mnemonic, 'TREZOR'))
|
190
|
+
.to eq(expected_seed)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Bitcoin::Dogecoin do
|
7
|
+
it 'validate dogecoin-address' do
|
8
|
+
Bitcoin.network = :dogecoin_testnet
|
9
|
+
|
10
|
+
# Testnet address
|
11
|
+
expect(Bitcoin.valid_address?('nUtMFED5VRg5xuj9QCrNFt9mVPFDXo7TTE'))
|
12
|
+
.to be true
|
13
|
+
# Livenet address
|
14
|
+
expect(Bitcoin.valid_address?('DSpgzjPyfQB6ZzeSbMWpaZiTTxGf2oBCs4'))
|
15
|
+
.to be false
|
16
|
+
# Broken address
|
17
|
+
expect(Bitcoin.valid_address?('DRjyUS2uuieEPkhZNdQz8hE5YycxVEqSXA'))
|
18
|
+
.to be false
|
19
|
+
|
20
|
+
Bitcoin.network = :dogecoin
|
21
|
+
|
22
|
+
# Testnet address
|
23
|
+
expect(Bitcoin.valid_address?('nUtMFED5VRg5xuj9QCrNFt9mVPFDXo7TTE'))
|
24
|
+
.to be false
|
25
|
+
# Livenet address
|
26
|
+
expect(Bitcoin.valid_address?('DSpgzjPyfQB6ZzeSbMWpaZiTTxGf2oBCs4'))
|
27
|
+
.to be true
|
28
|
+
# Broken address
|
29
|
+
expect(Bitcoin.valid_address?('DRjyUS2uuieEPkhZNdQz8hE5YycxVEqSXA'))
|
30
|
+
.to be false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should calculate retarget difficulty' do
|
34
|
+
Bitcoin.network = :dogecoin
|
35
|
+
|
36
|
+
prev_height = 239
|
37
|
+
prev_block_time = 1_386_475_638 # Block 239
|
38
|
+
prev_block_bits = 0x1e0ffff0
|
39
|
+
last_retarget_time = 1_386_474_927 # Block 1
|
40
|
+
new_difficulty = Bitcoin.block_new_target(
|
41
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
42
|
+
)
|
43
|
+
expect(new_difficulty.to_s(16)).to eq(0x1e00ffff.to_s(16))
|
44
|
+
|
45
|
+
prev_height = 479
|
46
|
+
prev_block_time = 1_386_475_840
|
47
|
+
prev_block_bits = 0x1e0fffff
|
48
|
+
last_retarget_time = 1_386_475_638 # Block 239
|
49
|
+
new_difficulty = Bitcoin.block_new_target(
|
50
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
51
|
+
)
|
52
|
+
expect(new_difficulty.to_s(16)).to eq(0x1e00ffff.to_s(16))
|
53
|
+
|
54
|
+
prev_height = 9_599
|
55
|
+
prev_block_time = 1_386_954_113
|
56
|
+
prev_block_bits = 0x1c1a1206
|
57
|
+
last_retarget_time = 1_386_942_008 # Block 9359
|
58
|
+
new_difficulty = Bitcoin.block_new_target(
|
59
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
60
|
+
)
|
61
|
+
expect(new_difficulty.to_s(16)).to eq(0x1c15ea59.to_s(16))
|
62
|
+
|
63
|
+
# First hard-fork at 145,000, which applies to block 145,001 onwards
|
64
|
+
prev_height = 145_000
|
65
|
+
prev_block_time = 1_395_094_679
|
66
|
+
prev_block_bits = 0x1b499dfd
|
67
|
+
last_retarget_time = 1_395_094_427
|
68
|
+
new_difficulty = Bitcoin.block_new_target(
|
69
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
70
|
+
)
|
71
|
+
expect(new_difficulty.to_s(16)).to eq(0x1b671062.to_s(16))
|
72
|
+
|
73
|
+
# Test case for correct rounding of modulated time - by default C++ and Ruby
|
74
|
+
# do not necessarily round identically
|
75
|
+
prev_height = 145_001
|
76
|
+
prev_block_time = 1_395_094_727
|
77
|
+
prev_block_bits = 0x1b671062
|
78
|
+
last_retarget_time = 1_395_094_679
|
79
|
+
new_difficulty = Bitcoin.block_new_target(
|
80
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
81
|
+
)
|
82
|
+
expect(new_difficulty.to_s(16)).to eq(0x1b6558a4.to_s(16))
|
83
|
+
|
84
|
+
# Test the second hard-fork at 371,337 as well
|
85
|
+
prev_height = 371_336
|
86
|
+
prev_block_time = 1_410_464_569
|
87
|
+
prev_block_bits = 0x1b2fdf75
|
88
|
+
last_retarget_time = 1_410_464_445
|
89
|
+
new_difficulty = Bitcoin.block_new_target(
|
90
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
91
|
+
)
|
92
|
+
expect(new_difficulty.to_s(16)).to eq(0x1b364184.to_s(16))
|
93
|
+
|
94
|
+
prev_height = 408_596
|
95
|
+
prev_block_time = 1_412_800_112
|
96
|
+
prev_block_bits = 0x1b033d8b
|
97
|
+
last_retarget_time = 1_412_799_989 # Block 408,595
|
98
|
+
new_difficulty = Bitcoin.block_new_target(
|
99
|
+
prev_height, prev_block_time, prev_block_bits, last_retarget_time
|
100
|
+
)
|
101
|
+
expect(new_difficulty.to_s(16)).to eq(0x1b039e52.to_s(16))
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should calculate reward upper bounds' do
|
105
|
+
Bitcoin.network = :dogecoin
|
106
|
+
|
107
|
+
# Note this is the maximum possible, not actual reward
|
108
|
+
expect(Bitcoin.block_creation_reward(99_000)).to eq(1_000_000 * Bitcoin::COIN)
|
109
|
+
# Hard-forked to remove random rewards
|
110
|
+
expect(Bitcoin.block_creation_reward(144_999)).to eq(500_000 * Bitcoin::COIN)
|
111
|
+
expect(Bitcoin.block_creation_reward(145_000)).to eq(250_000 * Bitcoin::COIN)
|
112
|
+
expect(Bitcoin.block_creation_reward(199_999)).to eq(250_000 * Bitcoin::COIN)
|
113
|
+
expect(Bitcoin.block_creation_reward(299_999)).to eq(125_000 * Bitcoin::COIN)
|
114
|
+
expect(Bitcoin.block_creation_reward(399_999)).to eq(62_500 * Bitcoin::COIN)
|
115
|
+
expect(Bitcoin.block_creation_reward(499_999)).to eq(31_250 * Bitcoin::COIN)
|
116
|
+
expect(Bitcoin.block_creation_reward(599_999)).to eq(15_625 * Bitcoin::COIN)
|
117
|
+
expect(Bitcoin.block_creation_reward(600_000)).to eq(10_000 * Bitcoin::COIN)
|
118
|
+
expect(Bitcoin.block_creation_reward(700_000)).to eq(10_000 * Bitcoin::COIN)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should calculate merkle root from AuxPoW transaction branch' do
|
122
|
+
# Taken directly from Dogecoin block #403,931
|
123
|
+
|
124
|
+
# Branch stored as bytes to reflect how data is stored in AuxPow class
|
125
|
+
branch = [
|
126
|
+
"\xbe\x07\x90\x78\x86\x93\x99\xfa\xcc\xaa\x76\x4c\x10\xe9\xdf\x6e\x99" \
|
127
|
+
"\x81\x70\x17\x59\xad\x18\xe1\x37\x24\xd9\xca\x58\x83\x13\x48",
|
128
|
+
"\x5f\x5b\xfb\x2c\x79\x54\x17\x78\x49\x9c\xab\x95\x6a\x10\x38\x87\x14" \
|
129
|
+
"\x7f\x2a\xb5\xd4\xa7\x17\xf3\x2f\x9e\xee\xbd\x29\xe1\xf8\x94",
|
130
|
+
"\xd8\xc6\xfe\x42\xca\x25\x07\x61\x59\xcd\x12\x1a\x5e\x20\xc4\x8c\x1b" \
|
131
|
+
"\xc5\x3a\xb9\x07\x30\x08\x3e\x44\xa3\x34\x56\x6e\xa6\xbb\xcb"
|
132
|
+
]
|
133
|
+
mrkl_index = 0
|
134
|
+
# Coinbase TX ID
|
135
|
+
target = '089b911f5e471c0e1800f3384281ebec5b372fbb6f358790a92747ade271ccdf'
|
136
|
+
expect(Bitcoin.mrkl_branch_root(branch.map(&:hth), target, mrkl_index))
|
137
|
+
.to eq('f29cd14243ed542d9a0b495efcb9feca1b208bb5b717dc5ac04f068d2fef595a')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should calculate merkle root from AuxPoW branch' do
|
141
|
+
# Taken directly from Dogecoin block #403,931
|
142
|
+
|
143
|
+
# Branch stored as bytes to reflect how data is stored in AuxPow class
|
144
|
+
aux_branch = [
|
145
|
+
"\x47\xa0\x22\x8b\x06\xc9\x36\x8f\x96\xc5\xf0\x4e\xb1\x09\xf8\x2c\xef" \
|
146
|
+
"\x36\xda\xe7\xc1\xbf\x25\x4c\x1a\x3f\x78\x61\x5e\xb0\xbe\x83",
|
147
|
+
"\xee\x67\xde\x31\x75\x76\x58\xdd\xd7\x40\x3e\x1a\x35\xd9\xc0\x6a\x5a" \
|
148
|
+
"\x13\xe6\x68\x98\x44\x3b\x45\x8c\xd6\xa7\x1b\x66\x27\x41\x6c",
|
149
|
+
"\xab\x9e\xf9\xbd\xa0\x2c\xad\x27\x90\xef\x9b\xb7\xc9\xa0\x7f\xe1\x79" \
|
150
|
+
"\x1a\x9d\x5a\xe0\x43\x09\xc0\xe9\x06\x48\x19\x19\x4c\x28\x31",
|
151
|
+
"\xff\x51\x61\x01\x80\xf6\x4d\x33\xa8\xc1\xba\x1d\xd9\xa9\xd0\x40\x48" \
|
152
|
+
"\x88\xc9\x6e\xaf\xd1\x57\x03\x64\x35\x8b\xbe\x99\x8f\x2d\xfe",
|
153
|
+
"\x9e\xe4\x18\x36\x7c\x3b\xce\x06\x5e\x7c\x01\x61\x29\x6e\xaa\x0d\x54" \
|
154
|
+
"\x96\xf9\x0f\x8b\x7b\x24\xeb\xf7\x2c\xc4\xba\xa5\x60\x9a\x1f",
|
155
|
+
"\x0b\x35\xf3\x73\x10\xe1\xde\x3f\xa4\xe1\x37\x7c\x02\x12\x62\x20\xe1" \
|
156
|
+
"\x64\xfa\x59\xec\xfe\xdc\xf4\x71\x4e\x61\xad\x74\xcc\x4b\x08"
|
157
|
+
]
|
158
|
+
aux_mrkl_index = 56
|
159
|
+
# Block hash
|
160
|
+
target = '0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609'
|
161
|
+
# Merkle root in coinbase script
|
162
|
+
expect(Bitcoin.mrkl_branch_root(aux_branch.map(&:hth), target, aux_mrkl_index))
|
163
|
+
.to eq('ce3040fdb7e37484f6a1ca4f8f5da81e6b7e404ec91102315a233e03a0c39c95')
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'parse AuxPoW' do
|
167
|
+
Bitcoin.network = :dogecoin
|
168
|
+
|
169
|
+
block_hash = '60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053'
|
170
|
+
data = fixtures_file("dogecoin-block-#{block_hash}.bin")
|
171
|
+
block = Bitcoin::Protocol::Block.new(data)
|
172
|
+
aux_pow = block.aux_pow
|
173
|
+
expect(aux_pow).not_to be_nil
|
174
|
+
expect(aux_pow.coinbase_index).to eq(0)
|
175
|
+
|
176
|
+
parent_block_merkle_root = Bitcoin.mrkl_branch_root(
|
177
|
+
aux_pow.coinbase_branch, aux_pow.coinbase_tx.hash, aux_pow.coinbase_index
|
178
|
+
)
|
179
|
+
expect(parent_block_merkle_root)
|
180
|
+
.to eq(aux_pow.parent_block.mrkl_root.reverse.unpack('H*')[0])
|
181
|
+
|
182
|
+
# Find the merged mining header in the coinbase input script
|
183
|
+
merged_mining_header = "\xfa\xbemm"
|
184
|
+
script = aux_pow.coinbase_tx.in[0].script
|
185
|
+
header_idx = script.index(merged_mining_header)
|
186
|
+
|
187
|
+
expect(header_idx).to eq(4)
|
188
|
+
chain_merkle_root = Bitcoin.mrkl_branch_root(
|
189
|
+
aux_pow.chain_branch, block_hash, aux_pow.chain_index
|
190
|
+
)
|
191
|
+
|
192
|
+
# Drop everything up to the merged mining data
|
193
|
+
script = script.slice(
|
194
|
+
header_idx + merged_mining_header.length, chain_merkle_root.length / 2 + 8
|
195
|
+
)
|
196
|
+
|
197
|
+
tx_root_hash = script.slice(0, chain_merkle_root.length / 2).unpack('H*')[0]
|
198
|
+
expect(chain_merkle_root).to eq(tx_root_hash)
|
199
|
+
|
200
|
+
merkle_branch_size = script.slice(
|
201
|
+
chain_merkle_root.length / 2, 4
|
202
|
+
).unpack('V')[0]
|
203
|
+
expect(merkle_branch_size).to eq(1 << aux_pow.chain_branch.length)
|
204
|
+
|
205
|
+
# Choose a pseudo-random slot in the chain merkle tree but have it be fixed
|
206
|
+
# for a size/nonce/chain combination.
|
207
|
+
nonce = script.slice(chain_merkle_root.length / 2 + 4, 4).unpack('V')[0]
|
208
|
+
rand = nonce
|
209
|
+
rand = rand * 1_103_515_245 + 12_345
|
210
|
+
rand += Bitcoin.network[:auxpow_chain_id]
|
211
|
+
rand = rand * 1_103_515_245 + 12_345
|
212
|
+
|
213
|
+
expect(aux_pow.chain_index).to eq(rand % merkle_branch_size)
|
214
|
+
end
|
215
|
+
end
|