Esteban Ordano
10 years ago
3 changed files with 86 additions and 37 deletions
@ -1,25 +1,72 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
var _ = require('lodash'); |
||||
|
|
||||
exports.mainnet = { |
/** |
||||
pubkeyhash: 0x00, |
* @constructor |
||||
identity: 0x0f, |
* A network is merely a map containing values that correspond to version |
||||
identephem: 0x02, |
* numbers for each bitcoin network. Currently only supporting "livenet" |
||||
identpersist: 0x01, |
* (a.k.a. "mainnet") and "testnet". |
||||
privatekey: 0x80, |
*/ |
||||
scripthash: 0x05, |
function Network() {} |
||||
bip32pubkey: 0x0488b21e, |
|
||||
bip32privkey: 0x0488ade4, |
|
||||
}; |
|
||||
|
|
||||
exports.testnet = { |
/** |
||||
pubkeyhash: 0x6f, |
* @instance |
||||
identity: 0x0f, |
* @member Network#livenet |
||||
identephem: 0x02, |
*/ |
||||
identpersist: 0x11, |
var livenet = new Network(); |
||||
privatekey: 0xef, |
_.extend(livenet, { |
||||
scripthash: 0xc4, |
name: 'livenet', |
||||
bip32pubkey: 0x043587cf, |
alias: 'mainnet', |
||||
bip32privkey: 0x04358394, |
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