mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Tweak method definition order
This commit is contained in:
@@ -27,14 +27,6 @@ function Ed25519Pair() {
|
||||
|
||||
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)
|
||||
* @return {Ed25519Pair} key pair
|
||||
@@ -43,6 +35,14 @@ Ed25519Pair.fromPublic = function(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() {
|
||||
if (this.seedBytes) {
|
||||
const seed256 = deriveEdKeyPairSeed(this.seedBytes);
|
||||
@@ -55,12 +55,12 @@ cachedProperty(Ed25519Pair, function pubKeyCanonicalBytes() {
|
||||
return [0xED].concat(this.key().pubBytes());
|
||||
});
|
||||
|
||||
Ed25519Pair.prototype.sign = function(message) {
|
||||
return this.key().sign(message).toBytes();
|
||||
};
|
||||
|
||||
Ed25519Pair.prototype.verify = function(message, signature) {
|
||||
return this.key().verify(message, signature);
|
||||
/**
|
||||
* @param {Array<Number>} seedBytes - A 128 bit seed
|
||||
* @return {Ed25519Pair} key pair
|
||||
*/
|
||||
Ed25519Pair.fromSeed = function(seedBytes) {
|
||||
return new Ed25519Pair({seedBytes});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -76,22 +76,6 @@ function K256Pair({validator}) {
|
||||
|
||||
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)
|
||||
*/
|
||||
@@ -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 = {
|
||||
K256Pair,
|
||||
accountPublicFromPublicGenerator
|
||||
|
||||
Reference in New Issue
Block a user