Tweak method definition order

This commit is contained in:
Nicholas Dudfield
2015-08-04 13:49:31 +07:00
parent 6bacd66d1a
commit 71d62fd58c
2 changed files with 30 additions and 30 deletions

View File

@@ -27,14 +27,6 @@ function Ed25519Pair() {
util.inherits(Ed25519Pair, KeyPair); util.inherits(Ed25519Pair, KeyPair);
/**
* @param {Array<Number>} seedBytes - A 128 bit seed
* @return {Ed25519Pair} key pair
*/
Ed25519Pair.fromSeed = function(seedBytes) {
return new Ed25519Pair({seedBytes});
};
/** /**
* @param {Seed} publicKey - public key in canonical form (0xED + 32 bytes) * @param {Seed} publicKey - public key in canonical form (0xED + 32 bytes)
* @return {Ed25519Pair} key pair * @return {Ed25519Pair} key pair
@@ -43,6 +35,14 @@ Ed25519Pair.fromPublic = function(publicKey) {
return new Ed25519Pair({pubBytes: parseBytes(publicKey)}); return new Ed25519Pair({pubBytes: parseBytes(publicKey)});
}; };
Ed25519Pair.prototype.sign = function(message) {
return this.key().sign(message).toBytes();
};
Ed25519Pair.prototype.verify = function(message, signature) {
return this.key().verify(message, signature);
};
cachedProperty(Ed25519Pair, function key() { cachedProperty(Ed25519Pair, function key() {
if (this.seedBytes) { if (this.seedBytes) {
const seed256 = deriveEdKeyPairSeed(this.seedBytes); const seed256 = deriveEdKeyPairSeed(this.seedBytes);
@@ -55,12 +55,12 @@ cachedProperty(Ed25519Pair, function pubKeyCanonicalBytes() {
return [0xED].concat(this.key().pubBytes()); return [0xED].concat(this.key().pubBytes());
}); });
Ed25519Pair.prototype.sign = function(message) { /**
return this.key().sign(message).toBytes(); * @param {Array<Number>} seedBytes - A 128 bit seed
}; * @return {Ed25519Pair} key pair
*/
Ed25519Pair.prototype.verify = function(message, signature) { Ed25519Pair.fromSeed = function(seedBytes) {
return this.key().verify(message, signature); return new Ed25519Pair({seedBytes});
}; };
module.exports = { module.exports = {

View File

@@ -76,22 +76,6 @@ function K256Pair({validator}) {
util.inherits(K256Pair, KeyPair); util.inherits(K256Pair, KeyPair);
K256Pair.fromSeed = function(seedBytes, opts={}) {
return new K256Pair({seedBytes, validator: opts.validator});
};
cachedProperty(K256Pair, function key() {
if (this.seedBytes) {
const options = {validator: this.validator};
return secp256k1.keyFromPrivate(deriveSecret(this.seedBytes, options));
}
return secp256k1.keyFromPublic(this.pubKeyCanonicalBytes());
});
cachedProperty(K256Pair, function pubKeyCanonicalBytes() {
return this.key().getPublic().encodeCompressed();
});
/* /*
@param {Array<Byte>} message (bytes) @param {Array<Byte>} message (bytes)
*/ */
@@ -124,6 +108,22 @@ K256Pair.prototype.verify = function(message, signature) {
} }
}; };
cachedProperty(K256Pair, function key() {
if (this.seedBytes) {
const options = {validator: this.validator};
return secp256k1.keyFromPrivate(deriveSecret(this.seedBytes, options));
}
return secp256k1.keyFromPublic(this.pubKeyCanonicalBytes());
});
cachedProperty(K256Pair, function pubKeyCanonicalBytes() {
return this.key().getPublic().encodeCompressed();
});
K256Pair.fromSeed = function(seedBytes, opts={}) {
return new K256Pair({seedBytes, validator: opts.validator});
};
module.exports = { module.exports = {
K256Pair, K256Pair,
accountPublicFromPublicGenerator accountPublicFromPublicGenerator