Esteban Ordano
10 years ago
3 changed files with 86 additions and 37 deletions
@ -1,25 +1,72 @@ |
|||
'use strict'; |
|||
var _ = require('lodash'); |
|||
|
|||
exports.mainnet = { |
|||
pubkeyhash: 0x00, |
|||
identity: 0x0f, |
|||
identephem: 0x02, |
|||
identpersist: 0x01, |
|||
privatekey: 0x80, |
|||
scripthash: 0x05, |
|||
bip32pubkey: 0x0488b21e, |
|||
bip32privkey: 0x0488ade4, |
|||
}; |
|||
/** |
|||
* @constructor |
|||
* A network is merely a map containing values that correspond to version |
|||
* numbers for each bitcoin network. Currently only supporting "livenet" |
|||
* (a.k.a. "mainnet") and "testnet". |
|||
*/ |
|||
function Network() {} |
|||
|
|||
exports.testnet = { |
|||
pubkeyhash: 0x6f, |
|||
identity: 0x0f, |
|||
identephem: 0x02, |
|||
identpersist: 0x11, |
|||
privatekey: 0xef, |
|||
scripthash: 0xc4, |
|||
bip32pubkey: 0x043587cf, |
|||
bip32privkey: 0x04358394, |
|||
}; |
|||
/** |
|||
* @instance |
|||
* @member Network#livenet |
|||
*/ |
|||
var livenet = new Network(); |
|||
_.extend(livenet, { |
|||
name: 'livenet', |
|||
alias: 'mainnet', |
|||
pubkeyhash: 0x00, |
|||
privatekey: 0x80, |
|||
scripthash: 0x05, |
|||
xpubkey: 0x0488b21e, |
|||
xprivkey: 0x0488ade4 |
|||
}); |
|||
|
|||
/** |
|||
* @instance |
|||
* @member Network#testnet |
|||
*/ |
|||
var testnet = new Network(); |
|||
_.extend(testnet, { |
|||
name: 'testnet', |
|||
pubkeyhash: 0x6f, |
|||
privatekey: 0xef, |
|||
scripthash: 0xc4, |
|||
xpubkey: 0x043587cf, |
|||
xprivkey: 0x04358394 |
|||
}); |
|||
|
|||
var networkMaps = {}; |
|||
|
|||
exports.livenet = exports.mainnet; |
|||
_.each(_.values(livenet), function(value) { |
|||
networkMaps[value] = livenet; |
|||
}); |
|||
_.each(_.values(testnet), function(value) { |
|||
networkMaps[value] = testnet; |
|||
}); |
|||
|
|||
/** |
|||
* @function |
|||
* @member Network#getNetwork |
|||
* Retrieves the network associated with a magic number or string. |
|||
* @param {string|number|Network} arg |
|||
* @return Network |
|||
*/ |
|||
function getNetwork(arg) { |
|||
if (arg === livenet || arg === testnet) { |
|||
return arg; |
|||
} |
|||
return networkMaps[arg]; |
|||
} |
|||
|
|||
/** |
|||
* @namespace Network |
|||
*/ |
|||
module.exports = { |
|||
livenet: livenet, |
|||
testnet: testnet, |
|||
mainnet: livenet, |
|||
get: getNetwork |
|||
}; |
|||
|
Loading…
Reference in new issue