move version constants to networks.js
...with all the other network-specific constants.
This commit is contained in:
parent
b7550fc862
commit
78a753a2d4
69
BIP32.js
69
BIP32.js
@ -4,27 +4,16 @@ var coinUtil = imports.coinUtil || require('./util/util');
|
|||||||
var Key = imports.Key || require('./Key');
|
var Key = imports.Key || require('./Key');
|
||||||
var bignum = imports.bignum || require('bignum');
|
var bignum = imports.bignum || require('bignum');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
var networks = require('./networks');
|
||||||
|
|
||||||
var BITCOIN_MAINNET_PUBLIC = 0x0488b21e;
|
|
||||||
var BITCOIN_MAINNET_PRIVATE = 0x0488ade4;
|
|
||||||
var BITCOIN_TESTNET_PUBLIC = 0x043587cf;
|
|
||||||
var BITCOIN_TESTNET_PRIVATE = 0x04358394;
|
|
||||||
var DOGECOIN_MAINNET_PUBLIC = 0x02facafd;
|
|
||||||
var DOGECOIN_MAINNET_PRIVATE = 0x02fac398;
|
|
||||||
var DOGECOIN_TESTNET_PUBLIC = 0x0432a9a8;
|
|
||||||
var DOGECOIN_TESTNET_PRIVATE = 0x0432a243;
|
|
||||||
var LITECOIN_MAINNET_PUBLIC = 0x019da462;
|
|
||||||
var LITECOIN_MAINNET_PRIVATE = 0x019d9cfe;
|
|
||||||
var LITECOIN_TESTNET_PUBLIC = 0x0436f6e1;
|
|
||||||
var LITECOIN_TESTNET_PRIVATE = 0x0436ef7d;
|
|
||||||
var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16);
|
var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16);
|
||||||
var secp256k1_G = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16); //x coordinate
|
var secp256k1_G = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16); //x coordinate
|
||||||
|
|
||||||
var BIP32 = function(bytes) {
|
var BIP32 = function(bytes) {
|
||||||
if (bytes == 'mainnet' || bytes == 'livenet')
|
if (bytes == 'mainnet' || bytes == 'livenet')
|
||||||
this.version = BITCOIN_MAINNET_PRIVATE;
|
this.version = networks['livenet'].bip32private;
|
||||||
else if (bytes == 'testnet')
|
else if (bytes == 'testnet')
|
||||||
this.version = BITCOIN_TESTNET_PRIVATE;
|
this.version = networks['testnet'].bip32private;
|
||||||
|
|
||||||
if (bytes == 'mainnet' || bytes == 'livenet' || bytes == 'testnet') {
|
if (bytes == 'mainnet' || bytes == 'livenet' || bytes == 'testnet') {
|
||||||
this.depth = 0x00;
|
this.depth = 0x00;
|
||||||
@ -71,20 +60,12 @@ BIP32.prototype.init_from_bytes = function(bytes) {
|
|||||||
var key_bytes = bytes.slice(45, 78);
|
var key_bytes = bytes.slice(45, 78);
|
||||||
|
|
||||||
var is_private =
|
var is_private =
|
||||||
(this.version == BITCOIN_MAINNET_PRIVATE ||
|
(this.version == networks['livenet'].bip32private ||
|
||||||
this.version == BITCOIN_TESTNET_PRIVATE ||
|
this.version == networks['testnet'].bip32private );
|
||||||
this.version == DOGECOIN_MAINNET_PRIVATE ||
|
|
||||||
this.version == DOGECOIN_TESTNET_PRIVATE ||
|
|
||||||
this.version == LITECOIN_MAINNET_PRIVATE ||
|
|
||||||
this.version == LITECOIN_TESTNET_PRIVATE );
|
|
||||||
|
|
||||||
var is_public =
|
var is_public =
|
||||||
(this.version == BITCOIN_MAINNET_PUBLIC ||
|
(this.version == networks['livenet'].bip32public ||
|
||||||
this.version == BITCOIN_TESTNET_PUBLIC ||
|
this.version == networks['testnet'].bip32public );
|
||||||
this.version == DOGECOIN_MAINNET_PUBLIC ||
|
|
||||||
this.version == DOGECOIN_TESTNET_PUBLIC ||
|
|
||||||
this.version == LITECOIN_MAINNET_PUBLIC ||
|
|
||||||
this.version == LITECOIN_TESTNET_PUBLIC );
|
|
||||||
|
|
||||||
if (is_private && key_bytes[0] == 0) {
|
if (is_private && key_bytes[0] == 0) {
|
||||||
this.eckey = new Key();
|
this.eckey = new Key();
|
||||||
@ -111,29 +92,13 @@ BIP32.prototype.build_extended_public_key = function() {
|
|||||||
|
|
||||||
var v = null;
|
var v = null;
|
||||||
switch(this.version) {
|
switch(this.version) {
|
||||||
case BITCOIN_MAINNET_PUBLIC:
|
case networks['livenet'].bip32public:
|
||||||
case BITCOIN_MAINNET_PRIVATE:
|
case networks['livenet'].bip32private:
|
||||||
v = BITCOIN_MAINNET_PUBLIC;
|
v = networks['livenet'].bip32public;
|
||||||
break;
|
break;
|
||||||
case BITCOIN_TESTNET_PUBLIC:
|
case networks['testnet'].bip32public:
|
||||||
case BITCOIN_TESTNET_PRIVATE:
|
case networks['testnet'].bip32private:
|
||||||
v = BITCOIN_TESTNET_PUBLIC;
|
v = networks['testnet'].bip32public;
|
||||||
break;
|
|
||||||
case DOGECOIN_MAINNET_PUBLIC:
|
|
||||||
case DOGECOIN_MAINNET_PRIVATE:
|
|
||||||
v = DOGECOIN_MAINNET_PUBLIC;
|
|
||||||
break;
|
|
||||||
case DOGECOIN_TESTNET_PUBLIC:
|
|
||||||
case DOGECOIN_TESTNET_PRIVATE:
|
|
||||||
v = DOGECOIN_TESTNET_PUBLIC;
|
|
||||||
break;
|
|
||||||
case LITECOIN_MAINNET_PUBLIC:
|
|
||||||
case LITECOIN_MAINNET_PRIVATE:
|
|
||||||
v = LITECOIN_MAINNET_PUBLIC;
|
|
||||||
break;
|
|
||||||
case LITECOIN_TESTNET_PUBLIC:
|
|
||||||
case LITECOIN_TESTNET_PRIVATE:
|
|
||||||
v = LITECOIN_TESTNET_PUBLIC;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Unknown version");
|
throw new Error("Unknown version");
|
||||||
@ -262,12 +227,8 @@ BIP32.prototype.derive_child = function(i) {
|
|||||||
var use_private = (i & 0x80000000) != 0;
|
var use_private = (i & 0x80000000) != 0;
|
||||||
|
|
||||||
var is_private =
|
var is_private =
|
||||||
(this.version == BITCOIN_MAINNET_PRIVATE ||
|
(this.version == networks['livenet'].bip32private ||
|
||||||
this.version == BITCOIN_TESTNET_PRIVATE ||
|
this.version == networks['testnet'].bip32private );
|
||||||
this.version == DOGECOIN_MAINNET_PRIVATE ||
|
|
||||||
this.version == DOGECOIN_TESTNET_PRIVATE ||
|
|
||||||
this.version == LITECOIN_MAINNET_PRIVATE ||
|
|
||||||
this.version == LITECOIN_TESTNET_PRIVATE);
|
|
||||||
|
|
||||||
if (use_private && (!this.has_private_key || !is_private))
|
if (use_private && (!this.has_private_key || !is_private))
|
||||||
throw new Error("Cannot do private key derivation without private key");
|
throw new Error("Cannot do private key derivation without private key");
|
||||||
|
|||||||
@ -42,6 +42,8 @@ exports.livenet = {
|
|||||||
checkpoints: [], // need to put checkpoint blocks here
|
checkpoints: [], // need to put checkpoint blocks here
|
||||||
addressPubkey: 0,
|
addressPubkey: 0,
|
||||||
addressScript: 5,
|
addressScript: 5,
|
||||||
|
bip32public: 0x0488b21e,
|
||||||
|
bip32private: 0x0488ade4,
|
||||||
keySecret: 128,
|
keySecret: 128,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,5 +66,7 @@ exports.testnet = {
|
|||||||
checkpoints: [], // need to put checkput blocks here
|
checkpoints: [], // need to put checkput blocks here
|
||||||
addressPubkey: 111,
|
addressPubkey: 111,
|
||||||
addressScript: 196,
|
addressScript: 196,
|
||||||
|
bip32public: 0x043587cf,
|
||||||
|
bip32private: 0x04358394,
|
||||||
keySecret: 239,
|
keySecret: 239,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user