fix address problems. update elliptic to 3.0.3.
This commit is contained in:
parent
505aad8729
commit
a2f13d94c3
@ -1,11 +1,7 @@
|
|||||||
var bcoin = exports;
|
var bcoin = exports;
|
||||||
var elliptic = require('elliptic');
|
var elliptic = require('elliptic');
|
||||||
|
|
||||||
if (elliptic.ec) {
|
bcoin.ecdsa = elliptic.ec('secp256k1');
|
||||||
bcoin.ecdsa = elliptic.ec('secp256k1');
|
|
||||||
} else {
|
|
||||||
bcoin.ecdsa = elliptic.ecdsa(elliptic.nist.secp256k1);
|
|
||||||
}
|
|
||||||
bcoin.utils = require('./bcoin/utils');
|
bcoin.utils = require('./bcoin/utils');
|
||||||
bcoin.bloom = require('./bcoin/bloom');
|
bcoin.bloom = require('./bcoin/bloom');
|
||||||
bcoin.protocol = require('./bcoin/protocol');
|
bcoin.protocol = require('./bcoin/protocol');
|
||||||
|
|||||||
@ -62,16 +62,7 @@ var crypto = require('crypto');
|
|||||||
|
|
||||||
var english = require('../../etc/english.json');
|
var english = require('../../etc/english.json');
|
||||||
|
|
||||||
var ec;
|
var ec = elliptic.curves.secp256k1;
|
||||||
if (!elliptic.curves) {
|
|
||||||
ec = elliptic.nist.secp256k1;
|
|
||||||
ec.curve.g = ec.g;
|
|
||||||
ec.curve.n = ec.n;
|
|
||||||
} else {
|
|
||||||
ec = elliptic.curves.secp256k1;
|
|
||||||
}
|
|
||||||
var ecPoint = ec.curve.point.bind(ec.curve);
|
|
||||||
var ecPointFromX = ec.curve.pointFromX.bind(ec.curve);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HD Seeds
|
* HD Seeds
|
||||||
@ -333,6 +324,8 @@ HDPriv.prototype.derive = function(index, hard) {
|
|||||||
var leftPart = new bn(hash.slice(0, 32));
|
var leftPart = new bn(hash.slice(0, 32));
|
||||||
var chainCode = hash.slice(32, 64);
|
var chainCode = hash.slice(32, 64);
|
||||||
|
|
||||||
|
// XXX This causes a call stack overflow with bn.js@4.0.5 and elliptic@3.0.3
|
||||||
|
// Example: new bn(0).mod(ec.curve.n)
|
||||||
var privateKey = leftPart.add(new bn(this.privateKey)).mod(ec.curve.n).toArray();
|
var privateKey = leftPart.add(new bn(this.privateKey)).mod(ec.curve.n).toArray();
|
||||||
|
|
||||||
return new HDPriv({
|
return new HDPriv({
|
||||||
|
|||||||
@ -242,7 +242,7 @@ TX.prototype.out = function out(output, value) {
|
|||||||
var keys = output.keys || output.address;
|
var keys = output.keys || output.address;
|
||||||
if (keys === output.address) {
|
if (keys === output.address) {
|
||||||
keys = keys.map(function(address) {
|
keys = keys.map(function(address) {
|
||||||
return bcoin.wallet.addr2hash(address);
|
return bcoin.wallet.addr2hash(address, 'normal');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
keys = keys.map(function(key) {
|
keys = keys.map(function(key) {
|
||||||
@ -275,7 +275,7 @@ TX.prototype.out = function out(output, value) {
|
|||||||
script = [
|
script = [
|
||||||
'dup',
|
'dup',
|
||||||
'hash160',
|
'hash160',
|
||||||
bcoin.wallet.addr2hash(output.address),
|
bcoin.wallet.addr2hash(output.address, 'normal'),
|
||||||
'eqverify',
|
'eqverify',
|
||||||
'checksig'
|
'checksig'
|
||||||
];
|
];
|
||||||
@ -383,7 +383,7 @@ TX.prototype.inputAddrs = function inputAddrs() {
|
|||||||
}).map(function(input) {
|
}).map(function(input) {
|
||||||
var pub = input.script[1];
|
var pub = input.script[1];
|
||||||
var hash = utils.ripesha(pub);
|
var hash = utils.ripesha(pub);
|
||||||
return bcoin.wallet.hash2addr(hash);
|
return bcoin.wallet.hash2addr(hash, 'normal');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -46,18 +46,14 @@ function Wallet(options, passphrase) {
|
|||||||
entropy: hash.sha256().update(options.passphrase).digest()
|
entropy: hash.sha256().update(options.passphrase).digest()
|
||||||
});
|
});
|
||||||
} else if (options.priv || options.pub) {
|
} else if (options.priv || options.pub) {
|
||||||
this.key = bcoin.ecdsa.keyPair(options.priv || options.pub, 'hex');
|
this.key = bcoin.ecdsa.keyPair({
|
||||||
|
priv: options.priv,
|
||||||
|
pub: options.pub
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.key = bcoin.ecdsa.genKeyPair();
|
this.key = bcoin.ecdsa.genKeyPair();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prefix = 'bt/' + this.getAddress() + '/';
|
|
||||||
this.tx = new bcoin.txPool(this);
|
|
||||||
|
|
||||||
// Just a constants, actually
|
|
||||||
this.fee = 10000;
|
|
||||||
this.dust = 5460;
|
|
||||||
|
|
||||||
this.addressType = options.addressType || 'normal';
|
this.addressType = options.addressType || 'normal';
|
||||||
|
|
||||||
// Multisig
|
// Multisig
|
||||||
@ -82,6 +78,13 @@ function Wallet(options, passphrase) {
|
|||||||
throw new Error(this.m + ' public keys required');
|
throw new Error(this.m + ' public keys required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.prefix = 'bt/' + this.getAddress() + '/';
|
||||||
|
this.tx = new bcoin.txPool(this);
|
||||||
|
|
||||||
|
// Just a constants, actually
|
||||||
|
this.fee = 10000;
|
||||||
|
this.dust = 5460;
|
||||||
|
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
inherits(Wallet, EventEmitter);
|
inherits(Wallet, EventEmitter);
|
||||||
@ -165,13 +168,13 @@ Wallet.prototype.getHash = function getHash() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.getAddress = function getAddress() {
|
Wallet.prototype.getAddress = function getAddress() {
|
||||||
return Wallet.hash2addr(this.getHash());
|
return Wallet.hash2addr(this.getHash(), this.addressType);
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.hash2addr = function hash2addr(hash, version) {
|
Wallet.hash2addr = function hash2addr(hash, version) {
|
||||||
hash = utils.toArray(hash, 'hex');
|
hash = utils.toArray(hash, 'hex');
|
||||||
|
|
||||||
version = constants.addr[version || this.addressType];
|
version = constants.addr[version || 'normal'];
|
||||||
hash = [ version ].concat(hash);
|
hash = [ version ].concat(hash);
|
||||||
|
|
||||||
var addr = hash.concat(utils.checksum(hash));
|
var addr = hash.concat(utils.checksum(hash));
|
||||||
@ -182,7 +185,7 @@ Wallet.addr2hash = function addr2hash(addr, version) {
|
|||||||
if (!Array.isArray(addr))
|
if (!Array.isArray(addr))
|
||||||
addr = utils.fromBase58(addr);
|
addr = utils.fromBase58(addr);
|
||||||
|
|
||||||
version = constants.addr[version || this.addressType];
|
version = constants.addr[version || 'normal'];
|
||||||
|
|
||||||
if (addr.length !== 25)
|
if (addr.length !== 25)
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^0.8.0",
|
"async": "^0.8.0",
|
||||||
"bn.js": "^0.10.0",
|
"bn.js": "^0.10.0",
|
||||||
"elliptic": "^0.14.1",
|
"elliptic": "^3.0.3",
|
||||||
"hash.js": "^0.2.0",
|
"hash.js": "^0.2.0",
|
||||||
"inherits": "^2.0.1"
|
"inherits": "^2.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user