network: always use lowercase

This commit is contained in:
Daniel Cousens 2014-06-14 00:30:13 +10:00
parent b68b1d5da4
commit 553ade1208
8 changed files with 26 additions and 26 deletions

View file

@ -11,7 +11,7 @@ function findScriptTypeByVersion(queryVersion) {
var version = network[versionName] var version = network[versionName]
if (version === queryVersion) { if (version === queryVersion) {
return versionName.toLowerCase() return versionName
} }
} }
} }
@ -41,10 +41,10 @@ Address.fromOutputScript = function(script, network) {
var type = scripts.classifyOutput(script) var type = scripts.classifyOutput(script)
if (type === 'pubkeyhash') { if (type === 'pubkeyhash') {
return new Address(script.chunks[2], network.pubKeyHash) return new Address(script.chunks[2], network.pubkeyhash)
} else if (type === 'scripthash') { } else if (type === 'scripthash') {
return new Address(script.chunks[1], network.scriptHash) return new Address(script.chunks[1], network.scripthash)
} }
assert(false, type + ' has no matching Address') assert(false, type + ' has no matching Address')

View file

@ -32,7 +32,7 @@ ECPubKey.fromHex = function(hex) {
ECPubKey.prototype.getAddress = function(network) { ECPubKey.prototype.getAddress = function(network) {
network = network || networks.bitcoin network = network || networks.bitcoin
return new Address(crypto.hash160(this.toBuffer()), network.pubKeyHash) return new Address(crypto.hash160(this.toBuffer()), network.pubkeyhash)
} }
ECPubKey.prototype.verify = function(hash, signature) { ECPubKey.prototype.verify = function(hash, signature) {

View file

@ -13,7 +13,7 @@ var ecurve = require('ecurve')
var ecparams = ecurve.getCurveByName('secp256k1') var ecparams = ecurve.getCurveByName('secp256k1')
function magicHash(message, network) { function magicHash(message, network) {
var magicPrefix = new Buffer(network.magicPrefix) var magicPrefix = new Buffer(network.magicprefix)
var messageBuffer = new Buffer(message) var messageBuffer = new Buffer(message)
var lengthBuffer = new Buffer(bufferutils.varIntSize(messageBuffer.length)) var lengthBuffer = new Buffer(bufferutils.varIntSize(messageBuffer.length))
bufferutils.writeVarInt(lengthBuffer, messageBuffer.length, 0) bufferutils.writeVarInt(lengthBuffer, messageBuffer.length, 0)

View file

@ -2,43 +2,43 @@
// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731 // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
module.exports = { module.exports = {
bitcoin: { bitcoin: {
magicPrefix: '\x18Bitcoin Signed Message:\n', magicprefix: '\x18Bitcoin Signed Message:\n',
bip32: { bip32: {
public: 0x0488b21e, public: 0x0488b21e,
private: 0x0488ade4 private: 0x0488ade4
}, },
pubKeyHash: 0x00, pubkeyhash: 0x00,
scriptHash: 0x05, scripthash: 0x05,
wif: 0x80 wif: 0x80
}, },
dogecoin: { dogecoin: {
magicPrefix: '\x19Dogecoin Signed Message:\n', magicprefix: '\x19Dogecoin Signed Message:\n',
bip32: { bip32: {
public: 0x02facafd, public: 0x02facafd,
private: 0x02fac398 private: 0x02fac398
}, },
pubKeyHash: 0x1e, pubkeyhash: 0x1e,
scriptHash: 0x16, scripthash: 0x16,
wif: 0x9e wif: 0x9e
}, },
litecoin: { litecoin: {
magicPrefix: '\x19Litecoin Signed Message:\n', magicprefix: '\x19Litecoin Signed Message:\n',
bip32: { bip32: {
public: 0x019da462, public: 0x019da462,
private: 0x019d9cfe private: 0x019d9cfe
}, },
pubKeyHash: 0x30, pubkeyhash: 0x30,
scriptHash: 0x05, scripthash: 0x05,
wif: 0xb0 wif: 0xb0
}, },
testnet: { testnet: {
magicPrefix: '\x18Bitcoin Signed Message:\n', magicprefix: '\x18Bitcoin Signed Message:\n',
bip32: { bip32: {
public: 0x043587cf, public: 0x043587cf,
private: 0x04358394 private: 0x04358394
}, },
pubKeyHash: 0x6f, pubkeyhash: 0x6f,
scriptHash: 0xc4, scripthash: 0xc4,
wif: 0xef wif: 0xef
} }
} }

View file

@ -56,10 +56,10 @@ describe('Bitcoin-core', function() {
assert.equal(address.hash.toString('hex'), hex) assert.equal(address.hash.toString('hex'), hex)
if (params.addrType === 'pubkey') { if (params.addrType === 'pubkey') {
assert.equal(address.version, network.pubKeyHash) assert.equal(address.version, network.pubkeyhash)
} else if (params.addrType === 'script') { } else if (params.addrType === 'script') {
assert.equal(address.version, network.scriptHash) assert.equal(address.version, network.scripthash)
} }
}) })
}) })
@ -68,10 +68,10 @@ describe('Bitcoin-core', function() {
// base58_keys_invalid // base58_keys_invalid
describe('Address', function() { describe('Address', function() {
var allowedNetworks = [ var allowedNetworks = [
networks.bitcoin.pubKeyHash, networks.bitcoin.pubkeyhash,
networks.bitcoin.scriptHash, networks.bitcoin.scripthash,
networks.testnet.pubKeyHash, networks.testnet.pubkeyhash,
networks.testnet.scriptHash networks.testnet.scripthash
] ]
base58_keys_invalid.forEach(function(f) { base58_keys_invalid.forEach(function(f) {

View file

@ -72,7 +72,7 @@ describe('ECPubKey', function() {
var pubKey = new ECPubKey(Q) var pubKey = new ECPubKey(Q)
var address = pubKey.getAddress(networks.testnet) var address = pubKey.getAddress(networks.testnet)
assert.equal(address.version, networks.testnet.pubKeyHash) assert.equal(address.version, networks.testnet.pubkeyhash)
assert.equal(address.hash.toString('hex'), fixtures.compressed.hash160) assert.equal(address.hash.toString('hex'), fixtures.compressed.hash160)
}) })
}) })

View file

@ -204,7 +204,7 @@ describe('HDNode', function() {
var hd = HDNode.fromBase58(f.master.base58) var hd = HDNode.fromBase58(f.master.base58)
hd.network = networks.testnet hd.network = networks.testnet
assert.equal(hd.getAddress().version, networks.testnet.pubKeyHash) assert.equal(hd.getAddress().version, networks.testnet.pubkeyhash)
}) })
}) })

View file

@ -100,7 +100,7 @@ describe('Scripts', function() {
var redeemScript = scripts.multisigOutput(2, pubKeys) var redeemScript = scripts.multisigOutput(2, pubKeys)
var hash160 = crypto.hash160(new Buffer(redeemScript.buffer)) var hash160 = crypto.hash160(new Buffer(redeemScript.buffer))
var multisigAddress = new Address(hash160, networks.bitcoin.scriptHash) var multisigAddress = new Address(hash160, networks.bitcoin.scripthash)
assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v') assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v')
}) })