lib/bitcoin.rb in bitcoin-ruby-0.0.7 vs lib/bitcoin.rb in bitcoin-ruby-0.0.8

- old
+ new

@@ -274,16 +274,27 @@ end target end def sign_data(key, data) - sig = key.dsa_sign_asn1(data) - if Script.is_low_der_signature?(sig) - sig - else - Bitcoin::OpenSSL_EC.signature_to_low_s(sig) - end + sig = nil + loop { + sig = key.dsa_sign_asn1(data) + sig = if Script.is_low_der_signature?(sig) + sig + else + Bitcoin::OpenSSL_EC.signature_to_low_s(sig) + end + + buf = sig + [Script::SIGHASH_TYPE[:all]].pack("C") # is_der_signature expects sig + sighash_type format + if Script.is_der_signature?(buf) + break + else + p ["Bitcoin#sign_data: invalid der signature generated, trying again.", data.unpack("H*")[0], sig.unpack("H*")[0]] + end + } + return sig end def verify_signature(hash, signature, public_key) key = bitcoin_elliptic_curve key.public_key = ::OpenSSL::PKey::EC::Point.from_hex(key.group, public_key) @@ -308,13 +319,17 @@ def regenerate_public_key(private_key) OpenSSL_EC.regenerate_key(private_key)[1] end def bitcoin_signed_message_hash(message) - # TODO: this will fail horribly on messages with len > 255. It's a cheap implementation of Bitcoin's CDataStream. - data = "\x18Bitcoin Signed Message:\n" + [message.bytesize].pack("C") + message - Digest::SHA256.digest(Digest::SHA256.digest(data)) + message = message.dup.force_encoding('binary') + + magic = "Bitcoin Signed Message:\n" + buf = Protocol.pack_var_int(magic.bytesize) + magic + buf << Protocol.pack_var_int(message.bytesize) + message + + Digest::SHA256.digest(Digest::SHA256.digest(buf)) end def sign_message(private_key_hex, public_key_hex, message) hash = bitcoin_signed_message_hash(message) signature = OpenSSL_EC.sign_compact(hash, private_key_hex, public_key_hex) @@ -550,24 +565,27 @@ min_tx_fee: 10_000, min_relay_tx_fee: 10_000, free_tx_bytes: 1_000, dust: CENT, per_dust_fee: false, + bip34_height: 227931, dns_seeds: [ "seed.bitcoin.sipa.be", "dnsseed.bluematt.me", "dnsseed.bitcoin.dashjr.org", "bitseed.xf2.org", + "dnsseed.webbtc.com", ], genesis_hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", proof_of_work_limit: 0x1d00ffff, alert_pubkeys: ["04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"], known_nodes: [ 'relay.eligius.st', 'mining.bitcoin.cz', 'blockchain.info', 'blockexplorer.com', + 'webbtc.com', ], checkpoints: { 11111 => "0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d", 33333 => "000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6", 74000 => "0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20", @@ -591,10 +609,11 @@ p2sh_version: "c4", privkey_version: "ef", extended_privkey_version: "04358394", extended_pubkey_version: "043587cf", default_port: 18333, + bip34_height: 21111, dns_seeds: [ ], genesis_hash: "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008", proof_of_work_limit: 0x1d07fff8, alert_pubkeys: ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"], known_nodes: [], @@ -602,11 +621,12 @@ }) NETWORKS[:regtest] = NETWORKS[:testnet].merge({ default_port: 18444, genesis_hash: "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", - proof_of_work_limit: (1 << 255) - 1, + proof_of_work_limit: 0x207fffff, + bip34_height: 0, }) NETWORKS[:testnet3] = NETWORKS[:testnet].merge({ magic_head: "\x0B\x11\x09\x07", no_difficulty: true, # no good. add right testnet3 difficulty calculation instead @@ -615,11 +635,13 @@ dns_seeds: [ "testnet-seed.alexykot.me", "testnet-seed.bitcoin.schildbach.de", "testnet-seed.bitcoin.petertodd.org", "testnet-seed.bluematt.me", + "dnsseed.test.webbtc.com", ], + known_nodes: ["test.webbtc.com"], checkpoints: { # 542 contains invalid transaction 542 => "0000000083c1f82cf72c6724f7a317325806384b06408bce7a4327f418dfd5ad", 71018 => "000000000010dd93dc55541116b2744eb8f4c3b706df6e8512d231a03fb9e435", 200000 => "0000000000287bffd321963ef05feab753ebe274e1d78b2fd4e2bfe9ad3aa6f2", @@ -809,15 +831,18 @@ address_version: "34", default_port: 8334, protocol_version: 35000, min_tx_fee: 50_000, per_dust_fee: true, - dns_seeds: [], + dns_seeds: [ + "nmc.seed.quisquis.de", + "dnsseed.namecoin.webbtc.com", + ], genesis_hash: "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770", known_nodes: [ "bitcoin.tunl.in", - "webbtc.com", + "namecoin.webbtc.com", "178.32.31.41", "78.47.86.43", "69.164.206.88", ], checkpoints: { @@ -831,13 +856,28 @@ }) NETWORKS[:namecoin_testnet] = NETWORKS[:namecoin].merge({ magic_head: "\xFA\xBF\xB5\xFE", default_port: 18334, - genesis_hash: "00000001f8ab0d14bceaeb50d163b0bef15aecf62b87bd5f5c864d37f201db97", - known_nodes: ["178.32.31.41"], - checkpoints: { - 0 => "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770", - } + genesis_hash: "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008", + dns_seeds: [ + "dnsseed.test.namecoin.webbtc.com", + ], + known_nodes: [ + "test.namecoin.webbtc.com", + "nmctest.net", + "192.99.247.234"], + checkpoints: { } + }) + + NETWORKS[:namecoin_regtest] = NETWORKS[:namecoin_testnet].merge({ + magic_head: "\xFA\xBF\xB5\xDA", + default_port: 18445, + genesis_hash: "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", + dns_seeds: [], known_nodes: [], + proof_of_work_limit: 0x207fffff, + checkpoints: { }, + address_versions: { pubkey_hash: "6f", script_hash: "c4" }, + privkey_version: "ef", }) end