keypair consistency.
This commit is contained in:
parent
a367674584
commit
49bcfc17e9
@ -154,7 +154,7 @@ Address.prototype.removeKey = function removeKey(key) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Address.prototype.getPrivateKey = function getPrivateKey(enc) {
|
Address.prototype.getPrivateKey = function getPrivateKey(enc) {
|
||||||
return this.key.getPrivate(enc);
|
return this.key.getPrivateKey(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
Address.toSecret = function toSecret(privateKey, compressed) {
|
Address.toSecret = function toSecret(privateKey, compressed) {
|
||||||
@ -218,12 +218,12 @@ Address.prototype.getPublicKey = function getPublicKey(enc) {
|
|||||||
if (this._pub)
|
if (this._pub)
|
||||||
return this._pub;
|
return this._pub;
|
||||||
|
|
||||||
this._pub = this.key.getPublic();
|
this._pub = this.key.getPublicKey();
|
||||||
|
|
||||||
return this._pub;
|
return this._pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.key.getPublic(enc);
|
return this.key.getPublicKey(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
Address.prototype.getKeyHash = function getKeyHash() {
|
Address.prototype.getKeyHash = function getKeyHash() {
|
||||||
|
|||||||
@ -78,25 +78,16 @@ function HDSeed(options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
this.bits = options.bits || 128;
|
this.bits = options.bits || 128;
|
||||||
this.entropy = options.entropy || HDSeed._entropy(this.bits / 8);
|
this.entropy = options.entropy || elliptic.rand(this.bits / 8);
|
||||||
this.mnemonic = options.mnemonic || HDSeed._mnemonic(this.entropy);
|
this.mnemonic = options.mnemonic || HDSeed._mnemonic(this.entropy);
|
||||||
this.seed = this.createSeed(options.passphrase);
|
this.seed = this.createSeed(options.passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
HDSeed.create = function create(options) {
|
|
||||||
var obj = new HDSeed(options);
|
|
||||||
return obj.seed || obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
HDSeed.prototype.createSeed = function createSeed(passphrase) {
|
HDSeed.prototype.createSeed = function createSeed(passphrase) {
|
||||||
this.passphrase = passphrase || '';
|
this.passphrase = passphrase || '';
|
||||||
return pbkdf2(this.mnemonic, 'mnemonic' + passphrase, 2048, 64);
|
return pbkdf2(this.mnemonic, 'mnemonic' + passphrase, 2048, 64);
|
||||||
};
|
};
|
||||||
|
|
||||||
HDSeed._entropy = function _entropy(size) {
|
|
||||||
return randomBytes(size);
|
|
||||||
};
|
|
||||||
|
|
||||||
HDSeed._mnemonic = function _mnemonic(entropy) {
|
HDSeed._mnemonic = function _mnemonic(entropy) {
|
||||||
var bin = '';
|
var bin = '';
|
||||||
var mnemonic = [];
|
var mnemonic = [];
|
||||||
@ -1003,16 +994,22 @@ HDPublicKey.prototype.deriveString = function deriveString(path) {
|
|||||||
return this.pair.validate.apply(this.pair, arguments);
|
return this.pair.validate.apply(this.pair, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
HD.prototype.getPublic =
|
HD.prototype.getPublic = function getPublic() {
|
||||||
HD.prototype.getPublicKey = function getPublicKey() {
|
|
||||||
return this.pair.getPublic.apply(this.pair, arguments);
|
return this.pair.getPublic.apply(this.pair, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
HD.prototype.getPrivate =
|
HD.prototype.getPrivate = function getPrivate() {
|
||||||
HD.prototype.getPrivateKey = function getPrivateKey() {
|
|
||||||
return this.pair.getPrivate.apply(this.pair, arguments);
|
return this.pair.getPrivate.apply(this.pair, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HD.prototype.getPublicKey = function getPublicKey() {
|
||||||
|
return bcoin.keypair.prototype.getPublicKey.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
HD.prototype.getPrivateKey = function getPrivateKey() {
|
||||||
|
return bcoin.keypair.prototype.getPrivateKey.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
HD.prototype.sign = function sign(msg) {
|
HD.prototype.sign = function sign(msg) {
|
||||||
return this.pair.sign.apply(this.pair, arguments);
|
return this.pair.sign.apply(this.pair, arguments);
|
||||||
};
|
};
|
||||||
@ -1028,10 +1025,12 @@ HDPublicKey.prototype.deriveString = function deriveString(path) {
|
|||||||
HD.prototype.__defineGetter__('priv', function() {
|
HD.prototype.__defineGetter__('priv', function() {
|
||||||
return this.pair.priv;
|
return this.pair.priv;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
HD.prototype.compressed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
HDPrivateKey.prototype.toSecret = function toSecret() {
|
HDPrivateKey.prototype.toSecret = function toSecret() {
|
||||||
return bcoin.keypair.toSecret(this.privateKey, true);
|
return bcoin.keypair.toSecret(this.privateKey, this.compressed);
|
||||||
};
|
};
|
||||||
|
|
||||||
HDPrivateKey.fromSecret = function fromSecret(privateKey) {
|
HDPrivateKey.fromSecret = function fromSecret(privateKey) {
|
||||||
@ -1056,18 +1055,6 @@ function sha512hmac(data, salt) {
|
|||||||
return Array.prototype.slice.call(h);
|
return Array.prototype.slice.call(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomBytes(size) {
|
|
||||||
if (isBrowser) {
|
|
||||||
var a = Uint8Array(size);
|
|
||||||
var buf = new Array(size);
|
|
||||||
(window.crypto || window.msCrypto).getRandomValues(a);
|
|
||||||
utils.copy(a, buf, 0);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
var crypto = require('crypto');
|
|
||||||
return Array.prototype.slice.call(crypto.randomBytes(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
function array32(data) {
|
function array32(data) {
|
||||||
var b = [];
|
var b = [];
|
||||||
utils.writeU32BE(b, data, 0);
|
utils.writeU32BE(b, data, 0);
|
||||||
|
|||||||
@ -99,7 +99,14 @@ KeyPair.prototype.verify = function verify(msg, signature) {
|
|||||||
return this.pair.verify.apply(this.pair, arguments);
|
return this.pair.verify.apply(this.pair, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyPair.prototype.getPrivate =
|
KeyPair.prototype.getPrivate = function getPrivate(enc) {
|
||||||
|
return this.pair.getPrivate.apply(this.pair, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
KeyPair.prototype.getPublic = function getPublic(enc) {
|
||||||
|
return this.pair.getPublic.apply(this.pair, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
KeyPair.prototype.getPrivateKey = function getPrivateKey(enc) {
|
KeyPair.prototype.getPrivateKey = function getPrivateKey(enc) {
|
||||||
var privateKey = this.pair.getPrivate();
|
var privateKey = this.pair.getPrivate();
|
||||||
|
|
||||||
@ -117,7 +124,6 @@ KeyPair.prototype.getPrivateKey = function getPrivateKey(enc) {
|
|||||||
return privateKey;
|
return privateKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyPair.prototype.getPublic =
|
|
||||||
KeyPair.prototype.getPublicKey = function getPublicKey(enc) {
|
KeyPair.prototype.getPublicKey = function getPublicKey(enc) {
|
||||||
var publicKey = this.pair.getPublic(this.compressed, 'array');
|
var publicKey = this.pair.getPublic(this.compressed, 'array');
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ KeyPair.prototype.getPublicKey = function getPublicKey(enc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
KeyPair.prototype.toSecret = function toSecret() {
|
KeyPair.prototype.toSecret = function toSecret() {
|
||||||
return KeyPair.toSecret(this.getPrivate(), this.compressed);
|
return KeyPair.toSecret(this.getPrivateKey(), this.compressed);
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyPair.toSecret = function toSecret(privateKey, compressed) {
|
KeyPair.toSecret = function toSecret(privateKey, compressed) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user