Merge pull request #216 from dcousens/addrser
Network: use capitalization
This commit is contained in:
commit
85e9723bfe
7 changed files with 26 additions and 40 deletions
|
@ -3,24 +3,19 @@ var base58check = require('./base58check')
|
|||
var networks = require('./networks')
|
||||
var scripts = require('./scripts')
|
||||
|
||||
function findScriptTypeByVersion(queryVersion) {
|
||||
function findScriptTypeByVersion(version) {
|
||||
for (var networkName in networks) {
|
||||
var network = networks[networkName]
|
||||
|
||||
for (var versionName in network) {
|
||||
var version = network[versionName]
|
||||
|
||||
if (version === queryVersion) {
|
||||
return versionName
|
||||
}
|
||||
}
|
||||
if (version === network.pubKeyHash) return 'pubkeyhash'
|
||||
if (version === network.scriptHash) return 'scripthash'
|
||||
}
|
||||
}
|
||||
|
||||
function Address(hash, version) {
|
||||
assert(Buffer.isBuffer(hash), 'Expected Buffer, got ' + hash)
|
||||
assert.strictEqual(hash.length, 20, 'Invalid hash length')
|
||||
assert.strictEqual(version & 0xFF, version, 'Invalid version byte')
|
||||
assert.strictEqual(version & 0xff, version, 'Invalid version byte')
|
||||
|
||||
this.hash = hash
|
||||
this.version = version
|
||||
|
@ -40,12 +35,8 @@ Address.fromOutputScript = function(script, network) {
|
|||
|
||||
var type = scripts.classifyOutput(script)
|
||||
|
||||
if (type === 'pubkeyhash') {
|
||||
return new Address(script.chunks[2], network.pubkeyhash)
|
||||
|
||||
} else if (type === 'scripthash') {
|
||||
return new Address(script.chunks[1], network.scripthash)
|
||||
}
|
||||
if (type === 'pubkeyhash') return new Address(script.chunks[2], network.pubKeyHash)
|
||||
if (type === 'scripthash') return new Address(script.chunks[1], network.scriptHash)
|
||||
|
||||
assert(false, type + ' has no matching Address')
|
||||
}
|
||||
|
@ -62,13 +53,8 @@ Address.prototype.toBase58Check = function () {
|
|||
Address.prototype.toOutputScript = function() {
|
||||
var scriptType = findScriptTypeByVersion(this.version)
|
||||
|
||||
if (scriptType === 'pubkeyhash') {
|
||||
return scripts.pubKeyHashOutput(this.hash)
|
||||
|
||||
} else if (scriptType === 'scripthash') {
|
||||
return scripts.scriptHashOutput(this.hash)
|
||||
|
||||
}
|
||||
if (scriptType === 'pubkeyhash') return scripts.pubKeyHashOutput(this.hash)
|
||||
if (scriptType === 'scripthash') return scripts.scriptHashOutput(this.hash)
|
||||
|
||||
assert(false, this.toString() + ' has no matching Script')
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ ECPubKey.fromHex = function(hex) {
|
|||
ECPubKey.prototype.getAddress = function(network) {
|
||||
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) {
|
||||
|
|
|
@ -14,7 +14,7 @@ var ecurve = require('ecurve')
|
|||
var ecparams = ecurve.getCurveByName('secp256k1')
|
||||
|
||||
function magicHash(message, network) {
|
||||
var magicPrefix = new Buffer(network.magicprefix)
|
||||
var magicPrefix = new Buffer(network.magicPrefix)
|
||||
var messageBuffer = new Buffer(message)
|
||||
var lengthBuffer = new Buffer(bufferutils.varIntSize(messageBuffer.length))
|
||||
bufferutils.writeVarInt(lengthBuffer, messageBuffer.length, 0)
|
||||
|
|
|
@ -2,43 +2,43 @@
|
|||
// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
|
||||
module.exports = {
|
||||
bitcoin: {
|
||||
magicprefix: '\x18Bitcoin Signed Message:\n',
|
||||
magicPrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubkeyhash: 0x00,
|
||||
scripthash: 0x05,
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
},
|
||||
dogecoin: {
|
||||
magicprefix: '\x19Dogecoin Signed Message:\n',
|
||||
magicPrefix: '\x19Dogecoin Signed Message:\n',
|
||||
bip32: {
|
||||
public: 0x02facafd,
|
||||
private: 0x02fac398
|
||||
},
|
||||
pubkeyhash: 0x1e,
|
||||
scripthash: 0x16,
|
||||
pubKeyHash: 0x1e,
|
||||
scriptHash: 0x16,
|
||||
wif: 0x9e
|
||||
},
|
||||
litecoin: {
|
||||
magicprefix: '\x19Litecoin Signed Message:\n',
|
||||
magicPrefix: '\x19Litecoin Signed Message:\n',
|
||||
bip32: {
|
||||
public: 0x019da462,
|
||||
private: 0x019d9cfe
|
||||
},
|
||||
pubkeyhash: 0x30,
|
||||
scripthash: 0x05,
|
||||
pubKeyHash: 0x30,
|
||||
scriptHash: 0x05,
|
||||
wif: 0xb0
|
||||
},
|
||||
testnet: {
|
||||
magicprefix: '\x18Bitcoin Signed Message:\n',
|
||||
magicPrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubkeyhash: 0x6f,
|
||||
scripthash: 0xc4,
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,10 @@ describe('Bitcoin-core', function() {
|
|||
|
||||
assert.equal(address.hash.toString('hex'), hex)
|
||||
if (params.addrType === 'pubkey') {
|
||||
assert.equal(address.version, network.pubkeyhash)
|
||||
assert.equal(address.version, network.pubKeyHash)
|
||||
|
||||
} else if (params.addrType === 'script') {
|
||||
assert.equal(address.version, network.scripthash)
|
||||
assert.equal(address.version, network.scriptHash)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -72,7 +72,7 @@ describe('ECPubKey', function() {
|
|||
var pubKey = new ECPubKey(Q)
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -204,7 +204,7 @@ describe('HDNode', function() {
|
|||
var hd = HDNode.fromBase58(f.master.base58)
|
||||
hd.network = networks.testnet
|
||||
|
||||
assert.equal(hd.getAddress().version, networks.testnet.pubkeyhash)
|
||||
assert.equal(hd.getAddress().version, networks.testnet.pubKeyHash)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue